/** * locate() should find paths from the include path * * @param string[] $paths * @dataProvider provideTestLocateFindsIncludePath * @see ConfigurationLocator::locate(); */ public function testLocateFindsIncludePath($includePath, array $paths) { set_include_path(get_include_path() . PATH_SEPARATOR . $includePath); $locator = new ConfigurationLocator($paths); $configuration = $locator->locate(); $this->assertInstanceOf("malkusch\\bav\\Configuration", $configuration); $this->assertEquals("test", $configuration->getTempDirectory()); restore_include_path(); }
/** * Tests the initialization with a configuration from the include path. * * @see ConfigurationRegistry::classConstructor() */ public function testInitWithIncludePathConfiguration() { set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . "/../data/"); ConfigurationRegistry::classConstructor(); $configuration = ConfigurationRegistry::getConfiguration(); $this->assertInstanceOf("malkusch\\bav\\Configuration", $configuration); $this->assertEquals("test", $configuration->getTempDirectory()); restore_include_path(); }
/** * Is the module active ? * * @return int */ public function isActive() { try { set_include_path('/usr/share/php/'); $res = @(include_once 'FirePHPCore/FirePHP.class.php'); restore_include_path(); if ($res) { return 1; } } catch (Exception $e) { print '<!-- FirePHP not available into PHP -->' . "\n"; } return -1; }
function __construct($__DIR__) { set_include_path($__DIR__); $c = \Pyrus\Config::singleton(dirname($__DIR__), dirname($__DIR__) . '/pearconfig.xml'); $c->bin_dir = $__DIR__ . '/bin'; restore_include_path(); $c->saveConfig(); $chan = new PEAR2\SimpleChannelServer\Channel('pear2.php.net', 'unit test channel'); $scs = new PEAR2\SimpleChannelServer\Main($chan, $__DIR__, dirname($__DIR__) . '/PEAR2'); $scs->saveChannel(); $this->chan = $chan; $this->scs = $scs; $this->__DIR__ = $__DIR__; }
/** * Is the module active ? * * @return boolean */ public function isActive() { global $conf; try { if (empty($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH)) { $conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH = '/usr/share/php'; } set_include_path($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH); $res = @(include_once 'ChromePhp.class.php'); restore_include_path(); if ($res) { return 1; } } catch (Exception $e) { print '<!-- ChromePHP not available into PHP -->' . "\n"; } return -1; }
/** * Is the module active ? * * @return int */ public function isActive() { global $conf; try { if (empty($conf->global->SYSLOG_FIREPHP_INCLUDEPATH)) { $conf->global->SYSLOG_FIREPHP_INCLUDEPATH = DOL_DOCUMENT_ROOT . self::$firephp_include_path; } set_include_path($conf->global->SYSLOG_FIREPHP_INCLUDEPATH); $res = @(include_once self::$firephp_class_path); restore_include_path(); if ($res) { return 1; } else { return 0; } } catch (Exception $e) { print '<!-- FirePHP not available into PHP -->' . "\n"; } return -1; }
/** * Is the module active ? * * @return int */ public function isActive() { global $conf; try { if (empty($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH)) { $conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH = DOL_DOCUMENT_ROOT . '/includes/chromephp/'; } set_include_path($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH); //print 'rrrrr'.get_include_path(); $res = @(include_once 'ChromePhp.php'); if (!$res) { $res = @(include_once 'ChromePhp.class.php'); } restore_include_path(); if ($res) { return 1; } } catch (Exception $e) { print '<!-- ChromePHP not available into PHP -->' . "\n"; } return -1; }
/** * Build an SReg attribute query extension if we've never seen this OpenID before. */ function openid_add_sreg_extension($extensions, $auth_request) { if (!get_user_by_openid($auth_request->endpoint->claimed_id)) { set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); require_once 'Auth/OpenID/SReg.php'; restore_include_path(); $extensions[] = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname')); } return $extensions; }
public static function dispatch($request) { $registry = Registry::getInstance(); $config = $registry->get('config'); $carray = $config->getArray(); self::$_request = $request; if (self::$_request->isComponent()) { $componente = self::$_request->getComponent(); restore_include_path(); set_include_path('../lib/' . PATH_SEPARATOR . get_include_path()); set_include_path('../app/Components/' . $componente . '/app/' . PATH_SEPARATOR . get_include_path()); set_include_path('../app/Components/' . $componente . '/app/Controller/' . PATH_SEPARATOR . get_include_path()); set_include_path('../app/Model/' . PATH_SEPARATOR . get_include_path()); self::initSite('../app/Components/' . $componente . '/app/Config/config.ini', $componente); self::$_request->constructsFromGet(); } if ($carray['general']['debug'] != true) { ob_start(); } $controller = self::$_request->getController(); $action = self::$_request->getAction(); $params = self::$_request->getParams(); self::preController(); $app = self::runController(); self::postController(); if ($carray['general']['debug'] != true) { ob_end_clean(); } // Manage view ob_start(); $layout = NULL; if (!empty($carray['general']['layout'])) { $layout = $carray['general']['layout']; } $template = $app->getView()->getTemplate($layout); self::loadTemplate($app->getView(), $template); $output = ob_get_clean(); echo $output; }
function LoadTPL($TPLName, $Values = "") { global $TEMPLATES; $TPLFile = MAINTEMPLATES . $TPLName . ".php"; if (is_file($TPLFile) && !strstr($TPLName, "..")) { if (is_array($Values)) { reset($Values); while ($key = key($Values)) { ${"TPL_" . $key} = current($Values); // lokale Variablen für die zu ersetzenden Werte erstellen next($Values); } } else { $Value = $Values; } ob_start("TemplateOB"); restore_include_path(); include $TPLFile; // Template-Datei einbinden. $Return = ob_get_clean(); $TEMPLATES[count($TEMPLATES)] = $TPLFile; // DEBUG return $Return; } else { Error("Unknown File: " . $TPLFile); } }
function _dispatchEnd() { global $phpbb_root_path, $phpbb_admin_path, $phpEx; global $user, $auth, $template, $cache, $db, $config, $phpbb_hook; global $action, $module, $mode, $starttime; global $forum_id, $topic_id, $post_id, $user_id; $contents = ob_get_contents(); ob_end_clean(); restore_include_path(); return $contents; }
<?php // disable array -> "Array" conversion notice error_reporting(error_reporting() & ~E_NOTICE); // originally came from ext/standard/tests/general_functions/include_path.phpt var_dump(get_include_path()); var_dump(get_include_path("var")); var_dump(restore_include_path()); var_dump(restore_include_path("")); var_dump(set_include_path()); var_dump(get_include_path()); var_dump(set_include_path("var")); var_dump(get_include_path()); var_dump(restore_include_path()); var_dump(get_include_path()); var_dump(set_include_path(".:/path/to/dir")); var_dump(get_include_path()); var_dump(restore_include_path()); var_dump(get_include_path()); var_dump(set_include_path("")); var_dump(get_include_path()); var_dump(restore_include_path()); var_dump(get_include_path()); var_dump(set_include_path(array())); var_dump(get_include_path()); var_dump(restore_include_path()); var_dump(get_include_path()); echo "Done\n";
/** * Initialize required store and consumer and make a few sanity checks. This method * does a lot of the heavy lifting to get everything initialized, so we don't call it * until we actually need it. */ function late_bind($reload = false) { global $wpdb; $this->core->log->debug('beginning late binding'); $this->enabled = true; // Be Optimistic if ($this->bind_done && !$reload) { $this->core->log->debug('we\'ve already done the late bind... moving on'); return $this->uptodate(); } $this->bind_done = true; $f = @fopen('/dev/urandom', 'r'); if ($f === false) { define('Auth_OpenID_RAND_SOURCE', null); } // include required JanRain OpenID library files set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); $this->core->log->debug('temporary include path for importing = ' . get_include_path()); require_once 'Auth/OpenID/Discover.php'; require_once 'Auth/OpenID/DatabaseConnection.php'; require_once 'Auth/OpenID/MySQLStore.php'; require_once 'Auth/OpenID/Consumer.php'; require_once 'Auth/OpenID/SReg.php'; restore_include_path(); $this->core->setStatus('database: WordPress\' table prefix', 'info', isset($wpdb->base_prefix) ? $wpdb->base_prefix : $wpdb->prefix); $this->core->log->debug("Bootstrap -- checking tables"); if ($this->enabled) { $store =& $this->getStore(); if (!$store) { return; } // something broke $this->enabled = $store->check_tables(); if (!$this->uptodate()) { update_option('oid_plugin_enabled', true); update_option('oid_plugin_revision', WPOPENID_PLUGIN_REVISION); update_option('oid_db_revision', WPOPENID_DB_REVISION); $this->uptodate(); } } else { $this->error = 'WPOpenID Core is Disabled!'; update_option('oid_plugin_enabled', false); } return $this->enabled; }
/** * @return string */ public static function restore() { restore_include_path(); return static::get(); }
/** * Generates a php code using a template file * * @param string $strModuleName * @param string $strFilename * @param boolean $blnOverrideFlag whether we are using the _core template, or using a custom one * @param mixed[] $mixArgumentArray * @param boolean $blnSave whether or not to actually perform the save * @throws QCallerException * @throws Exception * @return mixed returns the evaluated template or boolean save success. */ public function GenerateFile($strModuleName, $strFilename, $blnOverrideFlag, $mixArgumentArray, $blnSave = true) { // Figure out the actual TemplateFilePath if ($blnOverrideFlag) { $strTemplateFilePath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . '/' . $strFilename; } else { $strTemplateFilePath = __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . '/' . $strFilename; } // Setup Debug/Exception Message if (QCodeGen::DebugMode) { _p("Evaluating {$strTemplateFilePath}<br/>", false); } // Check to see if the template file exists, and if it does, Load It if (!file_exists($strTemplateFilePath)) { throw new QCallerException('Template File Not Found: ' . $strTemplateFilePath); } // Evaluate the Template if (substr($strFilename, strlen($strFilename) - 8) == '.tpl.php') { // make sure paths are set up to pick up included files from both the override directory and _core directory $strSearchPath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . PATH_SEPARATOR . __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . PATH_SEPARATOR . get_include_path(); set_include_path($strSearchPath); if ($strSearchPath != get_include_path()) { throw new QCallerException('Can\'t override include path. Make sure your apache or server settings allow include paths to be overridden. '); } $strTemplate = $this->EvaluatePHP($strTemplateFilePath, $strModuleName, $mixArgumentArray, $templateSettings); restore_include_path(); if (!isset($templateSettings) || !$templateSettings) { // check if we have old style <template .../> settings $templateSettings = $this->getTemplateSettings($strTemplateFilePath, $strTemplate); } } else { $strTemplate = file_get_contents($strTemplateFilePath); $strTemplate = $this->EvaluateTemplate($strTemplate, $strModuleName, $mixArgumentArray); $templateSettings = $this->getTemplateSettings($strTemplateFilePath, $strTemplate); } $blnOverwriteFlag = QType::Cast($templateSettings['OverwriteFlag'], QType::Boolean); $blnDocrootFlag = QType::Cast($templateSettings['DocrootFlag'], QType::Boolean); $strTargetDirectory = QType::Cast($templateSettings['TargetDirectory'], QType::String); $strDirectorySuffix = QType::Cast($templateSettings['DirectorySuffix'], QType::String); $strTargetFileName = QType::Cast($templateSettings['TargetFileName'], QType::String); if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix) || is_null($blnDocrootFlag)) { throw new Exception('the template settings cannot be null'); } if ($blnSave && $strTargetDirectory) { // Figure out the REAL target directory if ($blnDocrootFlag) { $strTargetDirectory = __DOCROOT__ . $strTargetDirectory . $strDirectorySuffix; } else { $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix; } // Create Directory (if needed) if (!is_dir($strTargetDirectory)) { if (!QApplication::MakeDirectory($strTargetDirectory, 0777)) { throw new Exception('Unable to mkdir ' . $strTargetDirectory); } } // Save to Disk $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName); if ($blnOverwriteFlag || !file_exists($strFilePath)) { $intBytesSaved = file_put_contents($strFilePath, $strTemplate); $this->setGeneratedFilePermissions($strFilePath); return $intBytesSaved == strlen($strTemplate); } else { // Becuase we are not supposed to overwrite, we should return "true" by default return true; } } // Why Did We Not Save? if ($blnSave) { // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated // By definition, we should return "true" return true; } // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead return $strTemplate; }
public static function buildConcatenatedStyleFile() { $directory = trailingslashit(self::getCacheDir()); $security_key = get_option('cfao_security_key'); if ($security_key != $_POST['key']) { exit; } if (!(file_exists($directory) && is_dir($directory))) { // We need to attempt to make the directory. if (!mkdir($directory, 0775, true)) { error_log('Could not create directory: ' . $directory); exit; } } $lockfile = self::getLockFile(); if (file_exists($directory . $lockfile)) { // We're currently running a build. Throttle it to avoid DDOS Attacks. exit; } if (empty($_POST['styles'])) { error_log('No styles received'); exit; } $lock = @fopen($directory . $lockfile, 'x'); if (!$lock) { error_log('Could not create lockfile: ' . $directory . $lockfile); exit; } fwrite($lock, time()); fclose($lock); $site_styles = get_option('cfao_styles', array()); if (!is_array($site_styles)) { $site_styles = array(); } $included_styles = $_POST['styles']; $style_file_header = "/**\n" . " * Included Files\n" . " *\n"; $style_file_src = ''; $my_domain = strtolower(untrailingslashit(preg_replace('#^http(s)?:#', '', site_url()))); $styles_updated = false; foreach ($included_styles as $handle => $url) { if (empty($url) || $url === 1) { $style_file_header .= ' * ' . $handle . " as empty script handle.\n"; continue; } else { $request_url = $url; if (strpos($request_url, '//') === 0) { $request_url = 'http:' . $request_url; } if (!preg_match('|^https?://|', $request_url) && true) { $request_url = 'http://' . $_SERVER['SERVER_NAME'] . $request_url; } } $style_request = wp_remote_get($request_url); // Handle the response if (is_wp_error($style_request)) { $site_styles[$handle]['enabled'] = false; $site_styles[$handle]['disable_reason'] = 'WP Error: ' . $style_request->get_error_message(); $styles_updated = true; } else { if ($style_request['response']['code'] < 200 || $style_request['response']['code'] >= 400) { // There was an error requesting the file $site_styles[$handle]['enabled'] = false; $site_styles[$handle]['disable_reason'] = 'HTTP Error ' . $style_request['response']['code'] . ' - ' . $style_request['response']['message']; $styles_updated = true; } else { // We had a valid style to add to the list. $style_file_header .= ' * ' . $handle . ' as ' . $url . "\n"; $src = $style_request['body'] . "\n"; // Convert relative URLs to absolute URLs. // Get URL parts for this script. $parts = array(); preg_match('#(https?://[^/]*)([^?]*/)([^?]*)(\\?.*)?#', $request_url, $parts); $parts[1] = apply_filters('cfao_styles_relative_domain', $parts[1]); // Update paths that are based on web root. if (count($parts) > 1) { $regex = '~ url\\s*\\( # url( with optional internal whitespace \\s* # optional whitespace ( # begin group 1 ["\']? # an optional single or double quote ) # end option group 1 \\s* # optional whitespace ( # begin option group 2 / # url starts with / for web root url [^[:space:]] # one single non-space character .+? # one or more (non-greedy) any character ) # end option group 2 \\s* # optional whitespace \\1 # match opening delimiter \\s* # optional whitespace \\) # closing ) ~x'; $src = preg_replace($regex, 'url(' . $parts[1] . '$2)', $src); } // Update paths based on style location if (count($parts) > 2) { $regex = '~ url\\s*\\( # url( with optional internal whitespace \\s* # optional whitespace ( # begin group 1 (optional delimiter) ["\']? # an optional single or double quote ) # end group 1 \\s* # optional whitespace (?! # negative lookahead assertion: skip if... (?: # noncapturing group (not needed with lookaheads) [\'"] # keep optional quote out of url match | # or // # url starts with // | # or https?:// # url starts with http:// or https:// | # or data: # url starts with data: ) # end noncapturing group ) # end negative lookahead ( # begin group 2 (relative URL) /? # optional root / [^[:space:]] # one single nonspace character .+? # one or more (non-greedy) any character ) # end group 2 \\s* # optional whitespace \\1 # match opening delimiter \\s* # optional whitespace \\) # closing ) ~x'; $src = preg_replace($regex, 'url(' . $parts[1] . $parts[2] . '$2)', $src); } $style_file_src .= $src . "\n"; } } } $style_file_header .= " **/\n"; if ($styles_updated) { // We're going to be out of sync, so don't serve up a file, just update the options. update_option('cfao_styles', $site_styles); } else { // We have a file to write $filename = self::_getConcatenatedStylesFilename($included_styles); $file = @fopen($directory . $filename, 'w'); if (!$file === false) { // We have a valid file pointer. // Minify the contents using Minify library set_include_path(dirname(__FILE__) . '/minify/min/lib'); include 'Minify/CSS.php'; $style_file_src = Minify_CSS::minify($style_file_src, array('preserveComments' => false)); restore_include_path(); $style_file_header = apply_filters('cfao_style_file_header', $style_file_header); // Write the file and close it. fwrite($file, $style_file_header . $style_file_src); fclose($file); } else { error_log('Could not create file: ' . $directory . $filename); } } unlink($directory . $lockfile); exit; }
/** * Enter description here... * * @param string $strModuleName * @param string $strFilename * @param boolean $blnOverrideFlag whether we are using the _core template, or using a custom one * @param mixed[] $mixArgumentArray * @param boolean $blnSave wheather or not to actually perform the save * @return mixed returns the evaluated template or boolean save success. */ public function GenerateFile($strModuleName, $strFilename, $blnOverrideFlag, $mixArgumentArray, $blnSave = true) { // Figure out the actual TemplateFilePath if ($blnOverrideFlag) { $strTemplateFilePath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . '/' . $strFilename; } else { $strTemplateFilePath = __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . '/' . $strFilename; } // Setup Debug/Exception Message if (QCodeGen::DebugMode) { _p("Evaluating {$strTemplateFilePath}<br/>", false); } $strError = 'Template\'s first line must be <template OverwriteFlag="boolean" DocrootFlag="boolean" TargetDirectory="string" DirectorySuffix="string" TargetFileName="string"/>: ' . $strTemplateFilePath; // Check to see if the template file exists, and if it does, Load It if (!file_exists($strTemplateFilePath)) { throw new QCallerException('Template File Not Found: ' . $strTemplateFilePath); } $strTemplate = file_get_contents($strTemplateFilePath); // Evaluate the Template if (substr($strFilename, strlen($strFilename) - 8) == '.tpl.php') { // make sure paths are set up to pick up included files from both the override directory and _core directory $strSearchPath = __QCUBED__ . QCodeGen::TemplatesPathCustom . $strModuleName . PATH_SEPARATOR . __QCUBED_CORE__ . QCodeGen::TemplatesPath . $strModuleName . PATH_SEPARATOR . get_include_path(); set_include_path($strSearchPath); if ($strSearchPath != get_include_path()) { throw new QCallerException('Can\'t override include path. Make sure your apache or server settings allow include paths to be overriden. '); } $strTemplate = $this->EvaluatePHP($strTemplateFilePath, $strModuleName, $mixArgumentArray); restore_include_path(); } else { $strTemplate = $this->EvaluateTemplate($strTemplate, $strModuleName, $mixArgumentArray); } // Parse out the first line (which contains path and overwriting information) $intPosition = strpos($strTemplate, "\n"); if ($intPosition === false) { throw new Exception($strError); } $strFirstLine = trim(substr($strTemplate, 0, $intPosition)); $strTemplate = substr($strTemplate, $intPosition + 1); $objTemplateXml = null; // Attempt to Parse the First Line as XML try { @($objTemplateXml = new SimpleXMLElement($strFirstLine)); } catch (Exception $objExc) { } if (is_null($objTemplateXml) || !$objTemplateXml instanceof SimpleXMLElement) { throw new Exception($strError); } $blnOverwriteFlag = QType::Cast($objTemplateXml['OverwriteFlag'], QType::Boolean); $blnDocrootFlag = QType::Cast($objTemplateXml['DocrootFlag'], QType::Boolean); $strTargetDirectory = QType::Cast($objTemplateXml['TargetDirectory'], QType::String); $strDirectorySuffix = QType::Cast($objTemplateXml['DirectorySuffix'], QType::String); $strTargetFileName = QType::Cast($objTemplateXml['TargetFileName'], QType::String); if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix) || is_null($blnDocrootFlag)) { throw new Exception($strError); } if ($blnSave && $strTargetDirectory) { // Figure out the REAL target directory if ($blnDocrootFlag) { $strTargetDirectory = __DOCROOT__ . $strTargetDirectory . $strDirectorySuffix; } else { $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix; } // Create Directory (if needed) if (!is_dir($strTargetDirectory)) { if (!QApplication::MakeDirectory($strTargetDirectory, 0777)) { throw new Exception('Unable to mkdir ' . $strTargetDirectory); } } // Save to Disk $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName); if ($blnOverwriteFlag || !file_exists($strFilePath)) { $intBytesSaved = file_put_contents($strFilePath, $strTemplate); $this->setGeneratedFilePermissions($strFilePath); return $intBytesSaved == strlen($strTemplate); } else { // Becuase we are not supposed to overwrite, we should return "true" by default return true; } } // Why Did We Not Save? if ($blnSave) { // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated // By definition, we should return "true" return true; } else { // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead return $strTemplate; } }
/** * Restore defaults. * * @return void */ public final function __destruct() { restore_include_path(); restore_error_handler(); restore_exception_handler(); }
* Source code: ext/zlib/zlib.c * Alias to functions: */ require_once 'gzopen_include_path.inc'; echo "*** Testing gzopen() : variation ***\n"; $thisTestDir = "gzopenVariation5.dir"; mkdir($thisTestDir); chdir($thisTestDir); $newpath = relative_include_path(); set_include_path($newpath); runtest(); $newpath = generate_next_rel_path(); set_include_path($newpath); runtest(); teardown_relative_path(); restore_include_path(); chdir(".."); rmdir($thisTestDir); function runtest() { $tmpfile = 'gzopen_variation5.tmp'; $h = gzopen($tmpfile, "w", true); fwrite($h, "This is the test file"); fclose($h); $h = @gzopen($tmpfile, "r"); if ($h === false) { echo "Not created in working dir\n"; } else { echo "created in working dir\n"; gzclose($h); unlink($tmpfile);
/** * Retrieve user data from OpenID Attribute Exchange. * * @param string $identity_url OpenID to get user data about * @param reference $data reference to user data array * @see get_user_data */ function openid_get_user_data_ax($data, $identity_url) { set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); require_once('Auth/OpenID/AX.php'); restore_include_path(); $response = openid_response(); $ax = Auth_OpenID_AX_FetchResponse::fromSuccessResponse($response); if (!$ax) return $data; $email = $ax->getSingle('http://axschema.org/contact/email'); if ($email && !is_a($email, 'Auth_OpenID_AX_Error')) { $data['user_email'] = $email; } $nickname = $ax->getSingle('http://axschema.org/namePerson/friendly'); if ($nickname && !is_a($nickname, 'Auth_OpenID_AX_Error')) { $data['nickname'] = $ax->getSingle('http://axschema.org/namePerson/friendly'); $data['user_nicename'] = $ax->getSingle('http://axschema.org/namePerson/friendly'); $data['display_name'] = $ax->getSingle('http://axschema.org/namePerson/friendly'); } $fullname = $ax->getSingle('http://axschema.org/namePerson'); if ($fullname && !is_a($fullname, 'Auth_OpenID_AX_Error')) { $namechunks = explode( ' ', $fullname, 2 ); if( isset($namechunks[0]) ) $data['first_name'] = $namechunks[0]; if( isset($namechunks[1]) ) $data['last_name'] = $namechunks[1]; $data['display_name'] = $fullname; } return $data; }
public function connect() { if (isset($this->gapi)) { return $this->is_ready; } // only one connection allowed $this->redirect_uri = admin_URL('/admin.php?page=social-metrics-tracker-settings§ion=gapi'); // Include the Google API Library set_include_path(plugin_dir_path(dirname(__FILE__)) . 'lib/'); require_once 'Google/Client.php'; require_once 'Google/Service/Analytics.php'; restore_include_path(); try { /* * Step 1: Connection to the Google API *************/ $this->step = 1; // Do we have the necessary credentials? if (!$this->data) { return false; } if (!$this->data['gapi_client_id']) { return false; } if (!$this->data['gapi_client_secret']) { return false; } if (!$this->data['gapi_developer_key']) { return false; } // Configure the Google API $this->gapi = new Google_Client(); $this->gapi->setApplicationName(get_bloginfo('name') . ' Social Metrics Tracker'); $this->gapi->setClientId($this->data['gapi_client_id']); $this->gapi->setClientSecret($this->data['gapi_client_secret']); $this->gapi->setDeveloperKey($this->data['gapi_developer_key']); $this->gapi->setRedirectUri($this->redirect_uri); $this->analytics = new Google_Service_Analytics($this->gapi); /* * Step 2: OAuth token verification *************/ $this->step = 2; // Did we just receive an authorization code? if (isset($_GET['code']) && $_GET['code'] && !$this->data['gapi_token']) { $this->gapi->authenticate($_GET['code']); $this->data['gapi_token'] = serialize($this->gapi->getAccessToken()); $this->update_gapi_data(); // save to DB } // We really do need that token... if (!isset($this->data['gapi_token'])) { return false; } $this->gapi->setAccessToken(unserialize($this->data['gapi_token'])); $smt_gapi_token_obj = json_decode(unserialize($this->data['gapi_token'])); // Refresh the token if needed if ($smt_gapi_token_obj->created + $smt_gapi_token_obj->expires_in < time()) { $this->gapi->refreshToken($smt_gapi_token_obj->refresh_token); $this->data['gapi_token'] = serialize($this->gapi->getAccessToken()); $this->update_gapi_data(); // save to DB } /* * Step 3: Link to Analytics reporting profile *************/ $this->step = 3; // Check for linked profile if (!$this->data['gapi_profile_id']) { return false; } /* * Ready to roll! *************/ $this->step = 4; $this->is_ready = true; $this->data['data_is_flowing'] = true; $this->update_gapi_data(); // save to DB return true; } catch (Exception $e) { print '<span style="color:red">An error occured with the Google API Library: ' . $e->getMessage() . '</span>'; print 'Please <a href="' . add_query_arg('go_to_step', '1') . '">re-configure your settings</a> from step 1.'; } }
/** * @return void */ protected function tearDown() { restore_include_path(); parent::tearDown(); }