1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function wikiplugin_sharethis_info() 9{ 10 return [ 11 'name' => tra('ShareThis'), 12 'documentation' => 'PluginSharethis', 13 'description' => tra('Add a ShareThis button'), 14 'prefs' => [ 'wikiplugin_sharethis' ], 15 'iconname' => 'sharethis', 16 'introduced' => 3, 17 'tags' => [ 'basic' ], 18 'params' => [ 19 'sendsvcs' => [ 20 'required' => false, 21 'name' => tra('Send Services'), 22 'description' => tr('By default, %0email%1, %0aim%1 and %0sms%1 are available. Input one or two of the 23 services separated by a %0|%1 to limit the choice of send services.', '<code>', '</code>'), 24 'since' => '3.2', 25 'default' => '', 26 'advanced' => true, 27 'separator' => '|', 28 'filter' => 'word', 29 'options' => [ 30 ['text' => '', 'value' => ''], 31 ['text' => tra('AIM'), 'value' => 'aim'], 32 ['text' => tra('AIM and Email'), 'value' => 'aim|email'], 33 ['text' => tra('AIM and SMS'), 'value' => 'aim|sms'], 34 ['text' => tra('Email'), 'value' => 'email'], 35 ['text' => tra('Email and SMS'), 'value' => 'email|sms'], 36 ] 37 ], 38 'style' => [ 39 'required' => false, 40 'name' => tra('Button Style'), 41 'description' => tra('Set button style.'), 42 'since' => '5.0', 43 'default' => '', 44 'filter' => 'word', 45 'options' => [ 46 ['text' => tra(''), 'value' => ''], 47 ['text' => tra('Horizontal'), 'value' => 'horizontal'], 48 ['text' => tra('Vertical'), 'value' => 'vertical'], 49 ['text' => tra('Rotate'), 'value' => 'rotate'] 50 ] 51 ], 52 'rotateimage' => [ 53 'required' => false, 54 'name' => tra('Rotate Image'), 55 'description' => tr('A value of %0y%1 (Yes) will cause the button icon to rotate every 3 seconds between 56 a few icons, cycling through twice before stopping.', '<code>', '</code>'), 57 'since' => '3.2', 58 'default' => '', 59 'filter' => 'alpha', 60 'options' => [ 61 ['text' => '', 'value' => ''], 62 ['text' => tra('Yes'), 'value' => 'y'], 63 ['text' => tra('No'), 'value' => 'n'] 64 ] 65 ], 66 'multiple' => [ 67 'required' => false, 68 'name' => tra('Multiple Icons'), 69 'description' => tr( 70 'Enter pipe-separated list of services, e.g., %0.', 71 '<code>email|facebook|twitter|sharethis</code>' 72 ), 73 'since' => '5.0', 74 'separator' => '|', 75 'filter' => 'word', 76 'default' => '', 77 ], 78 'postfirst' => [ 79 'required' => false, 80 'name' => tra('First Services Shown'), 81 'description' => tr('Input a list of post services (like %0Facebook|Myspace|Digg%1, etc.) separated by a 82 %0|%1 to customize the services that are shown in the opening panel of the widget.', '<code>', '</code>'), 83 'since' => '3.2', 84 'separator' => '|', 85 'filter' => 'word', 86 'advanced' => true, 87 'default' => '', 88 ], 89 'buttontext' => [ 90 'required' => false, 91 'name' => tra('Button Text'), 92 'description' => tra('Custom link text for the button.'), 93 'since' => '3.2', 94 'filter' => 'text', 95 'default' => '', 96 ], 97 'headertitle' => [ 98 'required' => false, 99 'name' => tra('Header Title'), 100 'description' => tra('Optional header title text for the widget.'), 101 'since' => '3.2', 102 'filter' => 'text', 103 'default' => '', 104 ], 105 'headerbg' => [ 106 'required' => false, 107 'name' => tra('Header Background'), 108 'description' => tra('HTML color code (not color name) for the background color for the header if an 109 optional header title is used.'), 110 'since' => '3.0', 111 'advanced' => true, 112 'filter' => 'text', 113 'default' => '', 114 ], 115 'headertxtcolor' => [ 116 'required' => false, 117 'name' => tra('Header Text Color'), 118 'description' => tra('HTML color code (not color name) for the header text if an optional header title is used.'), 119 'since' => '3.2', 120 'advanced' => true, 121 'filter' => 'text', 122 'default' => '', 123 ], 124 'linkfg' => [ 125 'required' => false, 126 'name' => tra('Link text color for services'), 127 'description' => tra('HTML color code (not color name) for the link text for all send and post services shown in the widget'), 128 'since' => '3.0', 129 'advanced' => true, 130 'filter' => 'text', 131 'default' => '', 132 ], 133 'popup' => [ 134 'required' => false, 135 'name' => tra('Popup'), 136 'description' => tra('Set whether the widget will show in a popup window.'), 137 'since' => '3.0', 138 'advanced' => true, 139 'filter' => 'word', 140 'default' => '', 141 'options' => [ 142 ['text' => '', 'value' => ''], 143 ['text' => tra('No'), 'value' => ''], 144 ['text' => tra('Yes'), 'value' => 'true'], 145 ] 146 ], 147 'embed' => [ 148 'required' => false, 149 'name' => tra('Embedded Elements'), 150 'description' => tra('Allow embedded elements (like flash) to be seen while iframe is loading.'), 151 'since' => '3.0', 152 'advanced' => true, 153 'filter' => 'word', 154 'default' => '', 155 'options' => [ 156 ['text' => '', 'value' => ''], 157 ['text' => tra('No'), 'value' => ''], 158 ['text' => tra('Yes'), 'value' => 'true'], 159 ] 160 ], 161 ] 162 ]; 163} 164function wikiplugin_sharethis($data, $params) 165{ 166 $headerlib = TikiLib::lib('header'); 167 extract($params, EXTR_SKIP); 168 $sharethis_options = []; 169 $iconcode = ''; 170 $sep = '&'; 171 $comma = '%2C'; 172 $lb = '%23'; 173 $sp = '%20'; 174 175 // The following is the array that holds the default options for the plugin. 176 $sharethis_options['type'] = 'website'; 177 $sharethis_options['sendsvcs'] = ''; 178 $sharethis_options['style'] = ''; 179 $sharethis_options['buttontext'] = ''; 180 $sharethis_options['postfirst'] = ''; 181 $sharethis_options['headertitle'] = ''; 182 $sharethis_options['headerbg'] = ''; 183 $sharethis_options['headertxtcolor'] = ''; 184 $sharethis_options['linkfg'] = ''; 185 $sharethis_options['popup'] = ''; 186 $sharethis_options['embed'] = ''; 187 188 // load setting options from $params 189 190 // set post services that appear upon widget opening 191 if (! empty($postfirst)) { 192 $sharethis_options['postfirst'] = str_replace('|', $comma, $postfirst); 193 } 194 // limit send services that will appear 195 if (! empty($sendsvcs)) { 196 $sharethis_options['sendsvcs'] = str_replace('|', $comma, $sendsvcs); 197 } 198 // set icon style 199 if (! empty($rotateimage) || ! empty($style)) { 200 if ($rotateimage == 'y' || $style == 'rotate') { 201 $sharethis_options['style'] = 'rotate'; 202 } elseif ($style == 'horizontal') { 203 $sharethis_options['style'] = 'horizontal'; 204 } elseif ($style == 'vertical') { 205 $sharethis_options['style'] = 'vertical'; 206 } 207 } 208 if (! empty($multiple)) { 209 $headerlib->add_css('body {font-family:helvetica,sans-serif;font-size:12px;}'); 210 $headerlib->add_css('a.stbar.chicklet img {border:0;height:16px;width:16px;margin-right:3px;vertical-align:middle;}'); 211 $headerlib->add_css('a.stbar.chicklet {height:16px;line-height:16px;}'); 212 $icons = explode('|', $multiple); 213 foreach ($icons as $icon) { 214 $iconcode .= '<a id="ck_' . $icon . '" class="stbar chicklet" href="javascript:void(0);">' 215 . '<img src="https://ws.sharethis.com/chicklets/' . $icon . '.gif" style="margin-right:3px;" />'; 216 if ($icon == 'sharethis') { 217 $iconcode .= 'ShareThis'; 218 } 219 $iconcode .= '</a>'; 220 } 221 $headerlib->add_js( 222 ' var shared_object = SHARETHIS.addEntry({ 223 title: document.title, 224 url: document.location.href 225 }); 226 227 shared_object.attachButton(document.getElementById("ck_sharethis")); 228 shared_object.attachChicklet("email", document.getElementById("ck_email")); 229 shared_object.attachChicklet("facebook", document.getElementById("ck_facebook")); 230 shared_object.attachChicklet("twitter", document.getElementById("ck_twitter"));' 231 ); 232 } 233 234 // set button text 235 if (! empty($buttontext)) { 236 $sharethis_options['buttontext'] = $buttontext; 237 } 238 // set header title text. If header title is set by user, then set background color and text color 239 if (! empty($headertitle)) { 240 $sharethis_options['headertitle'] = str_replace(' ', $sp, $headertitle); 241 if (! empty($headerbg)) { 242 $sharethis_options['headerbg'] = $headerbg; 243 } 244 if (! empty($headertxtcolor)) { 245 $sharethis_options['headertxtcolor'] = $headertxtcolor; 246 } 247 } else { 248 $sharethis_options['headerbg'] = ''; 249 $sharethis_options['headertxtcolor'] = ''; 250 } 251 // set link text color for services shown in popup 252 if (! empty($linkfg)) { 253 $sharethis_options['linkfg'] = $linkfg; 254 } 255 // set popup 256 if (! empty($popup)) { 257 $sharethis_options['popup'] = $popup; 258 } 259 // set embed 260 if (! empty($embed)) { 261 $sharethis_options['embed'] = $embed; 262 } 263 264 // put all the options together 265 266 $sharethiscode = "~hc~ ))ShareThis(( Bookmark Button BEGIN ~/hc~"; 267 $sharethiscode .= '<script type="text/javascript" src="https://ws.sharethis.com/button/sharethis.js#'; 268 $sharethiscode .= "type=" . $sharethis_options['type']; 269 270 if (! empty($sharethis_options['buttontext'])) { 271 $sharethiscode .= $sep . "buttonText=" . $sharethis_options['buttontext']; 272 } 273 if (! empty($sharethis_options['popup'])) { 274 $sharethiscode .= $sep . "popup=" . $sharethis_options['popup']; 275 } 276 if (! empty($sharethis_options['embed'])) { 277 $sharethiscode .= $sep . "embeds=" . $sharethis_options['embed']; 278 } 279 if (! empty($sharethis_options['style'])) { 280 $sharethiscode .= $sep . "style=" . $sharethis_options['style']; 281 } 282 if (! empty($sharethis_options['sendsvcs'])) { 283 $sharethiscode .= $sep . "send_services=" . $sharethis_options['sendsvcs']; 284 } 285 if (! empty($sharethis_options['postfirst'])) { 286 $sharethiscode .= $sep . "post_services=" . $sharethis_options['postfirst']; 287 } 288 if (! empty($sharethis_options['headertxtcolor'])) { 289 $sharethiscode .= $sep . "headerfg=" . $lb . $sharethis_options['headertxtcolor']; 290 } 291 if (! empty($sharethis_options['headerbg'])) { 292 $sharethiscode .= $sep . "headerbg=" . $lb . $sharethis_options['headerbg']; 293 } 294 if (! empty($sharethis_options['linkfg'])) { 295 $sharethiscode .= $sep . "linkfg=" . $lb . $sharethis_options['linkfg']; 296 } 297 if (! empty($sharethis_options['headertitle'])) { 298 $sharethiscode .= $sep . "headerTitle=" . $sharethis_options['headertitle']; 299 } 300 if (! empty($iconcode)) { 301 $sharethiscode .= ';button=false'; 302 } 303 $sharethiscode .= "\"></script>\n"; 304 if (! empty($iconcode)) { 305 $sharethiscode .= $iconcode; 306 } 307 $sharethiscode .= "~hc~ ))ShareThis(( Bookmark Button END ~/hc~"; 308 309 $result = $sharethiscode; 310 311 return $result; 312} 313