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

/wp-content/plugins/wordbooker/wordbooker.php

https://bitbucket.org/MaheshDhaduk/androidmobiles
PHP | 2682 lines | 2099 code | 268 blank | 315 comment | 511 complexity | f7d8dcdcd9b77f9d880434577775b80b MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /*
  3. Plugin Name: Wordbooker
  4. Plugin URI: http://wordbooker.tty.org.uk
  5. Description: Provides integration between your blog and your Facebook account. Navigate to <a href="options-general.php?page=wordbooker">Settings &rarr; Wordbooker</a> for configuration.
  6. Author: Steve Atty
  7. Author URI: http://wordbooker.tty.org.uk
  8. Version: 2.0.9
  9. */
  10. /*
  11. *
  12. *
  13. * Copyright 2011 Steve Atty (email : posty@tty.org.uk)
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the Free
  17. * Software Foundation; either version 2 of the License, or (at your option)
  18. * any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful, but WITHOUT
  21. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  22. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  23. * more details.
  24. *
  25. * You should have received a copy of the GNU General Public License along with
  26. * this program; if not, write to the Free Software Foundation, Inc., 51
  27. * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. # Putting this in here to see if it fixed some stupid bug
  30. #require_once('../../wp-includes/pluggable.php');
  31. @include("includes/premium.php");
  32. global $table_prefix, $wp_version,$wpdb,$db_prefix,$wbooker_user_id;
  33. $wbooker_user_id=0;
  34. $wordbooker_settings = wordbooker_options();
  35. if (! isset($wordbooker_settings['wordbooker_extract_length'])) $wordbooker_settings['wordbooker_extract_length']=256;
  36. define('WORDBOOKER_DEBUG', false);
  37. define('WORDBOOKER_TESTING', false);
  38. define('WORDBOOKER_CODE_RELEASE','2.0.9 - Wake Up and Dance!');
  39. # For Troubleshooting
  40. define('ADVANCED_DEBUG',false);
  41. #$facebook_config['debug'] = WORDBOOKER_TESTING && !$_POST['action'];
  42. #Wordbooker2 - Dev
  43. #define('WORDBOOKER_FB_APIKEY', '0138375357c1eb1257ed9970ec1a274c');
  44. #define('WORDBOOKER_FB_SECRET', '4310b484ec5236694cfa4b94166aca61');
  45. #define('WORDBOOKER_FB_ID', '111687885534181');
  46. # Wordbooker - live
  47. if (!defined('WORDBOOKER_PREMIUM')) {
  48. define('APP TITLE','Wordbooker');
  49. define('WORDBOOKER_FB_APIKEY', '0cbf13c858237f5d74ef0c32a4db11fd');
  50. define('WORDBOOKER_FB_SECRET', 'df04f22f3239fb75bf787f440e726f31');
  51. define('WORDBOOKER_FB_ID', '254577506873');
  52. define('WORDBOOKER_APPLICATION_NAME','Wordbooker');
  53. define('OPENGRAPH_NAMESPACE','wordbooker');
  54. define('OPENGRAPH_ACCESS_TOKEN','AAAAAO0YAejkBANAjpuFluuIfFnNeOkRBUXps0UqQ9aTBFNAYpOS11f7835w676UOxtyZB4KDekuoS6BXwrs1Y95fDrnAZD');
  55. }
  56. define('WORDBOOKER_FB_APIVERSION', '1.0');
  57. define('WORDBOOKER_FB_DOCPREFIX','http://wiki.developers.facebook.com/index.php/');
  58. define('WORDBOOKER_FB_PUBLISH_STREAM', 'publish_stream');
  59. define('WORDBOOKER_FB_READ_STREAM', 'read_stream');
  60. define('WORDBOOKER_FB_STATUS_UPDATE',"status_update");
  61. define('WORDBOOKER_FB_CREATE_NOTE',"create_note");
  62. define('WORDBOOKER_FB_OFFLINE_ACCESS',"offline_access");
  63. define('WORDBOOKER_FB_MANAGE_PAGES',"manage_pages");
  64. define('WORDBOOKER_FB_PHOTO_UPLOAD',"photo_upload");
  65. define('WORDBOOKER_FB_VIDEO_UPLOAD',"video_upload");
  66. define('WORDBOOKER_FB_READ_FRIENDS',"read_friendlists");
  67. define('WORDBOOKER_SETTINGS', 'wordbooker_settings');
  68. define('WORDBOOKER_OPTION_SCHEMAVERS', 'schema_vers');
  69. define('WORDBOOKER_SCHEMA_VERSION', '2.4');
  70. $new_wb_table_prefix=$wpdb->base_prefix;
  71. if (isset ($db_prefix) ) { $new_wb_table_prefix=$db_prefix;}
  72. define('WORDBOOKER_ERRORLOGS', $new_wb_table_prefix . 'wordbooker_errorlogs');
  73. define('WORDBOOKER_POSTLOGS', $new_wb_table_prefix . 'wordbooker_postlogs');
  74. define('WORDBOOKER_USERDATA', $new_wb_table_prefix . 'wordbooker_userdata');
  75. define('WORDBOOKER_USERSTATUS', $new_wb_table_prefix . 'wordbooker_userstatus');
  76. define('WORDBOOKER_POSTCOMMENTS', $new_wb_table_prefix . 'wordbooker_postcomments');
  77. define('WORDBOOKER_PROCESS_QUEUE', $new_wb_table_prefix . 'wordbooker_process_queue');
  78. define('WORDBOOKER_FB_FRIENDS', $new_wb_table_prefix . 'wordbooker_fb_friends');
  79. define('WORDBOOKER_FB_FRIEND_LISTS', $new_wb_table_prefix . 'wordbooker_fb_friend_lists');
  80. define('WORDBOOKER_MINIMUM_ADMIN_LEVEL', 'edit_posts'); /* Contributor role or above. */
  81. define('WORDBOOKER_SETTINGS_PAGENAME', 'wordbooker');
  82. define('WORDBOOKER_SETTINGS_URL', 'options-general.php?page=' . WORDBOOKER_SETTINGS_PAGENAME);
  83. $wordbooker_wp_version_tuple = explode('.', $wp_version);
  84. define('WORDBOOKER_WP_VERSION', $wordbooker_wp_version_tuple[0] * 10 + $wordbooker_wp_version_tuple[1]);
  85. if (function_exists('json_encode')) {
  86. define('WORDBOOKER_JSON_ENCODE', 'PHP');
  87. } else {
  88. define('WORDBOOKER_JSON_ENCODE', 'Wordbook');
  89. }
  90. if (function_exists('json_decode') ) {
  91. define('WORDBOOKER_JSON_DECODE', 'PHP');
  92. } else {
  93. define('WORDBOOKER_JSON_DECODE', 'Wordbooker');
  94. }
  95. if (function_exists('simplexml_load_string') ) {
  96. define('WORDBOOKER_SIMPLEXML', 'provided by PHP');
  97. } else {
  98. define('WORDBOOKER_SIMPLEXML', 'is missing - this is a problem');
  99. }
  100. function wordbooker_load_apis() {
  101. if (WORDBOOKER_JSON_DECODE == 'Wordbooker') {
  102. function json_decode($json)
  103. {
  104. $comment = false;
  105. $out = '$x=';
  106. for ($i=0; $i<strlen($json); $i++)
  107. {
  108. if (!$comment)
  109. {
  110. if ($json[$i] == '{') $out .= ' array(';
  111. else if ($json[$i] == '}') $out .= ')';
  112. else if ($json[$i] == ':') $out .= '=>';
  113. else $out .= $json[$i];
  114. }
  115. else $out .= $json[$i];
  116. if ($json[$i] == '"') $comment = !$comment;
  117. }
  118. eval($out . ';');
  119. return $x;
  120. }
  121. }
  122. if (WORDBOOKER_JSON_ENCODE == 'Wordbook') {
  123. function json_encode($var) {
  124. if (is_array($var)) {
  125. $encoded = '{';
  126. $first = true;
  127. foreach ($var as $key => $value) {
  128. if (!$first) {
  129. $encoded .= ',';
  130. } else {
  131. $first = false;
  132. }
  133. $encoded .= "\"$key\":"
  134. . json_encode($value);
  135. }
  136. $encoded .= '}';
  137. return $encoded;
  138. }
  139. if (is_string($var)) {
  140. return "\"$var\"";
  141. }
  142. return $var;
  143. }
  144. }
  145. }
  146. /******************************************************************************
  147. * Wordbook options.
  148. */
  149. function wordbooker_options() {
  150. return get_option(WORDBOOKER_SETTINGS);
  151. }
  152. function wordbooker_set_options($options) {
  153. update_option(WORDBOOKER_SETTINGS, $options);
  154. }
  155. function wordbooker_get_option($key) {
  156. $options = wordbooker_options();
  157. return isset($options[$key]) ? $options[$key] : null;
  158. }
  159. function wordbooker_set_option($key, $value) {
  160. $options = wordbooker_options();
  161. $options[$key] = $value;
  162. wordbooker_set_options($options);
  163. }
  164. function wordbooker_delete_option($key) {
  165. $options = wordbooker_options();
  166. unset($options[$key]);
  167. update_option(WORDBOOKER_SETTINGS, $options);
  168. }
  169. /******************************************************************************
  170. * DB schema.
  171. */
  172. function wordbooker_activate() {
  173. global $wpdb, $table_prefix;
  174. wp_cache_flush();
  175. $errors = array();
  176. $result = $wpdb->query('
  177. CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_POSTLOGS . ' (
  178. `post_id` bigint(20) NOT NULL,
  179. `blog_id` bigint(20) NOT NULL,
  180. `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  181. PRIMARY KEY (`blog_id`,`post_id`)
  182. ) DEFAULT CHARSET=utf8;
  183. ');
  184. if ($result === false)
  185. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_POSTLOGS;
  186. $result = $wpdb->query('
  187. CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_ERRORLOGS . ' (
  188. `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  189. `user_ID` bigint(20) unsigned NOT NULL,
  190. `method` longtext NOT NULL,
  191. `error_code` int(11) NOT NULL,
  192. `error_msg` longtext NOT NULL,
  193. `post_id` bigint(20) NOT NULL,
  194. `blog_id` bigint(20) NOT NULL,
  195. `sequence_id` bigint(20) NOT NULL auto_increment,
  196. `diag_level` int(4) default NULL,
  197. PRIMARY KEY (`sequence_id`),
  198. KEY `timestamp_idx` (`timestamp`),
  199. KEY `blog_idx` (`blog_id`)
  200. ) DEFAULT CHARSET=utf8;
  201. ');
  202. if ($result === false)
  203. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_ERRORLOGS;
  204. $result = $wpdb->query('
  205. CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_USERDATA . ' (
  206. `user_ID` bigint(20) unsigned NOT NULL,
  207. `uid` varchar(80) default NULL,
  208. `expires` varchar(80) default NULL,
  209. `access_token` varchar(255) default NULL,
  210. `sig` varchar(80) default NULL,
  211. `use_facebook` tinyint(1) default 1,
  212. `onetime_data` longtext,
  213. `facebook_error` longtext,
  214. `secret` varchar(80) default NULL,
  215. `session_key` varchar(80) default NULL,
  216. `facebook_id` varchar(40) default NULL,
  217. `name` varchar(250) default NULL,
  218. `status` varchar(2048) default NULL,
  219. `updated` int(20) default NULL,
  220. `url` varchar(250) default NULL,
  221. `pic` varchar(250) default NULL,
  222. `pages` longtext,
  223. `auths_needed` int(1) default NULL,
  224. `blog_id` bigint(20) default NULL,
  225. PRIMARY KEY (`user_ID`),
  226. KEY `facebook_idx` (`facebook_id`)
  227. ) DEFAULT CHARSET=utf8;
  228. ');
  229. if ($result === false)
  230. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_USERDATA;
  231. $result = $wpdb->query('
  232. CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_POSTCOMMENTS . ' (
  233. `fb_post_id` varchar(40) NOT NULL,
  234. `user_id` bigint(20) NOT NULL,
  235. `comment_timestamp` int(20) NOT NULL,
  236. `wp_post_id` int(11) NOT NULL,
  237. `blog_id` bigint(20) NOT NULL,
  238. `wp_comment_id` int(20) NOT NULL,
  239. PRIMARY KEY (`blog_id`,`wp_post_id`,`fb_post_id`,`wp_comment_id`)
  240. ) DEFAULT CHARSET=utf8;
  241. ');
  242. if ($result === false)
  243. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_POSTCOMMENTS;
  244. $result = $wpdb->query('
  245. CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_USERSTATUS . ' (
  246. `user_ID` bigint(20) unsigned NOT NULL,
  247. `name` varchar(250) default NULL,
  248. `status` varchar(2048) default NULL,
  249. `updated` int(20) default NULL,
  250. `url` varchar(250) default NULL,
  251. `pic` varchar(250) default NULL,
  252. `blog_id` bigint(20) NOT NULL default 0,
  253. `facebook_id` varchar(40) default NULL,
  254. PRIMARY KEY (`user_ID`,`blog_id`)
  255. ) DEFAULT CHARSET=utf8;
  256. ');
  257. if ($result === false)
  258. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_USERSTATUS;
  259. $result = $wpdb->query(' CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_FB_FRIENDS . ' (
  260. `user_id` int(11) NOT NULL,
  261. `blog_id` bigint(20) NOT NULL,
  262. `facebook_id` varchar(20) NOT NULL,
  263. `name` varchar(200) NOT NULL,
  264. PRIMARY KEY (`user_id`,`facebook_id`,`blog_id`),
  265. KEY `user_id_idx` (`user_id`),
  266. KEY `fb_id_idx` (`facebook_id`)
  267. ) DEFAULT CHARSET=utf8;
  268. ');
  269. if ($result === false)
  270. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_FB_FRIENDS;
  271. $result = $wpdb->query('
  272. CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_FB_FRIEND_LISTS . ' (
  273. `user_id` int(11) NOT NULL,
  274. `flid` varchar(80) NOT NULL,
  275. `owner` varchar(80) NOT NULL,
  276. `name` varchar(240) NOT NULL,
  277. PRIMARY KEY (`user_id`,`flid`)
  278. ) DEFAULT CHARSET=utf8;
  279. ');
  280. if ($result === false)
  281. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_FB_FRIEND_LISTS;
  282. $result = $wpdb->query(' CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_PROCESS_QUEUE . ' (
  283. `entry_type` varchar(20) NOT NULL,
  284. `blog_id` int(11) NOT NULL,
  285. `post_id` int(11) NOT NULL,
  286. `priority` int(11) NOT NULL,
  287. `status` varchar(20) NOT NULL,
  288. PRIMARY KEY (`blog_id`,`post_id`)
  289. ) DEFAULT CHARSET=utf8;
  290. ');
  291. if ($result === false)
  292. $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_PROCESS_QUEUE ;
  293. if ($errors) {
  294. echo '<div id="message" class="updated fade">' . "\n";
  295. foreach ($errors as $errormsg) {
  296. _e("$errormsg<br />\n", 'wordbooker');
  297. }
  298. echo "</div>\n";
  299. #return;
  300. }
  301. wordbooker_set_option(WORDBOOKER_OPTION_SCHEMAVERS, 2.4);
  302. $wordbooker_settings=wordbooker_options();
  303. #Setup the cron. We clear it first in case someone did a dirty de-install.
  304. $dummy=wp_clear_scheduled_hook('wb_cron_job');
  305. $dummy=wp_schedule_event(time(), 'hourly', 'wb_cron_job');
  306. }
  307. function wordbooker_upgrade() {
  308. global $wpdb, $table_prefix,$blog_id;
  309. $errors = array();
  310. #return;
  311. # We use this to make changes to Schema versions. We need to get the current schema version the user is using and then "upgrade" the various tables.
  312. $wordbooker_settings=wordbooker_options();
  313. # var_dump($wordbooker_settings);
  314. if (! isset($wordbooker_settings['schema_vers'])) {wordbooker_activate(); return;}
  315. if ($wordbooker_settings['schema_vers']< (float) WORDBOOKER_SCHEMA_VERSION ) {
  316. _e("Database changes being applied", 'wordbooker');
  317. } else {
  318. return;
  319. }
  320. if ($wordbooker_settings['schema_vers']=='2') {
  321. $result = $wpdb->query('
  322. ALTER TABLE '. WORDBOOKER_POSTCOMMENTS. ' DROP PRIMARY KEY , DROP INDEX fb_comment_id,
  323. ADD PRIMARY KEY ( `blog_id` , `wp_post_id` , `fb_post_id` , `wp_comment_id` )
  324. ');
  325. # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
  326. wordbooker_set_option('schema_vers', "2.1");
  327. }
  328. if ($wordbooker_settings['schema_vers']=='2.1') {
  329. $result = $wpdb->query('
  330. ALTER TABLE '. WORDBOOKER_POSTCOMMENTS. ' ADD `user_id` BIGINT( 20 ) NOT NULL
  331. ');
  332. # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
  333. wordbooker_set_option('schema_vers', "2.2");
  334. }
  335. if ($wordbooker_settings['schema_vers']=='2.2') {
  336. $result = $wpdb->query('
  337. ALTER TABLE '. WORDBOOKER_ERRORLOGS. ' ADD `sequence_id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT , ADD `diag_level` INT(4) NULL, ADD PRIMARY KEY ( `sequence_id` )
  338. ');
  339. # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
  340. wordbooker_set_option('schema_vers', "2.3");
  341. }
  342. if ($wordbooker_settings['schema_vers']=='2.3') {
  343. $result = $wpdb->query('
  344. ALTER TABLE '. WORDBOOKER_ERRORLOGS. ' ADD `sequence_id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT , ADD `diag_level` INT(4) NULL, ADD PRIMARY KEY ( `sequence_id` )
  345. ');
  346. # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
  347. wordbooker_set_option('schema_vers', "2.4");
  348. }
  349. $dummy=wp_clear_scheduled_hook('wb_cron_job');
  350. $dummy=wp_schedule_event(time(), 'hourly', 'wb_cron_job');
  351. wordbooker_set_option('schema_vers', WORDBOOKER_SCHEMA_VERSION );
  352. wp_cache_flush();
  353. }
  354. function wordbooker_delete_user($user_id,$level) {
  355. global $wpdb;
  356. $errors = array();
  357. $table_array[1]=array(WORDBOOKER_USERDATA);
  358. $table_array[2]=array(WORDBOOKER_USERDATA,WORDBOOKER_USERSTATUS);
  359. $table_array[3]=array(WORDBOOKER_USERDATA,WORDBOOKER_USERSTATUS,WORDBOOKER_FB_FRIENDS,WORDBOOKER_FB_FRIEND_LISTS);
  360. foreach ($table_array[$level] as $tablename) {
  361. $result = $wpdb->query('DELETE FROM ' . $tablename . ' WHERE user_ID = ' . $user_id . '');
  362. #var_dump($result);
  363. }
  364. if ($errors) {
  365. echo '<div id="message" class="updated fade">' . "\n";
  366. foreach ($errors as $errormsg) {
  367. _e("$errormsg<br />\n", 'wordbooker');
  368. }
  369. echo "</div>\n";
  370. }
  371. }
  372. /******************************************************************************
  373. * Wordbook user data.
  374. */
  375. function wordbooker_get_userdata($user_id) {
  376. global $wpdb;
  377. $sql='SELECT onetime_data,facebook_error,secret,session_key,user_ID,access_token,facebook_id,pages,name FROM ' . WORDBOOKER_USERDATA . ' WHERE user_ID = ' . $user_id ;
  378. $rows = $wpdb->get_results($sql);
  379. if ($rows) {
  380. $rows[0]->onetime_data = unserialize($rows[0]->onetime_data);
  381. $rows[0]->facebook_error = unserialize($rows[0]->facebook_error);
  382. $rows[0]->secret = unserialize($rows[0]->secret);
  383. $rows[0]->session_key = unserialize($rows[0]->session_key);
  384. $rows[0]->access_token = unserialize($rows[0]->access_token);
  385. $rows[0]->pages = unserialize($rows[0]->pages);
  386. return $rows[0];
  387. }
  388. return null;
  389. }
  390. function wordbooker_set_userdata($onetime_data, $facebook_error,$secret, $session,$facebook_id) {
  391. global $user_ID, $wpdb,$blog_id;
  392. wordbooker_delete_userdata();
  393. $result = $wpdb->query("
  394. INSERT INTO " . WORDBOOKER_USERDATA . " (
  395. user_ID
  396. , onetime_data
  397. , facebook_error
  398. , secret
  399. , session_key
  400. , uid
  401. , expires
  402. , access_token
  403. , sig
  404. ,blog_id
  405. ,facebook_id
  406. ) VALUES (
  407. " . $user_ID . "
  408. , '" . serialize($onetime_data) . "'
  409. , '" . serialize($facebook_error) . "'
  410. , '" . serialize($secret) . "'
  411. , '" . serialize($session->session_key)."'
  412. , '". serialize($session->uid)."'
  413. , '". serialize($session->expires)."'
  414. , '". serialize($session->access_token)."'
  415. , '". serialize($session->sig)."'
  416. , " . $blog_id . "
  417. , '". $facebook_id."'
  418. )
  419. ");
  420. }
  421. function wordbooker_set_userdata2( $onetime_data, $facebook_error, $secret, $session_key,$user_ID) {
  422. global $wpdb;
  423. $sql= "Update " . WORDBOOKER_USERDATA . " set
  424. onetime_data = '" . serialize($onetime_data) . "'
  425. , facebook_error = '" . serialize($facebook_error) . "'
  426. , secret = '" . serialize($secret) . "'
  427. , session_key = '" . serialize($session_key) . "'
  428. where user_id=".$user_ID;
  429. $result = $wpdb->query($sql);
  430. }
  431. function wordbooker_update_userdata($wbuser) {
  432. return wordbooker_set_userdata2( $wbuser->onetime_data, $wbuser->facebook_error, $wbuser->secret, $wbuser->session_key,$wbuser->user_ID);
  433. }
  434. function wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code, $error_msg, $post_id) {
  435. $wbuser->facebook_error = array(
  436. 'method' => $method,
  437. 'error_code' => mysql_real_escape_string ($error_code),
  438. 'error_msg' => mysql_real_escape_string ($error_msg),
  439. 'postid' => $post_id,
  440. );
  441. wordbooker_update_userdata($wbuser);
  442. wordbooker_append_to_errorlogs($method, $error_code, $error_msg, $post_id,$wbuser->user_ID);
  443. }
  444. function wordbooker_clear_userdata_facebook_error($wbuser) {
  445. $wbuser->facebook_error = null;
  446. return wordbooker_update_userdata($wbuser);
  447. }
  448. function wordbooker_remove_user(){
  449. global $user_ID;
  450. # Delete the user's meta
  451. $wordbooker_user_settings_id="wordbookuser".$blog_id;
  452. delete_usermeta( $user_ID, $wordbooker_user_settings_id);
  453. # Then go and delete their data from the tables
  454. wordbooker_delete_user($user_ID,3);
  455. }
  456. function wordbooker_delete_userdata() {
  457. global $user_ID;
  458. wordbooker_delete_user($user_ID,2);
  459. }
  460. /******************************************************************************
  461. * Post logs - record time of last post to Facebook
  462. */
  463. function wordbooker_trim_postlogs() {
  464. # Forget that something has been posted to Facebook if it's been there more than a year.
  465. global $wpdb;
  466. $result = $wpdb->query('
  467. DELETE FROM ' . WORDBOOKER_POSTLOGS . '
  468. WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL 365 DAY)
  469. ');
  470. }
  471. function wordbooker_postlogged($post_id,$tstamp=0) {
  472. global $wpdb,$wordbooker_post_options,$post;
  473. $wordbooker_settings = wordbooker_options();
  474. $wbo=get_post_meta($post_id, '_wordbooker_options', true);
  475. #if ($wbo["wordbooker_publish_default"]!='published') {
  476. $time=time() ;
  477. if (! isset($wordbooker_settings['wordbooker_republish_time_frame'])) $wordbooker_settings['wordbooker_republish_time_frame']='3';
  478. $sql='SELECT '. $time ." - UNIX_TIMESTAMP(post_date) as time, post_date_gmt,post_date,post_modified, post_modified_gmt,post_status FROM $wpdb->posts WHERE ID = " . $post_id;
  479. $rows = $wpdb->get_results($sql);
  480. wordbooker_debugger("Post is this old (Seconds) : ",$rows[0]->time,$post_id) ;
  481. #wordbooker_debugger("Post date : ",$rows[0]->post_date,$post_id) ;
  482. #wordbooker_debugger("Post modified : ",$rows[0]->post_modified,$post_id) ;
  483. #wordbooker_debugger("Post status : ",$rows[0]->post_status,$post_id) ;
  484. #wordbooker_debugger("Post status flag : ",$wbo['wordbooker_new_post'],$post_id) ;
  485. #wordbooker_debugger("Scheduled Post: ",$wbo['wordbooker_scheduled_post'],$post_id) ;
  486. if ($tstamp==1) { return $rows[0]->time;}
  487. if ($tstamp==1 && !isset($_POST['original_post_status']) && !isset($_POST['screen'])) {return 0;}
  488. # If the post isn't actually being published we give up - just in case
  489. if ($rows[0]->post_status!='publish') { return true;}
  490. # If the post is new then return false
  491. if ($rows[0]->post_date == $rows[0]->post_modified) {return false;}
  492. if ($wbo['wordbooker_scheduled_post']!=0) {
  493. $wbo['wordbooker_scheduled_post']=0;
  494. $y=update_post_meta($post_id, '_wordbooker_options', $wbo);
  495. return false;
  496. }
  497. if ($wbo['wordbooker_new_post']!=0) {
  498. $wbo['wordbooker_new_post']=0;
  499. $y=update_post_meta($post_id, '_wordbooker_options', $wbo);
  500. return false;
  501. }
  502. #}
  503. wordbooker_debugger("This post has already been published. So do checks "," ",$post_id) ;
  504. #if (!isset($_POST['original_post_status']) && !isset($_POST['screen'])) {return false;}
  505. // See if the user has overridden the repost on edit - i.e. they want to publish and be damned!
  506. if (isset ($wordbooker_post_options["wordbooker_publish_default"])) {
  507. wordbooker_debugger("Publish Post is set so user wants to republish "," ",$post_id) ;
  508. return false;
  509. }
  510. return true;
  511. }
  512. function wordbooker_insert_into_postlogs($post_id,$blog_id) {
  513. global $wpdb;
  514. wordbooker_delete_from_postlogs($post_id,$blog_id);
  515. if (!WORDBOOKER_TESTING) {
  516. $result = $wpdb->query(' INSERT INTO ' . WORDBOOKER_POSTLOGS . ' (post_id,blog_id) VALUES (' . $post_id . ','.$blog_id.')');
  517. }
  518. }
  519. function wordbooker_insert_into_process_queue($post_id,$blog_id,$entry_type) {
  520. global $wpdb;
  521. $result = $wpdb->query(' INSERT INTO ' . WORDBOOKER_PROCESS_QUEUE . ' (entry_type,blog_id,post_id,status) VALUES ("' . $entry_type. '",' .$blog_id .',' . $post_id . ',"B")');
  522. }
  523. function wordbooker_delete_from_process_queue($post_id,$blog_id) {
  524. global $wpdb,$blog_id;
  525. $result = $wpdb->query(' DELETE FROM ' . WORDBOOKER_PROCESS_QUEUE . ' where post_id='.$post_id.' and blog_id='.$blog_id);
  526. }
  527. function wordbooker_delete_from_postlogs($post_id,$blog_id) {
  528. global $wpdb,$blog_id;
  529. $result = $wpdb->query('DELETE FROM ' . WORDBOOKER_POSTLOGS . ' WHERE post_id = ' . $post_id . ' and blog_id='.$blog_id);
  530. }
  531. function wordbooker_delete_from_commentlogs($post_id,$blog_id) {
  532. global $wpdb,$blog_id;
  533. $result = $wpdb->query('DELETE FROM ' . WORDBOOKER_POSTCOMMENTS . ' WHERE wp_post_id = ' . $post_id . ' and blog_id='.$blog_id);
  534. }
  535. /******************************************************************************
  536. * Error logs - record errors
  537. */
  538. function wordbooker_hyperlinked_method($method) {
  539. return '<a href="'. WORDBOOKER_FB_DOCPREFIX . $method . '"'. ' title="Facebook API documentation" target="facebook"'. '>'. $method. '</a>';
  540. }
  541. function wordbooker_trim_errorlogs() {
  542. global $user_ID, $wpdb,$blog_id;
  543. $result = $wpdb->query('
  544. DELETE FROM ' . WORDBOOKER_ERRORLOGS . '
  545. WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL 2 DAY) and blog_id ='.$blog_id);
  546. }
  547. function wordbooker_clear_errorlogs() {
  548. global $user_ID, $wpdb,$blog_id;
  549. $result = $wpdb->query('
  550. DELETE FROM ' . WORDBOOKER_ERRORLOGS . '
  551. WHERE user_ID = ' . $user_ID . ' and error_code > -1 and blog_id ='.$blog_id);
  552. if ($result === false) {
  553. echo '<div id="message" class="updated fade">';
  554. _e('Failed to clear error logs.', 'wordbooker');
  555. echo "</div>\n";
  556. }
  557. }
  558. function wordbooker_clear_diagnosticlogs() {
  559. global $user_ID, $wpdb,$blog_id;
  560. $result = $wpdb->query('
  561. DELETE FROM ' . WORDBOOKER_ERRORLOGS . '
  562. WHERE blog_id ='.$blog_id);
  563. if ($result === false) {
  564. echo '<div id="message" class="updated fade">';
  565. _e('Failed to clear Diagnostic logs.', 'wordbooker');
  566. echo "</div>\n";
  567. }
  568. }
  569. function wordbooker_append_to_errorlogs($method, $error_code, $error_msg,$post_id,$user_id) {
  570. global $user_ID, $wpdb,$blog_id;
  571. if ($post_id == null) {
  572. $post_id = 0;
  573. } else {
  574. $post = get_post($post_id);
  575. }
  576. $result = $wpdb->insert(WORDBOOKER_ERRORLOGS,
  577. array('user_ID' => $user_id,
  578. 'method' => $method,
  579. 'error_code' => $error_code,
  580. 'error_msg' => $error_msg,
  581. 'post_id' => $post_id,
  582. 'blog_id' => $blog_id,
  583. 'diag_level'=> 900
  584. ),
  585. array('%d', '%s', '%d', '%s', '%d','%d')
  586. );
  587. }
  588. function wordbooker_delete_from_errorlogs($post_id) {
  589. global $wpdb,$blog_id;
  590. $result = $wpdb->query('DELETE FROM ' . WORDBOOKER_ERRORLOGS . ' WHERE post_id = ' . $post_id .' and blog_id ='.$blog_id );
  591. }
  592. function wordbooker_render_errorlogs() {
  593. global $user_ID, $wpdb,$blog_id;
  594. $diaglevel=wordbooker_get_option('wordbooker_advanced_diagnostics_level');
  595. #var_dump($diaglevel);
  596. #$sql='SELECT * FROM ' . WORDBOOKER_ERRORLOGS . ' WHERE user_ID = ' . $user_ID . ' and blog_id='.$blog_id.' and diag_level >'.$diaglevel.' order by sequence_id asc';
  597. #var_dump($sql);
  598. $rows = $wpdb->get_results('SELECT * FROM ' . WORDBOOKER_ERRORLOGS . ' WHERE user_ID = ' . $user_ID . ' and blog_id='.$blog_id.' and diag_level >'.$diaglevel.' order by sequence_id asc');
  599. if ($rows) {
  600. ?>
  601. <h3><?php _e('Diagnostic Messages', 'wordbooker'); ?></h3>
  602. <div class="wordbooker_errors">
  603. <p>
  604. </p>
  605. <table class="wordbooker_errorlogs">
  606. <tr>
  607. <th>Post</th>
  608. <th>Time</th>
  609. <th>Action</th>
  610. <th>Message</th>
  611. <th>Error Code</th>
  612. </tr>
  613. <?php
  614. foreach ($rows as $row) {
  615. $hyperlinked_post = '';
  616. if (($post = get_post($row->post_id))) {
  617. $hyperlinked_post = '<a href="'. get_permalink($row->post_id) . '">'. apply_filters('the_title',get_the_title($row->post_id)) . '</a>';
  618. }
  619. $hyperlinked_method= wordbooker_hyperlinked_method($row->method);
  620. if ($row->error_code>1){ echo "<tr class='error'>";} else {echo "<tr class='diag'>";}
  621. ?>
  622. <td><?php if ($row->post_id>0) { echo $hyperlinked_post;} else {echo "-";} ?></td>
  623. <td><?php echo $row->timestamp; ?></td>
  624. <td><?php echo $row->method; ?></td>
  625. <td><?php echo stripslashes($row->error_msg); ?></td>
  626. <td><?php if ($row->error_code>1) {echo $row->error_code;} else { echo "-";} ?></td>
  627. </tr>
  628. <?php
  629. }
  630. ?>
  631. </table>
  632. <form action="<?php echo WORDBOOKER_SETTINGS_URL; ?>" method="post">
  633. <input type="hidden" name="action" value="clear_errorlogs" />
  634. <p class="submit" style="text-align: center;">
  635. <input type="submit" value="<?php _e('Clear Diagnostic Messages', 'wordbooker'); ?>" />
  636. </p>
  637. </form>
  638. </div>
  639. <hr>
  640. <?php
  641. }
  642. }
  643. /******************************************************************************
  644. * Wordbooker setup and administration.
  645. */
  646. function wordbooker_admin_load() {
  647. if (isset($POST['reset_user_config'])){
  648. wordbooker_delete_userdata();
  649. return;}
  650. if (!$_POST['action'])
  651. return;
  652. switch ($_POST['action']) {
  653. case 'delete_userdata':
  654. # Catch if they got here using the perm_save/cache refresh
  655. if ( ! isset ($_POST["perm_save"])) {
  656. wordbooker_delete_userdata();
  657. }
  658. wp_redirect(WORDBOOKER_SETTINGS_URL);
  659. break;
  660. case 'clear_errorlogs':
  661. wordbooker_clear_diagnosticlogs();
  662. wp_redirect(WORDBOOKER_SETTINGS_URL);
  663. break;
  664. case 'clear_diagnosticlogs':
  665. wordbooker_clear_diagnosticlogs();
  666. wp_redirect(WORDBOOKER_SETTINGS_URL);
  667. break;
  668. case 'no_facebook':
  669. wordbooker_set_userdata(false, null, null, null,null,null);
  670. wp_redirect('/wp-admin/index.php');
  671. break;
  672. }
  673. exit;
  674. }
  675. function wordbooker_admin_head() {
  676. ?>
  677. <style type="text/css">
  678. .wordbooker_setup { margin: 0 3em; }
  679. .wordbooker_notices { margin: 0 3em; }
  680. .wordbooker_status { margin: 0 3em; }
  681. .wordbooker_errors { margin: 0 3em; }
  682. .wordbooker_thanks { margin: 0 3em; }
  683. .wordbooker_thanks ul { margin: 1em 0 1em 2em; list-style-type: disc; }
  684. .wordbooker_support { margin: 0 3em; }
  685. .wordbooker_support ul { margin: 1em 0 1em 2em; list-style-type: disc; }
  686. .facebook_picture {
  687. float: right;
  688. border: 1px solid black;
  689. padding: 2px;
  690. margin: 0 0 1ex 2ex;
  691. }
  692. .wordbooker_errorcolor { color: #c00; }
  693. table.wordbooker_errorlogs { text-align: center; }
  694. table.wordbooker_errorlogs th, table.wordbooker_errorlogs td {
  695. padding: 0.5ex 1.5em;
  696. }
  697. table.wordbooker_errorlogs th { background-color: #999; }
  698. table.wordbooker_errorlogs tr.error td { background-color: #f66; }
  699. table.wordbooker_errorlogs tr.diag td { background-color: #CCC; }
  700. </style>
  701. <?php
  702. }
  703. function wordbooker_option_notices() {
  704. global $user_ID, $wp_version;
  705. wordbooker_upgrade();
  706. wordbooker_trim_postlogs();
  707. wordbooker_trim_errorlogs();
  708. $errormsg = null;
  709. if (!function_exists('curl_init')) {
  710. $errormsg .= __('Wordbooker needs the CURL PHP extension to work. Please install / enable it and try again','wordbooker').' <br />';
  711. }
  712. if (!function_exists('json_decode')) {
  713. $errormsg .= __('Wordbooker needs the JSON PHP extension. Please install / enable it and try again ','wordbooker').'<br />';
  714. }
  715. if (!function_exists('simplexml_load_string')) {
  716. $errormsg .= __('Your PHP install is missing <code>simplexml_load_string()</code> ','wordbooker')."<br />";
  717. }
  718. $wbuser = wordbooker_get_userdata($user_ID);
  719. if (strlen($wbuser->access_token)< 50 ) {
  720. $errormsg .=__("Wordbooker needs to be set up", 'wordbooker')."<br />";
  721. } else if ($wbuser->facebook_error) {
  722. $method = $wbuser->facebook_error['method'];
  723. $error_code = $wbuser->facebook_error['error_code'];
  724. $error_msg = $wbuser->facebook_error['error_msg'];
  725. $post_id = $wbuser->facebook_error['postid'];
  726. $suffix = '';
  727. if ($post_id != null && ($post = get_post($post_id))) {
  728. wordbooker_delete_from_postlogs($post_id);
  729. $suffix = __('for', 'wordbooker').' <a href="'. get_permalink($post_id) . '">'. get_the_title($post_id) . '</a>';
  730. }
  731. $errormsg .= sprintf(__("<a href='%s'>Wordbooker</a> failed to communicate with Facebook" . $suffix . ": method = %s, error_code = %d (%s). Your blog is OK, but Facebook didn't get the update.", 'wordbooker'), " ".WORDBOOKER_SETTINGS_URL," ".wordbooker_hyperlinked_method($method)," ".$error_code," ".$error_msg)."<br />";
  732. wordbooker_clear_userdata_facebook_error($wbuser);
  733. }
  734. if ($errormsg) {
  735. ?>
  736. <h3><?php _e('Notices', 'wordbooker'); ?></h3>
  737. <div class="wordbooker_notices" style="background-color: #f66;">
  738. <p><?php echo $errormsg; ?></p>
  739. </div>
  740. <?php
  741. }
  742. }
  743. function get_check_session(){
  744. global $facebook2,$user_ID;
  745. # This function basically checks for a stored session and if we have one it returns it, If we have no stored session then it gets one and stores it
  746. # OK lets go to the database and see if we have a session stored
  747. wordbooker_debugger("Getting Userdata "," ",0) ;
  748. $session = wordbooker_get_userdata($user_ID);
  749. if (strlen($session->access_token)>5) {
  750. var_dump($session);
  751. wordbooker_debugger("Session found. Check validity "," ",0) ;
  752. # We have a session ID so lets not get a new one
  753. # Put some session checking in here to make sure its valid
  754. try {
  755. # var_dump($session->access_token);
  756. wordbooker_debugger("Calling Facebook API : get current user "," ",0) ;
  757. # $attachment = array('access_token' => $session->access_token,);
  758. #var_dump($attachment);
  759. $ret_code=wordbooker_me($session->facebook_id,$session->access_token);
  760. # echo "mee";
  761. # var_dump($ret_code);
  762. }
  763. catch (Exception $e) {
  764. # We don't have a good session so
  765. wordbooker_debugger("User Session invalid - clear down data "," ",0) ;
  766. #wordbooker_delete_user($user_ID,1);
  767. return;
  768. }
  769. #var_dump($session);
  770. return $session->access_token;
  771. }
  772. else
  773. {
  774. # Are we coming back from a login with a session set?
  775. $zz=htmlspecialchars_decode ($_POST['session'])."<br>";
  776. $oldkey=explode("|",$zz);
  777. $newkey=explode("&expires",$zz);
  778. $session->access_token=$newkey[0];
  779. $session->session_key=$oldkey[1];
  780. $session->expires=0;
  781. $ret_code=wordbooker_me_status($session->facebook_id,$session->access_token);
  782. #echo "mee tooo";
  783. # var_dump($ret_code);
  784. wordbooker_debugger("Checking session (2) "," ",0) ;
  785. # $session = $facebook2->getSession();
  786. #var_dump($session);
  787. if (strlen($session->access_token)>5){
  788. wordbooker_debugger("Session found. Store it "," ",0) ;
  789. # Yes! so lets store it!y)
  790. wordbooker_set_userdata($onetime_data, $facebook_error, $secret,$session,$ret_code->id);
  791. return $session->access_token;
  792. }
  793. }
  794. }
  795. function wordbooker_option_setup($wbuser) {
  796. ?>
  797. <h3><?php _e('Setup', 'wordbooker'); ?></h3>
  798. <div class="wordbooker_setup">
  799. <?php
  800. $access_token=get_check_session();
  801. $loginUrl2='https://www.facebook.com/dialog/oauth?client_id='.WORDBOOKER_FB_ID.'&redirect_uri=https://wordbooker.tty.org.uk/index2.html?br='.urlencode(get_bloginfo('wpurl')).'&scope=publish_stream,offline_access,user_status,read_stream,email,user_groups,manage_pages,read_friendlists&response_type=token';
  802. if ( is_null($access_token) ) {
  803. wordbooker_debugger("No session found - lets login and authorise "," ",0,99) ;
  804. echo "<br />".__("Secure link ( may require you to add a new certificate for wordbooker.tty.org.uk ) Also you may get a warning about passing data on a non secure connection :",'wordbooker').'<br /><br /> <a href="'. $loginUrl2.'"> <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif" alt="Facebook Login Button" /> </a><br />';
  805. }
  806. else {
  807. wordbooker_debugger("Everything looks good so lets ask them to refresh "," ",0,99) ;
  808. echo __("Wordbooker should now be authorised. Please click on the Reload Page Button",'wordbooker').'<br> <form action="options-general.php?page=wordbooker" method="post">';
  809. echo '<p style="text-align: center;"><input type="submit" name="perm_save" class="button-primary" value="'. __('Reload Page', 'wordbooker').'" /></p>';
  810. echo '</form> ';
  811. }
  812. echo "</div></div>";
  813. }
  814. function wordbooker_status($user_id)
  815. {
  816. echo '<h3>'.__('Status', 'wordbooker').'</h3>';
  817. global $wpdb, $user_ID,$table_prefix,$blog_id;
  818. $wordbooker_user_settings_id="wordbookuser".$blog_id;
  819. $wordbookuser=get_usermeta($user_ID,$wordbooker_user_settings_id);
  820. if ($wordbookuser['wordbooker_disable_status']=='on') {return;}
  821. global $shortcode_tags;
  822. $result = wordbooker_get_cache($user_id);
  823. ?>
  824. <div class="wordbooker_status">
  825. <div class="facebook_picture">
  826. <a href="<?php echo $result->url; ?>" target="facebook">
  827. <img src="<?php echo $result->pic; ?>" /></a>
  828. </div>
  829. <p>
  830. <a href="<?php echo $result->url; ?>"><?php echo $result->name; ?></a> ( <?php echo $result->facebook_id; ?> )<br /><br />
  831. <i><?php echo "<p>".$result->status; ?></i></p>
  832. (<?php
  833. $current_offset=0;
  834. $current_offset = get_option('gmt_offset');
  835. echo date('D M j, g:i a', $result->updated+(3600*$current_offset)); ?>).
  836. <br /><br />
  837. <?php
  838. }
  839. function wordbooker_option_status($wbuser) {
  840. global $wpdb,$user_ID;
  841. #$fbclient = wordbooker_fbclient($wbuser);
  842. # Go to the cache and try to pull details
  843. $fb_info=wordbooker_get_cache($user_ID,'use_facebook,facebook_id',1);
  844. # If we're missing stuff lets kick the cache.
  845. if (! isset($fb_info->facebook_id)) {
  846. wordbooker_cache_refresh ($user_ID,$fbclient);
  847. $fb_info=wordbooker_get_cache($user_ID,'use_facebook,facebook_id',1);
  848. }
  849. # if (isset($fbclient->secret)){
  850. #var_dump($fb_info);
  851. if ($fb_info->use_facebook==1) {
  852. echo"<p>".__('Wordbooker appears to be configured and working just fine', 'wordbooker');
  853. wordbooker_check_permissions($wbuser,$user);
  854. echo "</p><p>".__("If you like, you can start over from the beginning (this does not delete your posting and comment history)", 'wordbooker').":</p>";
  855. }
  856. else
  857. {
  858. echo "<p>".__('Wordbooker is able to connect to Facebook', 'wordbooker').'</p>';
  859. # _e( 'Or, you can start over from the beginning');
  860. }
  861. echo'<form action="" method="post">';
  862. echo '<p style="text-align: center;"><input type="submit" class="button-primary" name="reset_user_config" value="'.__('Reset User Session', 'wordbooker').'" />';
  863. echo '&nbsp;&nbsp;<input type="submit" name="perm_save" class="button-primary" value="'. __('Refresh Status', 'wordbooker').'" /></p>';
  864. echo '</form> </div>';
  865. $description=__("Recent Facebook Activity for this site", 'wordbooker');
  866. $iframe='<iframe src="http://www.facebook.com/plugins/activity.php?site='.get_bloginfo('url').'&amp;width=600&amp;height=400&amp;header=true&amp;colorscheme=light&amp;font&amp;border_color&amp;recommendations=true" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:600px; height:400px"></iframe>';
  867. $activity="<hr><h3>".$description.'</h3><p>'.$iframe."</p></div>";
  868. $options = wordbooker_options();
  869. if (isset($options["wordbooker_fb_rec_act"])) { echo $activity; }
  870. }
  871. function wordbooker_version_ok($currentvers, $minimumvers) {
  872. #Lets strip out the text and any other bits of crap so all we're left with is numbers.
  873. $currentvers=trim(preg_replace("/[^0-9.]/ ", "", $currentvers ));
  874. $current = preg_split('/\D+/', $currentvers);
  875. $minimum = preg_split('/\D+/', $minimumvers);
  876. for ($ii = 0; $ii < min(count($current), count($minimum)); $ii++) {
  877. if ($current[$ii] < $minimum[$ii])
  878. return false;
  879. }
  880. if (count($current) < count($minimum))
  881. return false;
  882. return true;
  883. }
  884. function wordbooker_option_support() {
  885. global $wp_version,$wpdb,$user_ID,$facebook2;
  886. $wordbooker_settings=wordbooker_options();
  887. ?>
  888. <h3><?php _e('Support', 'wordbooker'); ?></h3>
  889. <div class="wordbooker_support">
  890. <?php _e('For feature requests, bug reports, and general support :', 'wordbooker'); ?>
  891. <ul>
  892. <li><?php _e('Check the ', 'wordbooker'); ?><a href="../wp-content/plugins/wordbooker/wordbooker_user_guide.pdf" target="wordpress"><?php _e('User Guide', 'wordbooker'); ?></a>.</li>
  893. <li><?php _e('Check the ', 'wordbooker'); ?><a href="http://wordpress.org/extend/plugins/wordbooker/other_notes/" target="wordpress"><?php _e('WordPress.org Notes', 'wordbooker'); ?></a>.</li>
  894. <li><?php _e('Try the ', 'wordbooker'); ?><a href="http://wordbooker.tty.org.uk/forums/" target="facebook"><?php _e('Wordbooker Support Forums', 'wordbooker'); ?></a>.</li>
  895. <li><?php _e('Enhancement requests can be made at the ', 'wordbooker'); ?><a href="http://code.google.com/p/wordbooker/" target="facebook"><?php _e('Wordbooker Project on Google Code', 'wordbooker'); ?></a>.</li>
  896. <li><?php _e('Consider upgrading to the ', 'wordbooker'); ?><a href="http://wordpress.org/download/"><?php _e('latest stable release', 'wordbooker'); ?></a> <?php _e(' of WordPress. ', 'wordbooker'); ?></li>
  897. <li><?php _e('Read the release notes for Wordbooker on the ', 'wordbooker'); ?><a href="http://wordbooker.tty.org.uk/current-release/">Wordbooker</a> <?php _e('blog.', 'wordbooker'); ?></li>
  898. <li><?php _e('Check the Wordbooker ', 'wordbooker'); ?><a href="http://wordbooker.tty.org.uk/faqs/">Wordbooker</a> <?php _e('FAQs', 'wordbooker'); ?></li>
  899. </ul>
  900. <br />
  901. <?php _e('Please provide the following information about your installation:', 'wordbooker'); ?>
  902. <ul>
  903. <?php
  904. $active_plugins = get_option('active_plugins');
  905. $plug_info=get_plugins();
  906. $phpvers = phpversion();
  907. $jsonvers=phpversion('json');
  908. if (!phpversion('json')) { $jsonvers="Installed but version not being returned";}
  909. $sxmlvers=phpversion('simplexml');
  910. if (!phpversion('simplexml')) { $sxmlvers=" No version being returned";}
  911. $mysqlvers = function_exists('mysql_get_client_info') ? mysql_get_client_info() : 'Unknown';
  912. # If we dont have the function then lets go and get the version the old way
  913. if ($mysqlvers=="Unknown") {
  914. $t=mysql_query("select version() as ve");
  915. $r=mysql_fetch_object($t);
  916. $mysqlvers = $r->ve;
  917. }
  918. $http_coding="No Multibyte support";
  919. $int_coding="No Multibyte support";
  920. $mb_language="No Multibyte support";
  921. #$t=mysql_query("show variables like 'character%'");
  922. if (function_exists('mb_convert_encoding')) {
  923. $http_coding=mb_http_output();
  924. $int_coding=mb_internal_encoding();
  925. $mb_language=mb_language();
  926. }
  927. $curlcontent=__("Curl is not installed",'wordbooker');
  928. if (function_exists('curl_init')) {
  929. $ch = curl_init();
  930. curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/platform');
  931. curl_setopt($ch, CURLOPT_HEADER, 0);
  932. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  933. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  934. curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/includes/fb_ca_chain_bundle.crt');
  935. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
  936. $curlcontent = @curl_exec($ch);
  937. $x=json_decode($curlcontent);
  938. #var_dump($x->name);
  939. $curlstatus=__("Curl is available but cannot access Facebook - This is a problem (",'wordbooker').curl_errno($ch)." - ". curl_error($ch) ." )";
  940. if ($x->name=="Facebook Platform") {$curlstatus=__("Curl is available and can access Facebook - All is OK",'wordbooker');}
  941. curl_close($ch);
  942. }
  943. $new_wb_table_prefix=$wpdb->base_prefix;
  944. if (isset ($db_prefix) ) { $new_wb_table_prefix=$db_prefix;}
  945. $info = array(
  946. 'Wordbooker' => $plug_info['wordbooker/wordbooker.php']['Version'],
  947. 'Wordbooker ID'=>WORDBOOKER_FB_ID,
  948. 'Wordbooker Schema' => $wordbooker_settings['schema_vers'],
  949. 'WordPress' => $wp_version,
  950. 'Table prefix' =>$new_wb_table_prefix,
  951. 'PHP' => $phpvers,
  952. 'PHP Memory Usage (MB)' => memory_get_usage(true)/1024/1024,
  953. 'JSON Encode' => WORDBOOKER_JSON_ENCODE,
  954. 'JSON Decode' => WORDBOOKER_JSON_DECODE,
  955. 'Curl Status' => $curlstatus,
  956. # 'Fopen Status' => $fopenstat2.$fopenstat,
  957. 'JSON Version' => $jsonvers,
  958. 'SimpleXML library' => $sxmlvers." (". WORDBOOKER_SIMPLEXML.")",
  959. 'HTTP Output Character Encoding'=>$http_coding,
  960. 'Internal PHP Character Encoding'=>$int_coding,
  961. 'MySQL' => $mysqlvers,
  962. # 'Facebook Transaction limit'=>$result2,
  963. );
  964. $version_errors = array();
  965. $phpminvers = '5.0';
  966. $mysqlminvers = '4.0';
  967. if (!wordbooker_version_ok($phpvers, $phpminvers)) {
  968. $version_errors['PHP'] = $phpminvers;
  969. }
  970. if ($mysqlvers != 'Unknown' && !wordbooker_version_ok($mysqlvers, $mysqlminvers)) {
  971. $version_errors['MySQL'] = $mysqlminvers;
  972. }
  973. foreach ($info as $key => $value) {
  974. $suffix = '';
  975. if (($minvers = $version_errors[$key])) {
  976. $suffix = " <span class=\"wordbooker_errorcolor\">" . " (need $key version $minvers or greater)" . " </span>";
  977. }
  978. echo "<li>$key: <b>$value</b>$suffix</li>";
  979. }
  980. if (!function_exists('simplexml_load_string')) {
  981. _e("<li>XML: your PHP is missing <code>simplexml_load_string()</code></li>", 'wordbooker');
  982. }
  983. $rows = $wpdb->get_results("show variables like 'character_set%'");
  984. foreach ($rows as $chardata){
  985. echo "<li> Database ". $chardata->Variable_name ." : <b> ".$chardata->Value ."</b></li>";
  986. }
  987. $rows = $wpdb->get_results("show variables like 'collation%'");
  988. foreach ($rows as $chardata){
  989. echo "<li> Database ". $chardata->Variable_name ." : <b> ".$chardata->Value ."</b></li>";
  990. }
  991. echo "<li> Server : <b>".$_SERVER['SERVER_SOFTWARE']."</b></li>";
  992. _e("<li> Active Plugins : <b></li>", 'wordbooker');
  993. foreach($active_plugins as $name) {
  994. if ( $plug_info[$name]['Title']!='Wordbooker') {
  995. echo "&nbsp;&nbsp;&nbsp;".$plug_info[$name]['Title']." ( ".$plug_info[$name]['Version']." ) <br />";}
  996. }
  997. if (ADVANCED_DEBUG) { phpinfo(INFO_MODULES);}
  998. ?>
  999. </ul>
  1000. <?php
  1001. if ($version_errors) {
  1002. ?>
  1003. <div class="wordbooker_errorcolor">
  1004. <?php _e('Your system does not meet the', 'wordbooker'); ?> <a href="http://wordpress.org/about/requirements/"><?php _e('WordPress minimum requirements', 'wordbooker'); ?></a>. <?php _e('Things are unlikely to work.', 'wordbooker'); ?>
  1005. </div>
  1006. <?php
  1007. } else if ($mysqlvers == 'Unknown') {
  1008. ?>
  1009. <div>
  1010. <?php _e('Please ensure that your system meets the', 'wordbooker'); ?> <a href="http://wordpress.org/about/requirements/"><?php _e('WordPress minimum requirements', 'wordbooker'); ?></a>.
  1011. </div>
  1012. <?php
  1013. }
  1014. ?>
  1015. </div>
  1016. <?php
  1017. }
  1018. /******************************************************************************
  1019. * Facebook API wrappers.
  1020. */
  1021. /*
  1022. function wordbooker_fbclient_facebook_finish($wbuser, $result, $method,$error_code, $error_msg, $post_id,$result2, $error_code2, $error_msg2)
  1023. {
  1024. global $blog_id;
  1025. wordbooker_debugger("Publish complete"," ",$post_id,99) ;
  1026. if ($error_code) {
  1027. wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code, $error_msg, $post_id);
  1028. }
  1029. if ($error_code2) {
  1030. wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code2, $error_msg2, $post_id);
  1031. }
  1032. If ((! $error_code) && (! $error_code2))
  1033. {
  1034. wordbooker_clear_userdata_facebook_error($wbuser);
  1035. wordbooker_delete_from_process_queue($post_id,$blog_id);
  1036. }
  1037. return array($result,$result2);
  1038. }
  1039. */
  1040. function wordbooker_fbclient_publishaction($wbuser,$post_id)
  1041. {
  1042. global $wordbooker_post_options,$wpdb;
  1043. $wordbooker_settings =wordbooker_options();
  1044. $post = get_post($post_id);
  1045. $post_link_share = get_permalink($post_id);
  1046. $post_link=wordbooker_short_url($post_id);
  1047. $post_title=$post->post_title;
  1048. $post_content = $post->post_content;
  1049. # Grab the content of the post once its been filtered for display - this converts app tags into HTML so we can grab gallery images etc.
  1050. $processed_content ="!!! ".apply_filters('the_content', $post_content)." !!!";
  1051. $yturls = array();
  1052. $matches_tn=array();
  1053. # Get the Yapb image for the post
  1054. if (class_exists('YapbImage')) {
  1055. $siteUrl = get_option('siteurl');
  1056. if (substr($siteUrl, -1) != '/') $siteUrl .= '/';
  1057. $uri = substr($url, strpos($siteUrl, '/', strpos($url, '//')+2));
  1058. $WordbookerYapbImageclass = new YapbImage(null,$post->ID,$uri);
  1059. $WordbookerYapbImage=$WordbookerYapbImageclass->getInstanceFromDb($post_id);
  1060. if (strlen($WordbookerYapbImage->uri)>6) {$yturls[]=get_bloginfo('url').$WordbookerYapbImage->uri;}
  1061. }
  1062. if ( function_exists( 'get_the_post_thumbnail' ) ) {
  1063. wordbooker_debugger("Getting the thumnail image"," ",$post->ID) ;
  1064. preg_match_all('/<img \s+ ([^>]*\s+)? src \s* = \s* [\'"](.*?)[\'"]/ix',get_the_post_thumbnail($post_id), $matches_tn);
  1065. }
  1066. $meta_tag_scan=explode(',',$wordbooker_settings['wordbooker_meta_tag_scan']);
  1067. foreach($meta_tag_scan as $meta_tag) {
  1068. wordbooker_debugger("Getting image from custom meta : ",$meta_tag,$post->ID) ;
  1069. $matches_ct[]=get_post_meta($post->ID, $meta_tag, TRUE);
  1070. }
  1071. $matches=$matches_ct;
  1072. if ( function_exists( 'get_the_post_thumbnail' ) ) {
  1073. $matches=array_merge($matches_ct,$matches_tn[2]);
  1074. }
  1075. # If the user only wants the thumbnail then we can simply not do the skim over the processed images
  1076. if (! isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
  1077. wordbooker_debugger("Getting the rest of the images "," ",$post->ID) ;
  1078. preg_match_all('/<img \s+ ([^>]*\s+)? src \s* = \s* [\'"](.*?)[\'"]/ix',$processed_content, $matched);
  1079. $x=strip_shortcodes($post_content);
  1080. preg_match_all( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=|embed/)([\w-]+)(.*?)#i', $x, $matches3 );
  1081. if (is_array($matches3[3])) {
  1082. foreach ($matches3[3] as $key ) {
  1083. $yturls[]='http://img.youtube.com/vi/'.$key.'/0.jpg';
  1084. }
  1085. }
  1086. }
  1087. if ( function_exists( 'get_the_post_thumbnail' ) ) {
  1088. # If the thumb only is set then pulled images is just matches
  1089. if (!isset($wordbooker_settings["wordbooker_meta_tag_thumb"])) {
  1090. if (! isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
  1091. wordbooker_debugger("Setting image array to be both thumb and the post images "," ",$post->ID) ;
  1092. $pulled_images=@array_merge($matches[2],$matched[2],$yturls,$matches);
  1093. }
  1094. else {
  1095. wordbooker_debugger("Setting image array to be just thumb "," ",$post->ID) ;
  1096. $pulled_images[]=$matches[2];
  1097. }
  1098. }
  1099. }
  1100. if (isset($wordbooker_settings["wordbooker_meta_tag_thumb"]) && isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
  1101. wordbooker_debugger("Setting image array to be just thumb from meta. "," ",$post->ID) ;
  1102. $pulled_images[]=$matches_ct[2];}
  1103. else {
  1104. wordbooker_debugger("Setting image array to be post and thumb images. "," ",$post->ID) ;
  1105. if (is_array($matched[2])) {$pulled_images[]=array_merge($matches,$matched[2]);}
  1106. if (is_array($matched[2]) && is_array($yturls)) {$pulled_images=array_merge($matches,$matched[2],$yturls);}
  1107. }
  1108. $images = array();
  1109. if (is_array($pulled_images)) {
  1110. foreach ($pulled_images as $imgsrc) {
  1111. if ($imgsrc) {
  1112. if (stristr(substr($imgsrc, 0, 8), '://') ===false) {
  1113. /* Fully-qualify src URL if necessary. */
  1114. $scheme = $_SERVER['HTTPS'] ? 'https' : 'http';
  1115. $new_imgsrc = "$scheme://". $_SERVER['SERVER_NAME'];
  1116. if ($imgsrc[0] == '/') {
  1117. $new_imgsrc .= $imgsrc;
  1118. }
  1119. $imgsrc = $new_imgsrc;
  1120. }
  1121. $images[] = $imgsrc;
  1122. }
  1123. }
  1124. }
  1125. /* Pull out <wpg2> image tags. */
  1126. $wpg2_g2path = get_option('wpg2_g2paths');
  1127. if ($wpg2_g2path) {
  1128. $g2embeduri = $wpg2_g2path['g2_embeduri'];
  1129. if ($g2embeduri) {
  1130. preg_match_all('/<wpg2>(.*?)</ix', $processed_content,
  1131. $wpg_matches);
  1132. foreach ($wpg_matches[1] as $wpgtag) {
  1133. if ($wpgtag) {
  1134. $images[] = $g2embeduri.'?g2_view='.'core.DownloadItem'."&g2_itemId=$wpgtag";
  1135. }
  1136. }
  1137. }
  1138. }
  1139. $wordbooker_settings =wordbooker_options();
  1140. if (count($images)>0){
  1141. # Remove duplicates
  1142. $images=array_unique($images);
  1143. # Strip images from various plugins
  1144. $images=wordbooker_strip_images($images);
  1145. # And limit it to 5 pictures to keep Facebook happy.
  1146. $images = array_slice($images, 0, 5);
  1147. } else {
  1148. if (isset($wordbooker_settings['wordbooker_use_this_image'])) {
  1149. $images[]=$wordbooker_settings['wb_wordbooker_default_image'];
  1150. wordbooker_debugger("No Post images found so using open graph default to keep Facebook happy ",'',$post->ID) ;
  1151. }
  1152. else {
  1153. $x=get_bloginfo('wpurl').'/wp-content/plugins/wordbooker/includes/wordbooker_blank.jpg';
  1154. $images[]=$x;
  1155. wordbooker_debugger("No Post images found so loading blank to keep Facebook happy ",'',$post->ID) ;
  1156. }
  1157. }
  1158. #var_dump($images);
  1159. foreach ($images as $single) {
  1160. $images_array[]=array(
  1161. 'type' => 'image',
  1162. 'src' => $single,
  1163. 'href' => $post_link_share,
  1164. );
  1165. }
  1166. $images=$images_array;
  1167. #var_dump($images);
  1168. foreach ($images as $key){
  1169. wordbooker_debugger("Post Images : ".$key['src'],'',$post->ID) ;
  1170. }
  1171. // Set post_meta to be first image
  1172. update_post_meta($post->ID,'_wordbooker_thumb',$images[0]['src']);
  1173. wordbooker_debugger("Getting the Excerpt"," ",$post->ID) ;
  1174. unset ($processed_content);
  1175. if (isset($wordbooker_post_options["wordbooker_use_excerpt"]) && (strlen($post->post_excerpt)>3)) {
  1176. $post_content=$post->post_excerpt;
  1177. $post_content=wordbooker_translate($post_content);
  1178. }
  1179. else { $post_content=wordbooker_post_excerpt($post_content,$wordbooker_post_options['wordbooker_extract_length']);}
  1180. update_post_meta($post->ID,'_wordbooker_extract',$post_content);
  1181. # this is getting and setting the post attributes
  1182. $post_attribute=parse_wordbooker_attributes(stripslashes($wordbooker_post_options["wordbooker_attribute"]),$post_id,strtotime($post->post_date));
  1183. $post_data = array(
  1184. 'media' => $images,
  1185. 'post_link' => $post_link,
  1186. 'post_link_share' => $post_link_share,
  1187. 'post_title' => $post_title,
  1188. 'post_excerpt' => $post_content,
  1189. 'post_attribute' => $post_attribute,
  1190. # 'post_full_text' => $post->post_content,
  1191. 'post_id'=>$post->ID,
  1192. 'post_date'=>$post->post_date
  1193. );
  1194. # This is the tagging code -
  1195. #if (strlen($wordbooker_post_options['wordbooker_tag_list']) > 6 ) {
  1196. # $wordbooker_tag_list=str_replace('[','@[',$wordbooker_post_options['wordbooker_tag_list']);
  1197. # $message=$message. " (Tagged : ".$wordbooker_tag_list." ) ";
  1198. # }
  1199. if (function_exists('qtrans_use')) {
  1200. global $q_config;
  1201. $post_data['post_title']=qtrans_use($q_config['default_language'],$post_data['post_title']);
  1202. }
  1203. $post_id=$post->ID;
  1204. $wordbooker_fb_post = array(
  1205. 'name' => $post_data['post_title'],
  1206. 'link' => $post_data['post_link'],
  1207. 'message'=> $post_data['post_attribute'],
  1208. 'description' => $post_data['post_excerpt'],
  1209. 'picture'=>$images[0]['src']
  1210. # 'media' => json_encode($images)
  1211. );
  1212. wordbooker_debugger("Post Titled : ",$post_data['post_title'],$post_id,99) ;
  1213. wordbooker_debugger("Post URL : ",$post_data['post_link'],$post_id,99) ;
  1214. if ($wordbooker_post_options['wordbooker_actionlink']==100) {
  1215. // No action link
  1216. wordbooker_debugger("No action link being used","",$post_id,99) ;
  1217. }
  1218. if ($wordbooker_post_options['wordbooker_actionlink']==200) {
  1219. // Share This
  1220. wordbooker_debugger("Share Link being used"," ",$post_id,99) ;
  1221. $action_links = array('name' => __('Share', 'wordbooker'),'link' => 'http://www.facebook.com/share.php?u='.urlencode($post_data['post_link_share']));
  1222. $wordbooker_fb_post['actions']=json_encode($action_links);
  1223. }
  1224. if ($wordbooker_post_options['wordbooker_actionlink']==300) {
  1225. // Read Full
  1226. wordbooker_debugger("Read Full link being used"," ",$post_id,99) ;
  1227. $action_links = array('name' => __('Read entire article', 'wordbooker'),'link' => $post_data['post_link_share']);
  1228. $wordbooker_fb_post['actions'] =json_encode($action_links);
  1229. }
  1230. $posting_array[] = array('target_id'=>__("Primary", 'wordbooker'),
  1231. 'target'=>$wordbooker_post_options['wordbooker_primary_target'],
  1232. 'target_type'=>$wordbooker_post_options['wordbooker_primary_type'],
  1233. 'target_active'=>$wordbooker_post_options['wordbooker_primary_active']);
  1234. $posting_array[] = array('target_id'=>__("Secondary", 'wordbooker'),
  1235. 'target'=>$wordbooker_post_options['wordbooker_secondary_target'],
  1236. 'target_type'=>$wordbooker_post_options['wordbooker_secondary_type'],
  1237. 'target_active'=>$wordbooker_post_options['wordbooker_secondary_active']);;
  1238. $target_types = array('PW' => "",'FW' => __('Fan Wall', 'wordbooker'), 'GW'=>__('Group wall', 'wordbooker'));
  1239. $posting_type=array("1"=>"Wall Post","2"=>"Note","3"=>"Status Update");
  1240. foreach($posting_array as $posting_target) {
  1241. $access_token='dummy access token';
  1242. $wbuser->pages[]=array( 'id'=>'PW:'.$wbuser->facebook_id, 'name'=>"Personal Wall",'access_token'=>$wbuser->access_token);
  1243. if(is_array($wbuser->pages)){
  1244. foreach ($wbuser->pages as $pager) {
  1245. if ($pager['id']==$posting_target['target']) {
  1246. $target_name=$pager['name'];
  1247. $access_token=$pager['access_token'];
  1248. }
  1249. }
  1250. }
  1251. if (isset($posting_target['target_active'])) {
  1252. $target_type=substr($posting_target['target'],0,2);
  1253. wordbooker_debugger("Posting to ".$target_types[$target_type]." ".$target_name." (".$posting_target['target_id'].") as a ".$posting_type[$posting_target['target_type']],"",$post_id,99) ;
  1254. if ($access_token=='dummy access token') {$access_token=$wbuser->access_token;}
  1255. $target=substr($posting_target['target'],3);
  1256. $is_dummy=$wordbooker_settings['wordbooker_fake_publish'];
  1257. switch($posting_target['target_type']) {
  1258. # Wall Post
  1259. case 1 :
  1260. wordbooker_wall_post($post_id,$access_token,$post_title,$wordbooker_fb_post ,$target,$is_dummy,$target_name);
  1261. break;
  1262. # Note
  1263. case 2 :
  1264. wordbooker_notes_post($post_id,$access_token,$post_title,$target,$is_dummy,$target_name);
  1265. break;
  1266. # Status Update
  1267. case 3 :
  1268. wordbooker_status_update($post_id,$access_token,$post_data['post_date'],$target,$is_dummy,$target_name);
  1269. break ;
  1270. }
  1271. } else {wordbooker_debugger("Posting to ".$posting_target['target_id']." target (".$target_name.") not active","",$post_id,99) ; }
  1272. }
  1273. }
  1274. function wordbooker_strip_images($images)
  1275. {
  1276. $newimages = array();
  1277. $strip_array= array ('addthis.com','gravatar.com','zemanta.com','wp-includes','plugins','favicon.ico','facebook.com','themes','mu-plugins','fbcdn.net');
  1278. foreach($images as $single){
  1279. $ext = substr(strrchr($single, '.'), 1);
  1280. if (strlen($ext) >2){
  1281. foreach ($strip_array as $strip_domain) {
  1282. wordbooker_debugger("Looking for ".$strip_domain." in ".$single," ",$post->ID,200) ;
  1283. if (stripos($single,$strip_domain)) {wordbooker_debugger("Found a match so dump the image",$single,$post->ID,200) ;} else { if (!in_array($single,$newimages)){$newimages[]=$single;}}
  1284. }} else {wordbooker_debugger("Image URL ".$single." not valid ",$post->ID,200) ;}
  1285. }
  1286. return $newimages;
  1287. }
  1288. function wordbooker_get_language() {
  1289. global $q_config;
  1290. $wplang="en_US";
  1291. if (strlen(WPLANG) > 2) {$wplang=WPLANG;}
  1292. if (isset ($q_config["language"])) {
  1293. $x=get_option('qtranslate_locales');
  1294. $wplang=$x[$q_config["language"]];
  1295. }
  1296. if (strlen($wplang)< 5) {$wplang='en_US';}
  1297. if ($wplang=="WPLANG" ) {$wplang="en_US";}
  1298. return $wplang;
  1299. }
  1300. function wordbooker_short_url($post_id) {
  1301. # This provides short_url responses by checking for various functions and using
  1302. $wordbooker_settings =wordbooker_options();
  1303. if (isset($wordbooker_settings["wordbooker_disable_shorties"])) {
  1304. $url = get_permalink($post_id);
  1305. return $url;
  1306. }
  1307. $url = get_permalink($post_id);
  1308. $url2 = $url;
  1309. if (function_exists(fts_show_shorturl)) {
  1310. $post = get_post($post_id);
  1311. $url=fts_show_shorturl($post,$output = false);
  1312. }
  1313. if (function_exists(wp_ozh_yourls_geturl)) {
  1314. $url=wp_ozh_yourls_geturl($post_id);
  1315. }
  1316. if ("!!!".$url."XXXX"=="!!!XXXX") {$url = $url2;}
  1317. return $url;
  1318. }
  1319. function parse_wordbooker_attributes($attribute_text,$post_id,$timestamp) {
  1320. # Changes various "tags" into their WordPress equivalents.
  1321. $post = get_post($post_id);
  1322. $user_id=$post->post_author;
  1323. $title=$post->post_title;
  1324. $perma=get_permalink($post->ID);
  1325. $perma_short=wordbooker_short_url($post_id);
  1326. $user_info = get_userdata($user_id);
  1327. $blog_url= get_bloginfo('url');
  1328. $wp_url= get_bloginfo('wpurl');
  1329. $blog_name = get_bloginfo('name');
  1330. $author_nice=$user_info->display_name;
  1331. $author_nick=$user_info->nickname;
  1332. $author_first=$user_info->first_name;
  1333. $author_last=$user_info->last_name;
  1334. # Format date and time to the blogs preferences.
  1335. $date_info=date_i18n(get_option('date_format'),$timestamp);
  1336. $time_info=date_i18n(get_option('time_format'),$timestamp);
  1337. # Now do the replacements
  1338. $attribute_text=str_ireplace( '%author%',$author_nice,$attribute_text );
  1339. $attribute_text=str_ireplace( '%first%',$author_first,$attribute_text );
  1340. $attribute_text=str_ireplace( '%wpurl%',$wp_url,$attribute_text );
  1341. $attribute_text=str_ireplace( '%burl%',$blog_url,$attribute_text );
  1342. $attribute_text=str_ireplace( '%last%',$author_last,$attribute_text );
  1343. $attribute_text=str_ireplace( '%nick%',$author_nick,$attribute_text );
  1344. $attribute_text=str_ireplace( '%title%',$title,$attribute_text );
  1345. $attribute_text=str_ireplace( '%link%',$perma,$attribute_text );
  1346. $attribute_text=str_ireplace( '%slink%',$perma_short,$attribute_text );
  1347. $attribute_text=str_ireplace( '%date%', $date_info ,$attribute_text);
  1348. $attribute_text=str_ireplace( '%time%', $time_info,$attribute_text );
  1349. return $attribute_text;
  1350. }
  1351. function wordbooker_footer($blah)
  1352. {
  1353. if (is_404()) {
  1354. echo "\n<!-- Wordbooker code revision : ".WORDBOOKER_CODE_RELEASE." -->\n";
  1355. return;
  1356. }
  1357. $wplang=wordbooker_get_language();
  1358. $efb_script = <<< EOGS
  1359. <div id="fb-root"></div>
  1360. <script type="text/javascript">
  1361. window.fbAsyncInit = function() {
  1362. FB.init({
  1363. appId : '254577506873',
  1364. status : true, // check login status
  1365. cookie : true, // enable cookies to allow the server to access the session
  1366. xfbml : true, // parse XFBML
  1367. oauth:true
  1368. });
  1369. };
  1370. (function() {
  1371. var e = document.createElement('script');
  1372. EOGS;
  1373. $efb_script.= "e.src = document.location.protocol + '//connect.facebook.net/".$wplang."/all.js';";
  1374. $efb_script.= <<< EOGS
  1375. e.async = true;
  1376. document.getElementById('fb-root').appendChild(e);
  1377. }());
  1378. </script>
  1379. EOGS;
  1380. $wordbooker_settings = wordbooker_options();
  1381. if (isset($wordbooker_settings['wordbooker_like_button_show']) || isset($wordbooker_settings['wordbooker_like_share_too']))
  1382. {
  1383. echo $efb_script;
  1384. if ( isset($wordbooker_settings['wordbooker_iframe'])) {
  1385. echo '<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>';
  1386. }
  1387. }
  1388. # echo '\n<script type="text/javascript " defer="defer" > setTimeout("wordbooker_read()",3000); </script> \n';
  1389. echo "\n<!-- Wordbooker code revision : ".WORDBOOKER_CODE_RELEASE." -->\n";
  1390. return $blah;
  1391. }
  1392. function wordbooker_og_tags(){
  1393. if (is_404()) {return;}
  1394. global $post;
  1395. # Stops the code firing on non published posts
  1396. if ('publish' != get_post_status($post->ID)) {return;}
  1397. $bname=get_bloginfo('name');
  1398. $bdesc=get_bloginfo('description');
  1399. $wordbooker_settings = wordbooker_options();
  1400. # Always put out the tags because even if they are not using like/share it gives Facebook stuff to work with.
  1401. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1402. $wpuserid=$post->post_author;
  1403. if (is_array($wordbooker_post_options)){
  1404. if ($wordbooker_post_options["wordbooker_default_author"] > 0 ) {$wpuserid=$wordbooker_post_options["wordbooker_default_author"];}
  1405. }
  1406. $blog_name=get_bloginfo('name');
  1407. echo '<meta property="og:site_name" content="'.$bname.' - '.$bdesc.'"/> ';
  1408. if (strlen($wordbooker_settings["fb_comment_app_id"])<6) {
  1409. if ($wordbooker_settings['wordbooker_fb_comments_admin']) {
  1410. $xxx=wordbooker_get_cache(-99,facebook_id,1);
  1411. #var_dump($wordbooker_settings['wb_wordbooker_default_image']);
  1412. if (!is_null($xxx)) {
  1413. echo '<meta property="fb:admins" content="'.$xxx.'"/> ';
  1414. }
  1415. } else {
  1416. $xxx=wordbooker_get_cache( $wpuserid,facebook_id,1);
  1417. if (!is_null($xxx->facebook_id)) {
  1418. echo '<meta property="fb:admins" content="'.$xxx->facebook_id.'"/> ';
  1419. }
  1420. }
  1421. }
  1422. if (strlen($wordbooker_settings["fb_comment_app_id"])>6) {
  1423. echo '<meta property = "fb:app_id" content = "'.$wordbooker_settings["fb_comment_app_id"].'" /> ';
  1424. }
  1425. if (defined('WORDBOOKER_PREMIUM')) {
  1426. echo '<meta property = "fb:app_id" content = "'.WORDBOOKER_FB_ID.'" /> ';
  1427. }
  1428. if ( (is_single() || is_page()) && !is_front_page() && !is_category() && !is_home() ) {
  1429. $post_link = get_permalink($post->ID);
  1430. $post_title=$post->post_title;
  1431. echo '<meta property="og:title" content="'.htmlspecialchars(strip_tags($post_title),ENT_QUOTES).'"/> ';
  1432. echo '<meta property="og:url" content="'.$post_link.'"/> ';
  1433. echo '<meta property="og:type" content="article"/> ';
  1434. $ogimage=get_post_meta($post->ID, '_wordbooker_thumb', TRUE);
  1435. if (strlen($ogimage)<4 && strlen($wordbooker_settings['wb_wordbooker_default_image'])>4) {
  1436. $ogimage=$wordbooker_settings['wb_wordbooker_default_image'];
  1437. }
  1438. if (strlen($ogimage)>4) {
  1439. echo '<meta property="og:image" content="'.$ogimage.'"/> ';
  1440. }
  1441. }
  1442. else
  1443. { # Not a single post so we only need the og:type tag
  1444. echo '<meta property="og:type" content="blog"/> ';
  1445. }
  1446. #wordbooker_get_option('wordbooker_description_meta_length')
  1447. if ($meta_length = wordbooker_get_option('wordbooker_description_meta_length')) {
  1448. if (is_single() || is_page()) {
  1449. $excerpt=get_post_meta($post->ID, '_wordbooker_extract', TRUE);
  1450. #var_dump($excerpt);
  1451. if(strlen($excerpt) < 5 ) {
  1452. $excerpt=wordbooker_post_excerpt($post->post_content,$wordbooker_settings['wordbooker_extract_length']);
  1453. update_post_meta($post->ID, '_wordbooker_extract', $excerpt);
  1454. # var_dump($excerpt);
  1455. }
  1456. # If we've got an excerpt use that instead
  1457. if ((strlen($post->post_excerpt)>3) && (strlen($excerpt) <=5)) {
  1458. $excerpt=$post->post_excerpt;
  1459. $description = str_replace('"','&quot;',$post->post_content);
  1460. $excerpt = wordbooker_post_excerpt($description,$meta_length);
  1461. $excerpt = preg_replace('/(\r|\n)+/',' ',$excerpt);
  1462. $excerpt = preg_replace('/\s\s+/',' ',$excerpt);
  1463. update_post_meta($post->ID, '_wordbooker_extract', $excerpt);
  1464. }
  1465. # Now if we've got something put the meta tag out.
  1466. if (isset($excerpt)){
  1467. $meta_string = sprintf("<meta name=\"description\" content=\"%s\"/> ", htmlspecialchars($excerpt,ENT_QUOTES));
  1468. echo $meta_string;
  1469. }
  1470. }
  1471. else
  1472. {
  1473. $meta_string = sprintf("<meta name=\"description\" content=\"%s\"/> ", get_bloginfo('description'));
  1474. echo $meta_string;
  1475. }
  1476. }
  1477. }
  1478. function wordbooker_header($blah){
  1479. if (is_404()) {return;}
  1480. global $post;
  1481. # Stops the code firing on non published posts
  1482. if ('publish' != get_post_status($post->ID)) {return;}
  1483. $wordbooker_settings = wordbooker_options();
  1484. # Now we just call the wordbooker_og_tags function.
  1485. if (!isset ( $wordbooker_settings['wordbooker_fb_disable_og'])) {
  1486. wordbooker_og_tags();
  1487. }
  1488. /* if (is_single() && isset($wordbooker_settings['wordbooker_read_button']) ) {
  1489. $read_codes=" <script type=\"text/javascript\">
  1490. function wordbooker_read()
  1491. {
  1492. FB.api('/me/".OPENGRAPH_NAMESPACE.":read' +
  1493. '?article=";
  1494. $read_codes.=get_permalink($post->ID);
  1495. $read_codes.="&access_token=".OPENGRAPH_ACCESS_TOKEN."','post',";
  1496. $read_codes.=<<<READCODE4
  1497. function(response) {
  1498. var msg = 'Error occured';
  1499. if (!response || response.error) {
  1500. if (response.error) {
  1501. msg += " Type: " + response.error.type+" Message: " + response.error.message;
  1502. }
  1503. alert(msg);
  1504. }
  1505. else {
  1506. //alert('Post was successful! Action ID: ' + response.id);
  1507. }
  1508. });
  1509. }
  1510. </script>
  1511. READCODE4;
  1512. echo $read_codes;
  1513. }
  1514. */
  1515. return $blah;
  1516. }
  1517. function display_wordbooker_fb_comment() {
  1518. global $post;
  1519. if(!is_single()){return;}
  1520. $wordbooker_settings = wordbooker_options();
  1521. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1522. #var_dump($wordbooker_settings['wordbooker_comment_handling']);
  1523. # var_dump($wordbooker_post_options['wordbooker_use_facebook_comments']);
  1524. if ($wordbooker_settings['wordbooker_comment_handling']=="2" && isset($wordbooker_post_options['wordbooker_use_facebook_comments'])) {
  1525. $post_link = get_permalink($post->ID);
  1526. $checked_flag=array('on'=>'true','off'=>'false');
  1527. $comment_code= '<fb:comments href="'.$post_link.'" num_posts="'.$wordbooker_settings['fb_comment_box_count'].'" width="'.$wordbooker_settings['fb_comment_box_size'].'" notify="'.$checked_flag[$wordbooker_settings['fb_comment_box_notify']].' colorscheme="'.$wordbooker_settings['wb_comment_colorscheme'].'" ></fb:comments>';
  1528. echo $comment_code;
  1529. }
  1530. }
  1531. function wordbooker_fb_comment_inline() {
  1532. global $post;
  1533. if(!is_single()){return;}
  1534. $wordbooker_settings = wordbooker_options();
  1535. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1536. if ($wordbooker_settings['wordbooker_comment_handling']=="2" && isset($wordbooker_post_options['wordbooker_use_facebook_comments'])) {
  1537. $post_link = get_permalink($post->ID);
  1538. $checked_flag=array('on'=>'true','off'=>'false');
  1539. $comment_code= '<fb:comments href="'.$post_link.'" num_posts="'.$wordbooker_settings['fb_comment_box_count'].'" width="'.$wordbooker_settings['fb_comment_box_size'].'" notify="'.$checked_flag[$wordbooker_settings['fb_comment_box_notify']].' colorscheme="'.$wordbooker_settings['wb_comment_colorscheme'].'" ></fb:comments>';
  1540. return $comment_code;
  1541. }
  1542. }
  1543. function display_wordbooker_fb_share() {
  1544. global $post;
  1545. $wordbooker_settings = wordbooker_options();
  1546. $do_share=0;
  1547. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1548. #var_dump($$wordbooker_settings[);
  1549. if ($wordbooker_post_options['wordbooker_share_button_post']==2 && !is_page()) {return ;}
  1550. if ($wordbooker_post_options['wordbooker_share_button_page']==2 && is_page()) {return ;}
  1551. if (!isset($wordbooker_settings['wordbooker_like_share_too'])) {return ;}
  1552. if (isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() ) {$do_share=1;}
  1553. if (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() ) {$do_share=1;}
  1554. if (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() ) {$do_share=1;}
  1555. if (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ) {$do_share=1;}
  1556. if (isset($wordbooker_settings['wordbooker_no_share_stick']) && is_sticky() ) {$do_share=0; }
  1557. if ( $do_share==1 &&
  1558. ((isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() )
  1559. || (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() )
  1560. || (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() )
  1561. || (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ))
  1562. )
  1563. {
  1564. $post_link = get_permalink($post->ID);
  1565. $btype="button";
  1566. if (is_single() || is_page()) {
  1567. $btype="button_count";
  1568. }
  1569. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1570. $share_code='<!-- Wordbooker created FB tags --> <a name="fb_share" type="'.$btype.'" share_url="'.$post_link.'"></a>';
  1571. }
  1572. else {
  1573. $share_code='<!-- Wordbooker created FB tags --> <fb:share-button class="meta" type="'.$btype.'" href="'.$post_link.'" > </fb:share-button>';
  1574. }
  1575. echo $share_code;
  1576. }
  1577. }
  1578. function wordbooker_fb_share_inline() {
  1579. global $post;
  1580. $wordbooker_settings = wordbooker_options();
  1581. $do_share=0;
  1582. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1583. #var_dump($$wordbooker_settings[);
  1584. if ($wordbooker_post_options['wordbooker_share_button_post']==2 && !is_page()) {return ;}
  1585. if ($wordbooker_post_options['wordbooker_share_button_page']==2 && is_page()) {return ;}
  1586. if (!isset($wordbooker_settings['wordbooker_like_share_too'])) {return ;}
  1587. if (isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() && !is_front_page() ) {$do_share=1;}
  1588. if (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() && !is_front_page() ) {$do_share=1;}
  1589. if (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() ) {$do_share=1;}
  1590. if (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ) {$do_share=1;}
  1591. if (isset($wordbooker_settings['wordbooker_no_share_stick']) && is_sticky() ) {$do_share=0; }
  1592. if ( $do_share==1 &&
  1593. ((isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() )
  1594. || (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() )
  1595. || (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() )
  1596. || (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ))
  1597. )
  1598. {
  1599. $post_link = get_permalink($post->ID);
  1600. $btype="button";
  1601. if (is_single() || is_page()) {
  1602. $btype="button_count";
  1603. }
  1604. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1605. $share_code='<!-- Wordbooker created FB tags --> <a name="fb_share" type="'.$btype.'" share_url="'.$post_link.'"></a>';
  1606. }
  1607. else {
  1608. $share_code='<!-- Wordbooker created FB tags --> <fb:share-button class="meta" type="'.$btype.'" href="'.$post_link.'" > </fb:share-button>';
  1609. }
  1610. return $share_code;
  1611. }
  1612. }
  1613. function display_wordbooker_fb_send() {
  1614. global $post,$q_config;
  1615. $wordbooker_settings = wordbooker_options();
  1616. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1617. $post_link = get_permalink($post->ID);
  1618. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1619. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1620. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true') {return;}
  1621. $do_like=0;
  1622. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1623. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1624. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1625. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1626. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1627. if ( $do_like==1 &&
  1628. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1629. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1630. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1631. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1632. )
  1633. {
  1634. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1635. $px=35;
  1636. $wplang=wordbooker_get_language();
  1637. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=80;}
  1638. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/send.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1639. }
  1640. else {
  1641. #var_dump($wordbooker_settings);
  1642. $like_code='<!-- Wordbooker created FB tags --> <fb:send layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].' "></fb:send> ';}
  1643. echo $like_code;
  1644. }
  1645. }
  1646. function wordbooker_fb_send_inline() {
  1647. global $post;
  1648. $wordbooker_settings = wordbooker_options();
  1649. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1650. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1651. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1652. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true') {return;}
  1653. $post_link = get_permalink($post->ID);
  1654. $do_like=0;
  1655. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1656. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1657. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1658. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1659. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1660. if ( $do_like==1 &&
  1661. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1662. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1663. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1664. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1665. )
  1666. {
  1667. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1668. $px=35;
  1669. $wplang=wordbooker_get_language();
  1670. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=80;}
  1671. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/send.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1672. }
  1673. else {
  1674. #var_dump($wordbooker_settings);
  1675. $like_code='<!-- Wordbooker created FB tags --> <fb:send layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].' "></fb:send> ';}
  1676. return $like_code;
  1677. }
  1678. }
  1679. function display_wordbooker_fb_like() {
  1680. global $post;
  1681. $wordbooker_settings = wordbooker_options();
  1682. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1683. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1684. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1685. if (!isset($wordbooker_settings['wordbooker_like_button_show'])) {return;}
  1686. $do_like=0;
  1687. $post_link = get_permalink($post->ID);
  1688. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1689. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1690. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1691. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1692. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1693. if ( $do_like==1 &&
  1694. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1695. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1696. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1697. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1698. )
  1699. {
  1700. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1701. $px=35;
  1702. $wplang=wordbooker_get_language();
  1703. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=95;}
  1704. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/like.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1705. }
  1706. else {
  1707. #var_dump($wordbooker_settings);
  1708. $like_code='<!-- Wordbooker created FB tags --> <fb:like layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].'" ';
  1709. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true' ) { $like_code.=' send="'.$wordbooker_settings['wordbooker_fblike_send'].'" ';}
  1710. $like_code.='></fb:like> ';}
  1711. echo $like_code;
  1712. }
  1713. }
  1714. function wordbooker_fb_like_inline() {
  1715. global $post;
  1716. $wordbooker_settings = wordbooker_options();
  1717. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1718. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1719. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1720. if (!isset($wordbooker_settings['wordbooker_like_button_show'])) {return;}
  1721. $do_like=0;
  1722. $post_link = get_permalink($post->ID);
  1723. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1724. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1725. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1726. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1727. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1728. if ( $do_like==1 &&
  1729. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1730. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1731. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1732. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1733. )
  1734. {
  1735. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1736. $px=35;
  1737. $wplang="en_US";
  1738. if (strlen(WPLANG) > 2) {$wplang=WPLANG;}
  1739. # then we check if WPLANG is actually set to anything sensible.
  1740. if ($wplang=="WPLANG" ) {$wplang="en_US";}
  1741. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=95;}
  1742. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/like.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1743. }
  1744. else {
  1745. #var_dump($wordbooker_settings);
  1746. $like_code='<!-- Wordbooker created FB tags --> <fb:like layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].'" ';
  1747. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true' ) { $like_code.=' send="'.$wordbooker_settings['wordbooker_fblike_send'].'" ';}
  1748. $like_code.='> </fb:like> ';}
  1749. return $like_code;
  1750. }
  1751. }
  1752. function wordbooker_fb_read_inline() {
  1753. $wordbooker_settings = wordbooker_options();
  1754. if (is_single() && isset($wordbooker_settings['wordbooker_read_button']) ) {
  1755. $read_code='<form><input type="button" value="'.__("Post To Your Timeline ",'wordbooker').'" onclick="wordbooker_read()" /></form>';
  1756. return $read_code;
  1757. }
  1758. }
  1759. function wordbooker_fb_read() {
  1760. $wordbooker_settings = wordbooker_options();
  1761. if (is_single() && isset($wordbooker_settings['wordbooker_read_button']) ) {
  1762. $read_code='<form><input type="button" value="'.__("Post To Your Timeline ",'wordbooker').'" onclick="wordbooker_read()" /></form>';
  1763. echo $read_code;
  1764. }
  1765. }
  1766. #function wordbooker_fb_comment_insert($template){
  1767. # $comment_code=wordbooker_fb_comment(true);
  1768. # if ($template) {echo $comment_code;} else {return $comment_code;}
  1769. #}
  1770. function wordbooker_append_post($post_cont) {
  1771. global $post;
  1772. $do_share=0;
  1773. #var_dump(is_page());var_dump(is_category());var_dump(is_front_page());var_dump(is_single());
  1774. $wordbooker_settings = wordbooker_options();
  1775. if (!isset($wordbooker_settings['wordbooker_like_button_show']) && !isset($wordbooker_settings['wordbooker_like_share_too'])) {return $post_cont;}
  1776. $post_cont2=$post_cont;
  1777. $post_link = get_permalink($post->ID);
  1778. $share_code=wordbooker_fb_share_inline();
  1779. $like_code=wordbooker_fb_like_inline();
  1780. $send_code=wordbooker_fb_send_inline();
  1781. $comment_code=wordbooker_fb_comment_inline();
  1782. $read_code=wordbooker_fb_read_inline();
  1783. if ($wordbooker_settings['wordbooker_fblike_location']!=$wordbooker_settings['wordbooker_fbshare_location']){
  1784. if ($wordbooker_settings['wordbooker_fbshare_location']=='top'){
  1785. $post_cont2= "<div class='wp_fbs_top'>".$share_code."</div>".$post_cont2;
  1786. }
  1787. if ($wordbooker_settings['wordbooker_fbshare_location']=='bottom') {
  1788. $post_cont2=$post_cont2."<div class='wp_fbs_bottom'>".$share_code.'</div>';
  1789. }
  1790. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true'){
  1791. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1792. $post_cont2= $post_cont2."<div class='wp_fbl_bottom'>".$like_code.'</div>';
  1793. }
  1794. if ($wordbooker_settings['wordbooker_fblike_location']=='top') {
  1795. $post_cont2= "<div class='wp_fbl_top'>".$like_code.'</div>'.$post_cont2;
  1796. }
  1797. }
  1798. } else {
  1799. # if ($wordbooker_settings['wordbooker_fblike_location']==$wordbooker_settings['wordbooker_fbshare_location']){
  1800. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1801. $post_cont2=$post_cont2."<div class='wb_fb_bottom'>".$like_code.'<div style="float:right;">'.$share_code.'</div></div>';
  1802. }
  1803. if ($wordbooker_settings['wordbooker_fblike_location']=='top'){
  1804. $post_cont2= "<div class='wb_fb_top'>".$like_code.'<div style="float:right;">'.$share_code.'</div></div>'.$post_cont2;
  1805. }
  1806. #}
  1807. #}
  1808. }
  1809. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='false' && $wordbooker_settings['wordbooker_fblike_send']=='true' ){
  1810. if ($wordbooker_settings['wordbooker_fblike_location']==$wordbooker_settings['wordbooker_fbshare_location']){
  1811. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1812. $post_cont2=$post_cont2."<div class='wb_fb_bottom'>".$send_code.'<div style="float:right;">'.$share_code.'</div></div>';
  1813. }
  1814. if ($wordbooker_settings['wordbooker_fblike_location']=='top'){
  1815. $post_cont2= "<div class='wb_fb_top'>".$send_code.'<div style="float:right;">'.$share_code.'</div></div>'.$post_cont;
  1816. }
  1817. } else {
  1818. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1819. $post_cont2= $post_cont2."<div class='wp_fbl_bottom'>".$send_code.'</div>';
  1820. }
  1821. if ($wordbooker_settings['wordbooker_fblike_location']=='top') {
  1822. $post_cont2= "<div class='wp_fbl_top'>".$send_code.'</div>'.$post_cont2;
  1823. }
  1824. }
  1825. }
  1826. /*
  1827. if ($wordbooker_settings['wordbooker_fbread_location']=='top'){
  1828. $post_cont2= "<div class='wp_fbr_top'>".$read_code."</div>".$post_cont2;
  1829. }
  1830. if ($wordbooker_settings['wordbooker_fbread_location']=='bottom') {
  1831. $post_cont2=$post_cont2."<div class='wp_fbr_bottom'>".$read_code.'</div>';
  1832. }
  1833. */
  1834. if ($wordbooker_settings['wordbooker_comment_location']=='bottom') { $post_cont2=$post_cont2."<div class='wb_fb_comment'><br/>".$comment_code."</div>"; }
  1835. return $post_cont2;
  1836. }
  1837. function wordbooker_get_cache($user_id,$field=null,$table=0) {
  1838. global $wpdb,$blog_id;
  1839. #$blog_id=1;
  1840. if (!isset($user_id)) {return;}
  1841. $tname=WORDBOOKER_USERSTATUS;
  1842. $query_fields='facebook_id,name,url,pic,status,updated,facebook_id';
  1843. $blog_lim=' and blog_id='.$blog_id;
  1844. if ($table==1) {$tname=WORDBOOKER_USERDATA;$query_fields='facebook_id,name,url,pic,status,updated,auths_needed,use_facebook';$blog_lim='';}
  1845. if (isset($field)) {$query_fields=$field;}
  1846. if ($user_id==-99){
  1847. $query="select ".$query_fields." from ".$tname." where blog_id = ".$blog_id;
  1848. # var_dump($query);
  1849. $result = $wpdb->get_results($query,ARRAY_N );
  1850. foreach($result as $key){ $newkey[]=$key[0];}
  1851. $result = implode(",",$newkey);
  1852. }
  1853. else {
  1854. $query="select ".$query_fields." from ".$tname." where user_ID=".$user_id.$blog_lim;
  1855. # var_dump($query);
  1856. $result = $wpdb->get_row($query); }
  1857. return $result;
  1858. }
  1859. function wordbooker_check_permissions($wbuser,$user) {
  1860. global $user_ID;
  1861. $perm_miss=wordbooker_get_cache($user_ID,'auths_needed',1);
  1862. if ($perm_miss->auths_needed==0) { return;}
  1863. $perms_to_check= array(WORDBOOKER_FB_PUBLISH_STREAM,WORDBOOKER_FB_STATUS_UPDATE,WORDBOOKER_FB_READ_STREAM,WORDBOOKER_FB_CREATE_NOTE,WORDBOOKER_FB_PHOTO_UPLOAD,WORDBOOKER_FB_VIDEO_UPLOAD,WORDBOOKER_FB_MANAGE_PAGES,WORDBOOKER_FB_READ_FRIENDS);
  1864. $perm_messages= array( __('Publish content to your Wall/Fan pages', 'wordbooker'), __('Update your status', 'wordbooker'), __('Read your News Feed and Wall', 'wordbooker'),__('Create notes', 'wordbooker'),__('Upload photos', 'wordbooker'),__('Upload videos', 'wordbooker'),__('Manage_pages', 'wordbooker'),__('Read friend lists', 'wordbooker'));
  1865. $preamble= __("but requires authorization to ", 'wordbooker');
  1866. $postamble= __(" on Facebook. Click on the following link to grant permission", 'wordbooker');
  1867. $loginUrl2='https://www.facebook.com/dialog/oauth?client_id='.WORDBOOKER_FB_ID.'&redirect_uri=https://wordbooker.tty.org.uk/index2.html?br='.urlencode(get_bloginfo('wpurl')).'&scope='.implode(',',$perms_to_check).'&response_type=token';
  1868. if(is_array($perms_to_check)) {
  1869. foreach(array_keys($perms_to_check) as $key){
  1870. # Bit map check to put out the right text for the missing permissions.
  1871. if (pow(2,$key) & $perm_miss->auths_needed ) {
  1872. $midamble.=$perm_messages[$key].", ";
  1873. }
  1874. }
  1875. $midamble=rtrim($midamble,",");
  1876. $midamble=trim(preg_replace("/(.*?)((,|\s)*)$/m", "$1", $midamble));
  1877. $midamble=substr_replace($midamble, " and ", strrpos($midamble, ","), strlen(","));
  1878. echo " ".$preamble.$midamble.$postamble.'</p><div style="text-align: center;"><a href="'.$loginUrl2.'" > <img src="http://static.ak.facebook.com/images/devsite/facebook_login.gif" alt="Facebook Login Button" /></a><br /></div>';
  1879. }
  1880. echo "and then save your settings<br />";
  1881. echo '<form action="'.WORDBOOKER_SETTINGS_URL.'" method="post"> <input type="hidden" name="action" value="" />';
  1882. echo '<p style="text-align: center;"><input type="submit" name="perm_save" class="button-primary" value="'. __('Save Configuration', 'wordbooker').'" /></p></form>';
  1883. }
  1884. function wordbooker_contributed($url=0) {
  1885. global $user_ID;
  1886. if ($url==0){
  1887. $contributors=array('1595132200','100000818019269','39203171','666800299','500073624','711830142','503549492','100000589976474','254577506873','1567300610','701738627','100000442094620','754015348','29404010','748636937',
  1888. '676888540','768354692','1607820784','1709067850','769804853','100001597808077','1162591229','736138968','532656880','1000013707847','1352285955','836328641',
  1889. '23010694256','129976890383044','679511648','100001305747796','138561766210548','535106029','202891313077099','567894174','10150158518404391','689075829','214145618608444',
  1890. '23087261000','195010903860640'
  1891. );
  1892. $facebook_id=wordbooker_get_cache($user_ID,'facebook_id');
  1893. return in_array($facebook_id->facebook_id,$contributors);
  1894. }
  1895. if ($url==1){
  1896. $blogs=array(
  1897. "Steve's Blog"=>'blogs.canalplan.org.uk/steve',"Powered by Dan!"=>'dangarion.com',"Kathryn's Comments"=>'www.kathrynhuxtable.org/blog',"Luke Writes"=>'www.lukewrites.com',
  1898. "It's Nature"=>'www.itsnature.org',"Eat in OC"=>'eatinoc.com',"Christian Albert Muller"=>'christian-albert-mueller.com/blog/',"[overcrooked|de]"=>'blog.overcrooked.de/',
  1899. "Jesus is My Buddy"=>'www.jesusismybuddy.com',"Shirts of Bamboo"=>'www.shirtsofbamboo.com', "What's that bug?"=>'www.whatsthatbug.com',"Philip Bussman"=>'www.philipbussmann.com',
  1900. "PhantaNews"=>'phantanews.de/wp/', "HKMacs"=>'hkmacs.com/Blog', "Techerator"=>'www.techerator.com', "Mosalar.com"=>'www.mosalar.com/',
  1901. "Nono & His Self-Centered Universe"=>'www.noelacosta.com/',"Chart Porn"=>'www.chartporn.org',"Pawesome"=>'www.pawesome.net',"Margaret & Ian's Website"=>'www.margaretandian.com/',
  1902. "The GBMINI website"=>'www.gbmini.net',"Roca"=>'rocamusic.ca/home',"Drew Rozell"=>'www.drewrozell.com/',"Kartext"=>'www.nitsche.org/',
  1903. "Doug Berch - Musician and Appalachian Mountain Dulcimer Maker"=>'dougberch.com',"My Lifestyle Blog"=>'www.mylifestyleblog.de',
  1904. "tina rawatta photography" => 'www.tinarawatta.com',"Gary Said..."=>'GarySaid.com',"Bachateros Online Magazine"=>'www.bachateros.com.au/',"Linh's e-place"=>'www.linh.se',
  1905. "InkMusings" => 'www.inkmusings.com',"JĂźrgen Koller's website"=>'www.kollermedia.at',"Walk With Ben"=>'www.walkwithben.com',"GardenFork"=>'www.http://www.gardenfork.tv/',
  1906. "A Low Man's Lyric"=>'vivekiyer.net/',"OutofRange.net"=>'www.outofrange.net/',"This Ambitious Orchestra"=>'ambitiousorchestra.com',"Lydia Salnikova"=>'www.lydiasalnikova.com/',
  1907. "Westpark Gamers"=>'www.westpark-gamers.de/', "The Camera Zealot"=>'www.camerazealot.com', " Best Raw Organic" => 'BestRawOrganic.com',"Gibson Designs"=>'gibsondesigns.net',
  1908. "Looking out from Under"=>'www.lookingoutfromunder.com',"Our Excellent Adventures"=>'www.ourexcellentadventures.com',
  1909. "wisiwi.com - Das Magazin fĂźr Unternehmer"=>'www.wisiwi.com/',"Just One Cookbook"=>'justonecookbook.com/blog/',"Surfdog 2011"=>'hastenteufel.name/blog',
  1910. "Vice Versa Advertising Photography"=>'www.viceversa.gr/',"Swimming Pools Designs"=>'www.swimming-pools-designs.com',"Eastleigh District Scouts"=>'www.eastleigh-scouts.org.uk',"Sparkpr"=>'www.sparkpr.com',"Charlie Glickman - Adult Sexuality Education"=>'www.charlieglickman.com/',"iEatAtTheBar"=>'www.ieatatthebar.com/',"Devil's Cove | Boats, Booze & Fun on Lake Travis"=>'http://www.devilscove.com/',"Bored. Cure your boredom!"=>'bored.overnow.com/',"KinkyThought"=>'kinkythought.com/',
  1911. "The Chronicles of Mommia"=>'www.thechroniclesofmommia.com/',"Total Humour"=>'www.totalhumour.com/',"Six Seconds"=>'www.6seconds.org/',"The APBA Blog"=>'www.apbablog.com',"The Doc is In"=>'www.thedocisin.net'
  1912. );
  1913. $keys = array_keys($blogs);
  1914. shuffle($keys);
  1915. foreach ( $keys as $key) {
  1916. echo "<a href='http://".htmlspecialchars($blogs[$key])."' target='_new'>".htmlspecialchars($key)."</a>,&nbsp;";
  1917. }
  1918. # And then put canalplan on the end of it - saves us having to do clever things to remove commas
  1919. echo "<a href='http://www.canalplan.org.uk/' target='_new' >CanalPlan AC</a><br />";
  1920. }
  1921. }
  1922. /******************************************************************************
  1923. * WordPress hooks: update Facebook when a blog entry gets published.
  1924. */
  1925. function wordbooker_remove_HTML($s , $keep = '' , $expand = 'script|style|noframes|select|option'){
  1926. /**///prep the string
  1927. $s = ' ' . $s;
  1928. /**///initialize keep tag logic
  1929. if(strlen($keep) > 0){
  1930. $k = explode('|',$keep);
  1931. for($i=0;$i<count($k);$i++){
  1932. $s = str_replace('<' . $k[$i],'[{(' . $k[$i],$s);
  1933. $s = str_replace('</' . $k[$i],'[{(/' . $k[$i],$s);
  1934. }
  1935. }
  1936. //begin removal
  1937. /**///remove comment blocks
  1938. while(stripos($s,'<!--') > 0){
  1939. $pos[1] = stripos($s,'<!--');
  1940. $pos[2] = stripos($s,'-->', $pos[1]);
  1941. $len[1] = $pos[2] - $pos[1] + 3;
  1942. $x = substr($s,$pos[1],$len[1]);
  1943. $s = str_replace($x,'',$s);
  1944. }
  1945. /**///remove tags with content between them
  1946. if(strlen($expand) > 0){
  1947. $e = explode('|',$expand);
  1948. for($i=0;$i<count($e);$i++){
  1949. while(stripos($s,'<' . $e[$i]) > 0){
  1950. $len[1] = strlen('<' . $e[$i]);
  1951. $pos[1] = stripos($s,'<' . $e[$i]);
  1952. $pos[2] = stripos($s,$e[$i] . '>', $pos[1] + $len[1]);
  1953. $len[2] = $pos[2] - $pos[1] + $len[1];
  1954. $x = substr($s,$pos[1],$len[2]);
  1955. $s = str_replace($x,'',$s);
  1956. }
  1957. }
  1958. }
  1959. /**///remove remaining tags
  1960. while(stripos($s,'<') > 0){
  1961. $pos[1] = stripos($s,'<');
  1962. $pos[2] = stripos($s,'>', $pos[1]);
  1963. $len[1] = $pos[2] - $pos[1] + 1;
  1964. $x = substr($s,$pos[1],$len[1]);
  1965. $s = str_replace($x,'',$s);
  1966. }
  1967. /**///finalize keep tag
  1968. for($i=0;$i<count($k);$i++){
  1969. $s = str_replace('[{(' . $k[$i],'<' . $k[$i],$s);
  1970. $s = str_replace('[{(/' . $k[$i],'</' . $k[$i],$s);
  1971. }
  1972. return trim($s);
  1973. }
  1974. function wordbooker_post_excerpt($excerpt, $maxlength,$doyoutube=1) {
  1975. if (function_exists('strip_shortcodes')) {
  1976. $excerpt = strip_shortcodes($excerpt);
  1977. }
  1978. global $wordbooker_post_options;
  1979. if (!isset($maxlength)) {$maxlength=$wordbooker_post_options['wordbooker_extract_length'];}
  1980. if (!isset($maxlength)) {$maxlength=256;}
  1981. $excerpt = trim($excerpt);
  1982. # Now lets strip any tags which dont have balanced ends
  1983. # Need to put NGgallery tags in there - there are a lot of them and they are all different.
  1984. $open_tags="[simage,[[CP,[gallery,[imagebrowser,[slideshow,[tags,[albumtags,[singlepic,[album";
  1985. $close_tags="],]],],],],],],],]";
  1986. $open_tag=explode(",",$open_tags);
  1987. $close_tag=explode(",",$close_tags);
  1988. foreach (array_keys($open_tag) as $key) {
  1989. if (preg_match_all('/' . preg_quote($open_tag[$key]) . '(.*?)' . preg_quote($close_tag[$key]) .'/i',$excerpt,$matches)) {
  1990. $excerpt=str_replace($matches[0],"" , $excerpt);
  1991. }
  1992. }
  1993. $excerpt = preg_replace('#(<wpg.*?>).*?(</wpg2>)#', '$1$2', $excerpt);
  1994. $excerpt=wordbooker_translate($excerpt);
  1995. $excerpt = strip_tags($excerpt);
  1996. # Now lets strip off the youtube stuff.
  1997. preg_match_all( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=)([\w-]+)(.*?)player_embedded#i', $excerpt, $matches );
  1998. $excerpt=str_replace($matches[0],"" , $excerpt);
  1999. preg_match_all( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=|embed/)([\w-]+)(.*?)#i', $excerpt, $matches );
  2000. $excerpt=str_replace($matches[0],"" , $excerpt);
  2001. $excerpt = apply_filters('wordbooker_post_excerpt', $excerpt);
  2002. if (strlen($excerpt) > $maxlength) {
  2003. # If we've got multibyte support then we need to make sure we get the right length - Thanks to Kensuke Akai for the fix
  2004. if(function_exists('mb_strimwidth')){$excerpt=mb_strimwidth($excerpt, 0, $maxlength, " ...");}
  2005. else { $excerpt=current(explode("SJA26666AJS", wordwrap($excerpt, $maxlength, "SJA26666AJS")))." ...";}
  2006. }
  2007. return $excerpt;
  2008. }
  2009. function wordbooker_translate($text) {
  2010. if (function_exists('qtrans_use')) {
  2011. global $q_config;
  2012. $text=qtrans_use($q_config['language'],$text);
  2013. }
  2014. return $text;
  2015. }
  2016. function wordbooker_publish_action($post_id) {
  2017. global $user_ID, $user_identity, $user_login, $wpdb,$wordbooker_post_options,$blog_id,$doing_post;
  2018. if(isset($doing_post)) {wordbooker_debugger("Looks like we've already got a post going on so we can give up","",$post_id,99) ; return;}
  2019. $doing_post="running";
  2020. $x = get_post_meta($post_id, '_wordbooker_options', true);
  2021. $post=get_post($post_id);
  2022. # Get the settings from the post_meta.
  2023. if (is_array($x)){
  2024. foreach (array_keys($x) as $key ) {
  2025. if (substr($key,0,8)=='wordbook') {
  2026. $wordbooker_post_options[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$x[$key]);
  2027. }
  2028. }
  2029. }
  2030. if (is_array($wordbooker_post_options)){
  2031. foreach (array_keys($wordbooker_post_options) as $key){
  2032. wordbooker_debugger("Post option : ".$key,$wordbooker_post_options[$key],$post->ID) ;
  2033. }
  2034. }
  2035. if ($wordbooker_post_options["wordbooker_publish_default"]=="200") { $wordbooker_post_options["wordbooker_publish_default"]='on';}
  2036. # If the user_ID is set then lets use that, if not get the user_id from the post
  2037. $whichuser=$post->post_author;
  2038. if ($user_ID >=1) {$whichuser=$user_ID;}
  2039. # If the default user is set to 0 then we use the current user (or the author of the post if that isn't set - i.e. if this is a scheduled post)
  2040. if ($wordbooker_post_options["wordbooker_default_author"] == 0 ) {$wpuserid=$whichuser;} else {$wpuserid=$wordbooker_post_options["wordbooker_default_author"];}
  2041. if ($wordbooker_post_options["wordbooker_publish_default"]!="on") {
  2042. wordbooker_debugger("Publish Default is not Set, Giving up ",$wpuserid,$post->ID) ;
  2043. return;
  2044. }
  2045. wordbooker_debugger("User has been set to : ",$wpuserid,$post->ID) ;
  2046. #if (!($wbuser = wordbooker_get_userdata($wpuserid)) || !$wbuser->access_token) {
  2047. if (!$wbuser = wordbooker_get_userdata($wpuserid) ) {
  2048. wordbooker_debugger("Unable to get FB session for : ",$wpuserid,$post->ID) ;
  2049. return 28;
  2050. }
  2051. wordbooker_debugger("Posting as user : ",$wpuserid,$post->ID) ;
  2052. wordbooker_debugger("Calling wordbooker_fbclient_publishaction"," ",$post->ID) ;
  2053. wordbooker_fbclient_publishaction($wbuser, $post->ID);
  2054. unset($doing_post);
  2055. return 30;
  2056. }
  2057. /*
  2058. function wordbooker_transition_post_status($newstatus, $oldstatus, $post_id) {
  2059. if ($newstatus == 'publish') {
  2060. return wordbooker_publish_action($post_id);
  2061. }
  2062. return 31;
  2063. }
  2064. */
  2065. function wordbooker_delete_post($post_id) {
  2066. global $blog_id;
  2067. wordbooker_delete_from_errorlogs($post_id,$blog_id);
  2068. wordbooker_delete_from_postlogs($post_id,$blog_id);
  2069. wordbooker_delete_from_commentlogs($post_id,$blog_id);
  2070. }
  2071. function wordbooker_process_post_queue($post_id) {
  2072. global $wpdb,$blog_id;
  2073. # We need to get the lowest post_id from the post_queue which has the lowest priority ID
  2074. }
  2075. function wordbooker_process_post_data($newstatus, $oldstatus, $post) {
  2076. global $user_ID, $user_identity, $user_login, $wpdb, $blog_id;
  2077. # If this is an autosave then we give up and return as otherwise we lose user settings.
  2078. if ($_POST['action']=='autosave') { return;}
  2079. if ($_POST['action']=='editpost') {
  2080. foreach (array_keys($_POST) as $key ) {
  2081. if (substr($key,0,8)=='wordbook') {
  2082. $wordbooker_sets[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$_POST[$key]);
  2083. }
  2084. }
  2085. #var_dump($wordbooker_sets);
  2086. #var_dump($post->ID);
  2087. update_post_meta($post->ID, '_wordbooker_options', $wordbooker_sets);
  2088. }
  2089. if (!$newstatus=="publish") { return;}
  2090. # If this is a password protected post we give up
  2091. if ($post->post_password != '') {return;}
  2092. # Check for non public custom post types.
  2093. if ( $post->post_status == 'publish' && $post->post_type != 'post' ) {
  2094. $post_type_info = get_post_type_object( $post->post_type );
  2095. if ( $post_type_info && !$post_type_info->public ) { return; }
  2096. }
  2097. # Has this been fired by a post revision rather than a proper publish
  2098. if (wp_is_post_revision($post->ID)) {return;}
  2099. $wordbooker_settings=wordbooker_options();
  2100. $wb_params = get_post_meta($post->ID, '_wordbooker_options', true);
  2101. if (! wordbooker_get_userdata($post->post_author)) { $wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2102. if ($wordbooker_settings["wordbooker_default_author"] == 0 ) {$wb_user_id=$post->post_author;} else {$wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2103. if ( (!is_array($wb_params)) &&((stripos($_POST["_wp_http_referer"],'press-this')) || ( stripos($_POST["_wp_http_referer"],'index.php')) || (!isset($_POST['wordbooker_post_edited']) )) ) {
  2104. wordbooker_debugger("Inside the press this / quick press / remote client block "," ",$post->ID) ;
  2105. # Get the default publish setting for the post type
  2106. if($post->post_type=='page'){
  2107. $publish=$wordbooker_settings["wordbooker_publish_page_default"];
  2108. }
  2109. else {
  2110. $publish=$wordbooker_settings["wordbooker_publish_post_default"];
  2111. }
  2112. # New get the user level settings from the DB
  2113. $wordbooker_user_settings_id="wordbookuser".$blog_id;
  2114. $wordbookuser=get_usermeta($wb_user_id,$wordbooker_user_settings_id);
  2115. # If we have user settings then lets go through and override the blog level defaults.
  2116. if(is_array($wordbookuser)) {
  2117. foreach (array_keys($wordbookuser) as $key) {
  2118. if ((strlen($wordbookuser[$key])>0) && ($wordbookuser[$key]!="0") ) {
  2119. # wordbooker_debugger("replacing ".$key." - ".$wordbooker_settings[$key]." with ",$wordbookuser[$key],$post->ID) ;
  2120. $wordbooker_settings[$key]=$wordbookuser[$key];
  2121. }
  2122. }
  2123. }
  2124. $wordbooker_settings['wordbooker_publish_default']=$publish;
  2125. # Then populate the post array.
  2126. if (is_array($wordbooker_settings)) {
  2127. foreach (array_keys($wordbooker_settings) as $key ) {
  2128. if (substr($key,0,8)=='wordbook') {
  2129. $_POST[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$wordbooker_settings[$key]);
  2130. }
  2131. }
  2132. }
  2133. }
  2134. if ( !wordbooker_get_userdata($user_ID)) {
  2135. $wb_user_id=$wordbooker_settings["wordbooker_default_author"];
  2136. # New get the user level settings from the DB
  2137. $wordbooker_user_settings_id="wordbookuser".$blog_id;
  2138. $wordbookuser=get_usermeta($wb_user_id,$wordbooker_user_settings_id);
  2139. # If we have user settings then lets go through and override the blog level defaults.
  2140. if(is_array($wordbookuser)) {
  2141. foreach (array_keys($wordbookuser) as $key) {
  2142. if ((strlen($wordbookuser[$key])>0) && ($wordbookuser[$key]!="0") ) {
  2143. $wordbooker_settings[$key]=$wordbookuser[$key];
  2144. }
  2145. }
  2146. }
  2147. # Then populate the post array.
  2148. if(is_array($wordbooker_settings)) {
  2149. foreach (array_keys($wordbooker_settings) as $key ) {
  2150. if (substr($key,0,8)=='wordbook') {
  2151. if (!isset($_POST[$key])){$_POST[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$wordbooker_settings[$key]);}
  2152. }
  2153. }
  2154. }
  2155. }
  2156. # OK now lets get the settings from the POST array
  2157. foreach (array_keys($_POST) as $key ) {
  2158. if (substr($key,0,8)=='wordbook') {
  2159. $wb_params[$key]=str_replace(array('&','"','\'','<','>',"\t",), array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),$_POST[$key]);
  2160. }
  2161. }
  2162. if ($newstatus=="future") {
  2163. $wb_params['wordbooker_scheduled_post']=1;
  2164. wordbooker_debugger("This looks like a post that is scheduled for future publishing",$newstatus,$post->ID,99);
  2165. }
  2166. if ($newstatus=="publish" && (!isset($oldstatus) || $oldstatus!="publish") ) {
  2167. wordbooker_debugger("This looks like a new post being published ",$newstatus,$post->ID,99) ;
  2168. $wb_params['wordbooker_new_post']=1;
  2169. }
  2170. update_post_meta($post->ID, '_wordbooker_options', $wb_params);
  2171. if ($newstatus=="publish") {
  2172. wordbooker_debugger("Calling Wordbooker publishing function",' ',$post->ID,99) ;
  2173. wordbooker_publish($post->ID);
  2174. }
  2175. }
  2176. function wordbooker_publish($post_id) {
  2177. global $user_ID, $user_identity, $user_login, $wpdb, $blog_id,$wordbooker_settings;
  2178. $post = get_post($post_id);
  2179. # If its less than 10 seconds since we saw this post last we give up
  2180. #$ts=wordbooker_postlogged($post_id,1);
  2181. #var_dump($ts);
  2182. #if (isset($ts) && $ts<=60 && $ts>1) {wordbooker_debugger("Publish hook re-fire, ignoring ",$ts,$post_id,99) ; return;}
  2183. # Clear down the error / diagnostic logs for this post.
  2184. #wordbooker_deletefrom_errorlogs($post_id);
  2185. if ((isset($user_ID) && $user_ID>0) && (!current_user_can(WORDBOOKER_MINIMUM_ADMIN_LEVEL))) { wordbooker_debugger("This user doesn't have enough rights"," ",$post_id,99) ; return; }
  2186. wordbooker_debugger("Commence Publish "," ",$post_id,99) ;
  2187. $wb_params = get_post_meta($post_id, '_wordbooker_options', true);
  2188. $wordbooker_settings = wordbooker_options();
  2189. # If there is no user row for this user then set the user id to the default author. If the default author is set to 0 (i.e current logged in user) then only blog level settings apply.
  2190. if (! wordbooker_get_userdata($post->post_author)) { $wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2191. if ($wordbooker_settings["wordbooker_default_author"] == 0 ) {$wb_user_id=$post->post_author;} else {$wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2192. # If we've no FB user associated with this ID and the blog owner hasn't overridden then we give up.
  2193. if ((! wordbooker_get_userdata($post->post_author)) && ( !isset($wordbooker_settings['wordbooker_publish_no_user']))) { wordbooker_debugger("Not a WB user (".$post->post_author.") and no overide - give up "," ",$post_id,99) ; return;}
  2194. if ((! wordbooker_get_userdata($wb_user_id)) && ( !isset($wordbooker_settings['wordbooker_publish_no_user']))) {wordbooker_debugger("Author (".$post->post_author.") not a WB user and no overide- give up "," ",$post_id,99) ; return;}
  2195. #}
  2196. if ($_POST["wordbooker_default_author"]== 0 ) { wordbooker_debugger("Author of this post is the Post Author"," ",$post->ID,99); $_POST["wordbooker_default_author"]=$post->post_author; }
  2197. // If soupy isn't set then its either a future post or a post inherting another users options so we need to get the meta data rather than rely on post data
  2198. wordbooker_debugger("Options Set - call transition "," ",$post_id) ;
  2199. $retcode=wordbooker_publish_action($post_id);
  2200. return $retcode;
  2201. }
  2202. function wordbooker_publish_remote($post_id) {
  2203. global $blog_id;
  2204. $post = get_post($post_id);
  2205. wordbooker_debugger("Commence Remote publish "," ",$post->ID,99) ;
  2206. $wordbooker_settings = wordbooker_options();
  2207. }
  2208. function wordbooker_post_comment($commentid) {
  2209. $wordbooker_settings = wordbooker_options();
  2210. if ( !isset($wordbooker_settings['wordbooker_comment_push'])) {
  2211. return;
  2212. }
  2213. global $wpdb, $user_id,$table_prefix;
  2214. $comment= get_comment($commentid);
  2215. $cpid = $comment->comment_post_ID;
  2216. $cstatus=$comment->comment_approved;
  2217. $ctext=$comment->comment_content;
  2218. $caemail=$comment->comment_author_email;
  2219. $cauth=$comment->comment_author;
  2220. $cuid=$comment->user_id;
  2221. $real_comment=true;
  2222. wordbooker_debugger("Start Comment Push "," ",$cpid) ;
  2223. #if (($cuid==0) && ($caemail==$wordbooker_settings['wordbooker_comment_email'])) {$real_comment=false;}
  2224. if ($cuid==0) {$real_comment=false;}
  2225. #if ($ctype=='Facebook Comment') {$real_comment=false;}
  2226. if ($real_comment) {
  2227. if ($cstatus==1) {
  2228. $post = get_post($cpid);
  2229. $ctextblock = <<<CODEBLOX
  2230. Name : $cauth
  2231. Comment: [from blog ] : $ctext
  2232. CODEBLOX;
  2233. if (($wbuser = wordbooker_get_userdata($post->post_author)) && $wbuser->access_token) {
  2234. #$fbclient = wordbooker_fbclient($wbuser);
  2235. # WE NEED TO CHECK THAT THE FB POST ACTUALLY EXISTS BEFORE WE POST OR it blows up.
  2236. $sql='Select fb_post_id from ' . WORDBOOKER_POSTCOMMENTS . ' where wp_post_id ='.$cpid;
  2237. $rows = $wpdb->get_results($sql);
  2238. wordbooker_debugger("Comment count: ",count($rows),$cpid,0) ;
  2239. if (count($rows)>0) {
  2240. foreach ($rows as $comdata_row) {
  2241. $fb_post_id=$comdata_row->fb_post_id;
  2242. # @param string $xid external id associated with the comments
  2243. #@param string $text text of the comment
  2244. # @param int $uid user adding the comment (def: session user)
  2245. # @param string $title optional title for the stream story
  2246. # @param string $url optional url for the stream story
  2247. # @param bool $publish_to_stream publish a feed story about this comment?
  2248. # a link will be generated to title/url in the story
  2249. #$result2=$fbclient->comments_add('100000384338372_105295439493267', $ctextblock.' ');
  2250. # This returns the comment ID so we should store this as a "made" comment for the post in question so we can exclude it when pulling comments down from facebook.
  2251. try {
  2252. $result2=$fbclient->stream_addComment($fb_post_id , $ctextblock.' ');
  2253. wordbooker_debugger("Comment Posted : ",$result2,$cpid,0) ;
  2254. }
  2255. catch (Exception $e) {
  2256. $error_code = $e->getCode();
  2257. $error_msg = $e->getMessage();
  2258. wordbooker_debugger("Comment Push Error : ",$error_msg,$cpid,99) ;
  2259. }
  2260. }
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. function wordbooker_debugger($method,$error_msg,$post_id,$level=9) {
  2267. global $user_ID,$post_ID,$wpdb,$blog_id,$post,$wbooker_user_id;
  2268. if (isset($post_id)){
  2269. $p=get_post($post_id);
  2270. #we dont want to record anything if its an draft of any kind
  2271. if (stristr($p->post_status,'draft')) {return;}
  2272. }
  2273. $usid=1;
  2274. $row_id=1;
  2275. if (!isset($post_id)) {$post_id=$post_ID;}
  2276. if (!isset($post_id)) {$post_id=1;}
  2277. if (isset($user_ID)) {$usid=$user_ID;}
  2278. if ($usid==0) {$usid=$wbooker_user_id;}
  2279. if (!isset($usid)) {$usid=wordbooker_get_option('wordbooker_default_author');}
  2280. if (!isset($usid)) {$usid=1;}
  2281. $sql= "INSERT INTO " . WORDBOOKER_ERRORLOGS . " (
  2282. user_id
  2283. , method
  2284. , error_code
  2285. , error_msg
  2286. , post_id
  2287. , blog_id
  2288. , diag_level
  2289. ) VALUES (
  2290. " . $usid . "
  2291. , '" . mysql_real_escape_string($method) . "'
  2292. , $row_id
  2293. , '" . mysql_real_escape_string($error_msg) . "'
  2294. , " . $post_id . "
  2295. , " . $blog_id ."
  2296. , " . $level ."
  2297. )";
  2298. $result = $wpdb->query($sql);
  2299. }
  2300. /******************************************************************************
  2301. * Register hooks with WordPress.
  2302. */
  2303. /* Plugin maintenance. */
  2304. register_activation_hook(__FILE__, 'wordbooker_activate');
  2305. # When a user is deleted from the blog we should clear down everything they've done in Wordbooker.
  2306. add_action('delete_user', 'wordbooker_remove_user');
  2307. add_action ('init', 'wordbooker_init');
  2308. function wordbooker_init () {
  2309. #load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) )
  2310. #$plugin_dir = basename(dirname(__FILE__));
  2311. load_plugin_textdomain ('wordbooker',false,basename(dirname(__FILE__)).'/languages');
  2312. }
  2313. function wordbooker_schema($attr) {
  2314. $attr .= " xmlns:fb=\"http://www.facebook.com/2008/fbml\" xmlns:og=\"http://opengraphprotocol.org/schema/\" ";
  2315. return $attr;
  2316. }
  2317. function wordbooker_get_avatar($avatar, $id_or_email, $size, $default, $alt){
  2318. //$avatar format includes the tag <img>
  2319. $imgpath = "http://website.com/image/myownimage.jpg";
  2320. $my_avatar = "<img src='".$path."' alt='".$alt."' height='".$size."' width='".$size."' />";
  2321. return $my_avatar;
  2322. }
  2323. function wordbooker_custom_cron_schedules($schedules){
  2324. $schedules['10mins'] = array(
  2325. 'interval' => 600,
  2326. 'display' => __('Every 10 Minutes', 'wordbooker'),
  2327. );
  2328. $schedules['15mins'] = array(
  2329. 'interval' => 900,
  2330. 'display' => __('Every 15 Minutes', 'wordbooker'),
  2331. );
  2332. $schedules['20mins'] = array(
  2333. 'interval' => 1200,
  2334. 'display' => __('Every 20 Minutes', 'wordbooker'),
  2335. );
  2336. $schedules['30mins'] = array(
  2337. 'interval' => 1800,
  2338. 'display' => __('Every 30 Minutes', 'wordbooker'),
  2339. );
  2340. $schedules['45mins'] = array(
  2341. 'interval' => 2700,
  2342. 'display' => __('Every 45 Minutes', 'wordbooker'),
  2343. );
  2344. $schedules['2hours'] = array(
  2345. 'interval' => 7200,
  2346. 'display' => __('Every 2 Hours', 'wordbooker'),
  2347. );
  2348. return array_merge($schedules);
  2349. }
  2350. /* Post/page maintenance and publishing hooks. */
  2351. $wordbooker_disabled=wordbooker_get_option('wordbooker_disabled');
  2352. # If they've disabled Wordbooker then we don't need any of these
  2353. if (!isset($wordbooker_disabled)){
  2354. #add_action('xmlrpc_publish_post', 'wordbooker_publish_remote',20);
  2355. add_action('transition_post_status', 'wordbooker_process_post_data',10,3);
  2356. add_action('delete_post', 'wordbooker_delete_post');
  2357. add_action('wb_cron_job', 'wordbooker_poll_facebook');
  2358. add_action('delete_post', 'wordbooker_delete_post');
  2359. #add_action('comment_post', 'wordbooker_post_comment');
  2360. add_action('wp_head', 'wordbooker_header');
  2361. add_action('wp_footer', 'wordbooker_footer');
  2362. add_filter('language_attributes', 'wordbooker_schema');
  2363. #add_filter('get_avatar','wordbooker_get_avatar');
  2364. #add_action('comment_post', 'wordbooker_post_comment', 20);
  2365. #add_action('wp_set_comment_status', 'wordbooker_set_comment_status', 20, 2);
  2366. add_filter('the_content', 'wordbooker_append_post');
  2367. add_filter('the_excerpt','wordbooker_append_post');
  2368. add_filter('cron_schedules','wordbooker_custom_cron_schedules');
  2369. add_shortcode('wb_fb_like', 'wordbooker_fb_like_inline');
  2370. add_shortcode('wb_fb_send', 'wordbooker_fb_send_inline');
  2371. add_shortcode('wb_fb_share', 'wordbooker_fb_share_inline');
  2372. add_shortcode('wb_fb_comment', 'wordbooker_fb_comment_inline');
  2373. add_shortcode('wb_fb_read','wordbooker_fb_read_inline');
  2374. }
  2375. #load_plugin_textdomain( 'wordbooker', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  2376. # Includes - trying to keep my code base tidy.
  2377. include("includes/wordbooker_options.php");
  2378. # If they've disabled Wordbooker then we don't need to load any of these.
  2379. if (!isset($wordbooker_disabled)){
  2380. include("includes/wordbooker_wb_widget.php");
  2381. include("includes/wordbooker_fb_widget.php");
  2382. include("includes/wordbooker_cron.php");
  2383. include("includes/wordbooker_posting.php");
  2384. #include("includes/wordbooker_get_friend.php");
  2385. #include("includes/custom_quick_edit.php");
  2386. }
  2387. # This is for support for alternative posting processes. Only Curl is supported right now
  2388. #if (wordbooker_get_option('wordbooker_fopen_curl')=='fopen'){
  2389. # include("includes/wordbooker_facebook_fopen.php");
  2390. #}
  2391. # else {
  2392. include("includes/wordbooker_facebook_curl.php");
  2393. # }
  2394. ?>