main_file = $bt[0]['file']; // Get plugin url $this->plugin_url = WP_PLUGIN_URL . '/' . basename(dirname($this->main_file)); if (strpos($this->plugin_url, 'http') === 0 && is_ssl()) $this->plugin_url = str_replace('http://', 'https://', $this->plugin_url); // register activation actions register_activation_hook($this->main_file, array(&$this, 'Activate')); register_deactivation_hook($this->main_file, array(&$this, 'Deactivate')); // Register actions add_action('init', array(&$this, 'Init'), 0); if (is_admin()) { add_action('admin_menu', array(&$this, 'Admin_menu')); add_action('admin_notices', array(&$this, 'Admin_notices')); add_action('post_submitbox_start', array(&$this, 'Post_submitbox')); add_action('transition_post_status', array(&$this, 'Transition_post_status'), 10, 3); add_filter('manage_posts_columns', array(&$this, 'Manage_posts_columns')); add_action('manage_posts_custom_column', array(&$this, 'Manage_posts_custom_column'), 10, 2); add_action('add_meta_boxes', array(&$this, 'Add_meta_boxes')); add_action('save_post', array(&$this, 'Save_post')); } add_action('xmlrpc_publish_post', array(&$this, 'Publish_post')); add_action('app_publish_post', array(&$this, 'Publish_post')); } // Handle plugin activation function Activate() { $version = get_option(c_al2fb_option_version); if ($version == 1) { delete_option(c_al2fb_meta_client_id); delete_option(c_al2fb_meta_app_secret); delete_option(c_al2fb_meta_access_token); delete_option(c_al2fb_meta_picture_type); delete_option(c_al2fb_meta_picture); delete_option(c_al2fb_meta_page); delete_option(c_al2fb_meta_clean); delete_option(c_al2fb_meta_donated); } update_option(c_al2fb_option_version, 2); } // Handle plugin deactivation function Deactivate() { global $user_ID; get_currentuserinfo(); // Cleanup if requested if (get_user_meta($user_ID, c_al2fb_meta_clean, true)) { delete_user_meta($user_ID, c_al2fb_meta_client_id); delete_user_meta($user_ID, c_al2fb_meta_app_secret); delete_user_meta($user_ID, c_al2fb_meta_access_token); delete_user_meta($user_ID, c_al2fb_meta_picture_type); delete_user_meta($user_ID, c_al2fb_meta_picture); delete_user_meta($user_ID, c_al2fb_meta_page); delete_user_meta($user_ID, c_al2fb_meta_page_owner); delete_user_meta($user_ID, c_al2fb_meta_caption); delete_user_meta($user_ID, c_al2fb_meta_msg); delete_user_meta($user_ID, c_al2fb_meta_clean); delete_user_meta($user_ID, c_al2fb_meta_donated); } } function Init() { if (is_admin()) { // I18n load_plugin_textdomain(c_al2fb_text_domain, false, dirname(plugin_basename(__FILE__))); // Enqueue style sheet $css_name = $this->Change_extension(basename($this->main_file), '.css'); if (file_exists(WP_CONTENT_DIR . '/uploads/' . $css_name)) $css_url = WP_CONTENT_URL . '/uploads/' . $css_name; else if (file_exists(TEMPLATEPATH . '/' . $css_name)) $css_url = get_bloginfo('template_directory') . '/' . $css_name; else $css_url = $this->plugin_url . '/' . $css_name; wp_register_style('al2fb_style', $css_url); wp_enqueue_style('al2fb_style'); } // Initiate Facebook authorization if (isset($_REQUEST['al2fb_action']) && $_REQUEST['al2fb_action'] == 'init') { // Debug info update_option(c_al2fb_log_redir_init, date('c')); // Redirect wp_redirect(self::Authorize_url()); exit(); } // Handle Facebook authorization parse_str($_SERVER['QUERY_STRING'], $query); if (isset($query['state']) && strpos($query['state'], 'al2fb_authorize') !== false) { // Build new url $query['state'] = ''; $query['al2fb_action'] = 'authorize'; $url = admin_url('tools.php?page=' . plugin_basename($this->main_file)); $url .= '&' . http_build_query($query); // Debug info update_option(c_al2fb_log_redir_time, date('c')); update_option(c_al2fb_log_redir_ref, (empty($_SERVER['HTTP_REFERER']) ? null : $_SERVER['HTTP_REFERER'])); update_option(c_al2fb_log_redir_from, $_SERVER['REQUEST_URI']); update_option(c_al2fb_log_redir_to, $url); // Redirect wp_redirect($url); exit(); } // Set default capability if (!get_option(c_al2fb_option_min_cap)) update_option(c_al2fb_option_min_cap, 'edit_posts'); } // Display admin messages function Admin_notices() { // Get current user global $user_ID; get_currentuserinfo(); // Check if action if (isset($_REQUEST['al2fb_action'])) { // Configuration if ($_REQUEST['al2fb_action'] == 'config') { // Check security check_admin_referer(c_al2fb_nonce_form); // Default values if (empty($_POST[c_al2fb_meta_picture_type])) $_POST[c_al2fb_meta_picture_type] = 'wordpress'; if (empty($_POST[c_al2fb_meta_page])) $_POST[c_al2fb_meta_page] = null; if (empty($_POST[c_al2fb_meta_page_owner])) $_POST[c_al2fb_meta_page_owner] = null; if (empty($_POST[c_al2fb_meta_caption])) $_POST[c_al2fb_meta_caption] = null; if (empty($_POST[c_al2fb_meta_msg])) $_POST[c_al2fb_meta_msg] = null; if (empty($_POST[c_al2fb_meta_clean])) $_POST[c_al2fb_meta_clean] = null; if (empty($_POST[c_al2fb_meta_donated])) $_POST[c_al2fb_meta_donated] = null; // Invalidate access token if (get_user_meta($user_ID, c_al2fb_meta_client_id, true) != $_POST[c_al2fb_meta_client_id] || get_user_meta($user_ID, c_al2fb_meta_app_secret, true) != $_POST[c_al2fb_meta_app_secret]) delete_user_meta($user_ID, c_al2fb_meta_access_token); // Page owner changed if ($_POST[c_al2fb_meta_page_owner] && !get_user_meta($user_ID, c_al2fb_meta_page_owner, true)) delete_user_meta($user_ID, c_al2fb_meta_access_token); // Update user options update_user_meta($user_ID, c_al2fb_meta_client_id, $_POST[c_al2fb_meta_client_id]); update_user_meta($user_ID, c_al2fb_meta_app_secret, $_POST[c_al2fb_meta_app_secret]); update_user_meta($user_ID, c_al2fb_meta_picture_type, $_POST[c_al2fb_meta_picture_type]); update_user_meta($user_ID, c_al2fb_meta_picture, $_POST[c_al2fb_meta_picture]); update_user_meta($user_ID, c_al2fb_meta_page, $_POST[c_al2fb_meta_page]); update_user_meta($user_ID, c_al2fb_meta_page_owner, $_POST[c_al2fb_meta_page_owner]); update_user_meta($user_ID, c_al2fb_meta_caption, $_POST[c_al2fb_meta_caption]); update_user_meta($user_ID, c_al2fb_meta_msg, $_POST[c_al2fb_meta_msg]); update_user_meta($user_ID, c_al2fb_meta_clean, $_POST[c_al2fb_meta_clean]); update_user_meta($user_ID, c_al2fb_meta_donated, $_POST[c_al2fb_meta_donated]); // Update admin options if (current_user_can('manage_options')) { if (empty($_POST[c_al2fb_option_nonotice])) $_POST[c_al2fb_option_nonotice] = null; if (empty($_POST[c_al2fb_option_min_cap])) $_POST[c_al2fb_option_min_cap] = null; update_option(c_al2fb_option_nonotice, $_POST[c_al2fb_option_nonotice]); update_option(c_al2fb_option_min_cap, $_POST[c_al2fb_option_min_cap]); if (isset($_REQUEST['debug'])) { update_option(c_al2fb_option_siteurl, $_POST[c_al2fb_option_siteurl]); update_option(c_al2fb_option_nocurl, $_POST[c_al2fb_option_nocurl]); } } // Show result echo '

