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->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
71 | break; |
---|
72 | case 'toolbar': |
---|
73 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
74 | break; |
---|
75 | default; |
---|
76 | $template->assign('TWEET_BUTTON', $button); |
---|
77 | $template->set_prefilter('picture', 'tweet_add_button_prefilter'); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | function tweet_add_button_prefilter($content, &$smarty) |
---|
82 | { |
---|
83 | global $template; |
---|
84 | |
---|
85 | switch ($template->get_template_vars('TWEET_POSITON')) |
---|
86 | { |
---|
87 | case 'top': |
---|
88 | $search = '<div id="theImage">'; |
---|
89 | $replace = '<div>{$TWEET_BUTTON}</div>'; |
---|
90 | break; |
---|
91 | |
---|
92 | case 'bottom': |
---|
93 | $search = '{$ELEMENT_CONTENT}'; |
---|
94 | $replace = '{$TWEET_BUTTON}'; |
---|
95 | break; |
---|
96 | } |
---|
97 | |
---|
98 | return str_replace($search, $search.$replace, $content); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | if (script_basename() == 'admin') |
---|
103 | { |
---|
104 | add_event_handler('get_admin_plugin_menu_links', 'tweet_plugin_admin_menu'); |
---|
105 | |
---|
106 | function tweet_plugin_admin_menu($menu) |
---|
107 | { |
---|
108 | array_push($menu, array( |
---|
109 | 'NAME' => 'TweetThis', |
---|
110 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
111 | )); |
---|
112 | return $menu; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | ?> |
---|