main_file = str_replace('-class', '', __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); // Log $this->debug = get_option(c_al2fb_option_debug); // Get site & blog id if (is_multisite()) { $current_site = get_current_site(); $this->site_id = $current_site->id; global $blog_id; $this->blog_id = $blog_id; } // 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_filter('plugin_action_links', array(&$this, 'Plugin_action_links'), 10, 2); add_action('admin_notices', array(&$this, 'Admin_notices')); add_action('post_submitbox_misc_actions', array(&$this, 'Post_submitbox_misc_actions')); 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_filter('manage_pages_columns', array(&$this, 'Manage_posts_columns')); add_action('manage_pages_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('personal_options', array(&$this, 'Personal_options')); add_action('personal_options_update', array(&$this, 'Personal_options_update')); add_action('edit_user_profile_update', array(&$this, 'Personal_options_update')); } add_action('transition_post_status', array(&$this, 'Transition_post_status'), 10, 3); add_action('xmlrpc_publish_post', array(&$this, 'Remote_publish')); add_action('app_publish_post', array(&$this, 'Remote_publish')); add_action('future_to_publish', array(&$this, 'Future_to_publish')); add_action('al2fb_publish', array(&$this, 'Remote_publish')); if (get_option(c_al2fb_option_use_pp)) add_action('publish_post', array(&$this, 'Remote_publish')); add_action('comment_post', array(&$this, 'Comment_post')); add_action('comment_unapproved_to_approved', array(&$this, 'Comment_approved')); add_action('comment_approved_to_unapproved', array(&$this, 'Comment_unapproved')); // Content add_action('wp_head', array(&$this, 'WP_head')); add_filter('the_content', array(&$this, 'The_content'), 999); add_filter('comments_array', array(&$this, 'Comments_array'), 10, 2); add_filter('get_comments_number', array(&$this, 'Get_comments_number'), 10, 2); add_filter('comment_class', array(&$this, 'Comment_class')); add_filter('get_avatar', array(&$this, 'Get_avatar'), 10, 5); // Shortcodes add_shortcode('al2fb_likers', array(&$this, 'Shortcode_likers')); add_shortcode('al2fb_like_count', array(&$this, 'Shortcode_like_count')); add_shortcode('al2fb_like_button', array(&$this, 'Shortcode_like_button')); add_shortcode('al2fb_like_box', array(&$this, 'Shortcode_like_box')); add_shortcode('al2fb_send_button', array(&$this, 'Shortcode_send_button')); add_shortcode('al2fb_comments_plugin', array(&$this, 'Shortcode_comments_plugin')); add_shortcode('al2fb_face_pile', array(&$this, 'Shortcode_face_pile')); add_shortcode('al2fb_profile_link', array(&$this, 'Shortcode_profile_link')); add_shortcode('al2fb_registration', array(&$this, 'Shortcode_registration')); add_shortcode('al2fb_login', array(&$this, 'Shortcode_login')); add_shortcode('al2fb_activity_feed', array(&$this, 'Shortcode_activity_feed')); if (get_option(c_al2fb_option_shortcode_widget)) add_filter('widget_text', 'do_shortcode'); // Custom filters add_filter('al2fb_excerpt', array(&$this, 'Filter_excerpt'), 10, 2); add_filter('al2fb_content', array(&$this, 'Filter_content'), 10, 2); // Widget add_action('widgets_init', create_function('', 'return register_widget("AL2FB_Widget");')); if (!is_admin()) add_action('wp_print_styles', array(&$this, 'WP_print_styles')); } // Handle plugin activation function Activate() { global $wpdb; $version = get_option(c_al2fb_option_version); if (empty($version)) update_option(c_al2fb_option_siteurl, true); 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); } if ($version <= 2) { $rows = $wpdb->get_results("SELECT user_id, meta_value FROM " . $wpdb->usermeta . " WHERE meta_key='al2fb_integrate'"); foreach ($rows as $row) { update_user_meta($row->user_id, c_al2fb_meta_fb_comments, $row->meta_value); update_user_meta($row->user_id, c_al2fb_meta_fb_likes, $row->meta_value); delete_user_meta($row->user_id, 'al2fb_integrate'); } } if ($version <= 3) { global $wpdb; $rows = $wpdb->get_results("SELECT ID FROM " . $wpdb->users); foreach ($rows as $row) update_user_meta($row->ID, c_al2fb_meta_like_faces, true); } if ($version <= 4) { $rows = $wpdb->get_results("SELECT user_id, meta_value FROM " . $wpdb->usermeta . " WHERE meta_key='" . c_al2fb_meta_trailer . "'"); foreach ($rows as $row) { $value = get_user_meta($row->user_id, c_al2fb_meta_trailer, true); update_user_meta($row->user_id, c_al2fb_meta_trailer, ' ' . $value); } } if ($version <= 5) { if (!get_option(c_al2fb_option_css)) update_option(c_al2fb_option_css, '.al2fb_widget_comments { } .al2fb_widget_comments li { } .al2fb_widget_picture { width: 32px; height: 32px; } .al2fb_widget_name { } .al2fb_widget_comment { } .al2fb_widget_date { font-size: smaller; } '); } if ($version < 6) update_option(c_al2fb_option_version, 6); } // 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_picture_default); 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_use_groups); delete_user_meta($user_ID, c_al2fb_meta_group); 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_shortlink); delete_user_meta($user_ID, c_al2fb_meta_add_new_page); delete_user_meta($user_ID, c_al2fb_meta_trailer); delete_user_meta($user_ID, c_al2fb_meta_hyperlink); delete_user_meta($user_ID, c_al2fb_meta_share_link); delete_user_meta($user_ID, c_al2fb_meta_fb_comments); delete_user_meta($user_ID, c_al2fb_meta_fb_comments_postback); delete_user_meta($user_ID, c_al2fb_meta_fb_comments_copy); delete_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink); delete_user_meta($user_ID, c_al2fb_meta_fb_likes); delete_user_meta($user_ID, c_al2fb_meta_post_likers); delete_user_meta($user_ID, c_al2fb_meta_post_like_button); delete_user_meta($user_ID, c_al2fb_meta_like_nohome); delete_user_meta($user_ID, c_al2fb_meta_like_noposts); delete_user_meta($user_ID, c_al2fb_meta_like_nopages); delete_user_meta($user_ID, c_al2fb_meta_like_noarchives); delete_user_meta($user_ID, c_al2fb_meta_like_nocategories); delete_user_meta($user_ID, c_al2fb_meta_like_layout); delete_user_meta($user_ID, c_al2fb_meta_like_faces); delete_user_meta($user_ID, c_al2fb_meta_like_width); delete_user_meta($user_ID, c_al2fb_meta_like_action); delete_user_meta($user_ID, c_al2fb_meta_like_font); delete_user_meta($user_ID, c_al2fb_meta_like_colorscheme); delete_user_meta($user_ID, c_al2fb_meta_like_link); delete_user_meta($user_ID, c_al2fb_meta_like_top); delete_user_meta($user_ID, c_al2fb_meta_like_iframe); delete_user_meta($user_ID, c_al2fb_meta_post_send_button); delete_user_meta($user_ID, c_al2fb_meta_post_combine_buttons); delete_user_meta($user_ID, c_al2fb_meta_like_box_width); delete_user_meta($user_ID, c_al2fb_meta_like_box_border); delete_user_meta($user_ID, c_al2fb_meta_like_box_noheader); delete_user_meta($user_ID, c_al2fb_meta_like_box_nostream); delete_user_meta($user_ID, c_al2fb_meta_comments_posts); delete_user_meta($user_ID, c_al2fb_meta_comments_width); delete_user_meta($user_ID, c_al2fb_meta_pile_size); delete_user_meta($user_ID, c_al2fb_meta_pile_width); delete_user_meta($user_ID, c_al2fb_meta_pile_rows); delete_user_meta($user_ID, c_al2fb_meta_reg_width); delete_user_meta($user_ID, c_al2fb_meta_login_width); delete_user_meta($user_ID, c_al2fb_meta_login_regurl); delete_user_meta($user_ID, c_al2fb_meta_login_redir); delete_user_meta($user_ID, c_al2fb_meta_login_html); delete_user_meta($user_ID, c_al2fb_meta_act_width); delete_user_meta($user_ID, c_al2fb_meta_act_height); delete_user_meta($user_ID, c_al2fb_meta_act_header); delete_user_meta($user_ID, c_al2fb_meta_act_recommend); delete_user_meta($user_ID, c_al2fb_meta_open_graph); delete_user_meta($user_ID, c_al2fb_meta_open_graph_type); delete_user_meta($user_ID, c_al2fb_meta_open_graph_admins); delete_user_meta($user_ID, c_al2fb_meta_exclude_default); delete_user_meta($user_ID, c_al2fb_meta_not_post_list); delete_user_meta($user_ID, c_al2fb_meta_fb_encoding); delete_user_meta($user_ID, c_al2fb_meta_fb_locale); delete_user_meta($user_ID, c_al2fb_meta_clean); delete_user_meta($user_ID, c_al2fb_meta_donated); delete_user_meta($user_ID, c_al2fb_meta_rated); delete_user_meta($user_ID, c_al2fb_meta_nospsn); delete_user_meta($user_ID, c_al2fb_meta_service); } } // Initialization function Init() { // I18n load_plugin_textdomain(c_al2fb_text_domain, false, dirname(plugin_basename(__FILE__)) . '/language/'); // Image request if (isset($_GET['al2fb_image'])) { $img = dirname(__FILE__) . '/wp-blue-s.png'; header('Content-type: image/png'); readfile($img); exit(); } // Facebook registration if (isset($_REQUEST['al2fb_reg'])) { self::Facebook_registration(); exit(); } // Facebook login if (isset($_REQUEST['al2fb_login'])) { self::Facebook_login(); exit(); } // Set default capability if (!get_option(c_al2fb_option_min_cap)) update_option(c_al2fb_option_min_cap, 'edit_posts'); // Disable shorcodes if Mingle forum is used $mingle = 'mingle-forum/wpf-main.php'; $plugins = get_option('active_plugins'); if (in_array($mingle, $plugins)) update_option(c_al2fb_option_noshortcode, true); // Enqueue style sheet if (is_admin()) { $css_name = $this->Change_extension(basename($this->main_file), '-admin.css'); $css_url = $this->plugin_url . '/' . $css_name; wp_register_style('al2fb_style_admin', $css_url); wp_enqueue_style('al2fb_style_admin'); } else { $upload_dir = wp_upload_dir(); $css_name = $this->Change_extension(basename($this->main_file), '.css'); if (file_exists($upload_dir['basedir'] . '/' . $css_name)) $css_url = $upload_dir['baseurl'] . '/' . $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'); } // Check user capability if (current_user_can(get_option(c_al2fb_option_min_cap))) { if (is_admin()) { // Initiate Facebook authorization if (isset($_REQUEST['al2fb_action']) && $_REQUEST['al2fb_action'] == 'init') { // Debug info update_option(c_al2fb_log_redir_init, date('c')); // Get current user global $user_ID; get_currentuserinfo(); // Redirect $auth_url = self::Authorize_url($user_ID); try { // Check if (ini_get('safe_mode') || ini_get('open_basedir')) update_option(c_al2fb_log_redir_check, 'No'); else { $response = self::Request($auth_url, '', 'GET'); update_option(c_al2fb_log_redir_check, date('c')); } // Redirect wp_redirect($auth_url); exit(); } catch (Exception $e) { // Register error update_option(c_al2fb_log_redir_check, $e->getMessage()); update_option(c_al2fb_last_error, $e->getMessage()); update_option(c_al2fb_last_error_time, date('c')); // Redirect $error_url = admin_url('tools.php?page=' . plugin_basename($this->main_file)); $error_url .= '&al2fb_action=error'; $error_url .= '&error=' . urlencode($e->getMessage()); wp_redirect($error_url); exit(); } } } // Handle Facebook authorization self::Authorize(); } } // Display admin messages function Admin_notices() { // Check user capability if (current_user_can(get_option(c_al2fb_option_min_cap))) { // Get current user global $user_ID; get_currentuserinfo(); // Check actions if (isset($_REQUEST['al2fb_action'])) { // Configuration if ($_REQUEST['al2fb_action'] == 'config') self::Action_config(); // Authorization else if ($_REQUEST['al2fb_action'] == 'authorize') self::Action_authorize(); // Mail debug info else if ($_REQUEST['al2fb_action'] == 'mail') self::Action_mail(); else if ($_REQUEST['al2fb_action'] == 'service') self::Action_service(); } self::Check_config(); } } // Save settings function Action_config() { // Security check check_admin_referer(c_al2fb_nonce_form); // Get current user global $user_ID; get_currentuserinfo(); // Default values if (empty($_POST[c_al2fb_meta_picture_type])) $_POST[c_al2fb_meta_picture_type] = 'post'; 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_use_groups])) $_POST[c_al2fb_meta_use_groups] = null; if (empty($_POST[c_al2fb_meta_group])) $_POST[c_al2fb_meta_group] = 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_shortlink])) $_POST[c_al2fb_meta_shortlink] = null; if (empty($_POST[c_al2fb_meta_add_new_page])) $_POST[c_al2fb_meta_add_new_page] = null; if (empty($_POST[c_al2fb_meta_trailer])) $_POST[c_al2fb_meta_trailer] = null; if (empty($_POST[c_al2fb_meta_hyperlink])) $_POST[c_al2fb_meta_hyperlink] = null; if (empty($_POST[c_al2fb_meta_share_link])) $_POST[c_al2fb_meta_share_link] = null; if (empty($_POST[c_al2fb_meta_fb_comments])) $_POST[c_al2fb_meta_fb_comments] = null; if (empty($_POST[c_al2fb_meta_fb_comments_postback])) $_POST[c_al2fb_meta_fb_comments_postback] = null; if (empty($_POST[c_al2fb_meta_fb_comments_copy])) $_POST[c_al2fb_meta_fb_comments_copy] = null; if (empty($_POST[c_al2fb_meta_fb_comments_nolink])) $_POST[c_al2fb_meta_fb_comments_nolink] = null; if (empty($_POST[c_al2fb_meta_fb_likes])) $_POST[c_al2fb_meta_fb_likes] = null; if (empty($_POST[c_al2fb_meta_post_likers])) $_POST[c_al2fb_meta_post_likers] = null; if (empty($_POST[c_al2fb_meta_post_like_button])) $_POST[c_al2fb_meta_post_like_button] = null; if (empty($_POST[c_al2fb_meta_like_nohome])) $_POST[c_al2fb_meta_like_nohome] = null; if (empty($_POST[c_al2fb_meta_like_noposts])) $_POST[c_al2fb_meta_like_noposts] = null; if (empty($_POST[c_al2fb_meta_like_nopages])) $_POST[c_al2fb_meta_like_nopages] = null; if (empty($_POST[c_al2fb_meta_like_noarchives])) $_POST[c_al2fb_meta_like_noarchives] = null; if (empty($_POST[c_al2fb_meta_like_nocategories])) $_POST[c_al2fb_meta_like_nocategories] = null; if (empty($_POST[c_al2fb_meta_like_layout])) $_POST[c_al2fb_meta_like_layout] = null; if (empty($_POST[c_al2fb_meta_like_faces])) $_POST[c_al2fb_meta_like_faces] = null; if (empty($_POST[c_al2fb_meta_like_action])) $_POST[c_al2fb_meta_like_action] = null; if (empty($_POST[c_al2fb_meta_like_font])) $_POST[c_al2fb_meta_like_font] = null; if (empty($_POST[c_al2fb_meta_like_colorscheme])) $_POST[c_al2fb_meta_like_colorscheme] = null; if (empty($_POST[c_al2fb_meta_like_top])) $_POST[c_al2fb_meta_like_top] = null; if (empty($_POST[c_al2fb_meta_post_send_button])) $_POST[c_al2fb_meta_post_send_button] = null; if (empty($_POST[c_al2fb_meta_post_combine_buttons])) $_POST[c_al2fb_meta_post_combine_buttons] = null; if (empty($_POST[c_al2fb_meta_like_box_noheader])) $_POST[c_al2fb_meta_like_box_noheader] = null; if (empty($_POST[c_al2fb_meta_like_box_nostream])) $_POST[c_al2fb_meta_like_box_nostream] = null; if (empty($_POST[c_al2fb_meta_pile_size])) $_POST[c_al2fb_meta_pile_size] = null; if (empty($_POST[c_al2fb_meta_act_header])) $_POST[c_al2fb_meta_act_header] = null; if (empty($_POST[c_al2fb_meta_act_recommend])) $_POST[c_al2fb_meta_act_recommend] = null; if (empty($_POST[c_al2fb_meta_open_graph])) $_POST[c_al2fb_meta_open_graph] = null; if (empty($_POST[c_al2fb_meta_exclude_default])) $_POST[c_al2fb_meta_exclude_default] = null; if (empty($_POST[c_al2fb_meta_not_post_list])) $_POST[c_al2fb_meta_not_post_list] = 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; if (empty($_POST[c_al2fb_meta_rated])) $_POST[c_al2fb_meta_rated] = null; if (empty($_POST[c_al2fb_meta_nospsn])) $_POST[c_al2fb_meta_nospsn] = null; $_POST[c_al2fb_meta_client_id] = trim($_POST[c_al2fb_meta_client_id]); $_POST[c_al2fb_meta_app_secret] = trim($_POST[c_al2fb_meta_app_secret]); $_POST[c_al2fb_meta_picture] = trim(stripslashes($_POST[c_al2fb_meta_picture])); $_POST[c_al2fb_meta_picture_default] = trim(stripslashes($_POST[c_al2fb_meta_picture_default])); $_POST[c_al2fb_meta_trailer] = rtrim(html_entity_decode(stripslashes($_POST[c_al2fb_meta_trailer]), ENT_QUOTES, get_bloginfo('charset'))); $_POST[c_al2fb_meta_like_width] = trim($_POST[c_al2fb_meta_like_width]); $_POST[c_al2fb_meta_like_link] = trim($_POST[c_al2fb_meta_like_link]); $_POST[c_al2fb_meta_like_box_width] = trim($_POST[c_al2fb_meta_like_box_width]); $_POST[c_al2fb_meta_like_box_border] = trim($_POST[c_al2fb_meta_like_box_border]); $_POST[c_al2fb_meta_comments_posts] = trim($_POST[c_al2fb_meta_comments_posts]); $_POST[c_al2fb_meta_comments_width] = trim($_POST[c_al2fb_meta_comments_width]); $_POST[c_al2fb_meta_pile_width] = trim($_POST[c_al2fb_meta_pile_width]); $_POST[c_al2fb_meta_pile_rows] = trim($_POST[c_al2fb_meta_pile_rows]); $_POST[c_al2fb_meta_reg_width] = trim($_POST[c_al2fb_meta_reg_width]); $_POST[c_al2fb_meta_login_width] = trim($_POST[c_al2fb_meta_login_width]); $_POST[c_al2fb_meta_login_regurl] = trim($_POST[c_al2fb_meta_login_regurl]); $_POST[c_al2fb_meta_login_redir] = trim($_POST[c_al2fb_meta_login_redir]); $_POST[c_al2fb_meta_login_html] = trim($_POST[c_al2fb_meta_login_html]); $_POST[c_al2fb_meta_act_width] = trim($_POST[c_al2fb_meta_act_width]); $_POST[c_al2fb_meta_act_height] = trim($_POST[c_al2fb_meta_act_height]); $_POST[c_al2fb_meta_open_graph_type] = trim($_POST[c_al2fb_meta_open_graph_type]); $_POST[c_al2fb_meta_open_graph_admins] = trim($_POST[c_al2fb_meta_open_graph_admins]); $_POST[c_al2fb_meta_fb_encoding] = trim($_POST[c_al2fb_meta_fb_encoding]); $_POST[c_al2fb_meta_fb_locale] = trim($_POST[c_al2fb_meta_fb_locale]); // Prevent losing selected page if (!self::Is_authorized($user_ID) || (get_user_meta($user_ID, c_al2fb_meta_use_groups, true) && get_user_meta($user_ID, c_al2fb_meta_group, true))) $_POST[c_al2fb_meta_page] = get_user_meta($user_ID, c_al2fb_meta_page, true); // Prevent losing selected group if (!self::Is_authorized($user_ID) || !get_user_meta($user_ID, c_al2fb_meta_use_groups, true)) $_POST[c_al2fb_meta_group] = get_user_meta($user_ID, c_al2fb_meta_group, true); // App ID or secret changed 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); // Use groups changed if ($_POST[c_al2fb_meta_use_groups] && !get_user_meta($user_ID, c_al2fb_meta_use_groups, true)) if (!get_user_meta($user_ID, c_al2fb_meta_group, true)) delete_user_meta($user_ID, c_al2fb_meta_access_token); // Like or send button enabled if ((!get_user_meta($user_ID, c_al2fb_meta_post_like_button, true) && !empty($_POST[c_al2fb_meta_post_like_button])) || (!get_user_meta($user_ID, c_al2fb_meta_post_send_button, true) && !empty($_POST[c_al2fb_meta_post_send_button]))) $_POST[c_al2fb_meta_open_graph] = true; // 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_picture_default, $_POST[c_al2fb_meta_picture_default]); 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_use_groups, $_POST[c_al2fb_meta_use_groups]); update_user_meta($user_ID, c_al2fb_meta_group, $_POST[c_al2fb_meta_group]); 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_shortlink, $_POST[c_al2fb_meta_shortlink]); update_user_meta($user_ID, c_al2fb_meta_add_new_page, $_POST[c_al2fb_meta_add_new_page]); update_user_meta($user_ID, c_al2fb_meta_trailer, $_POST[c_al2fb_meta_trailer]); update_user_meta($user_ID, c_al2fb_meta_hyperlink, $_POST[c_al2fb_meta_hyperlink]); update_user_meta($user_ID, c_al2fb_meta_share_link, $_POST[c_al2fb_meta_share_link]); update_user_meta($user_ID, c_al2fb_meta_fb_comments, $_POST[c_al2fb_meta_fb_comments]); update_user_meta($user_ID, c_al2fb_meta_fb_comments_postback, $_POST[c_al2fb_meta_fb_comments_postback]); update_user_meta($user_ID, c_al2fb_meta_fb_comments_copy, $_POST[c_al2fb_meta_fb_comments_copy]); update_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, $_POST[c_al2fb_meta_fb_comments_nolink]); update_user_meta($user_ID, c_al2fb_meta_fb_likes, $_POST[c_al2fb_meta_fb_likes]); update_user_meta($user_ID, c_al2fb_meta_post_likers, $_POST[c_al2fb_meta_post_likers]); update_user_meta($user_ID, c_al2fb_meta_post_like_button, $_POST[c_al2fb_meta_post_like_button]); update_user_meta($user_ID, c_al2fb_meta_like_nohome, $_POST[c_al2fb_meta_like_nohome]); update_user_meta($user_ID, c_al2fb_meta_like_noposts, $_POST[c_al2fb_meta_like_noposts]); update_user_meta($user_ID, c_al2fb_meta_like_nopages, $_POST[c_al2fb_meta_like_nopages]); update_user_meta($user_ID, c_al2fb_meta_like_noarchives, $_POST[c_al2fb_meta_like_noarchives]); update_user_meta($user_ID, c_al2fb_meta_like_nocategories, $_POST[c_al2fb_meta_like_nocategories]); update_user_meta($user_ID, c_al2fb_meta_like_layout, $_POST[c_al2fb_meta_like_layout]); update_user_meta($user_ID, c_al2fb_meta_like_faces, $_POST[c_al2fb_meta_like_faces]); update_user_meta($user_ID, c_al2fb_meta_like_width, $_POST[c_al2fb_meta_like_width]); update_user_meta($user_ID, c_al2fb_meta_like_action, $_POST[c_al2fb_meta_like_action]); update_user_meta($user_ID, c_al2fb_meta_like_font, $_POST[c_al2fb_meta_like_font]); update_user_meta($user_ID, c_al2fb_meta_like_colorscheme, $_POST[c_al2fb_meta_like_colorscheme]); update_user_meta($user_ID, c_al2fb_meta_like_link, $_POST[c_al2fb_meta_like_link]); update_user_meta($user_ID, c_al2fb_meta_like_top, $_POST[c_al2fb_meta_like_top]); update_user_meta($user_ID, c_al2fb_meta_post_send_button, $_POST[c_al2fb_meta_post_send_button]); update_user_meta($user_ID, c_al2fb_meta_post_combine_buttons, $_POST[c_al2fb_meta_post_combine_buttons]); update_user_meta($user_ID, c_al2fb_meta_like_box_width, $_POST[c_al2fb_meta_like_box_width]); update_user_meta($user_ID, c_al2fb_meta_like_box_border, $_POST[c_al2fb_meta_like_box_border]); update_user_meta($user_ID, c_al2fb_meta_like_box_noheader, $_POST[c_al2fb_meta_like_box_noheader]); update_user_meta($user_ID, c_al2fb_meta_like_box_nostream, $_POST[c_al2fb_meta_like_box_nostream]); update_user_meta($user_ID, c_al2fb_meta_comments_posts, $_POST[c_al2fb_meta_comments_posts]); update_user_meta($user_ID, c_al2fb_meta_comments_width, $_POST[c_al2fb_meta_comments_width]); update_user_meta($user_ID, c_al2fb_meta_pile_size, $_POST[c_al2fb_meta_pile_size]); update_user_meta($user_ID, c_al2fb_meta_pile_width, $_POST[c_al2fb_meta_pile_width]); update_user_meta($user_ID, c_al2fb_meta_pile_rows, $_POST[c_al2fb_meta_pile_rows]); update_user_meta($user_ID, c_al2fb_meta_reg_width, $_POST[c_al2fb_meta_reg_width]); update_user_meta($user_ID, c_al2fb_meta_login_width, $_POST[c_al2fb_meta_login_width]); update_user_meta($user_ID, c_al2fb_meta_login_regurl, $_POST[c_al2fb_meta_login_regurl]); update_user_meta($user_ID, c_al2fb_meta_login_redir, $_POST[c_al2fb_meta_login_redir]); update_user_meta($user_ID, c_al2fb_meta_login_html, $_POST[c_al2fb_meta_login_html]); update_user_meta($user_ID, c_al2fb_meta_act_width, $_POST[c_al2fb_meta_act_width]); update_user_meta($user_ID, c_al2fb_meta_act_height, $_POST[c_al2fb_meta_act_height]); update_user_meta($user_ID, c_al2fb_meta_act_header, $_POST[c_al2fb_meta_act_header]); update_user_meta($user_ID, c_al2fb_meta_act_recommend, $_POST[c_al2fb_meta_act_recommend]); update_user_meta($user_ID, c_al2fb_meta_open_graph, $_POST[c_al2fb_meta_open_graph]); update_user_meta($user_ID, c_al2fb_meta_open_graph_type, $_POST[c_al2fb_meta_open_graph_type]); update_user_meta($user_ID, c_al2fb_meta_open_graph_admins, $_POST[c_al2fb_meta_open_graph_admins]); update_user_meta($user_ID, c_al2fb_meta_exclude_default, $_POST[c_al2fb_meta_exclude_default]); update_user_meta($user_ID, c_al2fb_meta_not_post_list, $_POST[c_al2fb_meta_not_post_list]); update_user_meta($user_ID, c_al2fb_meta_fb_encoding, $_POST[c_al2fb_meta_fb_encoding]); update_user_meta($user_ID, c_al2fb_meta_fb_locale, $_POST[c_al2fb_meta_fb_locale]); 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_user_meta($user_ID, c_al2fb_meta_rated, $_POST[c_al2fb_meta_rated]); update_user_meta($user_ID, c_al2fb_meta_nospsn, $_POST[c_al2fb_meta_nospsn]); if (isset($_REQUEST['debug'])) { if (empty($_POST[c_al2fb_meta_access_token])) $_POST[c_al2fb_meta_access_token] = null; $_POST[c_al2fb_meta_access_token] = trim($_POST[c_al2fb_meta_access_token]); update_user_meta($user_ID, c_al2fb_meta_access_token, $_POST[c_al2fb_meta_access_token]); } // Update admin options if (current_user_can('manage_options')) { if (empty($_POST[c_al2fb_option_app_share])) $_POST[c_al2fb_option_app_share] = null; else $_POST[c_al2fb_option_app_share] = $user_ID; if (is_multisite()) update_site_option(c_al2fb_option_app_share, $_POST[c_al2fb_option_app_share]); else update_option(c_al2fb_option_app_share, $_POST[c_al2fb_option_app_share]); if (empty($_POST[c_al2fb_option_timeout])) $_POST[c_al2fb_option_timeout] = null; 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; if (empty($_POST[c_al2fb_option_noverifypeer])) $_POST[c_al2fb_option_noverifypeer] = null; if (empty($_POST[c_al2fb_option_shortcode_widget])) $_POST[c_al2fb_option_shortcode_widget] = null; if (empty($_POST[c_al2fb_option_noshortcode])) $_POST[c_al2fb_option_noshortcode] = null; if (empty($_POST[c_al2fb_option_optout])) $_POST[c_al2fb_option_optout] = null; $_POST[c_al2fb_option_msg_refresh] = trim($_POST[c_al2fb_option_msg_refresh]); $_POST[c_al2fb_option_max_descr] = trim($_POST[c_al2fb_option_max_descr]); $_POST[c_al2fb_option_max_text] = trim($_POST[c_al2fb_option_max_text]); $_POST[c_al2fb_option_exclude_type] = trim($_POST[c_al2fb_option_exclude_type]); $_POST[c_al2fb_option_exclude_cat] = trim($_POST[c_al2fb_option_exclude_cat]); $_POST[c_al2fb_option_css] = trim($_POST[c_al2fb_option_css]); update_option(c_al2fb_option_timeout, $_POST[c_al2fb_option_timeout]); update_option(c_al2fb_option_nonotice, $_POST[c_al2fb_option_nonotice]); update_option(c_al2fb_option_min_cap, $_POST[c_al2fb_option_min_cap]); update_option(c_al2fb_option_msg_refresh, $_POST[c_al2fb_option_msg_refresh]); update_option(c_al2fb_option_max_descr, $_POST[c_al2fb_option_max_descr]); update_option(c_al2fb_option_max_text, $_POST[c_al2fb_option_max_text]); update_option(c_al2fb_option_exclude_type, $_POST[c_al2fb_option_exclude_type]); update_option(c_al2fb_option_exclude_cat, $_POST[c_al2fb_option_exclude_cat]); update_option(c_al2fb_option_noverifypeer, $_POST[c_al2fb_option_noverifypeer]); update_option(c_al2fb_option_shortcode_widget, $_POST[c_al2fb_option_shortcode_widget]); update_option(c_al2fb_option_noshortcode, $_POST[c_al2fb_option_noshortcode]); update_option(c_al2fb_option_optout, $_POST[c_al2fb_option_optout]); update_option(c_al2fb_option_css, $_POST[c_al2fb_option_css]); if (isset($_REQUEST['debug'])) { if (empty($_POST[c_al2fb_option_siteurl])) $_POST[c_al2fb_option_siteurl] = null; if (empty($_POST[c_al2fb_option_nocurl])) $_POST[c_al2fb_option_nocurl] = null; if (empty($_POST[c_al2fb_option_use_pp])) $_POST[c_al2fb_option_use_pp] = null; if (empty($_POST[c_al2fb_option_debug])) $_POST[c_al2fb_option_debug] = null; update_option(c_al2fb_option_siteurl, $_POST[c_al2fb_option_siteurl]); update_option(c_al2fb_option_nocurl, $_POST[c_al2fb_option_nocurl]); update_option(c_al2fb_option_use_pp, $_POST[c_al2fb_option_use_pp]); update_option(c_al2fb_option_debug, $_POST[c_al2fb_option_debug]); } } // Show result echo '

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