' . __('Settings updated', c_al2fb_text_domain) . '

'; } // Authorization else if ($_REQUEST['al2fb_action'] == 'authorize') { if (isset($_REQUEST['code'])) { try { $access_token = self::Get_token(); update_user_meta($user_ID, c_al2fb_meta_access_token, $access_token); echo '

' . __('Authorized, go posting!', c_al2fb_text_domain) . '

'; } catch (Exception $e) { delete_user_meta($user_ID, c_al2fb_meta_access_token); echo '

' . htmlspecialchars($e->getMessage(), ENT_QUOTES, get_bloginfo('charset')) . '

'; } } else if (isset($_REQUEST['error'])) { $msg = $_REQUEST['error_description']; $msg .= ' reason=' . $_REQUEST['error_reason']; $msg .= ' error=' . $_REQUEST['error']; update_option(c_al2fb_last_error, $msg); update_option(c_al2fb_last_error_time, date('c')); echo '

' . $_REQUEST['error_description'] . '

'; } } // Mail debug info else if ($_REQUEST['al2fb_action'] == 'mail') { // Check security check_admin_referer(c_al2fb_nonce_form); // Build headers $headers = 'From: ' . $_POST[c_al2fb_mail_name] . '<' . $_POST[c_al2fb_mail_email] . '>' . "\r\n"; $headers .= 'X-Mailer: AL2FB' . "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=' . get_bloginfo('charset') . "\r\n"; // Build message $message = 'AL2FB'; $message .= '

