1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Social Buttons |
---|
4 | Version: auto |
---|
5 | Description: Sharing functions for Facebook, Twitter, Google+ and Tumblr |
---|
6 | Plugin URI: auto |
---|
7 | Author: Mistic |
---|
8 | Author URI: http://www.strangeplanet.fr |
---|
9 | */ |
---|
10 | |
---|
11 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
12 | |
---|
13 | // +-----------------------------------------------------------------------+ |
---|
14 | // | Define plugin constants | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | define('SOCIALBUTT_ID', basename(dirname(__FILE__))); |
---|
17 | define('SOCIALBUTT_PATH' , PHPWG_PLUGINS_PATH . SOCIALBUTT_ID . '/'); |
---|
18 | define('SOCIALBUTT_ADMIN', get_root_url() . 'admin.php?page=plugin-' . SOCIALBUTT_ID); |
---|
19 | define('SOCIALBUTT_VERSION', 'auto'); |
---|
20 | |
---|
21 | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | // | Add event handlers | |
---|
24 | // +-----------------------------------------------------------------------+ |
---|
25 | // init the plugin |
---|
26 | add_event_handler('init', 'socialbutt_init'); |
---|
27 | |
---|
28 | if (defined('IN_ADMIN')) |
---|
29 | { |
---|
30 | add_event_handler('get_admin_plugin_menu_links', 'socialbutt_admin_plugin_menu_links'); |
---|
31 | |
---|
32 | function socialbutt_admin_plugin_menu_links($menu) |
---|
33 | { |
---|
34 | $menu[] = array( |
---|
35 | 'NAME' => 'Social Buttons', |
---|
36 | 'URL' => SOCIALBUTT_ADMIN, |
---|
37 | ); |
---|
38 | return $menu; |
---|
39 | } |
---|
40 | } |
---|
41 | else |
---|
42 | { |
---|
43 | add_event_handler('loc_end_picture', 'socialbutt_add_button'); |
---|
44 | add_event_handler('loc_end_index', 'socialbutt_add_button'); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | /** |
---|
49 | * plugin initialization |
---|
50 | */ |
---|
51 | function socialbutt_init() |
---|
52 | { |
---|
53 | global $conf, $pwg_loaded_plugins; |
---|
54 | |
---|
55 | include_once(SOCIALBUTT_PATH . 'maintain.inc.php'); |
---|
56 | $maintain = new SocialButtons_maintain(SOCIALBUTT_ID); |
---|
57 | $maintain->autoUpdate(SOCIALBUTT_VERSION, 'install'); |
---|
58 | |
---|
59 | $conf['SocialButtons'] = unserialize($conf['SocialButtons']); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /** |
---|
64 | * add buttons |
---|
65 | */ |
---|
66 | function socialbutt_add_button() |
---|
67 | { |
---|
68 | global $conf, $template, $picture; |
---|
69 | |
---|
70 | set_make_full_url(); |
---|
71 | $basename = script_basename(); |
---|
72 | $root_url = get_absolute_root_url(); |
---|
73 | |
---|
74 | if ($basename == 'picture') |
---|
75 | { |
---|
76 | // global $picture; |
---|
77 | |
---|
78 | // if ($picture['current']['level'] > 0) return; |
---|
79 | |
---|
80 | $share_url = duplicate_picture_url(); |
---|
81 | } |
---|
82 | else if ($basename == 'index' and $conf['SocialButtons']['on_index']) |
---|
83 | { |
---|
84 | $conf['SocialButtons']['position'] = 'index'; |
---|
85 | $share_url = duplicate_index_url(array(), array('start')); |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | return; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | $tpl_vars = array( |
---|
94 | 'share_url' => $share_url, |
---|
95 | 'basename' => $basename, |
---|
96 | 'position' => $conf['SocialButtons']['position'], |
---|
97 | 'light' => $conf['SocialButtons']['light'], |
---|
98 | 'copyright' => '(from <a href="'.$share_url.'">'.$conf['gallery_title'].'</a>)', |
---|
99 | ); |
---|
100 | |
---|
101 | if ($basename == 'picture') |
---|
102 | { |
---|
103 | if ($conf['SocialButtons']['img_size'] == 'Original') |
---|
104 | { |
---|
105 | $tpl_vars['source'] = $picture['current']['src_image']->get_url(); |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | $tpl_vars['source'] = DerivativeImage::url($conf['SocialButtons']['img_size'], $picture['current']['src_image']); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | $buttons = array(); |
---|
115 | $services = array('google', 'twitter', 'facebook', 'tumblr', 'pinterest', 'reddit', 'linkedin'); |
---|
116 | |
---|
117 | foreach ($services as $service) |
---|
118 | { |
---|
119 | if ($conf['SocialButtons'][$service]['enabled']) |
---|
120 | { |
---|
121 | if ($service=='pinterest' && $basename!='picture') |
---|
122 | { |
---|
123 | continue; |
---|
124 | } |
---|
125 | include_once(SOCIALBUTT_PATH . 'include/'. $service .'.inc.php'); |
---|
126 | call_user_func_array('socialbutt_'.$service, array($basename, $root_url, &$tpl_vars, &$buttons)); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | unset_make_full_url(); |
---|
131 | |
---|
132 | if (empty($buttons)) |
---|
133 | { |
---|
134 | return; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | $template->assign(array( |
---|
139 | 'SOCIALBUTT' => $tpl_vars, |
---|
140 | 'SOCIALBUTT_PATH' => SOCIALBUTT_PATH, |
---|
141 | )); |
---|
142 | |
---|
143 | // parse buttons |
---|
144 | foreach ($buttons as &$button) |
---|
145 | { |
---|
146 | $button = $template->parse($button, true); |
---|
147 | } |
---|
148 | unset($button); |
---|
149 | |
---|
150 | switch ($conf['SocialButtons']['position']) |
---|
151 | { |
---|
152 | case 'index': |
---|
153 | foreach ($buttons as $button) |
---|
154 | { |
---|
155 | $template->add_index_button($button, 100); |
---|
156 | } |
---|
157 | break; |
---|
158 | case 'toolbar': |
---|
159 | foreach ($buttons as $button) |
---|
160 | { |
---|
161 | $template->add_picture_button($button, 100); |
---|
162 | } |
---|
163 | break; |
---|
164 | default; |
---|
165 | define('SOCIALBUTT_POSITION', $conf['SocialButtons']['position']); |
---|
166 | $template->assign('SOCIALBUTT_BUTTONS', $buttons); |
---|
167 | $template->set_prefilter('picture', 'socialbutt_add_button_prefilter'); |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | function socialbutt_add_button_prefilter($content) |
---|
172 | { |
---|
173 | switch (SOCIALBUTT_POSITION) |
---|
174 | { |
---|
175 | case 'top': |
---|
176 | $search = '<div id="theImage">'; |
---|
177 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
178 | break; |
---|
179 | |
---|
180 | case 'bottom': |
---|
181 | $search = '{$ELEMENT_CONTENT}'; |
---|
182 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
183 | break; |
---|
184 | } |
---|
185 | |
---|
186 | return str_replace($search, $search.$add, $content); |
---|
187 | } |
---|
188 | |
---|
189 | ?> |
---|