[11419] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: TweetThis |
---|
| 4 | Version: auto |
---|
| 5 | Description: Add a "Tweet This" button on picture pages |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=560 |
---|
| 7 | Author: Mistic |
---|
| 8 | Author URI: http://www.strangeplanet.fr |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | define('TWEET_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
| 14 | |
---|
| 15 | load_language('plugin.lang', TWEET_PATH); |
---|
| 16 | add_event_handler('loc_end_picture', 'tweet_add_button'); |
---|
[11463] | 17 | add_event_handler('loc_end_index', 'tweet_add_button'); |
---|
[11419] | 18 | |
---|
| 19 | |
---|
| 20 | function tweet_add_button() |
---|
| 21 | { |
---|
[15122] | 22 | global $conf, $template, $user; |
---|
[11419] | 23 | |
---|
[15122] | 24 | $conf['TweetThis'] = unserialize($conf['TweetThis']); |
---|
| 25 | $conf['TweetThis']['lang'] = array( |
---|
| 26 | 'no','de','zh-cn','en','pl','sv','zh-tw','tr','es','th','fa','hu','pt','it','ar','he', |
---|
| 27 | 'ko','id','ru','ja','da','fi','hi','ur','fr','nl', |
---|
| 28 | ); |
---|
| 29 | |
---|
| 30 | $template->assign(array( |
---|
| 31 | 'TWEET_SIZE' => $conf['TweetThis']['size'], |
---|
| 32 | 'TWEET_COUNT' => $conf['TweetThis']['count'], |
---|
| 33 | 'TWEET_VIA' => $conf['TweetThis']['via'], |
---|
| 34 | )); |
---|
| 35 | |
---|
[11463] | 36 | if (script_basename() == 'picture') |
---|
| 37 | { |
---|
[15122] | 38 | $template->assign('TWEET_POSITON', $conf['TweetThis']['position']); |
---|
[11463] | 39 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
| 40 | } |
---|
| 41 | else if (script_basename() == 'index') |
---|
| 42 | { |
---|
[15122] | 43 | $template->assign('TWEET_POSITON', 'index'); |
---|
[11463] | 44 | $template->set_prefilter('index', 'tweet_add_button_prefilter'); |
---|
| 45 | } |
---|
[11514] | 46 | |
---|
[15122] | 47 | // button language |
---|
| 48 | if ( in_array(str_replace('_','-',strtolower($user['language'])), $conf['TweetThis']['lang']) ) |
---|
[11514] | 49 | { |
---|
[15122] | 50 | $template->assign('TWEET_LANG', str_replace('_','-',strtolower($user['language']))); |
---|
[11514] | 51 | } |
---|
[15122] | 52 | if ( in_array(substr($user['language'],0,2), $conf['TweetThis']['lang']) ) |
---|
[11514] | 53 | { |
---|
[15122] | 54 | $template->assign('TWEET_LANG', substr($user['language'],0,2)); |
---|
[11514] | 55 | } |
---|
[15122] | 56 | else |
---|
[11514] | 57 | { |
---|
[15122] | 58 | $template->assign('TWEET_LANG', 'en'); |
---|
[11514] | 59 | } |
---|
[11419] | 60 | } |
---|
| 61 | |
---|
| 62 | function tweet_add_button_prefilter($content, &$smarty) |
---|
| 63 | { |
---|
| 64 | global $template; |
---|
| 65 | |
---|
[15122] | 66 | $replace = '{combine_script id=\'twitter_widgets\' path=\'http://platform.twitter.com/widgets.js} |
---|
| 67 | <a href="https://twitter.com/share" class="twitter-share-button" data-lang="{$TWEET_LANG}" {if not empty($TWEET_VIA)}data-via="{$TWEET_VIA}"{/if} {if $TWEET_SIZE=="large"}data-size="large"{/if} {if not $TWEET_COUNT}data-count="none"{/if}>Tweet</a>'; |
---|
| 68 | |
---|
[11419] | 69 | switch ($template->get_template_vars('TWEET_POSITON')) |
---|
| 70 | { |
---|
| 71 | case 'top': |
---|
| 72 | $search = '<div id="theImage">'; |
---|
[15122] | 73 | $replace = '<div>'.$replace.'</div>'; |
---|
[11419] | 74 | break; |
---|
| 75 | |
---|
| 76 | case 'bottom': |
---|
| 77 | $search = '{$ELEMENT_CONTENT}'; |
---|
| 78 | break; |
---|
| 79 | |
---|
| 80 | case 'toolbar': |
---|
[15122] | 81 | $search = '<div class="actionButtons">'; |
---|
[11419] | 82 | break; |
---|
[11463] | 83 | |
---|
[11514] | 84 | case 'index': |
---|
[11463] | 85 | $search = '<ul class="categoryActions">'; |
---|
[15122] | 86 | $replace = '<li>'.$replace.'</li>'; |
---|
[11463] | 87 | break; |
---|
[11419] | 88 | } |
---|
| 89 | |
---|
[15122] | 90 | return str_replace($search, $search.$replace, $content); |
---|
[11419] | 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | if (script_basename() == 'admin') |
---|
| 95 | { |
---|
| 96 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
| 97 | |
---|
| 98 | function tweet_plugin_admin_menu($menu) |
---|
| 99 | { |
---|
[15122] | 100 | array_push($menu, array( |
---|
| 101 | 'NAME' => 'TweetThis', |
---|
| 102 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
| 103 | )); |
---|
[11419] | 104 | return $menu; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | ?> |
---|