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; } // Data URI request if (isset($_GET['al2fb_data_uri'])) { $post = get_post($_GET['al2fb_data_uri']); $data_uri = self::Get_first_image($post); // data:image/png;base64, // data:[<MIME-type>][;charset=<encoding>][;base64],<data> $semi = strpos($data_uri, ';'); $comma = strpos($data_uri, ','); $content_type = substr($data_uri, 5, $semi - 5); $data = substr($data_uri, $comma + 1); header('Content-type: ' . $content_type); echo base64_decode($data); exit; } // Facebook registration if (isset($_REQUEST['al2fb_reg'])) { WPAL2Int::Facebook_registration(); exit; } // Facebook login if (isset($_REQUEST['al2fb_login'])) { WPAL2Int::Facebook_login(); exit; } // Facebook subscription if (isset($_REQUEST['al2fb_subscription'])) { self::Handle_fb_subscription(); exit; } // Set default capability if (!get_option(c_al2fb_option_min_cap)) { update_option(c_al2fb_option_min_cap, 'edit_posts'); } // Enqueue style sheet if (is_admin()) { $css_name = $this->Change_extension(basename($this->main_file), '-admin.css'); $css_url = plugins_url($css_name, __FILE__); 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 = plugins_url($css_name, __FILE__); } } wp_register_style('al2fb_style', $css_url); wp_enqueue_style('al2fb_style'); } if (get_option(c_al2fb_option_use_ssp) || is_admin()) { wp_enqueue_script('jquery'); } // Social share privacy if (get_option(c_al2fb_option_use_ssp)) { wp_enqueue_script('socialshareprivacy', plugins_url('/js/jquery.socialshareprivacy.js', __FILE__), array('jquery')); } // 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(); // Clear cache WPAL2Int::Clear_fb_pages_cache($user_ID); WPAL2Int::Clear_fb_groups_cache($user_ID); WPAL2Int::Clear_fb_friends_cache($user_ID); // Redirect $auth_url = WPAL2Int::Authorize_url($user_ID); try { // Check if (ini_get('safe_mode') || ini_get('open_basedir') || $this->debug) { update_option(c_al2fb_log_redir_check, 'No'); } else { $response = WPAL2Int::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 if (is_multisite()) { global $blog_id; $error_url = get_admin_url($blog_id, 'admin.php?page=' . $this->main_plugin_name, 'admin'); } else { $error_url = admin_url('admin.php?page=' . $this->main_plugin_name); } $error_url .= '&al2fb_action=error'; $error_url .= '&error=' . urlencode($e->getMessage()); wp_redirect($error_url); exit; } } } // Handle Facebook authorization WPAL2Int::Authorize(); } self::Upgrade(); }
static function Facebook_login() { header('Content-type: text/plain'); try { // Check token $url = 'https://graph.facebook.com/v2.2/' . $_REQUEST['uid']; $url = apply_filters('al2fb_url', $url); $query = http_build_query(array('access_token' => $_REQUEST['token']), '', '&'); $response = WPAL2Int::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 = WPAL2Int::Login_by_email($users[0]->user_email, true); // Check login if ($user) { // Persist token update_user_meta($user->ID, c_al2fb_meta_facebook_token, $_REQUEST['token']); update_user_meta($user->ID, c_al2fb_meta_facebook_token_time, time()); // 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 (get_option(c_al2fb_option_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 (get_option(c_al2fb_option_debug)) { print_r($_REQUEST); print_r($response); } } } 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; } }