PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/digg-digg/include/dd-class.php

https://github.com/lloyddobbler/diggdigg
PHP | 2122 lines | 1457 code | 503 blank | 162 comment | 46 complexity | 2e42e73ef908bad58f1dcfb0c220ddcc MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // XXX: NEW BUTTONS: Extend this base class. Set defaults as class properties
  3. class BaseDD {
  4. //String for replacement.
  5. const VOTE_URL = 'VOTE_URL';
  6. const VOTE_TITLE = 'VOTE_TITLE';
  7. const VOTE_IMAGE = 'VOTE_IMAGE';
  8. const VOTE_BUTTON_DESIGN = 'VOTE_BUTTON_DESIGN';
  9. const SCHEDULER_TIMER = 'SCHEDULER_TIMER';
  10. const POST_ID = 'POST_ID';
  11. const VOTE_BUTTON_DESIGN_LAZY_WIDTH = 'VOTE_BUTTON_DESIGN_LAZY_WIDTH';
  12. const VOTE_BUTTON_DESIGN_LAZY_HEIGHT = 'VOTE_BUTTON_DESIGN_LAZY_HEIGHT';
  13. //default value
  14. const DEFAULT_APPEND_TYPE = 'none';
  15. const DEFAULT_OPTION_AJAX = 'false';
  16. const DEFAULT_BUTTON_DESIGN = 'Normal';
  17. const DEFAULT_BUTTON_WEIGHT = '100';
  18. // define properties
  19. var $name; //name of the vote button
  20. var $websiteURL; //website URL
  21. var $apiURL; //Button API for development
  22. var $baseURL; // vote button URL, before construt
  23. var $baseURL_lazy; // vote button URL, before construt, lazy version
  24. var $baseURL_lazy_script; // jQuery script , lazy version
  25. var $scheduler_lazy_script; //scheduler function
  26. var $scheduler_lazy_timer; //miliseconds
  27. var $finalURL; //final URL for display, after constructs
  28. var $finalURL_lazy;//final lazy URL for display, after constructs
  29. var $finalURL_lazy_script;//final jQuery, after constructs
  30. var $final_scheduler_lazy_script; //final scheduler, after constructs
  31. var $isEncodeRequired = true; //is URL or title need encode?
  32. var $islazyLoadAvailable = true; //is lazy load avaliable?
  33. //contains DD option value, in array
  34. var $wp_options;
  35. var $option_append_type;
  36. var $option_button_design;
  37. var $option_button_weight;
  38. var $option_ajax_left_float;
  39. var $option_lazy_load;
  40. var $button_weight_value;
  41. //default float button design
  42. var $float_button_design = self::DEFAULT_BUTTON_DESIGN;
  43. //default button layout, suit in most cases
  44. var $buttonLayout = array(
  45. "Normal" => "Normal",
  46. "Compact" => "Compact"
  47. );
  48. // Default options
  49. var $append_type = 'none';
  50. var $button_design = 'Normal';
  51. var $ajax_left_float = false;
  52. var $lazy_load = false;
  53. public function getButtonDesign($button){
  54. return $this->buttonLayout[$button];
  55. }
  56. //default lazy button layout, suit in most cases
  57. var $buttonLayoutLazy = array(
  58. "Normal" => "Normal",
  59. "Compact" => "Compact"
  60. );
  61. public function getButtonDesignLazy($button){
  62. return $this->buttonLayoutLazy[$button];
  63. }
  64. var $buttonLayoutLazyWidth = array(
  65. "Normal" => "51",
  66. "Compact" => "120"
  67. );
  68. public function getButtonDesignLazyWidth($button){
  69. return $this->buttonLayoutLazyWidth[$button];
  70. }
  71. var $buttonLayoutLazyHeight = array(
  72. "Normal" => "69",
  73. "Compact" => "22"
  74. );
  75. public function getButtonDesignLazyHeight($button){
  76. return $this->buttonLayoutLazyHeight[$button];
  77. }
  78. function BaseDD($name, $websiteURL, $apiURL, $baseURL) {
  79. $this->name = $name;
  80. $this->websiteURL = $websiteURL;
  81. $this->apiURL = $apiURL;
  82. $this->baseURL = $baseURL;
  83. $this->initWPOptions();
  84. }
  85. private function initWPOptions() {
  86. $this->wp_options = array();
  87. // XXX: Set default options in the subclass
  88. $this->wp_options[$this->option_append_type] = $this->append_type;
  89. //$this->wp_options[$this->option_append_type] = self::DEFAULT_APPEND_TYPE;
  90. $this->wp_options[$this->option_button_design] = $this->button_design;
  91. //$this->wp_options[$this->option_button_design] = self::DEFAULT_BUTTON_DESIGN;
  92. $this->wp_options[$this->option_ajax_left_float] = $this->ajax_left_float;
  93. //$this->wp_options[$this->option_ajax_left_float] = self::DEFAULT_OPTION_AJAX;
  94. $this->wp_options[$this->option_lazy_load] = $this->lazy_load;
  95. //$this->wp_options[$this->option_lazy_load] = self::DEFAULT_OPTION_AJAX;
  96. $this->wp_options[$this->option_button_weight] = $this->button_weight_value;
  97. }
  98. public function getOptionLazyLoad(){
  99. return $this->wp_options[$this->option_lazy_load];
  100. }
  101. public function getOptionAjaxLeftFloat(){
  102. return $this->wp_options[$this->option_ajax_left_float];
  103. }
  104. public function getOptionButtonWeight(){
  105. return $this->wp_options[$this->option_button_weight];
  106. }
  107. public function getOptionAppendType(){
  108. return $this->wp_options[$this->option_append_type];
  109. }
  110. public function getOptionButtonDesign(){
  111. return $this->wp_options[$this->option_button_design];
  112. }
  113. //construct base URL, based on $lazy value
  114. public function constructURL($url, $title,$button, $postId, $lazy, $globalcfg = ''){
  115. //rawurlencode - replace space with %20
  116. //urlencode - replace space with +
  117. if($this->isEncodeRequired){
  118. $title = rawurlencode($title);
  119. $url = rawurlencode($url);
  120. }
  121. if($lazy==DD_EMPTY_VALUE || $lazy==false){
  122. $this->constructNormalURL($url, $title,$button, $postId);
  123. }else{
  124. $this->constructLazyLoadURL($url, $title,$button, $postId);
  125. }
  126. }
  127. public function constructNormalURL($url, $title,$button, $postId){
  128. $finalURL = $this->baseURL;
  129. $finalURL = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$finalURL);
  130. $finalURL = str_replace(self::VOTE_TITLE,$title,$finalURL);
  131. $finalURL = str_replace(self::VOTE_URL,$url,$finalURL);
  132. $this->finalURL = $finalURL;
  133. }
  134. public function constructLazyLoadURL($url, $title,$button, $postId){
  135. $finalURL_lazy = $this->baseURL_lazy;
  136. $finalURL_lazy = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  137. $finalURL_lazy = str_replace(self::VOTE_TITLE,$title,$finalURL_lazy);
  138. $finalURL_lazy = str_replace(self::VOTE_URL,$url,$finalURL_lazy);
  139. $finalURL_lazy = str_replace(self::POST_ID,$postId,$finalURL_lazy);
  140. $this->finalURL_lazy = $finalURL_lazy;
  141. //lazy loading javascript
  142. $finalURL_lazy_script = $this->baseURL_lazy_script;
  143. $finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN_LAZY_WIDTH,$this->getButtonDesignLazyWidth($button),$finalURL_lazy_script);
  144. $finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN_LAZY_HEIGHT,$this->getButtonDesignLazyHeight($button),$finalURL_lazy_script);
  145. $finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy_script);
  146. $finalURL_lazy_script = str_replace(self::VOTE_TITLE,$title,$finalURL_lazy_script);
  147. $finalURL_lazy_script = str_replace(self::VOTE_URL,$url,$finalURL_lazy_script);
  148. $finalURL_lazy_script = str_replace(self::POST_ID,$postId,$finalURL_lazy_script);
  149. $this->finalURL_lazy_script = $finalURL_lazy_script;
  150. //scheduler to run the lazy loading
  151. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  152. $final_scheduler_lazy_script = str_replace(self::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  153. $final_scheduler_lazy_script = str_replace(self::POST_ID,$postId,$final_scheduler_lazy_script);
  154. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  155. }
  156. }
  157. //iframe class has different construct URL for normal and lazy load
  158. class BaseIFrameDD extends BaseDD{
  159. const EXTRA_VALUE = "EXTRA_VALUE";
  160. var $buttonLayoutWidthHeight = array(
  161. "Normal" => "height=\"69\" width=\"51\"",
  162. "Compact" => "height=\"22\" width=\"120\"",
  163. );
  164. public function getIframeWH($button){
  165. return $this->buttonLayoutWidthHeight[$button];
  166. }
  167. public function constructNormalURL($url, $title,$button, $postId){
  168. $finalURL = $this->baseURL;
  169. $finalURL = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$finalURL);
  170. $finalURL = str_replace(parent::VOTE_TITLE,$title,$finalURL);
  171. $finalURL = str_replace(parent::VOTE_URL,$url,$finalURL);
  172. $finalURL = str_replace(parent::POST_ID,$postId,$finalURL);
  173. $finalURL = str_replace(self::EXTRA_VALUE,$this->getIframeWH($button),$finalURL);
  174. $this->finalURL = $finalURL;
  175. }
  176. public function constructLazyLoadURL($url, $title,$button, $postId){
  177. $finalURL_lazy = $this->baseURL_lazy;
  178. $finalURL_lazy = str_replace(self::POST_ID,$postId,$finalURL_lazy);
  179. $this->finalURL_lazy = $finalURL_lazy;
  180. $finalURL_lazy_script = $this->baseURL_lazy_script;
  181. $finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN_LAZY_WIDTH,$this->getButtonDesignLazyWidth($button),$finalURL_lazy_script);
  182. $finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN_LAZY_HEIGHT,$this->getButtonDesignLazyHeight($button),$finalURL_lazy_script);
  183. $finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy_script);
  184. $finalURL_lazy_script = str_replace(self::VOTE_TITLE,$title,$finalURL_lazy_script);
  185. $finalURL_lazy_script = str_replace(self::VOTE_URL,$url,$finalURL_lazy_script);
  186. $finalURL_lazy_script = str_replace(self::POST_ID,$postId,$finalURL_lazy_script);
  187. $this->finalURL_lazy_script = $finalURL_lazy_script;
  188. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  189. $final_scheduler_lazy_script = str_replace(self::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  190. $final_scheduler_lazy_script = str_replace(self::POST_ID,$postId,$final_scheduler_lazy_script);
  191. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  192. }
  193. }
  194. //warning : in baseURL or lazyURL, all text have to enclose by html tag, else it will display pure text in the_excerpt mode
  195. // DEFAULT BUTTONS (IN THEIR DEFAULT ORDER)
  196. // TODO: consider tidying this up by loading these classes from separate files
  197. /******************************************************************************************
  198. *
  199. * http://www.twitter.com
  200. * //data-counturl
  201. */
  202. class DD_Twitter extends BaseDD{
  203. var $append_type = 'left_float';
  204. var $button_design = 'Normal';
  205. var $ajax_left_float = 'on';
  206. var $lazy_load = false;
  207. const NAME = "Twitter";
  208. const URL_WEBSITE = "http://www.twitter.com";
  209. const URL_API = "http://twitter.com/goodies/tweetbutton";
  210. const DEFAULT_BUTTON_WEIGHT = "110";
  211. const BASEURL ="<a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-url=\"VOTE_URL\" data-count=\"VOTE_BUTTON_DESIGN\" data-text=\"VOTE_TITLE\" data-via=\"VOTE_SOURCE\" ></a><script type=\"text/javascript\" src=\"http://platform.twitter.com/widgets.js\"></script>";
  212. const OPTION_APPEND_TYPE = "dd_twitter_appendType";
  213. const OPTION_BUTTON_DESIGN = "dd_twitter_buttonDesign";
  214. const OPTION_BUTTON_WEIGHT = "dd_twitter_button_weight";
  215. const OPTION_AJAX_LEFT_FLOAT = "dd_twitter_ajax_left_float";
  216. const OPTION_LAZY_LOAD = "dd_twitter_lazy_load";
  217. const BASEURL_LAZY ="<div class='dd-twitter-ajax-load dd-twitter-POST_ID'></div><a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-url=\"VOTE_URL\" data-count=\"VOTE_BUTTON_DESIGN\" data-text=\"VOTE_TITLE\" data-via=\"VOTE_SOURCE\" ></a>";
  218. const BASEURL_LAZY_SCRIPT = " function loadTwitter_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-twitter-POST_ID').remove();\$.getScript('http://platform.twitter.com/widgets.js'); }); }";
  219. const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadTwitter_POST_ID()',SCHEDULER_TIMER);";
  220. const SCHEDULER_LAZY_TIMER = "1000";
  221. var $buttonLayout = array(
  222. "Normal" => "vertical",
  223. "Compact" => "horizontal"
  224. );
  225. var $buttonLayoutLazy = array(
  226. "Normal" => "vertical",
  227. "Compact" => "horizontal"
  228. );
  229. var $isEncodeRequired = false;
  230. const VOTE_SOURCE = "VOTE_SOURCE";
  231. public function DD_Twitter() {
  232. $this->option_append_type = self::OPTION_APPEND_TYPE;
  233. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  234. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  235. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  236. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  237. $this->baseURL_lazy = self::BASEURL_LAZY;
  238. $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
  239. $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
  240. $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
  241. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  242. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  243. }
  244. public function constructURL($url, $title,$button, $postId, $lazy, $globalcfg = ''){
  245. if($this->isEncodeRequired){
  246. $title = rawurlencode($title);
  247. $url = rawurlencode($url);
  248. }
  249. $twitter_source = '';
  250. if($globalcfg!=''){
  251. $twitter_source = $globalcfg[DD_GLOBAL_TWITTER_OPTION][DD_GLOBAL_TWITTER_OPTION_SOURCE];
  252. }
  253. if($lazy==DD_EMPTY_VALUE){
  254. //format twitter source
  255. $this->baseURL = str_replace(self::VOTE_SOURCE,$twitter_source,$this->baseURL);
  256. $this->constructNormalURL($url, $title,$button, $postId);
  257. }else{
  258. //format twitter source
  259. $this->baseURL_lazy = str_replace(self::VOTE_SOURCE,$twitter_source,$this->baseURL_lazy);
  260. $this->constructLazyLoadURL($url, $title,$button, $postId);
  261. }
  262. }
  263. public function constructLazyLoadURL($url, $title,$button, $postId){
  264. $finalURL_lazy = $this->baseURL_lazy;
  265. $finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  266. $finalURL_lazy = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy);
  267. $finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
  268. $finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
  269. $this->finalURL_lazy = $finalURL_lazy;
  270. $finalURL_lazy_script = $this->baseURL_lazy_script;
  271. $finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
  272. $this->finalURL_lazy_script = $finalURL_lazy_script;
  273. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  274. $final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  275. $final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);
  276. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  277. }
  278. }
  279. /******************************************************************************************
  280. * Buffer Button
  281. * http://bufferapp.com/goodies/button
  282. *
  283. */
  284. class DD_Buffer extends BaseDD{
  285. var $append_type = 'after_content';
  286. var $button_design = 'Normal';
  287. var $ajax_left_float = 'on';
  288. var $lazy_load = false;
  289. const NAME = "Buffer";
  290. const URL_WEBSITE = "http://bufferapp.com/";
  291. const URL_API = "http://bufferapp.com/goodies/button/";
  292. const DEFAULT_BUTTON_WEIGHT = "99";
  293. var $isEncodeRequired = false;
  294. const BASEURL = '<a href="http://bufferapp.com/add" class="buffer-add-button" data-count="VOTE_BUTTON_DESIGN" data-url="VOTE_URL" data-via="VOTE_BUFFER_SOURCE"></a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script>';
  295. const BASEURL_LAZY = '<a href="http://bufferapp.com/add" class="buffer-add-button" data-count="VOTE_BUTTON_DESIGN" data-url="VOTE_URL" data-via="VOTE_BUFFER_SOURCE"></a>';
  296. const BASEURL_LAZY_SCRIPT = "function loadBuffer_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-buffer-POST_ID').remove();\$.getScript('http://static.bufferapp.com/js/button.js'); }); }";
  297. const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadBuffer_POST_ID()',SCHEDULER_TIMER);";
  298. const SCHEDULER_LAZY_TIMER = "1000";
  299. const OPTION_APPEND_TYPE = "dd_buffer_appendType";
  300. const OPTION_BUTTON_DESIGN = "dd_buffer_buttonDesign";
  301. const OPTION_BUTTON_WEIGHT = "dd_buffer_button_weight";
  302. const OPTION_AJAX_LEFT_FLOAT = "dd_buffer_ajax_left_float";
  303. const OPTION_LAZY_LOAD = "dd_buffer_lazy_load";
  304. const VOTE_BUFFER_SOURCE = "VOTE_BUFFER_SOURCE";
  305. var $buttonLayout = array(
  306. "Normal" => "vertical",
  307. "Compact" => "horizontal",
  308. "No Count" => "none"
  309. );
  310. var $buttonLayoutLazy = array(
  311. "Normal" => "vertical",
  312. "Compact" => "horizontal",
  313. "No Count" => "none"
  314. );
  315. // XXX: Old-style constructor
  316. public function DD_Buffer() {
  317. $this->option_append_type = self::OPTION_APPEND_TYPE;
  318. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  319. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  320. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  321. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  322. $this->baseURL_lazy = self::BASEURL_LAZY;
  323. $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
  324. $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
  325. $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
  326. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  327. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  328. }
  329. public function constructURL($url, $title, $button, $postId, $lazy, $globalcfg = ''){
  330. if($this->isEncodeRequired){
  331. $title = rawurlencode($title);
  332. $url = rawurlencode($url);
  333. }
  334. $buffer_source = '';
  335. if($globalcfg!=''){
  336. $buffer_source = $globalcfg[DD_GLOBAL_BUFFER_OPTION][DD_GLOBAL_BUFFER_OPTION_SOURCE];
  337. }
  338. if($lazy==DD_EMPTY_VALUE || $lazy==false){
  339. //format twitter source
  340. $this->baseURL = str_replace(self::VOTE_BUFFER_SOURCE,$buffer_source,$this->baseURL);
  341. $this->constructNormalURL($url, $title,$button, $postId);
  342. }else{
  343. //format twitter source
  344. $this->baseURL_lazy = str_replace(self::VOTE_BUFFER_SOURCE,$buffer_source,$this->baseURL_lazy);
  345. $this->constructLazyLoadURL($url, $title,$button, $postId);
  346. }
  347. }
  348. public function constructNormalURL($url, $title, $button, $postId){
  349. $finalURL = $this->baseURL;
  350. $finalURL = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$finalURL);
  351. $finalURL = str_replace(self::VOTE_TITLE,$title,$finalURL);
  352. $finalURL = str_replace(self::VOTE_URL,$url,$finalURL);
  353. $finalURL = str_replace(parent::POST_ID,$postId,$finalURL);
  354. $this->finalURL = $finalURL;
  355. }
  356. public function constructLazyLoadURL($url, $title,$button, $postId){
  357. $finalURL_lazy = $this->baseURL_lazy;
  358. $finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
  359. $finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  360. $finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
  361. $this->finalURL_lazy = $finalURL_lazy;
  362. $finalURL_lazy_script = $this->baseURL_lazy_script;
  363. $finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
  364. $this->finalURL_lazy_script = $finalURL_lazy_script;
  365. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  366. $final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  367. $final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);
  368. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  369. }
  370. }
  371. /******************************************************************************************
  372. *
  373. * Facebook Like (XFBML)
  374. * https://developers.facebook.com/tools/lint/
  375. *
  376. */
  377. class DD_FbLike_XFBML extends BaseDD{
  378. var $append_type = 'left_float';
  379. var $button_design = 'Like Button Count';
  380. var $ajax_left_float = 'on';
  381. var $lazy_load = false;
  382. const NAME = "Facebook Like (XFBML)";
  383. const URL_WEBSITE = "http://www.facebook.com";
  384. const URL_API = "http://developers.facebook.com/docs/reference/plugins/like";
  385. const BASEURL = "<script src=\"http://connect.facebook.net/FACEBOOK_LOCALE/all.js#xfbml=1\"></script><fb:like href=\"VOTE_URL\" FACEBOOK_SEND FACEBOOK_SHOW_FACE VOTE_BUTTON_DESIGN ></fb:like>";
  386. const FB_LOCALES = "http://www.facebook.com/translations/FacebookLocales.xml";
  387. const DEFAULT_BUTTON_WEIGHT = "96";
  388. const OPTION_APPEND_TYPE = "dd_fblike_xfbml_appendType";
  389. const OPTION_BUTTON_DESIGN = "dd_fblike_xfbml_buttonDesign";
  390. const OPTION_BUTTON_WEIGHT = "dd_fblike_xfbml_button_weight";
  391. const OPTION_AJAX_LEFT_FLOAT = "dd_fblike_xfbml_ajax_left_float";
  392. const OPTION_LAZY_LOAD = "dd_fblike_xfbml_lazy_load";
  393. const LIKE_STANDARD = " width=\"450\" ";
  394. const LIKE_BUTTON_COUNT= " layout=\"button_count\" width=\"92\" ";
  395. const LIKE_BOX_COUNT= " layout=\"box_count\" width=\"50\" ";
  396. const RECOMMEND_STANDARD = " action=\"recommend\" width=\"400\" ";
  397. const RECOMMEND_BUTTON_COUNT= " action=\"recommend\" layout=\"button_count\" width=\"130\" ";
  398. const RECOMMEND_BOX_COUNT= " action=\"recommend\" layout=\"box_count\" width=\"90\" ";
  399. const FACEBOOK_SEND = "FACEBOOK_SEND"; //send=\"true\"
  400. const FACEBOOK_SHOW_FACE = "FACEBOOK_SHOW_FACE"; //show_faces=\"true\"
  401. const FACEBOOK_LOCALE = "FACEBOOK_LOCALE";
  402. var $islazyLoadAvailable = false;
  403. var $float_button_design = "Like Box Count";
  404. var $buttonLayout = array(
  405. "Like Standard" => self::LIKE_STANDARD,
  406. "Like Button Count" => self::LIKE_BUTTON_COUNT,
  407. "Like Box Count" => self::LIKE_BOX_COUNT,
  408. "Recommend Standard" => self::RECOMMEND_STANDARD,
  409. "Recommend Button Count" => self::RECOMMEND_BUTTON_COUNT,
  410. "Recommend Box Count" => self::RECOMMEND_BOX_COUNT
  411. );
  412. public function DD_FbLike_XFBML() {
  413. $this->option_append_type = self::OPTION_APPEND_TYPE;
  414. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  415. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  416. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  417. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  418. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  419. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  420. }
  421. public function constructURL($url, $title,$button, $postId, $lazy, $globalcfg = ''){
  422. if($this->isEncodeRequired){
  423. $title = rawurlencode($title);
  424. $url = rawurlencode($url);
  425. }
  426. $fb_locale = '';
  427. $fb_send = '';
  428. $fb_face = '';
  429. $fb_send_value = '';
  430. $fb_face_value = '';
  431. if($globalcfg!=''){
  432. $fb_locale = $globalcfg[DD_GLOBAL_FACEBOOK_OPTION][DD_GLOBAL_FACEBOOK_OPTION_LOCALE];
  433. $fb_send = $globalcfg[DD_GLOBAL_FACEBOOK_OPTION][DD_GLOBAL_FACEBOOK_OPTION_SEND];
  434. $fb_face = $globalcfg[DD_GLOBAL_FACEBOOK_OPTION][DD_GLOBAL_FACEBOOK_OPTION_FACE];
  435. if($fb_send == DD_DISPLAY_ON){
  436. $fb_send_value = "send=\"true\"";
  437. }else{
  438. $fb_send_value = "send=\"false\"";
  439. }
  440. if($fb_face == DD_DISPLAY_ON){
  441. $fb_face_value = "show_faces=\"true\"";
  442. }else{
  443. $fb_face_value = "show_faces=\"false\"";
  444. }
  445. }
  446. //show face and send button
  447. $this->baseURL = str_replace(self::FACEBOOK_LOCALE,$fb_locale,$this->baseURL);
  448. $this->baseURL = str_replace(self::FACEBOOK_SEND,$fb_send_value,$this->baseURL);
  449. $this->baseURL = str_replace(self::FACEBOOK_SHOW_FACE,$fb_face_value,$this->baseURL);
  450. $this->constructNormalURL($url, $title,$button, $postId);
  451. }
  452. }
  453. /******************************************************************************************
  454. *
  455. * http://www.google.com/+1/button/
  456. * http://www.google.com/webmasters/+1/button/
  457. *
  458. */
  459. class DD_Google1 extends BaseDD{
  460. var $append_type = 'left_float';
  461. var $button_design = 'Normal';
  462. var $ajax_left_float = 'on';
  463. var $lazy_load = false;
  464. const NAME = "Google +1";
  465. const URL_WEBSITE = "http://www.google.com/+1/button/";
  466. const URL_API = "http://code.google.com/apis/+1button/";
  467. const DEFAULT_BUTTON_WEIGHT = "95";
  468. var $isEncodeRequired = false;
  469. const BASEURL = "<script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='VOTE_BUTTON_DESIGN' href='VOTE_URL'></g:plusone>";
  470. const BASEURL_LAZY = "<div class='dd-google1-ajax-load dd-google1-POST_ID'></div><g:plusone size='VOTE_BUTTON_DESIGN' href='VOTE_URL'></g:plusone>";
  471. const BASEURL_LAZY_SCRIPT = " function loadGoogle1_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-google1-POST_ID').remove();\$.getScript('https://apis.google.com/js/plusone.js'); }); }";
  472. const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadGoogle1_POST_ID()',SCHEDULER_TIMER);";
  473. const SCHEDULER_LAZY_TIMER = "1000";
  474. const OPTION_APPEND_TYPE = "dd_google1_appendType";
  475. const OPTION_BUTTON_DESIGN = "dd_google1_buttonDesign";
  476. const OPTION_BUTTON_WEIGHT = "dd_google1_button_weight";
  477. const OPTION_AJAX_LEFT_FLOAT = "dd_google1_ajax_left_float";
  478. const OPTION_LAZY_LOAD = "dd_google1_lazy_load";
  479. var $buttonLayout = array(
  480. "Normal" => "tall",
  481. "Compact (15px)" => "small",
  482. "Compact (20px)" => "medium",
  483. "Compact (24px)" => "none"
  484. );
  485. var $buttonLayoutLazy = array(
  486. "Normal" => "tall",
  487. "Compact (15px)" => "small",
  488. "Compact (20px)" => "medium",
  489. "Compact (24px)" => "none"
  490. );
  491. public function DD_Google1() {
  492. $this->option_append_type = self::OPTION_APPEND_TYPE;
  493. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  494. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  495. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  496. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  497. $this->baseURL_lazy = self::BASEURL_LAZY;
  498. $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
  499. $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
  500. $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
  501. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  502. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  503. }
  504. public function constructLazyLoadURL($url, $title,$button, $postId){
  505. $finalURL_lazy = $this->baseURL_lazy;
  506. $finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
  507. $finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  508. $finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
  509. $this->finalURL_lazy = $finalURL_lazy;
  510. $finalURL_lazy_script = $this->baseURL_lazy_script;
  511. $finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
  512. $this->finalURL_lazy_script = $finalURL_lazy_script;
  513. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  514. $final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  515. $final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);
  516. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  517. }
  518. }
  519. /******************************************************************************************
  520. *
  521. * http://www.linkedin.com
  522. *
  523. */
  524. class DD_Linkedin extends BaseDD{
  525. var $append_type = 'left_float';
  526. var $button_design = 'Normal';
  527. var $ajax_left_float = 'on';
  528. var $lazy_load = false;
  529. const NAME = "Linkedin";
  530. const URL_WEBSITE = "http://www.linkedin.com";
  531. const URL_API = "http://www.linkedin.com/publishers";
  532. const DEFAULT_BUTTON_WEIGHT = "94";
  533. const BASEURL = "<script src='//platform.linkedin.com/in.js' type='text/javascript'></script><script type='IN/Share' date-url='VOTE_URL' data-counter='VOTE_BUTTON_DESIGN'></script>";
  534. const BASEURL_LAZY = "<div class='dd-linkedin-ajax-load dd-linkedin-POST_ID'></div><script type='IN/share' data-url='VOTE_URL' data-counter='VOTE_BUTTON_DESIGN'></script>";
  535. const BASEURL_LAZY_SCRIPT = " function loadLinkedin_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-linkedin-POST_ID').remove();\$.getScript('http://platform.linkedin.com/in.js'); }); }";
  536. const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadLinkedin_POST_ID()',SCHEDULER_TIMER);";
  537. const SCHEDULER_LAZY_TIMER = "1000";
  538. const OPTION_APPEND_TYPE = "dd_linkedin_appendType";
  539. const OPTION_BUTTON_DESIGN = "dd_linkedin_buttonDesign";
  540. const OPTION_BUTTON_WEIGHT = "dd_linkedin_button_weight";
  541. const OPTION_AJAX_LEFT_FLOAT = "dd_linkedin_ajax_left_float";
  542. const OPTION_LAZY_LOAD = "dd_linkedin_lazy_load";
  543. var $buttonLayout = array(
  544. "Normal" => "top",
  545. "Compact" => "right",
  546. "NoCount" => "none"
  547. );
  548. var $buttonLayoutLazy = array(
  549. "Normal" => "top",
  550. "Compact" => "right",
  551. "NoCount" => "none"
  552. );
  553. var $isEncodeRequired = false;
  554. public function DD_Linkedin() {
  555. $this->option_append_type = self::OPTION_APPEND_TYPE;
  556. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  557. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  558. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  559. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  560. $this->baseURL_lazy = self::BASEURL_LAZY;
  561. $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
  562. $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
  563. $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
  564. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  565. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  566. }
  567. public function constructLazyLoadURL($url, $title,$button, $postId){
  568. $finalURL_lazy = $this->baseURL_lazy;
  569. $finalURL_lazy = str_replace(self::VOTE_URL,$url,$finalURL_lazy);
  570. $finalURL_lazy = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  571. $finalURL_lazy = str_replace(self::POST_ID,$postId,$finalURL_lazy);
  572. $this->finalURL_lazy = $finalURL_lazy;
  573. $finalURL_lazy_script = $this->baseURL_lazy_script;
  574. $finalURL_lazy_script = str_replace(self::POST_ID,$postId,$finalURL_lazy_script);
  575. $this->finalURL_lazy_script = $finalURL_lazy_script;
  576. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  577. $final_scheduler_lazy_script = str_replace(self::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  578. $final_scheduler_lazy_script = str_replace(self::POST_ID,$postId,$final_scheduler_lazy_script);
  579. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  580. }
  581. }
  582. // NON-DEFAULTS
  583. /******************************************************************************************
  584. *
  585. * Pinterest
  586. * http://pinterest.com/about/goodies/#button_for_websites
  587. *
  588. */
  589. class DD_Pinterest extends BaseDD{
  590. const NAME = "Pinterest";
  591. const URL_WEBSITE = "http://pinterest.com";
  592. const URL_API = "http://pinterest.com/about/goodies/#button_for_websites";
  593. const DEFAULT_BUTTON_WEIGHT = "10";
  594. const BASEURL = '<a href="http://pinterest.com/pin/create/button/?url=VOTE_URL&description=VOTE_TITLE&media=VOTE_IMAGE" class="pin-it-button" count-layout="VOTE_BUTTON_DESIGN"></a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>';
  595. const BASEURL_LAZY = '<a href="http://pinterest.com/pin/create/button/?url=VOTE_URL&description=VOTE_TITLE&media=VOTE_IMAGE" class="pin-it-button dd-pinterest-ajax-load dd-pinterest-POST_ID" count-layout="VOTE_BUTTON_DESIGN"></a>';
  596. const BASEURL_LAZY_SCRIPT = "function loadPinterest_POST_ID(){ jQuery(document).ready(function(\$) { \$.getScript('http://assets.pinterest.com/js/pinit.js'); }); }";
  597. const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadPinterest_POST_ID()',SCHEDULER_TIMER);";
  598. const SCHEDULER_LAZY_TIMER = "1000";
  599. const OPTION_APPEND_TYPE = "dd_pinterest_appendType";
  600. const OPTION_BUTTON_DESIGN = "dd_pinterest_buttonDesign";
  601. const OPTION_BUTTON_WEIGHT = "dd_pinterest_button_weight";
  602. const OPTION_AJAX_LEFT_FLOAT = "dd_pinterest_ajax_left_float";
  603. const OPTION_LAZY_LOAD = "dd_pinterest_lazy_load";
  604. var $buttonLayout = array(
  605. "Normal" => "vertical",
  606. "Compact" => "horizontal",
  607. "No Count" => "none"
  608. );
  609. var $buttonLayoutLazy = array(
  610. "Normal" => "vertical",
  611. "Compact" => "horizontal",
  612. "No Count" => "none"
  613. );
  614. public function DD_Pinterest() {
  615. $this->option_append_type = self::OPTION_APPEND_TYPE;
  616. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  617. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  618. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  619. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  620. $this->baseURL_lazy = self::BASEURL_LAZY;
  621. $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
  622. $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
  623. $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
  624. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  625. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  626. }
  627. //construct base URL, based on $lazy value
  628. public function constructURL($url, $title, $button, $postId, $lazy, $globalcfg = ''){
  629. //rawurlencode - replace space with %20
  630. //urlencode - replace space with +
  631. if($this->isEncodeRequired) {
  632. $title = rawurlencode($title);
  633. $url = rawurlencode($url);
  634. }
  635. if($lazy==DD_EMPTY_VALUE || $lazy==false){
  636. $this->constructNormalURL($url, $title,$button, $postId);
  637. }else{
  638. $this->constructLazyLoadURL($url, $title,$button, $postId);
  639. }
  640. }
  641. public function constructNormalURL($url, $title,$button, $postId){
  642. $finalURL = $this->baseURL;
  643. $finalURL = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$finalURL);
  644. $finalURL = str_replace(self::VOTE_TITLE,$title,$finalURL);
  645. $finalURL = str_replace(self::VOTE_URL,$url,$finalURL);
  646. $finalURL = str_replace(parent::POST_ID,$postId,$finalURL);
  647. $finalURL = str_replace(parent::VOTE_TITLE,$title,$finalURL);
  648. $finalURL = str_replace(parent::VOTE_URL,$url,$finalURL);
  649. // If theme uses post thumbnails, grab the chosen thumbnail if not grab the first image attached to post
  650. if(current_theme_supports('post-thumbnails')){
  651. $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($postId), 'full');
  652. } else {
  653. $image_args = array(
  654. 'order' => 'ASC',
  655. 'orderby' => 'menu_order',
  656. 'post_type' => 'attachment',
  657. 'post_parent' => $postId,
  658. 'post_mime_type' => 'image',
  659. 'post_status' => null,
  660. 'numberposts' => -1,
  661. );
  662. $attachments = get_posts($image_args);
  663. if ($attachments) {
  664. $thumb = wp_get_attachment_image_src($attachments[0]->ID, 'full');
  665. }
  666. }
  667. if($thumb){
  668. $image = $thumb[0];
  669. } else {
  670. $image = '';
  671. }
  672. $finalURL = str_replace(parent::VOTE_IMAGE,$image,$finalURL);
  673. $this->finalURL = $finalURL;
  674. }
  675. public function constructLazyLoadURL($url, $title,$button, $postId){
  676. $finalURL_lazy = $this->baseURL_lazy;
  677. $finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  678. $finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
  679. $finalURL_lazy = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy);
  680. $finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
  681. if(current_theme_supports('post-thumbnails')) $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($postId), 'full' );
  682. else $thumb = false;
  683. if($thumb) $image = $thumb[0];
  684. else $image = '';
  685. $finalURL_lazy = str_replace(parent::VOTE_IMAGE,$image,$finalURL_lazy);
  686. $this->finalURL_lazy = $finalURL_lazy;
  687. $finalURL_lazy_script = $this->baseURL_lazy_script;
  688. $finalURL_lazy_script = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy_script);
  689. $finalURL_lazy_script = str_replace(parent::VOTE_URL,$url,$finalURL_lazy_script);
  690. $finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
  691. $this->finalURL_lazy_script = $finalURL_lazy_script;
  692. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  693. $final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  694. $final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);
  695. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  696. }
  697. }
  698. /******************************************************************************************
  699. *
  700. * Flattr
  701. * http://developers.flattr.net/button/
  702. *
  703. */
  704. class DD_Flattr extends BaseDD{
  705. const NAME = "Flattr";
  706. const URL_WEBSITE = "http://flattr.com";
  707. const URL_API = "http://developers.flattr.net/button/";
  708. const DEFAULT_BUTTON_WEIGHT = "10";
  709. const BASEURL = '<script src="http://api.flattr.com/js/0.6/load.js?mode=auto"></script><a class="FlattrButton" href="VOTE_URL" style="display:none;" title="VOTE_TITLE" data-flattr-uid="VOTE_FLATTR_UID" data-flattr-button="VOTE_BUTTON_DESIGN" data-flattr-category="text"></a>';
  710. const BASEURL_LAZY = '<a class="FlattrButton" href="VOTE_URL" style="display:none;" title="VOTE_TITLE" data-flattr-uid="VOTE_FLATTR_UID" data-flattr-button="VOTE_BUTTON_DESIGN" data-flattr-category="text"></a>';
  711. const BASEURL_LAZY_SCRIPT = "function loadFlattr_POST_ID(){ jQuery(document).ready(function(\$) { \$.getScript('http://api.flattr.com/js/0.6/load.js?mode=auto'); }); }";
  712. const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadFlattr_POST_ID()',SCHEDULER_TIMER);";
  713. const SCHEDULER_LAZY_TIMER = "1000";
  714. const OPTION_APPEND_TYPE = "dd_flattr_appendType";
  715. const OPTION_BUTTON_DESIGN = "dd_flattr_buttonDesign";
  716. const OPTION_BUTTON_WEIGHT = "dd_flattr_button_weight";
  717. const OPTION_AJAX_LEFT_FLOAT = "dd_flattr_ajax_left_float";
  718. const OPTION_LAZY_LOAD = "dd_flattr_lazy_load";
  719. var $buttonLayout = array(
  720. "Normal" => "default",
  721. "Compact" => "compact"
  722. );
  723. var $buttonLayoutLazy = array(
  724. "Normal" => "default",
  725. "Compact" => "compact"
  726. );
  727. const VOTE_FLATTR_UID = 'VOTE_FLATTR_UID';
  728. public function DD_Flattr() {
  729. $this->option_append_type = self::OPTION_APPEND_TYPE;
  730. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  731. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  732. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  733. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  734. $this->baseURL = self::BASEURL;
  735. $this->baseURL_lazy = self::BASEURL_LAZY;
  736. $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
  737. $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
  738. $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
  739. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  740. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  741. }
  742. //construct base URL, based on $lazy value
  743. public function constructURL($url, $title, $button, $postId, $lazy, $globalcfg = ''){
  744. $flattr_uid = 'flattr';
  745. if($globalcfg!=''){
  746. $flattr_uid = $globalcfg[DD_GLOBAL_FLATTR_OPTION][DD_GLOBAL_FLATTR_OPTION_UID];
  747. if(empty($flattr_uid)) $flattr_uid = 'flattr';
  748. }
  749. if($lazy==DD_EMPTY_VALUE || $lazy==false){
  750. $this->baseURL = str_replace(self::VOTE_FLATTR_UID, $flattr_uid, $this->baseURL);
  751. $this->constructNormalURL($url, $title, $button, $postId);
  752. }else{
  753. $this->baseURL_lazy = str_replace(self::VOTE_FLATTR_UID, $flattr_uid, $this->baseURL_lazy);
  754. $this->constructLazyLoadURL($url, $title, $button, $postId);
  755. }
  756. }
  757. public function constructNormalURL($url, $title, $button, $postId){
  758. $finalURL = $this->baseURL;
  759. $finalURL = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$finalURL);
  760. $finalURL = str_replace(self::VOTE_TITLE,$title,$finalURL);
  761. $finalURL = str_replace(self::VOTE_URL,$url,$finalURL);
  762. $finalURL = str_replace(parent::POST_ID,$postId,$finalURL);
  763. $this->finalURL = $finalURL;
  764. }
  765. public function constructLazyLoadURL($url, $title, $button, $postId){
  766. $finalURL_lazy = $this->baseURL_lazy;
  767. $finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  768. $finalURL_lazy = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy);
  769. $finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
  770. $finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
  771. $this->finalURL_lazy = $finalURL_lazy;
  772. $finalURL_lazy_script = $this->baseURL_lazy_script;
  773. $finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
  774. $this->finalURL_lazy_script = $finalURL_lazy_script;
  775. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  776. $final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  777. $final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);
  778. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  779. }
  780. }
  781. /******************************************************************************************
  782. *
  783. * Facebook Like (IFrame)
  784. *
  785. */
  786. class DD_FbLike extends BaseIFrameDD{
  787. const NAME = "Facebook Like (IFrame)";
  788. const URL_WEBSITE = "http://www.facebook.com";
  789. const URL_API = "http://developers.facebook.com/docs/reference/plugins/like";
  790. const BASEURL = "<iframe src='http://www.facebook.com/plugins/like.php?href=VOTE_URL&amp;locale=FACEBOOK_LOCALE&amp;VOTE_BUTTON_DESIGN' scrolling='no' frameborder='0' style='border:none; overflow:hidden; EXTRA_VALUE' allowTransparency='true'></iframe>";
  791. const FB_LOCALES = "http://www.facebook.com/translations/FacebookLocales.xml";
  792. const DEFAULT_BUTTON_WEIGHT = "96";
  793. const OPTION_APPEND_TYPE = "dd_fblike_appendType";
  794. const OPTION_BUTTON_DESIGN = "dd_fblike_buttonDesign";
  795. const OPTION_BUTTON_WEIGHT = "dd_fblike_button_weight";
  796. const OPTION_AJAX_LEFT_FLOAT = "dd_fblike_ajax_left_float";
  797. const OPTION_LAZY_LOAD = "dd_fblike_lazy_load";
  798. const BASEURL_LAZY = "<div class='dd-fblike-ajax-load dd-fblike-POST_ID'></div><iframe class=\"DD_FBLIKE_AJAX_POST_ID\" src='' height='0' width='0' scrolling='no' frameborder='0' allowTransparency='true'></iframe>";
  799. const BASEURL_LAZY_SCRIPT = " function loadFBLike_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-fblike-POST_ID').remove();\$('.DD_FBLIKE_AJAX_POST_ID').attr('width','VOTE_BUTTON_DESIGN_LAZY_WIDTH');\$('.DD_FBLIKE_AJAX_POST_ID').attr('height','VOTE_BUTTON_DESIGN_LAZY_HEIGHT');\$('.DD_FBLIKE_AJAX_POST_ID').attr('src','http://www.facebook.com/plugins/like.php?href=VOTE_URL&amp;locale=FACEBOOK_LOCALE&amp;VOTE_BUTTON_DESIGN'); }); }";
  800. const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadFBLike_POST_ID()',SCHEDULER_TIMER);";
  801. const SCHEDULER_LAZY_TIMER = "1000";
  802. const LIKE_STANDARD = "layout=standard&amp;action=like&amp;width=350&amp;height=24&amp;colorscheme=light"; //350x24
  803. const LIKE_BUTTON_COUNT= "layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light"; //92x20
  804. const LIKE_BOX_COUNT= "layout=box_count&amp;action=like&amp;width=50&amp;height=60&amp;colorscheme=light"; //50x60
  805. const RECOMMEND_STANDARD = "layout=standard&amp;action=recommend&amp;width=400&amp;height=24&amp;colorscheme=light"; //400x24
  806. const RECOMMEND_BUTTON_COUNT= "layout=button_count&amp;action=recommend&amp;width=130&amp;height=20&amp;colorscheme=light"; //130x20
  807. const RECOMMEND_BOX_COUNT= "layout=box_count&amp;action=recommend&amp;width=90&amp;height=60&amp;colorscheme=light"; //90x60
  808. const EXTRA_VALUE = "EXTRA_VALUE";
  809. const FACEBOOK_LOCALE = "FACEBOOK_LOCALE";
  810. var $float_button_design = "Like Box Count";
  811. var $buttonLayout = array(
  812. "Like Standard" => self::LIKE_STANDARD,
  813. "Like Button Count" => self::LIKE_BUTTON_COUNT,
  814. "Like Box Count" => self::LIKE_BOX_COUNT,
  815. "Recommend Standard" => self::RECOMMEND_STANDARD,
  816. "Recommend Button Count" => self::RECOMMEND_BUTTON_COUNT,
  817. "Recommend Box Count" => self::RECOMMEND_BOX_COUNT
  818. );
  819. var $buttonLayoutLazy = array(
  820. "Like Standard" => self::LIKE_STANDARD,
  821. "Like Button Count" => self::LIKE_BUTTON_COUNT,
  822. "Like Box Count" => self::LIKE_BOX_COUNT,
  823. "Recommend Standard" => self::RECOMMEND_STANDARD,
  824. "Recommend Button Count" => self::RECOMMEND_BUTTON_COUNT,
  825. "Recommend Box Count" => self::RECOMMEND_BOX_COUNT
  826. );
  827. var $buttonLayoutWidthHeight = array(
  828. "Like Standard" => "width:500px; height:24px;",
  829. "Like Button Count" => "width:92px; height:20px;",
  830. "Like Box Count" => "width:50px; height:62px;",
  831. "Recommend Standard" => "width:500px; height:24px;",
  832. "Recommend Button Count" => "width:130px; height:20px;",
  833. "Recommend Box Count" => "width:90px; height:60px;"
  834. );
  835. var $buttonLayoutLazyWidth = array(
  836. "Like Standard" => "500",
  837. "Like Button Count" => "92",
  838. "Like Box Count" => "50",
  839. "Recommend Standard" => "500",
  840. "Recommend Button Count" => "130",
  841. "Recommend Box Count" => "90"
  842. );
  843. var $buttonLayoutLazyHeight = array(
  844. "Like Standard" => "24",
  845. "Like Button Count" => "20",
  846. "Like Box Count" => "62",
  847. "Recommend Standard" => "24",
  848. "Recommend Button Count" => "20",
  849. "Recommend Box Count" => "60"
  850. );
  851. public function DD_FbLike() {
  852. $this->option_append_type = self::OPTION_APPEND_TYPE;
  853. $this->option_button_design = self::OPTION_BUTTON_DESIGN;
  854. $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
  855. $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
  856. $this->option_lazy_load = self::OPTION_LAZY_LOAD;
  857. $this->baseURL_lazy = self::BASEURL_LAZY;
  858. $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
  859. $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
  860. $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
  861. $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
  862. parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);
  863. }
  864. public function constructLazyLoadURL($url, $title,$button, $postId){
  865. $finalURL_lazy = $this->baseURL_lazy;
  866. $finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);
  867. $finalURL_lazy = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy);
  868. $finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
  869. $finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
  870. $this->finalURL_lazy = $finalURL_lazy;
  871. $finalURL_lazy_script = $this->baseURL_lazy_script;
  872. $finalURL_lazy_script = str_replace(parent::VOTE_BUTTON_DESIGN_LAZY_WIDTH,$this->getButtonDesignLazyWidth($button),$finalURL_lazy_script);
  873. $finalURL_lazy_script = str_replace(parent::VOTE_BUTTON_DESIGN_LAZY_HEIGHT,$this->getButtonDesignLazyHeight($button),$finalURL_lazy_script);
  874. $finalURL_lazy_script = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy_script);
  875. $finalURL_lazy_script = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy_script);
  876. $finalURL_lazy_script = str_replace(parent::VOTE_URL,$url,$finalURL_lazy_script);
  877. $finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
  878. //add new line
  879. //convert &amp; to &
  880. $finalURL_lazy_script = str_replace("&amp;","&",$finalURL_lazy_script);
  881. $this->finalURL_lazy_script = $finalURL_lazy_script;
  882. $final_scheduler_lazy_script = $this->scheduler_lazy_script;
  883. $final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);
  884. $final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);
  885. $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;
  886. }
  887. public function constructURL($url, $title,$button, $postId, $lazy, $globalcfg = ''){
  888. if($this->isEncodeRequired){
  889. $title = rawurlencode($title);
  890. $url = rawurlencode($url);
  891. }
  892. $facebook_locale = '';
  893. if($globalcfg!=''){
  894. $facebook_locale = $globalcfg[DD_GLOBAL_FACEBOOK_OPTION][DD_GLOBAL_FACEBOOK_OPTION_LOCALE];
  895. }
  896. if($lazy==DD_EMPTY_VALUE){
  897. $this->baseURL = str_replace(self::FACEBOOK_LOCALE,$facebook_locale,$this->baseURL);
  898. $this->constructNormalURL($url, $title,$button, $postId);
  899. }else{
  900. $this->baseURL_lazy_script = str_replace(self::FACEBOOK_LOCALE,$facebook_locale,$this->baseURL_lazy_script);
  901. $this->constructLazyLoadURL($url, $title,$button, $postId);
  902. }
  903. }
  904. }
  905. /******************************************************************************************
  906. *
  907. * http://www.digg.com
  908. *
  909. */
  910. class DD_Digg extends BaseDD{
  911. }
  912. /******************************************************************************************
  913. *
  914. * http://www.reddit.com
  915. *
  916. */
  917. class DD_Reddit extends BaseIFrameDD{
  918. const NAME = "Reddit";
  919. const URL_WEBSITE = "http://www.reddit.com";
  920. const URL_API = "http://www.reddit.com/buttons/…

Large files files are truncated, but you can click here to view the full file