[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 | |
---|
[20362] | 19 | add_event_handler('loc_begin_admin_page', 'tweet_depreciated'); |
---|
[11419] | 20 | |
---|
[20361] | 21 | function tweet_depreciated() |
---|
| 22 | { |
---|
| 23 | global $page; |
---|
| 24 | $page['warnings'][] = 'TweetThis is depreciated, please use <a href="http://piwigo.org/ext/extension_view.php?eid=673">Social Buttons</a> instead.'; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | |
---|
[11419] | 28 | function tweet_add_button() |
---|
| 29 | { |
---|
[15122] | 30 | global $conf, $template, $user; |
---|
[11419] | 31 | |
---|
[15122] | 32 | $conf['TweetThis'] = unserialize($conf['TweetThis']); |
---|
| 33 | $conf['TweetThis']['lang'] = array( |
---|
| 34 | 'no','de','zh-cn','en','pl','sv','zh-tw','tr','es','th','fa','hu','pt','it','ar','he', |
---|
| 35 | 'ko','id','ru','ja','da','fi','hi','ur','fr','nl', |
---|
| 36 | ); |
---|
| 37 | |
---|
[19395] | 38 | // urls and position |
---|
[11463] | 39 | if (script_basename() == 'picture') |
---|
| 40 | { |
---|
[19395] | 41 | $template->assign('TWEET_URL', get_absolute_root_url().ltrim(duplicate_picture_url(), './')); |
---|
[11463] | 42 | } |
---|
| 43 | else if (script_basename() == 'index') |
---|
| 44 | { |
---|
[16309] | 45 | $conf['TweetThis']['position'] = 'index'; |
---|
[19395] | 46 | $template->assign('TWEET_URL', get_absolute_root_url().ltrim(duplicate_index_url(array(), array('start')), './')); |
---|
[11463] | 47 | } |
---|
[19395] | 48 | else |
---|
| 49 | { |
---|
| 50 | return; |
---|
| 51 | } |
---|
[11514] | 52 | |
---|
[16309] | 53 | // config |
---|
| 54 | $template->assign(array( |
---|
| 55 | 'TWEET_POSITION' => $conf['TweetThis']['position'], |
---|
| 56 | 'TWEET_SIZE' => $conf['TweetThis']['size'], |
---|
| 57 | 'TWEET_COUNT' => $conf['TweetThis']['count'], |
---|
| 58 | 'TWEET_VIA' => $conf['TweetThis']['via'], |
---|
| 59 | )); |
---|
| 60 | |
---|
[15122] | 61 | // button language |
---|
| 62 | if ( in_array(str_replace('_','-',strtolower($user['language'])), $conf['TweetThis']['lang']) ) |
---|
[11514] | 63 | { |
---|
[15122] | 64 | $template->assign('TWEET_LANG', str_replace('_','-',strtolower($user['language']))); |
---|
[11514] | 65 | } |
---|
[15122] | 66 | if ( in_array(substr($user['language'],0,2), $conf['TweetThis']['lang']) ) |
---|
[11514] | 67 | { |
---|
[15122] | 68 | $template->assign('TWEET_LANG', substr($user['language'],0,2)); |
---|
[11514] | 69 | } |
---|
[15122] | 70 | else |
---|
[11514] | 71 | { |
---|
[15122] | 72 | $template->assign('TWEET_LANG', 'en'); |
---|
[11514] | 73 | } |
---|
[16309] | 74 | |
---|
| 75 | |
---|
| 76 | $template->set_filename('tweet_button', dirname(__FILE__).'/button.tpl'); |
---|
| 77 | $button = $template->parse('tweet_button', true); |
---|
| 78 | |
---|
| 79 | switch ($conf['TweetThis']['position']) |
---|
| 80 | { |
---|
| 81 | case 'index': |
---|
[19362] | 82 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
[16309] | 83 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
| 84 | break; |
---|
| 85 | case 'toolbar': |
---|
[19362] | 86 | // $template->add_picture_button($button, 100); |
---|
[16309] | 87 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
| 88 | break; |
---|
| 89 | default; |
---|
| 90 | $template->assign('TWEET_BUTTON', $button); |
---|
| 91 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
| 92 | } |
---|
[11419] | 93 | } |
---|
| 94 | |
---|
| 95 | function tweet_add_button_prefilter($content, &$smarty) |
---|
| 96 | { |
---|
| 97 | global $template; |
---|
| 98 | |
---|
[19362] | 99 | switch ($template->get_template_vars('TWEET_POSITION')) |
---|
[11419] | 100 | { |
---|
| 101 | case 'top': |
---|
| 102 | $search = '<div id="theImage">'; |
---|
[16309] | 103 | $replace = '<div>{$TWEET_BUTTON}</div>'; |
---|
[11419] | 104 | break; |
---|
| 105 | |
---|
| 106 | case 'bottom': |
---|
| 107 | $search = '{$ELEMENT_CONTENT}'; |
---|
[16309] | 108 | $replace = '{$TWEET_BUTTON}'; |
---|
[11419] | 109 | break; |
---|
| 110 | } |
---|
| 111 | |
---|
[15122] | 112 | return str_replace($search, $search.$replace, $content); |
---|
[11419] | 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | if (script_basename() == 'admin') |
---|
| 117 | { |
---|
| 118 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
| 119 | |
---|
| 120 | function tweet_plugin_admin_menu($menu) |
---|
| 121 | { |
---|
[15122] | 122 | array_push($menu, array( |
---|
| 123 | 'NAME' => 'TweetThis', |
---|
| 124 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
| 125 | )); |
---|
[11419] | 126 | return $menu; |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | ?> |
---|