/wp-content/plugins/wordbooker/wordbooker.php
PHP | 2684 lines | 2101 code | 269 blank | 314 comment | 513 complexity | 9b693a07ad6f5a4ccb049488a0a472bf MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- Plugin Name: Wordbooker
- Plugin URI: http://wordbooker.tty.org.uk
- Description: Provides integration between your blog and your Facebook account. Navigate to <a href="options-general.php?page=wordbooker">Settings → Wordbooker</a> for configuration.
- Author: Steve Atty
- Author URI: http://wordbooker.tty.org.uk
- Version: 2.0.8
- */
-
- /*
- *
- *
- * Copyright 2011 Steve Atty (email : posty@tty.org.uk)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
- # Putting this in here to see if it fixed some stupid bug
- #require_once('../../wp-includes/pluggable.php');
-
-
- @include("includes/premium.php");
- global $table_prefix, $wp_version,$wpdb,$db_prefix,$wbooker_user_id;
- $wbooker_user_id=0;
-
- $wordbooker_settings = wordbooker_options();
- if (! isset($wordbooker_settings['wordbooker_extract_length'])) $wordbooker_settings['wordbooker_extract_length']=256;
-
- define('WORDBOOKER_DEBUG', false);
- define('WORDBOOKER_TESTING', false);
- define('WORDBOOKER_CODE_RELEASE','2.0.8 - Mandragora');
-
- # For Troubleshooting
- define('ADVANCED_DEBUG',false);
-
- #$facebook_config['debug'] = WORDBOOKER_TESTING && !$_POST['action'];
- #Wordbooker2 - Dev
- #define('WORDBOOKER_FB_APIKEY', '0138375357c1eb1257ed9970ec1a274c');
- #define('WORDBOOKER_FB_SECRET', '4310b484ec5236694cfa4b94166aca61');
- #define('WORDBOOKER_FB_ID', '111687885534181');
-
- # Wordbooker - live
- if (!defined('WORDBOOKER_PREMIUM')) {
- define('APP TITLE','Wordbooker');
- define('WORDBOOKER_FB_APIKEY', '0cbf13c858237f5d74ef0c32a4db11fd');
- define('WORDBOOKER_FB_SECRET', 'df04f22f3239fb75bf787f440e726f31');
- define('WORDBOOKER_FB_ID', '254577506873');
- define('WORDBOOKER_APPLICATION_NAME','Wordbooker');
- define('OPENGRAPH_NAMESPACE','wordbooker');
- define('OPENGRAPH_ACCESS_TOKEN','AAAAAO0YAejkBANAjpuFluuIfFnNeOkRBUXps0UqQ9aTBFNAYpOS11f7835w676UOxtyZB4KDekuoS6BXwrs1Y95fDrnAZD');
- }
-
- define('WORDBOOKER_FB_APIVERSION', '1.0');
- define('WORDBOOKER_FB_DOCPREFIX','http://wiki.developers.facebook.com/index.php/');
- define('WORDBOOKER_FB_PUBLISH_STREAM', 'publish_stream');
- define('WORDBOOKER_FB_READ_STREAM', 'read_stream');
- define('WORDBOOKER_FB_STATUS_UPDATE',"status_update");
- define('WORDBOOKER_FB_CREATE_NOTE',"create_note");
- define('WORDBOOKER_FB_OFFLINE_ACCESS',"offline_access");
- define('WORDBOOKER_FB_MANAGE_PAGES',"manage_pages");
- define('WORDBOOKER_FB_PHOTO_UPLOAD',"photo_upload");
- define('WORDBOOKER_FB_VIDEO_UPLOAD',"video_upload");
- define('WORDBOOKER_FB_READ_FRIENDS',"read_friendlists");
- define('WORDBOOKER_SETTINGS', 'wordbooker_settings');
- define('WORDBOOKER_OPTION_SCHEMAVERS', 'schema_vers');
- define('WORDBOOKER_SCHEMA_VERSION', '2.4');
-
- $new_wb_table_prefix=$wpdb->base_prefix;
- if (isset ($db_prefix) ) { $new_wb_table_prefix=$db_prefix;}
-
- define('WORDBOOKER_ERRORLOGS', $new_wb_table_prefix . 'wordbooker_errorlogs');
- define('WORDBOOKER_POSTLOGS', $new_wb_table_prefix . 'wordbooker_postlogs');
- define('WORDBOOKER_USERDATA', $new_wb_table_prefix . 'wordbooker_userdata');
- define('WORDBOOKER_USERSTATUS', $new_wb_table_prefix . 'wordbooker_userstatus');
- define('WORDBOOKER_POSTCOMMENTS', $new_wb_table_prefix . 'wordbooker_postcomments');
- define('WORDBOOKER_PROCESS_QUEUE', $new_wb_table_prefix . 'wordbooker_process_queue');
- define('WORDBOOKER_FB_FRIENDS', $new_wb_table_prefix . 'wordbooker_fb_friends');
- define('WORDBOOKER_FB_FRIEND_LISTS', $new_wb_table_prefix . 'wordbooker_fb_friend_lists');
-
- define('WORDBOOKER_MINIMUM_ADMIN_LEVEL', 'edit_posts'); /* Contributor role or above. */
- define('WORDBOOKER_SETTINGS_PAGENAME', 'wordbooker');
- define('WORDBOOKER_SETTINGS_URL', 'options-general.php?page=' . WORDBOOKER_SETTINGS_PAGENAME);
-
-
-
- $wordbooker_wp_version_tuple = explode('.', $wp_version);
- define('WORDBOOKER_WP_VERSION', $wordbooker_wp_version_tuple[0] * 10 + $wordbooker_wp_version_tuple[1]);
-
- if (function_exists('json_encode')) {
- define('WORDBOOKER_JSON_ENCODE', 'PHP');
- } else {
- define('WORDBOOKER_JSON_ENCODE', 'Wordbook');
- }
-
- if (function_exists('json_decode') ) {
- define('WORDBOOKER_JSON_DECODE', 'PHP');
- } else {
- define('WORDBOOKER_JSON_DECODE', 'Wordbooker');
- }
- if (function_exists('simplexml_load_string') ) {
- define('WORDBOOKER_SIMPLEXML', 'provided by PHP');
- } else {
- define('WORDBOOKER_SIMPLEXML', 'is missing - this is a problem');
- }
-
-
- function wordbooker_load_apis() {
- if (WORDBOOKER_JSON_DECODE == 'Wordbooker') {
- function json_decode($json)
- {
- $comment = false;
- $out = '$x=';
-
- for ($i=0; $i<strlen($json); $i++)
- {
- if (!$comment)
- {
- if ($json[$i] == '{') $out .= ' array(';
- else if ($json[$i] == '}') $out .= ')';
- else if ($json[$i] == ':') $out .= '=>';
- else $out .= $json[$i];
- }
- else $out .= $json[$i];
- if ($json[$i] == '"') $comment = !$comment;
- }
- eval($out . ';');
- return $x;
- }
- }
-
- if (WORDBOOKER_JSON_ENCODE == 'Wordbook') {
- function json_encode($var) {
- if (is_array($var)) {
- $encoded = '{';
- $first = true;
- foreach ($var as $key => $value) {
- if (!$first) {
- $encoded .= ',';
- } else {
- $first = false;
- }
- $encoded .= "\"$key\":"
- . json_encode($value);
- }
- $encoded .= '}';
- return $encoded;
- }
- if (is_string($var)) {
- return "\"$var\"";
- }
- return $var;
- }
- }
- }
-
-
- /******************************************************************************
- * Wordbook options.
- */
-
- function wordbooker_options() {
- return get_option(WORDBOOKER_SETTINGS);
- }
-
- function wordbooker_set_options($options) {
- update_option(WORDBOOKER_SETTINGS, $options);
- }
-
- function wordbooker_get_option($key) {
- $options = wordbooker_options();
- return isset($options[$key]) ? $options[$key] : null;
- }
-
- function wordbooker_set_option($key, $value) {
- $options = wordbooker_options();
- $options[$key] = $value;
- wordbooker_set_options($options);
- }
-
- function wordbooker_delete_option($key) {
- $options = wordbooker_options();
- unset($options[$key]);
- update_option(WORDBOOKER_SETTINGS, $options);
- }
-
-
- /******************************************************************************
- * DB schema.
- */
-
- function wordbooker_activate() {
- global $wpdb, $table_prefix;
- wp_cache_flush();
- $errors = array();
- $result = $wpdb->query('
- CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_POSTLOGS . ' (
- `post_id` bigint(20) NOT NULL,
- `blog_id` bigint(20) NOT NULL,
- `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
- PRIMARY KEY (`blog_id`,`post_id`)
- ) DEFAULT CHARSET=utf8;
- ');
- if ($result === false)
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_POSTLOGS;
-
- $result = $wpdb->query('
- CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_ERRORLOGS . ' (
- `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
- `user_ID` bigint(20) unsigned NOT NULL,
- `method` longtext NOT NULL,
- `error_code` int(11) NOT NULL,
- `error_msg` longtext NOT NULL,
- `post_id` bigint(20) NOT NULL,
- `blog_id` bigint(20) NOT NULL,
- `sequence_id` bigint(20) NOT NULL auto_increment,
- `diag_level` int(4) default NULL,
- PRIMARY KEY (`sequence_id`),
- KEY `timestamp_idx` (`timestamp`),
- KEY `blog_idx` (`blog_id`)
- ) DEFAULT CHARSET=utf8;
- ');
- if ($result === false)
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_ERRORLOGS;
-
- $result = $wpdb->query('
- CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_USERDATA . ' (
- `user_ID` bigint(20) unsigned NOT NULL,
- `uid` varchar(80) default NULL,
- `expires` varchar(80) default NULL,
- `access_token` varchar(255) default NULL,
- `sig` varchar(80) default NULL,
- `use_facebook` tinyint(1) default 1,
- `onetime_data` longtext,
- `facebook_error` longtext,
- `secret` varchar(80) default NULL,
- `session_key` varchar(80) default NULL,
- `facebook_id` varchar(40) default NULL,
- `name` varchar(250) default NULL,
- `status` varchar(2048) default NULL,
- `updated` int(20) default NULL,
- `url` varchar(250) default NULL,
- `pic` varchar(250) default NULL,
- `pages` longtext,
- `auths_needed` int(1) default NULL,
- `blog_id` bigint(20) default NULL,
- PRIMARY KEY (`user_ID`),
- KEY `facebook_idx` (`facebook_id`)
- ) DEFAULT CHARSET=utf8;
- ');
- if ($result === false)
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_USERDATA;
-
- $result = $wpdb->query('
- CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_POSTCOMMENTS . ' (
- `fb_post_id` varchar(40) NOT NULL,
- `user_id` bigint(20) NOT NULL,
- `comment_timestamp` int(20) NOT NULL,
- `wp_post_id` int(11) NOT NULL,
- `blog_id` bigint(20) NOT NULL,
- `wp_comment_id` int(20) NOT NULL,
- PRIMARY KEY (`blog_id`,`wp_post_id`,`fb_post_id`,`wp_comment_id`)
- ) DEFAULT CHARSET=utf8;
- ');
- if ($result === false)
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_POSTCOMMENTS;
-
- $result = $wpdb->query('
- CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_USERSTATUS . ' (
- `user_ID` bigint(20) unsigned NOT NULL,
- `name` varchar(250) default NULL,
- `status` varchar(2048) default NULL,
- `updated` int(20) default NULL,
- `url` varchar(250) default NULL,
- `pic` varchar(250) default NULL,
- `blog_id` bigint(20) NOT NULL default 0,
- `facebook_id` varchar(40) default NULL,
- PRIMARY KEY (`user_ID`,`blog_id`)
- ) DEFAULT CHARSET=utf8;
- ');
- if ($result === false)
-
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_USERSTATUS;
- $result = $wpdb->query(' CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_FB_FRIENDS . ' (
- `user_id` int(11) NOT NULL,
- `blog_id` bigint(20) NOT NULL,
- `facebook_id` varchar(20) NOT NULL,
- `name` varchar(200) NOT NULL,
- PRIMARY KEY (`user_id`,`facebook_id`,`blog_id`),
- KEY `user_id_idx` (`user_id`),
- KEY `fb_id_idx` (`facebook_id`)
- ) DEFAULT CHARSET=utf8;
- ');
- if ($result === false)
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_FB_FRIENDS;
-
- $result = $wpdb->query('
- CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_FB_FRIEND_LISTS . ' (
- `user_id` int(11) NOT NULL,
- `flid` varchar(80) NOT NULL,
- `owner` varchar(80) NOT NULL,
- `name` varchar(240) NOT NULL,
- PRIMARY KEY (`user_id`,`flid`)
- ) DEFAULT CHARSET=utf8;
-
- ');
- if ($result === false)
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_FB_FRIEND_LISTS;
-
-
- $result = $wpdb->query(' CREATE TABLE IF NOT EXISTS ' . WORDBOOKER_PROCESS_QUEUE . ' (
- `entry_type` varchar(20) NOT NULL,
- `blog_id` int(11) NOT NULL,
- `post_id` int(11) NOT NULL,
- `priority` int(11) NOT NULL,
- `status` varchar(20) NOT NULL,
- PRIMARY KEY (`blog_id`,`post_id`)
- ) DEFAULT CHARSET=utf8;
- ');
- if ($result === false)
- $errors[] = __('Failed to create ', 'wordbooker') . WORDBOOKER_PROCESS_QUEUE ;
-
- if ($errors) {
- echo '<div id="message" class="updated fade">' . "\n";
- foreach ($errors as $errormsg) {
- _e("$errormsg<br />\n", 'wordbooker');
- }
- echo "</div>\n";
- #return;
- }
- wordbooker_set_option(WORDBOOKER_OPTION_SCHEMAVERS, 2.4);
- $wordbooker_settings=wordbooker_options();
- #Setup the cron. We clear it first in case someone did a dirty de-install.
- $dummy=wp_clear_scheduled_hook('wb_cron_job');
- $dummy=wp_schedule_event(time(), 'hourly', 'wb_cron_job');
- }
-
-
- function wordbooker_upgrade() {
- global $wpdb, $table_prefix,$blog_id;
- $errors = array();
- #return;
- # 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.
- $wordbooker_settings=wordbooker_options();
- # var_dump($wordbooker_settings);
- if (! isset($wordbooker_settings['schema_vers'])) {wordbooker_activate(); return;}
- if ($wordbooker_settings['schema_vers']< (float) WORDBOOKER_SCHEMA_VERSION ) {
- _e("Database changes being applied", 'wordbooker');
- } else {
- return;
- }
-
-
- if ($wordbooker_settings['schema_vers']=='2') {
-
- $result = $wpdb->query('
- ALTER TABLE '. WORDBOOKER_POSTCOMMENTS. ' DROP PRIMARY KEY , DROP INDEX fb_comment_id,
- ADD PRIMARY KEY ( `blog_id` , `wp_post_id` , `fb_post_id` , `wp_comment_id` )
- ');
- # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
- wordbooker_set_option('schema_vers', "2.1");
- }
-
- if ($wordbooker_settings['schema_vers']=='2.1') {
- $result = $wpdb->query('
- ALTER TABLE '. WORDBOOKER_POSTCOMMENTS. ' ADD `user_id` BIGINT( 20 ) NOT NULL
- ');
- # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
- wordbooker_set_option('schema_vers', "2.2");
- }
-
- if ($wordbooker_settings['schema_vers']=='2.2') {
- $result = $wpdb->query('
- ALTER TABLE '. WORDBOOKER_ERRORLOGS. ' ADD `sequence_id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT , ADD `diag_level` INT(4) NULL, ADD PRIMARY KEY ( `sequence_id` )
- ');
- # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
- wordbooker_set_option('schema_vers', "2.3");
- }
-
- if ($wordbooker_settings['schema_vers']=='2.3') {
- $result = $wpdb->query('
- ALTER TABLE '. WORDBOOKER_ERRORLOGS. ' ADD `sequence_id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT , ADD `diag_level` INT(4) NULL, ADD PRIMARY KEY ( `sequence_id` )
- ');
- # All done, set the schemaversion to version 5. NOT the current version, as this allow us to string updates.
- wordbooker_set_option('schema_vers', "2.4");
- }
-
- $dummy=wp_clear_scheduled_hook('wb_cron_job');
- $dummy=wp_schedule_event(time(), 'hourly', 'wb_cron_job');
- wordbooker_set_option('schema_vers', WORDBOOKER_SCHEMA_VERSION );
- wp_cache_flush();
- }
-
- function wordbooker_delete_user($user_id,$level) {
- global $wpdb;
- $errors = array();
- $table_array[1]=array(WORDBOOKER_USERDATA);
- $table_array[2]=array(WORDBOOKER_USERDATA,WORDBOOKER_USERSTATUS);
- $table_array[3]=array(WORDBOOKER_USERDATA,WORDBOOKER_USERSTATUS,WORDBOOKER_FB_FRIENDS,WORDBOOKER_FB_FRIEND_LISTS);
- foreach ($table_array[$level] as $tablename) {
- $result = $wpdb->query('DELETE FROM ' . $tablename . ' WHERE user_ID = ' . $user_id . '');
- #var_dump($result);
- }
- if ($errors) {
- echo '<div id="message" class="updated fade">' . "\n";
- foreach ($errors as $errormsg) {
- _e("$errormsg<br />\n", 'wordbooker');
- }
- echo "</div>\n";
- }
- }
-
- /******************************************************************************
- * Wordbook user data.
- */
- function wordbooker_get_userdata($user_id) {
- global $wpdb;
- $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 ;
- $rows = $wpdb->get_results($sql);
- if ($rows) {
- $rows[0]->onetime_data = unserialize($rows[0]->onetime_data);
- $rows[0]->facebook_error = unserialize($rows[0]->facebook_error);
- $rows[0]->secret = unserialize($rows[0]->secret);
- $rows[0]->session_key = unserialize($rows[0]->session_key);
- $rows[0]->access_token = unserialize($rows[0]->access_token);
- $rows[0]->pages = unserialize($rows[0]->pages);
- return $rows[0];
- }
- return null;
- }
-
- function wordbooker_set_userdata($onetime_data, $facebook_error,$secret, $session,$facebook_id) {
- global $user_ID, $wpdb,$blog_id;
- wordbooker_delete_userdata();
- $result = $wpdb->query("
- INSERT INTO " . WORDBOOKER_USERDATA . " (
- user_ID
- , onetime_data
- , facebook_error
- , secret
- , session_key
- , uid
- , expires
- , access_token
- , sig
- ,blog_id
- ,facebook_id
- ) VALUES (
- " . $user_ID . "
- , '" . serialize($onetime_data) . "'
- , '" . serialize($facebook_error) . "'
- , '" . serialize($secret) . "'
- , '" . serialize($session->session_key)."'
- , '". serialize($session->uid)."'
- , '". serialize($session->expires)."'
- , '". serialize($session->access_token)."'
- , '". serialize($session->sig)."'
- , " . $blog_id . "
- , '". $facebook_id."'
- )
- ");
- }
-
- function wordbooker_set_userdata2( $onetime_data, $facebook_error, $secret, $session_key,$user_ID) {
- global $wpdb;
- $sql= "Update " . WORDBOOKER_USERDATA . " set
- onetime_data = '" . serialize($onetime_data) . "'
- , facebook_error = '" . serialize($facebook_error) . "'
- , secret = '" . serialize($secret) . "'
- , session_key = '" . serialize($session_key) . "'
- where user_id=".$user_ID;
- $result = $wpdb->query($sql);
- }
-
-
- function wordbooker_update_userdata($wbuser) {
- return wordbooker_set_userdata2( $wbuser->onetime_data, $wbuser->facebook_error, $wbuser->secret, $wbuser->session_key,$wbuser->user_ID);
- }
-
- function wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code, $error_msg, $post_id) {
- $wbuser->facebook_error = array(
- 'method' => $method,
- 'error_code' => mysql_real_escape_string ($error_code),
- 'error_msg' => mysql_real_escape_string ($error_msg),
- 'postid' => $post_id,
- );
- wordbooker_update_userdata($wbuser);
- wordbooker_append_to_errorlogs($method, $error_code, $error_msg, $post_id,$wbuser->user_ID);
- }
-
- function wordbooker_clear_userdata_facebook_error($wbuser) {
- $wbuser->facebook_error = null;
- return wordbooker_update_userdata($wbuser);
- }
-
- function wordbooker_remove_user(){
- global $user_ID;
- # Delete the user's meta
- $wordbooker_user_settings_id="wordbookuser".$blog_id;
- delete_usermeta( $user_ID, $wordbooker_user_settings_id);
- # Then go and delete their data from the tables
- wordbooker_delete_user($user_ID,3);
- }
-
- function wordbooker_delete_userdata() {
- global $user_ID;
- wordbooker_delete_user($user_ID,2);
- }
-
- /******************************************************************************
- * Post logs - record time of last post to Facebook
- */
-
- function wordbooker_trim_postlogs() {
- # Forget that something has been posted to Facebook if it's been there more than a year.
- global $wpdb;
- $result = $wpdb->query('
- DELETE FROM ' . WORDBOOKER_POSTLOGS . '
- WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL 365 DAY)
- ');
- }
-
- function wordbooker_postlogged($post_id,$tstamp=0) {
- global $wpdb,$wordbooker_post_options,$post;
- $wordbooker_settings = wordbooker_options();
- $wbo=get_post_meta($post_id, '_wordbooker_options', true);
- #if ($wbo["wordbooker_publish_default"]!='published') {
- $time=time() ;
- if (! isset($wordbooker_settings['wordbooker_republish_time_frame'])) $wordbooker_settings['wordbooker_republish_time_frame']='3';
- $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;
- $rows = $wpdb->get_results($sql);
-
- wordbooker_debugger("Post is this old (Seconds) : ",$rows[0]->time,$post_id) ;
- #wordbooker_debugger("Post date : ",$rows[0]->post_date,$post_id) ;
- #wordbooker_debugger("Post modified : ",$rows[0]->post_modified,$post_id) ;
- #wordbooker_debugger("Post status : ",$rows[0]->post_status,$post_id) ;
- #wordbooker_debugger("Post status flag : ",$wbo['wordbooker_new_post'],$post_id) ;
- #wordbooker_debugger("Scheduled Post: ",$wbo['wordbooker_scheduled_post'],$post_id) ;
- if ($tstamp==1) { return $rows[0]->time;}
- if ($tstamp==1 && !isset($_POST['original_post_status']) && !isset($_POST['screen'])) {return 0;}
-
- # If the post isn't actually being published we give up - just in case
- if ($rows[0]->post_status!='publish') { return true;}
- # If the post is new then return false
- if ($rows[0]->post_date == $rows[0]->post_modified) {return false;}
- if ($wbo['wordbooker_scheduled_post']!=0) {
- $wbo['wordbooker_scheduled_post']=0;
- $y=update_post_meta($post_id, '_wordbooker_options', $wbo);
- return false;
- }
- if ($wbo['wordbooker_new_post']!=0) {
- $wbo['wordbooker_new_post']=0;
- $y=update_post_meta($post_id, '_wordbooker_options', $wbo);
- return false;
- }
- #}
- wordbooker_debugger("This post has already been published. So do checks "," ",$post_id) ;
- #if (!isset($_POST['original_post_status']) && !isset($_POST['screen'])) {return false;}
- // See if the user has overridden the repost on edit - i.e. they want to publish and be damned!
- if (isset ($wordbooker_post_options["wordbooker_publish_default"])) {
- wordbooker_debugger("Publish Post is set so user wants to republish "," ",$post_id) ;
- return false;
- }
- return true;
- }
-
-
- function wordbooker_insert_into_postlogs($post_id,$blog_id) {
- global $wpdb;
- wordbooker_delete_from_postlogs($post_id,$blog_id);
- if (!WORDBOOKER_TESTING) {
- $result = $wpdb->query(' INSERT INTO ' . WORDBOOKER_POSTLOGS . ' (post_id,blog_id) VALUES (' . $post_id . ','.$blog_id.')');
- }
- }
-
- function wordbooker_insert_into_process_queue($post_id,$blog_id,$entry_type) {
- global $wpdb;
- $result = $wpdb->query(' INSERT INTO ' . WORDBOOKER_PROCESS_QUEUE . ' (entry_type,blog_id,post_id,status) VALUES ("' . $entry_type. '",' .$blog_id .',' . $post_id . ',"B")');
- }
-
- function wordbooker_delete_from_process_queue($post_id,$blog_id) {
- global $wpdb,$blog_id;
- $result = $wpdb->query(' DELETE FROM ' . WORDBOOKER_PROCESS_QUEUE . ' where post_id='.$post_id.' and blog_id='.$blog_id);
- }
-
- function wordbooker_delete_from_postlogs($post_id,$blog_id) {
- global $wpdb,$blog_id;
- $result = $wpdb->query('DELETE FROM ' . WORDBOOKER_POSTLOGS . ' WHERE post_id = ' . $post_id . ' and blog_id='.$blog_id);
- }
-
- function wordbooker_delete_from_commentlogs($post_id,$blog_id) {
- global $wpdb,$blog_id;
- $result = $wpdb->query('DELETE FROM ' . WORDBOOKER_POSTCOMMENTS . ' WHERE wp_post_id = ' . $post_id . ' and blog_id='.$blog_id);
- }
-
- /******************************************************************************
- * Error logs - record errors
- */
-
- function wordbooker_hyperlinked_method($method) {
- return '<a href="'. WORDBOOKER_FB_DOCPREFIX . $method . '"'. ' title="Facebook API documentation" target="facebook"'. '>'. $method. '</a>';
- }
-
- function wordbooker_trim_errorlogs() {
- global $user_ID, $wpdb,$blog_id;
- $result = $wpdb->query('
- DELETE FROM ' . WORDBOOKER_ERRORLOGS . '
- WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL 2 DAY) and blog_id ='.$blog_id);
- }
-
- function wordbooker_clear_errorlogs() {
- global $user_ID, $wpdb,$blog_id;
- $result = $wpdb->query('
- DELETE FROM ' . WORDBOOKER_ERRORLOGS . '
- WHERE user_ID = ' . $user_ID . ' and error_code > -1 and blog_id ='.$blog_id);
- if ($result === false) {
- echo '<div id="message" class="updated fade">';
- _e('Failed to clear error logs.', 'wordbooker');
- echo "</div>\n";
- }
- }
-
-
- function wordbooker_clear_diagnosticlogs() {
- global $user_ID, $wpdb,$blog_id;
- $result = $wpdb->query('
- DELETE FROM ' . WORDBOOKER_ERRORLOGS . '
- WHERE blog_id ='.$blog_id);
- if ($result === false) {
- echo '<div id="message" class="updated fade">';
- _e('Failed to clear Diagnostic logs.', 'wordbooker');
- echo "</div>\n";
- }
- }
- function wordbooker_append_to_errorlogs($method, $error_code, $error_msg,$post_id,$user_id) {
- global $user_ID, $wpdb,$blog_id;
- if ($post_id == null) {
- $post_id = 0;
- } else {
- $post = get_post($post_id);
- }
- $result = $wpdb->insert(WORDBOOKER_ERRORLOGS,
- array('user_ID' => $user_id,
- 'method' => $method,
- 'error_code' => $error_code,
- 'error_msg' => $error_msg,
- 'post_id' => $post_id,
- 'blog_id' => $blog_id,
- 'diag_level'=> 900
- ),
- array('%d', '%s', '%d', '%s', '%d','%d')
- );
- }
-
- function wordbooker_delete_from_errorlogs($post_id) {
- global $wpdb,$blog_id;
- $result = $wpdb->query('DELETE FROM ' . WORDBOOKER_ERRORLOGS . ' WHERE post_id = ' . $post_id .' and blog_id ='.$blog_id );
- }
-
- function wordbooker_render_errorlogs() {
- global $user_ID, $wpdb,$blog_id;
- $diaglevel=wordbooker_get_option('wordbooker_advanced_diagnostics_level');
- #var_dump($diaglevel);
- #$sql='SELECT * FROM ' . WORDBOOKER_ERRORLOGS . ' WHERE user_ID = ' . $user_ID . ' and blog_id='.$blog_id.' and diag_level >'.$diaglevel.' order by sequence_id asc';
- #var_dump($sql);
- $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');
- if ($rows) {
- ?>
- <h3><?php _e('Diagnostic Messages', 'wordbooker'); ?></h3>
- <div class="wordbooker_errors">
- <p>
- </p>
- <table class="wordbooker_errorlogs">
- <tr>
- <th>Post</th>
- <th>Time</th>
- <th>Action</th>
- <th>Message</th>
- <th>Error Code</th>
- </tr>
- <?php
- foreach ($rows as $row) {
- $hyperlinked_post = '';
- if (($post = get_post($row->post_id))) {
- $hyperlinked_post = '<a href="'. get_permalink($row->post_id) . '">'. apply_filters('the_title',get_the_title($row->post_id)) . '</a>';
- }
- $hyperlinked_method= wordbooker_hyperlinked_method($row->method);
- if ($row->error_code>1){ echo "<tr class='error'>";} else {echo "<tr class='diag'>";}
- ?>
- <td><?php if ($row->post_id>0) { echo $hyperlinked_post;} else {echo "-";} ?></td>
- <td><?php echo $row->timestamp; ?></td>
- <td><?php echo $row->method; ?></td>
- <td><?php echo stripslashes($row->error_msg); ?></td>
- <td><?php if ($row->error_code>1) {echo $row->error_code;} else { echo "-";} ?></td>
- </tr>
-
- <?php
- }
- ?>
-
- </table>
- <form action="<?php echo WORDBOOKER_SETTINGS_URL; ?>" method="post">
- <input type="hidden" name="action" value="clear_errorlogs" />
- <p class="submit" style="text-align: center;">
- <input type="submit" value="<?php _e('Clear Diagnostic Messages', 'wordbooker'); ?>" />
- </p>
- </form>
- </div>
- <hr>
- <?php
- }
- }
-
-
- /******************************************************************************
- * Wordbooker setup and administration.
- */
-
- function wordbooker_admin_load() {
-
- if (isset($POST['reset_user_config'])){
- wordbooker_delete_userdata();
- return;}
- if (!$_POST['action'])
- return;
-
- switch ($_POST['action']) {
-
-
- case 'delete_userdata':
- # Catch if they got here using the perm_save/cache refresh
-
- if ( ! isset ($_POST["perm_save"])) {
- wordbooker_delete_userdata();
- }
- wp_redirect(WORDBOOKER_SETTINGS_URL);
- break;
-
- case 'clear_errorlogs':
- wordbooker_clear_diagnosticlogs();
- wp_redirect(WORDBOOKER_SETTINGS_URL);
- break;
-
- case 'clear_diagnosticlogs':
- wordbooker_clear_diagnosticlogs();
- wp_redirect(WORDBOOKER_SETTINGS_URL);
- break;
-
-
- case 'no_facebook':
- wordbooker_set_userdata(false, null, null, null,null,null);
- wp_redirect('/wp-admin/index.php');
- break;
- }
-
- exit;
- }
-
- function wordbooker_admin_head() {
- ?>
- <style type="text/css">
- .wordbooker_setup { margin: 0 3em; }
- .wordbooker_notices { margin: 0 3em; }
- .wordbooker_status { margin: 0 3em; }
- .wordbooker_errors { margin: 0 3em; }
- .wordbooker_thanks { margin: 0 3em; }
- .wordbooker_thanks ul { margin: 1em 0 1em 2em; list-style-type: disc; }
- .wordbooker_support { margin: 0 3em; }
- .wordbooker_support ul { margin: 1em 0 1em 2em; list-style-type: disc; }
- .facebook_picture {
- float: right;
- border: 1px solid black;
- padding: 2px;
- margin: 0 0 1ex 2ex;
- }
- .wordbooker_errorcolor { color: #c00; }
- table.wordbooker_errorlogs { text-align: center; }
- table.wordbooker_errorlogs th, table.wordbooker_errorlogs td {
- padding: 0.5ex 1.5em;
- }
- table.wordbooker_errorlogs th { background-color: #999; }
- table.wordbooker_errorlogs tr.error td { background-color: #f66; }
- table.wordbooker_errorlogs tr.diag td { background-color: #CCC; }
- </style>
- <?php
- }
-
- function wordbooker_option_notices() {
- global $user_ID, $wp_version;
- wordbooker_upgrade();
- wordbooker_trim_postlogs();
- wordbooker_trim_errorlogs();
- $errormsg = null;
- if (!function_exists('curl_init')) {
- $errormsg .= __('Wordbooker needs the CURL PHP extension to work. Please install / enable it and try again','wordbooker').' <br />';
- }
- if (!function_exists('json_decode')) {
- $errormsg .= __('Wordbooker needs the JSON PHP extension. Please install / enable it and try again ','wordbooker').'<br />';
- }
-
- if (!function_exists('simplexml_load_string')) {
- $errormsg .= __('Your PHP install is missing <code>simplexml_load_string()</code> ','wordbooker')."<br />";
- }
-
- if (WORDBOOKER_WP_VERSION < 29) {
- $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>";
- } else if (!($options = wordbooker_options()) ||
- !($wbuser = wordbooker_get_userdata($user_ID)) ||
- ( !$wbuser->access_token)) {
- $errormsg .=__("Wordbooker needs to be set up", 'wordbooker')."<br />";
- } else if ($wbuser->facebook_error) {
- $method = $wbuser->facebook_error['method'];
- $error_code = $wbuser->facebook_error['error_code'];
- $error_msg = $wbuser->facebook_error['error_msg'];
- $post_id = $wbuser->facebook_error['postid'];
- $suffix = '';
- if ($post_id != null && ($post = get_post($post_id))) {
- wordbooker_delete_from_postlogs($post_id);
- $suffix = __('for', 'wordbooker').' <a href="'. get_permalink($post_id) . '">'. get_the_title($post_id) . '</a>';
- }
- $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 />";
- wordbooker_clear_userdata_facebook_error($wbuser);
- }
-
- if ($errormsg) {
- ?>
-
- <h3><?php _e('Notices', 'wordbooker'); ?></h3>
-
- <div class="wordbooker_notices" style="background-color: #f66;">
- <p><?php echo $errormsg; ?></p>
- </div>
-
- <?php
- }
- }
-
- function get_check_session(){
- global $facebook2,$user_ID;
- # 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
- # OK lets go to the database and see if we have a session stored
-
-
- wordbooker_debugger("Getting Userdata "," ",0) ;
- $session = wordbooker_get_userdata($user_ID);
- if (strlen($session->access_token)>5) {
- var_dump($session);
- wordbooker_debugger("Session found. Check validity "," ",0) ;
- # We have a session ID so lets not get a new one
- # Put some session checking in here to make sure its valid
- try {
- # var_dump($session->access_token);
-
- wordbooker_debugger("Calling Facebook API : get current user "," ",0) ;
- # $attachment = array('access_token' => $session->access_token,);
- #var_dump($attachment);
- $ret_code=wordbooker_me($session->facebook_id,$session->access_token);
- # echo "mee";
- # var_dump($ret_code);
- }
- catch (Exception $e) {
- # We don't have a good session so
- wordbooker_debugger("User Session invalid - clear down data "," ",0) ;
- #wordbooker_delete_user($user_ID,1);
- return;
-
- }
- #var_dump($session);
- return $session->access_token;
- }
- else
- {
- # Are we coming back from a login with a session set?
- $zz=htmlspecialchars_decode ($_POST['session'])."<br>";
- $oldkey=explode("|",$zz);
- $newkey=explode("&expires",$zz);
-
- $session->access_token=$newkey[0];
- $session->session_key=$oldkey[1];
- $session->expires=0;
- $ret_code=wordbooker_me_status($session->facebook_id,$session->access_token);
- #echo "mee tooo";
- # var_dump($ret_code);
-
- wordbooker_debugger("Checking session (2) "," ",0) ;
- # $session = $facebook2->getSession();
- #var_dump($session);
- if (strlen($session->access_token)>5){
- wordbooker_debugger("Session found. Store it "," ",0) ;
- # Yes! so lets store it!y)
- wordbooker_set_userdata($onetime_data, $facebook_error, $secret,$session,$ret_code->id);
- return $session->access_token;
- }
-
- }
- }
-
-
-
-
- function wordbooker_option_setup($wbuser) {
- ?>
-
- <h3><?php _e('Setup', 'wordbooker'); ?></h3>
- <div class="wordbooker_setup">
- <?php
- $access_token=get_check_session();
- $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';
-
- if ( is_null($access_token) ) {
- wordbooker_debugger("No session found - lets login and authorise "," ",0,99) ;
- 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 />';
- }
- else {
- wordbooker_debugger("Everything looks good so lets ask them to refresh "," ",0,99) ;
- echo __("Wordbooker should now be authorised. Please click on the Reload Page Button",'wordbooker').'<br> <form action="options-general.php?page=wordbooker" method="post">';
- echo '<p style="text-align: center;"><input type="submit" name="perm_save" class="button-primary" value="'. __('Reload Page', 'wordbooker').'" /></p>';
- echo '</form> ';
- }
- echo "</div></div>";
- }
-
- function wordbooker_status($user_id)
- {
- echo '<h3>'.__('Status', 'wordbooker').'</h3>';
- global $wpdb, $user_ID,$table_prefix,$blog_id;
- $wordbooker_user_settings_id="wordbookuser".$blog_id;
- $wordbookuser=get_usermeta($user_ID,$wordbooker_user_settings_id);
- if ($wordbookuser['wordbooker_disable_status']=='on') {return;}
- global $shortcode_tags;
- $result = wordbooker_get_cache($user_id);
- ?>
-
- <div class="wordbooker_status">
- <div class="facebook_picture">
- <a href="<?php echo $result->url; ?>" target="facebook">
- <img src="<?php echo $result->pic; ?>" /></a>
- </div>
- <p>
- <a href="<?php echo $result->url; ?>"><?php echo $result->name; ?></a> ( <?php echo $result->facebook_id; ?> )<br /><br />
- <i><?php echo "<p>".$result->status; ?></i></p>
- (<?php
- $current_offset=0;
- $current_offset = get_option('gmt_offset');
- echo date('D M j, g:i a', $result->updated+(3600*$current_offset)); ?>).
- <br /><br />
-
-
- <?php
-
- }
-
- function wordbooker_option_status($wbuser) {
- global $wpdb,$user_ID;
-
- #$fbclient = wordbooker_fbclient($wbuser);
- # Go to the cache and try to pull details
- $fb_info=wordbooker_get_cache($user_ID,'use_facebook,facebook_id',1);
- # If we're missing stuff lets kick the cache.
- if (! isset($fb_info->facebook_id)) {
- wordbooker_cache_refresh ($user_ID,$fbclient);
- $fb_info=wordbooker_get_cache($user_ID,'use_facebook,facebook_id',1);
- }
- # if (isset($fbclient->secret)){
- #var_dump($fb_info);
- if ($fb_info->use_facebook==1) {
- echo"<p>".__('Wordbooker appears to be configured and working just fine', 'wordbooker');
- wordbooker_check_permissions($wbuser,$user);
- echo "</p><p>".__("If you like, you can start over from the beginning (this does not delete your posting and comment history)", 'wordbooker').":</p>";
- }
- else
- {
- echo "<p>".__('Wordbooker is able to connect to Facebook', 'wordbooker').'</p>';
- # _e( 'Or, you can start over from the beginning');
-
- }
-
- echo'<form action="" method="post">';
- echo '<p style="text-align: center;"><input type="submit" class="button-primary" name="reset_user_config" value="'.__('Reset User Session', 'wordbooker').'" />';
- echo ' <input type="submit" name="perm_save" class="button-primary" value="'. __('Refresh Status', 'wordbooker').'" /></p>';
- echo '</form> </div>';
-
- $description=__("Recent Facebook Activity for this site", 'wordbooker');
-
-
- $iframe='<iframe src="http://www.facebook.com/plugins/activity.php?site='.get_bloginfo('url').'&width=600&height=400&header=true&colorscheme=light&font&border_color&recommendations=true" scrolling="no" frameborder="no" style="border:none; overflow:hidden; width:600px; height:400px"></iframe>';
- $activity="<hr><h3>".$description.'</h3><p>'.$iframe."</p></div>";
- $options = wordbooker_options();
- if (isset($options["wordbooker_fb_rec_act"])) { echo $activity; }
-
-
- }
-
- function wordbooker_version_ok($currentvers, $minimumvers) {
- #Lets strip out the text and any other bits of crap so all we're left with is numbers.
- $currentvers=trim(preg_replace("/[^0-9.]/ ", "", $currentvers ));
- $current = preg_split('/\D+/', $currentvers);
- $minimum = preg_split('/\D+/', $minimumvers);
- for ($ii = 0; $ii < min(count($current), count($minimum)); $ii++) {
- if ($current[$ii] < $minimum[$ii])
- return false;
- }
- if (count($current) < count($minimum))
- return false;
- return true;
- }
-
-
- function wordbooker_option_support() {
- global $wp_version,$wpdb,$user_ID,$facebook2;
- $wordbooker_settings=wordbooker_options();
- ?>
- <h3><?php _e('Support', 'wordbooker'); ?></h3>
- <div class="wordbooker_support">
- <?php _e('For feature requests, bug reports, and general support :', 'wordbooker'); ?>
- <ul>
- <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>
- <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>
- <li><?php _e('Try the ', 'wordbooker'); ?><a href="http://wordbooker.tty.org.uk/forums/" target="facebook"><?php _e('Wordbooker Support Forums', 'wordbooker'); ?></a>.</li>
- <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>
- <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>
- <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>
- <li><?php _e('Check the Wordbooker ', 'wordbooker'); ?><a href="http://wordbooker.tty.org.uk/faqs/">Wordbooker</a> <?php _e('FAQs', 'wordbooker'); ?></li>
- </ul>
- <br />
- <?php _e('Please provide the following information about your installation:', 'wordbooker'); ?>
- <ul>
- <?php
- $active_plugins = get_option('active_plugins');
- $plug_info=get_plugins();
- $phpvers = phpversion();
- $jsonvers=phpversion('json');
- if (!phpversion('json')) { $jsonvers="Installed but version not being returned";}
- $sxmlvers=phpversion('simplexml');
- if (!phpversion('simplexml')) { $sxmlvers=" No version being returned";}
- $mysqlvers = function_exists('mysql_get_client_info') ? mysql_get_client_info() : 'Unknown';
- # If we dont have the function then lets go and get the version the old way
- if ($mysqlvers=="Unknown") {
- $t=mysql_query("select version() as ve");
- $r=mysql_fetch_object($t);
- $mysqlvers = $r->ve;
- }
- $http_coding="No Multibyte support";
- $int_coding="No Multibyte support";
- $mb_language="No Multibyte support";
- #$t=mysql_query("show variables like 'character%'");
- if (function_exists('mb_convert_encoding')) {
- $http_coding=mb_http_output();
- $int_coding=mb_internal_encoding();
- $mb_language=mb_language();
- }
-
-
- $curlcontent=__("Curl is not installed",'wordbooker');
- if (function_exists('curl_init')) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/platform');
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/includes/fb_ca_chain_bundle.crt');
- 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');
- $curlcontent = @curl_exec($ch);
- $x=json_decode($curlcontent);
- #var_dump($x->name);
- $curlstatus=__("Curl is available but cannot access Facebook - This is a problem (",'wordbooker').curl_errno($ch)." - ". curl_error($ch) ." )";
- if ($x->name=="Facebook Platform") {$curlstatus=__("Curl is available and can access Facebook - All is OK",'wordbooker');}
- curl_close($ch);
- }
- $new_wb_table_prefix=$wpdb->base_prefix;
- if (isset ($db_prefix) ) { $new_wb_table_prefix=$db_prefix;}
- $info = array(
- 'Wordbooker' => $plug_info['wordbooker/wordbooker.php']['Version'],
- 'Wordbooker ID'=>WORDBOOKER_FB_ID,
- 'Wordbooker Schema' => $wordbooker_settings['schema_vers'],
- 'WordPress' => $wp_version,
- 'Table prefix' =>$new_wb_table_prefix,
- 'PHP' => $phpvers,
- 'PHP Memory Usage (MB)' => memory_get_usage(true)/1024/1024,
- 'JSON Encode' => WORDBOOKER_JSON_ENCODE,
- 'JSON Decode' => WORDBOOKER_JSON_DECODE,
- 'Curl Status' => $curlstatus,
- # 'Fopen Status' => $fopenstat2.$fopenstat,
- 'JSON Version' => $jsonvers,
- 'SimpleXML library' => $sxmlvers." (". WORDBOOKER_SIMPLEXML.")",
- 'HTTP Output Character Encoding'=>$http_coding,
- 'Internal PHP Character Encoding'=>$int_coding,
- 'MySQL' => $mysqlvers,
- # 'Facebook Transaction limit'=>$result2,
- );
- $version_errors = array();
- $phpminvers = '5.0';
- $mysqlminvers = '4.0';
- if (!wordbooker_version_ok($phpvers, $phpminvers)) {
- $version_errors['PHP'] = $phpminvers;
- }
- if ($mysqlvers != 'Unknown' && !wordbooker_version_ok($mysqlvers, $mysqlminvers)) {
- $version_errors['MySQL'] = $mysqlminvers;
- }
-
- foreach ($info as $key => $value) {
- $suffix = '';
- if (($minvers = $version_errors[$key])) {
- $suffix = " <span class=\"wordbooker_errorcolor\">" . " (need $key version $minvers or greater)" . " </span>";
- }
- echo "<li>$key: <b>$value</b>$suffix</li>";
- }
- if (!function_exists('simplexml_load_string')) {
- _e("<li>XML: your PHP is missing <code>simplexml_load_string()</code></li>", 'wordbooker');
- }
-
- $rows = $wpdb->get_results("show variables like 'character_set%'");
- foreach ($rows as $chardata){
- echo "<li> Database ". $chardata->Variable_name ." : <b> ".$chardata->Value ."</b></li>";
- }
- $rows = $wpdb->get_results("show variables like 'collation%'");
- foreach ($rows as $chardata){
- echo "<li> Database ". $chardata->Variable_name ." : <b> ".$chardata->Value ."</b></li>";
- }
- echo "<li> Server : <b>".$_SERVER['SERVER_SOFTWARE']."</b></li>";
- _e("<li> Active Plugins : <b></li>", 'wordbooker');
- foreach($active_plugins as $name) {
- if ( $plug_info[$name]['Title']!='Wordbooker') {
- echo " ".$plug_info[$name]['Title']." ( ".$plug_info[$name]['Version']." ) <br />";}
- }
-
-
- if (ADVANCED_DEBUG) { phpinfo(INFO_MODULES);}
- ?>
- </ul>
-
- <?php
- if ($version_errors) {
- ?>
-
- <div class="wordbooker_errorcolor">
- <?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'); ?>
- </div>
-
- <?php
- } else if ($mysqlvers == 'Unknown') {
- ?>
-
- <div>
- <?php _e('Please ensure that your system meets the', 'wordbooker'); ?> <a href="http://wordpress.org/about/requirements/"><?php _e('WordPress minimum requirements', 'wordbooker'); ?></a>.
- </div>
-
- <?php
- }
- ?>
- </div>
-
- <?php
- }
-
-
- /******************************************************************************
- * Facebook API wrappers.
- */
-
- /*
- function wordbooker_fbclient_facebook_finish($wbuser, $result, $method,$error_code, $error_msg, $post_id,$result2, $error_code2, $error_msg2)
- {
- global $blog_id;
- wordbooker_debugger("Publish complete"," ",$post_id,99) ;
- if ($error_code) {
- wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code, $error_msg, $post_id);
- }
-
- if ($error_code2) {
- wordbooker_set_userdata_facebook_error($wbuser, $method, $error_code2, $error_msg2, $post_id);
- }
- If ((! $error_code) && (! $error_code2))
- {
- wordbooker_clear_userdata_facebook_error($wbuser);
- wordbooker_delete_from_process_queue($post_id,$blog_id);
- }
-
- return array($result,$result2);
- }
- */
-
- function wordbooker_fbclient_publishaction($wbuser,$post_id)
- {
- global $wordbooker_post_options,$wpdb;
-
- $wordbooker_settings =wordbooker_options();
- $post = get_post($post_id);
- $post_link_share = get_permalink($post_id);
- $post_link=wordbooker_short_url($post_id);
- $post_title=$post->post_title;
- $post_content = $post->post_content;
- # 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.
- $processed_content ="!!! ".apply_filters('the_content', $post_content)." !!!";
- $yturls = array();
- $matches_tn=array();
- # Get the Yapb image for the post
- if (class_exists('YapbImage')) {
- $siteUrl = get_option('siteurl');
- if (substr($siteUrl, -1) != '/') $siteUrl .= '/';
- $uri = substr($url, strpos($siteUrl, '/', strpos($url, '//')+2));
- $WordbookerYapbImageclass = new YapbImage(null,$post->ID,$uri);
- $WordbookerYapbImage=$WordbookerYapbImageclass->getInstanceFromDb($post_id);
- if (strlen($WordbookerYapbImage->uri)>6) {$yturls[]=get_bloginfo('url').$WordbookerYapbImage->uri;}
- }
-
- if ( function_exists( 'get_the_post_thumbnail' ) ) {
- wordbooker_debugger("Getting the thumnail image"," ",$post->ID) ;
- preg_match_all('/<img \s+ ([^>]*\s+)? src \s* = \s* [\'"](.*?)[\'"]/ix',get_the_post_thumbnail($post_id), $matches_tn);
- }
-
- $meta_tag_scan=explode(',',$wordbooker_settings['wordbooker_meta_tag_scan']);
- foreach($meta_tag_scan as $meta_tag) {
- wordbooker_debugger("Getting image from custom meta : ",$meta_tag,$post->ID) ;
- $matches_ct[]=get_post_meta($post->ID, $meta_tag, TRUE);
- }
- $matches=$matches_ct;
- if ( function_exists( 'get_the_post_thumbnail' ) ) {
- $matches=array_merge($matches_ct,$matches_tn[2]);
- }
-
- # If the user only wants the thumbnail then we can simply not do the skim over the processed images
- if (! isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
- wordbooker_debugger("Getting the rest of the images "," ",$post->ID) ;
- preg_match_all('/<img \s+ ([^>]*\s+)? src \s* = \s* [\'"](.*?)[\'"]/ix',$processed_content, $matched);
- $x=strip_shortcodes($post_content);
- preg_match_all( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=|embed/)([\w-]+)(.*?)#i', $x, $matches3 );
- if (is_array($matches3[3])) {
- foreach ($matches3[3] as $key ) {
- $yturls[]='http://img.youtube.com/vi/'.$key.'/0.jpg';
- }
- }
-
- }
- if ( function_exists( 'get_the_post_thumbnail' ) ) {
- # If the thumb only is set then pulled images is just matches
- if (!isset($wordbooker_settings["wordbooker_meta_tag_thumb"])) {
- if (! isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
- wordbooker_debugger("Setting image array to be both thumb and the post images "," ",$post->ID) ;
- $pulled_images=@array_merge($matches[2],$matched[2],$yturls,$matches);
- }
- else {
- wordbooker_debugger("Setting image array to be just thumb "," ",$post->ID) ;
- $pulled_images[]=$matches[2];
- }
- }
- }
-
- if (isset($wordbooker_settings["wordbooker_meta_tag_thumb"]) && isset($wordbooker_post_options["wordbooker_thumb_only"]) ) {
- wordbooker_debugger("Setting image array to be just thumb from meta. "," ",$post->ID) ;
- $pulled_images[]=$matches_ct[2];}
-
- else {
- wordbooker_debugger("Setting image array to be post and thumb images. "," ",$post->ID) ;
- if (is_array($matched[2])) {$pulled_images[]=array_merge($matches,$matched[2]);}
- if (is_array($matched[2]) && is_array($yturls)) {$pulled_images=array_merge($matches,$matched[2],$yturls);}
- }
-
- $images = array();
- if (is_array($pulled_images)) {
- foreach ($pulled_images as $imgsrc) {
- if ($imgsrc) {
- if (stristr(substr($imgsrc, 0, 8), '://') ===false) {
- /* Fully-qualify src URL if necessary. */
- $scheme = $_SERVER['HTTPS'] ? 'https' : 'http';
- $new_imgsrc = "$scheme://". $_SERVER['SERVER_NAME'];
- if ($imgsrc[0] == '/') {
- $new_imgsrc .= $imgsrc;
- }
- $imgsrc = $new_imgsrc;
- }
- $images[] = $imgsrc;
- }
- }
- }
- /* Pull out <wpg2> image tags. */
- $wpg2_g2path = get_option('wpg2_g2paths');
- if ($wpg2_g2path) {
- $g2embeduri = $wpg2_g2path['g2_embeduri'];
- if ($g2embeduri) {
- preg_match_all('/<wpg2>(.*?)</ix', $processed_content,
- $wpg_matches);
- foreach ($wpg_matches[1] as $wpgtag) {
- if ($wpgtag) {
- $images[] = $g2embeduri.'?g2_view='.'core.DownloadItem'."&g2_itemId=$wpgtag";
- }
- }
- }
- }
- $wordbooker_settings =wordbooker_options();
- if (count($images)>0){
- # Remove duplicates
- $images=array_unique($images);
- # Strip images from various plugins
- $im…
Large files files are truncated, but you can click here to view the full file