[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 | |
---|
[19395] | 30 | // urls and position |
---|
[11463] | 31 | if (script_basename() == 'picture') |
---|
| 32 | { |
---|
[19395] | 33 | $template->assign('TWEET_URL', get_absolute_root_url().ltrim(duplicate_picture_url(), './')); |
---|
[11463] | 34 | } |
---|
| 35 | else if (script_basename() == 'index') |
---|
| 36 | { |
---|
[16309] | 37 | $conf['TweetThis']['position'] = 'index'; |
---|
[19395] | 38 | $template->assign('TWEET_URL', get_absolute_root_url().ltrim(duplicate_index_url(array(), array('start')), './')); |
---|
[11463] | 39 | } |
---|
[19395] | 40 | else |
---|
| 41 | { |
---|
| 42 | return; |
---|
| 43 | } |
---|
[11514] | 44 | |
---|
[16309] | 45 | // config |
---|
| 46 | $template->assign(array( |
---|
| 47 | 'TWEET_POSITION' => $conf['TweetThis']['position'], |
---|
| 48 | 'TWEET_SIZE' => $conf['TweetThis']['size'], |
---|
| 49 | 'TWEET_COUNT' => $conf['TweetThis']['count'], |
---|
| 50 | 'TWEET_VIA' => $conf['TweetThis']['via'], |
---|
| 51 | )); |
---|
| 52 | |
---|
[15122] | 53 | // button language |
---|
| 54 | if ( in_array(str_replace('_','-',strtolower($user['language'])), $conf['TweetThis']['lang']) ) |
---|
[11514] | 55 | { |
---|
[15122] | 56 | $template->assign('TWEET_LANG', str_replace('_','-',strtolower($user['language']))); |
---|
[11514] | 57 | } |
---|
[15122] | 58 | if ( in_array(substr($user['language'],0,2), $conf['TweetThis']['lang']) ) |
---|
[11514] | 59 | { |
---|
[15122] | 60 | $template->assign('TWEET_LANG', substr($user['language'],0,2)); |
---|
[11514] | 61 | } |
---|
[15122] | 62 | else |
---|
[11514] | 63 | { |
---|
[15122] | 64 | $template->assign('TWEET_LANG', 'en'); |
---|
[11514] | 65 | } |
---|
[16309] | 66 | |
---|
| 67 | |
---|
| 68 | $template->set_filename('tweet_button', dirname(__FILE__).'/button.tpl'); |
---|
| 69 | $button = $template->parse('tweet_button', true); |
---|
| 70 | |
---|
| 71 | switch ($conf['TweetThis']['position']) |
---|
| 72 | { |
---|
| 73 | case 'index': |
---|
[19362] | 74 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
[16309] | 75 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
| 76 | break; |
---|
| 77 | case 'toolbar': |
---|
[19362] | 78 | // $template->add_picture_button($button, 100); |
---|
[16309] | 79 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
| 80 | break; |
---|
| 81 | default; |
---|
| 82 | $template->assign('TWEET_BUTTON', $button); |
---|
| 83 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
| 84 | } |
---|
[11419] | 85 | } |
---|
| 86 | |
---|
| 87 | function tweet_add_button_prefilter($content, &$smarty) |
---|
| 88 | { |
---|
| 89 | global $template; |
---|
| 90 | |
---|
[19362] | 91 | switch ($template->get_template_vars('TWEET_POSITION')) |
---|
[11419] | 92 | { |
---|
| 93 | case 'top': |
---|
| 94 | $search = '<div id="theImage">'; |
---|
[16309] | 95 | $replace = '<div>{$TWEET_BUTTON}</div>'; |
---|
[11419] | 96 | break; |
---|
| 97 | |
---|
| 98 | case 'bottom': |
---|
| 99 | $search = '{$ELEMENT_CONTENT}'; |
---|
[16309] | 100 | $replace = '{$TWEET_BUTTON}'; |
---|
[11419] | 101 | break; |
---|
| 102 | } |
---|
| 103 | |
---|
[15122] | 104 | return str_replace($search, $search.$replace, $content); |
---|
[11419] | 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | if (script_basename() == 'admin') |
---|
| 109 | { |
---|
| 110 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
| 111 | |
---|
| 112 | function tweet_plugin_admin_menu($menu) |
---|
| 113 | { |
---|
[15122] | 114 | array_push($menu, array( |
---|
| 115 | 'NAME' => 'TweetThis', |
---|
| 116 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
| 117 | )); |
---|
[11419] | 118 | return $menu; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | ?> |
---|