PageRenderTime 62ms CodeModel.GetById 19ms 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

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

  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

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