1 | <?php |
---|
2 | /* |
---|
3 | * Plugin Name: AddThis |
---|
4 | * Version: 0.0.3 |
---|
5 | * Description: AddThis activation |
---|
6 | * Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=293 |
---|
7 | * Author: Tiico |
---|
8 | * Author URI: |
---|
9 | * */ |
---|
10 | /********* Fichier addthis.class.php *********/ |
---|
11 | |
---|
12 | class AddThis |
---|
13 | { |
---|
14 | var $my_config; |
---|
15 | |
---|
16 | // Add Addthis CSS in HEAD section |
---|
17 | function AddThis_link() |
---|
18 | { |
---|
19 | global $template, $page, $user; |
---|
20 | |
---|
21 | if (isset($page['section']) && ($page['section']) == 'categories') |
---|
22 | { |
---|
23 | // Selection du mode 'icones' |
---|
24 | if ( (isset($page['image_id']) && $this->my_config['ImageButton'] == 8) |
---|
25 | || (empty($page['category']) && $this->my_config['HomeButton'] == 8) |
---|
26 | || (isset($page['category']) && $this->my_config['CategoryButton'] == 8) |
---|
27 | ) |
---|
28 | // $cssfile = '<link href="./plugins/AddThis/js/addthis.css" rel="stylesheet" type="text/css" />'; |
---|
29 | $cssfile = '<link href="'.ADDTHIS_JS_PATH.'addthis.css" rel="stylesheet" type="text/css" />'; |
---|
30 | } |
---|
31 | if (isset($cssfile)) |
---|
32 | $template->append('head_elements',$cssfile); |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | // Add Addthis icon |
---|
38 | function add_AddThis_icon() |
---|
39 | { |
---|
40 | global $template, $page, $user; |
---|
41 | |
---|
42 | include ADDTHIS_INC_PATH.'constants.inc.php'; |
---|
43 | |
---|
44 | if ($this->my_config['addthis_languser']) // langue de l'utilisateur |
---|
45 | { |
---|
46 | $research = pwg_query('SELECT language FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$user['id'].';'); |
---|
47 | $defaultlanguage = mysql_fetch_array($research); |
---|
48 | $defaultlanguage = substr($defaultlanguage[0], 0, 2); |
---|
49 | |
---|
50 | if (in_array($defaultlanguage, $language_list[0])) |
---|
51 | $this->my_config['addthis_language'] = $defaultlanguage; |
---|
52 | |
---|
53 | } |
---|
54 | |
---|
55 | $addthis_img_src = array( |
---|
56 | '', |
---|
57 | '<img id="bm3i" src="http://s7.addthis.com/static/btn/lg-share-'.$this->my_config['addthis_language'].'.gif" width="125" height="16" border="0" alt="Share" />', |
---|
58 | '<img id="bm6i" src="http://s7.addthis.com/static/btn/sm-share-'.$this->my_config['addthis_language'].'.gif" width="83" height="16" border="0" alt="Share" />', |
---|
59 | '<img id="bm1i" src="http://s7.addthis.com/static/btn/lg-bookmark-en.gif" width="125" height="16" border="0" alt="Bookmark" />', |
---|
60 | '<img id="bm0i" src="http://s7.addthis.com/static/btn/sm-bookmark-en.gif" width="83" height="16" border="0" alt="Bookmark" />', |
---|
61 | '<img id="bm4i" src="http://s7.addthis.com/static/btn/lg-addthis-en.gif" width="125" height="16" border="0" alt="Add This" />', |
---|
62 | '<img id="bm5i" src="http://s7.addthis.com/static/btn/sm-plus.gif" width="16" height="16" border="0" alt="AddThis" />', |
---|
63 | '' |
---|
64 | ); |
---|
65 | |
---|
66 | // Taille des boutons |
---|
67 | $addthis_img_size = array( |
---|
68 | '', |
---|
69 | '125', |
---|
70 | '83', |
---|
71 | '123', |
---|
72 | '83', |
---|
73 | '125', |
---|
74 | '16', |
---|
75 | ''); |
---|
76 | $addthis_option = ''; |
---|
77 | $addthis_img = 0; |
---|
78 | if (isset($page['section']) && ($page['section']) == 'categories') |
---|
79 | { |
---|
80 | // image |
---|
81 | if (isset($page['image_id'])) |
---|
82 | { |
---|
83 | $addthis_img = $this->my_config['ImageButton']; |
---|
84 | } |
---|
85 | // Page accueil |
---|
86 | elseif( empty($page['category'])) |
---|
87 | { |
---|
88 | $addthis_img = $this->my_config['HomeButton']; |
---|
89 | } |
---|
90 | elseif (isset($page['category'])) |
---|
91 | { |
---|
92 | $addthis_img = $this->my_config['CategoryButton']; |
---|
93 | } |
---|
94 | } |
---|
95 | // pas d'affichage sur selection = 'desactive' ou si selection = 'icones' |
---|
96 | if ($addthis_img > 0 && $addthis_img < 9) |
---|
97 | { |
---|
98 | foreach ($this->my_config['addthis_options'] as $key => $value) |
---|
99 | { |
---|
100 | if ($value == true) |
---|
101 | { |
---|
102 | if (strlen($addthis_option) != 0) |
---|
103 | $addthis_option .= ', '; |
---|
104 | $addthis_option .= $key; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | $tpl_code = (isset($page['image_id']) ? "\n" :"\n<li>") |
---|
110 | .'<script type="text/javascript">' |
---|
111 | .(strlen($this->my_config['addthis_pub']) != 0 ? "\n".'var addthis_pub = "'.$this->my_config['addthis_pub'].'";' : '') |
---|
112 | .(strlen($this->my_config['addthis_brand']) != 0 ? "\n".'var addthis_brand = "'.$this->my_config['addthis_brand'].'";' : '') |
---|
113 | .(strlen($this->my_config['addthis_header_color']) != 0 ? "\n".'var addthis_header_color = "'.$this->my_config['addthis_header_color'].'";' : '') |
---|
114 | .(strlen($this->my_config['addthis_header_background']) != 0 ? "\n".'var addthis_header_background = "'.$this->my_config['addthis_header_background'].'";' : '') |
---|
115 | .(strlen($this->my_config['addthis_offset_top']) != 0 ? "\n".'var addthis_offset_top = '.$this->my_config['addthis_offset_top'].';' : '') |
---|
116 | .(strlen($this->my_config['addthis_offset_left']) != 0 ? "\n".'var addthis_offset_left = '.$this->my_config['addthis_offset_left'].';' : '') |
---|
117 | .(strlen($this->my_config['addthis_hover_delay']) != 0 ? "\n".'var addthis_hover_delay = '.$this->my_config['addthis_hover_delay'].';' : '') |
---|
118 | .(strlen($this->my_config['addthis_language']) != 0 ? "\n".'var addthis_language = "'.$this->my_config['addthis_language'].'";' : '') |
---|
119 | ."\n" ; |
---|
120 | |
---|
121 | if ($addthis_img > 0 && $addthis_img < 8) |
---|
122 | { |
---|
123 | $tpl_code.=(strlen($addthis_option) != 0 ? 'var addthis_options = \''.$addthis_option.'\'': '') |
---|
124 | ."\n" |
---|
125 | .'</script>'; |
---|
126 | |
---|
127 | |
---|
128 | $tpl_code .= '<a style="padding:4px;'.(isset($addthis_img_size[$addthis_img]) ? 'width:'.$addthis_img_size[$addthis_img].'px;' : '').'" href="http://www.addthis.com/bookmark.php?v=250" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()">' |
---|
129 | ."\n" |
---|
130 | .$addthis_img_src[$addthis_img] |
---|
131 | ."\n" |
---|
132 | // si selection du 7 |
---|
133 | .($addthis_img == 7 ? (strlen($this->my_config['addthis_icon_text']) != 0 ? $this->my_config['addthis_icon_text'] : 'Share' ) : '') |
---|
134 | ."\n" |
---|
135 | .'</a><script type="text/javascript" src="'.ADDTHIS_JS_PATH.'addthis_widget.js"></script>' |
---|
136 | ."\n" |
---|
137 | .(isset($page['image_id']) ? '' :'</li>'); |
---|
138 | } |
---|
139 | |
---|
140 | else if ($addthis_img == 8) |
---|
141 | { |
---|
142 | $tpl_code .= '</script>'; |
---|
143 | |
---|
144 | $tpl_code .= ' |
---|
145 | <script type="text/javascript"> |
---|
146 | addthis_title = document.title; |
---|
147 | addthis_url = window.location.href; |
---|
148 | addthis_clickout= true;' |
---|
149 | .(strlen($this->my_config['addthis_pub']) != 0 ? 'addthis_id = \''.$this->my_config['addthis_pub'].'\';' : '') |
---|
150 | ."\n" |
---|
151 | .'</script>' |
---|
152 | ."\n"; |
---|
153 | |
---|
154 | $nb_icons = 1; |
---|
155 | |
---|
156 | $tpl_code .= (isset($page['image_id']) ? '' : '<li>'); |
---|
157 | |
---|
158 | $tpl_code .= '<div class="addthis_toolbox addthis_default_style">'; |
---|
159 | |
---|
160 | foreach ($this->my_config['addthis_options'] as $key => $value) |
---|
161 | { |
---|
162 | if ($nb_icons <= $this->my_config['addthis_icon_nb']) |
---|
163 | { |
---|
164 | if ($value == true) |
---|
165 | { |
---|
166 | $nb_icons++; |
---|
167 | if ($key == "more") |
---|
168 | { |
---|
169 | $tpl_code .='<span class="addthis_separator" style="padding:1px;">|</span>'; |
---|
170 | $tpl_code .='<a href="http://www.addthis.com/bookmark.php?v=250" class="addthis_button_compact""></a>'; |
---|
171 | } |
---|
172 | else |
---|
173 | $tpl_code .='<a class="addthis_button_'.$key.'" ></a>'; |
---|
174 | |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|
178 | // $tpl_code .= '<script type="text/javascript" src="http://s7.addthis.com/js/200/addthis_widget.js"></script>'."\n"; |
---|
179 | $tpl_code .= '<script type="text/javascript" src="'.ADDTHIS_JS_PATH.'addthis_widget.js"></script>'."\n"; |
---|
180 | $tpl_code .= (isset($page['image_id']) ? '' : '</li>'); |
---|
181 | |
---|
182 | |
---|
183 | } |
---|
184 | |
---|
185 | } |
---|
186 | if (isset($tpl_code)) |
---|
187 | { |
---|
188 | if (isset($page['image_id'])) |
---|
189 | $template->concat('PLUGIN_PICTURE_ACTIONS', $tpl_code); |
---|
190 | else |
---|
191 | $template->concat('PLUGIN_INDEX_ACTIONS', $tpl_code); |
---|
192 | |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | /* Loading of the configuration file - If not exist -> load default values */ |
---|
199 | function load_config() |
---|
200 | { |
---|
201 | |
---|
202 | $x = @file_get_contents( ADDTHIS_CFG_FILE ); |
---|
203 | if ($x!==false) |
---|
204 | { |
---|
205 | $c = unserialize($x); |
---|
206 | $this->my_config = $c; |
---|
207 | } |
---|
208 | // Init default value for the config file |
---|
209 | $this->load_default_config(); |
---|
210 | |
---|
211 | } |
---|
212 | |
---|
213 | /* Saving of the configuration file with data */ |
---|
214 | function save_config() |
---|
215 | { |
---|
216 | $file = fopen( ADDTHIS_CFG_FILE, 'w' ); |
---|
217 | fwrite($file, serialize($this->my_config) ); |
---|
218 | fclose( $file ); |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | private function load_default_config() |
---|
223 | { |
---|
224 | include ADDTHIS_INC_PATH.'default_values.inc.php'; |
---|
225 | foreach ($addthis_default_values as $key => $value) |
---|
226 | { |
---|
227 | if (!isset($this->my_config[$key])) $this->my_config[$key] = $value; |
---|
228 | if ($key = 'addthis_options') |
---|
229 | { |
---|
230 | foreach ($addthis_default_values[$key] as $subkey => $subvalue) |
---|
231 | if (!isset($this->my_config[$key][$subkey])) $this->my_config[$key][$subkey] = $subvalue; |
---|
232 | } |
---|
233 | |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | function restore_default_config() |
---|
238 | { |
---|
239 | include ADDTHIS_INC_PATH.'default_values.inc.php'; |
---|
240 | foreach ($addthis_default_values as $key => $value) |
---|
241 | { |
---|
242 | $this->my_config[$key] = $value; |
---|
243 | |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | |
---|
248 | function AddThis_admin_menu($menu) |
---|
249 | { |
---|
250 | array_push($menu, |
---|
251 | array( |
---|
252 | 'NAME' => 'AddThis', |
---|
253 | 'URL' => get_admin_plugin_menu_link(ADDTHIS_ADMIN_PATH.'AddThis_admin.php') |
---|
254 | ) |
---|
255 | ); |
---|
256 | return $menu; |
---|
257 | } |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | } |
---|
262 | |
---|
263 | ?> |
---|