PageRenderTime 64ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/share-this/sharethis.php

https://bitbucket.org/cblakebarber/circle_bastiat
PHP | 650 lines | 571 code | 47 blank | 32 comment | 60 complexity | 8804fed5cd2c6e56d1a501188551ba55 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. // ShareThis
  3. //
  4. // Copyright (c) 2010 ShareThis, Inc.
  5. // http://sharethis.com
  6. //
  7. //
  8. // Released under the GPL license
  9. // http://www.opensource.org/licenses/gpl-license.php
  10. //
  11. // This is an add-on for WordPress
  12. // http://wordpress.org/
  13. //
  14. // **********************************************************************
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. // *****************************************************************
  19. /*
  20. Plugin Name: ShareThis
  21. Plugin URI: http://sharethis.com
  22. Description: Let your visitors share a post/page with others. Supports e-mail and posting to social bookmarking sites. <a href="options-general.php?page=sharethis.php">Configuration options are here</a>. Questions on configuration, etc.? Make sure to read the README.
  23. Version: 5.0.0
  24. Author: ShareThis, Manu Mukerji <manu@sharethis.com>
  25. Author URI: http://sharethis.com
  26. */
  27. load_plugin_textdomain('sharethis');
  28. $_stversion=5.0;
  29. function install_ShareThis(){
  30. $publisher_id = get_option('st_pubid'); //pub key value
  31. $widget = get_option('st_widget'); //entire script tag
  32. $newUser=false;
  33. if (get_option('st_version') == '') {
  34. update_option('st_version', '5x');
  35. }
  36. if(empty($publisher_id)){
  37. if(!empty($widget)){
  38. $newPkey=getKeyFromTag();
  39. if($newPkey==false){
  40. $newUser=true;
  41. update_option('st_pubid',trim(makePkey()));
  42. }else{
  43. update_option('st_pubid',$newPkey); //pkey found set old key
  44. }
  45. }else{
  46. $newUser=true;
  47. update_option('st_pubid',trim(makePkey()));
  48. }
  49. }
  50. if($widget==false || !preg_match('/stLight.options/',$widget)){
  51. $pkey2=get_option('st_pubid');
  52. $widget ="<script charset=\"utf-8\" type=\"text/javascript\">var switchTo5x=true;</script>";
  53. $widget.="<script charset=\"utf-8\" type=\"text/javascript\" src=\"http://w.sharethis.com/button/buttons.js\"></script>";
  54. $widget.="<script type=\"text/javascript\">stLight.options({publisher:'$pkey2'});var st_type='wordpress".trim(get_bloginfo('version'))."';</script>";
  55. update_option('st_widget',$widget);
  56. }
  57. $st_sent=get_option('st_sent');
  58. $st_upgrade_five=get_option('st_upgrade_five');
  59. if(empty($st_sent)){
  60. update_option('st_sent','true');
  61. update_option('st_upgrade_five', '5x');
  62. $st_sent=get_option('st_sent'); //confirm if value has been set
  63. if(!(empty($st_sent))){
  64. sendWelcomeEmail($newUser);
  65. }
  66. $st_upgrade_five=get_option('st_upgrade_five');
  67. } else if (empty($st_upgrade_five)) {
  68. update_option('st_upgrade_five', '5x');
  69. $st_upgrade_five=get_option('st_upgrade_five'); //confirm if value has been set
  70. if(!(empty($st_upgrade_five))){
  71. sendUpgradeEmail();
  72. }
  73. }
  74. if (get_option('st_add_to_content') == '') {
  75. update_option('st_add_to_content', 'yes');
  76. }
  77. if (get_option('st_add_to_page') == '') {
  78. update_option('st_add_to_page', 'yes');
  79. }
  80. }
  81. function getKeyFromTag(){
  82. $widget = get_option('st_widget');
  83. $pattern = "/publisher\=([^\&\"]*)/";
  84. preg_match($pattern, $widget, $matches);
  85. $pkey = $matches[1];
  86. if(empty($pkey)){
  87. return false;
  88. }
  89. else{
  90. return $pkey;
  91. }
  92. }
  93. function getNewTag($oldTag){
  94. $pattern = '/(http\:\/\/*.*)[(\')|(\")]/';
  95. preg_match($pattern, $oldTag, $matches);
  96. $url=$matches[1];
  97. $pattern = '/(type=)/';
  98. preg_match($pattern, $url, $matches);
  99. if(empty($matches)){
  100. $url.="&amp;type=wordpress".get_bloginfo('version');
  101. }
  102. $qs=parse_url($url);
  103. if($qs['query']){
  104. $qs=$qs['query'];
  105. $newUrl="http://w.sharethis.com/button/sharethis.js#$qs";
  106. }
  107. else{
  108. $newUrl=$url;
  109. }
  110. return $newTag='<script type="text/javascript" charset="utf-8" src="'.$newUrl.'"></script>';
  111. }
  112. if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
  113. install_ShareThis();
  114. }
  115. function st_widget_head() {
  116. $widget = get_option('st_widget');
  117. if ($widget == '') {
  118. }
  119. else{
  120. //$widget = st_widget_add_wp_version($widget);
  121. $widget = st_widget_fix_domain($widget);
  122. $widget = preg_replace("/\&/", "&amp;", $widget);
  123. }
  124. print($widget);
  125. }
  126. function sendWelcomeEmail($newUser){
  127. $to=get_option('admin_email');
  128. $updatePage=get_option('siteurl');
  129. $updatePage.="/wp-admin/options-general.php?page=sharethis.php";
  130. $body = "The ShareThis plugin on your website has been activated on ".get_option('siteurl')."\n\n"
  131. ."If you would like to customize the look of your widget, go to the ShareThis Options page in your WordPress administration area. $updatePage\n\n"
  132. ."Get more information on customization options at http://help.sharethis.com/integration/wordpress."
  133. ."To get reporting on share data login to your account at http://sharethis.com/account and choose options in the Analytics section\n\n"
  134. ."If you have any additional questions or need help please email us at support@sharethis.com\n\n--The ShareThis Team";
  135. $subject = "ShareThis WordPress Plugin";
  136. if(empty($to)){
  137. return false;
  138. }
  139. if($newUser){
  140. $subject = "ShareThis WordPress Plugin Activation";
  141. $body ="Thanks for installing the ShareThis plugin on your blog.\n\n"
  142. ."If you would like to customize the look of your widget, go to the ShareThis Options page in your WordPress administration area. $updatePage\n\n"
  143. ."Get more information on customization options at http://help.sharethis.com/integration/wordpress.\n\n"
  144. ."If you have any additional questions or need help please email us at support@sharethis.com\n\n--The ShareThis Team";
  145. }
  146. $headers = "From: ShareThis Support <support@sharethis.com>\r\n" ."X-Mailer: php";
  147. update_option('st_sent','true');
  148. mail($to, $subject, $body, $headers);
  149. }
  150. function sendUpgradeEmail() {
  151. $to=get_option('admin_email');
  152. $updatePage=get_option('siteurl');
  153. $updatePage.="/wp-admin/options-general.php?page=sharethis.php";
  154. $body = "The ShareThis plugin on your website has been updated!\n\n"
  155. ."If you would like to customize the look of your widget, go to the ShareThis Options page in your WordPress administration area. $updatePage\n\n"
  156. ."Get more information on customization options at http://help.sharethis.com/integration/wordpress."
  157. ."To get reporting on share data login to your account at http://sharethis.com/account and choose options in the Analytics section\n\n"
  158. ."If you have any additional questions or need help please email us at support@sharethis.com\n\n--The ShareThis Team";
  159. $subject = "ShareThis WordPress Plugin Updated";
  160. if(empty($to)){
  161. return false;
  162. }
  163. $headers = "From: ShareThis Support <support@sharethis.com>\r\n" ."X-Mailer: php";
  164. update_option('st_sent','true');
  165. mail($to, $subject, $body, $headers);
  166. }
  167. function st_link() {
  168. global $post;
  169. $sharethis = '<p><a href="http://sharethis.com/item?&wp='
  170. .get_bloginfo('version').'&amp;publisher='
  171. .get_option('st_pubid').'&amp;title='
  172. .urlencode(get_the_title()).'&amp;url='
  173. .urlencode(get_permalink($post->ID)).'">ShareThis</a></p>';
  174. return $sharethis;
  175. }
  176. function sharethis_button() {
  177. echo st_makeEntries();
  178. }
  179. function st_remove_st_add_link($content) {
  180. remove_action('the_content', 'st_add_link');
  181. remove_action('the_content', 'st_add_widget');
  182. return $content;
  183. }
  184. function st_add_widget($content) {
  185. if ((is_page() && get_option('st_add_to_page') != 'no') || (!is_page() && get_option('st_add_to_content') != 'no')) {
  186. if (!is_feed()) {
  187. return $content.'<p>'.st_makeEntries().'</p>';
  188. }
  189. }
  190. return $content;
  191. }
  192. // 2006-06-02 Renamed function from st_add_st_link() to st_add_feed_link()
  193. function st_add_feed_link($content) {
  194. if (is_feed()) {
  195. $content .= st_link();
  196. }
  197. return $content;
  198. }
  199. // 2006-06-02 Filters to Add Sharethis widget on content and/or link on RSS
  200. // 2006-06-02 Expected behavior is that the feed link will show up if an option is not 'no'
  201. if (get_option('st_add_to_content') != 'no' || get_option('st_add_to_page') != 'no') {
  202. add_filter('the_content', 'st_add_widget');
  203. // 2008-08-15 Excerpts don't play nice due to strip_tags().
  204. add_filter('get_the_excerpt', 'st_remove_st_add_link',9);
  205. add_filter('the_excerpt', 'st_add_widget');
  206. }
  207. function st_widget_fix_domain($widget) {
  208. return preg_replace(
  209. "/\<script\s([^\>]*)src\=\"http\:\/\/sharethis/"
  210. , "<script $1src=\"http://w.sharethis"
  211. , $widget
  212. );
  213. }
  214. function st_widget_add_wp_version($widget) {
  215. preg_match("/([\&\?])wp\=([^\&\"]*)/", $widget, $matches);
  216. if ($matches[0] == "") {
  217. $widget = preg_replace("/\"\>\s*\<\/\s*script\s*\>/", "&wp=".get_bloginfo('version')."\"></script>", $widget);
  218. $widget = preg_replace("/widget\/\&wp\=/", "widget/?wp=", $widget);
  219. }
  220. else {
  221. $widget = preg_replace("/([\&\?])wp\=([^\&\"]*)/", "$1wp=".get_bloginfo('version'), $widget);
  222. }
  223. return $widget;
  224. }
  225. if (!function_exists('ak_can_update_options')) {
  226. function ak_can_update_options() {
  227. if (function_exists('current_user_can')) {
  228. if (current_user_can('manage_options')) {
  229. return true;
  230. }
  231. }
  232. else {
  233. global $user_level;
  234. get_currentuserinfo();
  235. if ($user_level >= 8) {
  236. return true;
  237. }
  238. }
  239. return false;
  240. }
  241. }
  242. function st_request_handler() {
  243. if (!empty($_REQUEST['st_action'])) {
  244. switch ($_REQUEST['st_action']) {
  245. case 'st_update_settings':
  246. if (ak_can_update_options()) {
  247. if (!empty($_POST['st_widget'])) { // have widget
  248. $widget = stripslashes($_POST['st_widget']);
  249. $widget = preg_replace("/\&amp;/", "&", $widget);
  250. if(!preg_match('/buttons.js/',$widget)){
  251. $pattern = "/publisher\=([^\&\"]*)/";
  252. preg_match($pattern, $widget, $matches);
  253. if ($matches[0] == "") { // widget does not have publisher parameter at all
  254. $publisher_id = get_option('st_pubid');
  255. if ($publisher_id != "") {
  256. $widget = preg_replace("/\"\>\s*\<\/\s*script\s*\>/", "&publisher=".$publisher_id."\"></script>", $widget);
  257. $widget = preg_replace("/widget\/\&publisher\=/", "widget/?publisher=", $widget);
  258. }
  259. }
  260. elseif ($matches[1] == "") { // widget does not have pubid in publisher parameter
  261. $publisher_id = get_option('st_pubid');
  262. if ($publisher_id != "") {
  263. $widget = preg_replace("/([\&\?])publisher\=/", "$1publisher=".$publisher_id, $widget);
  264. } else {
  265. $widget = preg_replace("/([\&\?])publisher\=/", "$1publisher=".$publisher_id, $widget);
  266. }
  267. } else { // widget has pubid in publisher parameter
  268. $publisher_id = get_option('st_pubid');
  269. if ($publisher_id != "") {
  270. if ($publisher_id != $matches[1]) {
  271. $publisher_id = $matches[1];
  272. }
  273. } else {
  274. $publisher_id = $matches[1];
  275. }
  276. }
  277. }else{
  278. $publisher_id = get_option('st_pubid');
  279. $pkeyUpdated=false;
  280. if(!empty($_POST['st_pkey']) && $publisher_id!==$_POST['st_pkey'] ){
  281. update_option('st_pubid', $_POST['st_pkey']);
  282. $publisher_id=$_POST['st_pkey'];
  283. $pkeyUpdated=true;
  284. }
  285. if(!preg_match('/stLight.options/',$widget) || $pkeyUpdated==true){
  286. $widget="<script charset=\"utf-8\" type=\"text/javascript\" src=\"http://w.sharethis.com/button/buttons.js\"></script>";
  287. $widget.="<script type=\"text/javascript\">stLight.options({publisher:'$publisher_id'});var st_type='wordpress".trim(get_bloginfo('version'))."';</script>";
  288. update_option('st_widget',$widget);
  289. }
  290. }
  291. }
  292. else { // does not have widget
  293. $publisher_id = get_option('st_pubid');
  294. }
  295. preg_match("/\<script\s[^\>]*charset\=\"utf\-8\"[^\>]*/", $widget, $matches);
  296. if ($matches[0] == "") {
  297. preg_match("/\<script\s[^\>]*charset\=\"[^\"]*\"[^\>]*/", $widget, $matches);
  298. if ($matches[0] == "") {
  299. $widget = preg_replace("/\<script\s/", "<script charset=\"utf-8\" ", $widget);
  300. }
  301. else {
  302. $widget = preg_replace("/\scharset\=\"[^\"]*\"/", " charset=\"utf-8\"", $widget);
  303. }
  304. }
  305. preg_match("/\<script\s[^\>]*type\=\"text\/javascript\"[^\>]*/", $widget, $matches);
  306. if ($matches[0] == "") {
  307. preg_match("/\<script\s[^\>]*type\=\"[^\"]*\"[^\>]*/", $widget, $matches);
  308. if ($matches[0] == "") {
  309. $widget = preg_replace("/\<script\s/", "<script type=\"text/javascript\" ", $widget);
  310. }
  311. else {
  312. $widget = preg_replace("/\stype\=\"[^\"]*\"/", " type=\"text/javascript\"", $widget);
  313. }
  314. }
  315. //update st_version to figure out which widget to use.
  316. if(!empty($_POST['st_version'])) {
  317. update_option('st_version', $_POST['st_version']);
  318. if (($_POST['st_version']) == '5x') {
  319. if (strpos($widget, "switchTo5x=true")) {
  320. } else if (strpos($widget, "switchTo5x=false")) {
  321. $widget = preg_replace("/switchTo5x=false/", "switchTo5x=true", $widget);
  322. } else {
  323. $widget = "<script charset=\"utf-8\" type=\"text/javascript\">var switchTo5x=true;</script>" . $widget;
  324. }
  325. } elseif (($_POST['st_version']) == '4x') {
  326. $widget = preg_replace("/switchTo5x=true/", "switchTo5x=false", $widget);
  327. }
  328. }
  329. // note: do not convert & to &amp; or append WP version here
  330. $widget = st_widget_fix_domain($widget);
  331. update_option('st_pubid', $publisher_id);
  332. update_option('st_widget', $widget);
  333. if(!empty($_POST['st_pkey'])){
  334. update_option('st_pubid', $_POST['st_pkey']);
  335. }
  336. if(!empty($_POST['st_tags'])){
  337. $tagsin=$_POST['st_tags'];
  338. $tagsin=preg_replace("/\\n|\\t/","</span>", $tagsin);
  339. $tagsin=preg_replace("/\\\'/","'", $tagsin);
  340. //$tagsin=htmlspecialchars_decode($tagsin);
  341. $tagsin=trim($tagsin);
  342. update_option('st_tags',$tagsin);
  343. }
  344. if(!empty($_POST['st_services'])){
  345. update_option('st_services', trim($_POST['st_services'],",") );
  346. }
  347. if(!empty($_POST['st_current_type'])){
  348. update_option('st_current_type', trim($_POST['st_current_type'],",") );
  349. }
  350. $options = array(
  351. 'st_add_to_content'
  352. , 'st_add_to_page'
  353. );
  354. foreach ($options as $option) {
  355. if (isset($_POST[$option]) && in_array($_POST[$option], array('yes', 'no'))) {
  356. update_option($option, $_POST[$option]);
  357. }
  358. }
  359. header('Location: '.get_bloginfo('wpurl').'/wp-admin/options-general.php?page=sharethis.php&updated=true');
  360. die();
  361. }
  362. break;
  363. }
  364. }
  365. }
  366. function st_options_form() {
  367. $publisher_id = get_option('st_pubid');
  368. $services = get_option('st_services');
  369. $tags = get_option('st_tags');
  370. $st_current_type=get_option('st_current_type');
  371. $st_widget_version = get_option('st_version');
  372. $st_prompt = get_option('st_prompt');
  373. if(empty($st_current_type)){
  374. $st_current_type="_buttons";
  375. }
  376. if(empty($services)){
  377. $services="facebook,twitter,email,sharethis";
  378. }
  379. if(empty($st_prompt)){
  380. $services.=",fblike,plusone";
  381. update_option('st_prompt', 'true');
  382. }
  383. if(empty($tags)){
  384. foreach(explode(',',$services) as $svc){
  385. $tags.="<span class='st_".$svc."_vcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span>";
  386. }
  387. }
  388. if(empty($st_widget_version)){
  389. $st_widget_version="4x";
  390. }
  391. $fourCheck = $st_widget_version == "4x" ? 'checked="checked"' : "";
  392. $fiveCheck = $st_widget_version == "5x" ? 'checked="checked"' : "";
  393. $fourTag = $st_widget_version == "4x" ? 'versionSelect' : "";
  394. $fiveTag = $st_widget_version == "5x" ? 'versionSelect' : "";
  395. $wImage = $fiveTag == "" ? 'Image_Classic-1.png' : 'Image_Multi_Post-1.png';
  396. if(empty($publisher_id)){
  397. $toShow="";
  398. }
  399. else{
  400. $toShow=get_option('st_widget');
  401. }
  402. print('
  403. <script type="text/javascript" src="http://w.sharethis.com/widget/jquery-1.4.2.min.js"></script>
  404. <script type="text/javascript" src="http://w.sharethis.com/widget/jquery.carousel.min.js"></script>
  405. <script type="text/javascript">
  406. var _gaq = _gaq || [];
  407. _gaq.push(["_setAccount", "UA-1645146-1"]);
  408. _gaq.push(["_trackPageview"]);
  409. (function() {
  410. var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
  411. ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
  412. var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
  413. })();
  414. </script>
  415. <link rel="stylesheet" href="http://w.sharethis.com/widget/wp_ex.css" type="text/css" media="screen" />
  416. <div class="wrap">
  417. <h2>'.__('ShareThis Options', 'sharethis').'</h2>
  418. <div style="padding:10px;border:1px solid #aaa;background-color:#9fde33;text-align:center;display:none;" id="st_updated">Your options were successfully updated</div>
  419. <form id="ak_sharethis" name="ak_sharethis" action="'.get_bloginfo('wpurl').'/wp-admin/index.php" method="post">
  420. <fieldset class="options">
  421. <div class="st_options">
  422. <div class="carousel_div">
  423. <span class="heading">Choose the display style for your social buttons.<br/>Selected Choice: <span id="curr_type" style="display:none"></span><span id="currentType"></span></span>
  424. <ul id="carousel" class="jcarousel-skin-tango">
  425. <li st_type="large"><div class="buttonType">Large Icons (1/7)</div><img src="http://w.sharethis.com/images/wp_ex4.png" alt="" /></li>
  426. <li st_type="hcount"><div class="buttonType">Horizontal Count (2/7)</div><img src="http://w.sharethis.com/images/wp_ex2.png" alt="" /></li>
  427. <li st_type="vcount"><div class="buttonType">Vertical Count (3/7)</div><img src="http://w.sharethis.com/images/wp_ex1.png" alt="" /></li>
  428. <li st_type="sharethis"><div class="buttonType">Classic (4/7)</div><img src="http://w.sharethis.com/images/wp_ex7.png" alt="" /></li>
  429. <li st_type="chicklet"><div class="buttonType">Regular Buttons (5/7)</div><img src="http://w.sharethis.com/images/wp_ex5.png" alt="" /></li>
  430. <li st_type="chicklet2"><div class="buttonType">Regular Button No-Text (6/7)</div><img src="http://w.sharethis.com/images/wp_ex6.png" alt="" /></li>
  431. <li st_type="buttons"><div class="buttonType">Buttons (7/7)</div><img src="http://w.sharethis.com/images/wp_ex3.png" alt="" /></li>
  432. </ul>
  433. </div>
  434. <br/>
  435. <div class="fblikeplusone">
  436. <span class="heading">Include Facebook Like and Google +1.<br/></span><br/>
  437. <label>Add Facebook Like</label>
  438. <input type="checkbox" id="st_fblike" name="st_fblike" value="1" ></input>
  439. <label>Add Google +1</label>
  440. <input type="checkbox" id="st_plusone" name="st_plusone" value="1" ></input>
  441. </div>
  442. <br/>
  443. <div class="version">
  444. <span class="heading">Choose which version of the widget you would like to use:</span><br /><br />
  445. <label>Multi-Post</label>
  446. <input type="radio" id="get5x" ' . $fiveCheck . ' name="st_version" value="5x" class="versionItem '.$fiveTag.'" onclick="$(\'.versionImage\').attr(\'src\', \'http://www.sharethis.com/images/Image_Multi_Post-1.png\');"></input>
  447. <label>Classic</label>
  448. <input type="radio" id="get4x" ' . $fourCheck . ' name="st_version" value="4x" class="versionItem '.$fourTag.'" onclick="$(\'.versionImage\').attr(\'src\', \'http://www.sharethis.com/images/Image_Classic-1.png\');"></input>
  449. <br />
  450. <img class="versionImage" src="http://www.sharethis.com/images/' . $wImage . '"></img>
  451. </div>
  452. <br />
  453. <div class="services">
  454. <span class="heading" onclick="javascript:$(\'#st_services\').toggle(\'slow\');"><span class="headingimg">[+]</span>Click to change order of social buttons or modify list of buttons.</span>&nbsp;(<a href="http://help.sharethis.com/customization/chicklets#supported-services" target="_blank">?</a>)<br/>
  455. <textarea name="st_services" id="st_services" style="height: 30px; width: 400px;">'.htmlspecialchars($services).'</textarea>
  456. </div>
  457. <br/>
  458. <div class="tags">
  459. <span class="heading" onclick="javascript:$(\'#st_tags\').toggle(\'slow\');"><span class="headingimg">[+]</span>Click to view/modify the HTML tags.</span><br/>
  460. <textarea name="st_tags" id="st_tags" style="height: 100px; width: 500px;">'.htmlspecialchars(preg_replace("/<\/span>/","</span>\n", $tags)).'</textarea>
  461. </div>
  462. <br/>
  463. <div class="widget_code">
  464. <span class="heading" onclick="javascript:$(\'#st_widget\').toggle(\'slow\');">
  465. <span class="headingimg">[+]</span>
  466. Click to modify other widget options.
  467. </span>
  468. <br/>
  469. <textarea id="st_widget" name="st_widget" style="height: 80px; width: 500px;">'.htmlspecialchars($toShow).'</textarea>
  470. </div>
  471. <br/>
  472. <div>
  473. <span class="heading" onclick="javascript:$(\'#st_pkey\').toggle(\'slow\');"><span class="headingimg">[+]</span>Your Publisher Key:</span><br/>
  474. <textarea name="st_pkey" id="st_pkey" style="height: 30px; width: 400px;">'.htmlspecialchars($publisher_id).'</textarea>
  475. </div>
  476. <input type="hidden" id="st_current_type" name="st_current_type" value="'.$st_current_type.'"/>
  477. </div>
  478. <script type="text/javascript">var st_current_type="'.$st_current_type.'";</script>
  479. ');
  480. $plugin_location=WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
  481. $opt_js_location=$plugin_location."wp_st_opt.js";
  482. print("<script type=\"text/javascript\" src=\"$opt_js_location\"></script>");
  483. $options = array(
  484. 'st_add_to_content' => __('Automatically add ShareThis to your posts?*', 'sharethis')
  485. , 'st_add_to_page' => __('Automatically add ShareThis to your pages?*', 'sharethis')
  486. );
  487. foreach ($options as $option => $description) {
  488. $$option = get_option($option);
  489. if (empty($$option) || $$option == 'yes') {
  490. $yes = ' selected="selected"';
  491. $no = '';
  492. }
  493. else {
  494. $yes = '';
  495. $no = ' selected="selected"';
  496. }
  497. print('
  498. <p>
  499. <label for="'.$option.'">'.$description.'</label>
  500. <select name="'.$option.'" id="'.$option.'">
  501. <option value="yes"'.$yes.'>'.__('Yes', 'sharethis').'</option>
  502. <option value="no"'.$no.'>'.__('No', 'sharethis').'</option>
  503. </select>
  504. </p>
  505. ');
  506. }
  507. echo '<br/><p>To learn more about other sharing features and available options, visit our <a href="http://help.sharethis.com/integration/wordpress" target="_blank">help center</a>.</p>';
  508. print('
  509. </fieldset>
  510. <p class="submit">
  511. <input type="submit" onclick="st_log();" name="submit_button" value="'.__('Update ShareThis Options', 'sharethis').'" />
  512. </p>
  513. <input type="hidden" name="st_action" value="st_update_settings" />
  514. </form>
  515. </div>
  516. ');
  517. }
  518. function st_menu_items() {
  519. if (ak_can_update_options()) {
  520. add_options_page(
  521. __('ShareThis Options', 'sharethis')
  522. , __('ShareThis', 'sharethis')
  523. , manage_options
  524. , basename(__FILE__)
  525. , 'st_options_form'
  526. );
  527. }
  528. }
  529. function st_makeEntries(){
  530. global $post;
  531. //$st_json='{"type":"vcount","services":"sharethis,facebook,twitter,email"}';
  532. $out="";
  533. $widget=get_option('st_widget');
  534. $tags=get_option('st_tags');
  535. if(!empty($widget)){
  536. if(preg_match('/buttons.js/',$widget)){
  537. if(!empty($tags)){
  538. $tags=preg_replace("/\\\'/","'", $tags);
  539. $tags=preg_replace("/<\?php the_permalink\(\); \?>/",get_permalink($post->ID), $tags);
  540. $tags=preg_replace("/<\?php the_title\(\); \?>/",strip_tags(get_the_title()), $tags);
  541. $tags=preg_replace("/{URL}/",get_permalink($post->ID), $tags);
  542. $tags=preg_replace("/{TITLE}/",strip_tags(get_the_title()), $tags);
  543. }else{
  544. $tags="<span class='st_sharethis' st_title='".strip_tags(get_the_title())."' st_url='".get_permalink($post->ID)."' displayText='ShareThis'></span>";
  545. $tags="<span class='st_facebook_buttons' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span><span class='st_twitter_buttons' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span><span class='st_email_buttons' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span><span class='st_sharethis_buttons' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span><span class='st_fblike_buttons' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span><span class='st_plusone_buttons' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span>";
  546. $tags=preg_replace("/<\?php the_permalink\(\); \?>/",get_permalink($post->ID), $tags);
  547. $tags=preg_replace("/<\?php the_title\(\); \?>/",strip_tags(get_the_title()), $tags);
  548. }
  549. $out=$tags;
  550. }else{
  551. $out = '<script type="text/javascript">SHARETHIS.addEntry({ title: "'.strip_tags(get_the_title()).'", url: "'.get_permalink($post->ID).'" });</script>';
  552. }
  553. }
  554. return $out;
  555. }
  556. function makePkey(){
  557. return "wp.".sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),mt_rand( 0, 0x0fff ) | 0x4000,mt_rand( 0, 0x3fff ) | 0x8000,mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) );
  558. }
  559. add_action('wp_head', 'st_widget_head');
  560. add_action('init', 'st_request_handler', 9999);
  561. add_action('admin_menu', 'st_menu_items');
  562. ?>