Google Drive (second look)

This commit is contained in:
RainLoop Team 2014-07-29 14:28:02 +04:00
parent eea55d4e0a
commit 7107104e1a
18 changed files with 507 additions and 233 deletions

View file

@ -449,8 +449,8 @@ class Http
$sNewUrl = $sUrl;
$oCurl = \curl_init($sUrl);
\curl_setopt_array($oCurl, array(
$aAddOptions = array(
CURLOPT_URL => $sUrl,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
@ -460,7 +460,14 @@ class Http
CURLOPT_FORBID_REUSE => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5
));
);
if (isset($aOptions[CURLOPT_HTTPHEADER]) && \is_array($aOptions[CURLOPT_HTTPHEADER]) && 0 < \count($aOptions[CURLOPT_HTTPHEADER]))
{
$aAddOptions[CURLOPT_HTTPHEADER] = $aOptions[CURLOPT_HTTPHEADER];
}
\curl_setopt_array($oCurl, $aAddOptions);
do
{
@ -514,11 +521,12 @@ class Http
* @param int $iTimeout = 10
* @param string $sProxy = ''
* @param string $sProxyAuth = ''
* @param string $sAuthorization = ''
*
* @return bool
*/
public function SaveUrlToFile($sUrl, $rFile, $sCustomUserAgent = 'MailSo Http User Agent (v1)', &$sContentType = '', &$iCode = 0,
$oLogger = null, $iTimeout = 10, $sProxy = '', $sProxyAuth = '')
$oLogger = null, $iTimeout = 10, $sProxy = '', $sProxyAuth = '', $sAuthorization = '')
{
if (!is_resource($rFile))
{
@ -530,6 +538,8 @@ class Http
return false;
}
$aHeaders = array();
$aOptions = array(
CURLOPT_URL => $sUrl,
CURLOPT_HEADER => false,
@ -547,6 +557,11 @@ class Http
$aOptions[CURLOPT_USERAGENT] = $sCustomUserAgent;
}
if (0 < \strlen($sAuthorization))
{
$aHeaders[] = 'Authorization '.$sAuthorization;
}
if (0 < \strlen($sProxy))
{
$aOptions[CURLOPT_PROXY] = $sProxy;
@ -556,6 +571,11 @@ class Http
}
}
if (0 < \count($aHeaders))
{
$aOptions[CURLOPT_HTTPHEADER] = $aHeaders;
}
if ($oLogger)
{
$oLogger->Write('cUrl: URL: '.$sUrl);

View file

@ -1130,13 +1130,11 @@ class Actions
$aResult['AllowGoogleSocial'] = (bool) $oConfig->Get('social', 'google_enable', false);
$aResult['GoogleClientID'] = \trim($oConfig->Get('social', 'google_client_id', ''));
$aResult['GoogleApiKey'] = \trim($oConfig->Get('social', 'google_api_key', ''));
if ($aResult['AllowGoogleSocial'] && (
'' === \trim($oConfig->Get('social', 'google_client_id', '')) || '' === \trim($oConfig->Get('social', 'google_client_secret', ''))))
{
$aResult['AllowGoogleSocial'] = false;
$aResult['GoogleClientID'] = '';
$aResult['GoogleApiKey'] = '';
}
$aResult['AllowFacebookSocial'] = (bool) $oConfig->Get('social', 'fb_enable', false);
@ -1193,7 +1191,6 @@ class Actions
$aResult['AllowGoogleSocial'] = (bool) $oConfig->Get('social', 'google_enable', false);
$aResult['GoogleClientID'] = (string) $oConfig->Get('social', 'google_client_id', '');
$aResult['GoogleClientSecret'] = (string) $oConfig->Get('social', 'google_client_secret', '');
$aResult['GoogleApiKey'] = (string) $oConfig->Get('social', 'google_api_key', '');
$aResult['AllowFacebookSocial'] = (bool) $oConfig->Get('social', 'fb_enable', false);
$aResult['FacebookAppID'] = (string) $oConfig->Get('social', 'fb_app_id', '');
@ -2399,7 +2396,6 @@ class Actions
$this->setConfigFromParams($oConfig, 'GoogleEnable', 'social', 'google_enable', 'bool');
$this->setConfigFromParams($oConfig, 'GoogleClientID', 'social', 'google_client_id', 'string');
$this->setConfigFromParams($oConfig, 'GoogleClientSecret', 'social', 'google_client_secret', 'string');
$this->setConfigFromParams($oConfig, 'GoogleApiKey', 'social', 'google_api_key', 'string');
$this->setConfigFromParams($oConfig, 'FacebookEnable', 'social', 'fb_enable', 'bool');
$this->setConfigFromParams($oConfig, 'FacebookAppID', 'social', 'fb_app_id', 'string');
@ -5827,6 +5823,45 @@ class Actions
return $this->DefaultResponse(__FUNCTION__, $mResult);
}
/**
* @return array
*/
public function DoComposeUploadDrive()
{
$oAccount = $this->getAccountFromToken();
$mResult = false;
$sUrl = $this->GetActionParam('Url', '');
$sAccessToken = $this->GetActionParam('AccessToken', '');
if (0 < \strlen($sUrl) && 0 < \strlen($sAccessToken))
{
$oHttp = \MailSo\Base\Http::SingletonInstance();
$mResult[$sUrl] = '';
$sTempName = \md5($sUrl);
$iCode = 0;
$sContentType = '';
$rFile = $this->FilesProvider()->GetFile($oAccount, $sTempName, 'wb+');
if ($rFile && $oHttp->SaveUrlToFile($sUrl, $rFile, '', $sContentType, $iCode, $this->Logger(), 60,
$this->Config()->Get('labs', 'curl_proxy', ''), $this->Config()->Get('labs', 'curl_proxy_auth', ''),
'Authorization: Bearer '.$sAccessToken))
{
$mResult[$sUrl] = $sTempName;
}
if (\is_resource($rFile))
{
@\fclose($rFile);
}
}
return $this->DefaultResponse(__FUNCTION__, $mResult);
}
/**
* @return array

View file

@ -37,16 +37,6 @@
<div data-bind="saveTrigger: googleTrigger2"></div>
</div>
</div>
<div class="control-group">
<label class="control-label">
Client Api Key
</label>
<div class="controls">
<input type="text" class="span5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: googleApiKey, saveTrigger: googleTrigger3" />
<div data-bind="saveTrigger: googleTrigger3"></div>
</div>
</div>
<div class="legend">
Facebook
<span style="color: #ccc; font-size: 14px;" data-bind="visible: !facebookSupported()">(requires PHP 5.4 or greater)</span>