'; } // Get token function Action_authorize() { // Get current user global $user_ID; get_currentuserinfo(); // Server-side flow authorization if (isset($_REQUEST['code'])) { try { // Get & store token $access_token = self::Get_fb_token($user_ID); update_option(c_al2fb_log_auth_time, date('c')); update_user_meta($user_ID, c_al2fb_meta_access_token, $access_token); if (get_option(c_al2fb_option_version) <= 6) update_option(c_al2fb_option_version, 7); delete_option(c_al2fb_last_error); delete_option(c_al2fb_last_error_time); echo '

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

'; } catch (Exception $e) { delete_user_meta($user_ID, c_al2fb_meta_access_token); update_option(c_al2fb_last_error, $e->getMessage()); update_option(c_al2fb_last_error_time, date('c')); echo '

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

'; } } // Authorization error else if (isset($_REQUEST['error'])) { delete_user_meta($user_ID, c_al2fb_meta_access_token); $faq = 'http://wordpress.org/extend/plugins/add-link-to-facebook/faq/'; $msg = stripslashes($_REQUEST['error_description']); $msg .= ' error: ' . stripslashes($_REQUEST['error']); $msg .= ' reason: ' . stripslashes($_REQUEST['error_reason']); update_option(c_al2fb_last_error, $msg); update_option(c_al2fb_last_error_time, date('c')); $msg .= '

