/** * @param string $name * @return \League\Flysystem\AdapterInterface * @throws \RuntimeException */ public static function make($name) { $connections = Config::get('storage.connections'); if (!isset($connections[$name])) { throw new \RuntimeException(sprintf('The storage connection %d does not exist.', $name)); } $connection = $connections[$name]; $connection['adapter'] = strtoupper($connection['adapter']); switch ($connection['adapter']) { case 'LOCAL': return new Local($connection['root_path'], $connection['public_url_base']); case 'RACKSPACE': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.rackspace'); $client = new Rackspace($service['api_endpoint'], array('username' => $service['username'], 'tenantName' => $service['tenant_name'], 'apiKey' => $service['api_key'])); $store = $client->objectStoreService($connection['store'], $connection['region']); $container = $store->getContainer($connection['container']); return new RackspaceAdapter($container); case 'AWS': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.aws'); $client = S3Client::factory(array('credentials' => array('key' => $service['access_key'], 'secret' => $service['secret_key']), 'region' => $service['region'], 'version' => 'latest')); return new AwsS3Adapter($client, $connection['bucket']); case 'GCLOUD': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.google_cloud'); $credentials = new \Google_Auth_AssertionCredentials($service['service_account'], [\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL], file_get_contents($service['key_file']), $service['secret']); $config = new \Google_Config(); $config->setAuthClass(GoogleAuthOAuth2::class); $client = new \Google_Client($config); $client->setAssertionCredentials($credentials); $client->setDeveloperKey($service['developer_key']); $service = new \Google_Service_Storage($client); return new GoogleStorageAdapter($service, $connection['bucket']); } throw new \RuntimeException(sprintf('The storage adapter %s is invalid.', $connection['adapter'])); }
public function get() { $callback = 'http://api.soundeavor.com/User/Auth/Login/Google/index.php'; $config = new \Google_Config(); $config->setApplicationName('Soundeavor'); $config->setClientId(Config::getConfig('GoogleClientId')); $config->setClientSecret(Config::getConfig('GoogleClientSecret')); $config->setRedirectUri($callback); $client = new \Google_Client($config); /* * Add scopes (permissions) for the client https://developers.google.com/oauthplayground/ */ $client->addScope('https://www.googleapis.com/auth/plus.me'); if (!isset($_GET['code'])) { $loginUrl = $client->createAuthUrl(); header('Location: ' . $loginUrl); } $code = $_GET['code']; $client->authenticate($code); $accessToken = $client->getAccessToken(); $accessToken = $accessToken['access_token']; $service = new \Google_Service_Plus($client); $scopes = $service->availableScopes; print_r($scopes); die; }
public function testExecutorSelection() { $client = $this->getClient(); $this->assertInstanceOf('Google_IO_Curl', $client->getIo()); $config = new Google_Config(); $config->setIoClass('Google_IO_Stream'); $client = new Google_Client($config); $this->assertInstanceOf('Google_IO_Stream', $client->getIo()); }
public function testExecutorSelection() { $default = function_exists('curl_version') ? 'Google_IO_Curl' : 'Google_IO_Stream'; $client = $this->getClient(); $this->assertInstanceOf($default, $client->getIo()); $config = new Google_Config(); $config->setIoClass('Google_IO_Stream'); $client = new Google_Client($config); $this->assertInstanceOf('Google_IO_Stream', $client->getIo()); }
/** * Creates a google client * * @return Google_Client */ public function createClient() { $config = new \Google_Config(); $config->setClassConfig('Google_Cache_File', array('directory' => $this->cacheDir)); $client = new \Google_Client($config); // set assertion credentials $client->setAssertionCredentials(new \Google_Auth_AssertionCredentials($this->settings->get('Analytics', 'email'), array('https://www.googleapis.com/auth/analytics.readonly'), base64_decode($this->settings->get('Analytics', 'certificate')))); $client->setAccessType('offline_access'); return $client; }
public function __construct() { $this->gadwp = GADWP(); include_once GADWP_DIR . 'tools/autoload.php'; $config = new Google_Config(); $config->setCacheClass('Google_Cache_Null'); if (function_exists('curl_version')) { $curlversion = curl_version(); if (isset($curlversion['version']) && version_compare(PHP_VERSION, '5.3.0') >= 0 && version_compare($curlversion['version'], '7.10.8') >= 0 && defined('GADWP_IP_VERSION') && GADWP_IP_VERSION) { $config->setClassConfig('Google_IO_Curl', array('options' => array(CURLOPT_IPRESOLVE => GADWP_IP_VERSION))); // Force CURL_IPRESOLVE_V4 or CURL_IPRESOLVE_V6 } } $this->client = new Google_Client($config); $this->client->setScopes('https://www.googleapis.com/auth/analytics.readonly'); $this->client->setAccessType('offline'); $this->client->setApplicationName('Google Analytics Dashboard'); $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); $this->set_error_timeout(); $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id(); $this->access = array_map(array($this, 'map'), $this->access); if ($this->gadwp->config->options['ga_dash_userapi']) { $this->client->setClientId($this->gadwp->config->options['ga_dash_clientid']); $this->client->setClientSecret($this->gadwp->config->options['ga_dash_clientsecret']); $this->client->setDeveloperKey($this->gadwp->config->options['ga_dash_apikey']); } else { $this->client->setClientId($this->access[0]); $this->client->setClientSecret($this->access[1]); } $this->service = new Google_Service_Analytics($this->client); if ($this->gadwp->config->options['ga_dash_token']) { $token = $this->gadwp->config->options['ga_dash_token']; if ($token) { try { $this->client->setAccessToken($token); $gadwp->config->options['ga_dash_token'] = $this->client->getAccessToken(); } catch (Google_IO_Exception $e) { GADWP_Tools::set_cache('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout); } catch (Google_Service_Exception $e) { GADWP_Tools::set_cache('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout); GADWP_Tools::set_cache('ga_dash_gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout); $this->reset_token(); } catch (Exception $e) { GADWP_Tools::set_cache('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout); $this->reset_token(); } if (is_multisite() && $this->gadwp->config->options['ga_dash_network']) { $this->gadwp->config->set_plugin_options(true); } else { $this->gadwp->config->set_plugin_options(); } } } }
/** * Google * @param $params array - data from config.neon * @param $cookieName String cookie name * @param Nette\Http\Response $httpResponse * @param Nette\Http\Request $httpRequest */ public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest) { $this->params = $params; $this->cookieName = $cookieName; $this->httpResponse = $httpResponse; $this->httpRequest = $httpRequest; $config = new \Google_Config(); $config->setClassConfig('Google_Cache_File', array('directory' => '/temp/cache')); $this->client = new \Google_Client($config); $this->client->setClientId($this->params["clientId"]); $this->client->setClientSecret($this->params["clientSecret"]); $this->client->setRedirectUri($this->params["callbackURL"]); }
/** * getReferenceLink * @return string */ public function getReferenceLink() { $link = '<a href="' . $this->vizReference; $link .= strtolower($this->config->getConfigObject()->type); $link .= '.html" target="_blank">Goto Google Visualization Web API Gallery</a>'; return $link; }
public function __construct() { $this->gadwp = GADWP(); include_once GADWP_DIR . 'tools/autoload.php'; $config = new Google_Config(); $config->setCacheClass('Google_Cache_Null'); if (function_exists('curl_version')) { $curlversion = curl_version(); if (isset($curlversion['version']) && version_compare(PHP_VERSION, '5.3.0') >= 0 && version_compare($curlversion['version'], '7.10.8') >= 0 && defined('GADWP_IP_VERSION') && GADWP_IP_VERSION) { $config->setClassConfig('Google_IO_Curl', array('options' => array(CURLOPT_IPRESOLVE => GADWP_IP_VERSION))); // Force // CURL_IPRESOLVE_V4 // or // CURL_IPRESOLVE_V6 } } $this->client = new Google_Client($config); $this->client->setScopes('https://www.googleapis.com/auth/analytics.readonly'); $this->client->setAccessType('offline'); $this->client->setApplicationName('Google Analytics Dashboard'); $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); $this->set_error_timeout(); $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id(); if ($this->gadwp->config->options['ga_dash_userapi']) { $this->client->setClientId($this->gadwp->config->options['ga_dash_clientid']); $this->client->setClientSecret($this->gadwp->config->options['ga_dash_clientsecret']); $this->client->setDeveloperKey($this->gadwp->config->options['ga_dash_apikey']); } else { $this->client->setClientId($this->gadwp->config->access[0]); $this->client->setClientSecret($this->gadwp->config->access[1]); $this->client->setDeveloperKey($this->gadwp->config->access[2]); } $this->service = new Google_Service_Analytics($this->client); if ($this->gadwp->config->options['ga_dash_token']) { $token = $this->gadwp->config->options['ga_dash_token']; $token = $this->refresh_token(); if ($token) { $this->client->setAccessToken($token); } } }
function __construct() { global $GADASH_Config; include_once $GADASH_Config->plugin_path . '/tools/autoload.php'; $config = new Google_Config(); $config->setCacheClass('Google_Cache_Null'); if (function_exists('curl_version')) { $curlversion = curl_version(); if (isset($curlversion['version']) and version_compare($curlversion['version'], '7.10.8') >= 0 and defined('GADWP_IP_VERSION') and GADWP_IP_VERSION) { $config->setClassConfig('Google_IO_Curl', array('options' => array(CURLOPT_IPRESOLVE => GADWP_IP_VERSION))); // Force CURL_IPRESOLVE_V4 OR CURL_IPRESOLVE_V6 } } $this->client = new Google_Client($config); $this->client->setScopes('https://www.googleapis.com/auth/analytics.readonly'); $this->client->setAccessType('offline'); $this->client->setApplicationName('Google Analytics Dashboard'); $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); $this->set_error_timeout(); $this->managequota = 'u' . get_current_user_id() . 's' . get_current_blog_id(); if ($GADASH_Config->options['ga_dash_userapi']) { $this->client->setClientId($GADASH_Config->options['ga_dash_clientid']); $this->client->setClientSecret($GADASH_Config->options['ga_dash_clientsecret']); $this->client->setDeveloperKey($GADASH_Config->options['ga_dash_apikey']); } else { $this->client->setClientId('65556128781.apps.googleusercontent.com'); $this->client->setClientSecret('Kc7888wgbc_JbeCpbFjnYpwE'); $this->client->setDeveloperKey('AIzaSyBG7LlUoHc29ZeC_dsShVaBEX15SfRl_WY'); } $this->service = new Google_Service_Analytics($this->client); if ($GADASH_Config->options['ga_dash_token']) { $token = $GADASH_Config->options['ga_dash_token']; $token = $this->ga_dash_refresh_token(); if ($token) { $this->client->setAccessToken($token); } } }
/** * Wrapper to get a Google Client object. * * This automatically sets the config to Moodle's defaults. * * @return Google_Client */ function get_google_client() { global $CFG, $SITE; make_temp_directory('googleapi'); $tempdir = $CFG->tempdir . '/googleapi'; $config = new Google_Config(); $config->setApplicationName('Moodle ' . $CFG->release); $config->setIoClass('moodle_google_curlio'); $config->setClassConfig('Google_Cache_File', 'directory', $tempdir); $config->setClassConfig('Google_Auth_OAuth2', 'access_type', 'online'); $config->setClassConfig('Google_Auth_OAuth2', 'approval_prompt', 'auto'); return new Google_Client($config); }
private function createApplicationDefaultCredentials() { $scopes = $this->prepareScopes(); $sub = $this->config->get('subject'); $signingKey = $this->config->get('signing_key'); // create credentials using values supplied in setAuthConfig if ($signingKey) { $serviceAccountCredentials = array('client_id' => $this->config->get('client_id'), 'client_email' => $this->config->get('client_email'), 'private_key' => $signingKey, 'type' => 'service_account'); $keyStream = Stream::factory(json_encode($serviceAccountCredentials)); $credentials = CredentialsLoader::makeCredentials($scopes, $keyStream); } else { $credentials = ApplicationDefaultCredentials::getCredentials($scopes); } // for service account domain-wide authority (impersonating a user) // @see https://developers.google.com/identity/protocols/OAuth2ServiceAccount if ($sub) { if (!$credentials instanceof ServiceAccountCredentials) { throw new DomainException('domain-wide authority requires service account credentials'); } $credentials->setSub($sub); } return $credentials; }
$o->addStringCellToRow("2005"); $o->addNumberCellToRow(1150); $o->addNumberCellToRow(450); $o->addNewRow(); $o->addStringCellToRow("2006"); $o->addNumberCellToRow(660); $o->addNumberCellToRow(1122); $o->addNewRow(); $o->addStringCellToRow("2007"); $o->addNumberCellToRow(855); $o->addNumberCellToRow(900); $o->addNewRow(); $o->addStringCellToRow("2008"); $o->addNumberCellToRow(545); $o->addNumberCellToRow(827); $c = new Google_Config("AreaChart", "My Title"); $c->setProperty("width", 300)->setProperty("height", 200); //$c->setIsStacked(true); $c->setPointSize(8); $c->setColors(array("red", "blue")); $c->setBorderColor("navy"); $c->setLineSize(3); $c->setAxisBackgroundColor("#f5f5f5"); $v = new Google_Visualization(); $v->setConfig($c); $v->setData($o); ?> <html> <head> <?php echo $v->render();
public function testIniConfig() { $config = new Google_Config(__DIR__ . "/testdata/test.ini"); $this->assertEquals('My Test application', $config->getApplicationName()); $this->assertEquals('gjfiwnGinpena3', $config->getClassConfig('Google_Auth_OAuth2', 'client_secret')); }
/** * @return \Google_Client */ public static function getSimpleClient() { if (!self::isSimpleConfigured()) { return false; } $clientConfig = new \Google_Config(); $clientConfig->setClassConfig("Google_Cache_File", "directory", PIMCORE_CACHE_DIRECTORY); $client = new \Google_Client($clientConfig); $client->setApplicationName("pimcore CMF"); $client->setDeveloperKey(Config::getSystemConfig()->services->google->simpleapikey); return $client; }
public function bootstrap($access_token = false) { global $updraftplus; if (!empty($this->service) && is_object($this->service) && is_a($this->service, 'Google_Service_Drive')) { return $this->service; } $opts = $this->get_opts(); if (empty($access_token)) { if (empty($opts['token']) || empty($opts['clientid']) || empty($opts['secret'])) { $updraftplus->log('Google Drive: this account is not authorised'); $updraftplus->log('Google Drive: ' . __('Account is not authorized.', 'updraftplus'), 'error', 'googledrivenotauthed'); return new WP_Error('not_authorized', __('Account is not authorized.', 'updraftplus')); } } // $included_paths = explode(PATH_SEPARATOR, get_include_path()); // if (!in_array(UPDRAFTPLUS_DIR.'/includes', $included_paths)) { // set_include_path(UPDRAFTPLUS_DIR.'/includes'.PATH_SEPARATOR.get_include_path()); // } $spl = spl_autoload_functions(); if (is_array($spl)) { // Workaround for Google Drive CDN plugin's autoloader if (in_array('wpbgdc_autoloader', $spl)) { spl_autoload_unregister('wpbgdc_autoloader'); } // http://www.wpdownloadmanager.com/download/google-drive-explorer/ - but also others, since this is the default function name used by the Google SDK if (in_array('google_api_php_client_autoload', $spl)) { spl_autoload_unregister('google_api_php_client_autoload'); } } /* if (!class_exists('Google_Config')) require_once 'Google/Config.php'; if (!class_exists('Google_Client')) require_once 'Google/Client.php'; if (!class_exists('Google_Service_Drive')) require_once 'Google/Service/Drive.php'; if (!class_exists('Google_Http_Request')) require_once 'Google/Http/Request.php'; */ if ((!class_exists('Google_Config') || !class_exists('Google_Client') || !class_exists('Google_Service_Drive') || !class_exists('Google_Http_Request')) && !function_exists('google_api_php_client_autoload_updraftplus')) { require_once UPDRAFTPLUS_DIR . '/includes/Google/autoload.php'; } $config = new Google_Config(); $config->setClassConfig('Google_IO_Abstract', 'request_timeout_seconds', 60); # In our testing, $service->about->get() fails if gzip is not disabled when using the stream wrapper if (!function_exists('curl_version') || !function_exists('curl_exec') || defined('UPDRAFTPLUS_GOOGLEDRIVE_DISABLEGZIP') && UPDRAFTPLUS_GOOGLEDRIVE_DISABLEGZIP) { $config->setClassConfig('Google_Http_Request', 'disable_gzip', true); } $client = new Google_Client($config); $client->setClientId($opts['clientid']); $client->setClientSecret($opts['secret']); // $client->setUseObjects(true); if (empty($access_token)) { $access_token = $this->access_token($opts['token'], $opts['clientid'], $opts['secret']); } // Do we have an access token? if (empty($access_token) || is_wp_error($access_token)) { $updraftplus->log('ERROR: Have not yet obtained an access token from Google (has the user authorised?)'); $updraftplus->log(__('Have not yet obtained an access token from Google - you need to authorise or re-authorise your connection to Google Drive.', 'updraftplus'), 'error'); return $access_token; } $client->setAccessToken(json_encode(array('access_token' => $access_token, 'refresh_token' => $opts['token']))); $io = $client->getIo(); $setopts = array(); if (is_a($io, 'Google_IO_Curl')) { $setopts[CURLOPT_SSL_VERIFYPEER] = UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify') ? false : true; if (!UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts')) { $setopts[CURLOPT_CAINFO] = UPDRAFTPLUS_DIR . '/includes/cacert.pem'; } // Raise the timeout from the default of 15 $setopts[CURLOPT_TIMEOUT] = 60; $setopts[CURLOPT_CONNECTTIMEOUT] = 15; if (defined('UPDRAFTPLUS_IPV4_ONLY') && UPDRAFTPLUS_IPV4_ONLY) { $setopts[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; } } elseif (is_a($io, 'Google_IO_Stream')) { $setopts['timeout'] = 60; # We had to modify the SDK to support this # https://wiki.php.net/rfc/tls-peer-verification - before PHP 5.6, there is no default CA file if (!UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts') || version_compare(PHP_VERSION, '5.6.0', '<')) { $setopts['cafile'] = UPDRAFTPLUS_DIR . '/includes/cacert.pem'; } if (UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify')) { $setopts['disable_verify_peer'] = true; } } $io->setOptions($setopts); $service = new Google_Service_Drive($client); $this->client = $client; $this->service = $service; try { # Get the folder name, if not previously known (this is for the legacy situation where an id, not a name, was stored) if (!empty($opts['parentid']) && (!is_array($opts['parentid']) || empty($opts['parentid']['name']))) { $rootid = $this->root_id(); $title = ''; $parentid = is_array($opts['parentid']) ? $opts['parentid']['id'] : $opts['parentid']; while (!empty($parentid) && $parentid != $rootid) { $resource = $service->files->get($parentid); $title = $title ? $resource->getTitle() . '/' . $title : $resource->getTitle(); $parents = $resource->getParents(); if (is_array($parents) && count($parents) > 0) { $parent = array_shift($parents); $parentid = is_a($parent, 'Google_Service_Drive_ParentReference') ? $parent->getId() : false; } else { $parentid = false; } } if (!empty($title)) { $opts['parentid'] = array('id' => is_array($opts['parentid']) ? $opts['parentid']['id'] : $opts['parentid'], 'name' => $title); UpdraftPlus_Options::update_updraft_option('updraft_googledrive', $opts); } } } catch (Exception $e) { $updraftplus->log("Google Drive: failed to obtain name of parent folder: " . $e->getMessage() . ' (line: ' . $e->getLine() . ', file: ' . $e->getFile() . ')'); } return $this->service; }
public function register(Application $app) { $app['gapi.services'] = $app->share(function () use($app) { $path = __DIR__ . '/../Resources/services.json'; $data = file_get_contents($path); return json_decode($data, true); }); $app['gapi.scopes'] = $app->share(function () use($app) { $path = __DIR__ . '/../Resources/scopes.json'; $data = file_get_contents($path); return json_decode($data, true); }); $app['gapi.config'] = $app->share(function () use($app) { $options = $app['gapi.options']; $config = new \Google_Config(); if (isset($options['application_name'])) { $config->setApplicationName($options['application_name']); } if (isset($options['client_id'])) { $config->setClientId($options['client_id']); } if (isset($options['client_secret'])) { $config->setClientSecret($options['client_secret']); } if (isset($options['redirect_uri'])) { $config->setRedirectUri($options['redirect_uri']); } if (isset($options['access_type'])) { $config->setAccessType($options['access_type']); } if (isset($options['approval_prompt'])) { $config->setApprovalPrompt($options['approval_prompt']); } if (isset($options['developer_key'])) { $config->setDeveloperKey($options['developer_key']); } return $config; }); $app['gapi.client'] = $app->share(function () use($app) { $options = $app['gapi.options']; $client = new \Google_Client($app['gapi.config']); foreach (array('scope', 'scopes') as $key) { if (isset($options[$key]) && $options[$key]) { $scopes = $options[$key]; if (!is_array($scopes)) { $scopes = array($scopes); } foreach ($scopes as $scope) { if (isset($app['gapi.scopes'][strtolower($scope)])) { $scope = $app['gapi.scopes'][strtolower($scope)]; } $client->addScope($scope); } } } if (isset($options['refresh_token'])) { $client->refreshToken($options['refresh_token']); } return $client; }); $app['gapi.access_token'] = function () use($app) { $token = json_decode($app['gapi.client']->getAccessToken()); if (is_object($token) && isset($token->access_token)) { return $token->access_token; } else { return null; } }; foreach ($app['gapi.services'] as $service => $classname) { $app['gapi.service.' . $service] = $app->share(function () use($app, $classname) { $class = new \ReflectionClass($classname); return $class->newInstance($app['gapi.client']); }); } }
public function do_bootstrap($opts, $connect) { global $updraftplus; if (!empty($this->service) && is_object($this->service) && is_a($this->service, 'Google_Service_Storage')) { return $this->service; } if (empty($opts)) { $opts = $this->get_opts(); } if (empty($opts['token']) || empty($opts['clientid']) || empty($opts['secret'])) { $updraftplus->log('Google Cloud: this account is not authorised'); $updraftplus->log('Google Cloud: ' . __('Account is not authorized.', 'updraftplus'), 'error', 'googlecloudnotauthed'); return new WP_Error('not_authorized', __('Account is not authorized.', 'updraftplus')); } $access_token = $this->access_token($opts['token'], $opts['clientid'], $opts['secret']); $spl = spl_autoload_functions(); if (is_array($spl)) { // Workaround for Google Cloud CDN plugin's autoloader if (in_array('wpbgdc_autoloader', $spl)) { spl_autoload_unregister('wpbgdc_autoloader'); } // http://www.wpdownloadmanager.com/download/google-drive-explorer/ - but also others, since this is the default function name used by the Google SDK if (in_array('google_api_php_client_autoload', $spl)) { spl_autoload_unregister('google_api_php_client_autoload'); } } if ((!class_exists('Google_Config') || !class_exists('Google_Client') || !class_exists('Google_Service_Storage') || !class_exists('Google_Http_Request')) && !function_exists('google_api_php_client_autoload_updraftplus')) { require_once UPDRAFTPLUS_DIR . '/includes/Google/autoload.php'; } $config = new Google_Config(); $config->setClassConfig('Google_IO_Abstract', 'request_timeout_seconds', 60); # In our testing, $service->about->get() fails if gzip is not disabled when using the stream wrapper if (!function_exists('curl_version') || !function_exists('curl_exec') || defined('UPDRAFTPLUS_GOOGLECLOUD_DISABLEGZIP') && UPDRAFTPLUS_GOOGLECLOUD_DISABLEGZIP) { $config->setClassConfig('Google_Http_Request', 'disable_gzip', true); } $client = new Google_Client($config); $client->setClientId($opts['clientid']); $client->setClientSecret($opts['secret']); $client->setApplicationName("UpdraftPlus WordPress Backups"); $client->setRedirectUri($this->redirect_uri()); $client->setScopes('https://www.googleapis.com/auth/devstorage.full_control'); // Do we have an access token? if (empty($access_token) || is_wp_error($access_token)) { $updraftplus->log('ERROR: Have not yet obtained an access token from Google (has the user authorised?)'); $updraftplus->log(__('Have not yet obtained an access token from Google - you need to authorise or re-authorise your connection to Google Cloud.', 'updraftplus'), 'error'); return $access_token; } $client->setAccessToken(json_encode(array('access_token' => $access_token, 'refresh_token' => $opts['token']))); $io = $client->getIo(); $setopts = array(); $ssl_disableverify = isset($opts['ssl_disableverify']) ? $opts['ssl_disableverify'] : UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'); $ssl_useservercerts = isset($opts['ssl_useservercerts']) ? $opts['ssl_useservercerts'] : UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'); if (is_a($io, 'Google_IO_Curl')) { $setopts[CURLOPT_SSL_VERIFYPEER] = $ssl_disableverify ? false : true; if (!$ssl_useservercerts) { $setopts[CURLOPT_CAINFO] = UPDRAFTPLUS_DIR . '/includes/cacert.pem'; } // Raise the timeout from the default of 15 $setopts[CURLOPT_TIMEOUT] = 60; $setopts[CURLOPT_CONNECTTIMEOUT] = 15; if (defined('UPDRAFTPLUS_IPV4_ONLY') && UPDRAFTPLUS_IPV4_ONLY) { $setopts[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; } } elseif (is_a($io, 'Google_IO_Stream')) { $setopts['timeout'] = 60; # We had to modify the SDK to support this # https://wiki.php.net/rfc/tls-peer-verification - before PHP 5.6, there is no default CA file if (!$ssl_useservercerts || version_compare(PHP_VERSION, '5.6.0', '<')) { $setopts['cafile'] = UPDRAFTPLUS_DIR . '/includes/cacert.pem'; } if ($ssl_disableverify) { $setopts['disable_verify_peer'] = true; } } $io->setOptions($setopts); $service = new Google_Service_Storage($client); $this->client = $client; $this->service = $service; return $this->service; }
/** * __toString * @return string */ public function __toString() { $string = 'var formatter=new '; $string .= $this->provider; $string .= '.'; $string .= $this->scope; $string .= '.'; $string .= $this->type; $string .= '(\'' . (!empty($this->pattern) ? (string) $this->pattern : '') . '\');'; $string .= "\n"; if (empty($this->opt_dstColumnIndex)) { $string .= 'formatter.format(' . $this->dataTable . ', ' . Google_Base::toJson($this->srcColumnIndices) . ');'; } else { $string .= 'formatter.format(' . $this->dataTable . ', ' . Google_Base::toJson($this->srcColumnIndices) . ', ' . Google_Config::toJson($this->opt_dstColumnIndex) . ');'; } $string .= "\n"; return $string; }
} } else { $chartType = 'AreaChart'; $query = 'SELECT A,D WHERE D > 100 ORDER BY D'; } $id = 'viz'; $url = 'http://spreadsheets.google.com/tq?key=pCQbetd-CptGXxxQIG7VFIQ&pub=1'; # new visualization using template default $v = new Google_Visualization("Default"); # register package $p = new Google_Package(array("packages" => array($chartType), "language" => "de_DE")); $v->setPackage($p); // set package object to visualization # setup chart $chart = new Google_Chart($chartType, Google_Base::getElementById($id)); $options = new Google_Config($chartType); $options->setProperty("width", 550); $chart->draw("data", $options); # init functions $f1 = new Google_Function('drawVisualization'); $f2 = new Google_Function('handleQueryResponse', array('response')); # setup query $q = new Google_Data_Query($url); $q->setQuery($query); $q->send($f2->getName()); $f1->add($q); $f1->setCallBack(); $v->setFunction($f1); # setup response $qr = new Google_Data_QueryResponse(); $qr->asVar($chart->getDataTable())->getDataTable();
/** Google authentication */ function googleAuthenticate($code) { $state = getGoogleAuthenticateState(); if ($state === false) { return; } include dirname(__DIR__) . '/config/config.php'; global $CDASH_DB_HOST, $CDASH_DB_LOGIN, $CDASH_DB_PASS, $CDASH_DB_NAME; $SessionCachePolicy = 'private_no_expire'; // initialize the session session_name('CDash'); session_cache_limiter($SessionCachePolicy); session_set_cookie_params($CDASH_COOKIE_EXPIRATION_TIME); @ini_set('session.gc_maxlifetime', $CDASH_COOKIE_EXPIRATION_TIME + 600); session_start(); // check that the anti-forgery token is valid if ($state->csrfToken != $_SESSION['cdash']['csrfToken']) { add_log('state anti-forgery token mismatch: ' . $state->csrfToken . ' vs ' . $_SESSION['cdash']['csrfToken'], 'googleAuthenticate', LOG_ERR); return; } $redirectURI = strtok(get_server_URI(false), '?'); // The return value of get_server_URI can be inconsistent. // It simply returns $CDASH_BASE_URL if that variable is set, yielding a // return value like http://mydomain.com/CDash. // If this variable is not set, then it will return the full URI including // the current script, ie // http://mydomain.com/CDash/googleauth_callback.php. // // Make sure that redirectURI contains the path to our callback script. if (strpos($redirectURI, 'googleauth_callback.php') === false) { $redirectURI .= '/googleauth_callback.php'; } try { $config = new Google_Config(); if ($CDASH_MEMCACHE_ENABLED) { $config->setCacheClass('Google_Cache_Memcache'); list($server, $port) = $CDASH_MEMCACHE_SERVER; $config->setClassConfig('Google_Cache_Memcache', 'host', $server); $config->setClassConfig('Google_Cache_Memcache', 'port', $port); } $client = new Google_Client($config); $client->setClientId($GOOGLE_CLIENT_ID); $client->setClientSecret($GOOGLE_CLIENT_SECRET); $client->setRedirectUri($redirectURI); $client->authenticate($_GET['code']); $oauth = new Google_Service_Oauth2($client); $me = $oauth->userinfo->get(); $tokenResponse = json_decode($client->getAccessToken()); } catch (Google_Auth_Exception $e) { add_log('Google access token request failed: ' . $e->getMessage(), 'googleAuthenticate', LOG_ERR); return; } // Check if this email address appears in our user database $email = strtolower($me->getEmail()); $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}"); pdo_select_db("{$CDASH_DB_NAME}", $db); $sql = 'SELECT id,password FROM ' . qid('user') . " WHERE email='" . pdo_real_escape_string($email) . "'"; $result = pdo_query("{$sql}"); if (pdo_num_rows($result) == 0) { // if no match is found, redirect to pre-filled out registration page pdo_free_result($result); $firstname = $me->getGivenName(); $lastname = $me->getFamilyName(); header("Location: register.php?firstname={$firstname}&lastname={$lastname}&email={$email}"); return false; } $user_array = pdo_fetch_array($result); $pass = $user_array['password']; if ($state->rememberMe) { require_once 'include/login_functions.php'; setRememberMeCookie($user_array['id']); } $sessionArray = array('login' => $email, 'passwd' => $user_array['password'], 'ID' => session_id(), 'valid' => 1, 'loginid' => $user_array['id']); $_SESSION['cdash'] = $sessionArray; session_write_close(); pdo_free_result($result); header("Location: {$state->requestedURI}"); return true; // authentication succeeded }
public function testIniConfig() { $config = new Google_Config(__DIR__ . "/testdata/test.ini"); $this->assertEquals('My Test application', $config->getApplicationName()); $this->assertEquals('gjfiwnGinpena3', $config->getClassConfig('Google_Auth_OAuth2', 'client_secret')); $this->assertInternalType('array', $config->getClassConfig('Google_IO_Abstract')); $this->assertEquals(100, $config->getClassConfig('Google_IO_Abstract', 'request_timeout_seconds')); }
protected function createDefaultAuthHttpClient($http = null) { $options = ['base_url' => $this->config->get('base_path'), 'defaults' => ['exceptions' => true, 'verify' => $http ? $http->getDefaultOption('verify') : true, 'proxy' => $http ? $http->getDefaultOption('proxy') : null]]; return new Client($options); }
<?php include_once 'Google.merge.v_1_0.php'; // main $v = new Google_Visualization("Table_Format"); // config $c = new Google_Config("Table"); $c->setAllowHtml(true); // using dynamic setter $c->setShowRowNumber(true); // format $f = new Google_Format_Pattern(); $f->pattern('<a href="mailto:{1}">{0}</a>'); $f->format("data", array(0, 1)); // data view $d = new Google_Data_View(); $d->setColumns(array(0)); // data $o = Google_Data::getInstance()->getDataObject(); $o->addColumn("0", "Name", "string"); $o->addColumn("1", "Email", "string"); $o->addNewRow(); $o->addStringCellToRow("Tom"); $o->addStringCellToRow("*****@*****.**"); $o->addNewRow(); $o->addStringCellToRow("Mike"); $o->addStringCellToRow("*****@*****.**"); $v->setConfig($c); $v->setData($o); $v->setFormat($f); $v->setDataView($d);
<?php include_once 'Google.merge.v_1_0.php'; // main $v = new Google_Visualization("Table_Format"); // config $c = new Google_Config("Table"); $c->setProperty("allowHtml", true); // format $f = Google_Format::factory("Bar"); $f->min = -10000; $f->max = 10000; $f->drawZeroLine = true; $f->colorNegative = 'red'; $f->showValue = false; $f->width = 250; $f->format("data", 1); $c->setProperty("showRowNumber", true); // data $o = new Google_Data_Base(); $o->addColumn("0", "Country", "string"); $o->addColumn("1", "Sales", "number"); $o->addColumn("2", "Expenses", "number"); $o->addNewRow(); $o->addStringCellToRow("US"); $o->addNumberCellToRow(10000); $o->addNumberCellToRow(8000); $o->addNewRow(); $o->addStringCellToRow("CA"); $o->addNumberCellToRow(-7000); $o->addNumberCellToRow(5000);
<?php include_once '../config.inc.php'; $v = new Google_Visualization("Gauge"); $c = new Google_Config("Gauge"); $o = new Google_Data_Base(); // config $c->defaultConfig("MyTestGauge"); $c->setProperty("min", 0); $c->setProperty("max", 280); $c->setProperty("yellowFrom", 200); $c->setProperty("yellowTo", 250); $c->setProperty("redFrom", 250); $c->setProperty("redTo", 280); $c->setProperty("minorTicks", 5); $v->setConfig($c); // data $o->addColumn("0", "Engine", "number"); $o->addColumn("1", "Torpedo", "number"); $o->addNewRow(); $o->addNumberCellToRow(120, "400.0"); $o->addNumberCellToRow(80, "400.0"); $v->setData($o); ?> <html> <head> <?php echo $v->render(); ?> </head> <body>
<?php include_once 'Google.merge.v_1_0.php'; $c = new Google_Config("AreaChart", "My Title"); $c->setProperty("width", 300); $c->setProperty("height", 200); $v = new Google_Visualization(); $c = new Google_Config("AreaChart"); // data $o = Google_Data::getInstance()->getDataObject(); $o->addColumn("0", "Country", "string"); $o->addColumn("1", "Sales", "number"); $o->addColumn("1", "Expenses", "number"); $o->addNewRow(); $o->addStringCellToRow("US"); $o->addNumberCellToRow(10000, "400.0"); $o->addNumberCellToRow(8000, "400.0"); $o->addNewRow(); $o->addStringCellToRow("CA"); $o->addNumberCellToRow(7000, "400.0"); $o->addNumberCellToRow(5000, "400.0"); $o->addNewRow(); $o->addStringCellToRow("CN"); $o->addNumberCellToRow(8000, "400.0"); $o->addNumberCellToRow(12000, "400.0"); $o->addNewRow(); $o->addStringCellToRow("UK"); $o->addNumberCellToRow(7000, "400.0"); $o->addNumberCellToRow(15000, "400.0"); $v->setConfig($c); $v->setData($o);
/** * @return string the name of the application */ public function getApplicationName() { return $this->config->getApplicationName(); }
<?php include_once 'Google.merge.v_1_0.php'; $v = new Google_Visualization(); $c = new Google_Config("IntensityMap"); // config $c->defaultConfig("MyIntensityMap"); // data $o = Google_Data::getInstance()->getDataObject(); $o->addColumn("0", "Country", "string"); $o->addColumn("1", "Sales", "number"); $o->addColumn("1", "Expenses", "number"); $o->addNewRow(); $o->addStringCellToRow("US"); $o->addNumberCellToRow(10000, "400.0"); $o->addNumberCellToRow(8000, "400.0"); $o->addNewRow(); $o->addStringCellToRow("CA"); $o->addNumberCellToRow(7000, "400.0"); $o->addNumberCellToRow(5000, "400.0"); $o->addNewRow(); $o->addStringCellToRow("CN"); $o->addNumberCellToRow(8000, "400.0"); $o->addNumberCellToRow(12000, "400.0"); $o->addNewRow(); $o->addStringCellToRow("UK"); $o->addNumberCellToRow(7000, "400.0"); $o->addNumberCellToRow(15000, "400.0"); $v->setConfig($c); $v->setData($o); ?>