status updates to Ping.fm or Twitter everytime you publish a post. Using Bit.ly or Tr.im for the permalinks (accounts for these services required).
Author: Samuel Aguilera
Version: 1.1.1
Author URI: http://www.samuelaguilera.com
*/
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
/*
Originally based on WordTwit 1.2 by Duane Storey.
PingFM function based on one by Sold Out Activistclass for the pingPressFM plugin, and Bit.ly function by David Walsh & Jason Lengstorf.
HISTORY:
1.0 - Initial release.
1.0.1 - Fixed a typo and Ping.fm developer approved.
1.0.2 - Replaced PHPingFM by Dmitri Gaskin for a single function based on the one by Sold Out Activist for the pingPressFM.
- Removed 'includes' directory (now only one function for each service) and merged functions into shorten2ping.php file.
1.1 - Store settings in an array to reduce calls to database.
- Some other minor improvements/cleanup in the code.
- Added support for http://tr.im.
- Added support for Twitter.
- Added options for choose shorten and notification services, and to turn off them (so you can use Shorten2Ping only for notification if your
domain is already short enough for you, or use Shorten2Ping only to get shortened urls for your posts).
1.1.1 - Changed action hook. Now the ping function is called only when post changed status from X to publish (where X can be new, draft, pending or future).
So now, if you edit an old post (that you published before installing Shorten2Ping) this plugin does nothing.
*/
// setting some internal information
$shorten2ping_plugin_prefix = 'shorten2ping_';
$shorten2ping_dirname = plugin_basename(dirname(__FILE__));
//load translation file if any for the current language
load_plugin_textdomain('shorten2ping', PLUGINDIR . '/' . $shorten2ping_dirname . '/locale');
// simple function to use in your theme if you want to show the short url for the current post
function short_permalink() {
global $post;
$short_permalink = get_post_meta($post->ID, 'short_url', 'true');
// Using rel="shorturl" as proposed at http://wiki.snaplog.com/short_url
if (!empty($short_permalink)) echo "post_title\">" . __('Short URL','shorten2ping') . "";
}
function short_url_head() {
global $post;
$short_permalink = get_post_meta($post->ID, 'short_url', 'true');
if (is_single($post->ID) && !empty($short_permalink)) {
echo "\n";
echo "\n";
}
}
function shorten2ping_published_post($post)
{
global $shorten2ping_plugin_prefix;
$post_id = $post->ID;
$s2p_options = get_option($shorten2ping_plugin_prefix . 'options');
$post_url = get_permalink($post_id);
$post_title = get_the_title($post_id);
$has_been_pinged = get_post_meta($post_id, 'pinged', true);
$short_url_exists = get_post_meta($post_id, 'short_url', true);
if (!($has_been_pinged == 'yes')) {
if (empty($short_url_exists)) {
if ($s2p_options['shorten_service'] == 'bitly') {
//acortamos la url del post con bit.ly
$bitly_user = $s2p_options['bitly_user'];
$bitly_key = $s2p_options['bitly_key'];
$short_url = make_bitly_url($post_id,$post_url,$bitly_user,$bitly_key);
} elseif ($s2p_options['shorten_service'] == 'trim') {
$trim_user = $s2p_options['trim_user'];
$trim_pass = $s2p_options['trim_pass'];
$short_url = make_trim($post_id,$post_url,$trim_user,$trim_pass);
} elseif ($s2p_options['shorten_service'] == 'none') {
$short_url = $post_url;
}
} else {
$short_url = $short_url_exists;
}
//get message from settings and process title and link
$message = $s2p_options['message'];
$message = str_replace('[title]', $post_title, $message);
$message = str_replace('[link]', $short_url, $message);
if ($s2p_options['ping_service'] == 'pingfm'){
$pingfm_user_key = $s2p_options['pingfm_key'];
$post_data = Array(
'api_key' => '6f604abd220a79bcd443a4824354734d',
'user_app_key' => $pingfm_user_key,
'post_method' => 'status',
'body' => $message,
// 'debug' => 1
);
send_pingfm($post_id,$post_data);
} elseif ($s2p_options['ping_service'] == 'twitter') {
send_twit($post_id,$s2p_options['twitter_user'], $s2p_options['twitter_pass'], $message);
} elseif ($s2p_options['ping_service'] == 'none') {
return;
}
}
}
function s2p_bnc_stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('s2p_bnc_stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
function s2c_init_options() {
// create options array. if options already exists add_option function does nothing.
$s2p_options['message'] = "New Blog Entry, \"[title]\" - [link]";
$s2p_options['ping_service'] = "pingfm";
$s2p_options['pingfm_key'] = "";
$s2p_options['twitter_user'] = "";
$s2p_options['twitter_pass'] = "";
$s2p_options['shorten_service'] = "bitly";
$s2p_options['bitly_user'] = "";
$s2p_options['bitly_key'] = "";
$s2p_options['trim_user'] = "";
$s2p_options['trim_pass'] = "";
// check if old options exists and update to the new system
foreach( $s2p_options as $key => $value ) {
if($existing = get_option('shorten2ping_'. $key)) {
$s2p_options[$key] = $existing;
delete_option('shorten2ping_' . $key);
}
}
add_option('shorten2ping_options', $s2p_options );
}
function shorten2ping_options_subpanel()
{
global $shorten2ping_plugin_prefix;
$s2p_options = get_option($shorten2ping_plugin_prefix . 'options');
if (get_magic_quotes_gpc()) {
$_POST = array_map('s2p_bnc_stripslashes_deep', $_POST);
$_GET = array_map('s2p_bnc_stripslashes_deep', $_GET);
$_COOKIE = array_map('s2p_bnc_stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('s2p_bnc_stripslashes_deep', $_REQUEST);
}
if (isset($_POST['info_update']))
{
foreach( $s2p_options as $key => $value ) {
if(isset($_POST[$key])) {
if ($_POST[$key] == $_POST['message']) {
$s2p_options[$key] = stripslashes($_POST['message']);
} else {
$s2p_options[$key] = $_POST[$key];
}
} else {
$s2p_options[$key] = '';
}
}
update_option( $shorten2ping_plugin_prefix . 'options', $s2p_options );
echo '