Most errors are described in the FAQ'; echo '

' . htmlspecialchars($msg, ENT_QUOTES, get_bloginfo('charset')) . '

'; } } // Send debug info function Action_mail() { // Check security check_admin_referer(c_al2fb_nonce_form); // Build headers $headers = 'From: ' . stripslashes($_POST[c_al2fb_mail_name]) . '<' . stripslashes($_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 = 'Add Link to Facebook'; $message .= '

' . nl2br(htmlspecialchars(stripslashes($_POST[c_al2fb_mail_msg]), ENT_QUOTES, get_bloginfo('charset'))) . '

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

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

'; else echo '

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

'; } // Handle service message function Action_service() { // Security check check_admin_referer(c_al2fb_nonce_form); // Get current user global $user_ID; get_currentuserinfo(); // Check messages $msgs = get_user_meta($user_ID, c_al2fb_meta_service, false); if ($msgs) foreach ($msgs as $msg) if ($msg['id'] == $_POST['al2fb_msgid']) if ($msg['report'] && (isset($msg['userid']) ? $msg['userid'] == $user_ID : true)) try { // Send report $query = http_build_query(array( 'action' => 'report', 'api' => 1, 'url' => self::Redirect_uri(), 'userid' => $user_ID, 'id' => $_POST['al2fb_msgid'], 'choice' => $_POST['al2fb_choice'], 'hash' => md5(AUTH_KEY ? AUTH_KEY : get_bloginfo('url')) ), '', '&'); $response = self::Request('http://al2fb.bokhorst.biz/', $query, 'POST'); $service = json_decode($response); if (isset($service->status) && $service->status == 'ok') { // Check response $text = __('Settings updated', c_al2fb_text_domain); $func = null; if ($_POST['al2fb_choice'] == 'yes') { if (isset($msg['yes_text'])) $text = $msg['yes_text']; if (isset($msg['yes_func'])) $func = array(&$this, $msg['yes_func']); } else { if (isset($msg['no_text'])) $text = $msg['no_text']; if (isset($msg['no_func'])) $func = array(&$this, $msg['no_func']); } // Do action if (is_callable($func)) $show = call_user_func($func, $msg); else $show = true; if ($show) echo '

' . $text . '

'; // Delete the message delete_user_meta($user_ID, c_al2fb_meta_service, $msg); } } catch (Exception $e) { if ($this->debug) print_r($e); } else delete_user_meta($user_ID, c_al2fb_meta_service, $msg); } function eula_yes($msg) { return true; } function eula_no($msg) { return true; } // Display notices function Check_config() { // Get current user global $user_ID; get_currentuserinfo(); // Check config/authorization $uri = $_SERVER['REQUEST_URI']; $url = 'tools.php?page=' . plugin_basename($this->main_file); $nonotice = get_option(c_al2fb_option_nonotice); if (is_multisite()) $nonotice = $nonotice || get_site_option(c_al2fb_option_app_share); else $nonotice = $nonotice || get_option(c_al2fb_option_app_share); $donotice = ($nonotice ? strpos($uri, $url) !== false : true); if ($donotice) { 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 (!self::Is_authorized($user_ID)) { $notice = __('needs authorization', c_al2fb_text_domain); $anchor = 'authorize'; } else { $version = get_option(c_al2fb_option_version); if ($version && $version <= 6) { $notice = __('should be authorized again to show Facebook messages in the widget', c_al2fb_text_domain); $anchor = 'authorize'; } } if (!empty($notice)) { echo '

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

'; } } // Check for error if (isset($_REQUEST['al2fb_action']) && $_REQUEST['al2fb_action'] == 'error') { $faq = 'http://wordpress.org/extend/plugins/add-link-to-facebook/faq/'; $msg = htmlspecialchars(stripslashes($_REQUEST['error']), ENT_QUOTES, get_bloginfo('charset')); $msg .= '

Most errors are described in the FAQ'; echo '

' . $msg . '

'; } // Check for post errors $posts = new WP_Query(array( 'author' => $user_ID, '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(get_the_title($posts->post->ID), null, null, $posts->post->ID); echo ': ' . htmlspecialchars($error, ENT_QUOTES, get_bloginfo('charset')) . '

'; } } // Check for rating notice if ($donotice && !get_user_meta($user_ID, c_al2fb_meta_rated, true)) { echo '

'; $msg = __('If you like the Add Link to Facebook plugin, please rate it on wordpress.org.
If the average rating is low, it makes no sense to support this plugin any longer.
You can disable this notice by checking the option "I have rated this plugin" on the settings page.', c_al2fb_text_domain); $msg = str_replace('[wordpress]', 'http://wordpress.org/extend/plugins/add-link-to-facebook/', $msg); $msg = str_replace('[settings]', $url, $msg); echo $msg . '

'; } // Get messages $msgs = get_user_meta($user_ID, c_al2fb_meta_service, false); // Convert messages for ($i = 0; $i < count($msgs); $i++) if (is_object($msgs[$i])) { delete_user_meta($user_ID, c_al2fb_meta_service, $msgs[$i]); $msgs[$i] = json_decode(json_encode($msgs[$i]), true); add_user_meta($user_ID, c_al2fb_meta_service, $msgs[$i]); } // Display messages if ($msgs) foreach ($msgs as $msg) { ?>

main_file, array(&$this, 'Administration')); } function Plugin_action_links($links, $file) { if ($file == plugin_basename($this->main_file)) { if (current_user_can(get_option(c_al2fb_option_min_cap))) { // Get current user global $user_ID; get_currentuserinfo(); // Check for shared app if (is_multisite()) $shared_user_ID = get_site_option(c_al2fb_option_app_share); else $shared_user_ID = get_option(c_al2fb_option_app_share); if (!$shared_user_ID || $shared_user_ID == $user_ID) { // Add settings link $config_url = admin_url('tools.php?page=' . plugin_basename($this->main_file)); $links[] = '' . __('Settings', c_al2fb_text_domain) . ''; } } } return $links; } // Handle option page function Administration() { // Handle service message if (isset($_REQUEST['al2fb_action']) && $_REQUEST['al2fb_action'] == 'service') { echo '
'; echo '

' . __('Add Link to Facebook', c_al2fb_text_domain) . '

'; echo '' . __('Go to dashboard', c_al2fb_text_domain) . ''; echo '
'; return; } // Security check if (!current_user_can(get_option(c_al2fb_option_min_cap))) die('Unauthorized'); // Sustainable Plugins Sponsorship Network self::Render_SPSN(); ?>

'; echo __('Only this user can access the settings:', c_al2fb_text_domain); echo ' ' . $userdata->user_login . ' (id=' . $shared_user_ID . ')

'; echo ''; return; } // Get settings $charset = get_bloginfo('charset'); $config_url = admin_url('tools.php?page=' . plugin_basename($this->main_file)); if (isset($_REQUEST['debug'])) $config_url .= '&debug=1'; // Decode picture type $pic_type = get_user_meta($user_ID, c_al2fb_meta_picture_type, true); $pic_wordpress = ($pic_type == 'wordpress' ? ' checked' : ''); $pic_media = ($pic_type == 'media' ? ' checked' : ''); $pic_featured = ($pic_type == 'featured' ? ' checked' : ''); $pic_facebook = ($pic_type == 'facebook' ? ' checked' : ''); $pic_post = ($pic_type == 'post' ? ' checked' : ''); $pic_avatar = ($pic_type == 'avatar' ? ' checked' : ''); $pic_userphoto = ($pic_type == 'userphoto' ? ' checked' : ''); $pic_custom = ($pic_type == 'custom' ? ' checked' : ''); if (!current_theme_supports('post-thumbnails') || !function_exists('get_post_thumbnail_id') || !function_exists('wp_get_attachment_image_src')) $pic_featured .= ' disabled'; if (!in_array('user-photo/user-photo.php', get_option('active_plugins'))) $pic_userphoto .= ' disabled'; // Like button $like_layout = get_user_meta($user_ID, c_al2fb_meta_like_layout, true); $like_layout_standard = ($like_layout == 'standard' ? ' checked' : ''); $like_layout_button = ($like_layout == 'button_count' ? ' checked' : ''); $like_layout_box = ($like_layout == 'box_count' ? ' checked' : ''); $like_action = get_user_meta($user_ID, c_al2fb_meta_like_action, true); $like_action_like = ($like_action == 'like' ? ' checked' : ''); $like_action_recommend = ($like_action == 'recommend' ? ' checked' : ''); $like_font = get_user_meta($user_ID, c_al2fb_meta_like_font, true); $like_color = get_user_meta($user_ID, c_al2fb_meta_like_colorscheme, true); $like_color_light = ($like_color == 'light' ? ' checked' : ''); $like_color_dark = ($like_color == 'dark' ? ' checked' : ''); // Comment link option $comments_nolink = get_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, true); if (empty($comments_nolink)) $comments_nolink = 'author'; else if ($comments_nolink == 'on') $comments_nolink = 'none'; $comments_nolink_none = ($comments_nolink == 'none' ? ' checked' : ''); $comments_nolink_author = ($comments_nolink == 'author' ? ' checked' : ''); $comments_nolink_link = ($comments_nolink == 'link' ? ' checked' : ''); // Face pile $pile_size = get_user_meta($user_ID, c_al2fb_meta_pile_size, true); // Check connectivity if (!ini_get('allow_url_fopen') && !function_exists('curl_init')) echo '

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

'; self::Render_debug_info(); self::Render_resources(); ?>

' . __('Plugin is authorized', c_al2fb_text_domain) . '
'; // Get page name try { $me = self::Get_fb_me($user_ID, false); if ($me != null) { _e('Links will be added to', c_al2fb_text_domain); echo ' ' . 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) . '

'; } } ?>

Flattr this
Bitcoin: 19Y8QKKK4cpBMZ64UtAT4C6MEwknUerNDe

Site URL & Domain:', c_al2fb_text_domain); ?>
My Apps\' and then to \'Set Up New App\'', c_al2fb_text_domain); ?>

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

'; } if (current_user_can('manage_options')) { ?>
name, ENT_QUOTES, $charset); ?>
/>


>
>
>
>
>
>
>
>


/>

/>

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

'; } ?>

/>
""
/>

/>
/> Experimental!
/>
/>

/>
/>
/>
>

>
>

/>
/>

/>
>
>
>
>
>
/>
/>
/>

/>
/>




/>
/>

/>
/>
/>
/>
/>
/>
>
>

/>


/>
/>


 ()
/>
/>
/>
/>


/>





/>
/>
/>
/>

/>
/>
/>
/>


Flattr this



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, '/'); } // Generate authorization secret function Authorize_secret() { return 'al2fb_auth_' . substr(md5(AUTH_KEY ? AUTH_KEY : get_bloginfo('url')), 0, 10); } // Handle Facebook authorization function Authorize() { parse_str($_SERVER['QUERY_STRING'], $query); if (isset($query['state']) && strpos($query['state'], self::Authorize_secret()) !== 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(); } } // Request token function Get_fb_token($user_ID) { $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; } // Get application properties function Get_fb_application($user_ID) { $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 wall, page or group name and cache function Get_fb_me_cached($user_ID, $self) { $page_id = self::Get_page_id($user_ID, $self); $me_key = c_al2fb_transient_cache . md5('me' . $user_ID . $page_id); $me = get_transient($me_key); if ($me === false) { $me = self::Get_fb_me($user_ID, $self); if ($me != null) { $duration = intval(get_option(c_al2fb_option_msg_refresh)); if (!$duration) $duration = 10; set_transient($me_key, $me, $duration * 60); } } return $me; } // Get wall, page or group name function Get_fb_me($user_ID, $self) { $page_id = self::Get_page_id($user_ID, $self); $url = 'https://graph.facebook.com/' . $page_id; $token = self::Get_access_token_by_page($user_ID, $page_id); if (empty($token)) return null; $query = http_build_query(array('access_token' => $token), '', '&'); $response = self::Request($url, $query, 'GET'); $me = json_decode($response); if ($me) { if (empty($me->link)) // Group $me->link = 'http://www.facebook.com/home.php?sk=group_' . $page_id; return $me; } else throw new Exception('Page "' . $page_id . '" not found'); } function Get_page_id($user_ID, $self) { if (get_user_meta($user_ID, c_al2fb_meta_use_groups, true)) $page_id = get_user_meta($user_ID, c_al2fb_meta_group, true); if (empty($page_id)) $page_id = get_user_meta($user_ID, c_al2fb_meta_page, true); if ($self || empty($page_id)) $page_id = 'me'; return $page_id; } // Get page list function Get_fb_pages($user_ID) { $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; } // Get group list function Get_fb_groups($user_ID) { $url = 'https://graph.facebook.com/me/groups'; $query = http_build_query(array( 'access_token' => get_user_meta($user_ID, c_al2fb_meta_access_token, true) ), '', '&'); $response = self::Request($url, $query, 'GET'); $groups = json_decode($response); return $groups; } // Get comments and cache function Get_fb_comments_cached($user_ID, $link_id) { // Get (cached) comments $fb_key = c_al2fb_transient_cache . md5( 'c' . $link_id); $fb_comments = get_transient($fb_key); if ($this->debug) $fb_comments = false; if ($fb_comments === false) { $fb_comments = self::Get_fb_comments($user_ID, $link_id); $duration = intval(get_option(c_al2fb_option_msg_refresh)); if (!$duration) $duration = 10; set_transient($fb_key, $fb_comments, $duration * 60); } return $fb_comments; } // Get comments function Get_fb_comments($user_ID, $id) { $url = 'https://graph.facebook.com/' . $id . '/comments'; $query = http_build_query(array( 'access_token' => get_user_meta($user_ID, c_al2fb_meta_access_token, true) ), '', '&'); $response = self::Request($url, $query, 'GET'); $comments = json_decode($response); return $comments; } // Get likes and cache function Get_fb_likes_cached($user_ID, $link_id) { // Get (cached) likes $fb_key = c_al2fb_transient_cache . md5('l' . $link_id); $fb_likes = get_transient($fb_key); if ($this->debug) $fb_likes = false; if ($fb_likes === false) { $fb_likes = self::Get_fb_likes($user_ID, $link_id); $duration = intval(get_option(c_al2fb_option_msg_refresh)); if (!$duration) $duration = 10; set_transient($fb_key, $fb_likes, $duration * 60); } return $fb_likes; } // Get likes function Get_fb_likes($user_ID, $id) { $url = 'https://graph.facebook.com/' . $id . '/likes'; $query = http_build_query(array( 'access_token' => get_user_meta($user_ID, c_al2fb_meta_access_token, true) ), '', '&'); $response = self::Request($url, $query, 'GET'); $likes = json_decode($response); return $likes; } function Get_fb_feed($user_ID) { if (get_user_meta($user_ID, c_al2fb_meta_use_groups, true)) $page_id = get_user_meta($user_ID, c_al2fb_meta_group, true); if (empty($page_id)) $page_id = get_user_meta($user_ID, c_al2fb_meta_page, true); if (empty($page_id)) $page_id = 'me'; $url = 'https://graph.facebook.com/' . $page_id . '/feed'; $token = self::Get_access_token_by_page($user_ID, $page_id); if (empty($token)) return null; $query = http_build_query(array('access_token' => $token), '', '&'); $response = self::Request($url, $query, 'GET'); $posts = json_decode($response); return $posts; } // Get Facebook picture function Get_fb_picture_url_cached($id, $size) { $fb_key = c_al2fb_transient_cache . md5('p' . $id); $fb_url = get_transient($fb_key); if ($this->debug) $fb_url = false; if ($fb_url === false) { $fb_url = self::Get_fb_picture_url($id, 'normal'); $duration = intval(get_option(c_al2fb_option_msg_refresh)); if (!$duration) $duration = 10; set_transient($fb_key, $fb_url, $duration * 60); } return $fb_url; } // Get Facebook picture // Returns a HTTP 302 with the URL of the user's profile picture (use ?type=square | small | normal | large to request a different photo) function Get_fb_picture_url($id, $size) { $url = 'https://graph.facebook.com/' . $id . '/picture?' . $size; if (function_exists('curl_init') && !get_option(c_al2fb_option_nocurl)) { $timeout = get_option(c_al2fb_option_timeout); if (!$timeout) $timeout = 30; $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_HEADER, 1); curl_setopt($c, CURLOPT_NOBODY, 1); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_TIMEOUT, $timeout); $headers = curl_exec($c); curl_close ($c); if (preg_match('/Location: (.*)/', $headers, $location)) return trim($location[1]); else return false; } else if (function_exists('get_header') && ini_get('allow_url_fopen')) { $headers = get_headers($url, true); if (isset($headers['Location'])) return $headers['Location']; else return false; } else return false; } // Add checkboxes function Post_submitbox_misc_actions() { global $post; // Check exclusion $ex_custom_types = explode(',', get_option(c_al2fb_option_exclude_type)); if (in_array($post->post_type, $ex_custom_types)) return; // Get user $user_ID = self::Get_user_ID($post); // Get exclude indication $exclude = get_post_meta($post->ID, c_al2fb_meta_exclude, true); $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); if (!$link_id && get_user_meta($user_ID, c_al2fb_meta_exclude_default, true)) $exclude = true; $chk_exclude = ($exclude ? ' checked' : ''); // Get no like button indication $chk_nolike = (get_post_meta($post->ID, c_al2fb_meta_nolike, true) ? ' checked' : ''); $chk_nointegrate = (get_post_meta($post->ID, c_al2fb_meta_nointegrate, true) ? ' checked' : ''); // Check if errors $error = get_post_meta($post->ID, c_al2fb_meta_error, true); global $wp_version; if (version_compare($wp_version, '3.2') < 0) { ?>
/>
/>
/>