' . nl2br(htmlspecialchars($_POST[c_al2fb_mail_msg])) . '

'; $message .= '
'; $message .= self::Debug_info(); $message .= ''; if (mail('marcel@bokhorst.biz', '[AL2FB] Debug information', $message, $headers)) echo '

' . __('Debug information sent', c_al2fb_text_domain) . '

'; else echo '

' . __('Sending debug information failed', c_al2fb_text_domain) . '

'; } } // Check config/authorization $uri = $_SERVER['REQUEST_URI']; $url = 'tools.php?page=' . plugin_basename($this->main_file); if (get_option(c_al2fb_option_nonotice) ? strpos($uri, $url) !== false : true) { if (!get_user_meta($user_ID, c_al2fb_meta_client_id, true) || !get_user_meta($user_ID, c_al2fb_meta_app_secret, true)) { $notice = __('needs configuration', c_al2fb_text_domain); $anchor = 'configure'; } else if (!get_user_meta($user_ID, c_al2fb_meta_access_token, true)) { $notice = __('needs authorization', c_al2fb_text_domain); $anchor = 'authorize'; } if (!empty($notice)) { $url .= '#' . $anchor; echo '

'; _e('Add Link to Facebook', c_al2fb_text_domain); echo ' ' . $notice . '

'; } } // Check for errors $posts = new WP_Query(array('meta_key' => c_al2fb_meta_error, 'posts_per_page' => 5)); while ($posts->have_posts()) { $posts->next_post(); $error = get_post_meta($posts->post->ID, c_al2fb_meta_error, true); if (!empty($error)) { echo '

'; echo __('Add Link to Facebook', c_al2fb_text_domain) . ' - '; edit_post_link($posts->post->post_title, null, null, $posts->post->ID); echo ': ' . htmlspecialchars($error) . '

