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() {
?>
<div class="wrap">
<h2>CR Post2Pingfm</h2>
<form action="options.php" method="post">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">Ping.fm Application Key</th>
<td>
<input name="cr_post_2_pingfm_options[cl_post_pingfm_api_key]" size="45" type="text" value="<?php echo $options[‘cl_post_pingfm_api_key’]; ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Ping Template</th>
<td>
<input name="cr_post_2_pingfm_options[cl_post_pingfm_message_template]" size="45" type="text" value="<?php echo ($options[‘cl_post_pingfm_message_template’] ? $options[‘cl_post_pingfm_message_template’] : ‘I just post {title} on {url}’); ?>" />
Template Tags: <strong>{title}</strong> for <em>Post Title</em> and <strong>{url}</strong> for <em>Permalink URL</em>
eg: <em>I just post {title} on {url}</em></td>
</tr>
<tr valign="top">
<th scope="row">Ping mode</th>
<td>
Allow submit new post to ping.fm:
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode]" type="radio" value="all" />For all categories (<em>all</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode]" type="radio" value="allow" />For this categories (<em>allow</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode]" type="radio" value="deny" />For categories except this one (<em>deny</em>)
Category list (<em>category ID and slug is supported</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_mode_category]" type="text" value="<?php echo $options[‘cl_post_pingfm_ping_mode_category’]; ?>" />(comma separated, eg: <em>1,23,random-caregory,10,rants</em>)
Category list is ignored if mode <em>all</em> is selected.</td>
</tr>
<tr valign="top">
<th>Publish mode</th>
<td>
Allow submit to ping.fm on the following condition:
<input name="cr_post_2_pingfm_options[cl_post_pingfm_publish_mode]" type="radio" value="once" />Only submit for the <strong>first time</strong>(<em>once</em>)
<input name="cr_post_2_pingfm_options[cl_post_pingfm_publish_mode]" type="radio" value="all" />For everytime you push <strong>publish</strong> button(<em>all</em>)</td>
</tr>
<tr valign="top">
<th>Re-Publish template</th>
<td>
This option only used if you choose <em>all</em> in <strong>publish mode</strong>.
<input name="cr_post_2_pingfm_options[cl_post_pingfm_republish_template]" type="radio" value="above" />Use Ping Template above
<input name="cr_post_2_pingfm_options[cl_post_pingfm_republish_template]" type="radio" value="this" />Use this template
<input name="cr_post_2_pingfm_options[cl_post_pingfm_ping_republish_template_text]" size="45" type="text" value="<?php echo ($options[‘cl_post_pingfm_ping_republish_template_text’] ? $options[‘cl_post_pingfm_ping_republish_template_text’] : ‘republished {title} on {url}’); ?>" />
The above template tags, apply.</td>
</tr>
</tbody>
</table>
<input name="action" type="hidden" value="update" />
<input name="page_options" type="hidden" value="cl_post_pingfm_message_template,cl_post_pingfm_api_key,cl_post_pingfm_ping_mode_category,cl_post_pingfm_ping_mode,cl_post_pingfm_publish_mode,cl_post_pingfm_ping_republish_template_text,cl_post_pingfm_republish_template" />

<input class="button-primary" type="submit" value="<?php _e(‘Save Changes’) ?>" />
</form></div>
$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]

Print Friendly, PDF & Email

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 🙂