' . __('Yes', c_al2fb_text_domain) . ''; else echo '' . __('No', c_al2fb_text_domain) . ''; if ($link_id) { $post = get_post($post_ID); $user_ID = self::Get_user_ID($post); // Show number of comments if (get_user_meta($user_ID, c_al2fb_meta_fb_comments, true)) { $fb_comments = self::Get_comments_or_likes($post, false); if (!empty($fb_comments)) echo '
' . count($fb_comments->data) . ' ' . __('comments', c_al2fb_text_domain) . ''; } // Show number of likes if (get_user_meta($user_ID, c_al2fb_meta_fb_likes, true)) { $fb_likes = self::Get_comments_or_likes($post, true); if (!empty($fb_likes)) echo '
' . count($fb_comments->data) . ' ' . __('likes', 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, 'Meta_box'), 'post'); add_meta_box( 'al2fb_meta', __('Add Link to Facebook', c_al2fb_text_domain), array(&$this, 'Meta_box'), 'page'); } // Display attached image selector function Meta_box() { global $post; // Security wp_nonce_field(plugin_basename(__FILE__), c_al2fb_nonce_form); if ($this->debug) { $texts = self::Get_texts($post); echo 'Original: ' . htmlspecialchars($post->post_content) . '
'; echo 'Processed: ' . htmlspecialchars($texts['content']) . '
'; } if (function_exists('wp_get_attachment_image_src')) { // Get attached images $images = &get_children('post_type=attachment&post_mime_type=image&order=ASC&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 if ($images) foreach ($images as $attachment_id => $attachment) { $picture = wp_get_attachment_image_src($attachment_id, 'thumbnail'); echo '
'; echo ''; echo '
'; echo ''; echo '
'; echo '' . $picture[1] . ' x ' . $picture[2] . ''; echo '
'; } echo '
'; } } else echo 'wp_get_attachment_image_src does not exist'; // Custom excerpt $excerpt = get_post_meta($post->ID, c_al2fb_meta_excerpt, true); echo '

' . __('Custom exerpt', c_al2fb_text_domain) . '

'; echo ''; // Custom text $text = get_post_meta($post->ID, c_al2fb_meta_text, true); echo '

' . __('Custom text', c_al2fb_text_domain) . '

'; echo ''; } // Save indications & selected attached image function Save_post($post_id) { // Security checks $nonce = (isset($_POST[c_al2fb_nonce_form]) ? $_POST[c_al2fb_nonce_form] : null); if (!wp_verify_nonce($nonce, 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; // Check exclusion $post = get_post($post_id); $ex_custom_types = explode(',', get_option(c_al2fb_option_exclude_type)); if (in_array($post->post_type, $ex_custom_types)) return; // Process exclude indication if (isset($_POST[c_al2fb_meta_exclude]) && $_POST[c_al2fb_meta_exclude]) update_post_meta($post_id, c_al2fb_meta_exclude, true); else delete_post_meta($post_id, c_al2fb_meta_exclude); // Process no like indication if (isset($_POST[c_al2fb_meta_nolike]) && $_POST[c_al2fb_meta_nolike]) update_post_meta($post_id, c_al2fb_meta_nolike, true); else delete_post_meta($post_id, c_al2fb_meta_nolike); // Process no integrate indication if (isset($_POST[c_al2fb_meta_nointegrate]) && $_POST[c_al2fb_meta_nointegrate]) update_post_meta($post_id, c_al2fb_meta_nointegrate, true); else delete_post_meta($post_id, c_al2fb_meta_nointegrate); // Clear errors if (isset($_POST[c_al2fb_action_clear]) && $_POST[c_al2fb_action_clear]) delete_post_meta($post_id, c_al2fb_meta_error); // Persist data if (empty($_POST['al2fb_image_id'])) delete_post_meta($post_id, c_al2fb_meta_image_id); else update_post_meta($post_id, c_al2fb_meta_image_id, $_POST['al2fb_image_id']); if (isset($_POST['al2fb_excerpt']) && !empty($_POST['al2fb_excerpt'])) update_post_meta($post_id, c_al2fb_meta_excerpt, trim($_POST['al2fb_excerpt'])); else delete_post_meta($post_id, c_al2fb_meta_excerpt); if (isset($_POST['al2fb_text']) && !empty($_POST['al2fb_text'])) update_post_meta($post_id, c_al2fb_meta_text, trim($_POST['al2fb_text'])); else delete_post_meta($post_id, c_al2fb_meta_text); } // Remote publish & custom action function Remote_publish($post_ID) { $post = get_post($post_ID); // Only if published if ($post->post_status == 'publish') self::Publish_post($post); } // Workaround function Future_to_publish($post_ID) { $post = get_post($post_ID); // Delegate self::Transition_post_status('publish', 'future', $post); } // Handle post status change function Transition_post_status($new_status, $old_status, $post) { $user_ID = self::Get_user_ID($post); $update = (isset($_POST[c_al2fb_action_update]) && $_POST[c_al2fb_action_update]); $delete = (isset($_POST[c_al2fb_action_delete]) && $_POST[c_al2fb_action_delete]); // Security check if (self::user_can($user_ID, get_option(c_al2fb_option_min_cap))) { // Add, update or delete link if ($update || $delete) { $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); if (!empty($link_id) && self::Is_authorized($user_ID)) self::Delete_fb_link($post); } if (!$delete) { // Check post status if ($new_status == 'publish' && ($new_status != $old_status || $update || get_post_meta($post->ID, c_al2fb_meta_error, true))) self::Publish_post($post); } } } // Handle publish post / XML-RPC publish post function Publish_post($post) { $user_ID = self::Get_user_ID($post); // Checks if (self::user_can($user_ID, get_option(c_al2fb_option_min_cap))) { // Check if not added if (self::Is_authorized($user_ID) && !get_post_meta($post->ID, c_al2fb_meta_link_id, true) && !get_post_meta($post->ID, c_al2fb_meta_exclude, true)) { $add_new_page = get_user_meta($user_ID, c_al2fb_meta_add_new_page, true); $exclude_category = false; $categories = get_the_category($post->ID); $excluding_categories = explode(',', get_option(c_al2fb_option_exclude_cat)); if ($categories) foreach ($categories as $category) if (in_array($category->cat_ID, $excluding_categories)) $exclude_category = true; $ex_custom_types = explode(',', get_option(c_al2fb_option_exclude_type)); $ex_custom_types[] = 'nav_menu_item'; // Check if public post if (empty($post->post_password) && ($post->post_type != 'page' || $add_new_page) && !in_array($post->post_type, $ex_custom_types) && !$exclude_category) self::Add_fb_link($post); } } } // Build texts for link/ogp function Get_texts($post) { $user_ID = self::Get_user_ID($post); // Filter excerpt $excerpt = get_post_meta($post->ID, c_al2fb_meta_excerpt, true); if (empty($excerpt)) $excerpt = $post->post_excerpt; $excerpt = apply_filters('al2fb_excerpt', $excerpt, $post); // Filter post text $content = get_post_meta($post->ID, c_al2fb_meta_text, true); if (empty($content)) $content = $post->post_content; $content = apply_filters('al2fb_content', $content, $post); // Get body $description = ''; if (get_user_meta($user_ID, c_al2fb_meta_msg, true)) $description = $content; else $description = ($excerpt ? $excerpt : $content); // Trailer: limit body size $trailer = get_user_meta($user_ID, c_al2fb_meta_trailer, true); if ($trailer) { $trailer = preg_replace('/<[^>]*>/', '', $trailer); // Get maximum FB description size $maxlen = get_option(c_al2fb_option_max_descr); if (!$maxlen) $maxlen = 256; // Add maximum number of sentences $lines = explode('.', $description); if ($lines) { $count = 0; $description = ''; foreach ($lines as $sentence) { $line = $sentence; if ($count + 1 < count($lines)) $line .= '.'; if (strlen($description) + strlen($line) + strlen($trailer) < $maxlen) $description .= $line; else break; } if (empty($description) && count($lines) > 0) $description = substr($lines[0], 0, $maxlen - strlen($trailer)); $description .= $trailer; } } // Build result $texts = array( 'excerpt' => $excerpt, 'content' => $content, 'description' => $description ); return $texts; } // Get link picture function Get_link_picture($post, $user_ID) { // Get selected image $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_type = 'meta'; $picture = wp_get_attachment_thumb_url($image_id); // Workaround if (strpos($picture, 'http') === false) $picture = content_url($picture); } if (empty($picture)) { // Default picture $picture = get_user_meta($user_ID, c_al2fb_meta_picture_default, true); if (empty($picture)) $picture = self::Redirect_uri() . '?al2fb_image=1'; // Check picture type $picture_type = get_user_meta($user_ID, c_al2fb_meta_picture_type, true); if ($picture_type == 'media') { $images = array_values(get_children('post_type=attachment&post_mime_type=image&order=ASC&post_parent=' . $post->ID)); if (!empty($images) && function_exists('wp_get_attachment_image_src')) { $picture = wp_get_attachment_image_src($images[0]->ID, 'thumbnail'); if ($picture && $picture[0]) $picture = $picture[0]; } } else if ($picture_type == 'featured') { if (current_theme_supports('post-thumbnails') && function_exists('get_post_thumbnail_id') && function_exists('wp_get_attachment_image_src')) { $picture_id = get_post_thumbnail_id($post->ID); if ($picture_id) { $picture = wp_get_attachment_image_src($picture_id, 'thumbnail'); if ($picture && $picture[0]) $picture = $picture[0]; } } } else if ($picture_type == 'facebook') $picture = ''; else if ($picture_type == 'post' || empty($picture_type)) { if (preg_match('/< *img[^>]*src *= *["\']([^"\']*)["\']/i', do_shortcode($post->post_content), $matches)) $picture = $matches[1]; } else if ($picture_type == 'avatar') { $userdata = get_userdata($post->post_author); $avatar = get_avatar($userdata->user_email); if (!empty($avatar)) if (preg_match('/< *img[^>]*src *= *["\']([^"\']*)["\']/i', $avatar, $matches)) $picture = $matches[1]; } else if ($picture_type == 'userphoto') { $userdata = get_userdata($post->post_author); if ($userdata->userphoto_approvalstatus == USERPHOTO_APPROVED) { $image_file = $userdata->userphoto_image_file; $upload_dir = wp_upload_dir(); $picture = trailingslashit($upload_dir['baseurl']) . 'userphoto/' . $image_file; } } else if ($picture_type == 'custom') { $custom = get_user_meta($user_ID, c_al2fb_meta_picture, true); if ($custom) $picture = $custom; } } return array( 'picture' => $picture, 'picture_type' => $picture_type ); } function Get_fb_profilelink($id) { if (empty($id)) return ''; return 'http://www.facebook.com/profile.php?id=' . $id; } function Get_fb_permalink($link_id) { if (empty($link_id)) return ''; $ids = explode('_', $link_id); return 'http://www.facebook.com/permalink.php?story_fbid=' . $ids[1] . '&id=' . $ids[0]; } function Filter_excerpt($excerpt, $post) { return self::Filter_standard($excerpt, $post); } function Filter_content($content, $post) { return self::Filter_standard($content, $post); } function Filter_standard($text, $post) { $user_ID = self::Get_user_ID($post); // Convert to UTF-8 if needed $text = self::Convert_encoding($user_ID, $text); // Execute shortcodes if (!get_option(c_al2fb_option_noshortcode)) $text = do_shortcode($text); // http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php // Remove scripts $text = preg_replace('//ims', '', $text); // Remove styles $text = preg_replace('//ims', '', $text); // Replace hyperlinks if (get_user_meta($user_ID, c_al2fb_meta_hyperlink, true)) $text = preg_replace('/< *a[^>]*href *= *["\']([^"\']*)["\'][^<]*/i', '$1', $text); // Remove image captions $text = preg_replace('/]*class="wp-caption-text"[^>]*>[^<]*<\/p>/i', '', $text); // Get plain texts $text = preg_replace('/<[^>]*>/', '', $text); // Truncate text if (!empty($text)) { $maxtext = get_option(c_al2fb_option_max_text); if (!$maxtext) $maxtext = 10000; $text = substr($text, 0, $maxtext); } return $text; } // Convert charset function Convert_encoding($user_ID, $text) { $blog_encoding = get_option('blog_charset'); $fb_encoding = get_user_meta($user_ID, c_al2fb_meta_fb_encoding, true); if (empty($fb_encoding)) $fb_encoding = 'UTF-8'; if ($blog_encoding != $fb_encoding && function_exists('mb_convert_encoding')) return @mb_convert_encoding($text, $fb_encoding, $blog_encoding); else return $text; } // Add Link to Facebook function Add_fb_link($post) { // Get url $user_ID = self::Get_user_ID($post); if (get_user_meta($user_ID, c_al2fb_meta_shortlink, true)) $link = wp_get_shortlink($post->ID); if (empty($link)) $link = get_permalink($post->ID); $link = apply_filters('al2fb_link', $link, $post); // Get processed texts $texts = self::Get_texts($post); $excerpt = $texts['excerpt']; $content = $texts['content']; $description = $texts['description']; // Get name $name = self::Convert_encoding($user_ID, get_the_title($post->ID)); $name = apply_filters('al2fb_name', $name, $post); // Get caption $caption = ''; if (get_user_meta($user_ID, c_al2fb_meta_caption, true)) { $caption = html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset')); $caption = self::Convert_encoding($user_ID, $caption); $caption = apply_filters('al2fb_caption', $caption, $post); } // Get link picture $picture_info = self::Get_link_picture($post, $user_ID); $picture = $picture_info['picture']; $picture_type = $picture_info['picture_type']; $picture = apply_filters('al2fb_picture', $picture, $post); // Get user note $message = ''; if (get_user_meta($user_ID, c_al2fb_meta_msg, true)) $message = $excerpt; // Do not disturb WordPress try { // Build request if (get_user_meta($user_ID, c_al2fb_meta_use_groups, true)) $page_id = get_user_meta($user_ID, c_al2fb_meta_group, true); if (empty($page_id)) $page_id = get_user_meta($user_ID, c_al2fb_meta_page, true); if (empty($page_id)) $page_id = 'me'; $url = 'https://graph.facebook.com/' . $page_id . '/feed'; $query_array = array( 'access_token' => self::Get_access_token_by_post($post), 'link' => $link, 'name' => $name, 'caption' => $caption, 'description' => $description, 'picture' => $picture, 'message' => $message ); // Add share link if (get_user_meta($user_ID, c_al2fb_meta_share_link, true)) { // http://forum.developers.facebook.net/viewtopic.php?id=50049 // http://bugs.developers.facebook.net/show_bug.cgi?id=9075 $actions = array( 'name' => __('Share', c_al2fb_text_domain), 'link' => 'http://www.facebook.com/share.php?u=' . urlencode($link) . '&t=' . urlencode(get_the_title($post->ID)) ); $query_array['actions'] = json_encode($actions); } // Build request $query = http_build_query($query_array, '', '&'); // Log request if ($this->debug) add_post_meta($post->ID, c_al2fb_meta_log, 'request=' . $query); // Execute request $response = self::Request($url, $query, 'POST'); // Log response if ($this->debug) add_post_meta($post->ID, c_al2fb_meta_log, 'response=' . $response); // Decode response $fb_link = json_decode($response); // Register link/date add_post_meta($post->ID, c_al2fb_meta_link_id, $fb_link->id); update_post_meta($post->ID, c_al2fb_meta_link_time, date('c')); update_post_meta($post->ID, c_al2fb_meta_link_picture, $picture_type . '=' . $picture); delete_post_meta($post->ID, c_al2fb_meta_error); // Update stats $this->Update_statistics('add', $post); } 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')); update_post_meta($post->ID, c_al2fb_meta_link_picture, $picture_type . '=' . $picture); } } // Delete Link from Facebook function Delete_fb_link($post) { // Do not disturb WordPress try { // Build request // http://developers.facebook.com/docs/reference/api/link/ $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); $url = 'https://graph.facebook.com/' . $link_id; $query = http_build_query(array( 'access_token' => self::Get_access_token_by_post($post), 'method' => 'delete' ), '', '&'); // Execute request $response = self::Request($url, $query, 'POST'); // Delete meta data delete_post_meta($post->ID, c_al2fb_meta_link_id); delete_post_meta($post->ID, c_al2fb_meta_link_time); delete_post_meta($post->ID, c_al2fb_meta_link_picture); delete_post_meta($post->ID, c_al2fb_meta_error); // Update stats $this->Update_statistics('del', $post); } 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')); } } // Delete Link from Facebook function Delete_fb_link_comment($comment) { // Get data $fb_comment_id = get_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, true); if (empty($fb_comment_id)) return; $post = get_post($comment->comment_post_ID); if (empty($post)) return; // Do not disturb WordPress try { // Build request $url = 'https://graph.facebook.com/' . $fb_comment_id; $query = http_build_query(array( 'access_token' => self::Get_access_token_by_post($post), 'method' => 'delete' ), '', '&'); // Execute request $response = self::Request($url, $query, 'POST'); // Delete meta data delete_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id); } catch (Exception $e) { add_post_meta($post->ID, c_al2fb_meta_error, $e->getMessage()); } } // New comment function Comment_post($comment_ID) { $comment = get_comment($comment_ID); if ($comment->comment_approved == '1') self::Add_fb_link_comment($comment); } // Approved comment function Comment_approved($comment) { self::Add_fb_link_comment($comment); } // Disapproved comment function Comment_unapproved($comment) { self::Delete_fb_link_comment($comment); } // Add comment to link function Add_fb_link_comment($comment) { // Get data $fb_comment_id = get_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, true); if (!empty($fb_comment_id)) return; $post = get_post($comment->comment_post_ID); if (empty($post)) return; $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); if (empty($link_id)) return; if (get_post_meta($post->ID, c_al2fb_meta_nointegrate, true)) return; $user_ID = self::Get_user_ID($post); if (!get_user_meta($user_ID, c_al2fb_meta_fb_comments_postback, true)) return; // Build message $message = $comment->comment_author . ' ' . __('commented on', c_al2fb_text_domain) . ' '; $message .= html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset')) . ":\n\n"; $message .= $comment->comment_content; $message = apply_filters('al2fb_comment', $message, $comment, $post); $message = self::Convert_encoding($user_ID, $message); // Do not disturb WordPress try { $url = 'https://graph.facebook.com/' . $link_id . '/comments'; $query_array = array( 'access_token' => self::Get_access_token_by_post($post), 'message' => $message ); // http://developers.facebook.com/docs/reference/api/Comment/ $query = http_build_query($query_array, '', '&'); // Execute request $response = self::Request($url, $query, 'POST'); // Process response $fb_comment = json_decode($response); add_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, $fb_comment->id); } catch (Exception $e) { add_post_meta($post->ID, c_al2fb_meta_error, $e->getMessage()); } } function Is_authorized($user_ID) { return get_user_meta($user_ID, c_al2fb_meta_access_token, true); } // Get correct access for post function Get_access_token_by_post($post) { $user_ID = self::Get_user_ID($post); $page_id = get_user_meta($user_ID, c_al2fb_meta_page, true); return self::Get_access_token_by_page($user_ID, $page_id); } // Get access token for page function Get_access_token_by_page($user_ID, $page_id) { $access_token = get_user_meta($user_ID, c_al2fb_meta_access_token, true); if ($page_id && $page_id != 'me' && get_user_meta($user_ID, c_al2fb_meta_page_owner, true)) { $found = false; $pages = self::Get_fb_pages($user_ID); if ($pages->data) foreach ($pages->data as $page) if ($page->id == $page_id) { $found = true; $access_token = $page->access_token; } } return $access_token; } // HTML header function WP_head() { if (is_single() || is_page()) { global $post; $user_ID = self::Get_user_ID($post); if (get_user_meta($user_ID, c_al2fb_meta_open_graph, true)) { $charset = get_bloginfo('charset'); $title = html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset')); // Get link picture $link_picture = get_post_meta($post->ID, c_al2fb_meta_link_picture, true); if (empty($link_picture)) { $picture_info = self::Get_link_picture($post, $user_ID); $picture = $picture_info['picture']; if (empty($picture)) $picture = self::Redirect_uri() . '?al2fb_image=1'; } else $picture = substr($link_picture, strpos($link_picture, '=') + 1); // Get type $ogp_type = get_user_meta($user_ID, c_al2fb_meta_open_graph_type, true); if (empty($ogp_type)) $ogp_type = 'article'; // Generate meta tags echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; $texts = self::Get_texts($post); $maxlen = get_option(c_al2fb_option_max_descr); $description = substr($texts['description'], 0, $maxlen ? $maxlen : 256); echo '' . PHP_EOL; $appid = get_user_meta($user_ID, c_al2fb_meta_client_id, true); if (!empty($appid)) echo '' . PHP_EOL; $admins = get_user_meta($user_ID, c_al2fb_meta_open_graph_admins, true); if (!empty($admins)) echo '' . PHP_EOL; } } else if (is_home()) { // Check if any user has enabled the OGP global $wpdb; $opg = false; $rows = $wpdb->get_results("SELECT meta_value FROM " . $wpdb->usermeta . " WHERE meta_key='" . c_al2fb_meta_open_graph . "'"); foreach ($rows as $row) if ($row->meta_value) { $opg = true; break; } // Generate meta tags if ($opg) { $charset = get_bloginfo('charset'); $title = html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset')); echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; } } } // Additional styles function WP_print_styles() { $css = get_option(c_al2fb_option_css); if (!empty($css)) { echo '' . PHP_EOL; } } // Post content function The_content($content = '') { global $post; // Excluded post types $ex_custom_types = explode(',', get_option(c_al2fb_option_exclude_type)); if (in_array($post->post_type, $ex_custom_types)) return $content; $user_ID = self::Get_user_ID($post); if (!(get_user_meta($user_ID, c_al2fb_meta_like_nohome, true) && is_home()) && !(get_user_meta($user_ID, c_al2fb_meta_like_noposts, true) && is_single()) && !(get_user_meta($user_ID, c_al2fb_meta_like_nopages, true) && is_page()) && !(get_user_meta($user_ID, c_al2fb_meta_like_noarchives, true) && is_archive()) && !(get_user_meta($user_ID, c_al2fb_meta_like_nocategories, true) && is_category())) { // Show likers if (get_user_meta($user_ID, c_al2fb_meta_post_likers, true)) { $likers = self::Get_likers($post); if (!empty($likers)) if (get_user_meta($user_ID, c_al2fb_meta_like_top, true)) $content = $likers . $content; else $content .= $likers; } // Show like button if (!get_post_meta($post->ID, c_al2fb_meta_nolike, true)) { if (get_user_meta($user_ID, c_al2fb_meta_post_like_button, true)) $button = self::Get_like_button($post, false); if (get_user_meta($user_ID, c_al2fb_meta_post_send_button, true) && !get_user_meta($user_ID, c_al2fb_meta_post_combine_buttons, true)) $button .= self::Get_send_button($post); } if (!empty($button)) if (get_user_meta($user_ID, c_al2fb_meta_like_top, true)) $content = $button . $content; else $content .= $button; } return $content; } // Shortcode likers names function Shortcode_likers($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_likers($post); else return ''; } // Shortcode like count function Shortcode_like_count($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_like_count($post); else return ''; } // Shortcode like button function Shortcode_like_button($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_like_button($post, false); else return ''; } // Shortcode like box function Shortcode_like_box($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_like_button($post, true); else return ''; } // Shortcode send button function Shortcode_send_button($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_send_button($post); else return ''; } // Shortcode comments plugin function Shortcode_comments_plugin($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_comments_plugin($post); else return ''; } // Shortcode face pile function Shortcode_face_pile($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_face_pile($post); else return ''; } // Shortcode profile link function Shortcode_profile_link($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_profile_link($post); else return ''; } // Shortcode Facebook registration function Shortcode_registration($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_registration($post); else return ''; } // Shortcode Facebook login function Shortcode_login($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_login($post); else return ''; } // Shortcode Facebook activity feed function Shortcode_activity_feed($atts) { extract(shortcode_atts(array('post_id' => null), $atts)); if (empty($post_id)) global $post; else $post = get_post($post_id); if (isset($post)) return self::Get_activity_feed($post); else return ''; } // Get HTML for likers function Get_likers($post) { $user_ID = self::Get_user_ID($post); $likers = ''; $charset = get_bloginfo('charset'); $fb_likes = self::Get_comments_or_likes($post, true); if ($fb_likes) foreach ($fb_likes->data as $fb_like) { if (!empty($likers)) $likers .= ', '; if (get_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, true) == 'author') { $link = self::Get_fb_profilelink($fb_like->id); $likers .= '' . htmlspecialchars($fb_like->name, ENT_QUOTES, $charset) . ''; } else $likers .= htmlspecialchars($fb_like->name, ENT_QUOTES, $charset); } if (!empty($likers)) { $likers .= ' ' . _n('liked this post', 'liked this post', count($fb_likes->data), c_al2fb_text_domain) . ''; $likers = '
' . $likers . '
'; } return $likers; } // Get HTML for like count function Get_like_count($post) { $user_ID = self::Get_user_ID($post); $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); $fb_likes = self::Get_comments_or_likes($post, true); if ($fb_likes && count($fb_likes->data) > 0) return ''; return ''; } // Get language code for Facebook function Get_locale($user_ID) { $locale = get_user_meta($user_ID, c_al2fb_meta_fb_locale, true); if (empty($locale)) { $locale = defined('WPLANG') ? WPLANG : ''; $locale = str_replace('-', '_', $locale); if (empty($locale) || strlen($locale) != 5) $locale = 'en_US'; } return $locale; } function Get_fb_script($user_ID) { $lang = self::Get_locale($user_ID); $appid = get_user_meta($user_ID, c_al2fb_meta_client_id, true); if ($appid) return 'http://connect.facebook.net/' . $lang . '/all.js#appId=' . $appid . '&xfbml=1'; else return 'http://connect.facebook.net/' . $lang . '/all.js#xfbml=1'; } // Get HTML for like button function Get_like_button($post, $box) { $user_ID = self::Get_user_ID($post); if ($user_ID) { // Get options $layout = get_user_meta($user_ID, c_al2fb_meta_like_layout, true); $faces = get_user_meta($user_ID, c_al2fb_meta_like_faces, true); if ($box) $width = get_user_meta($user_ID, c_al2fb_meta_like_box_width, true); else $width = get_user_meta($user_ID, c_al2fb_meta_like_width, true); $action = get_user_meta($user_ID, c_al2fb_meta_like_action, true); $font = get_user_meta($user_ID, c_al2fb_meta_like_font, true); $colorscheme = get_user_meta($user_ID, c_al2fb_meta_like_colorscheme, true); $border = get_user_meta($user_ID, c_al2fb_meta_like_box_border, true); $noheader = get_user_meta($user_ID, c_al2fb_meta_like_box_noheader, true); $nostream = get_user_meta($user_ID, c_al2fb_meta_like_box_nostream, true); $link = get_user_meta($user_ID, c_al2fb_meta_like_link, true); if (empty($link)) if ($box) { // Get page if (self::Is_authorized($user_ID) && !get_user_meta($user_ID, c_al2fb_meta_use_groups, true) && get_user_meta($user_ID, c_al2fb_meta_page, true)) try { $page = self::Get_fb_me_cached($user_ID, false); $link = $page->link; } catch (Exception $e) { } } else $link = get_permalink($post->ID); // Build content $content = ($box ? '
' : '
'); $content .= '
'; $content .= ''; $content .= ($box ? '' : '>'); $content .= '
'; return $content; } else return ''; } // Get HTML for like button function Get_send_button($post) { $user_ID = self::Get_user_ID($post); if ($user_ID) { // Get options $font = get_user_meta($user_ID, c_al2fb_meta_like_font, true); $colorscheme = get_user_meta($user_ID, c_al2fb_meta_like_colorscheme, true); $link = get_user_meta($user_ID, c_al2fb_meta_like_link, true); if (empty($link)) $link = get_permalink($post->ID); // Send button $content = '
'; $content .= '
'; $content .= ''; $content .= ''; $content .= '
'; return $content; } else return ''; } // Get HTML for comments plugin function Get_comments_plugin($post) { $user_ID = self::Get_user_ID($post); if ($user_ID) { // Get options $posts = get_user_meta($user_ID, c_al2fb_meta_comments_posts, true); $width = get_user_meta($user_ID, c_al2fb_meta_comments_width, true); $colorscheme = get_user_meta($user_ID, c_al2fb_meta_like_colorscheme, true); $link = get_user_meta($user_ID, c_al2fb_meta_like_link, true); if (empty($link)) $link = get_permalink($post->ID); // Send button $content = '
'; $content .= '
'; $content .= ''; $content .= ''; $content .= '
'; return $content; } else return ''; } // Get HTML face pile function Get_face_pile($post) { $user_ID = self::Get_user_ID($post); if ($user_ID) { // Get options $size = get_user_meta($user_ID, c_al2fb_meta_pile_size, true); $width = get_user_meta($user_ID, c_al2fb_meta_pile_width, true); $rows = get_user_meta($user_ID, c_al2fb_meta_pile_rows, true); $link = get_user_meta($user_ID, c_al2fb_meta_like_link, true); if (empty($link)) $link = get_permalink($post->ID); // Face pile $content = '
'; $content .= '
'; $content .= ''; $content .= ''; $content .= '
'; return $content; } else return ''; } // Get HTML profile link function Get_profile_link($post) { $content = ''; try { $user_ID = self::Get_user_ID($post); $me = self::Get_fb_me_cached($user_ID, false); if (!empty($me)) { $img = 'http://creative.ak.fbcdn.net/ads3/creative/pressroom/jpg/b_1234209334_facebook_logo.jpg'; $content .= ''; } } catch (Exception $e) { } return $content; } // Get HTML Facebook registration function Get_registration($post) { // Check if registration enabled if (!get_option('users_can_register')) return ''; // Get data $user_ID = self::Get_user_ID($post); if ($user_ID) { // Check if user logged in if (is_user_logged_in()) return do_shortcode(get_user_meta($user_ID, c_al2fb_meta_login_html, true)); // Get options $appid = get_user_meta($user_ID, c_al2fb_meta_client_id, true); $width = get_user_meta($user_ID, c_al2fb_meta_reg_width, true); $border = get_user_meta($user_ID, c_al2fb_meta_like_box_border, true); $fields = "[{'name':'name'}"; $fields .= ",{'name':'first_name'}"; $fields .= ",{'name':'last_name'}"; $fields .= ",{'name':'email'}"; $fields .= ",{'name':'user_name','description':'" . __('WordPress user name', c_al2fb_text_domain) . "','type':'text'}"; $fields .= ",{'name':'password'}]"; // Build content if ($appid) { $content = '
'; $content .= '
'; $content .= ''; $content .= ''; $content .= ''; $content .= '
'; return $content; } } return ''; } // Get HTML Facebook login function Get_login($post) { // Get data $user_ID = self::Get_user_ID($post); if ($user_ID) { // Check if user logged in if (is_user_logged_in()) return do_shortcode(get_user_meta($user_ID, c_al2fb_meta_login_html, true)); // Get options $appid = get_user_meta($user_ID, c_al2fb_meta_client_id, true); $regurl = get_user_meta($user_ID, c_al2fb_meta_login_regurl, true); $faces = false; $width = get_user_meta($user_ID, c_al2fb_meta_login_width, true); $rows = get_user_meta($user_ID, c_al2fb_meta_pile_rows, true); $permissions = ''; // Build content if ($appid) { $content = ''; return $content; } return ''; } // Handle Facebook registration function Facebook_registration() { // Decode Facebook data $reg = self::Parse_signed_request($_REQUEST['user']); // Check result if ($reg == null) { header('Content-type: text/plain'); _e('Facebook registration failed', c_al2fb_text_domain); echo PHP_EOL; } else { if (!get_option('users_can_register')) { // Registration not enabled header('Content-type: text/plain'); _e('User registration disabled', c_al2fb_text_domain); echo PHP_EOL; } else if (empty($reg['registration']['email'])) { // E-mail missing header('Content-type: text/plain'); _e('Facebook e-mail address missing', c_al2fb_text_domain); echo PHP_EOL; if ($this->debug) print_r($reg); } else if (email_exists($reg['registration']['email'])) { // E-mail in use header('Content-type: text/plain'); _e('E-mail address in use', c_al2fb_text_domain); echo PHP_EOL; if ($this->debug) print_r($reg); } else if (empty($reg['user_id'])) { // User ID missing header('Content-type: text/plain'); _e('Facebook user ID missing', c_al2fb_text_domain); echo PHP_EOL; if ($this->debug) print_r($reg); } else { // Create new WP user $user_ID = wp_insert_user(array( 'first_name' => $reg['registration']['first_name'], 'last_name' => $reg['registration']['last_name'], 'user_email' => $reg['registration']['email'], 'user_login' => $reg['registration']['user_name'], 'user_pass' => $reg['registration']['password'] )) ; // Check result if (is_wp_error($user_ID)) { header('Content-type: text/plain'); _e($user_ID->get_error_message()); echo PHP_EOL; if ($this->debug) print_r($reg); } else { // Persist Facebook ID update_user_meta($user_ID, c_al2fb_meta_facebook_id, $reg['user_id']); // Log user in $user = self::Login_by_email($reg['registration']['email']); // Redirect $self = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_REQUEST['uri']; $redir = get_user_meta($user_ID, c_al2fb_meta_login_redir, true); wp_redirect($redir ? $redir : $self); } } } } // Handle Facebook login function Facebook_login() { header('Content-type: text/plain'); try { // Check token $url = 'https://graph.facebook.com/' . $_REQUEST['uid']; $query = http_build_query(array('access_token' => $_REQUEST['token']), '', '&'); $response = self::Request($url, $query, 'GET'); $me = json_decode($response); // Workaround if no e-mail present if (!empty($me) && empty($me->email)) { $users = get_users(array( 'meta_key' => c_al2fb_meta_facebook_id, 'meta_value' => $me->id )); if (count($users) == 0) { $regurl = get_user_meta($_REQUEST['user'], c_al2fb_meta_login_regurl, true); if (!empty($regurl)) wp_redirect($regurl); } else if (count($users) == 1) $me->email = $users[0]->user_email; } // Check Facebook user if (!empty($me) && !empty($me->id)) { // Find user by Facebook ID $users = get_users(array( 'meta_key' => c_al2fb_meta_facebook_id, 'meta_value' => $me->id )); // Check if found one if (count($users) == 1) { // Try to login $user = self::Login_by_email($users[0]->user_email); // Check login if ($user) { // Redirect $self = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_REQUEST['uri']; $redir = get_user_meta($_REQUEST['user'], c_al2fb_meta_login_redir, true); wp_redirect($redir ? $redir : $self); } else { // User not found (anymore) header('Content-type: text/plain'); _e('User not found', c_al2fb_text_domain); echo PHP_EOL; if ($this->debug) print_r($me); } } else { $self = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_REQUEST['uri']; $regurl = get_user_meta($_REQUEST['user'], c_al2fb_meta_login_regurl, true); wp_redirect($regurl ? $regurl : $self); } } else { // Something went wrong header('Content-type: text/plain'); _e('Could not verify Facebook login', c_al2fb_text_domain); echo PHP_EOL; if ($this->debug) print_r($me); } } catch (Exception $e) { // Communication error? header('Content-type: text/plain'); _e('Could not verify Facebook login', c_al2fb_text_domain); echo PHP_EOL; echo $e->getMessage(); echo PHP_EOL; } } // Log WordPress user in using e-mail function Login_by_email($email) { $user = get_user_by_email($email); if ($user) { wp_set_current_user($user->ID, $user->user_login); wp_set_auth_cookie($user->ID); do_action('wp_login', $user->user_login); } return $user; } // Decode Facebook registration response function Parse_signed_request($user_ID) { $signed_request = $_REQUEST['signed_request']; $secret = get_user_meta($user_ID, c_al2fb_meta_app_secret, true); list($encoded_sig, $payload) = explode('.', $signed_request, 2); // Decode the data $sig = self::base64_url_decode($encoded_sig); $data = json_decode(self::base64_url_decode($payload), true); if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') return null; // Check sig $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true); if ($sig !== $expected_sig) return null; return $data; } // Helper: base64 decode url function base64_url_decode($input) { return base64_decode(strtr($input, '-_', '+/')); } // Profile personal options function Personal_options($user) { $fid = get_user_meta($user->ID, c_al2fb_meta_facebook_id, true); echo '' . __('Facebook ID', c_al2fb_text_domain) . ''; echo ''; if ($fid) echo '' . $fid . ''; else echo '' . __('What is my Facebook ID?', c_al2fb_text_domain) . ''; echo ''; } // Handle personal options change function Personal_options_update($user_id) { update_user_meta($user_id, c_al2fb_meta_facebook_id, trim($_REQUEST[c_al2fb_meta_facebook_id])); } // Modify comment list function Comments_array($comments, $post_ID) { $post = get_post($post_ID); $user_ID = self::Get_user_ID($post); // Integration? if (!get_post_meta($post->ID, c_al2fb_meta_nointegrate, true)) { // Get time zone offset $tz_off = get_option('gmt_offset'); if (empty($tz_off)) $tz_off = 0; else $tz_off = $tz_off * 3600; // Get Facebook comments if (get_user_meta($user_ID, c_al2fb_meta_fb_comments, true)) { $fb_comments = self::Get_comments_or_likes($post, false); if ($fb_comments) { // Get WordPress comments $stored_comments = array_merge( get_comments('post_id=' . $post->ID), get_comments('status=spam&post_id=' . $post->ID)); foreach ($fb_comments->data as $fb_comment) { // Check if stored comment $stored = false; if ($stored_comments) foreach ($stored_comments as $comment) { $fb_comment_id = get_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, true); if ($fb_comment_id == $fb_comment->id) { $stored = true; break; } } // Create new comment if (!$stored) { $comment_ID = $fb_comment->id; $commentdata = array( 'comment_post_ID' => $post_ID, 'comment_author' => $fb_comment->from->name . ' ' . __('on Facebook', c_al2fb_text_domain), 'comment_author_email' => $fb_comment->from->id . '@facebook.com', 'comment_author_url' => self::Get_fb_profilelink($fb_comment->from->id), 'comment_author_IP' => '', 'comment_date' => date('Y-m-d H:i:s', strtotime($fb_comment->created_time) + $tz_off), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime($fb_comment->created_time)), 'comment_content' => $fb_comment->message, 'comment_karma' => 0, 'comment_approved' => 1, 'comment_agent' => 'AL2FB', 'comment_type' => '', // pingback|trackback 'comment_parent' => 0, 'user_id' => 0 ); // Copy Facebook comment to WordPress database if (get_user_meta($user_ID, c_al2fb_meta_fb_comments_copy, true)) { // Apply filters $commentdata = apply_filters('preprocess_comment', $commentdata); $commentdata = wp_filter_comment($commentdata); $commentdata['comment_approved'] = wp_allow_comment($commentdata); // Insert comment in database $comment_ID = wp_insert_comment($commentdata); add_comment_meta($comment_ID, c_al2fb_meta_fb_comment_id, $fb_comment->id); do_action('comment_post', $comment_ID, $commentdata['comment_approved']); // Notify if ('spam' !== $commentdata['comment_approved']) { if ('0' == $commentdata['comment_approved']) wp_notify_moderator($comment_ID); if (get_option('comments_notify') && $commentdata['comment_approved']) wp_notify_postauthor($comment_ID, $commentdata['comment_type']); } } // Add comment to array if ($commentdata['comment_approved'] == 1) { $new = null; $new->comment_ID = $comment_ID; $new->comment_post_ID = $commentdata['comment_post_ID']; $new->comment_author = $commentdata['comment_author']; $new->comment_author_email = $commentdata['comment_author_email']; $new->comment_author_url = $commentdata['comment_author_url']; $new->comment_author_ip = $commentdata['comment_author_IP']; $new->comment_date = $commentdata['comment_date']; $new->comment_date_gmt = $commentdata['comment_date_gmt']; $new->comment_content = stripslashes($commentdata['comment_content']); $new->comment_karma = $commentdata['comment_karma']; $new->comment_approved = $commentdata['comment_approved']; $new->comment_agent = $commentdata['comment_agent']; $new->comment_type = $commentdata['comment_type']; $new->comment_parent = $commentdata['comment_parent']; $new->user_id = $commentdata['user_id']; $comments[] = $new; } } } } } // Get likes if (get_user_meta($user_ID, c_al2fb_meta_fb_likes, true)) { $fb_likes = self::Get_comments_or_likes($post, true); if ($fb_likes) foreach ($fb_likes->data as $fb_like) { // Create new virtual comment $link = self::Get_fb_profilelink($fb_like->id); $new = null; $new->comment_ID = $fb_like->id; $new->comment_post_ID = $post_ID; $new->comment_author = $fb_like->name . ' ' . __('on Facebook', c_al2fb_text_domain); $new->comment_author_email = ''; $new->comment_author_url = $link; $new->comment_author_ip = ''; $new->comment_date_gmt = date('Y-m-d H:i:s', time()); $new->comment_date = $new->comment_date_gmt; $new->comment_content = '' . __('Liked this post', c_al2fb_text_domain) . ''; $new->comment_karma = 0; $new->comment_approved = 1; $new->comment_agent = 'AL2FB'; $new->comment_type = 'pingback'; $new->comment_parent = 0; $new->user_id = 0; $comments[] = $new; } } // Sort comments by time if (!empty($fb_comments) || !empty($fb_likes)) { usort($comments, array(&$this, 'Comment_compare')); if (get_option('comment_order') == 'desc') array_reverse($comments); } } // Comment link type $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); $comments_nolink = get_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, true); if (empty($comments_nolink)) $comments_nolink = 'author'; else if ($comments_nolink == 'on' || empty($link_id)) $comments_nolink = 'none'; if ($comments_nolink == 'none' || $comments_nolink == 'link') { $link = self::Get_fb_permalink($link_id); if ($comments) foreach ($comments as $comment) if ($comment->comment_agent == 'AL2FB') if ($comments_nolink == 'none') $comment->comment_author_url = ''; else if ($comments_nolink == 'link') $comment->comment_author_url = $link; } return $comments; } // Sort helper function Comment_compare($a, $b) { return strcmp($a->comment_date_gmt, $b->comment_date_gmt); } // Get comment count with FB comments/likes function Get_comments_number($count, $post_ID) { $post = get_post($post_ID); // Integration turned off? if (get_post_meta($post->ID, c_al2fb_meta_nointegrate, true)) return $count; $user_ID = self::Get_user_ID($post); // Comment count if (get_user_meta($user_ID, c_al2fb_meta_fb_comments, true)) { $fb_comments = self::Get_comments_or_likes($post, false); if ($fb_comments) { $stored_comments = get_comments('post_id=' . $post_ID); foreach ($fb_comments->data as $fb_comment) if (!empty($fb_comments)) { $stored = false; if ($stored_comments) foreach ($stored_comments as $comment) { $fb_comment_id = get_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, true); if ($fb_comment_id == $fb_comment->id) { $stored = true; break; } } if (!$stored) $count++; } } } // Like count if (get_user_meta($user_ID, c_al2fb_meta_fb_likes, true)) $fb_likes = self::Get_comments_or_likes($post, true); if (!empty($fb_likes)) $count += count($fb_likes->data); return $count; } // Annotate FB comments/likes function Comment_class($classes) { global $comment; if (!empty($comment) && $comment->comment_agent == 'AL2FB') $classes[] = 'facebook-comment'; return $classes; } // Get FB picture as avatar function Get_avatar($avatar, $id_or_email, $size, $default) { if (is_object($id_or_email)) { $comment = $id_or_email; if ($comment->comment_agent == 'AL2FB' && ($comment->comment_type == '' || $comment->comment_type == 'comment')) { // Get picture url $id = explode('id=', $comment->comment_author_url); if (count($id) == 2) { $fb_picture_url = self::Get_fb_picture_url_cached($id[1], 'normal'); // Build avatar image if ($fb_picture_url) { $avatar = '' . esc_attr($comment->comment_author) . 'ID, c_al2fb_meta_link_id, true); if ($link_id) try { if ($likes) return self::Get_fb_likes_cached($user_ID, $link_id); else return self::Get_fb_comments_cached($user_ID, $link_id); } catch (Exception $e) { if ($this->debug) echo htmlspecialchars($e->getMessage()); return null; } return null; } function Get_user_ID($post) { if (is_multisite()) $shared_user_ID = get_site_option(c_al2fb_option_app_share); else $shared_user_ID = get_option(c_al2fb_option_app_share); if ($shared_user_ID) return $shared_user_ID; return $post->post_author; } // 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::Request_cURL($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 ? '?' . $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; $auth_error = ''; if (!empty($http_response_header)) foreach ($http_response_header as $h) if (strpos($h, 'HTTP/') === 0) { $status = explode(' ', $h); $status = intval($status[1]); } else if (strpos($h, 'WWW-Authenticate:') === 0) $auth_error = $h; if ($status == 200) return $content; else { if ($auth_error) $msg = 'Error ' . $status . ': ' . $auth_error; 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 Request_cURL($url, $query, $type, $timeout) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); if (!ini_get('safe_mode') && !ini_get('open_basedir')) { curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); curl_setopt($c, CURLOPT_MAXREDIRS, 10); } curl_setopt($c, CURLOPT_TIMEOUT, $timeout); if ($type == 'GET') curl_setopt($c, CURLOPT_URL, $url . ($query ? '?' . $query : '')); else { curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_POSTFIELDS, $query); } if (get_option(c_al2fb_option_noverifypeer)) curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); $content = curl_exec($c); $errno = curl_errno($c); $info = curl_getinfo($c); curl_close($c); if ($errno === 0 && $info['http_code'] == 200) return $content; else { $error = json_decode($content); $error = empty($error->error->message) ? $content : $error->error->message; if ($errno || !$error) $msg = 'cURL error ' . $errno . ': ' . $error . ' ' . print_r($info, true); else $msg = $error; update_option(c_al2fb_last_error, $msg); update_option(c_al2fb_last_error_time, date('c')); throw new Exception($msg); } } function user_can($user, $capability) { if (!is_object($user)) $user = new WP_User($user); if (!$user || !$user->ID) return false; $args = array_slice(func_get_args(), 2 ); $args = array_merge(array($capability), $args); return call_user_func_array(array(&$user, 'has_cap'), $args); } // Generate debug info function Debug_info() { // Get current user global $user_ID; get_currentuserinfo(); // Get users global $wpdb; $users = $wpdb->get_var('SELECT COUNT(ID) FROM ' . $wpdb->users); // Get versions global $wp_version; if (!function_exists('get_plugins')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); $plugin_folder = get_plugins('/' . plugin_basename(dirname(__FILE__))); $plugin_version = $plugin_folder[basename($this->main_file)]['Version']; // Get charset, token $charset = get_bloginfo('charset'); // Get application try { if (self::Is_authorized($user_ID)) { $a = self::Get_fb_application($user_ID); $app = '' . $a->name . ''; } else $app = 'n/a'; } catch (Exception $e) { $app = get_user_meta($user_ID, c_al2fb_meta_client_id, true) . ': ' . $e->getMessage(); } // Sharing if (is_multisite()) $shared_user_ID = get_site_option(c_al2fb_option_app_share); else $shared_user_ID = get_option(c_al2fb_option_app_share); // Get page try { if (self::Is_authorized($user_ID)) { $me = self::Get_fb_me($user_ID, false); if ($me == null) $page = 'n/a'; else { $page = '' . htmlspecialchars($me->name, ENT_QUOTES, $charset); if (!empty($me->category)) $page .= ' - ' . htmlspecialchars($me->category, ENT_QUOTES, $charset); $page .= ''; } } else $page = 'n/a'; } catch (Exception $e) { $page = get_user_meta($user_ID, c_al2fb_meta_page, true) . ': ' . $e->getMessage(); } // Get picture $picture = '' . get_user_meta($user_ID, c_al2fb_meta_picture, true) . ''; $picture_default = '' . get_user_meta($user_ID, c_al2fb_meta_picture_default, true) . ''; // Get theme data $theme_data = get_theme_data(STYLESHEETPATH . '/style.css'); $info = '
'; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; foreach (get_plugins() as $plugin_data) $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $fid = get_user_meta($user_ID, c_al2fb_meta_facebook_id, true); $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; $info .= ''; // Last posts $posts = new WP_Query(array('posts_per_page' => 10)); while ($posts->have_posts()) { $posts->next_post(); $userdata = get_userdata($posts->post->post_author); $link_id = get_post_meta($posts->post->ID, c_al2fb_meta_link_id, true); // Selected picture $selected_picture = null; $image_id = get_post_meta($posts->post->ID, c_al2fb_meta_image_id, true); if (!empty($image_id) && function_exists('wp_get_attachment_thumb_url')) $selected_picture = wp_get_attachment_thumb_url($image_id); // Attached picture $attached_picture = null; $images = array_values(get_children('post_type=attachment&post_mime_type=image&order=ASC&post_parent=' . $posts->post->ID)); if (!empty($images) && function_exists('wp_get_attachment_image_src')) { $picture = wp_get_attachment_image_src($images[0]->ID, 'thumbnail'); if ($picture && $picture[0]) $attached_picture = $picture[0]; } // Feature picture $featured_picture = null; if (current_theme_supports('post-thumbnails') && function_exists('get_post_thumbnail_id') && function_exists('wp_get_attachment_image_src')) { $picture_id = get_post_thumbnail_id($posts->post->ID); if ($picture_id) { $picture = wp_get_attachment_image_src($picture_id, 'thumbnail'); if ($picture && $picture[0]) $featured_picture = $picture[0]; } } // First picture in post $post_picture = null; if (preg_match('/< *img[^>]*src *= *["\']([^"\']*)["\']/i', do_shortcode($posts->post->post_content), $matches)) $post_picture = $matches[1]; // Author avatar $avatar_picture = null; $avatar = get_avatar($userdata->user_email); if (!empty($avatar)) if (preg_match('/< *img[^>]*src *= *["\']([^"\']*)["\']/i', $avatar, $matches)) $avatar_picture = $matches[1]; // Actual picture $picture = self::Get_link_picture($posts->post, self::Get_user_ID($posts->post)); $info .= ''; $info .= ''; } // Last link pictures $posts = new WP_Query(array('meta_key' => c_al2fb_meta_link_picture, 'posts_per_page' => 5)); while ($posts->have_posts()) { $posts->next_post(); $link_picture = get_post_meta($posts->post->ID, c_al2fb_meta_link_picture, true); if (!empty($link_picture)) { $info .= ''; $info .= ''; } } // Last errors $posts = new WP_Query(array('meta_key' => c_al2fb_meta_error, 'posts_per_page' => 10)); 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 .= ''; $info .= ''; $info .= '
Time:' . date('c') . '
Server software:' . htmlspecialchars($_SERVER['SERVER_SOFTWARE'], ENT_QUOTES, $charset) . '
SAPI:' . htmlspecialchars(php_sapi_name(), ENT_QUOTES, $charset) . '
PHP version:' . PHP_VERSION . '
safe_mode:' . (ini_get('safe_mode') ? 'Yes' : 'No') . '
open_basedir:' . ini_get('open_basedir') . '
User agent:' . htmlspecialchars($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, $charset) . '
WordPress version:' . $wp_version . '
Theme name:' . '' . htmlspecialchars($theme_data['Name'], ENT_QUOTES, $charset) . '' . '
Theme version:' . htmlspecialchars($theme_data['Version'], ENT_QUOTES, $charset) . '
Active plugin:' . htmlspecialchars($plugin_data['Name'], ENT_QUOTES, $charset) . '
Plugin version:' . $plugin_version . '
Settings version:' . get_option(c_al2fb_option_version) . '
Multi site:' . (is_multisite() ? 'Yes' : 'No') . '
Site id:' . $this->site_id . '
Blog id:' . $this->blog_id . '
Number of users:' . $users . '
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($user_ID), ENT_QUOTES, $charset) . '
Authorization init:' . htmlspecialchars(get_option(c_al2fb_log_redir_init), ENT_QUOTES, $charset) . '
Authorization check:' . htmlspecialchars(get_option(c_al2fb_log_redir_check), ENT_QUOTES, $charset) . '
Redirect time:' . htmlspecialchars(get_option(c_al2fb_log_redir_time), ENT_QUOTES, $charset) . '
Redirect referer:' . htmlspecialchars(get_option(c_al2fb_log_redir_ref), ENT_QUOTES, $charset) . '
Redirect from:' . htmlspecialchars(get_option(c_al2fb_log_redir_from), ENT_QUOTES, $charset) . '
Redirect to:' . htmlspecialchars(get_option(c_al2fb_log_redir_to), ENT_QUOTES, $charset) . '
Authorized:' . (self::Is_authorized($user_ID) ? 'Yes' : 'No') . '
Authorized time:' . get_option(c_al2fb_log_auth_time) . '
allow_url_fopen:' . (ini_get('allow_url_fopen') ? 'Yes' : 'No') . '
cURL:' . (function_exists('curl_init') ? 'Yes' : 'No') . '
SSL:' . (function_exists('openssl_sign') ? 'Yes' : 'No') . '
Encoding:' . htmlspecialchars(get_option('blog_charset'), ENT_QUOTES, $charset) . '
Facebook:' . htmlspecialchars(get_user_meta($user_ID, c_al2fb_meta_fb_encoding, true), ENT_QUOTES, $charset) . '
Locale:' . htmlspecialchars(WPLANG, ENT_QUOTES, $charset) . '
Facebook:' . htmlspecialchars(self::Get_locale($user_ID), ENT_QUOTES, $charset) . '
mb_convert_encoding:' . (function_exists('mb_convert_encoding') ? 'Yes' : 'No') . '
Application:' . $app . '
Shared user ID:' . $shared_user_ID . '
Picture type:' . get_user_meta($user_ID, c_al2fb_meta_picture_type, true) . '
Custom picture URL:' . $picture . '
Default picture URL:' . $picture_default . '
Page:' . $page . '
Page owner:' . (get_user_meta($user_ID, c_al2fb_meta_page_owner, true) ? 'Yes' : 'No') . '
Use groups:' . (get_user_meta($user_ID, c_al2fb_meta_use_groups, true) ? 'Yes' : 'No') . '
Group:' . get_user_meta($user_ID, c_al2fb_meta_group, true) . '
Caption:' . (get_user_meta($user_ID, c_al2fb_meta_caption, true) ? 'Yes' : 'No') . '
Excerpt:' . (get_user_meta($user_ID, c_al2fb_meta_msg, true) ? 'Yes' : 'No') . '
Trailer:' . htmlspecialchars(get_user_meta($user_ID, c_al2fb_meta_trailer, true), ENT_QUOTES, $charset) . '
Hyperlink:' . (get_user_meta($user_ID, c_al2fb_meta_hyperlink, true) ? 'Yes' : 'No') . '
Share link:' . (get_user_meta($user_ID, c_al2fb_meta_share_link, true) ? 'Yes' : 'No') . '
Shortlink:' . (get_user_meta($user_ID, c_al2fb_meta_shortlink, true) ? 'Yes' : 'No') . '
Page link:' . (get_user_meta($user_ID, c_al2fb_meta_add_new_page, true) ? 'Yes' : 'No') . '
FB comments:' . (get_user_meta($user_ID, c_al2fb_meta_fb_comments, true) ? 'Yes' : 'No') . '
FB comments postback:' . (get_user_meta($user_ID, c_al2fb_meta_fb_comments_postback, true) ? 'Yes' : 'No') . '
FB comments copy:' . (get_user_meta($user_ID, c_al2fb_meta_fb_comments_copy, true) ? 'Yes' : 'No') . '
FB comments no link:' . get_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, true) . '
FB likes:' . (get_user_meta($user_ID, c_al2fb_meta_fb_likes, true) ? 'Yes' : 'No') . '
Post likers:' . (get_user_meta($user_ID, c_al2fb_meta_post_likers, true) ? 'Yes' : 'No') . '
Post like button:' . (get_user_meta($user_ID, c_al2fb_meta_post_like_button, true) ? 'Yes' : 'No') . '
Not home page:' . (get_user_meta($user_ID, c_al2fb_meta_like_nohome, true) ? 'Yes' : 'No') . '
Not posts:' . (get_user_meta($user_ID, c_al2fb_meta_like_noposts, true) ? 'Yes' : 'No') . '
Not pages:' . (get_user_meta($user_ID, c_al2fb_meta_like_nopages, true) ? 'Yes' : 'No') . '
Not archives:' . (get_user_meta($user_ID, c_al2fb_meta_like_noarchives, true) ? 'Yes' : 'No') . '
Not categories:' . (get_user_meta($user_ID, c_al2fb_meta_like_nocategories, true) ? 'Yes' : 'No') . '
Like layout:' . get_user_meta($user_ID, c_al2fb_meta_like_layout, true) . '
Like faces:' . (get_user_meta($user_ID, c_al2fb_meta_like_faces, true) ? 'Yes' : 'No') . '
Like width:' . get_user_meta($user_ID, c_al2fb_meta_like_width, true) . '
Like action:' . get_user_meta($user_ID, c_al2fb_meta_like_action, true) . '
Like font:' . get_user_meta($user_ID, c_al2fb_meta_like_font, true) . '
Like color scheme:' . get_user_meta($user_ID, c_al2fb_meta_like_colorscheme, true) . '
Like link:' . get_user_meta($user_ID, c_al2fb_meta_like_link, true) . '
Like top:' . (get_user_meta($user_ID, c_al2fb_meta_like_top, true) ? 'Yes' : 'No') . '
Send button:' . (get_user_meta($user_ID, c_al2fb_meta_post_send_button, true) ? 'Yes' : 'No') . '
Combine buttons:' . (get_user_meta($user_ID, c_al2fb_meta_post_combine_buttons, true) ? 'Yes' : 'No') . '
Like box width:' . get_user_meta($user_ID, c_al2fb_meta_like_box_width, true) . '
Like box border:' . get_user_meta($user_ID, c_al2fb_meta_like_box_border, true) . '
Like box no header:' . (get_user_meta($user_ID, c_al2fb_meta_like_box_noheader, true) ? 'Yes' : 'No') . '
Like box no stream:' . (get_user_meta($user_ID, c_al2fb_meta_like_box_nostream, true) ? 'Yes' : 'No') . '
Comments posts:' . get_user_meta($user_ID, c_al2fb_meta_comments_posts, true) . '
Comments width:' . get_user_meta($user_ID, c_al2fb_meta_comments_width, true) . '
Facepile size:' . get_user_meta($user_ID, c_al2fb_meta_pile_size, true) . '
Facepile width:' . get_user_meta($user_ID, c_al2fb_meta_pile_width, true) . '
Facepile rows:' . get_user_meta($user_ID, c_al2fb_meta_pile_rows, true) . '
Registration width:' . get_user_meta($user_ID, c_al2fb_meta_reg_width, true) . '
Login width:' . get_user_meta($user_ID, c_al2fb_meta_login_width, true) . '
Registration URL:Link
Redir URL:Link
Login text/HTML:Link
Activity width:' . get_user_meta($user_ID, c_al2fb_meta_act_width, true) . '
Activity height:' . get_user_meta($user_ID, c_al2fb_meta_act_height, true) . '
Activity header:' . (get_user_meta($user_ID, c_al2fb_meta_act_header, true) ? 'Yes' : 'No') . '
Activity recommend:' . (get_user_meta($user_ID, c_al2fb_meta_act_recommend, true) ? 'Yes' : 'No') . '
Facebook ID:' . $fid . '
OGP:' . (get_user_meta($user_ID, c_al2fb_meta_open_graph, true) ? 'Yes' : 'No') . '
OGP type:' . get_user_meta($user_ID, c_al2fb_meta_open_graph_type, true) . '
OGP admins:' . get_user_meta($user_ID, c_al2fb_meta_open_graph_admins, true) . '
Timeout:' . htmlspecialchars(get_option(c_al2fb_option_timeout), ENT_QUOTES, $charset) . '
No notices:' . (get_option(c_al2fb_option_nonotice) ? 'Yes' : 'No') . '
Min. capability:' . htmlspecialchars(get_option(c_al2fb_option_min_cap), ENT_QUOTES, $charset) . '
Refresh comments:' . htmlspecialchars(get_option(c_al2fb_option_msg_refresh), ENT_QUOTES, $charset) . '
Max. length:' . htmlspecialchars(get_option(c_al2fb_option_max_descr), ENT_QUOTES, $charset) . '
Max. text length:' . htmlspecialchars(get_option(c_al2fb_option_max_text), ENT_QUOTES, $charset) . '
Exclude post types:' . htmlspecialchars(get_option(c_al2fb_option_exclude_type), ENT_QUOTES, $charset) . '
Exclude categories:' . htmlspecialchars(get_option(c_al2fb_option_exclude_cat), ENT_QUOTES, $charset) . '
No verify peer:' . (get_option(c_al2fb_option_noverifypeer) ? 'Yes' : 'No') . '
Shortcode/widget:' . (get_option(c_al2fb_option_shortcode_widget) ? 'Yes' : 'No') . '
No shortcode:' . (get_option(c_al2fb_option_noshortcode) ? 'Yes' : 'No') . '
No statistics:' . (get_option(c_al2fb_option_optout) ? 'Yes' : 'No') . '
Site URL:' . htmlspecialchars(get_option(c_al2fb_option_siteurl), ENT_QUOTES, $charset) . '
Do not use cURL:' . (get_option(c_al2fb_option_nocurl) ? 'Yes' : 'No') . '
Use publish_post:' . (get_option(c_al2fb_option_use_pp) ? 'Yes' : 'No') . '
Debug:' . (get_option(c_al2fb_option_debug) ? 'Yes' : 'No') . '
CSS:' . htmlspecialchars(get_option(c_al2fb_option_css), ENT_QUOTES, $charset) . '
wp_get_attachment_thumb_url:' . (function_exists('wp_get_attachment_thumb_url') ? 'Yes' : 'No') . '
wp_get_attachment_image_src:' . (function_exists('wp_get_attachment_image_src') ? 'Yes' : 'No') . '
theme - post-thumbnails:' . (current_theme_supports('post-thumbnails') ? 'Yes' : 'No') . '
get_post_thumbnail_id:' . (function_exists('get_post_thumbnail_id') ? 'Yes' : 'No') . '
wp_get_attachment_image_src:' . (function_exists('wp_get_attachment_image_src') ? 'Yes' : 'No') . '
Post #' . $posts->post->ID . ':' . htmlspecialchars(get_the_title($posts->post->ID), ENT_QUOTES, $charset) . ''; $info .= ' by ' . htmlspecialchars($userdata->user_login, ENT_QUOTES, $charset); $info .= ' @ ' . $posts->post->post_date; $info .= ' ' . $picture['picture_type'] . ''; if (!empty($selected_picture)) $info .= ' selected'; if (!empty($attached_picture)) $info .= ' attached'; if (!empty($featured_picture)) $info .= ' featured'; if (!empty($post_picture)) $info .= ' post'; if (!empty($avatar_picture)) $info .= ' avatar'; if (!empty($link_id)) $info .= ' Facebook'; $info .= '
Link picture #' . $posts->post->ID . ':' . htmlspecialchars(get_the_title($posts->post->ID), ENT_QUOTES, $charset) . ''; $info .= ' ' . htmlspecialchars($link_picture, ENT_QUOTES, $charset); $info .= ' @ ' . $posts->post->post_date . '
Error:' . htmlspecialchars($error, ENT_QUOTES, $charset) . '
Error time:' . htmlspecialchars(get_post_meta($posts->post->ID, c_al2fb_meta_link_time, true), ENT_QUOTES, $charset) . '
Error post:' . htmlspecialchars(get_the_title($posts->post->ID), ENT_QUOTES, $charset) . '
Last error:' . htmlspecialchars(get_option(c_al2fb_last_error), ENT_QUOTES, $charset) . '
Last error time:' . htmlspecialchars(get_option(c_al2fb_last_error_time), ENT_QUOTES, $charset) . '
'; $info .= '
' . print_r($_SERVER, true) . '
'; return $info; } // Update usage statistics function Update_statistics($action, $post) { if (get_option(c_al2fb_option_optout)) return; try { $uri = self::Redirect_uri(); $title = html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset')); // Get plugin version if (!function_exists('get_plugins')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); $plugin_folder = get_plugins('/' . plugin_basename(dirname(__FILE__))); $plugin_version = $plugin_folder[basename($this->main_file)]['Version']; // Security $hash = md5(AUTH_KEY ? AUTH_KEY : get_bloginfo('url')); // Update $query = http_build_query(array( 'action' => $action, 'api' => 1, 'url' => $uri, 'userid' => self::Get_user_ID($post), 'charset' => get_bloginfo('charset'), 'lang' => get_bloginfo('language'), 'dir' => get_bloginfo('text_direction'), 'zone' => get_option('gmt_offset'), 'ver' => $plugin_version, 'title' => $title, 'hash' => $hash ), '', '&'); $response = self::Request('http://al2fb.bokhorst.biz/', $query, 'POST'); $service = json_decode($response, true); if (isset($service->id)) { $user_ID = self::Get_user_ID($post); // Delete existing messages $msgs = get_user_meta($user_ID, c_al2fb_meta_service, false); if ($msgs) foreach ($msgs as $msg) if (is_object($msg) ? $msg->id == $service['id'] : $msg['id'] == $service['id']) delete_user_meta($user_ID, c_al2fb_meta_service, $msg); // Add new message add_user_meta($user_ID, c_al2fb_meta_service, $service); } } catch (Exception $e) { if ($this->debug) print_r($e); } } // 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'); self::Check_function('md5'); } 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); } } } class AL2FB_Widget extends WP_Widget { function AL2FB_Widget() { $widget_ops = array('classname' => 'widget_al2fb', 'description' => ''); $this->WP_Widget('AL2FB_Widget', 'Add Link to Facebook', $widget_ops); } function widget($args, $instance) { global $wp_al2fb; if (!is_single() && !is_page()) return; // Get current post if (!empty($GLOBALS['post'])) $post = $GLOBALS['post']; if (empty($post->ID) && !empty($post['post_id'])) $post = get_post($post['post_id']); if (empty($post) || empty($post->ID)) return; // Excluded post types $ex_custom_types = explode(',', get_option(c_al2fb_option_exclude_type)); if (in_array($post->post_type, $ex_custom_types)) return; // Get user $user_ID = $wp_al2fb->Get_user_ID($post); // Check if widget should be displayed if ((get_user_meta($user_ID, c_al2fb_meta_like_nohome, true) && is_home()) || (get_user_meta($user_ID, c_al2fb_meta_like_noposts, true) && is_single()) || (get_user_meta($user_ID, c_al2fb_meta_like_nopages, true) && is_page()) || (get_user_meta($user_ID, c_al2fb_meta_like_noarchives, true) && is_archive()) || (get_user_meta($user_ID, c_al2fb_meta_like_nocategories, true) && is_category()) || get_post_meta($post->ID, c_al2fb_meta_nolike, true)) return; // Get settings $comments = isset($instance['al2fb_comments']) ? $instance['al2fb_comments'] : false; $messages = isset($instance['al2fb_messages']) ? $instance['al2fb_messages'] : false; $messages_comments = isset($instance['al2fb_messages_comments']) ? $instance['al2fb_messages_comments'] : false; $like_button = isset($instance['al2fb_like_button']) ? $instance['al2fb_like_button'] : false; $like_box = isset($instance['al2fb_like_box']) ? $instance['al2fb_like_box'] : false; $send_button = isset($instance['al2fb_send_button']) ? $instance['al2fb_send_button'] : false; $comments_plugin = isset($instance['al2fb_comments_plugin']) ? $instance['al2fb_comments_plugin'] : false; $face_pile = isset($instance['al2fb_face_pile']) ? $instance['al2fb_face_pile'] : false; $profile = isset($instance['al2fb_profile']) ? $instance['al2fb_profile'] : false; $registration = isset($instance['al2fb_registration']) ? $instance['al2fb_registration'] : false; $login = isset($instance['al2fb_login']) ? $instance['al2fb_login'] : false; $activity = isset($instance['al2fb_activity']) ? $instance['al2fb_activity'] : false; // Logged in? $registration = ($registration && !is_user_logged_in() && get_option('users_can_register')); $login = ($login && !is_user_logged_in()); // More settings $charset = get_bloginfo('charset'); $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); // Get link type $comments_nolink = get_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, true); if (empty($comments_nolink)) $comments_nolink = 'author'; else if ($comments_nolink == 'on') $comments_nolink = 'none'; // Get time zone offset $tz_off = get_option('gmt_offset'); if (empty($tz_off)) $tz_off = 0; else $tz_off = $tz_off * 3600; // Get comments $fb_comments = false; if ($comments) $fb_comments = $wp_al2fb->Get_comments_or_likes($post, false); // Get messages $fb_messages = false; if ($messages) try { $fb_messages = $wp_al2fb->Get_fb_feed($user_ID); } catch (Exception $e) { } if ($fb_comments || $fb_messages || $like_button || $like_box || $send_button || $comments_plugin || $face_pile || $profile || $registration || $login || $activity) { // Get values extract($args); $title = apply_filters('widget_title', $instance['title']); // Build content echo $before_widget; if (empty($title)) $title = 'Add Link to Facebook'; echo $before_title . $title . $after_title; // Comments if ($fb_comments) { echo '
'; self::Render_fb_comments($fb_comments, $comments_nolink, $link_id); echo '
'; } // Messages if ($fb_messages) { echo '
    '; foreach ($fb_messages->data as $fb_message) if ($fb_message->type == 'status') { echo '
  • '; // Image if ($comments_nolink == 'author') echo '' . htmlspecialchars($fb_message->from->name, ENT_QUOTES, $charset) . ''; // Author if ($comments_nolink == 'link') echo '' . htmlspecialchars($fb_message->from->name, ENT_QUOTES, $charset) . ''; else if ($comments_nolink == 'author') echo '' . htmlspecialchars($fb_message->from->name, ENT_QUOTES, $charset) . ''; else echo '' . htmlspecialchars($fb_message->from->name, ENT_QUOTES, $charset) . ''; // Message echo ' '; echo '' . htmlspecialchars($fb_message->message, ENT_QUOTES, $charset) . ''; // Time echo ' '; $fb_time = strtotime($fb_message->created_time) + $tz_off; echo '' . date(get_option('date_format') . ' ' . get_option('time_format'), $fb_time) . ''; // Comments if ($messages_comments) try { $fb_message_comments = $wp_al2fb->Get_fb_comments_cached($user_ID, $fb_message->id); if ($fb_message_comments) self::Render_fb_comments($fb_message_comments, $comments_nolink, $fb_message->id); } catch (Exception $e) { $error = $e->getMessage(); } echo '
  • '; } echo '
