ID, 'twipub_oauth_token', $_GET['twipub_oauth_token']);
update_usermeta($profileuser->ID, 'twipub_oauth_token_secret', $_GET['twipub_oauth_token_secret']);
update_usermeta($profileuser->ID, 'twipub_screen_name', $_GET['twipub_screen_name']);
update_usermeta($profileuser->ID, 'twitter_username', $_GET['twipub_screen_name']);
header('Location: /wp-admin/profile.php?updated=true');
exit;
}
echo '
'. screen_icon() .'
'.__('Twitter Publisher Settings', 'twitter_publisher').'
';
if(!empty($_POST)) {
echo '
'.__('Settings saved', 'twitter_publisher').'
';
}
echo '
'.__('Do not forget to have your authors enter their Twitter name in their profiles. Otherwise their Wordpress display name will be mentioned in the tweets.', 'twitter_publisher').'
';
}
function twitter_publisher_custom_box() {
global $post;
$options = get_option('twitter_publisher_options');
//get blog post title
$title = $post->post_title;
//get author
$author = get_userdata($post->post_author);
//get permalink
$permalink = get_permalink($post->ID);
//generate short url
$post_url = twitter_publisher_create_short_url($permalink, 'twitter', 'twitter-publisher-main');
//check if twitter name has been filled in
if(!empty($author->twitter_username)) {
$author_name = '@'.$author->twitter_username;
} else {
//use display name instead
$author_name = $author->display_name;
}
//concat the meta data of the tweet (= tweet without the title) when option is checked to add author's name
if($options['twitter_incl_author'] == 1) {
$tweet_meta = ' '. $post_url .' by '. $author_name;
} else {
//just concat the URL instead
$tweet_meta = ' '. $post_url;
}
//get the Tweet prefix from the settings (if there is one)
$tweet_prefix = $options['title_prefix'];
if(!empty($tweet_prefix)) {
$tweet_prefix .= ' ';
}
//get the Tweet suffix from the settings (if there is one)
$tweet_suffix = $options['title_suffix'];
if(!empty($tweet_suffix)) {
$tweet_suffix = ' '. $tweet_suffix;
}
//if title + meta > 140 chars, shorten the title
if(strlen($title) + strlen($tweet_meta) + strlen($tweet_prefix) + strlen($tweet_suffix) > 140) {
if($options['drop_suffix'] == 1) {
$tweet_suffix = '';
}
$title = substr($title, 0, 140-(strlen($tweet_prefix) + strlen($tweet_meta) + strlen($tweet_suffix) + 3)). '...';
}
//now concatinate the tweet
$tweet = $tweet_prefix . $title . $tweet_meta . $tweet_suffix;
if( $post->post_status == 'publish') {
echo '
';
//now call do_action for plugins which are using Post Play
do_action('postplay_add_content');
} else {
echo '
';
}
}
function twitter_publisher_add_meta_box_wrapper() {
$options = get_option('twitter_publisher_options');
if($options['manual_tweeting'] == 1) {
add_meta_box('twitter_publisher_box_id', 'Twitter Publisher', 'twitter_publisher_custom_box', 'post', 'side', 'high');
}
}
add_action('admin_menu', 'twitter_publisher_add_meta_box_wrapper');
function twitter_publisher_js_admin_header() {
// use JavaScript SACK library for Ajax
//wp_print_scripts( array( 'sack' ));
// Define custom JavaScript function
?>
0)
$delimiter = '&';
$permalink .= urlencode( $delimiter . 'utm_source='.$sharetype.'&utm_medium='.$createtype.'&utm_campaign='.$sharetype);
}
//generate bit.ly url
$snoop = new Snoopy();
$snoop->agent = 'Twitter Publisher';
$snoop->fetch('http://api.bit.ly/shorten?'.
'version=2.0.1&'.
'longUrl='.$permalink.'&'.
'login='.$options['bitly_apilogin'].'&'.
'apiKey='.$options['bitly_apikey'].'&'.
'format=xml&'.
'history=1'
);
if (strpos($snoop->response_code, '200')) {
//get shortUrl from XML, without the use of a XML parser
$post_url_match = null;
preg_match('|
(.*?)|is', $snoop->results, $post_url_match);
$post_url = trim($post_url_match[1]);
return $post_url;
} else {
return $permalink;
}
} else {
//use awe.sm
//get awe.sm API key
$awesm_api_key = $options['awesm_apikey'];
//only continue when API key is set
if(empty($awesm_api_key)) {
return $permalink;
}
// generate main awe.sm url
$snoop = new Snoopy();
$snoop->agent = 'Twitter Publisher';
$snoop->submit(
'http://create.awe.sm/url.txt',
array(
'target' => $permalink,
'version' => 1,
'share_type' => $sharetype,
'create_type' => $createtype,
'api_key' => $awesm_api_key
)
);
if (strpos($snoop->response_code, '200')) {
$post_url = trim($snoop->results);
return $post_url;
} else {
return $permalink;
}
}
}
/**
* returns the short url for this post
*
* @param int $post_id
* @return string
*/
function twitter_publisher_short_url($post_id) {
//get post_url
$short_url = get_post_meta($post_id, 'twipub_short_url', true);
//is there already a short url?
if(empty($short_url)) {
//get permalink
$permalink = get_permalink($post_id);
//generate short url
$short_url = twitter_publisher_create_short_url($permalink, 'other', 'twitter-publisher-other');
//save short url
add_post_meta($post_id, 'twipub_short_url', $short_url, true);
}
return $short_url;
}
/**
* Adds a link to the menu in Wordpress' admin
*/
function twitter_publisher_configpagelink() {
add_options_page('Twitter Publisher', 'Twitter Publisher', 8, basename(__FILE__), 'twitter_publisher_configpage');
}
add_action('admin_menu', 'twitter_publisher_configpagelink');
/**
* Adds a settings link to the plugin description row
*/
function twitter_publisher_filter_plugin_actions($links, $file) {
//Static so we don't call plugin_basename on every plugin row.
static $this_plugin;
if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
if ( $file == $this_plugin ){
$settings_link = '
' . __('Settings', 'twitter_publisher') . '';
array_unshift( $links, $settings_link ); // before other links
}
return $links;
}
add_filter( 'plugin_action_links', 'twitter_publisher_filter_plugin_actions', 10, 2 );