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 | global $conf; |
---|
14 | |
---|
15 | define('SOCIALBUTT_ID', basename(dirname(__FILE__))); |
---|
16 | define('SOCIALBUTT_PATH' , PHPWG_PLUGINS_PATH . SOCIALBUTT_ID . '/'); |
---|
17 | define('SOCIALBUTT_ADMIN', get_root_url() . 'admin.php?page=plugin-' . SOCIALBUTT_ID); |
---|
18 | |
---|
19 | |
---|
20 | $conf['SocialButtons'] = safe_unserialize($conf['SocialButtons']); |
---|
21 | |
---|
22 | |
---|
23 | if (defined('IN_ADMIN')) |
---|
24 | { |
---|
25 | add_event_handler('get_admin_plugin_menu_links', 'socialbutt_admin_plugin_menu_links'); |
---|
26 | |
---|
27 | function socialbutt_admin_plugin_menu_links($menu) |
---|
28 | { |
---|
29 | $menu[] = array( |
---|
30 | 'NAME' => 'Social Buttons', |
---|
31 | 'URL' => SOCIALBUTT_ADMIN, |
---|
32 | ); |
---|
33 | return $menu; |
---|
34 | } |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | add_event_handler('loc_end_picture', 'socialbutt_add_button'); |
---|
39 | add_event_handler('loc_end_index', 'socialbutt_add_button'); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | /** |
---|
44 | * add buttons |
---|
45 | */ |
---|
46 | function socialbutt_add_button() |
---|
47 | { |
---|
48 | global $conf, $template, $picture; |
---|
49 | |
---|
50 | set_make_full_url(); |
---|
51 | $basename = script_basename(); |
---|
52 | $root_url = get_absolute_root_url(); |
---|
53 | |
---|
54 | if ($basename == 'picture') |
---|
55 | { |
---|
56 | // global $picture; |
---|
57 | |
---|
58 | // if ($picture['current']['level'] > 0) return; |
---|
59 | |
---|
60 | $share_url = duplicate_picture_url(); |
---|
61 | } |
---|
62 | else if ($basename == 'index' and $conf['SocialButtons']['on_index']) |
---|
63 | { |
---|
64 | $conf['SocialButtons']['position'] = 'index'; |
---|
65 | $share_url = duplicate_index_url(array(), array('start')); |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | return; |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | $tpl_vars = array( |
---|
74 | 'share_url' => $share_url, |
---|
75 | 'basename' => $basename, |
---|
76 | 'position' => $conf['SocialButtons']['position'], |
---|
77 | 'light' => $conf['SocialButtons']['light'], |
---|
78 | 'copyright' => '(from <a href="'.$share_url.'">'.$conf['gallery_title'].'</a>)', |
---|
79 | ); |
---|
80 | |
---|
81 | if ($basename == 'picture') |
---|
82 | { |
---|
83 | if ($conf['SocialButtons']['img_size'] == 'Original') |
---|
84 | { |
---|
85 | $tpl_vars['source'] = $picture['current']['src_image']->get_url(); |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | $tpl_vars['source'] = DerivativeImage::url($conf['SocialButtons']['img_size'], $picture['current']['src_image']); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | $buttons = array(); |
---|
95 | $services = array('google', 'twitter', 'facebook', 'tumblr', 'pinterest', 'reddit', 'linkedin'); |
---|
96 | |
---|
97 | foreach ($services as $service) |
---|
98 | { |
---|
99 | if ($conf['SocialButtons'][$service]['enabled']) |
---|
100 | { |
---|
101 | if ($service=='pinterest' && $basename!='picture') |
---|
102 | { |
---|
103 | continue; |
---|
104 | } |
---|
105 | include_once(SOCIALBUTT_PATH . 'include/'. $service .'.inc.php'); |
---|
106 | call_user_func_array('socialbutt_'.$service, array($basename, $root_url, &$tpl_vars, &$buttons)); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | unset_make_full_url(); |
---|
111 | |
---|
112 | if (empty($buttons)) |
---|
113 | { |
---|
114 | return; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | $template->assign(array( |
---|
119 | 'SOCIALBUTT' => $tpl_vars, |
---|
120 | 'SOCIALBUTT_PATH' => SOCIALBUTT_PATH, |
---|
121 | )); |
---|
122 | |
---|
123 | // parse buttons |
---|
124 | foreach ($buttons as &$button) |
---|
125 | { |
---|
126 | $button = $template->parse($button, true); |
---|
127 | } |
---|
128 | unset($button); |
---|
129 | |
---|
130 | switch ($conf['SocialButtons']['position']) |
---|
131 | { |
---|
132 | case 'index': |
---|
133 | foreach ($buttons as $button) |
---|
134 | { |
---|
135 | $template->add_index_button($button, 100); |
---|
136 | } |
---|
137 | break; |
---|
138 | case 'toolbar': |
---|
139 | foreach ($buttons as $button) |
---|
140 | { |
---|
141 | $template->add_picture_button($button, 100); |
---|
142 | } |
---|
143 | break; |
---|
144 | default; |
---|
145 | define('SOCIALBUTT_POSITION', $conf['SocialButtons']['position']); |
---|
146 | $template->assign('SOCIALBUTT_BUTTONS', $buttons); |
---|
147 | $template->set_prefilter('picture', 'socialbutt_add_button_prefilter'); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | function socialbutt_add_button_prefilter($content) |
---|
152 | { |
---|
153 | switch (SOCIALBUTT_POSITION) |
---|
154 | { |
---|
155 | case 'top': |
---|
156 | $search = '<div id="theImage">'; |
---|
157 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
158 | break; |
---|
159 | |
---|
160 | case 'bottom': |
---|
161 | $search = '{$ELEMENT_CONTENT}'; |
---|
162 | $add = '<div id="socialButtons">{foreach from=$SOCIALBUTT_BUTTONS item=BUTTON}{$BUTTON} {/foreach}</div>'; |
---|
163 | break; |
---|
164 | } |
---|
165 | |
---|
166 | return str_replace($search, $search.$add, $content); |
---|
167 | } |
---|