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; |
---|
23 | $conf['TweetThis'] = explode(',', $conf['TweetThis']); |
---|
24 | |
---|
25 | if (script_basename() == 'picture') |
---|
26 | { |
---|
27 | $template->assign(array( |
---|
28 | 'TWEET_IMAGE' => $conf['TweetThis'][0], |
---|
29 | 'TWEET_POSITON' => $conf['TweetThis'][1], |
---|
30 | )); |
---|
31 | |
---|
32 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
33 | } |
---|
34 | else if (script_basename() == 'index') |
---|
35 | { |
---|
36 | $template->assign(array( |
---|
37 | 'TWEET_IMAGE' => $conf['TweetThis'][0], |
---|
38 | 'TWEET_POSITON' => 'index', |
---|
39 | )); |
---|
40 | |
---|
41 | $template->set_prefilter('index', 'tweet_add_button_prefilter'); |
---|
42 | } |
---|
43 | |
---|
44 | // html change a bit if we use custom button, or official with counter |
---|
45 | if ( in_array( $conf['TweetThis'][0], array('none','horizontal','vertical') ) ) |
---|
46 | { |
---|
47 | $template->assign('TWEET_IFRAME', true); |
---|
48 | $template->assign('TWEET_COUNTER', $conf['TweetThis'][0]); |
---|
49 | } |
---|
50 | else |
---|
51 | { |
---|
52 | $template->assign('TWEET_IFRAME', false); |
---|
53 | $template->assign('TWEET_COUNTER', 'none'); |
---|
54 | } |
---|
55 | |
---|
56 | // if the link is in the toolbar, we must use smallest buttons |
---|
57 | if ( script_basename() == 'index' OR $conf['TweetThis'][1] == 'toolbar') |
---|
58 | { |
---|
59 | switch ($conf['TweetThis'][0]) |
---|
60 | { |
---|
61 | case 'vertical': |
---|
62 | $template->assign('TWEET_COUNTER', 'horizontal'); break; |
---|
63 | case 't_logo-a': |
---|
64 | $template->assign('TWEET_IMAGE', 't_small-a'); break; |
---|
65 | case 't_logo-b': |
---|
66 | $template->assign('TWEET_IMAGE', 't_small-b'); break; |
---|
67 | case 't_logo-c': |
---|
68 | $template->assign('TWEET_IMAGE', 't_small-c'); break; |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | function tweet_add_button_prefilter($content, &$smarty) |
---|
74 | { |
---|
75 | global $template; |
---|
76 | |
---|
77 | switch ($template->get_template_vars('TWEET_POSITON')) |
---|
78 | { |
---|
79 | case 'top': |
---|
80 | $search = '<div id="theImage">'; |
---|
81 | $replace = ' |
---|
82 | <div><a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')" |
---|
83 | class="{if $TWEET_IFRAME}twitter-share-button{/if}" title="{\'Share on Twitter\'|@translate}"> |
---|
84 | {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if} |
---|
85 | </a></div> |
---|
86 | '; |
---|
87 | break; |
---|
88 | |
---|
89 | case 'bottom': |
---|
90 | $search = '{$ELEMENT_CONTENT}'; |
---|
91 | $replace = ' |
---|
92 | <a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')" |
---|
93 | class="{if $TWEET_IFRAME}twitter-share-button{/if}" title="{\'Share on Twitter\'|@translate}"> |
---|
94 | {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if} |
---|
95 | </a> |
---|
96 | '; |
---|
97 | break; |
---|
98 | |
---|
99 | case 'toolbar': |
---|
100 | $search = '{*caddie management END*}'; |
---|
101 | $replace = ' |
---|
102 | <a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')" |
---|
103 | class="{if $TWEET_IFRAME}twitter-share-button{/if} pwg-button" title="{\'Share on Twitter\'|@translate}"> |
---|
104 | {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if} |
---|
105 | </a> |
---|
106 | '; |
---|
107 | break; |
---|
108 | |
---|
109 | case 'index': |
---|
110 | $search = '<ul class="categoryActions">'; |
---|
111 | $replace = ' |
---|
112 | <li><a href="javascript:phpWGOpenWindow(\'http://twitter.com/share?count={$TWEET_COUNTER}\', \'{\'Share on Twitter\'|@translate}\', \'scrollbars=yes,width=550,height=370\')" |
---|
113 | class="{if $TWEET_IFRAME}twitter-share-button{/if} pwg-button" title="{\'Share on Twitter\'|@translate}"> |
---|
114 | {if $TWEET_IFRAME}Tweet{else}<img src="http://twitter-badges.s3.amazonaws.com/{$TWEET_IMAGE}.png"/>{/if} |
---|
115 | </a></li> |
---|
116 | '; |
---|
117 | break; |
---|
118 | } |
---|
119 | |
---|
120 | $replace = $search . $replace . '{if $TWEET_IFRAME}{combine_script id=\'twitter_widgets\' path=\'http://platform.twitter.com/widgets.js}{/if}'; |
---|
121 | |
---|
122 | return str_replace($search, $replace, $content); |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | if (script_basename() == 'admin') |
---|
127 | { |
---|
128 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
129 | |
---|
130 | function tweet_plugin_admin_menu($menu) |
---|
131 | { |
---|
132 | array_push( |
---|
133 | $menu, |
---|
134 | array( |
---|
135 | 'NAME' => 'TweetThis', |
---|
136 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
137 | ) |
---|
138 | ); |
---|
139 | |
---|
140 | return $menu; |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | ?> |
---|