'; } } } // Register options page function Admin_menu() { if (function_exists('add_management_page')) add_management_page( __('Add Link to Facebook', c_al2fb_text_domain) . ' ' . __('Administration', c_al2fb_text_domain), __('Add Link to Facebook', c_al2fb_text_domain), get_option(c_al2fb_option_min_cap), $this->main_file, array(&$this, 'Administration')); } // Handle option page function Administration() { // Security check $min_cap = get_option(c_al2fb_option_min_cap); if (!current_user_can($min_cap)) die('Unauthorized: ' . $min_cap); // Get current user global $user_ID; get_currentuserinfo(); $charset = get_bloginfo('charset'); $access_token = get_user_meta($user_ID, c_al2fb_meta_access_token, true); self::Sponsorship(); $pic_type = get_user_meta($user_ID, c_al2fb_meta_picture_type, true); $pic_wordpress = ($pic_type == 'wordpress' ? ' checked' : ''); $pic_featured = ($pic_type == 'featured' ? ' checked' : ''); $pic_facebook = ($pic_type == 'facebook' ? ' checked' : ''); $pic_custom = ($pic_type == 'custom' ? ' checked' : ''); if (!current_theme_supports('post-thumbnails')) $pic_featured .= ' disabled'; ?>

' . __('Your server may not allow external connections', c_al2fb_text_domain) . '

'; // Debug information if (isset($_REQUEST['debug'])) { echo '
'; echo self::Debug_info(); ?>


link . '" target="_blank">' . htmlspecialchars($me->name, ENT_QUOTES, $charset); if (!empty($me->category)) echo ' - ' . htmlspecialchars($me->category, ENT_QUOTES, $charset); echo ''; } catch (Exception $e) { echo '

' . htmlspecialchars($e->getMessage(), ENT_QUOTES, $charset) . '

'; } } ?>



Site URL:', c_al2fb_text_domain); ?>

' . htmlspecialchars($e->getMessage(), ENT_QUOTES, $charset) . '

'; } ?>
name, ENT_QUOTES, $charset, $charset); ?>


' . htmlspecialchars($e->getMessage(), ENT_QUOTES, $charset) . '

'; } ?>
>
>
>
>

/>
/>
/>
/>
/>

/>
/>
/>

get_site_url() -> WordPress folder // Blog Address -> get_home_url() -> Home page if (get_option(c_al2fb_option_siteurl)) return get_site_url(null, '/'); else return get_home_url(null, '/'); } // Request token function Get_token() { // Get current user global $user_ID; get_currentuserinfo(); $url = 'https://graph.facebook.com/oauth/access_token'; $query = http_build_query(array( 'client_id' => get_user_meta($user_ID, c_al2fb_meta_client_id, true), 'redirect_uri' => self::Redirect_uri(), 'client_secret' => get_user_meta($user_ID, c_al2fb_meta_app_secret, true), 'code' => $_REQUEST['code'] )); $response = self::Request($url, $query, 'GET'); $key = 'access_token='; $access_token = substr($response, strpos($response, $key) + strlen($key)); $access_token = explode('&', $access_token); $access_token = $access_token[0]; return $access_token; } function Get_application() { // Get current user global $user_ID; get_currentuserinfo(); $app_id = get_user_meta($user_ID, c_al2fb_meta_client_id, true); $url = 'https://graph.facebook.com/' . $app_id; $query = http_build_query(array( 'access_token' => get_user_meta($user_ID, c_al2fb_meta_access_token, true) )); $response = self::Request($url, $query, 'GET'); $app = json_decode($response); return $app; } // Get profile data function Get_me($self) { // Get current user global $user_ID; get_currentuserinfo(); $page = get_user_meta($user_ID, c_al2fb_meta_page, true); if ($self | empty($page)) $page = 'me'; $url = 'https://graph.facebook.com/' . $page; $query = http_build_query(array( 'access_token' => get_user_meta($user_ID, c_al2fb_meta_access_token, true) )); $response = self::Request($url, $query, 'GET'); $me = json_decode($response); return $me; } function Get_pages() { // Get current user global $user_ID; get_currentuserinfo(); $url = 'https://graph.facebook.com/me/accounts'; $query = http_build_query(array( 'access_token' => get_user_meta($user_ID, c_al2fb_meta_access_token, true) )); $response = self::Request($url, $query, 'GET'); $accounts = json_decode($response); return $accounts; } // Add exclude checkbox function Post_submitbox() { if (current_user_can(get_option(c_al2fb_option_min_cap))) { global $post; $exclude = get_post_meta($post->ID, c_al2fb_meta_exclude, true); $chk_exclude = $exclude ? 'checked' : ''; ?>
/>
' . ($link_id ? __('Yes', c_al2fb_text_domain) : __('No', c_al2fb_text_domain)) . ''; } } // Add post meta box function Add_meta_boxes() { add_meta_box( 'al2fb_meta', __('Add Link to Facebook', c_al2fb_text_domain), array(&$this, 'Generate_meta_box'), 'post'); } // Display attached image selector function Generate_meta_box() { // Security wp_nonce_field(plugin_basename(__FILE__), c_al2fb_nonce_form); if (function_exists('wp_get_attachment_thumb_url')) { // Get attached images global $post; $images = &get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID); if (empty($images)) echo '' . __('No images in the media library for this post', c_al2fb_text_domain) . ''; else { // Display image selector $image_id = get_post_meta($post->ID, c_al2fb_meta_image_id, true); // Header echo '