'; } // Facebook like button if ($like_button) echo $wp_al2fb->Get_like_button($post, false); // Facebook like box if ($like_box) echo $wp_al2fb->Get_like_button($post, true); // Facebook send button if ($send_button) echo $wp_al2fb->Get_send_button($post); // Facebook comments plugins if ($comments_plugin) echo $wp_al2fb->Get_comments_plugin($post); // Facebook Face pile if ($face_pile) echo $wp_al2fb->Get_face_pile($post); // Facebook profile if ($profile) echo $wp_al2fb->Get_profile_link($post); // Facebook registration if ($registration) echo $wp_al2fb->Get_registration($post); // Facebook login if ($login) echo $wp_al2fb->Get_login($post); // Facebook activity feed if ($activity) echo $wp_al2fb->Get_activity_feed($post); echo $after_widget; } } // Helper render Facebook comments function Render_fb_comments($fb_comments, $comments_nolink, $link_id) { global $wp_al2fb; $charset = get_bloginfo('charset'); // Get time zone offset $tz_off = get_option('gmt_offset'); if (empty($tz_off)) $tz_off = 0; else $tz_off = $tz_off * 3600; echo '
    '; foreach ($fb_comments->data as $fb_comment) { echo '
  • '; // Picture if ($comments_nolink == 'author') echo '' . htmlspecialchars($fb_comment->from->name, ENT_QUOTES, $charset) . ''; // Author echo ' '; if ($comments_nolink == 'link') echo '' . htmlspecialchars($fb_comment->from->name, ENT_QUOTES, $charset) . ''; else if ($comments_nolink == 'author') echo '' . htmlspecialchars($fb_comment->from->name, ENT_QUOTES, $charset) . ''; else echo '' . htmlspecialchars($fb_comment->from->name, ENT_QUOTES, $charset) . ''; // Comment echo ' '; echo '' . htmlspecialchars($fb_comment->message, ENT_QUOTES, $charset) . ''; // Time echo ' '; $fb_time = strtotime($fb_comment->created_time) + $tz_off; echo '' . date(get_option('date_format') . ' ' . get_option('time_format'), $fb_time) . ''; echo '
  • '; } echo '
'; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['al2fb_comments'] = $new_instance['al2fb_comments']; $instance['al2fb_messages'] = $new_instance['al2fb_messages']; $instance['al2fb_messages_comments'] = $new_instance['al2fb_messages_comments']; $instance['al2fb_like_button'] = $new_instance['al2fb_like_button']; $instance['al2fb_like_box'] = $new_instance['al2fb_like_box']; $instance['al2fb_send_button'] = $new_instance['al2fb_send_button']; $instance['al2fb_comments_plugin'] = $new_instance['al2fb_comments_plugin']; $instance['al2fb_face_pile'] = $new_instance['al2fb_face_pile']; $instance['al2fb_profile'] = $new_instance['al2fb_profile']; $instance['al2fb_registration'] = $new_instance['al2fb_registration']; $instance['al2fb_login'] = $new_instance['al2fb_login']; $instance['al2fb_activity'] = $new_instance['al2fb_activity']; return $instance; } function form($instance) { if (empty($instance['title'])) $instance['title'] = null; if (empty($instance['al2fb_comments'])) $instance['al2fb_comments'] = false; if (empty($instance['al2fb_messages'])) $instance['al2fb_messages'] = false; if (empty($instance['al2fb_messages_comments'])) $instance['al2fb_messages_comments'] = false; if (empty($instance['al2fb_like_button'])) $instance['al2fb_like_button'] = false; if (empty($instance['al2fb_like_box'])) $instance['al2fb_like_box'] = false; if (empty($instance['al2fb_send_button'])) $instance['al2fb_send_button'] = false; if (empty($instance['al2fb_comments_plugin'])) $instance['al2fb_comments_plugin'] = false; if (empty($instance['al2fb_face_pile'])) $instance['al2fb_face_pile'] = false; if (empty($instance['al2fb_profile'])) $instance['al2fb_profile'] = false; if (empty($instance['al2fb_registration'])) $instance['al2fb_registration'] = false; if (empty($instance['al2fb_login'])) $instance['al2fb_login'] = false; if (empty($instance['al2fb_activity'])) $instance['al2fb_activity'] = false; $chk_comments = ($instance['al2fb_comments'] ? ' checked ' : ''); $chk_messages = ($instance['al2fb_messages'] ? ' checked ' : ''); $chk_messages_comments = ($instance['al2fb_messages_comments'] ? ' checked ' : ''); $chk_like = ($instance['al2fb_like_button'] ? ' checked ' : ''); $chk_box = ($instance['al2fb_like_box'] ? ' checked ' : ''); $chk_send = ($instance['al2fb_send_button'] ? ' checked ' : ''); $chk_comments_plugin = ($instance['al2fb_comments_plugin'] ? ' checked ' : ''); $chk_face_pile = ($instance['al2fb_face_pile'] ? ' checked ' : ''); $chk_profile = ($instance['al2fb_profile'] ? ' checked ' : ''); $chk_registration = ($instance['al2fb_registration'] ? ' checked ' : ''); $chk_login = ($instance['al2fb_login'] ? ' checked ' : ''); $chk_activity = ($instance['al2fb_activity'] ? ' checked ' : ''); ?>


id="get_field_id('al2fb_comments'); ?>" name="get_field_name('al2fb_comments'); ?>" />

id="get_field_id('al2fb_messages'); ?>" name="get_field_name('al2fb_messages'); ?>" />
id="get_field_id('al2fb_messages_comments'); ?>" name="get_field_name('al2fb_messages_comments'); ?>" />

id="get_field_id('al2fb_like_button'); ?>" name="get_field_name('al2fb_like_button'); ?>" />
id="get_field_id('al2fb_like_box'); ?>" name="get_field_name('al2fb_like_box'); ?>" />
id="get_field_id('al2fb_send_button'); ?>" name="get_field_name('al2fb_send_button'); ?>" />
id="get_field_id('al2fb_comments_plugin'); ?>" name="get_field_name('al2fb_comments_plugin'); ?>" />
id="get_field_id('al2fb_face_pile'); ?>" name="get_field_name('al2fb_face_pile'); ?>" />
id="get_field_id('al2fb_profile'); ?>" name="get_field_name('al2fb_profile'); ?>" />
id="get_field_id('al2fb_registration'); ?>" name="get_field_name('al2fb_registration'); ?>" />
id="get_field_id('al2fb_login'); ?>" name="get_field_name('al2fb_login'); ?>" />
id="get_field_id('al2fb_activity'); ?>" name="get_field_name('al2fb_activity'); ?>" />