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 | add_event_handler('loc_begin_admin_page', 'tweet_depreciated'); |
---|
20 | |
---|
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 | |
---|
28 | function tweet_add_button() |
---|
29 | { |
---|
30 | global $conf, $template, $user; |
---|
31 | |
---|
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 | |
---|
38 | // urls and position |
---|
39 | if (script_basename() == 'picture') |
---|
40 | { |
---|
41 | $template->assign('TWEET_URL', get_absolute_root_url().ltrim(duplicate_picture_url(), './')); |
---|
42 | } |
---|
43 | else if (script_basename() == 'index') |
---|
44 | { |
---|
45 | $conf['TweetThis']['position'] = 'index'; |
---|
46 | $template->assign('TWEET_URL', get_absolute_root_url().ltrim(duplicate_index_url(array(), array('start')), './')); |
---|
47 | } |
---|
48 | else |
---|
49 | { |
---|
50 | return; |
---|
51 | } |
---|
52 | |
---|
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 | |
---|
61 | // button language |
---|
62 | if ( in_array(str_replace('_','-',strtolower($user['language'])), $conf['TweetThis']['lang']) ) |
---|
63 | { |
---|
64 | $template->assign('TWEET_LANG', str_replace('_','-',strtolower($user['language']))); |
---|
65 | } |
---|
66 | if ( in_array(substr($user['language'],0,2), $conf['TweetThis']['lang']) ) |
---|
67 | { |
---|
68 | $template->assign('TWEET_LANG', substr($user['language'],0,2)); |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | $template->assign('TWEET_LANG', 'en'); |
---|
73 | } |
---|
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': |
---|
82 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
83 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
84 | break; |
---|
85 | case 'toolbar': |
---|
86 | // $template->add_picture_button($button, 100); |
---|
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 | } |
---|
93 | } |
---|
94 | |
---|
95 | function tweet_add_button_prefilter($content, &$smarty) |
---|
96 | { |
---|
97 | global $template; |
---|
98 | |
---|
99 | switch ($template->get_template_vars('TWEET_POSITION')) |
---|
100 | { |
---|
101 | case 'top': |
---|
102 | $search = '<div id="theImage">'; |
---|
103 | $replace = '<div>{$TWEET_BUTTON}</div>'; |
---|
104 | break; |
---|
105 | |
---|
106 | case 'bottom': |
---|
107 | $search = '{$ELEMENT_CONTENT}'; |
---|
108 | $replace = '{$TWEET_BUTTON}'; |
---|
109 | break; |
---|
110 | } |
---|
111 | |
---|
112 | return str_replace($search, $search.$replace, $content); |
---|
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 | { |
---|
122 | array_push($menu, array( |
---|
123 | 'NAME' => 'TweetThis', |
---|
124 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
125 | )); |
---|
126 | return $menu; |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | ?> |
---|