' . __('Select link image:', c_al2fb_text_domain) . '

'; echo '
'; // None echo '
'; echo ''; echo '
'; echo ''; echo '
'; // Images foreach ($images as $attachment_id => $attachment) { echo '
'; echo ''; echo '
'; echo ''; echo '
'; } echo '
'; } } else echo 'wp_get_attachment_thumb_url not available'; } // Save selected attached image function Save_post($post_id) { // Security checks if (!wp_verify_nonce($_POST[c_al2fb_nonce_form], plugin_basename(__FILE__))) return $post_id; if (!current_user_can('edit_post', $post_id)) return $post_id; // Skip auto save if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; // Persist data $image_id = $_POST['al2fb_image_id']; if (empty($image_id)) delete_post_meta($post_id, c_al2fb_meta_image_id); else update_post_meta($post_id, c_al2fb_meta_image_id, $image_id); } // Handle post status change function Transition_post_status($new_status, $old_status, $post) { // Process exclude flag $prev_exclude = $_POST[c_al2fb_meta_exclude . '_prev']; $exclude = (empty($_POST[c_al2fb_meta_exclude]) ? null : $_POST[c_al2fb_meta_exclude]); if ($exclude) update_post_meta($post->ID, c_al2fb_meta_exclude, $exclude); else delete_post_meta($post->ID, c_al2fb_meta_exclude); // Check post status if ($new_status == 'publish' && ($new_status != $old_status || (!$exclude && $prev_exclude) || get_post_meta($post->ID, c_al2fb_meta_error, true))) self::Publish_post($post->ID); } // Handle publish post / XML-RPC publish post function Publish_post($post_ID) { $post = get_post($post_ID); // Check if not added if (get_user_meta($post->post_author, c_al2fb_meta_access_token, true) && !get_post_meta($post->ID, c_al2fb_meta_link_id, true) && !get_post_meta($post->ID, c_al2fb_meta_exclude, true)) { // Check if public if ($post->post_status == 'publish' && empty($post->post_password)) self::Add_link($post); } } function Add_link($post) { // Get plain texts $excerpt = preg_replace('/<[^>]*>/', '', do_shortcode($post->post_excerpt)); $content = preg_replace('/<[^>]*>/', '', do_shortcode($post->post_content)); // Get caption $caption = ''; if (get_user_meta($post->post_author, c_al2fb_meta_caption, true)) $caption = html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset')); // Get body $description = ''; if (get_user_meta($post->post_author, c_al2fb_meta_msg, true)) $description = $content; else $description = ($excerpt ? $excerpt : $content); // Get link picture $image_id = get_post_meta($post->ID, c_al2fb_meta_image_id, true); if (!empty($image_id) && function_exists('wp_get_attachment_thumb_url')) $picture = wp_get_attachment_thumb_url($image_id); if (empty($picture)) { // Default picture $picture = 'http://s.wordpress.org/about/images/logo-blue/blue-s.png'; // Check picture type $picture_type = get_user_meta($post->post_author, c_al2fb_meta_picture_type, true); if ($picture_type == 'featured') { if (current_theme_supports('post-thumbnails') && function_exists('get_post_thumbnail_id')) { $picture_id = get_post_thumbnail_id($post->ID); if ($picture_id) { $picture = wp_get_attachment_image_src($picture_id, 'medium'); if ($picture && $picture[0]) $picture = $picture[0]; } } } else if ($picture_type == 'facebook') $picture = ''; else if ($picture_type == 'custom') { $custom = get_user_meta($post->post_author, c_al2fb_meta_picture, true); if ($custom) $picture = $custom; } } // Get user note $message = ''; if (get_user_meta($post->post_author, c_al2fb_meta_msg, true)) $message = $excerpt; // Do not disturb WordPress try { // Select page $page_id = get_user_meta($post->post_author, c_al2fb_meta_page, true); if (empty($page_id)) $page_id = 'me'; // Get access token $access_token = get_user_meta($post->post_author, c_al2fb_meta_access_token, true); if ($page_id != 'me' && get_user_meta($post->post_author, c_al2fb_meta_page_owner, true)) { $found = false; $pages = self::Get_pages(); foreach ($pages->data as $page) if ($page->id == $page_id) { $found = true; $access_token = $page->access_token; } if (!$found) throw new Exception('Page token not found id=' . $page_id); } // Build rquest // http://developers.facebook.com/docs/reference/api/link/ $url = 'https://graph.facebook.com/' . $page_id . '/feed'; $query = http_build_query(array( 'access_token' => $access_token, 'link' => get_permalink($post->ID), 'name' => $post->post_title, 'caption' => $caption, 'description' => $description, 'picture' => $picture, 'message' => $message )); // Execute request $response = self::Request($url, $query, 'POST'); $link = json_decode($response); // Register link/date add_post_meta($post->ID, c_al2fb_meta_link_id, $link->id); update_post_meta($post->ID, c_al2fb_meta_link_time, date('c')); delete_post_meta($post->ID, c_al2fb_meta_error); } catch (Exception $e) { add_post_meta($post->ID, c_al2fb_meta_error, $e->getMessage()); update_post_meta($post->ID, c_al2fb_meta_link_time, date('c')); } } // Generic http request function Request($url, $query, $type) { // Get timeout $timeout = get_option(c_al2fb_option_timeout); if (!$timeout) $timeout = 30; // Use cURL if available if (function_exists('curl_init') && !get_option(c_al2fb_option_nocurl)) return self::curl_file_get_contents($url, $query, $type, $timeout); if (version_compare(PHP_VERSION, '5.2.1') < 0) ini_set('default_socket_timeout', $timeout); $this->php_error = ''; set_error_handler(array(&$this, 'PHP_error_handler')); if ($type == 'GET') { $context = stream_context_create(array( 'http' => array( 'method' => 'GET', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'timeout' => $timeout ) )); $content = file_get_contents($url . '?' . $query, false, $context); } else { $context = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'timeout' => $timeout, 'content' => $query ) )); $content = file_get_contents($url, false, $context); } restore_error_handler(); // Check for errors $status = false; if (!empty($http_response_header)) foreach ($http_response_header as $h) if (strpos($h, 'HTTP/') === 0) { $status = explode(' ', $h); $status = intval($status[1]); } if ($status == 200) return $content; else { $msg = 'Error ' . $status . ': ' . $this->php_error . ' ' . print_r($http_response_header, true); update_option(c_al2fb_last_error, $msg); update_option(c_al2fb_last_error_time, date('c')); throw new Exception($msg); } } // Persist PHP errors function PHP_error_handler($errno, $errstr) { $this->php_error = $errstr; } // cURL http request function curl_file_get_contents($url, $query, $type, $timeout) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_TIMEOUT, $timeout); if ($type == 'GET') curl_setopt($c, CURLOPT_URL, $url . '?' . $query); else { curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_POSTFIELDS, $query); } $content = curl_exec($c); $status = curl_getinfo($c, CURLINFO_HTTP_CODE); curl_close($c); if ($status == 200) return $content; else { $error = json_decode($content); $error = empty($error->error->message) ? $content : $error->error->message; $msg = 'cURL error ' . $status . ': ' . $error; update_option(c_al2fb_last_error, $msg); update_option(c_al2fb_last_error_time, date('c')); throw new Exception($msg); } } function Debug_info() { global $wp_version; $plugin_folder = get_plugins('/' . plugin_basename(dirname(__FILE__))); $plugin_version = $plugin_folder[basename($this->main_file)]['Version']; $info = '

