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->assign('TWEET_URL', get_absolute_root_url().duplicate_picture_url()); |
---|
40 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
41 | } |
---|
42 | else if (script_basename() == 'index') |
---|
43 | { |
---|
44 | $template->assign('TWEET_POSITON', 'index'); |
---|
45 | $template->assign('TWEET_URL', get_absolute_root_url().duplicate_index_url()); |
---|
46 | $template->set_prefilter('index', 'tweet_add_button_prefilter'); |
---|
47 | } |
---|
48 | |
---|
49 | // button language |
---|
50 | if ( in_array(str_replace('_','-',strtolower($user['language'])), $conf['TweetThis']['lang']) ) |
---|
51 | { |
---|
52 | $template->assign('TWEET_LANG', str_replace('_','-',strtolower($user['language']))); |
---|
53 | } |
---|
54 | if ( in_array(substr($user['language'],0,2), $conf['TweetThis']['lang']) ) |
---|
55 | { |
---|
56 | $template->assign('TWEET_LANG', substr($user['language'],0,2)); |
---|
57 | } |
---|
58 | else |
---|
59 | { |
---|
60 | $template->assign('TWEET_LANG', 'en'); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | function tweet_add_button_prefilter($content, &$smarty) |
---|
65 | { |
---|
66 | global $template; |
---|
67 | |
---|
68 | $replace = '{combine_script id=\'twitter_widgets\' path=\'http://platform.twitter.com/widgets.js} |
---|
69 | <a href="https://twitter.com/share" class="twitter-share-button" |
---|
70 | data-url="{$TWEET_URL}" data-lang="{$TWEET_LANG}" {if not empty($TWEET_VIA)}data-via="{$TWEET_VIA}"{/if} |
---|
71 | {if $TWEET_SIZE=="large"}data-size="large"{/if} {if not $TWEET_COUNT}data-count="none"{/if}>Tweet</a>'; |
---|
72 | switch ($template->get_template_vars('TWEET_POSITON')) |
---|
73 | { |
---|
74 | case 'top': |
---|
75 | $search = '<div id="theImage">'; |
---|
76 | $replace = '<div>'.$replace.'</div>'; |
---|
77 | break; |
---|
78 | |
---|
79 | case 'bottom': |
---|
80 | $search = '{$ELEMENT_CONTENT}'; |
---|
81 | break; |
---|
82 | |
---|
83 | case 'toolbar': |
---|
84 | $search = '<div class="actionButtons">'; |
---|
85 | break; |
---|
86 | |
---|
87 | case 'index': |
---|
88 | $search = '<ul class="categoryActions">'; |
---|
89 | $replace = '<li>'.$replace.'</li>'; |
---|
90 | break; |
---|
91 | } |
---|
92 | |
---|
93 | return str_replace($search, $search.$replace, $content); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | if (script_basename() == 'admin') |
---|
98 | { |
---|
99 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
100 | |
---|
101 | function tweet_plugin_admin_menu($menu) |
---|
102 | { |
---|
103 | array_push($menu, array( |
---|
104 | 'NAME' => 'TweetThis', |
---|
105 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
106 | )); |
---|
107 | return $menu; |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | ?> |
---|