Instantly share code, notes, and snippets.
Created
April 30, 2013 01:30
-
Save bryceac/5486091 to your computer and use it in GitHub Desktop.
Add Tumblr support to Socialink Habari plugin. Code is based on Stuchl4n3k's script that includes the Google+ plus one button.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Socialink | |
* adding Social Bookmark Links to your posts. | |
* | |
* @package socialink | |
* @version $Id: socialink.plugin.php 3194 2010-06-13 05:30:15Z philip $ | |
* @author ayunyan <ayu@commun.jp> | |
* @author rickc (@535) | |
* @author dmondark (@582) | |
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | |
* @link http://ayu.commun.jp/habari-socialink | |
*/ | |
class Socialink extends Plugin | |
{ | |
var $services = array( | |
// Global | |
'email' => array('name' => 'Email', 'url' => 'mailto:?subject=%TITLE%&body=%PERMALINK%'), | |
'digg' => array('name' => 'Digg', 'url' => 'http://digg.com/submit?phase=2&url=%PERMALINK%'), | |
'delicious' => array('name' => 'delicious', 'url' => 'http://delicious.com/save?url=%PERMALINK%&title=%TITLE%&v=5&jump=yes'), | |
'technorati' => array('name' => 'Technorati', 'url' => 'http://technorati.com/faves?add=%PERMALINK%'), | |
'google' => array('name' => 'Google', 'url' => "javascript:(function(){var a=window,b=document,c=encodeURIComponent,d=a.open('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=%PERMALINK%&title=%TITLE%','bkmk_popup','left='+((a.screenX||a.screenLeft)+10)+',top='+((a.screenY||a.screenTop)+10)+',height=420px,width=550px,resizable=1,alwaysRaised=1');a.setTimeout(function(){d.focus()},300)})();"), | |
'google+' => array('name' => 'Google+', 'url' => 'javascript:void(0);'), | |
'yahoo' => array('name' => 'Yahoo! My Web 2.0', 'url' => 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=%PERMALINK%&t=%TITLE%'), | |
'furl' => array('name' => 'furl', 'url' => 'http://www.furl.net/storeIt.jsp?u=%PERMALINK%'), | |
'reddit' => array('name' => 'Reddit', 'url' => 'http://reddit.com/submit?url=%PERMALINK%&title=%PERMALINK%'), | |
'magnolia' => array('name' => 'Ma.gnolia', 'url' => 'http://ma.gnolia.com/bookmarklet/add?url=%PERMALINK%&title=%TITLE%'), | |
'faves' => array('name' => 'Faves', 'url' => 'http://faves.com/Authoring.aspx?u=%PERMALINK%&t=%TITLE%'), | |
'blinklist' => array('name' => 'blinklist', 'url' => 'http://www.blinklist.com/?Action=Blink/addblink.php&Description=&Url=%PERMALINK%&Title=%TITLE%'), | |
'stumbleupon' => array( 'name' => 'StumbleUpon', 'url'=> 'http://www.stumbleupon.com/submit?url=%PERMALINK%&title=%TITLE%'), | |
'diigo' => array( 'name' => 'Diigo', 'url'=> 'hhttp://www.diigo.com/post?url=%PERMALINK%&title=%TITLE%'), | |
'facebook' => array('name' => 'Facebook', 'url' => 'http://www.facebook.com/share.php?u=%PERMALINK%'), | |
'tumblr' => array('name' => 'Tumblr', 'url' => 'http://www.tumblr.com/share/link?url=%PERMALINK%&name=%TITLE%'), | |
// Japan | |
'hatena' => array('name' => 'Hatena Bookmark', 'url' => "javascript:(function(){window.open('http://b.hatena.ne.jp/add?mode=confirm&is_bm=1&title=%TITLE%&url=%PERMALINK%','socialink','width=550,height=600,resizable=1,scrollbars=1');})();"), | |
'yahoojbookmarks' => array('name' => 'Yahoo! JAPAN Bookmarks', 'url' => "javascript:(function(){window.open('http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t=%TITLE%&u=%PERMALINK%&opener=bm&ei=UTF-8','socialink','width=550px,height=480px,status=1,location=0,resizable=1,scrollbars=0,left=100,top=50',0);})();"), | |
'topicit' => array('name' => 'TopicIT@nifty', 'url' => "javascript:(function(){window.open('http://topic.nifty.com/up/add?mode=2&topic_title=%TITLE%&topic_url=%PERMALINK%');})();"), | |
'buzzurl' => array('name' => 'Buzzurl', 'url' => 'http://buzzurl.jp/entry/%PERMALINK%'), | |
'choix' => array('name' => 'Choix', 'url' => 'http://www.choix.jp/bloglink/%PERMALINK%'), | |
'newsing' => array('name' => 'newsing', 'url' => 'http://newsing.jp/add?url=%PERMALINK%&title=%TITLE%'), | |
'livedoorclip' => array('name' => 'livedoor Clip', 'url' => 'http://clip.livedoor.com/redirect?link=%PERMALINK%&title=%TITLE%&ie=utf-8'), | |
'pookmark' => array('name' => 'POOKMARK Airlines', 'url' => 'http://pookmark.jp/post?url=%PERMALINK%&title=%TITLE%'), | |
'goobookmark' => array('name' => 'goo Bookmark', 'url' => 'http://bookmark.goo.ne.jp/add/detail/?url=%PERMALINK%'), | |
); | |
/** | |
* action: plugin_activation | |
* | |
* @access public | |
* @param string $file | |
* @return void | |
*/ | |
public function action_plugin_activation($file) | |
{ | |
if ( Plugins::id_from_file( $file ) != Plugins::id_from_file( __FILE__ ) ) return; | |
Options::set( 'socialink__link_pos', 'top' ); | |
Options::set( 'socialink__services', serialize( array( 'digg', 'delicious', 'technorati', 'google', 'yahoo', 'furl', 'reddit', 'magnolia' ) ) ); | |
} | |
/** | |
* action: update_check | |
* | |
* @access public | |
* @return void | |
*/ | |
public function action_update_check() | |
{ | |
Update::add( 'Socialink', '58c939f3-26ae-11dd-b5d6-001b210f913f', $this->info->version ); | |
} | |
/** | |
* action: plugin_ui | |
* | |
* @access public | |
* @param string $plugin_id | |
* @param string $action | |
* @return void | |
*/ | |
public function action_plugin_ui( $plugin_id, $action ) | |
{ | |
if ( $plugin_id != $this->plugin_id() ) return; | |
if ( $action == _t( 'Configure' ) ) { | |
$ui_services = array(); | |
foreach ($this->services as $k => $service) { | |
$ui_services[$k] = $service['name']; | |
} | |
$ui = new FormUI( strtolower( get_class( $this ) ) ); | |
$link_pos = $ui->append( 'radio', 'link_pos', 'option:socialink__link_pos', _t( 'Auto Insert: ' ) ); | |
$link_pos->options = array('none' => 'None', 'top' => 'Top', 'bottom' => 'Bottom'); | |
$services = $ui->append( 'select', 'services', 'option:socialink__services', _t( 'Services: ' ), $ui_services); | |
$services->options = $ui_services; | |
$services->multiple = true; | |
$ui->append( 'submit', 'save', _t( 'Save' ) ); | |
$ui->out(); | |
} | |
} | |
/** | |
* Add Google+ button js to the page header. | |
* | |
* @access public | |
* @param object $theme | |
* @return void | |
*/ | |
public function theme_header( $theme ) | |
{ | |
$s_services = Options::get( 'socialink__services' ); | |
$keys = array_keys($s_services); | |
if (in_array('google+', $keys)) { | |
// Add javascript into page footer if Google +1 button is enabled | |
Stack::add( 'template_footer_javascript', 'http://apis.google.com/js/plusone.js', 'plusone' ); | |
} | |
if (in_array('tumblr', $keys)) | |
{ | |
//Add javascript into page footer | |
Stack::add( 'template_footer_javascript', 'http://platform.tumblr.com/v1/share.js'); | |
} | |
} | |
/** | |
* filter: plugin_config | |
* | |
* @access public | |
* @return array | |
*/ | |
public function filter_plugin_config( $actions, $plugin_id ) | |
{ | |
if ( $plugin_id == $this->plugin_id() ) { | |
$actions[]= _t( 'Configure' ); | |
} | |
return $actions; | |
} | |
/** | |
* filter: post_content_out | |
* | |
* @access public | |
* @return string | |
*/ | |
public function filter_post_content_out($content, $post) | |
{ | |
$link_pos = Options::get('socialink__link_pos'); | |
if ($link_pos == 'top') { | |
$content = $this->create_link($post) . $content; | |
} elseif ($link_pos == 'bottom') { | |
$content = $content . $this->create_link($post); | |
} | |
return $content; | |
} | |
/** | |
* theme: show_socialink | |
* | |
* @access public | |
* @param object $theme | |
* @param object $post | |
* @return string | |
*/ | |
public function theme_show_socialink($theme, $post) | |
{ | |
return $this->create_link($post); | |
} | |
private function create_link($post) | |
{ | |
$link = '<div class="socialink">'; | |
$site_title = Options::get( 'title' ); | |
$s_services = Options::get( 'socialink__services' ); | |
@reset( $s_services ); | |
while ( list( , $k ) = @each( $s_services ) ) { | |
if ( !isset( $this->services[$k] ) ) continue; | |
$url = $this->services[$k]['url']; | |
$url = str_replace( '%PERMALINK%', urlencode( $post->permalink ), $url ); | |
$url = str_replace( '%TITLE%', urlencode( $site_title . ' - ' . $post->title_out ), $url ); | |
$target = ''; | |
if ( substr( $url, 0, 11 ) != 'javascript:' ) { | |
$target = ' target="_blank"'; | |
} | |
if ($k == 'google+') { | |
$link .= '<g:plusone size="medium" count="false"></g:plusone>'; | |
} else { | |
$link.= '<a href="' . $url .'"' . $target . ' title="Post to ' . $this->services[$k]['name'] . '" rel="nofollow"><img src="' . $this->get_url() .'/img/icon/' . $k . '.png" width="16" height="16" alt="Post to ' . $this->services[$k]['name'] . '" style="padding:0 3px" /></a>'; | |
} | |
} | |
$link.= '</div>'; | |
return $link; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment