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'); |
---|
17 | add_event_handler('loc_end_index', 'tweet_add_button'); |
---|
18 | |
---|
19 | |
---|
20 | function tweet_add_button() |
---|
21 | { |
---|
22 | global $conf, $template, $user; |
---|
23 | |
---|
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 | |
---|
36 | if (script_basename() == 'picture') |
---|
37 | { |
---|
38 | $template->assign('TWEET_POSITON', $conf['TweetThis']['position']); |
---|
39 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
40 | } |
---|
41 | else if (script_basename() == 'index') |
---|
42 | { |
---|
43 | $template->assign('TWEET_POSITON', 'index'); |
---|
44 | $template->set_prefilter('index', 'tweet_add_button_prefilter'); |
---|
45 | } |
---|
46 | |
---|
47 | // button language |
---|
48 | if ( in_array(str_replace('_','-',strtolower($user['language'])), $conf['TweetThis']['lang']) ) |
---|
49 | { |
---|
50 | $template->assign('TWEET_LANG', str_replace('_','-',strtolower($user['language']))); |
---|
51 | } |
---|
52 | if ( in_array(substr($user['language'],0,2), $conf['TweetThis']['lang']) ) |
---|
53 | { |
---|
54 | $template->assign('TWEET_LANG', substr($user['language'],0,2)); |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | $template->assign('TWEET_LANG', 'en'); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | function tweet_add_button_prefilter($content, &$smarty) |
---|
63 | { |
---|
64 | global $template; |
---|
65 | |
---|
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 | |
---|
69 | switch ($template->get_template_vars('TWEET_POSITON')) |
---|
70 | { |
---|
71 | case 'top': |
---|
72 | $search = '<div id="theImage">'; |
---|
73 | $replace = '<div>'.$replace.'</div>'; |
---|
74 | break; |
---|
75 | |
---|
76 | case 'bottom': |
---|
77 | $search = '{$ELEMENT_CONTENT}'; |
---|
78 | break; |
---|
79 | |
---|
80 | case 'toolbar': |
---|
81 | $search = '<div class="actionButtons">'; |
---|
82 | break; |
---|
83 | |
---|
84 | case 'index': |
---|
85 | $search = '<ul class="categoryActions">'; |
---|
86 | $replace = '<li>'.$replace.'</li>'; |
---|
87 | break; |
---|
88 | } |
---|
89 | |
---|
90 | return str_replace($search, $search.$replace, $content); |
---|
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 | { |
---|
100 | array_push($menu, array( |
---|
101 | 'NAME' => 'TweetThis', |
---|
102 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
103 | )); |
---|
104 | return $menu; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | ?> |
---|