' . __('Debug information', c_al2fb_text_domain) . '

'; $info .= '
'; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $posts = new WP_Query(array('meta_key' => c_al2fb_meta_error, 'posts_per_page' => 5)); while ($posts->have_posts()) { $posts->next_post(); $error = get_post_meta($posts->post->ID, c_al2fb_meta_error, true); if (!empty($error)) { $info .= ''; $info .= ''; $info .= ''; $info .= ''; } } $info .= ''; $info .= ''; $info .= '
Time:' . date('c') . '
Server software:' . htmlspecialchars($_SERVER['SERVER_SOFTWARE']) . '
SAPI:' . htmlspecialchars(php_sapi_name()) . '
PHP version:' . PHP_VERSION . '
User agent:' . htmlspecialchars($_SERVER['HTTP_USER_AGENT']) . '
WordPress version:' . $wp_version . '
Plugin version:' . $plugin_version . '
Multi site:' . (is_multisite() ? 'Yes' : 'No') . '
Blog address (home):' . htmlspecialchars(get_home_url(), ENT_QUOTES, $charset) . '
WordPress address (site):' . htmlspecialchars(get_site_url(), ENT_QUOTES, $charset) . '
Redirect URI:' . htmlspecialchars(self::Redirect_uri(), ENT_QUOTES, $charset) . '
Authorize URL:' . htmlspecialchars(self::Authorize_url()) . '
Authorization start:' . htmlspecialchars(get_option(c_al2fb_log_redir_init)) . '
Redirect time:' . htmlspecialchars(get_option(c_al2fb_log_redir_time)) . '
Redirect referer:' . htmlspecialchars(get_option(c_al2fb_log_redir_ref)) . '
Redirect from:' . htmlspecialchars(get_option(c_al2fb_log_redir_from)) . '
Redirect to:' . htmlspecialchars(get_option(c_al2fb_log_redir_to)) . '
Authorized:' . ($access_token ? 'Yes' : 'No') . '
allow_url_fopen:' . (ini_get('allow_url_fopen') ? 'Yes' : 'No') . '
cURL:' . (function_exists('curl_init') ? 'Yes' : 'No') . '
Do not use cURL:' . (get_option('c_al2fb_option_nocurl') ? 'Yes' : 'No') . '
Error:' . htmlspecialchars($error) . '
Error time:' . htmlspecialchars(get_post_meta($posts->post->ID, c_al2fb_meta_link_time, true)) . '
Last error:' . htmlspecialchars(get_option(c_al2fb_last_error)) . '
Last error time:' . htmlspecialchars(get_option(c_al2fb_last_error_time)) . '
'; return $info; } // Check environment function Check_prerequisites() { // Check WordPress version global $wp_version; if (version_compare($wp_version, '3.0') < 0) die('Add Link to Facebook requires at least WordPress 3.0'); // Check basic prerequisities self::Check_function('add_action'); self::Check_function('add_filter'); self::Check_function('wp_register_style'); self::Check_function('wp_enqueue_style'); self::Check_function('file_get_contents'); self::Check_function('json_decode'); } function Check_function($name) { if (!function_exists($name)) die('Required WordPress function "' . $name . '" does not exist'); } // Change file extension function Change_extension($filename, $new_extension) { return preg_replace('/\..+$/', $new_extension, $filename); } } } ?>