CR-Post2PingFM Plugin Tweaked for WordPress MU

Although this is not strictly related to Second Life itself, I need some place to put a tweaked version of Arief Bayu Purwanto’s CR Post2PingFM plugin, which required some tweaking to work well with WordPress MU.

The problem has to do with setting and reading options properly in a multiblog environment. WordPress and WordPress MU handle this differently, thus the original, untweaked plugin didn’t work properly.

Thanks to Marcus Cudd for helping me to debug it!

You have to enclose it in the usual PHP tags, which this code plugin sadly eats up.

Warning: Beachbum noticed quite correctly that the single quotes in the code get unfortunately converted by WordPress into “typographical quotes”, so you have to be extra-careful when copying & pasting this! Thanks for the tip, Beachbum 🙂
[code lang=”php” wraplines=”true” toolbar=”true”]
/*
Plugin Name: CR Post to Ping.fm
Plugin URI: http://bayu.freelancer.web.id/2009/03/31/wordpress-plugin-cr-post2pingfm/
Description: This plugin will submit your new post to ping.fm account.
Version: 0.7.2
Author: Arief Bayu Purwanto, tweaked by Gwyneth Llewelyn to work with WordPress MU 2.8.6
Author URI: http://bayu.freelancer.web.id/
*/

define(‘API_KEY’, ‘41121eb3a56f921bc2957b2458d65bad’);

add_action(‘publish_post’, ‘cr_post_2_pingfm_submit_to_ping_fm’);
add_action(‘admin_menu’, ‘cr_post_2_pingfm_submit_config_admin’);
add_action(‘admin_init’, ‘cr_post_2_pingfm_settings_api_init’);

function cr_post_2_pingfm_settings_api_init()
{
register_setting(‘cr_post_2_pingfm_settings’, ‘cr_post_2_pingfm_options’);
}

function cr_post_2_pingfm_submit_to_ping_fm($postId)
{
$continue = false;
$categories = array();
$postMode = get_option(‘cl_post_pingfm_publish_mode’, false);
$republish = false;

if(!wp_is_post_revision($postId))
{
$this_post_submitted = get_option(‘cr_post_2_pingfm_submit_post_submitted_’.$postId, false);
if(!$this_post_submitted)
{
$continue = true;
}
else
{
if("all" == $postMode)
{
$continue = true;
$republish = true;
}
}

if($continue)
{
$theCats = get_the_category($postId);
foreach($theCats as $cats)
{
$categories[] = $cats->cat_ID;
$categories[] = $cats->category_nicename;
}
$continue = isCategoriesAllowedToPing($postId, $categories);
}

if($continue)
{
update_option(‘cr_post_2_pingfm_submit_post_submitted_’.$postId, true);
submitPingFM($postId, $republish);
}
}
}

function cr_post_2_pingfm_submit_config_admin()
{
add_options_page(‘CR Post2Pingfm’, ‘CR Post2Pingfm’, 8, __FILE__, ‘cr_post_2_pingfm_submit_config_form’);
}

function cr_post_2_pingfm_submit_config_form() {
?>


CR Post2Pingfm


























Ping.fm Application Key
Ping Template

Template Tags: {title} for Post Title and {url} for Permalink URL
eg: I just post {title} on {url}
Ping mode
Allow submit new post to ping.fm:
For all categories (all)
For this categories (allow)
For categories except this one (deny)
Category list (category ID and slug is supported)
(comma separated, eg: 1,23,random-caregory,10,rants)
Category list is ignored if mode all is selected.
Publish mode
Allow submit to ping.fm on the following condition:
Only submit for the first time(once)
For everytime you push publish button(all)
Re-Publish template
This option only used if you choose all in publish mode.
Use Ping Template above
Use this template

The above template tags, apply.




$post->post_title,
‘{url}’ => get_permalink($postId),
);

foreach($arrTemplate as $template => $template_data)
{
$ping_template = str_replace($template, $template_data, $ping_template);
}

// error_log(date("c") . " – Ping template: ‘" . $ping_template . "’\n", 3, "/var/tmp/pingfm-" . date("Ymd") . ".log");

$result = $pfm->post("status", $ping_template);
}

function isCategoriesAllowedToPing($postId, $categories)
{
$pingMode = get_option(‘cl_post_pingfm_ping_mode’);
$pingCats = get_option(‘cl_post_pingfm_ping_mode_category’);
$pingCats = array_map("trim", explode(",", $pingCats));
if(!is_array($pingCats)) $pingCats = array();

if("allow" == $pingMode)
{
foreach($categories as $cats)
{
if(in_array($cats, $pingCats))
{
return true;
}
}
}
else if("deny" == $pingMode)
{
foreach($categories as $cats)
{
if(in_array($cats, $pingCats))
{
return false;
}
}
return true;
}
else
{
return true;
}
}
[/code]

CC BY 4.0 CR-Post2PingFM Plugin Tweaked for WordPress MU by Gwyneth Llewelyn is licensed under a Creative Commons Attribution 4.0 International License.

About Gwyneth Llewelyn

I'm just a virtual girl in a virtual world...

  • Well this plugin stopped working again many months ago. It seems like pingfm is closing everything.  I just delt with it and used manual posting thru the ping.fm website. then i found the hotsuite firefox button plugin. that was a little easier. Then I tried posting by sms and email, neither worked. the post by RSS didnt either. So now i am hard coding a addfilter(publish)with a mailto script for the sites but theres only a few sites that you can publish by email. sux ass

  • Hmm. The last time I’ve checked, it worked well five days ago. Note that I’m using the newest released version, where you can enter your own API key; I just keep this post around for historical reasons.

    But if you have problems with Ping.fm, you can try HelloTxt.com instead — they provide a similar service and there are plenty of plugins for it as well 🙂