PageRenderTime 76ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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. $images=wordbooker_strip_images($images);
  1148. # And limit it to 5 pictures to keep Facebook happy.
  1149. $images = array_slice($images, 0, 5);
  1150. } else {
  1151. if (isset($wordbooker_settings['wordbooker_use_this_image'])) {
  1152. $images[]=$wordbooker_settings['wb_wordbooker_default_image'];
  1153. wordbooker_debugger("No Post images found so using open graph default to keep Facebook happy ",'',$post->ID) ;
  1154. }
  1155. else {
  1156. $x=get_bloginfo('wpurl').'/wp-content/plugins/wordbooker/includes/wordbooker_blank.jpg';
  1157. $images[]=$x;
  1158. wordbooker_debugger("No Post images found so loading blank to keep Facebook happy ",'',$post->ID) ;
  1159. }
  1160. }
  1161. #var_dump($images);
  1162. foreach ($images as $single) {
  1163. $images_array[]=array(
  1164. 'type' => 'image',
  1165. 'src' => $single,
  1166. 'href' => $post_link_share,
  1167. );
  1168. }
  1169. $images=$images_array;
  1170. #var_dump($images);
  1171. foreach ($images as $key){
  1172. wordbooker_debugger("Post Images : ".$key['src'],'',$post->ID) ;
  1173. }
  1174. // Set post_meta to be first image
  1175. update_post_meta($post->ID,'_wordbooker_thumb',$images[0]['src']);
  1176. wordbooker_debugger("Getting the Excerpt"," ",$post->ID) ;
  1177. unset ($processed_content);
  1178. if (isset($wordbooker_post_options["wordbooker_use_excerpt"]) && (strlen($post->post_excerpt)>3)) {
  1179. $post_content=$post->post_excerpt;
  1180. $post_content=wordbooker_translate($post_content);
  1181. }
  1182. else { $post_content=wordbooker_post_excerpt($post_content,$wordbooker_post_options['wordbooker_extract_length']);}
  1183. update_post_meta($post->ID,'_wordbooker_extract',$post_content);
  1184. # this is getting and setting the post attributes
  1185. $post_attribute=parse_wordbooker_attributes(stripslashes($wordbooker_post_options["wordbooker_attribute"]),$post_id,strtotime($post->post_date));
  1186. $post_data = array(
  1187. 'media' => $images,
  1188. 'post_link' => $post_link,
  1189. 'post_link_share' => $post_link_share,
  1190. 'post_title' => $post_title,
  1191. 'post_excerpt' => $post_content,
  1192. 'post_attribute' => $post_attribute,
  1193. # 'post_full_text' => $post->post_content,
  1194. 'post_id'=>$post->ID,
  1195. 'post_date'=>$post->post_date
  1196. );
  1197. # This is the tagging code -
  1198. #if (strlen($wordbooker_post_options['wordbooker_tag_list']) > 6 ) {
  1199. # $wordbooker_tag_list=str_replace('[','@[',$wordbooker_post_options['wordbooker_tag_list']);
  1200. # $message=$message. " (Tagged : ".$wordbooker_tag_list." ) ";
  1201. # }
  1202. if (function_exists('qtrans_use')) {
  1203. global $q_config;
  1204. $post_data['post_title']=qtrans_use($q_config['default_language'],$post_data['post_title']);
  1205. }
  1206. $post_id=$post->ID;
  1207. $wordbooker_fb_post = array(
  1208. 'name' => $post_data['post_title'],
  1209. 'link' => $post_data['post_link'],
  1210. 'message'=> $post_data['post_attribute'],
  1211. 'description' => $post_data['post_excerpt'],
  1212. 'media' => json_encode($images)
  1213. );
  1214. wordbooker_debugger("Post Titled : ",$post_data['post_title'],$post_id,99) ;
  1215. wordbooker_debugger("Post URL : ",$post_data['post_link'],$post_id,99) ;
  1216. if ($wordbooker_post_options['wordbooker_actionlink']==100) {
  1217. // No action link
  1218. wordbooker_debugger("No action link being used","",$post_id,99) ;
  1219. }
  1220. if ($wordbooker_post_options['wordbooker_actionlink']==200) {
  1221. // Share This
  1222. wordbooker_debugger("Share Link being used"," ",$post_id,99) ;
  1223. $action_links = array('name' => __('Share', 'wordbooker'),'link' => 'http://www.facebook.com/share.php?u='.urlencode($post_data['post_link_share']));
  1224. $wordbooker_fb_post['actions']=json_encode($action_links);
  1225. }
  1226. if ($wordbooker_post_options['wordbooker_actionlink']==300) {
  1227. // Read Full
  1228. wordbooker_debugger("Read Full link being used"," ",$post_id,99) ;
  1229. $action_links = array('name' => __('Read entire article', 'wordbooker'),'link' => $post_data['post_link_share']);
  1230. $wordbooker_fb_post['actions'] =json_encode($action_links);
  1231. }
  1232. $posting_array[] = array('target_id'=>__("Primary", 'wordbooker'),
  1233. 'target'=>$wordbooker_post_options['wordbooker_primary_target'],
  1234. 'target_type'=>$wordbooker_post_options['wordbooker_primary_type'],
  1235. 'target_active'=>$wordbooker_post_options['wordbooker_primary_active']);
  1236. $posting_array[] = array('target_id'=>__("Secondary", 'wordbooker'),
  1237. 'target'=>$wordbooker_post_options['wordbooker_secondary_target'],
  1238. 'target_type'=>$wordbooker_post_options['wordbooker_secondary_type'],
  1239. 'target_active'=>$wordbooker_post_options['wordbooker_secondary_active']);;
  1240. $target_types = array('PW' => "",'FW' => __('Fan Wall', 'wordbooker'), 'GW'=>__('Group wall', 'wordbooker'));
  1241. $posting_type=array("1"=>"Wall Post","2"=>"Note","3"=>"Status Update");
  1242. foreach($posting_array as $posting_target) {
  1243. $access_token='dummy access token';
  1244. $wbuser->pages[]=array( 'id'=>'PW:'.$wbuser->facebook_id, 'name'=>"Personal Wall",'access_token'=>$wbuser->access_token);
  1245. if(is_array($wbuser->pages)){
  1246. foreach ($wbuser->pages as $pager) {
  1247. if ($pager['id']==$posting_target['target']) {
  1248. $target_name=$pager['name'];
  1249. $access_token=$pager['access_token'];
  1250. }
  1251. }
  1252. }
  1253. if (isset($posting_target['target_active'])) {
  1254. $target_type=substr($posting_target['target'],0,2);
  1255. wordbooker_debugger("Posting to ".$target_types[$target_type]." ".$target_name." (".$posting_target['target_id'].") as a ".$posting_type[$posting_target['target_type']],"",$post_id,99) ;
  1256. if ($access_token=='dummy access token') {$access_token=$wbuser->access_token;}
  1257. $target=substr($posting_target['target'],3);
  1258. $is_dummy=$wordbooker_settings['wordbooker_fake_publish'];
  1259. switch($posting_target['target_type']) {
  1260. # Wall Post
  1261. case 1 :
  1262. wordbooker_wall_post($post_id,$access_token,$post_title,$wordbooker_fb_post ,$target,$is_dummy,$target_name);
  1263. break;
  1264. # Note
  1265. case 2 :
  1266. wordbooker_notes_post($post_id,$access_token,$post_title,$target,$is_dummy,$target_name);
  1267. break;
  1268. # Status Update
  1269. case 3 :
  1270. wordbooker_status_update($post_id,$access_token,$post_data['post_date'],$target,$is_dummy,$target_name);
  1271. break ;
  1272. }
  1273. } else {wordbooker_debugger("Posting to ".$posting_target['target_id']." target (".$target_name.") not active","",$post_id,99) ; }
  1274. }
  1275. }
  1276. function wordbooker_strip_images($images)
  1277. {
  1278. $newimages = array();
  1279. $strip_array= array ('addthis.com','gravatar.com','zemanta.com','wp-includes','plugins','favicon.ico','facebook.com','themes','mu-plugins','fbcdn.net');
  1280. foreach($images as $single){
  1281. $ext = substr(strrchr($single, '.'), 1);
  1282. if (strlen($ext) >2){
  1283. foreach ($strip_array as $strip_domain) {
  1284. wordbooker_debugger("Looking for ".$strip_domain." in ".$single," ",$post->ID,200) ;
  1285. if (stripos($single,$strip_domain)) {wordbooker_debugger("Found a match so dump the image",$single,$post->ID,200) ;} else { if (!in_array($single,$newimages)){$newimages[]=$single;}}
  1286. }} else {wordbooker_debugger("Image URL ".$single." not valid ",$post->ID,200) ;}
  1287. }
  1288. return $newimages;
  1289. }
  1290. function wordbooker_get_language() {
  1291. global $q_config;
  1292. $wplang="en_US";
  1293. if (strlen(WPLANG) > 2) {$wplang=WPLANG;}
  1294. if (isset ($q_config["language"])) {
  1295. $x=get_option('qtranslate_locales');
  1296. $wplang=$x[$q_config["language"]];
  1297. }
  1298. if (strlen($wplang)< 5) {$wplang='en_US';}
  1299. if ($wplang=="WPLANG" ) {$wplang="en_US";}
  1300. return $wplang;
  1301. }
  1302. function wordbooker_short_url($post_id) {
  1303. # This provides short_url responses by checking for various functions and using
  1304. $wordbooker_settings =wordbooker_options();
  1305. if (isset($wordbooker_settings["wordbooker_disable_shorties"])) {
  1306. $url = get_permalink($post_id);
  1307. return $url;
  1308. }
  1309. $url = get_permalink($post_id);
  1310. $url2 = $url;
  1311. if (function_exists(fts_show_shorturl)) {
  1312. $post = get_post($post_id);
  1313. $url=fts_show_shorturl($post,$output = false);
  1314. }
  1315. if (function_exists(wp_ozh_yourls_geturl)) {
  1316. $url=wp_ozh_yourls_geturl($post_id);
  1317. }
  1318. if ("!!!".$url."XXXX"=="!!!XXXX") {$url = $url2;}
  1319. return $url;
  1320. }
  1321. function parse_wordbooker_attributes($attribute_text,$post_id,$timestamp) {
  1322. # Changes various "tags" into their WordPress equivalents.
  1323. $post = get_post($post_id);
  1324. $user_id=$post->post_author;
  1325. $title=$post->post_title;
  1326. $perma=get_permalink($post->ID);
  1327. $perma_short=wordbooker_short_url($post_id);
  1328. $user_info = get_userdata($user_id);
  1329. $blog_url= get_bloginfo('url');
  1330. $wp_url= get_bloginfo('wpurl');
  1331. $blog_name = get_bloginfo('name');
  1332. $author_nice=$user_info->display_name;
  1333. $author_nick=$user_info->nickname;
  1334. $author_first=$user_info->first_name;
  1335. $author_last=$user_info->last_name;
  1336. # Format date and time to the blogs preferences.
  1337. $date_info=date_i18n(get_option('date_format'),$timestamp);
  1338. $time_info=date_i18n(get_option('time_format'),$timestamp);
  1339. # Now do the replacements
  1340. $attribute_text=str_ireplace( '%author%',$author_nice,$attribute_text );
  1341. $attribute_text=str_ireplace( '%first%',$author_first,$attribute_text );
  1342. $attribute_text=str_ireplace( '%wpurl%',$wp_url,$attribute_text );
  1343. $attribute_text=str_ireplace( '%burl%',$blog_url,$attribute_text );
  1344. $attribute_text=str_ireplace( '%last%',$author_last,$attribute_text );
  1345. $attribute_text=str_ireplace( '%nick%',$author_nick,$attribute_text );
  1346. $attribute_text=str_ireplace( '%title%',$title,$attribute_text );
  1347. $attribute_text=str_ireplace( '%link%',$perma,$attribute_text );
  1348. $attribute_text=str_ireplace( '%slink%',$perma_short,$attribute_text );
  1349. $attribute_text=str_ireplace( '%date%', $date_info ,$attribute_text);
  1350. $attribute_text=str_ireplace( '%time%', $time_info,$attribute_text );
  1351. return $attribute_text;
  1352. }
  1353. function wordbooker_footer($blah)
  1354. {
  1355. if (is_404()) {
  1356. echo "\n<!-- Wordbooker code revision : ".WORDBOOKER_CODE_RELEASE." -->\n";
  1357. return;
  1358. }
  1359. $wplang=wordbooker_get_language();
  1360. $efb_script = <<< EOGS
  1361. <div id="fb-root"></div>
  1362. <script type="text/javascript">
  1363. window.fbAsyncInit = function() {
  1364. FB.init({
  1365. appId : '254577506873',
  1366. status : true, // check login status
  1367. cookie : true, // enable cookies to allow the server to access the session
  1368. xfbml : true, // parse XFBML
  1369. oauth:true
  1370. });
  1371. };
  1372. (function() {
  1373. var e = document.createElement('script');
  1374. EOGS;
  1375. $efb_script.= "e.src = document.location.protocol + '//connect.facebook.net/".$wplang."/all.js';";
  1376. $efb_script.= <<< EOGS
  1377. e.async = true;
  1378. document.getElementById('fb-root').appendChild(e);
  1379. }());
  1380. </script>
  1381. EOGS;
  1382. $wordbooker_settings = wordbooker_options();
  1383. if (isset($wordbooker_settings['wordbooker_like_button_show']) || isset($wordbooker_settings['wordbooker_like_share_too']))
  1384. {
  1385. echo $efb_script;
  1386. if ( isset($wordbooker_settings['wordbooker_iframe'])) {
  1387. echo '<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>';
  1388. }
  1389. }
  1390. # echo '\n<script type="text/javascript " defer="defer" > setTimeout("wordbooker_read()",3000); </script> \n';
  1391. echo "\n<!-- Wordbooker code revision : ".WORDBOOKER_CODE_RELEASE." -->\n";
  1392. return $blah;
  1393. }
  1394. function wordbooker_og_tags(){
  1395. if (is_404()) {return;}
  1396. global $post;
  1397. # Stops the code firing on non published posts
  1398. if ('publish' != get_post_status($post->ID)) {return;}
  1399. $bname=get_bloginfo('name');
  1400. $bdesc=get_bloginfo('description');
  1401. $wordbooker_settings = wordbooker_options();
  1402. # Always put out the tags because even if they are not using like/share it gives Facebook stuff to work with.
  1403. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1404. $wpuserid=$post->post_author;
  1405. if (is_array($wordbooker_post_options)){
  1406. if ($wordbooker_post_options["wordbooker_default_author"] > 0 ) {$wpuserid=$wordbooker_post_options["wordbooker_default_author"];}
  1407. }
  1408. $blog_name=get_bloginfo('name');
  1409. echo '<meta property="og:site_name" content="'.$bname.' - '.$bdesc.'"/> ';
  1410. if (strlen($wordbooker_settings["fb_comment_app_id"])<6) {
  1411. if ($wordbooker_settings['wordbooker_fb_comments_admin']) {
  1412. $xxx=wordbooker_get_cache(-99,facebook_id,1);
  1413. #var_dump($wordbooker_settings['wb_wordbooker_default_image']);
  1414. if (!is_null($xxx)) {
  1415. echo '<meta property="fb:admins" content="'.$xxx.'"/> ';
  1416. }
  1417. } else {
  1418. $xxx=wordbooker_get_cache( $wpuserid,facebook_id,1);
  1419. if (!is_null($xxx->facebook_id)) {
  1420. echo '<meta property="fb:admins" content="'.$xxx->facebook_id.'"/> ';
  1421. }
  1422. }
  1423. }
  1424. if (strlen($wordbooker_settings["fb_comment_app_id"])>6) {
  1425. echo '<meta property = "fb:app_id" content = "'.$wordbooker_settings["fb_comment_app_id"].'" /> ';
  1426. }
  1427. if (defined('WORDBOOKER_PREMIUM')) {
  1428. echo '<meta property = "fb:app_id" content = "'.WORDBOOKER_FB_ID.'" /> ';
  1429. }
  1430. if ( (is_single() || is_page()) && !is_front_page() && !is_category() && !is_home() ) {
  1431. $post_link = get_permalink($post->ID);
  1432. $post_title=$post->post_title;
  1433. echo '<meta property="og:title" content="'.htmlspecialchars(strip_tags($post_title),ENT_QUOTES).'"/> ';
  1434. echo '<meta property="og:url" content="'.$post_link.'"/> ';
  1435. echo '<meta property="og:type" content="article"/> ';
  1436. $ogimage=get_post_meta($post->ID, '_wordbooker_thumb', TRUE);
  1437. if (strlen($ogimage)<4 && strlen($wordbooker_settings['wb_wordbooker_default_image'])>4) {
  1438. $ogimage=$wordbooker_settings['wb_wordbooker_default_image'];
  1439. }
  1440. if (strlen($ogimage)>4) {
  1441. echo '<meta property="og:image" content="'.$ogimage.'"/> ';
  1442. }
  1443. }
  1444. else
  1445. { # Not a single post so we only need the og:type tag
  1446. echo '<meta property="og:type" content="blog"/> ';
  1447. }
  1448. #wordbooker_get_option('wordbooker_description_meta_length')
  1449. if ($meta_length = wordbooker_get_option('wordbooker_description_meta_length')) {
  1450. if (is_single() || is_page()) {
  1451. $excerpt=get_post_meta($post->ID, '_wordbooker_extract', TRUE);
  1452. #var_dump($excerpt);
  1453. if(strlen($excerpt) < 5 ) {
  1454. $excerpt=wordbooker_post_excerpt($post->post_content,$wordbooker_settings['wordbooker_extract_length']);
  1455. update_post_meta($post->ID, '_wordbooker_extract', $excerpt);
  1456. # var_dump($excerpt);
  1457. }
  1458. # If we've got an excerpt use that instead
  1459. if ((strlen($post->post_excerpt)>3) && (strlen($excerpt) <=5)) {
  1460. $excerpt=$post->post_excerpt;
  1461. $description = str_replace('"','&quot;',$post->post_content);
  1462. $excerpt = wordbooker_post_excerpt($description,$meta_length);
  1463. $excerpt = preg_replace('/(\r|\n)+/',' ',$excerpt);
  1464. $excerpt = preg_replace('/\s\s+/',' ',$excerpt);
  1465. update_post_meta($post->ID, '_wordbooker_extract', $excerpt);
  1466. }
  1467. # Now if we've got something put the meta tag out.
  1468. if (isset($excerpt)){
  1469. $meta_string = sprintf("<meta name=\"description\" content=\"%s\"/> ", htmlspecialchars($excerpt,ENT_QUOTES));
  1470. echo $meta_string;
  1471. }
  1472. }
  1473. else
  1474. {
  1475. $meta_string = sprintf("<meta name=\"description\" content=\"%s\"/> ", get_bloginfo('description'));
  1476. echo $meta_string;
  1477. }
  1478. }
  1479. }
  1480. function wordbooker_header($blah){
  1481. if (is_404()) {return;}
  1482. global $post;
  1483. # Stops the code firing on non published posts
  1484. if ('publish' != get_post_status($post->ID)) {return;}
  1485. $wordbooker_settings = wordbooker_options();
  1486. # Now we just call the wordbooker_og_tags function.
  1487. if (!isset ( $wordbooker_settings['wordbooker_fb_disable_og'])) {
  1488. wordbooker_og_tags();
  1489. }
  1490. /* if (is_single() && isset($wordbooker_settings['wordbooker_read_button']) ) {
  1491. $read_codes=" <script type=\"text/javascript\">
  1492. function wordbooker_read()
  1493. {
  1494. FB.api('/me/".OPENGRAPH_NAMESPACE.":read' +
  1495. '?article=";
  1496. $read_codes.=get_permalink($post->ID);
  1497. $read_codes.="&access_token=".OPENGRAPH_ACCESS_TOKEN."','post',";
  1498. $read_codes.=<<<READCODE4
  1499. function(response) {
  1500. var msg = 'Error occured';
  1501. if (!response || response.error) {
  1502. if (response.error) {
  1503. msg += " Type: " + response.error.type+" Message: " + response.error.message;
  1504. }
  1505. alert(msg);
  1506. }
  1507. else {
  1508. //alert('Post was successful! Action ID: ' + response.id);
  1509. }
  1510. });
  1511. }
  1512. </script>
  1513. READCODE4;
  1514. echo $read_codes;
  1515. }
  1516. */
  1517. return $blah;
  1518. }
  1519. function display_wordbooker_fb_comment() {
  1520. global $post;
  1521. if(!is_single()){return;}
  1522. $wordbooker_settings = wordbooker_options();
  1523. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1524. #var_dump($wordbooker_settings['wordbooker_comment_handling']);
  1525. # var_dump($wordbooker_post_options['wordbooker_use_facebook_comments']);
  1526. if ($wordbooker_settings['wordbooker_comment_handling']=="2" && isset($wordbooker_post_options['wordbooker_use_facebook_comments'])) {
  1527. $post_link = get_permalink($post->ID);
  1528. $checked_flag=array('on'=>'true','off'=>'false');
  1529. $comment_code= '<fb:comments href="'.$post_link.'" num_posts="'.$wordbooker_settings['fb_comment_box_count'].'" width="'.$wordbooker_settings['fb_comment_box_size'].'" notify="'.$checked_flag[$wordbooker_settings['fb_comment_box_notify']].' colorscheme="'.$wordbooker_settings['wb_comment_colorscheme'].'" ></fb:comments>';
  1530. echo $comment_code;
  1531. }
  1532. }
  1533. function wordbooker_fb_comment_inline() {
  1534. global $post;
  1535. if(!is_single()){return;}
  1536. $wordbooker_settings = wordbooker_options();
  1537. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1538. if ($wordbooker_settings['wordbooker_comment_handling']=="2" && isset($wordbooker_post_options['wordbooker_use_facebook_comments'])) {
  1539. $post_link = get_permalink($post->ID);
  1540. $checked_flag=array('on'=>'true','off'=>'false');
  1541. $comment_code= '<fb:comments href="'.$post_link.'" num_posts="'.$wordbooker_settings['fb_comment_box_count'].'" width="'.$wordbooker_settings['fb_comment_box_size'].'" notify="'.$checked_flag[$wordbooker_settings['fb_comment_box_notify']].' colorscheme="'.$wordbooker_settings['wb_comment_colorscheme'].'" ></fb:comments>';
  1542. return $comment_code;
  1543. }
  1544. }
  1545. function display_wordbooker_fb_share() {
  1546. global $post;
  1547. $wordbooker_settings = wordbooker_options();
  1548. $do_share=0;
  1549. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1550. #var_dump($$wordbooker_settings[);
  1551. if ($wordbooker_post_options['wordbooker_share_button_post']==2 && !is_page()) {return ;}
  1552. if ($wordbooker_post_options['wordbooker_share_button_page']==2 && is_page()) {return ;}
  1553. if (!isset($wordbooker_settings['wordbooker_like_share_too'])) {return ;}
  1554. if (isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() ) {$do_share=1;}
  1555. if (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() ) {$do_share=1;}
  1556. if (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() ) {$do_share=1;}
  1557. if (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ) {$do_share=1;}
  1558. if (isset($wordbooker_settings['wordbooker_no_share_stick']) && is_sticky() ) {$do_share=0; }
  1559. if ( $do_share==1 &&
  1560. ((isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() )
  1561. || (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() )
  1562. || (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() )
  1563. || (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ))
  1564. )
  1565. {
  1566. $post_link = get_permalink($post->ID);
  1567. $btype="button";
  1568. if (is_single() || is_page()) {
  1569. $btype="button_count";
  1570. }
  1571. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1572. $share_code='<!-- Wordbooker created FB tags --> <a name="fb_share" type="'.$btype.'" share_url="'.$post_link.'"></a>';
  1573. }
  1574. else {
  1575. $share_code='<!-- Wordbooker created FB tags --> <fb:share-button class="meta" type="'.$btype.'" href="'.$post_link.'" > </fb:share-button>';
  1576. }
  1577. echo $share_code;
  1578. }
  1579. }
  1580. function wordbooker_fb_share_inline() {
  1581. global $post;
  1582. $wordbooker_settings = wordbooker_options();
  1583. $do_share=0;
  1584. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1585. #var_dump($$wordbooker_settings[);
  1586. if ($wordbooker_post_options['wordbooker_share_button_post']==2 && !is_page()) {return ;}
  1587. if ($wordbooker_post_options['wordbooker_share_button_page']==2 && is_page()) {return ;}
  1588. if (!isset($wordbooker_settings['wordbooker_like_share_too'])) {return ;}
  1589. if (isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() && !is_front_page() ) {$do_share=1;}
  1590. if (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() && !is_front_page() ) {$do_share=1;}
  1591. if (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() ) {$do_share=1;}
  1592. if (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ) {$do_share=1;}
  1593. if (isset($wordbooker_settings['wordbooker_no_share_stick']) && is_sticky() ) {$do_share=0; }
  1594. if ( $do_share==1 &&
  1595. ((isset($wordbooker_settings['wordbooker_share_button_post']) && is_single() )
  1596. || (isset($wordbooker_settings['wordbooker_share_button_page']) && is_page() )
  1597. || (isset($wordbooker_settings['wordbooker_share_button_frontpage']) && is_front_page() )
  1598. || (isset($wordbooker_settings['wordbooker_share_button_category']) && is_category() ))
  1599. )
  1600. {
  1601. $post_link = get_permalink($post->ID);
  1602. $btype="button";
  1603. if (is_single() || is_page()) {
  1604. $btype="button_count";
  1605. }
  1606. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1607. $share_code='<!-- Wordbooker created FB tags --> <a name="fb_share" type="'.$btype.'" share_url="'.$post_link.'"></a>';
  1608. }
  1609. else {
  1610. $share_code='<!-- Wordbooker created FB tags --> <fb:share-button class="meta" type="'.$btype.'" href="'.$post_link.'" > </fb:share-button>';
  1611. }
  1612. return $share_code;
  1613. }
  1614. }
  1615. function display_wordbooker_fb_send() {
  1616. global $post,$q_config;
  1617. $wordbooker_settings = wordbooker_options();
  1618. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1619. $post_link = get_permalink($post->ID);
  1620. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1621. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1622. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true') {return;}
  1623. $do_like=0;
  1624. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1625. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1626. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1627. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1628. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1629. if ( $do_like==1 &&
  1630. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1631. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1632. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1633. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1634. )
  1635. {
  1636. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1637. $px=35;
  1638. $wplang=wordbooker_get_language();
  1639. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=80;}
  1640. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/send.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1641. }
  1642. else {
  1643. #var_dump($wordbooker_settings);
  1644. $like_code='<!-- Wordbooker created FB tags --> <fb:send layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].' "></fb:send> ';}
  1645. echo $like_code;
  1646. }
  1647. }
  1648. function wordbooker_fb_send_inline() {
  1649. global $post;
  1650. $wordbooker_settings = wordbooker_options();
  1651. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1652. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1653. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1654. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true') {return;}
  1655. $post_link = get_permalink($post->ID);
  1656. $do_like=0;
  1657. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1658. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1659. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1660. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1661. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1662. if ( $do_like==1 &&
  1663. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1664. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1665. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1666. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1667. )
  1668. {
  1669. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1670. $px=35;
  1671. $wplang=wordbooker_get_language();
  1672. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=80;}
  1673. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/send.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1674. }
  1675. else {
  1676. #var_dump($wordbooker_settings);
  1677. $like_code='<!-- Wordbooker created FB tags --> <fb:send layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].' "></fb:send> ';}
  1678. return $like_code;
  1679. }
  1680. }
  1681. function display_wordbooker_fb_like() {
  1682. global $post;
  1683. $wordbooker_settings = wordbooker_options();
  1684. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1685. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1686. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1687. if (!isset($wordbooker_settings['wordbooker_like_button_show'])) {return;}
  1688. $do_like=0;
  1689. $post_link = get_permalink($post->ID);
  1690. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1691. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1692. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1693. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1694. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1695. if ( $do_like==1 &&
  1696. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1697. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1698. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1699. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1700. )
  1701. {
  1702. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1703. $px=35;
  1704. $wplang=wordbooker_get_language();
  1705. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=95;}
  1706. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/like.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1707. }
  1708. else {
  1709. #var_dump($wordbooker_settings);
  1710. $like_code='<!-- Wordbooker created FB tags --> <fb:like layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].'" ';
  1711. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true' ) { $like_code.=' send="'.$wordbooker_settings['wordbooker_fblike_send'].'" ';}
  1712. $like_code.='></fb:like> ';}
  1713. echo $like_code;
  1714. }
  1715. }
  1716. function wordbooker_fb_like_inline() {
  1717. global $post;
  1718. $wordbooker_settings = wordbooker_options();
  1719. $wordbooker_post_options= get_post_meta($post->ID, '_wordbooker_options', true);
  1720. if ($wordbooker_post_options['wordbooker_like_button_post']==2 && !is_page()) {return ;}
  1721. if ($wordbooker_post_options['wordbooker_like_button_page']==2 && is_page()) {return ;}
  1722. if (!isset($wordbooker_settings['wordbooker_like_button_show'])) {return;}
  1723. $do_like=0;
  1724. $post_link = get_permalink($post->ID);
  1725. if (isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() && !is_front_page() ) {$do_like=1;}
  1726. if (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() && !is_front_page()) {$do_like=1;}
  1727. if (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() ) {$do_like=1;}
  1728. if (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() && !is_front_page() ) {$do_like=1;}
  1729. if (isset($wordbooker_settings['wordbooker_no_like_stick']) && is_sticky() ) { $do_like=0;}
  1730. if ( $do_like==1 &&
  1731. ((isset($wordbooker_settings['wordbooker_like_button_post']) && is_single() )
  1732. || (isset($wordbooker_settings['wordbooker_like_button_page']) && is_page() )
  1733. || (isset($wordbooker_settings['wordbooker_like_button_frontpage']) && is_front_page() )
  1734. || (isset($wordbooker_settings['wordbooker_like_button_category']) && is_category() ))
  1735. )
  1736. {
  1737. if (isset($wordbooker_settings['wordbooker_iframe'])) {
  1738. $px=35;
  1739. $wplang="en_US";
  1740. if (strlen(WPLANG) > 2) {$wplang=WPLANG;}
  1741. # then we check if WPLANG is actually set to anything sensible.
  1742. if ($wplang=="WPLANG" ) {$wplang="en_US";}
  1743. if ($wordbooker_settings['wordbooker_fblike_faces']=='true') {$px=95;}
  1744. $like_code='<!-- Wordbooker created FB tags --> <iframe src="http://www.facebook.com/plugins/like.php?locale='.$wplang.'&href='.$post_link.'&amp;layout='.$wordbooker_settings['wordbooker_fblike_button'].'&amp;show_faces='.$wordbooker_settings['wordbooker_fblike_faces'].'&amp;width='.$wordbooker_settings["wordbooker_like_width"].'&amp;action='.$wordbooker_settings['wordbooker_fblike_action'].'&amp;colorscheme='.$wordbooker_settings['wordbooker_fblike_colorscheme'].'&amp;font='.$wordbooker_settings['wordbooker_fblike_font'].'&amp;height='.$px.'px" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:'.$wordbooker_settings["wordbooker_like_width"].'px; height:'.$px.'px;" allowTransparency="true"></iframe>';
  1745. }
  1746. else {
  1747. #var_dump($wordbooker_settings);
  1748. $like_code='<!-- Wordbooker created FB tags --> <fb:like layout="'.$wordbooker_settings['wordbooker_fblike_button'] .'" show_faces="'.$wordbooker_settings['wordbooker_fblike_faces'].'" action="'.$wordbooker_settings['wordbooker_fblike_action'].'" font="'.$wordbooker_settings['wordbooker_fblike_font'].'" colorscheme="'.$wordbooker_settings['wordbooker_fblike_colorscheme'].'" href="'.$post_link.'" width="'.$wordbooker_settings["wordbooker_like_width"].'" ';
  1749. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true' ) { $like_code.=' send="'.$wordbooker_settings['wordbooker_fblike_send'].'" ';}
  1750. $like_code.='> </fb:like> ';}
  1751. return $like_code;
  1752. }
  1753. }
  1754. function wordbooker_fb_read_inline() {
  1755. $wordbooker_settings = wordbooker_options();
  1756. if (is_single() && isset($wordbooker_settings['wordbooker_read_button']) ) {
  1757. $read_code='<form><input type="button" value="'.__("Post To Your Timeline ",'wordbooker').'" onclick="wordbooker_read()" /></form>';
  1758. return $read_code;
  1759. }
  1760. }
  1761. function wordbooker_fb_read() {
  1762. $wordbooker_settings = wordbooker_options();
  1763. if (is_single() && isset($wordbooker_settings['wordbooker_read_button']) ) {
  1764. $read_code='<form><input type="button" value="'.__("Post To Your Timeline ",'wordbooker').'" onclick="wordbooker_read()" /></form>';
  1765. echo $read_code;
  1766. }
  1767. }
  1768. #function wordbooker_fb_comment_insert($template){
  1769. # $comment_code=wordbooker_fb_comment(true);
  1770. # if ($template) {echo $comment_code;} else {return $comment_code;}
  1771. #}
  1772. function wordbooker_append_post($post_cont) {
  1773. global $post;
  1774. $do_share=0;
  1775. #var_dump(is_page());var_dump(is_category());var_dump(is_front_page());var_dump(is_single());
  1776. $wordbooker_settings = wordbooker_options();
  1777. if (!isset($wordbooker_settings['wordbooker_like_button_show']) && !isset($wordbooker_settings['wordbooker_like_share_too'])) {return $post_cont;}
  1778. $post_cont2=$post_cont;
  1779. $post_link = get_permalink($post->ID);
  1780. $share_code=wordbooker_fb_share_inline();
  1781. $like_code=wordbooker_fb_like_inline();
  1782. $send_code=wordbooker_fb_send_inline();
  1783. $comment_code=wordbooker_fb_comment_inline();
  1784. $read_code=wordbooker_fb_read_inline();
  1785. if ($wordbooker_settings['wordbooker_fblike_location']!=$wordbooker_settings['wordbooker_fbshare_location']){
  1786. if ($wordbooker_settings['wordbooker_fbshare_location']=='top'){
  1787. $post_cont2= "<div class='wp_fbs_top'>".$share_code."</div>".$post_cont2;
  1788. }
  1789. if ($wordbooker_settings['wordbooker_fbshare_location']=='bottom') {
  1790. $post_cont2=$post_cont2."<div class='wp_fbs_bottom'>".$share_code.'</div>';
  1791. }
  1792. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='true'){
  1793. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1794. $post_cont2= $post_cont2."<div class='wp_fbl_bottom'>".$like_code.'</div>';
  1795. }
  1796. if ($wordbooker_settings['wordbooker_fblike_location']=='top') {
  1797. $post_cont2= "<div class='wp_fbl_top'>".$like_code.'</div>'.$post_cont2;
  1798. }
  1799. }
  1800. } else {
  1801. # if ($wordbooker_settings['wordbooker_fblike_location']==$wordbooker_settings['wordbooker_fbshare_location']){
  1802. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1803. $post_cont2=$post_cont2."<div class='wb_fb_bottom'>".$like_code.'<div style="float:right;">'.$share_code.'</div></div>';
  1804. }
  1805. if ($wordbooker_settings['wordbooker_fblike_location']=='top'){
  1806. $post_cont2= "<div class='wb_fb_top'>".$like_code.'<div style="float:right;">'.$share_code.'</div></div>'.$post_cont2;
  1807. }
  1808. #}
  1809. #}
  1810. }
  1811. if ($wordbooker_settings['wordbooker_fblike_send_combi']=='false' && $wordbooker_settings['wordbooker_fblike_send']=='true' ){
  1812. if ($wordbooker_settings['wordbooker_fblike_location']==$wordbooker_settings['wordbooker_fbshare_location']){
  1813. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1814. $post_cont2=$post_cont2."<div class='wb_fb_bottom'>".$send_code.'<div style="float:right;">'.$share_code.'</div></div>';
  1815. }
  1816. if ($wordbooker_settings['wordbooker_fblike_location']=='top'){
  1817. $post_cont2= "<div class='wb_fb_top'>".$send_code.'<div style="float:right;">'.$share_code.'</div></div>'.$post_cont;
  1818. }
  1819. } else {
  1820. if ($wordbooker_settings['wordbooker_fblike_location']=='bottom'){
  1821. $post_cont2= $post_cont2."<div class='wp_fbl_bottom'>".$send_code.'</div>';
  1822. }
  1823. if ($wordbooker_settings['wordbooker_fblike_location']=='top') {
  1824. $post_cont2= "<div class='wp_fbl_top'>".$send_code.'</div>'.$post_cont2;
  1825. }
  1826. }
  1827. }
  1828. /*
  1829. if ($wordbooker_settings['wordbooker_fbread_location']=='top'){
  1830. $post_cont2= "<div class='wp_fbr_top'>".$read_code."</div>".$post_cont2;
  1831. }
  1832. if ($wordbooker_settings['wordbooker_fbread_location']=='bottom') {
  1833. $post_cont2=$post_cont2."<div class='wp_fbr_bottom'>".$read_code.'</div>';
  1834. }
  1835. */
  1836. if ($wordbooker_settings['wordbooker_comment_location']=='bottom') { $post_cont2=$post_cont2."<div class='wb_fb_comment'><br/>".$comment_code."</div>"; }
  1837. return $post_cont2;
  1838. }
  1839. function wordbooker_get_cache($user_id,$field=null,$table=0) {
  1840. global $wpdb,$blog_id;
  1841. #$blog_id=1;
  1842. if (!isset($user_id)) {return;}
  1843. $tname=WORDBOOKER_USERSTATUS;
  1844. $query_fields='facebook_id,name,url,pic,status,updated,facebook_id';
  1845. $blog_lim=' and blog_id='.$blog_id;
  1846. if ($table==1) {$tname=WORDBOOKER_USERDATA;$query_fields='facebook_id,name,url,pic,status,updated,auths_needed,use_facebook';$blog_lim='';}
  1847. if (isset($field)) {$query_fields=$field;}
  1848. if ($user_id==-99){
  1849. $query="select ".$query_fields." from ".$tname." where blog_id = ".$blog_id;
  1850. # var_dump($query);
  1851. $result = $wpdb->get_results($query,ARRAY_N );
  1852. foreach($result as $key){ $newkey[]=$key[0];}
  1853. $result = implode(",",$newkey);
  1854. }
  1855. else {
  1856. $query="select ".$query_fields." from ".$tname." where user_ID=".$user_id.$blog_lim;
  1857. # var_dump($query);
  1858. $result = $wpdb->get_row($query); }
  1859. return $result;
  1860. }
  1861. function wordbooker_check_permissions($wbuser,$user) {
  1862. global $user_ID;
  1863. $perm_miss=wordbooker_get_cache($user_ID,'auths_needed',1);
  1864. if ($perm_miss->auths_needed==0) { return;}
  1865. $perms_to_check= array(WORDBOOKER_FB_PUBLISH_STREAM,WORDBOOKER_FB_STATUS_UPDATE,WORDBOOKER_FB_READ_STREAM,WORDBOOKER_FB_CREATE_NOTE,WORDBOOKER_FB_PHOTO_UPLOAD,WORDBOOKER_FB_VIDEO_UPLOAD,WORDBOOKER_FB_MANAGE_PAGES,WORDBOOKER_FB_READ_FRIENDS);
  1866. $perm_messages= array( __('Publish content to your Wall/Fan pages', 'wordbooker'), __('Update your status', 'wordbooker'), __('Read your News Feed and Wall', 'wordbooker'),__('Create notes', 'wordbooker'),__('Upload photos', 'wordbooker'),__('Upload videos', 'wordbooker'),__('Manage_pages', 'wordbooker'),__('Read friend lists', 'wordbooker'));
  1867. $preamble= __("but requires authorization to ", 'wordbooker');
  1868. $postamble= __(" on Facebook. Click on the following link to grant permission", 'wordbooker');
  1869. $loginUrl2='https://www.facebook.com/dialog/oauth?client_id='.WORDBOOKER_FB_ID.'&redirect_uri=https://wordbooker.tty.org.uk/index2.html?br='.urlencode(get_bloginfo('wpurl')).'&scope='.implode(',',$perms_to_check).'&response_type=token';
  1870. if(is_array($perms_to_check)) {
  1871. foreach(array_keys($perms_to_check) as $key){
  1872. # Bit map check to put out the right text for the missing permissions.
  1873. if (pow(2,$key) & $perm_miss->auths_needed ) {
  1874. $midamble.=$perm_messages[$key].", ";
  1875. }
  1876. }
  1877. $midamble=rtrim($midamble,",");
  1878. $midamble=trim(preg_replace("/(.*?)((,|\s)*)$/m", "$1", $midamble));
  1879. $midamble=substr_replace($midamble, " and ", strrpos($midamble, ","), strlen(","));
  1880. echo " ".$preamble.$midamble.$postamble.'</p><div style="text-align: center;"><a href="'.$loginUrl2.'" > <img src="http://static.ak.facebook.com/images/devsite/facebook_login.gif" alt="Facebook Login Button" /></a><br /></div>';
  1881. }
  1882. echo "and then save your settings<br />";
  1883. echo '<form action="'.WORDBOOKER_SETTINGS_URL.'" method="post"> <input type="hidden" name="action" value="" />';
  1884. echo '<p style="text-align: center;"><input type="submit" name="perm_save" class="button-primary" value="'. __('Save Configuration', 'wordbooker').'" /></p></form>';
  1885. }
  1886. function wordbooker_contributed($url=0) {
  1887. global $user_ID;
  1888. if ($url==0){
  1889. $contributors=array('1595132200','100000818019269','39203171','666800299','500073624','711830142','503549492','100000589976474','254577506873','1567300610','701738627','100000442094620','754015348','29404010','748636937',
  1890. '676888540','768354692','1607820784','1709067850','769804853','100001597808077','1162591229','736138968','532656880','1000013707847','1352285955','836328641',
  1891. '23010694256','129976890383044','679511648','100001305747796','138561766210548','535106029','202891313077099','567894174','10150158518404391','689075829','214145618608444',
  1892. '23087261000','195010903860640'
  1893. );
  1894. $facebook_id=wordbooker_get_cache($user_ID,'facebook_id');
  1895. return in_array($facebook_id->facebook_id,$contributors);
  1896. }
  1897. if ($url==1){
  1898. $blogs=array(
  1899. "Steve's Blog"=>'blogs.canalplan.org.uk/steve',"Powered by Dan!"=>'dangarion.com',"Kathryn's Comments"=>'www.kathrynhuxtable.org/blog',"Luke Writes"=>'www.lukewrites.com',
  1900. "It's Nature"=>'www.itsnature.org',"Eat in OC"=>'eatinoc.com',"Christian Albert Muller"=>'christian-albert-mueller.com/blog/',"[overcrooked|de]"=>'blog.overcrooked.de/',
  1901. "Jesus is My Buddy"=>'www.jesusismybuddy.com',"Shirts of Bamboo"=>'www.shirtsofbamboo.com', "What's that bug?"=>'www.whatsthatbug.com',"Philip Bussman"=>'www.philipbussmann.com',
  1902. "PhantaNews"=>'phantanews.de/wp/', "HKMacs"=>'hkmacs.com/Blog', "Techerator"=>'www.techerator.com', "Mosalar.com"=>'www.mosalar.com/',
  1903. "Nono & His Self-Centered Universe"=>'www.noelacosta.com/',"Chart Porn"=>'www.chartporn.org',"Pawesome"=>'www.pawesome.net',"Margaret & Ian's Website"=>'www.margaretandian.com/',
  1904. "The GBMINI website"=>'www.gbmini.net',"Roca"=>'rocamusic.ca/home',"Drew Rozell"=>'www.drewrozell.com/',"Kartext"=>'www.nitsche.org/',
  1905. "Doug Berch - Musician and Appalachian Mountain Dulcimer Maker"=>'dougberch.com',"My Lifestyle Blog"=>'www.mylifestyleblog.de',
  1906. "tina rawatta photography" => 'www.tinarawatta.com',"Gary Said..."=>'GarySaid.com',"Bachateros Online Magazine"=>'www.bachateros.com.au/',"Linh's e-place"=>'www.linh.se',
  1907. "InkMusings" => 'www.inkmusings.com',"JĂźrgen Koller's website"=>'www.kollermedia.at',"Walk With Ben"=>'www.walkwithben.com',"GardenFork"=>'www.http://www.gardenfork.tv/',
  1908. "A Low Man's Lyric"=>'vivekiyer.net/',"OutofRange.net"=>'www.outofrange.net/',"This Ambitious Orchestra"=>'ambitiousorchestra.com',"Lydia Salnikova"=>'www.lydiasalnikova.com/',
  1909. "Westpark Gamers"=>'www.westpark-gamers.de/', "The Camera Zealot"=>'www.camerazealot.com', " Best Raw Organic" => 'BestRawOrganic.com',"Gibson Designs"=>'gibsondesigns.net',
  1910. "Looking out from Under"=>'www.lookingoutfromunder.com',"Our Excellent Adventures"=>'www.ourexcellentadventures.com',
  1911. "wisiwi.com - Das Magazin fĂźr Unternehmer"=>'www.wisiwi.com/',"Just One Cookbook"=>'justonecookbook.com/blog/',"Surfdog 2011"=>'hastenteufel.name/blog',
  1912. "Vice Versa Advertising Photography"=>'www.viceversa.gr/',"Swimming Pools Designs"=>'www.swimming-pools-designs.com',"Eastleigh District Scouts"=>'www.eastleigh-scouts.org.uk',"Sparkpr"=>'www.sparkpr.com',"Charlie Glickman - Adult Sexuality Education"=>'www.charlieglickman.com/',"iEatAtTheBar"=>'www.ieatatthebar.com/',"Devil's Cove | Boats, Booze & Fun on Lake Travis"=>'http://www.devilscove.com/',"Bored. Cure your boredom!"=>'bored.overnow.com/',"KinkyThought"=>'kinkythought.com/',
  1913. "The Chronicles of Mommia"=>'www.thechroniclesofmommia.com/',"Total Humour"=>'www.totalhumour.com/',"Six Seconds"=>'www.6seconds.org/',"The APBA Blog"=>'www.apbablog.com',"The Doc is In"=>'www.thedocisin.net'
  1914. );
  1915. $keys = array_keys($blogs);
  1916. shuffle($keys);
  1917. foreach ( $keys as $key) {
  1918. echo "<a href='http://".htmlspecialchars($blogs[$key])."' target='_new'>".htmlspecialchars($key)."</a>,&nbsp;";
  1919. }
  1920. # And then put canalplan on the end of it - saves us having to do clever things to remove commas
  1921. echo "<a href='http://www.canalplan.org.uk/' target='_new' >CanalPlan AC</a><br />";
  1922. }
  1923. }
  1924. /******************************************************************************
  1925. * WordPress hooks: update Facebook when a blog entry gets published.
  1926. */
  1927. function wordbooker_remove_HTML($s , $keep = '' , $expand = 'script|style|noframes|select|option'){
  1928. /**///prep the string
  1929. $s = ' ' . $s;
  1930. /**///initialize keep tag logic
  1931. if(strlen($keep) > 0){
  1932. $k = explode('|',$keep);
  1933. for($i=0;$i<count($k);$i++){
  1934. $s = str_replace('<' . $k[$i],'[{(' . $k[$i],$s);
  1935. $s = str_replace('</' . $k[$i],'[{(/' . $k[$i],$s);
  1936. }
  1937. }
  1938. //begin removal
  1939. /**///remove comment blocks
  1940. while(stripos($s,'<!--') > 0){
  1941. $pos[1] = stripos($s,'<!--');
  1942. $pos[2] = stripos($s,'-->', $pos[1]);
  1943. $len[1] = $pos[2] - $pos[1] + 3;
  1944. $x = substr($s,$pos[1],$len[1]);
  1945. $s = str_replace($x,'',$s);
  1946. }
  1947. /**///remove tags with content between them
  1948. if(strlen($expand) > 0){
  1949. $e = explode('|',$expand);
  1950. for($i=0;$i<count($e);$i++){
  1951. while(stripos($s,'<' . $e[$i]) > 0){
  1952. $len[1] = strlen('<' . $e[$i]);
  1953. $pos[1] = stripos($s,'<' . $e[$i]);
  1954. $pos[2] = stripos($s,$e[$i] . '>', $pos[1] + $len[1]);
  1955. $len[2] = $pos[2] - $pos[1] + $len[1];
  1956. $x = substr($s,$pos[1],$len[2]);
  1957. $s = str_replace($x,'',$s);
  1958. }
  1959. }
  1960. }
  1961. /**///remove remaining tags
  1962. while(stripos($s,'<') > 0){
  1963. $pos[1] = stripos($s,'<');
  1964. $pos[2] = stripos($s,'>', $pos[1]);
  1965. $len[1] = $pos[2] - $pos[1] + 1;
  1966. $x = substr($s,$pos[1],$len[1]);
  1967. $s = str_replace($x,'',$s);
  1968. }
  1969. /**///finalize keep tag
  1970. for($i=0;$i<count($k);$i++){
  1971. $s = str_replace('[{(' . $k[$i],'<' . $k[$i],$s);
  1972. $s = str_replace('[{(/' . $k[$i],'</' . $k[$i],$s);
  1973. }
  1974. return trim($s);
  1975. }
  1976. function wordbooker_post_excerpt($excerpt, $maxlength,$doyoutube=1) {
  1977. if (function_exists('strip_shortcodes')) {
  1978. $excerpt = strip_shortcodes($excerpt);
  1979. }
  1980. global $wordbooker_post_options;
  1981. if (!isset($maxlength)) {$maxlength=$wordbooker_post_options['wordbooker_extract_length'];}
  1982. if (!isset($maxlength)) {$maxlength=256;}
  1983. $excerpt = trim($excerpt);
  1984. # Now lets strip any tags which dont have balanced ends
  1985. # Need to put NGgallery tags in there - there are a lot of them and they are all different.
  1986. $open_tags="[simage,[[CP,[gallery,[imagebrowser,[slideshow,[tags,[albumtags,[singlepic,[album";
  1987. $close_tags="],]],],],],],],],]";
  1988. $open_tag=explode(",",$open_tags);
  1989. $close_tag=explode(",",$close_tags);
  1990. foreach (array_keys($open_tag) as $key) {
  1991. if (preg_match_all('/' . preg_quote($open_tag[$key]) . '(.*?)' . preg_quote($close_tag[$key]) .'/i',$excerpt,$matches)) {
  1992. $excerpt=str_replace($matches[0],"" , $excerpt);
  1993. }
  1994. }
  1995. $excerpt = preg_replace('#(<wpg.*?>).*?(</wpg2>)#', '$1$2', $excerpt);
  1996. $excerpt=wordbooker_translate($excerpt);
  1997. $excerpt = strip_tags($excerpt);
  1998. # Now lets strip off the youtube stuff.
  1999. preg_match_all( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=)([\w-]+)(.*?)player_embedded#i', $excerpt, $matches );
  2000. $excerpt=str_replace($matches[0],"" , $excerpt);
  2001. preg_match_all( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=|embed/)([\w-]+)(.*?)#i', $excerpt, $matches );
  2002. $excerpt=str_replace($matches[0],"" , $excerpt);
  2003. $excerpt = apply_filters('wordbooker_post_excerpt', $excerpt);
  2004. if (strlen($excerpt) > $maxlength) {
  2005. # If we've got multibyte support then we need to make sure we get the right length - Thanks to Kensuke Akai for the fix
  2006. if(function_exists('mb_strimwidth')){$excerpt=mb_strimwidth($excerpt, 0, $maxlength, " ...");}
  2007. else { $excerpt=current(explode("SJA26666AJS", wordwrap($excerpt, $maxlength, "SJA26666AJS")))." ...";}
  2008. }
  2009. return $excerpt;
  2010. }
  2011. function wordbooker_translate($text) {
  2012. if (function_exists('qtrans_use')) {
  2013. global $q_config;
  2014. $text=qtrans_use($q_config['language'],$text);
  2015. }
  2016. return $text;
  2017. }
  2018. function wordbooker_publish_action($post_id) {
  2019. global $user_ID, $user_identity, $user_login, $wpdb,$wordbooker_post_options,$blog_id,$doing_post;
  2020. if(isset($doing_post)) {wordbooker_debugger("Looks like we've already got a post going on so we can give up","",$post_id,99) ; return;}
  2021. $doing_post="running";
  2022. $x = get_post_meta($post_id, '_wordbooker_options', true);
  2023. $post=get_post($post_id);
  2024. # Get the settings from the post_meta.
  2025. if (is_array($x)){
  2026. foreach (array_keys($x) as $key ) {
  2027. if (substr($key,0,8)=='wordbook') {
  2028. $wordbooker_post_options[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$x[$key]);
  2029. }
  2030. }
  2031. }
  2032. if (is_array($wordbooker_post_options)){
  2033. foreach (array_keys($wordbooker_post_options) as $key){
  2034. wordbooker_debugger("Post option : ".$key,$wordbooker_post_options[$key],$post->ID) ;
  2035. }
  2036. }
  2037. if ($wordbooker_post_options["wordbooker_publish_default"]=="200") { $wordbooker_post_options["wordbooker_publish_default"]='on';}
  2038. # If the user_ID is set then lets use that, if not get the user_id from the post
  2039. $whichuser=$post->post_author;
  2040. if ($user_ID >=1) {$whichuser=$user_ID;}
  2041. # If the default user is set to 0 then we use the current user (or the author of the post if that isn't set - i.e. if this is a scheduled post)
  2042. if ($wordbooker_post_options["wordbooker_default_author"] == 0 ) {$wpuserid=$whichuser;} else {$wpuserid=$wordbooker_post_options["wordbooker_default_author"];}
  2043. if ($wordbooker_post_options["wordbooker_publish_default"]!="on") {
  2044. wordbooker_debugger("Publish Default is not Set, Giving up ",$wpuserid,$post->ID) ;
  2045. return;
  2046. }
  2047. wordbooker_debugger("User has been set to : ",$wpuserid,$post->ID) ;
  2048. #if (!($wbuser = wordbooker_get_userdata($wpuserid)) || !$wbuser->access_token) {
  2049. if (!$wbuser = wordbooker_get_userdata($wpuserid) ) {
  2050. wordbooker_debugger("Unable to get FB session for : ",$wpuserid,$post->ID) ;
  2051. return 28;
  2052. }
  2053. wordbooker_debugger("Posting as user : ",$wpuserid,$post->ID) ;
  2054. wordbooker_debugger("Calling wordbooker_fbclient_publishaction"," ",$post->ID) ;
  2055. wordbooker_fbclient_publishaction($wbuser, $post->ID);
  2056. unset($doing_post);
  2057. return 30;
  2058. }
  2059. /*
  2060. function wordbooker_transition_post_status($newstatus, $oldstatus, $post_id) {
  2061. if ($newstatus == 'publish') {
  2062. return wordbooker_publish_action($post_id);
  2063. }
  2064. return 31;
  2065. }
  2066. */
  2067. function wordbooker_delete_post($post_id) {
  2068. global $blog_id;
  2069. wordbooker_delete_from_errorlogs($post_id,$blog_id);
  2070. wordbooker_delete_from_postlogs($post_id,$blog_id);
  2071. wordbooker_delete_from_commentlogs($post_id,$blog_id);
  2072. }
  2073. function wordbooker_process_post_queue($post_id) {
  2074. global $wpdb,$blog_id;
  2075. # We need to get the lowest post_id from the post_queue which has the lowest priority ID
  2076. }
  2077. function wordbooker_process_post_data($newstatus, $oldstatus, $post) {
  2078. global $user_ID, $user_identity, $user_login, $wpdb, $blog_id;
  2079. # If this is an autosave then we give up and return as otherwise we lose user settings.
  2080. if ($_POST['action']=='autosave') { return;}
  2081. if ($_POST['action']=='editpost') {
  2082. foreach (array_keys($_POST) as $key ) {
  2083. if (substr($key,0,8)=='wordbook') {
  2084. $wordbooker_sets[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$_POST[$key]);
  2085. }
  2086. }
  2087. #var_dump($wordbooker_sets);
  2088. #var_dump($post->ID);
  2089. update_post_meta($post->ID, '_wordbooker_options', $wordbooker_sets);
  2090. }
  2091. if (!$newstatus=="publish") { return;}
  2092. # If this is a password protected post we give up
  2093. if ($post->post_password != '') {return;}
  2094. # Check for non public custom post types.
  2095. if ( $post->post_status == 'publish' && $post->post_type != 'post' ) {
  2096. $post_type_info = get_post_type_object( $post->post_type );
  2097. if ( $post_type_info && !$post_type_info->public ) { return; }
  2098. }
  2099. # Has this been fired by a post revision rather than a proper publish
  2100. if (wp_is_post_revision($post->ID)) {return;}
  2101. $wordbooker_settings=wordbooker_options();
  2102. $wb_params = get_post_meta($post->ID, '_wordbooker_options', true);
  2103. if (! wordbooker_get_userdata($post->post_author)) { $wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2104. if ($wordbooker_settings["wordbooker_default_author"] == 0 ) {$wb_user_id=$post->post_author;} else {$wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2105. if ( (!is_array($wb_params)) &&((stripos($_POST["_wp_http_referer"],'press-this')) || ( stripos($_POST["_wp_http_referer"],'index.php')) || (!isset($_POST['wordbooker_post_edited']) )) ) {
  2106. wordbooker_debugger("Inside the press this / quick press / remote client block "," ",$post->ID) ;
  2107. # Get the default publish setting for the post type
  2108. if($post->post_type=='page'){
  2109. $publish=$wordbooker_settings["wordbooker_publish_page_default"];
  2110. }
  2111. else {
  2112. $publish=$wordbooker_settings["wordbooker_publish_post_default"];
  2113. }
  2114. # New get the user level settings from the DB
  2115. $wordbooker_user_settings_id="wordbookuser".$blog_id;
  2116. $wordbookuser=get_usermeta($wb_user_id,$wordbooker_user_settings_id);
  2117. # If we have user settings then lets go through and override the blog level defaults.
  2118. if(is_array($wordbookuser)) {
  2119. foreach (array_keys($wordbookuser) as $key) {
  2120. if ((strlen($wordbookuser[$key])>0) && ($wordbookuser[$key]!="0") ) {
  2121. # wordbooker_debugger("replacing ".$key." - ".$wordbooker_settings[$key]." with ",$wordbookuser[$key],$post->ID) ;
  2122. $wordbooker_settings[$key]=$wordbookuser[$key];
  2123. }
  2124. }
  2125. }
  2126. $wordbooker_settings['wordbooker_publish_default']=$publish;
  2127. # Then populate the post array.
  2128. if (is_array($wordbooker_settings)) {
  2129. foreach (array_keys($wordbooker_settings) as $key ) {
  2130. if (substr($key,0,8)=='wordbook') {
  2131. $_POST[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$wordbooker_settings[$key]);
  2132. }
  2133. }
  2134. }
  2135. }
  2136. if ( !wordbooker_get_userdata($user_ID)) {
  2137. $wb_user_id=$wordbooker_settings["wordbooker_default_author"];
  2138. # New get the user level settings from the DB
  2139. $wordbooker_user_settings_id="wordbookuser".$blog_id;
  2140. $wordbookuser=get_usermeta($wb_user_id,$wordbooker_user_settings_id);
  2141. # If we have user settings then lets go through and override the blog level defaults.
  2142. if(is_array($wordbookuser)) {
  2143. foreach (array_keys($wordbookuser) as $key) {
  2144. if ((strlen($wordbookuser[$key])>0) && ($wordbookuser[$key]!="0") ) {
  2145. $wordbooker_settings[$key]=$wordbookuser[$key];
  2146. }
  2147. }
  2148. }
  2149. # Then populate the post array.
  2150. if(is_array($wordbooker_settings)) {
  2151. foreach (array_keys($wordbooker_settings) as $key ) {
  2152. if (substr($key,0,8)=='wordbook') {
  2153. if (!isset($_POST[$key])){$_POST[$key]=str_replace( array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),array('&','"','\'','<','>',"\t"),$wordbooker_settings[$key]);}
  2154. }
  2155. }
  2156. }
  2157. }
  2158. # OK now lets get the settings from the POST array
  2159. foreach (array_keys($_POST) as $key ) {
  2160. if (substr($key,0,8)=='wordbook') {
  2161. $wb_params[$key]=str_replace(array('&','"','\'','<','>',"\t",), array('&amp;','&quot;','&#039;','&lt;','&gt;','&nbsp;&nbsp;'),$_POST[$key]);
  2162. }
  2163. }
  2164. if ($newstatus=="future") {
  2165. $wb_params['wordbooker_scheduled_post']=1;
  2166. wordbooker_debugger("This looks like a post that is scheduled for future publishing",$newstatus,$post->ID,99);
  2167. }
  2168. if ($newstatus=="publish" && (!isset($oldstatus) || $oldstatus!="publish") ) {
  2169. wordbooker_debugger("This looks like a new post being published ",$newstatus,$post->ID,99) ;
  2170. $wb_params['wordbooker_new_post']=1;
  2171. }
  2172. update_post_meta($post->ID, '_wordbooker_options', $wb_params);
  2173. if ($newstatus=="publish") {
  2174. wordbooker_debugger("Calling Wordbooker publishing function",' ',$post->ID,99) ;
  2175. wordbooker_publish($post->ID);
  2176. }
  2177. }
  2178. function wordbooker_publish($post_id) {
  2179. global $user_ID, $user_identity, $user_login, $wpdb, $blog_id,$wordbooker_settings;
  2180. $post = get_post($post_id);
  2181. # If its less than 10 seconds since we saw this post last we give up
  2182. #$ts=wordbooker_postlogged($post_id,1);
  2183. #var_dump($ts);
  2184. #if (isset($ts) && $ts<=60 && $ts>1) {wordbooker_debugger("Publish hook re-fire, ignoring ",$ts,$post_id,99) ; return;}
  2185. # Clear down the error / diagnostic logs for this post.
  2186. #wordbooker_deletefrom_errorlogs($post_id);
  2187. if ((isset($user_ID) && $user_ID>0) && (!current_user_can(WORDBOOKER_MINIMUM_ADMIN_LEVEL))) { wordbooker_debugger("This user doesn't have enough rights"," ",$post_id,99) ; return; }
  2188. wordbooker_debugger("Commence Publish "," ",$post_id,99) ;
  2189. $wb_params = get_post_meta($post_id, '_wordbooker_options', true);
  2190. $wordbooker_settings = wordbooker_options();
  2191. # If there is no user row for this user then set the user id to the default author. If the default author is set to 0 (i.e current logged in user) then only blog level settings apply.
  2192. if (! wordbooker_get_userdata($post->post_author)) { $wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2193. if ($wordbooker_settings["wordbooker_default_author"] == 0 ) {$wb_user_id=$post->post_author;} else {$wb_user_id=$wordbooker_settings["wordbooker_default_author"];}
  2194. # If we've no FB user associated with this ID and the blog owner hasn't overridden then we give up.
  2195. if ((! wordbooker_get_userdata($post->post_author)) && ( !isset($wordbooker_settings['wordbooker_publish_no_user']))) { wordbooker_debugger("Not a WB user (".$post->post_author.") and no overide - give up "," ",$post_id,99) ; return;}
  2196. if ((! wordbooker_get_userdata($wb_user_id)) && ( !isset($wordbooker_settings['wordbooker_publish_no_user']))) {wordbooker_debugger("Author (".$post->post_author.") not a WB user and no overide- give up "," ",$post_id,99) ; return;}
  2197. #}
  2198. if ($_POST["wordbooker_default_author"]== 0 ) { wordbooker_debugger("Author of this post is the Post Author"," ",$post->ID,99); $_POST["wordbooker_default_author"]=$post->post_author; }
  2199. // If soupy isn't set then its either a future post or a post inherting another users options so we need to get the meta data rather than rely on post data
  2200. wordbooker_debugger("Options Set - call transition "," ",$post_id) ;
  2201. $retcode=wordbooker_publish_action($post_id);
  2202. return $retcode;
  2203. }
  2204. function wordbooker_publish_remote($post_id) {
  2205. global $blog_id;
  2206. $post = get_post($post_id);
  2207. wordbooker_debugger("Commence Remote publish "," ",$post->ID,99) ;
  2208. $wordbooker_settings = wordbooker_options();
  2209. }
  2210. function wordbooker_post_comment($commentid) {
  2211. $wordbooker_settings = wordbooker_options();
  2212. if ( !isset($wordbooker_settings['wordbooker_comment_push'])) {
  2213. return;
  2214. }
  2215. global $wpdb, $user_id,$table_prefix;
  2216. $comment= get_comment($commentid);
  2217. $cpid = $comment->comment_post_ID;
  2218. $cstatus=$comment->comment_approved;
  2219. $ctext=$comment->comment_content;
  2220. $caemail=$comment->comment_author_email;
  2221. $cauth=$comment->comment_author;
  2222. $cuid=$comment->user_id;
  2223. $real_comment=true;
  2224. wordbooker_debugger("Start Comment Push "," ",$cpid) ;
  2225. #if (($cuid==0) && ($caemail==$wordbooker_settings['wordbooker_comment_email'])) {$real_comment=false;}
  2226. if ($cuid==0) {$real_comment=false;}
  2227. #if ($ctype=='Facebook Comment') {$real_comment=false;}
  2228. if ($real_comment) {
  2229. if ($cstatus==1) {
  2230. $post = get_post($cpid);
  2231. $ctextblock = <<<CODEBLOX
  2232. Name : $cauth
  2233. Comment: [from blog ] : $ctext
  2234. CODEBLOX;
  2235. if (($wbuser = wordbooker_get_userdata($post->post_author)) && $wbuser->access_token) {
  2236. #$fbclient = wordbooker_fbclient($wbuser);
  2237. # WE NEED TO CHECK THAT THE FB POST ACTUALLY EXISTS BEFORE WE POST OR it blows up.
  2238. $sql='Select fb_post_id from ' . WORDBOOKER_POSTCOMMENTS . ' where wp_post_id ='.$cpid;
  2239. $rows = $wpdb->get_results($sql);
  2240. wordbooker_debugger("Comment count: ",count($rows),$cpid,0) ;
  2241. if (count($rows)>0) {
  2242. foreach ($rows as $comdata_row) {
  2243. $fb_post_id=$comdata_row->fb_post_id;
  2244. # @param string $xid external id associated with the comments
  2245. #@param string $text text of the comment
  2246. # @param int $uid user adding the comment (def: session user)
  2247. # @param string $title optional title for the stream story
  2248. # @param string $url optional url for the stream story
  2249. # @param bool $publish_to_stream publish a feed story about this comment?
  2250. # a link will be generated to title/url in the story
  2251. #$result2=$fbclient->comments_add('100000384338372_105295439493267', $ctextblock.' ');
  2252. # This returns the comment ID so we should store this as a "made" comment for the post in question so we can exclude it when pulling comments down from facebook.
  2253. try {
  2254. $result2=$fbclient->stream_addComment($fb_post_id , $ctextblock.' ');
  2255. wordbooker_debugger("Comment Posted : ",$result2,$cpid,0) ;
  2256. }
  2257. catch (Exception $e) {
  2258. $error_code = $e->getCode();
  2259. $error_msg = $e->getMessage();
  2260. wordbooker_debugger("Comment Push Error : ",$error_msg,$cpid,99) ;
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. }
  2267. }
  2268. function wordbooker_debugger($method,$error_msg,$post_id,$level=9) {
  2269. global $user_ID,$post_ID,$wpdb,$blog_id,$post,$wbooker_user_id;
  2270. if (isset($post_id)){
  2271. $p=get_post($post_id);
  2272. #we dont want to record anything if its an draft of any kind
  2273. if (stristr($p->post_status,'draft')) {return;}
  2274. }
  2275. $usid=1;
  2276. $row_id=1;
  2277. if (!isset($post_id)) {$post_id=$post_ID;}
  2278. if (!isset($post_id)) {$post_id=1;}
  2279. if (isset($user_ID)) {$usid=$user_ID;}
  2280. if ($usid==0) {$usid=$wbooker_user_id;}
  2281. if (!isset($usid)) {$usid=wordbooker_get_option('wordbooker_default_author');}
  2282. if (!isset($usid)) {$usid=1;}
  2283. $sql= "INSERT INTO " . WORDBOOKER_ERRORLOGS . " (
  2284. user_id
  2285. , method
  2286. , error_code
  2287. , error_msg
  2288. , post_id
  2289. , blog_id
  2290. , diag_level
  2291. ) VALUES (
  2292. " . $usid . "
  2293. , '" . mysql_real_escape_string($method) . "'
  2294. , $row_id
  2295. , '" . mysql_real_escape_string($error_msg) . "'
  2296. , " . $post_id . "
  2297. , " . $blog_id ."
  2298. , " . $level ."
  2299. )";
  2300. $result = $wpdb->query($sql);
  2301. }
  2302. /******************************************************************************
  2303. * Register hooks with WordPress.
  2304. */
  2305. /* Plugin maintenance. */
  2306. register_activation_hook(__FILE__, 'wordbooker_activate');
  2307. # When a user is deleted from the blog we should clear down everything they've done in Wordbooker.
  2308. add_action('delete_user', 'wordbooker_remove_user');
  2309. add_action ('init', 'wordbooker_init');
  2310. function wordbooker_init () {
  2311. #load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) )
  2312. #$plugin_dir = basename(dirname(__FILE__));
  2313. load_plugin_textdomain ('wordbooker',false,basename(dirname(__FILE__)).'/languages');
  2314. }
  2315. function wordbooker_schema($attr) {
  2316. $attr .= " xmlns:fb=\"http://www.facebook.com/2008/fbml\" xmlns:og=\"http://opengraphprotocol.org/schema/\" ";
  2317. return $attr;
  2318. }
  2319. function wordbooker_get_avatar($avatar, $id_or_email, $size, $default, $alt){
  2320. //$avatar format includes the tag <img>
  2321. $imgpath = "http://website.com/image/myownimage.jpg";
  2322. $my_avatar = "<img src='".$path."' alt='".$alt."' height='".$size."' width='".$size."' />";
  2323. return $my_avatar;
  2324. }
  2325. function wordbooker_custom_cron_schedules($schedules){
  2326. $schedules['10mins'] = array(
  2327. 'interval' => 600,
  2328. 'display' => __('Every 10 Minutes', 'wordbooker'),
  2329. );
  2330. $schedules['15mins'] = array(
  2331. 'interval' => 900,
  2332. 'display' => __('Every 15 Minutes', 'wordbooker'),
  2333. );
  2334. $schedules['20mins'] = array(
  2335. 'interval' => 1200,
  2336. 'display' => __('Every 20 Minutes', 'wordbooker'),
  2337. );
  2338. $schedules['30mins'] = array(
  2339. 'interval' => 1800,
  2340. 'display' => __('Every 30 Minutes', 'wordbooker'),
  2341. );
  2342. $schedules['45mins'] = array(
  2343. 'interval' => 2700,
  2344. 'display' => __('Every 45 Minutes', 'wordbooker'),
  2345. );
  2346. $schedules['2hours'] = array(
  2347. 'interval' => 7200,
  2348. 'display' => __('Every 2 Hours', 'wordbooker'),
  2349. );
  2350. return array_merge($schedules);
  2351. }
  2352. /* Post/page maintenance and publishing hooks. */
  2353. $wordbooker_disabled=wordbooker_get_option('wordbooker_disabled');
  2354. # If they've disabled Wordbooker then we don't need any of these
  2355. if (!isset($wordbooker_disabled)){
  2356. #add_action('xmlrpc_publish_post', 'wordbooker_publish_remote',20);
  2357. add_action('transition_post_status', 'wordbooker_process_post_data',10,3);
  2358. add_action('delete_post', 'wordbooker_delete_post');
  2359. add_action('wb_cron_job', 'wordbooker_poll_facebook');
  2360. add_action('delete_post', 'wordbooker_delete_post');
  2361. #add_action('comment_post', 'wordbooker_post_comment');
  2362. add_action('wp_head', 'wordbooker_header');
  2363. add_action('wp_footer', 'wordbooker_footer');
  2364. add_filter('language_attributes', 'wordbooker_schema');
  2365. #add_filter('get_avatar','wordbooker_get_avatar');
  2366. #add_action('comment_post', 'wordbooker_post_comment', 20);
  2367. #add_action('wp_set_comment_status', 'wordbooker_set_comment_status', 20, 2);
  2368. add_filter('the_content', 'wordbooker_append_post');
  2369. add_filter('the_excerpt','wordbooker_append_post');
  2370. add_filter('cron_schedules','wordbooker_custom_cron_schedules');
  2371. add_shortcode('wb_fb_like', 'wordbooker_fb_like_inline');
  2372. add_shortcode('wb_fb_send', 'wordbooker_fb_send_inline');
  2373. add_shortcode('wb_fb_share', 'wordbooker_fb_share_inline');
  2374. add_shortcode('wb_fb_comment', 'wordbooker_fb_comment_inline');
  2375. add_shortcode('wb_fb_read','wordbooker_fb_read_inline');
  2376. }
  2377. #load_plugin_textdomain( 'wordbooker', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  2378. # Includes - trying to keep my code base tidy.
  2379. include("includes/wordbooker_options.php");
  2380. # If they've disabled Wordbooker then we don't need to load any of these.
  2381. if (!isset($wordbooker_disabled)){
  2382. include("includes/wordbooker_wb_widget.php");
  2383. include("includes/wordbooker_fb_widget.php");
  2384. include("includes/wordbooker_cron.php");
  2385. include("includes/wordbooker_posting.php");
  2386. #include("includes/wordbooker_get_friend.php");
  2387. #include("includes/custom_quick_edit.php");
  2388. }
  2389. # This is for support for alternative posting processes. Only Curl is supported right now
  2390. #if (wordbooker_get_option('wordbooker_fopen_curl')=='fopen'){
  2391. # include("includes/wordbooker_facebook_fopen.php");
  2392. #}
  2393. # else {
  2394. include("includes/wordbooker_facebook_curl.php");
  2395. # }
  2396. ?>