1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: tumblr.share |
---|
4 | Version: auto |
---|
5 | Description: Add a "Share on Tumblr" button on picture pages |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=658 |
---|
7 | Author: Mistic |
---|
8 | Author URI: http://www.strangeplanet.fr |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | |
---|
13 | define('TUMBLR_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
14 | |
---|
15 | load_language('plugin.lang', TUMBLR_PATH); |
---|
16 | add_event_handler('loc_end_picture', 'tumblr_add_button'); |
---|
17 | add_event_handler('loc_end_index', 'tumblr_add_button'); |
---|
18 | |
---|
19 | |
---|
20 | function tumblr_add_button() |
---|
21 | { |
---|
22 | global $conf, $template, $page; |
---|
23 | |
---|
24 | $conf['TumblrShare'] = unserialize($conf['TumblrShare']); |
---|
25 | $conf['TumblrShare']['css'] = array( |
---|
26 | 'share_1' => 'width:81px; height:20px;', |
---|
27 | 'share_2' => 'width:61px; height:20px;', |
---|
28 | 'share_3' => 'width:129px; height:20px;', |
---|
29 | 'share_4' => 'width:20px; height:20px;', |
---|
30 | 'share_1T' => 'width:81px; height:20px;', |
---|
31 | 'share_2T' => 'width:61px; height:20px;', |
---|
32 | 'share_3T' => 'width:129px; height:20px;', |
---|
33 | 'share_4T' => 'width:20px; height:20px;', |
---|
34 | ); |
---|
35 | |
---|
36 | $root_url = get_absolute_root_url(); |
---|
37 | |
---|
38 | // button on piture page |
---|
39 | if (script_basename() == 'picture') |
---|
40 | { |
---|
41 | global $picture; |
---|
42 | |
---|
43 | $template->assign(array( |
---|
44 | 'TUMBLR_MODE' => 'photo', |
---|
45 | 'TUMBLR_URL' => $root_url.ltrim(duplicate_picture_url(), './'), |
---|
46 | 'TUMBLR_TITLE' => $picture['current']['TITLE'], |
---|
47 | )); |
---|
48 | |
---|
49 | if ($conf['TumblrShare']['img_size'] == 'Original') |
---|
50 | { |
---|
51 | $template->assign('TUMBLR_SOURCE', $root_url.ltrim($picture['current']['src_image']->get_url(), './')); |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | $template->assign('TUMBLR_SOURCE', $root_url.ltrim(DerivativeImage::url($conf['TumblrShare']['img_size'], $picture['current']['src_image']), './')); |
---|
56 | } |
---|
57 | } |
---|
58 | // button on other pages |
---|
59 | else if (script_basename() == 'index') |
---|
60 | { |
---|
61 | $conf['TumblrShare']['position'] = 'index'; |
---|
62 | $template->assign(array( |
---|
63 | 'TUMBLR_MODE' => 'link', |
---|
64 | 'TUMBLR_URL' => $root_url.ltrim(duplicate_index_url(), './'), |
---|
65 | 'TUMBLR_TITLE' => strip_tags($page['title']), |
---|
66 | )); |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | return; |
---|
71 | } |
---|
72 | |
---|
73 | // config |
---|
74 | $template->assign(array( |
---|
75 | 'TUMBLR_POSITION' => $conf['TumblrShare']['position'], |
---|
76 | 'TUMBLR_TYPE' => $conf['TumblrShare']['type'], |
---|
77 | 'TUMBLR_CSS' => $conf['TumblrShare']['css'][ $conf['TumblrShare']['type'] ], |
---|
78 | 'TUMBLR_COPY' => ' (from <a href="'.$root_url.'">'.$conf['gallery_title'].'</a>)', |
---|
79 | )); |
---|
80 | |
---|
81 | |
---|
82 | $template->set_filename('tumblr_button', dirname(__FILE__).'/button.tpl'); |
---|
83 | $button = $template->parse('tumblr_button', true); |
---|
84 | |
---|
85 | switch ($conf['TumblrShare']['position']) |
---|
86 | { |
---|
87 | case 'index': |
---|
88 | // $template->add_index_button('<li>'.$button.'</li>', 100); |
---|
89 | $template->concat('PLUGIN_INDEX_ACTIONS', '<li>'.$button.'</li>'); |
---|
90 | break; |
---|
91 | case 'toolbar': |
---|
92 | // $template->add_picture_button($button, 100); |
---|
93 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
94 | break; |
---|
95 | default; |
---|
96 | $template->assign('TUMBLR_BUTTON', $button); |
---|
97 | $template->set_prefilter('picture', 'tumblr_add_button_prefilter'); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | function tumblr_add_button_prefilter($content, &$smarty) |
---|
102 | { |
---|
103 | global $template; |
---|
104 | |
---|
105 | switch ($template->get_template_vars('TUMBLR_POSITION')) |
---|
106 | { |
---|
107 | case 'top': |
---|
108 | $search = '<div id="theImage">'; |
---|
109 | $replace = '<div>{$TUMBLR_BUTTON}</div>'; |
---|
110 | break; |
---|
111 | |
---|
112 | case 'bottom': |
---|
113 | $search = '{$ELEMENT_CONTENT}'; |
---|
114 | $replace = '{$TUMBLR_BUTTON}'; |
---|
115 | break; |
---|
116 | } |
---|
117 | |
---|
118 | return str_replace($search, $search.$replace, $content); |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | if (script_basename() == 'admin') |
---|
123 | { |
---|
124 | add_event_handler('get_admin_plugin_menu_links', 'tumblr_plugin_admin_menu'); |
---|
125 | |
---|
126 | function tumblr_plugin_admin_menu($menu) |
---|
127 | { |
---|
128 | array_push($menu, array( |
---|
129 | 'NAME' => 'tumblr.share', |
---|
130 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)) |
---|
131 | )); |
---|
132 | return $menu; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | ?> |
---|