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 | // urls and position for index |
---|
31 | if (script_basename() == 'picture') |
---|
32 | { |
---|
33 | $template->assign('TWEET_URL', get_absolute_root_url().duplicate_picture_url()); |
---|
34 | } |
---|
35 | else if (script_basename() == 'index') |
---|
36 | { |
---|
37 | $conf['TweetThis']['position'] = 'index'; |
---|
38 | $template->assign('TWEET_URL', get_absolute_root_url().duplicate_index_url()); |
---|
39 | } |
---|
40 | |
---|
41 | // config |
---|
42 | $template->assign(array( |
---|
43 | 'TWEET_POSITION' => $conf['TweetThis']['position'], |
---|
44 | 'TWEET_SIZE' => $conf['TweetThis']['size'], |
---|
45 | 'TWEET_COUNT' => $conf['TweetThis']['count'], |
---|
46 | 'TWEET_VIA' => $conf['TweetThis']['via'], |
---|
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 | $template->set_filename('tweet_button', dirname(__FILE__).'/button.tpl'); |
---|
65 | $button = $template->parse('tweet_button', true); |
---|
66 | |
---|
67 | switch ($conf['TweetThis']['position']) |
---|
68 | { |
---|
69 | case 'index': |
---|
70 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
71 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
72 | break; |
---|
73 | case 'toolbar': |
---|
74 | // $template->add_picture_button($button, 100); |
---|
75 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
76 | break; |
---|
77 | default; |
---|
78 | $template->assign('TWEET_BUTTON', $button); |
---|
79 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | function tweet_add_button_prefilter($content, &$smarty) |
---|
84 | { |
---|
85 | global $template; |
---|
86 | |
---|
87 | switch ($template->get_template_vars('TWEET_POSITION')) |
---|
88 | { |
---|
89 | case 'top': |
---|
90 | $search = '<div id="theImage">'; |
---|
91 | $replace = '<div>{$TWEET_BUTTON}</div>'; |
---|
92 | break; |
---|
93 | |
---|
94 | case 'bottom': |
---|
95 | $search = '{$ELEMENT_CONTENT}'; |
---|
96 | $replace = '{$TWEET_BUTTON}'; |
---|
97 | break; |
---|
98 | } |
---|
99 | |
---|
100 | return str_replace($search, $search.$replace, $content); |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | if (script_basename() == 'admin') |
---|
105 | { |
---|
106 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
107 | |
---|
108 | function tweet_plugin_admin_menu($menu) |
---|
109 | { |
---|
110 | array_push($menu, array( |
---|
111 | 'NAME' => 'TweetThis', |
---|
112 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
113 | )); |
---|
114 | return $menu; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | ?> |
---|