public function process_request($request) { if ($request == 'facebook-login') { $app_id = qa_opt('facebook_app_id'); $app_secret = qa_opt('facebook_app_secret'); $tourl = qa_get('to'); if (!strlen($tourl)) { $tourl = qa_path_absolute(''); } if (strlen($app_id) && strlen($app_secret)) { require_once $this->directory . 'facebook.php'; $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true)); $fb_userid = $facebook->getUser(); if ($fb_userid) { try { $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)'); if (is_array($user)) { qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null)); } } catch (FacebookApiException $e) { } } else { qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl))); } } qa_redirect_raw($tourl); } }
/** * Fetch metadata information from an URL * @param string $url URL linking to a metadata.json file * @return array The metadata fetched from the file */ public function fetchFromUrl($url, $type = 'Plugin') { $contents = qa_retrieve_url($url); $metadata = $this->getArrayFromJson($contents); // fall back to old metadata format if (empty($metadata)) { $metadata = qa_addon_metadata($contents, $type); } return $metadata; }
function check_login() { // Based on sample code: http://developers.facebook.com/docs/guides/web $testfacebook = false; foreach ($_COOKIE as $key => $value) { if (substr($key, 0, 5) == 'fbsr_') { $testfacebook = true; } } if (!$testfacebook) { // to save making a database query for qa_opt() if there's no point return; } $app_id = qa_opt('facebook_app_id'); $app_secret = qa_opt('facebook_app_secret'); if (!(strlen($app_id) && strlen($app_secret))) { return; } if (!function_exists('json_decode')) { // work around fact that PHP might not have JSON extension installed require_once $this->directory . 'JSON.php'; function json_decode($json) { $decoder = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); return $decoder->decode($json); } } require_once $this->directory . 'facebook.php'; $facebook = new Facebook(array('appId' => qa_opt('facebook_app_id'), 'secret' => qa_opt('facebook_app_secret'), 'cookie' => true)); $fb_userid = $facebook->getUser(); if ($fb_userid) { try { $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture'); if (is_array($user)) { qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']) ? qa_retrieve_url($user['picture']) : null)); } } catch (FacebookApiException $e) { $facebookuserid = null; } } }
function check_login() { // Based on sample code: http://developers.facebook.com/docs/guides/web $testfacebook = false; foreach ($_COOKIE as $key => $value) { if (substr($key, 0, 4) == 'fbs_') { $testfacebook = true; } } if (!$testfacebook) { // to save making a database query for qa_opt() if there's no point return; } $app_id = qa_opt('facebook_app_id'); $app_secret = qa_opt('facebook_app_secret'); if (!(strlen($app_id) && strlen($app_secret))) { return; } if (isset($_COOKIE['fbs_' . $app_id])) { $args = array(); parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args); ksort($args); $payload = ''; foreach ($args as $key => $value) { if ($key != 'sig') { $payload .= $key . '=' . $value; } } if (md5($payload . qa_opt('facebook_app_secret')) == $args['sig']) { $rawuser = qa_retrieve_url('https://graph.facebook.com/me?access_token=' . $args['access_token'] . '&fields=email,name,verified,location,website,about,picture'); if (strlen($rawuser)) { require_once $this->directory . 'JSON.php'; $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $user = $json->decode($rawuser); if (is_array($user)) { qa_log_in_external_user('facebook', $args['uid'], array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['about'], 'avatar' => strlen(@$user['picture']) ? qa_retrieve_url($user['picture']) : null)); } } } } }
function doctype() { if ($this->request == 'admin/emails') { if (qa_post_text('option_notify_admin_a_post')) { qa_opt('notify_admin_a_post', (bool) qa_post_text('option_notify_admin_a_post')); qa_opt('notify_admin_c_post', (bool) qa_post_text('option_notify_admin_c_post')); } foreach ($this->content['form']['fields'] as $key => $val) { $arr[$key] = $val; if ($key == 'notify_admin_q_post') { $arr['notify_admin_a_post'] = array('id' => 'notify_admin_a_post', 'label' => 'Email this address when an answer is posted', 'tags' => 'NAME="option_notify_admin_a_post" ID="option_notify_admin_a_post"', 'value' => qa_opt('notify_admin_a_post'), 'type' => 'checkbox', 'error' => ''); $arr['notify_admin_c_post'] = array('id' => 'notify_admin_a_post', 'label' => 'Email this address when a comment is posted', 'tags' => 'NAME="option_notify_admin_c_post" ID="option_notify_admin_c_post"', 'value' => qa_opt('notify_admin_c_post'), 'type' => 'checkbox', 'error' => ''); } $this->content['form']['fields'] = $arr; } } if (qa_opt('admin_plus_notify') && qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN && (time() - (int) qa_opt('admin_plus_notify_checked')) / 3600 > qa_opt('admin_plus_notify_hours')) { qa_opt('admin_plus_notify_checked', time()); $pluginfiles = glob(QA_PLUGIN_DIR . '*/qa-plugin.php'); if (count($pluginfiles)) { require_once QA_INCLUDE_DIR . 'qa-app-admin.php'; $cnt = 0; foreach ($pluginfiles as $pluginfile) { $plugindirectory = dirname($pluginfile) . '/'; $contents = file_get_contents($pluginfile); $metadata = qa_admin_addon_metadata($contents, array('version' => 'Plugin Version', 'update' => 'Plugin Update Check URI')); if (@$metadata['version'] && @$metadata['update']) { $newdata = qa_admin_addon_metadata(qa_retrieve_url($metadata['update']), array('version' => 'Plugin Version', 'uri' => 'Plugin URI')); if (strlen(@$newdata['version']) && strcmp($newdata['version'], $metadata['version'])) { $this->content['notices'][] = qa_notice_form('updates', qa_viewer_html(qa_opt('admin_plus_notify_text'), 'html')); $this->content['script'][] = "<script type=\"text/javascript\">jQuery(document).ready(function(){qa_reveal(document.getElementById('notice_updates'), 'notice');});</script>"; break; } } } } } qa_html_theme_base::doctype(); }
function process_request($request) { if ($request == 'facebook-login') { $app_id = qa_opt('facebook_app_id'); $app_secret = qa_opt('facebook_app_secret'); $tourl = qa_get('to'); if (!strlen($tourl)) { $tourl = qa_path_absolute(''); } if (strlen($app_id) && strlen($app_secret)) { if (!function_exists('json_decode')) { // work around fact that PHP might not have JSON extension installed require_once $this->directory . 'JSON.php'; function json_decode($json) { $decoder = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); return $decoder->decode($json); } } require_once $this->directory . 'facebook.php'; $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true)); $fb_userid = $facebook->getUser(); if ($fb_userid) { try { $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture'); if (is_array($user)) { qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null)); } } catch (FacebookApiException $e) { } } else { qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl))); } } qa_redirect_raw($tourl); } }
as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. More about this license: http://www.question2answer.org/license.php */ require_once QA_INCLUDE_DIR . 'qa-app-admin.php'; $uri = qa_post_text('uri'); $versionkey = qa_post_text('versionkey'); $urikey = qa_post_text('urikey'); $version = qa_post_text('version'); $metadata = qa_admin_addon_metadata(qa_retrieve_url($uri), array('version' => $versionkey, 'uri' => $urikey, 'min_q2a' => 'Plugin Minimum Question2Answer Version', 'min_php' => 'Plugin Minimum PHP Version')); if (strlen(@$metadata['version'])) { if (strcmp($metadata['version'], $version)) { if (qa_qa_version_below(@$metadata['min_q2a'])) { $response = strtr(qa_lang_html('admin/version_requires_q2a'), array('^1' => qa_html('v' . $metadata['version']), '^2' => qa_html($metadata['min_q2a']))); } elseif (qa_php_version_below(@$metadata['min_php'])) { $response = strtr(qa_lang_html('admin/version_requires_php'), array('^1' => qa_html('v' . $metadata['version']), '^2' => qa_html($metadata['min_php']))); } else { $response = qa_lang_html_sub('admin/version_get_x', qa_html('v' . $metadata['version'])); if (strlen(@$metadata['uri'])) { $response = '<A HREF="' . qa_html($metadata['uri']) . '" STYLE="color:#d00;">' . $response . '</A>'; } } } else { $response = qa_lang_html('admin/version_latest'); }
function check_login() { $action = null; $key = null; if (!empty($_GET['hauth_start'])) { $key = trim(strip_tags($_GET['hauth_start'])); $action = 'process'; } else { if (!empty($_GET['hauth_done'])) { $key = trim(strip_tags($_GET['hauth_done'])); $action = 'process'; } else { if (!empty($_GET['login'])) { $key = trim(strip_tags($_GET['login'])); $action = 'login'; } else { if (isset($_GET['fb_source']) && $_GET['fb_source'] == 'appcenter' && isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], 'www.facebook.com') !== false && isset($_GET['fb_appcenter']) && $_GET['fb_appcenter'] == '1' && isset($_GET['code'])) { // allow AppCenter users to login directly $key = 'facebook'; $action = 'login'; } } } } if ($key == null || strcasecmp($key, $this->provider) != 0) { return false; } if ($action == 'login') { // handle the login // after login come back to the same page $loginCallback = qa_path('', array(), qa_opt('site_url')); require_once $this->directory . 'Hybrid/Auth.php'; require_once $this->directory . 'qa-open-utils.php'; // prepare the configuration of HybridAuth $config = $this->getConfig($loginCallback); $topath = qa_get('to'); if (!isset($topath)) { $topath = ''; // redirect to front page } try { // try to login $hybridauth = new Hybrid_Auth($config); $adapter = $hybridauth->authenticate($this->provider); // if ok, create/refresh the user account $user = $adapter->getUserProfile(); $duplicates = 0; if (!empty($user)) { $duplicates = qa_log_in_external_user($key, $user->identifier, array('email' => @$user->email, 'handle' => @$user->displayName, 'confirmed' => !empty($user->emailVerified), 'name' => @$user->displayName, 'location' => @$user->region, 'website' => @$user->webSiteURL, 'about' => @$user->description, 'avatar' => strlen(@$user->photoURL) ? qa_retrieve_url($user->photoURL) : null)); } if ($duplicates > 0) { qa_redirect('logins', array('confirm' => '1', 'to' => $topath)); } else { qa_redirect_raw(qa_opt('site_url') . $topath); } } catch (Exception $e) { // not really interested in the error message - for now // however, in case we have errors 6 or 7, then we have to call logout to clean everything up if ($e->getCode() == 6 || $e->getCode() == 7) { $adapter->logout(); } $qry = 'provider=' . $this->provider . '&code=' . $e->getCode(); if (strstr($topath, '?') === false) { $topath .= '?' . $qry; } else { $topath .= '&' . $qry; } // redirect qa_redirect_raw(qa_opt('site_url') . $topath); } } if ($action == 'process') { require_once "Hybrid/Auth.php"; require_once "Hybrid/Endpoint.php"; Hybrid_Endpoint::process(); } return false; }