Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes/Google
File: Config.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* Copyright 2010 Google Inc.
[2] Fix | Delete
*
[3] Fix | Delete
* Licensed under the Apache License, Version 2.0 (the "License");
[4] Fix | Delete
* you may not use this file except in compliance with the License.
[5] Fix | Delete
* You may obtain a copy of the License at
[6] Fix | Delete
*
[7] Fix | Delete
* http://www.apache.org/licenses/LICENSE-2.0
[8] Fix | Delete
*
[9] Fix | Delete
* Unless required by applicable law or agreed to in writing, software
[10] Fix | Delete
* distributed under the License is distributed on an "AS IS" BASIS,
[11] Fix | Delete
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
[12] Fix | Delete
* See the License for the specific language governing permissions and
[13] Fix | Delete
* limitations under the License.
[14] Fix | Delete
*/
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* A class to contain the library configuration for the Google API client.
[18] Fix | Delete
*/
[19] Fix | Delete
class UDP_Google_Config
[20] Fix | Delete
{
[21] Fix | Delete
const GZIP_DISABLED = true;
[22] Fix | Delete
const GZIP_ENABLED = false;
[23] Fix | Delete
const GZIP_UPLOADS_ENABLED = true;
[24] Fix | Delete
const GZIP_UPLOADS_DISABLED = false;
[25] Fix | Delete
const USE_AUTO_IO_SELECTION = "auto";
[26] Fix | Delete
const TASK_RETRY_NEVER = 0;
[27] Fix | Delete
const TASK_RETRY_ONCE = 1;
[28] Fix | Delete
const TASK_RETRY_ALWAYS = -1;
[29] Fix | Delete
protected $configuration;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Create a new UDP_Google_Config. Can accept an ini file location with the
[33] Fix | Delete
* local configuration. For example:
[34] Fix | Delete
* application_name="My App"
[35] Fix | Delete
*
[36] Fix | Delete
* @param [$ini_file_location] - optional - The location of the ini file to load
[37] Fix | Delete
*/
[38] Fix | Delete
public function __construct($ini_file_location = null)
[39] Fix | Delete
{
[40] Fix | Delete
$this->configuration = array(
[41] Fix | Delete
// The application_name is included in the User-Agent HTTP header.
[42] Fix | Delete
'application_name' => '',
[43] Fix | Delete
[44] Fix | Delete
// Which Authentication, Storage and HTTP IO classes to use.
[45] Fix | Delete
'auth_class' => 'Google_Auth_OAuth2',
[46] Fix | Delete
'io_class' => self::USE_AUTO_IO_SELECTION,
[47] Fix | Delete
'cache_class' => 'Google_Cache_File',
[48] Fix | Delete
'logger_class' => 'Google_Logger_Null',
[49] Fix | Delete
[50] Fix | Delete
// Don't change these unless you're working against a special development
[51] Fix | Delete
// or testing environment.
[52] Fix | Delete
'base_path' => 'https://www.googleapis.com',
[53] Fix | Delete
[54] Fix | Delete
// Definition of class specific values, like file paths and so on.
[55] Fix | Delete
'classes' => array(
[56] Fix | Delete
'UDP_Google_IO_Abstract' => array(
[57] Fix | Delete
'request_timeout_seconds' => 100,
[58] Fix | Delete
),
[59] Fix | Delete
'Google_Logger_Abstract' => array(
[60] Fix | Delete
'level' => 'debug',
[61] Fix | Delete
'log_format' => "[%datetime%] %level%: %message% %context%\n",
[62] Fix | Delete
'date_format' => 'd/M/Y:H:i:s O',
[63] Fix | Delete
'allow_newlines' => true
[64] Fix | Delete
),
[65] Fix | Delete
'Google_Logger_File' => array(
[66] Fix | Delete
'file' => 'php://stdout',
[67] Fix | Delete
'mode' => 0640,
[68] Fix | Delete
'lock' => false,
[69] Fix | Delete
),
[70] Fix | Delete
'UDP_Google_Http_Request' => array(
[71] Fix | Delete
// Disable the use of gzip on calls if set to true. Defaults to false.
[72] Fix | Delete
'disable_gzip' => self::GZIP_ENABLED,
[73] Fix | Delete
[74] Fix | Delete
// We default gzip to disabled on uploads even if gzip is otherwise
[75] Fix | Delete
// enabled, due to some issues seen with small packet sizes for uploads.
[76] Fix | Delete
// Please test with this option before enabling gzip for uploads in
[77] Fix | Delete
// a production environment.
[78] Fix | Delete
'enable_gzip_for_uploads' => self::GZIP_UPLOADS_DISABLED,
[79] Fix | Delete
),
[80] Fix | Delete
// If you want to pass in OAuth 2.0 settings, they will need to be
[81] Fix | Delete
// structured like this.
[82] Fix | Delete
'Google_Auth_OAuth2' => array(
[83] Fix | Delete
// Keys for OAuth 2.0 access, see the API console at
[84] Fix | Delete
// https://developers.google.com/console
[85] Fix | Delete
'client_id' => '',
[86] Fix | Delete
'client_secret' => '',
[87] Fix | Delete
'redirect_uri' => '',
[88] Fix | Delete
[89] Fix | Delete
// Simple API access key, also from the API console. Ensure you get
[90] Fix | Delete
// a Server key, and not a Browser key.
[91] Fix | Delete
'developer_key' => '',
[92] Fix | Delete
[93] Fix | Delete
// Other parameters.
[94] Fix | Delete
'hd' => '',
[95] Fix | Delete
'prompt' => '',
[96] Fix | Delete
'openid.realm' => '',
[97] Fix | Delete
'include_granted_scopes' => '',
[98] Fix | Delete
'login_hint' => '',
[99] Fix | Delete
'request_visible_actions' => '',
[100] Fix | Delete
'access_type' => 'online',
[101] Fix | Delete
'approval_prompt' => 'auto',
[102] Fix | Delete
'federated_signon_certs_url' =>
[103] Fix | Delete
'https://www.googleapis.com/oauth2/v1/certs',
[104] Fix | Delete
),
[105] Fix | Delete
'Google_Task_Runner' => array(
[106] Fix | Delete
// Delays are specified in seconds
[107] Fix | Delete
'initial_delay' => 1,
[108] Fix | Delete
'max_delay' => 60,
[109] Fix | Delete
// Base number for exponential backoff
[110] Fix | Delete
'factor' => 2,
[111] Fix | Delete
// A random number between -jitter and jitter will be added to the
[112] Fix | Delete
// factor on each iteration to allow for better distribution of
[113] Fix | Delete
// retries.
[114] Fix | Delete
'jitter' => .5,
[115] Fix | Delete
// Maximum number of retries allowed
[116] Fix | Delete
'retries' => 0
[117] Fix | Delete
),
[118] Fix | Delete
'UDP_Google_Service_Exception' => array(
[119] Fix | Delete
'retry_map' => array(
[120] Fix | Delete
'500' => self::TASK_RETRY_ALWAYS,
[121] Fix | Delete
'503' => self::TASK_RETRY_ALWAYS,
[122] Fix | Delete
'rateLimitExceeded' => self::TASK_RETRY_ALWAYS,
[123] Fix | Delete
'userRateLimitExceeded' => self::TASK_RETRY_ALWAYS
[124] Fix | Delete
)
[125] Fix | Delete
),
[126] Fix | Delete
'UDP_Google_IO_Exception' => array(
[127] Fix | Delete
'retry_map' => !extension_loaded('curl') ? array() : array(
[128] Fix | Delete
CURLE_COULDNT_RESOLVE_HOST => self::TASK_RETRY_ALWAYS,
[129] Fix | Delete
CURLE_COULDNT_CONNECT => self::TASK_RETRY_ALWAYS,
[130] Fix | Delete
CURLE_OPERATION_TIMEOUTED => self::TASK_RETRY_ALWAYS,
[131] Fix | Delete
CURLE_SSL_CONNECT_ERROR => self::TASK_RETRY_ALWAYS,
[132] Fix | Delete
CURLE_GOT_NOTHING => self::TASK_RETRY_ALWAYS
[133] Fix | Delete
)
[134] Fix | Delete
),
[135] Fix | Delete
// Set a default directory for the file cache.
[136] Fix | Delete
'Google_Cache_File' => array(
[137] Fix | Delete
'directory' => sys_get_temp_dir() . '/UDP_Google_Client'
[138] Fix | Delete
)
[139] Fix | Delete
),
[140] Fix | Delete
);
[141] Fix | Delete
[142] Fix | Delete
if ($ini_file_location) {
[143] Fix | Delete
$ini = parse_ini_file($ini_file_location, true);
[144] Fix | Delete
if (is_array($ini) && count($ini)) {
[145] Fix | Delete
$merged_configuration = $ini + $this->configuration;
[146] Fix | Delete
if (isset($ini['classes']) && isset($this->configuration['classes'])) {
[147] Fix | Delete
$merged_configuration['classes'] = $ini['classes'] + $this->configuration['classes'];
[148] Fix | Delete
}
[149] Fix | Delete
$this->configuration = $merged_configuration;
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Set configuration specific to a given class.
[156] Fix | Delete
* $config->setClassConfig('Google_Cache_File',
[157] Fix | Delete
* array('directory' => '/tmp/cache'));
[158] Fix | Delete
* @param $class string The class name for the configuration
[159] Fix | Delete
* @param $config string key or an array of configuration values
[160] Fix | Delete
* @param $value string optional - if $config is a key, the value
[161] Fix | Delete
*/
[162] Fix | Delete
public function setClassConfig($class, $config, $value = null)
[163] Fix | Delete
{
[164] Fix | Delete
if (!is_array($config)) {
[165] Fix | Delete
if (!isset($this->configuration['classes'][$class])) {
[166] Fix | Delete
$this->configuration['classes'][$class] = array();
[167] Fix | Delete
}
[168] Fix | Delete
$this->configuration['classes'][$class][$config] = $value;
[169] Fix | Delete
} else {
[170] Fix | Delete
$this->configuration['classes'][$class] = $config;
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
public function getClassConfig($class, $key = null)
[175] Fix | Delete
{
[176] Fix | Delete
if (!isset($this->configuration['classes'][$class])) {
[177] Fix | Delete
return null;
[178] Fix | Delete
}
[179] Fix | Delete
if ($key === null) {
[180] Fix | Delete
return $this->configuration['classes'][$class];
[181] Fix | Delete
} else {
[182] Fix | Delete
return $this->configuration['classes'][$class][$key];
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Return the configured cache class.
[188] Fix | Delete
* @return string
[189] Fix | Delete
*/
[190] Fix | Delete
public function getCacheClass()
[191] Fix | Delete
{
[192] Fix | Delete
return $this->configuration['cache_class'];
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Return the configured logger class.
[197] Fix | Delete
* @return string
[198] Fix | Delete
*/
[199] Fix | Delete
public function getLoggerClass()
[200] Fix | Delete
{
[201] Fix | Delete
return $this->configuration['logger_class'];
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Return the configured Auth class.
[206] Fix | Delete
* @return string
[207] Fix | Delete
*/
[208] Fix | Delete
public function getAuthClass()
[209] Fix | Delete
{
[210] Fix | Delete
return $this->configuration['auth_class'];
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Set the auth class.
[215] Fix | Delete
*
[216] Fix | Delete
* @param $class string the class name to set
[217] Fix | Delete
*/
[218] Fix | Delete
public function setAuthClass($class)
[219] Fix | Delete
{
[220] Fix | Delete
$prev = $this->configuration['auth_class'];
[221] Fix | Delete
if (!isset($this->configuration['classes'][$class]) &&
[222] Fix | Delete
isset($this->configuration['classes'][$prev])) {
[223] Fix | Delete
$this->configuration['classes'][$class] =
[224] Fix | Delete
$this->configuration['classes'][$prev];
[225] Fix | Delete
}
[226] Fix | Delete
$this->configuration['auth_class'] = $class;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Set the IO class.
[231] Fix | Delete
*
[232] Fix | Delete
* @param $class string the class name to set
[233] Fix | Delete
*/
[234] Fix | Delete
public function setIoClass($class)
[235] Fix | Delete
{
[236] Fix | Delete
$prev = $this->configuration['io_class'];
[237] Fix | Delete
if (!isset($this->configuration['classes'][$class]) &&
[238] Fix | Delete
isset($this->configuration['classes'][$prev])) {
[239] Fix | Delete
$this->configuration['classes'][$class] =
[240] Fix | Delete
$this->configuration['classes'][$prev];
[241] Fix | Delete
}
[242] Fix | Delete
$this->configuration['io_class'] = $class;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
/**
[246] Fix | Delete
* Set the cache class.
[247] Fix | Delete
*
[248] Fix | Delete
* @param $class string the class name to set
[249] Fix | Delete
*/
[250] Fix | Delete
public function setCacheClass($class)
[251] Fix | Delete
{
[252] Fix | Delete
$prev = $this->configuration['cache_class'];
[253] Fix | Delete
if (!isset($this->configuration['classes'][$class]) &&
[254] Fix | Delete
isset($this->configuration['classes'][$prev])) {
[255] Fix | Delete
$this->configuration['classes'][$class] =
[256] Fix | Delete
$this->configuration['classes'][$prev];
[257] Fix | Delete
}
[258] Fix | Delete
$this->configuration['cache_class'] = $class;
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* Set the logger class.
[263] Fix | Delete
*
[264] Fix | Delete
* @param $class string the class name to set
[265] Fix | Delete
*/
[266] Fix | Delete
public function setLoggerClass($class)
[267] Fix | Delete
{
[268] Fix | Delete
$prev = $this->configuration['logger_class'];
[269] Fix | Delete
if (!isset($this->configuration['classes'][$class]) &&
[270] Fix | Delete
isset($this->configuration['classes'][$prev])) {
[271] Fix | Delete
$this->configuration['classes'][$class] =
[272] Fix | Delete
$this->configuration['classes'][$prev];
[273] Fix | Delete
}
[274] Fix | Delete
$this->configuration['logger_class'] = $class;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
/**
[278] Fix | Delete
* Return the configured IO class.
[279] Fix | Delete
*
[280] Fix | Delete
* @return string
[281] Fix | Delete
*/
[282] Fix | Delete
public function getIoClass()
[283] Fix | Delete
{
[284] Fix | Delete
return $this->configuration['io_class'];
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Set the application name, this is included in the User-Agent HTTP header.
[289] Fix | Delete
* @param string $name
[290] Fix | Delete
*/
[291] Fix | Delete
public function setApplicationName($name)
[292] Fix | Delete
{
[293] Fix | Delete
$this->configuration['application_name'] = $name;
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* @return string the name of the application
[298] Fix | Delete
*/
[299] Fix | Delete
public function getApplicationName()
[300] Fix | Delete
{
[301] Fix | Delete
return $this->configuration['application_name'];
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
* Set the client ID for the auth class.
[306] Fix | Delete
* @param $clientId string - the API console client ID
[307] Fix | Delete
*/
[308] Fix | Delete
public function setClientId($clientId)
[309] Fix | Delete
{
[310] Fix | Delete
$this->setAuthConfig('client_id', $clientId);
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
/**
[314] Fix | Delete
* Set the client secret for the auth class.
[315] Fix | Delete
* @param $secret string - the API console client secret
[316] Fix | Delete
*/
[317] Fix | Delete
public function setClientSecret($secret)
[318] Fix | Delete
{
[319] Fix | Delete
$this->setAuthConfig('client_secret', $secret);
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
/**
[323] Fix | Delete
* Set the redirect uri for the auth class. Note that if using the
[324] Fix | Delete
* Javascript based sign in flow, this should be the string 'postmessage'.
[325] Fix | Delete
*
[326] Fix | Delete
* @param $uri string - the URI that users should be redirected to
[327] Fix | Delete
*/
[328] Fix | Delete
public function setRedirectUri($uri)
[329] Fix | Delete
{
[330] Fix | Delete
$this->setAuthConfig('redirect_uri', $uri);
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
/**
[334] Fix | Delete
* Set the app activities for the auth class.
[335] Fix | Delete
* @param $rva string a space separated list of app activity types
[336] Fix | Delete
*/
[337] Fix | Delete
public function setRequestVisibleActions($rva)
[338] Fix | Delete
{
[339] Fix | Delete
$this->setAuthConfig('request_visible_actions', $rva);
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
/**
[343] Fix | Delete
* Set the the access type requested (offline or online.)
[344] Fix | Delete
* @param $access string - the access type
[345] Fix | Delete
*/
[346] Fix | Delete
public function setAccessType($access)
[347] Fix | Delete
{
[348] Fix | Delete
$this->setAuthConfig('access_type', $access);
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
/**
[352] Fix | Delete
* Set when to show the approval prompt (auto or force)
[353] Fix | Delete
* @param $approval string - the approval request
[354] Fix | Delete
*/
[355] Fix | Delete
public function setApprovalPrompt($approval)
[356] Fix | Delete
{
[357] Fix | Delete
$this->setAuthConfig('approval_prompt', $approval);
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
/**
[361] Fix | Delete
* Set the login hint (email address or sub identifier)
[362] Fix | Delete
* @param $hint string
[363] Fix | Delete
*/
[364] Fix | Delete
public function setLoginHint($hint)
[365] Fix | Delete
{
[366] Fix | Delete
$this->setAuthConfig('login_hint', $hint);
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
/**
[370] Fix | Delete
* Set the developer key for the auth class. Note that this is separate value
[371] Fix | Delete
* from the client ID - if it looks like a URL, its a client ID!
[372] Fix | Delete
* @param $key string - the API console developer key
[373] Fix | Delete
*/
[374] Fix | Delete
public function setDeveloperKey($key)
[375] Fix | Delete
{
[376] Fix | Delete
$this->setAuthConfig('developer_key', $key);
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
/**
[380] Fix | Delete
* Set the hd (hosted domain) parameter streamlines the login process for
[381] Fix | Delete
* Google Apps hosted accounts. By including the domain of the user, you
[382] Fix | Delete
* restrict sign-in to accounts at that domain.
[383] Fix | Delete
*
[384] Fix | Delete
* This should not be used to ensure security on your application - check
[385] Fix | Delete
* the hd values within an id token (@see Google_Auth_LoginTicket) after sign
[386] Fix | Delete
* in to ensure that the user is from the domain you were expecting.
[387] Fix | Delete
*
[388] Fix | Delete
* @param $hd string - the domain to use.
[389] Fix | Delete
*/
[390] Fix | Delete
public function setHostedDomain($hd)
[391] Fix | Delete
{
[392] Fix | Delete
$this->setAuthConfig('hd', $hd);
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
/**
[396] Fix | Delete
* Set the prompt hint. Valid values are none, consent and select_account.
[397] Fix | Delete
* If no value is specified and the user has not previously authorized
[398] Fix | Delete
* access, then the user is shown a consent screen.
[399] Fix | Delete
* @param $prompt string
[400] Fix | Delete
*/
[401] Fix | Delete
public function setPrompt($prompt)
[402] Fix | Delete
{
[403] Fix | Delete
$this->setAuthConfig('prompt', $prompt);
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
/**
[407] Fix | Delete
* openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth
[408] Fix | Delete
* 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which
[409] Fix | Delete
* an authentication request is valid.
[410] Fix | Delete
* @param $realm string - the URL-space to use.
[411] Fix | Delete
*/
[412] Fix | Delete
public function setOpenidRealm($realm)
[413] Fix | Delete
{
[414] Fix | Delete
$this->setAuthConfig('openid.realm', $realm);
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
/**
[418] Fix | Delete
* If this is provided with the value true, and the authorization request is
[419] Fix | Delete
* granted, the authorization will include any previous authorizations
[420] Fix | Delete
* granted to this user/application combination for other scopes.
[421] Fix | Delete
* @param $include boolean - the URL-space to use.
[422] Fix | Delete
*/
[423] Fix | Delete
public function setIncludeGrantedScopes($include)
[424] Fix | Delete
{
[425] Fix | Delete
$this->setAuthConfig(
[426] Fix | Delete
'include_granted_scopes',
[427] Fix | Delete
$include ? "true" : "false"
[428] Fix | Delete
);
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
/**
[432] Fix | Delete
* @return string the base URL to use for API calls
[433] Fix | Delete
*/
[434] Fix | Delete
public function getBasePath()
[435] Fix | Delete
{
[436] Fix | Delete
return $this->configuration['base_path'];
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* Set the auth configuration for the current auth class.
[441] Fix | Delete
* @param $key - the key to set
[442] Fix | Delete
* @param $value - the parameter value
[443] Fix | Delete
*/
[444] Fix | Delete
private function setAuthConfig($key, $value)
[445] Fix | Delete
{
[446] Fix | Delete
if (!isset($this->configuration['classes'][$this->getAuthClass()])) {
[447] Fix | Delete
$this->configuration['classes'][$this->getAuthClass()] = array();
[448] Fix | Delete
}
[449] Fix | Delete
$this->configuration['classes'][$this->getAuthClass()][$key] = $value;
[450] Fix | Delete
}
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function