PageRenderTime 62ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 2684 lines | 2101 code | 269 blank | 314 comment | 513 complexity | 9b693a07ad6f5a4ccb049488a0a472bf MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.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.8
  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.8 - Mandragora');
  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. if (WORDBOOKER_WP_VERSION < 29) {
  719. $errormsg .= sprintf(__('Wordbooker requires <a href="%s">WordPress</a>-2.9 or newer (you appear to be running version %s).', 'wordbooker'),'http://wordpress.org/download/', $wp_version)."<b /r>";
  720. } else if (!($options = wordbooker_options()) ||
  721. !($wbuser = wordbooker_get_userdata($user_ID)) ||
  722. ( !$wbuser->access_token)) {
  723. $errormsg .=__("Wordbooker needs to be set up", 'wordbooker')."<br />";
  724. } else if ($wbuser->facebook_error) {
  725. $method = $wbuser->facebook_error['method'];
  726. $error_code = $wbuser->facebook_error['error_code'];
  727. $error_msg = $wbuser->facebook_error['error_msg'];
  728. $post_id = $wbuser->facebook_error['postid'];
  729. $suffix = '';
  730. if ($post_id != null && ($post = get_post($post_id))) {
  731. wordbooker_delete_from_postlogs($post_id);
  732. $suffix = __('for', 'wordbooker').' <a href="'. get_permalink($post_id) . '">'. get_the_title($post_id) . '</a>';
  733. }
  734. $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 />";
  735. wordbooker_clear_userdata_facebook_error($wbuser);
  736. }
  737. if ($errormsg) {
  738. ?>
  739. <h3><?php _e('Notices', 'wordbooker'); ?></h3>
  740. <div class="wordbooker_notices" style="background-color: #f66;">
  741. <p><?php echo $errormsg; ?></p>
  742. </div>
  743. <?php
  744. }
  745. }
  746. function get_check_session(){
  747. global $facebook2,$user_ID;
  748. # 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
  749. # OK lets go to the database and see if we have a session stored
  750. wordbooker_debugger("Getting Userdata "," ",0) ;
  751. $session = wordbooker_get_userdata($user_ID);
  752. if (strlen($session->access_token)>5) {
  753. var_dump($session);
  754. wordbooker_debugger("Session found. Check validity "," ",0) ;
  755. # We have a session ID so lets not get a new one
  756. # Put some session checking in here to make sure its valid
  757. try {
  758. # var_dump($session->access_token);
  759. wordbooker_debugger("Calling Facebook API : get current user "," ",0) ;
  760. # $attachment = array('access_token' => $session->access_token,);
  761. #var_dump($attachment);
  762. $ret_code=wordbooker_me($session->facebook_id,$session->access_token);
  763. # echo "mee";
  764. # var_dump($ret_code);
  765. }
  766. catch (Exception $e) {
  767. # We don't have a good session so
  768. wordbooker_debugger("User Session invalid - clear down data "," ",0) ;
  769. #wordbooker_delete_user($user_ID,1);
  770. return;
  771. }
  772. #var_dump($session);
  773. return $session->access_token;
  774. }
  775. else
  776. {
  777. # Are we coming back from a login with a session set?
  778. $zz=htmlspecialchars_decode ($_POST['session'])."<br>";
  779. $oldkey=explode("|",$zz);
  780. $newkey=explode("&expires",$zz);
  781. $session->access_token=$newkey[0];
  782. $session->session_key=$oldkey[1];
  783. $session->expires=0;
  784. $ret_code=wordbooker_me_status($session->facebook_id,$session->access_token);
  785. #echo "mee tooo";
  786. # var_dump($ret_code);
  787. wordbooker_debugger("Checking session (2) "," ",0) ;
  788. # $session = $facebook2->getSession();
  789. #var_dump($session);
  790. if (strlen($session->access_token)>5){
  791. wordbooker_debugger("Session found. Store it "," ",0) ;
  792. # Yes! so lets store it!y)
  793. wordbooker_set_userdata($onetime_data, $facebook_error, $secret,$session,$ret_code->id);
  794. return $session->access_token;
  795. }
  796. }
  797. }
  798. function wordbooker_option_setup($wbuser) {
  799. ?>
  800. <h3><?php _e('Setup', 'wordbooker'); ?></h3>
  801. <div class="wordbooker_setup">
  802. <?php
  803. $access_token=get_check_session();
  804. $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';
  805. if ( is_null($access_token) ) {
  806. wordbooker_debugger("No session found - lets login and authorise "," ",0,99) ;
  807. 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 />';
  808. }
  809. else {
  810. wordbooker_debugger("Everything looks good so lets ask them to refresh "," ",0,99) ;
  811. echo __("Wordbooker should now be authorised. Please click on the Reload Page Button",'wordbooker').'<br> <form action="options-general.php?page=wordbooker" method="post">';
  812. echo '<p style="text-align: center;"><input type="submit" name="perm_save" class="button-primary" value="'. __('Reload Page', 'wordbooker').'" /></p>';
  813. echo '</form> ';
  814. }
  815. echo "</div></div>";
  816. }
  817. function wordbooker_status($user_id)
  818. {
  819. echo '<h3>'.__('Status', 'wordbooker').'</h3>';
  820. global $wpdb, $user_ID,$table_prefix,$blog_id;
  821. $wordbooker_user_settings_id="wordbookuser".$blog_id;
  822. $wordbookuser=get_usermeta($user_ID,$wordbooker_user_settings_id);
  823. if ($wordbookuser['wordbooker_disable_status']=='on') {return;}
  824. global $shortcode_tags;
  825. $result = wordbooker_get_cache($user_id);
  826. ?>
  827. <div class="wordbooker_status">
  828. <div class="facebook_picture">
  829. <a href="<?php echo $result->url; ?>" target="facebook">
  830. <img src="<?php echo $result->pic; ?>" /></a>
  831. </div>
  832. <p>
  833. <a href="<?php echo $result->url; ?>"><?php echo $result->name; ?></a> ( <?php echo $result->facebook_id; ?> )<br /><br />
  834. <i><?php echo "<p>".$result->status; ?></i></p>
  835. (<?php
  836. $current_offset=0;
  837. $current_offset = get_option('gmt_offset');
  838. echo date('D M j, g:i a', $result->updated+(3600*$current_offset)); ?>).
  839. <br /><br />
  840. <?php
  841. }
  842. function wordbooker_option_status($wbuser) {
  843. global $wpdb,$user_ID;
  844. #$fbclient = wordbooker_fbclient($wbuser);
  845. # Go to the cache and try to pull details
  846. $fb_info=wordbooker_get_cache($user_ID,'use_facebook,facebook_id',1);
  847. # If we're missing stuff lets kick the cache.
  848. if (! isset($fb_info->facebook_id)) {
  849. wordbooker_cache_refresh ($user_ID,$fbclient);
  850. $fb_info=wordbooker_get_cache($user_ID,'use_facebook,facebook_id',1);
  851. }
  852. # if (isset($fbclient->secret)){
  853. #var_dump($fb_info);
  854. if ($fb_info->use_facebook==1) {
  855. echo"<p>".__('Wordbooker appears to be configured and working just fine', 'wordbooker');
  856. wordbooker_check_permissions($wbuser,$user);
  857. echo "</p><p>".__("If you like, you can start over from the beginning (this does not delete your posting and comment history)", 'wordbooker').":</p>";
  858. }
  859. else
  860. {
  861. echo "<p>".__('Wordbooker is able to connect to Facebook', 'wordbooker').'</p>';
  862. # _e( 'Or, you can start over from the beginning');
  863. }
  864. echo'<form action="" method="post">';
  865. echo '<p style="text-align: center;"><input type="submit" class="button-primary" name="reset_user_config" value="'.__('Reset User Session', 'wordbooker').'" />';
  866. echo '&nbsp;&nbsp;<input type="submit" name="perm_save" class="button-primary" value="'. __('Refresh Status', 'wordbooker').'" /></p>';
  867. echo '</form> </div>';
  868. $description=__("Recent Facebook Activity for this site", 'wordbooker');
  869. $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>';
  870. $activity="<hr><h3>".$description.'</h3><p>'.$iframe."</p></div>";
  871. $options = wordbooker_options();
  872. if (isset($options["wordbooker_fb_rec_act"])) { echo $activity; }
  873. }
  874. function wordbooker_version_ok($currentvers, $minimumvers) {
  875. #Lets strip out the text and any other bits of crap so all we're left with is numbers.
  876. $currentvers=trim(preg_replace("/[^0-9.]/ ", "", $currentvers ));
  877. $current = preg_split('/\D+/', $currentvers);
  878. $minimum = preg_split('/\D+/', $minimumvers);
  879. for ($ii = 0; $ii < min(count($current), count($minimum)); $ii++) {
  880. if ($current[$ii] < $minimum[$ii])
  881. return false;
  882. }
  883. if (count($current) < count($minimum))
  884. return false;
  885. return true;
  886. }
  887. function wordbooker_option_support() {
  888. global $wp_version,$wpdb,$user_ID,$facebook2;
  889. $wordbooker_settings=wordbooker_options();
  890. ?>
  891. <h3><?php _e('Support', 'wordbooker'); ?></h3>
  892. <div class="wordbooker_support">
  893. <?php _e('For feature requests, bug reports, and general support :', 'wordbooker'); ?>
  894. <ul>
  895. <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>
  896. <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>
  897. <li><?php _e('Try the ', 'wordbooker'); ?><a href="http://wordbooker.tty.org.uk/forums/" target="facebook"><?php _e('Wordbooker Support Forums', 'wordbooker'); ?></a>.</li>
  898. <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>
  899. <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>
  900. <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>
  901. <li><?php _e('Check the Wordbooker ', 'wordbooker'); ?><a href="http://wordbooker.tty.org.uk/faqs/">Wordbooker</a> <?php _e('FAQs', 'wordbooker'); ?></li>
  902. </ul>
  903. <br />
  904. <?php _e('Please provide the following information about your installation:', 'wordbooker'); ?>
  905. <ul>
  906. <?php
  907. $active_plugins = get_option('active_plugins');
  908. $plug_info=get_plugins();
  909. $phpvers = phpversion();
  910. $jsonvers=phpversion('json');
  911. if (!phpversion('json')) { $jsonvers="Installed but version not being returned";}
  912. $sxmlvers=phpversion('simplexml');
  913. if (!phpversion('simplexml')) { $sxmlvers=" No version being returned";}
  914. $mysqlvers = function_exists('mysql_get_client_info') ? mysql_get_client_info() : 'Unknown';
  915. # If we dont have the function then lets go and get the version the old way
  916. if ($mysqlvers=="Unknown") {
  917. $t=mysql_query("select version() as ve");
  918. $r=mysql_fetch_object($t);
  919. $mysqlvers = $r->ve;
  920. }
  921. $http_coding="No Multibyte support";
  922. $int_coding="No Multibyte support";
  923. $mb_language="No Multibyte support";
  924. #$t=mysql_query("show variables like 'character%'");
  925. if (function_exists('mb_convert_encoding')) {
  926. $http_coding=mb_http_output();
  927. $int_coding=mb_internal_encoding();
  928. $mb_language=mb_language();
  929. }
  930. $curlcontent=__("Curl is not installed",'wordbooker');
  931. if (function_exists('curl_init')) {
  932. $ch = curl_init();
  933. curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/platform');
  934. curl_setopt($ch, CURLOPT_HEADER, 0);
  935. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  936. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  937. curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/includes/fb_ca_chain_bundle.crt');
  938. 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');
  939. $curlcontent = @curl_exec($ch);
  940. $x=json_decode($curlcontent);
  941. #var_dump($x->name);
  942. $curlstatus=__("Curl is available but cannot access Facebook - This is a problem (",'wordbooker').curl_errno($ch)." - ". curl_error($ch) ." )";
  943. if ($x->name=="Facebook Platform") {$curlstatus=__("Curl is available and can access Facebook - All is OK",'wordbooker');}
  944. curl_close($ch);
  945. }
  946. $new_wb_table_prefix=$wpdb->base_prefix;
  947. if (isset ($db_prefix) ) { $new_wb_table_prefix=$db_prefix;}
  948. $info = array(
  949. 'Wordbooker' => $plug_info['wordbooker/wordbooker.php']['Version'],
  950. 'Wordbooker ID'=>WORDBOOKER_FB_ID,
  951. 'Wordbooker Schema' => $wordbooker_settings['schema_vers'],
  952. 'WordPress' => $wp_version,
  953. 'Table prefix' =>$new_wb_table_prefix,
  954. 'PHP' => $phpvers,
  955. 'PHP Memory Usage (MB)' => memory_get_usage(true)/1024/1024,
  956. 'JSON Encode' => WORDBOOKER_JSON_ENCODE,
  957. 'JSON Decode' => WORDBOOKER_JSON_DECODE,
  958. 'Curl Status' => $curlstatus,
  959. # 'Fopen Status' => $fopenstat2.$fopenstat,
  960. 'JSON Version' => $jsonvers,
  961. 'SimpleXML library' => $sxmlvers." (". WORDBOOKER_SIMPLEXML.")",
  962. 'HTTP Output Character Encoding'=>$http_coding,
  963. 'Internal PHP Character Encoding'=>$int_coding,
  964. 'MySQL' => $mysqlvers,
  965. # 'Facebook Transaction limit'=>$result2,
  966. );
  967. $version_errors = array();
  968. $phpminvers = '5.0';
  969. $mysqlminvers = '4.0';
  970. if (!wordbooker_version_ok($phpvers, $phpminvers)) {
  971. $version_errors['PHP'] = $phpminvers;
  972. }
  973. if ($mysqlvers != 'Unknown' && !wordbooker_version_ok($mysqlvers, $mysqlminvers)) {
  974. $version_errors['MySQL'] = $mysqlminvers;
  975. }
  976. foreach ($info as $key => $value) {
  977. $suffix = '';
  978. if (($minvers = $version_errors[$key])) {
  979. $suffix = " <span class=\"wordbooker_errorcolor\">" . " (need $key version $minvers or greater)" . " </span>";
  980. }
  981. echo "<li>$key: <b>$value</b>$suffix</li>";
  982. }
  983. if (!function_exists('simplexml_load_string')) {
  984. _e("<li>XML: your PHP is missing <code>simplexml_load_string()</code></li>", 'wordbooker');
  985. }
  986. $rows = $wpdb->get_results("show variables like 'character_set%'");
  987. foreach ($rows as $chardata){
  988. echo "<li> Database ". $chardata->Variable_name ." : <b> ".$chardata->Value ."</b></li>";
  989. }
  990. $rows = $wpdb->get_results("show variables like 'collation%'");
  991. foreach ($rows as $chardata){
  992. echo "<li> Database ". $chardata->Variable_name ." : <b> ".$chardata->Value ."</b></li>";
  993. }
  994. echo "<li> Server : <b>".$_SERVER['SERVER_SOFTWARE']."</b></li>";
  995. _e("<li> Active Plugins : <b></li>", 'wordbooker');
  996. foreach($active_plugins as $name) {
  997. if ( $plug_info[$name]['Title']!='Wordbooker') {
  998. echo "&nbsp;&nbsp;&nbsp;".$plug_info[$name]['Title']." ( ".$plug_info[$name]['Version']." ) <br />";}
  999. }
  1000. if (ADVANCED_DEBUG) { phpinfo(INFO_MODULES);}
  1001. ?>
  1002. </ul>
  1003. <?php
  1004. if ($version_errors) {
  1005. ?>
  1006. <div class="wordbooker_errorcolor">
  1007. <?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'); ?>
  1008. </div>
  1009. <?php
  1010. } else if ($mysqlvers == 'Unknown') {
  1011. ?>
  1012. <div>
  1013. <?php _e('Please ensure that your system meets the', 'wordbooker'); ?> <a href="http://wordpress.org/about/requirements/"><?php _e('WordPress minimum requirements', 'wordbooker'); ?></a>.
  1014. </div>
  1015. <?php
  1016. }
  1017. ?>
  1018. </div>
  1019. <?php
  1020. }
  1021. /******************************************************************************
  1022. * Facebook API wrappers.
  1023. */
  1024. /*
  1025. function wordbooker_fbclient_facebook_finish($wbuser, $result, $method,$error_code, $error_msg, $post_id,$result2, $error_code2, $error_msg2)
  1026. {
  1027. global $blog_id;
  1028. wordbooker_debugger("Publish complete"," ",$post_id,99) ;
  1029. if ($error_code) {
  1030. wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code, $error_msg, $post_id);
  1031. }
  1032. if ($error_code2) {
  1033. wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code2, $error_msg2, $post_id);
  1034. }
  1035. If ((! $error_code) && (! $error_code2))
  1036. {
  1037. wordbooker_clear_userdata_facebook_error($wbuser);
  1038. wordbooker_delete_from_process_queue($post_id,$blog_id);
  1039. }
  1040. return array($result,$result2);
  1041. }
  1042. */
  1043. function wordbooker_fbclient_publishaction($wbuser,$post_id)
  1044. {
  1045. global $wordbooker_post_options,$wpdb;
  1046. $wordbooker_settings =wordbooker_options();
  1047. $post = get_post($post_id);
  1048. $post_link_share = get_permalink($post_id);
  1049. $post_link=wordbooker_short_url($post_id);
  1050. $post_title=$post->post_title;
  1051. $post_content = $post->post_content;
  1052. # 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.
  1053. $processed_content ="!!! ".apply_filters('the_content', $post_content)." !!!";
  1054. $yturls = array();
  1055. $matches_tn=array();
  1056. # Get the Yapb image for the post
  1057. if (class_exists('YapbImage')) {
  1058. $siteUrl = get_option('siteurl');
  1059. if (substr($siteUrl, -1) != '/') $siteUrl .= '/';
  1060. $uri = substr($url, strpos($siteUrl, '/', strpos($url, '//')+2));
  1061. $WordbookerYapbImageclass = new YapbImage(null,$post->ID,$uri);
  1062. $WordbookerYapbImage=$WordbookerYapbImageclass->getInstanceFromDb($post_id);
  1063. if (strlen($WordbookerYapbImage->uri)>6) {$yturls[]=get_bloginfo('url').$WordbookerYapbImage->uri;}
  1064. }
  1065. if ( function_exists( 'get_the_post_thumbnail' ) ) {
  1066. wordbooker_debugger("Getting the thumnail image"," ",$post->ID) ;
  1067. preg_match_all('/<img \s+ ([^>]*\s+)? src \s* = \s* [\'"](.*?)[\'"]/ix',get_the_post_thumbnail($post_id), $matches_tn);
  1068. }
  1069. $meta_tag_scan=explode(',',$wordbooker_settings['wordbooker_meta_tag_scan']);
  1070. foreach($meta_tag_scan as $meta_tag) {
  1071. wordbooker_debugger("Getting image from custom meta : ",$meta_tag,$post->ID) ;
  1072. $matches_ct[]=get_post_meta($post->ID, $meta_tag, TRUE);
  1073. }
  1074. $matches=$matches_ct;
  1075. if ( function_exists( 'get_the_post_thumbnail' ) ) {
  1076. $matches=array_merge($matches_ct,$matches_tn[2]);
  1077. }
  1078. # If the user only wants the thumbnail then we can simply not do the skim over the processed images
  1079. if (! isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
  1080. wordbooker_debugger("Getting the rest of the images "," ",$post->ID) ;
  1081. preg_match_all('/<img \s+ ([^>]*\s+)? src \s* = \s* [\'"](.*?)[\'"]/ix',$processed_content, $matched);
  1082. $x=strip_shortcodes($post_content);
  1083. preg_match_all( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=|embed/)([\w-]+)(.*?)#i', $x, $matches3 );
  1084. if (is_array($matches3[3])) {
  1085. foreach ($matches3[3] as $key ) {
  1086. $yturls[]='http://img.youtube.com/vi/'.$key.'/0.jpg';
  1087. }
  1088. }
  1089. }
  1090. if ( function_exists( 'get_the_post_thumbnail' ) ) {
  1091. # If the thumb only is set then pulled images is just matches
  1092. if (!isset($wordbooker_settings["wordbooker_meta_tag_thumb"])) {
  1093. if (! isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
  1094. wordbooker_debugger("Setting image array to be both thumb and the post images "," ",$post->ID) ;
  1095. $pulled_images=@array_merge($matches[2],$matched[2],$yturls,$matches);
  1096. }
  1097. else {
  1098. wordbooker_debugger("Setting image array to be just thumb "," ",$post->ID) ;
  1099. $pulled_images[]=$matches[2];
  1100. }
  1101. }
  1102. }
  1103. if (isset($wordbooker_settings["wordbooker_meta_tag_thumb"]) && isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
  1104. wordbooker_debugger("Setting image array to be just thumb from meta. "," ",$post->ID) ;
  1105. $pulled_images[]=$matches_ct[2];}
  1106. else {
  1107. wordbooker_debugger("Setting image array to be post and thumb images. "," ",$post->ID) ;
  1108. if (is_array($matched[2])) {$pulled_images[]=array_merge($matches,$matched[2]);}
  1109. if (is_array($matched[2]) && is_array($yturls)) {$pulled_images=array_merge($matches,$matched[2],$yturls);}
  1110. }
  1111. $images = array();
  1112. if (is_array($pulled_images)) {
  1113. foreach ($pulled_images as $imgsrc) {
  1114. if ($imgsrc) {
  1115. if (stristr(substr($imgsrc, 0, 8), '://') ===false) {
  1116. /* Fully-qualify src URL if necessary. */
  1117. $scheme = $_SERVER['HTTPS'] ? 'https' : 'http';
  1118. $new_imgsrc = "$scheme://". $_SERVER['SERVER_NAME'];
  1119. if ($imgsrc[0] == '/') {
  1120. $new_imgsrc .= $imgsrc;
  1121. }
  1122. $imgsrc = $new_imgsrc;
  1123. }
  1124. $images[] = $imgsrc;
  1125. }
  1126. }
  1127. }
  1128. /* Pull out <wpg2> image tags. */
  1129. $wpg2_g2path = get_option('wpg2_g2paths');
  1130. if ($wpg2_g2path) {
  1131. $g2embeduri = $wpg2_g2path['g2_embeduri'];
  1132. if ($g2embeduri) {
  1133. preg_match_all('/<wpg2>(.*?)</ix', $processed_content,
  1134. $wpg_matches);
  1135. foreach ($wpg_matches[1] as $wpgtag) {
  1136. if ($wpgtag) {
  1137. $images[] = $g2embeduri.'?g2_view='.'core.DownloadItem'."&g2_itemId=$wpgtag";
  1138. }
  1139. }
  1140. }
  1141. }
  1142. $wordbooker_settings =wordbooker_options();
  1143. if (count($images)>0){
  1144. # Remove duplicates
  1145. $images=array_unique($images);
  1146. # Strip images from various plugins
  1147. $im

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