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 |
---|
31 | if (script_basename() == 'picture') |
---|
32 | { |
---|
33 | $template->assign('TWEET_URL', get_absolute_root_url().ltrim(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().ltrim(duplicate_index_url(array(), array('start')), './')); |
---|
39 | } |
---|
40 | else |
---|
41 | { |
---|
42 | return; |
---|
43 | } |
---|
44 | |
---|
45 | // config |
---|
46 | $template->assign(array( |
---|
47 | 'TWEET_POSITION' => $conf['TweetThis']['position'], |
---|
48 | 'TWEET_SIZE' => $conf['TweetThis']['size'], |
---|
49 | 'TWEET_COUNT' => $conf['TweetThis']['count'], |
---|
50 | 'TWEET_VIA' => $conf['TweetThis']['via'], |
---|
51 | )); |
---|
52 | |
---|
53 | // button language |
---|
54 | if ( in_array(str_replace('_','-',strtolower($user['language'])), $conf['TweetThis']['lang']) ) |
---|
55 | { |
---|
56 | $template->assign('TWEET_LANG', str_replace('_','-',strtolower($user['language']))); |
---|
57 | } |
---|
58 | if ( in_array(substr($user['language'],0,2), $conf['TweetThis']['lang']) ) |
---|
59 | { |
---|
60 | $template->assign('TWEET_LANG', substr($user['language'],0,2)); |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | $template->assign('TWEET_LANG', 'en'); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | $template->set_filename('tweet_button', dirname(__FILE__).'/button.tpl'); |
---|
69 | $button = $template->parse('tweet_button', true); |
---|
70 | |
---|
71 | switch ($conf['TweetThis']['position']) |
---|
72 | { |
---|
73 | case 'index': |
---|
74 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
75 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
76 | break; |
---|
77 | case 'toolbar': |
---|
78 | // $template->add_picture_button($button, 100); |
---|
79 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
80 | break; |
---|
81 | default; |
---|
82 | $template->assign('TWEET_BUTTON', $button); |
---|
83 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | function tweet_add_button_prefilter($content, &$smarty) |
---|
88 | { |
---|
89 | global $template; |
---|
90 | |
---|
91 | switch ($template->get_template_vars('TWEET_POSITION')) |
---|
92 | { |
---|
93 | case 'top': |
---|
94 | $search = '<div id="theImage">'; |
---|
95 | $replace = '<div>{$TWEET_BUTTON}</div>'; |
---|
96 | break; |
---|
97 | |
---|
98 | case 'bottom': |
---|
99 | $search = '{$ELEMENT_CONTENT}'; |
---|
100 | $replace = '{$TWEET_BUTTON}'; |
---|
101 | break; |
---|
102 | } |
---|
103 | |
---|
104 | return str_replace($search, $search.$replace, $content); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | if (script_basename() == 'admin') |
---|
109 | { |
---|
110 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
111 | |
---|
112 | function tweet_plugin_admin_menu($menu) |
---|
113 | { |
---|
114 | array_push($menu, array( |
---|
115 | 'NAME' => 'TweetThis', |
---|
116 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
117 | )); |
---|
118 | return $menu; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | ?> |
---|