verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09') || $licensedFeatures->verifyfeature('AhKNjBEVXZlWUFpWE8wVTREQ0FObmo0aTdhVzhvalFic1M='))) { G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels'); G::header('location: ../login/login'); die; } $this->loadSettings(); } public function setScope($scope) { $this->scope[] = $scope; } public function getScope() { return $this->scope; } public function setUser($user) { $this->user = $user; } public function getUser() { return $this->user; } public function setStatusService($status) { $this->configuration->aConfig['statusService'] = $status; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->statusService = $status; } public function getStatusService() { return $this->statusService; } public function getConfigGmail() { $this->configuration = new Configurations(); $this->configuration->loadConfig($gmail, 'GOOGLE_API_SETTINGS', ''); } public function setServiceAccountEmail($serviceAccountEmail) { $this->configuration->aConfig['serviceAccountEmail'] = $serviceAccountEmail; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->serviceAccountEmail = $serviceAccountEmail; } public function getServiceAccountEmail() { return $this->serviceAccountEmail; } public function setServiceAccountCertificate ($serviceAccountCertificate) { $this->configuration->aConfig['serviceAccountCertificate'] = $serviceAccountCertificate; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->serviceAccountCertificate = $serviceAccountCertificate; } public function getServiceAccountCertificate() { return $this->serviceAccountCertificate; } public function setDomain($domain) { $this->configuration->aConfig['domain'] = $domain; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->domain = $domain; } public function getDomain() { return $this->domain; } public function setTypeAuthentication($type) { $this->configuration->aConfig['typeAuthentication'] = $type; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->typeAuthentication = $type; } public function getTypeAuthentication() { return $this->typeAuthentication; } public function setAccountJson($accountJson) { $this->configuration->aConfig['accountJson'] = $accountJson; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->accountJson = $accountJson; } public function getAccountJson() { return $this->accountJson; } public function setServiceGmailStatus($status) { $this->configuration->aConfig['serviceGmailStatus'] = $status; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->serviceGmailStatus = $status; } public function getServiceGmailStatus() { return $this->serviceGmailStatus; } public function setServiceDriveStatus($status) { $this->configuration->aConfig['serviceDriveStatus'] = $status; $this->configuration->saveConfig('GOOGLE_API_SETTINGS', '', '', ''); $this->serviceDriveStatus = $status; } public function getServiceDriveStatus() { return $this->serviceDriveStatus; } /** * load configuration gmail service account * */ public function loadSettings() { $this->getConfigGmail(); $typeAuthentication = empty($this->configuration->aConfig['typeAuthentication']) ? '' : $this->configuration->aConfig['typeAuthentication']; $accountJson = empty($this->configuration->aConfig['accountJson']) ? '' : $this->configuration->aConfig['accountJson']; $serviceAccountCertificate = empty($this->configuration->aConfig['serviceAccountCertificate']) ? '' : $this->configuration->aConfig['serviceAccountCertificate']; $serviceAccountEmail = empty($this->configuration->aConfig['serviceAccountEmail']) ? '' : $this->configuration->aConfig['serviceAccountEmail']; $statusService = empty($this->configuration->aConfig['statusService']) ? '' : $this->configuration->aConfig['statusService']; $serviceGmailStatus = empty($this->configuration->aConfig['serviceGmailStatus']) ? false : $this->configuration->aConfig['serviceGmailStatus']; $serviceDriveStatus = empty($this->configuration->aConfig['serviceDriveStatus']) ? false : $this->configuration->aConfig['serviceDriveStatus']; $this->scope = array(); $this->typeAuthentication = $typeAuthentication; $this->accountJson = $accountJson; $this->serviceAccountEmail = $serviceAccountEmail; $this->serviceAccountCertificate = $serviceAccountCertificate; $this->statusService = $statusService; $this->serviceGmailStatus = $serviceGmailStatus; $this->serviceDriveStatus = $serviceDriveStatus; } /** * New service client - Authentication google Api * * @return Google_Service_Client $service API service instance. */ public function serviceClient() { $client = null; if (file_exists(PATH_DATA_SITE . $this->serviceAccountCertificate)) { $key = file_get_contents(PATH_DATA_SITE . $this->serviceAccountCertificate); } else { throw new Exception(G::LoadTranslation('ID_GOOGLE_CERTIFICATE_ERROR')); } $data = json_decode($key); $assertionCredentials = new Google_Auth_AssertionCredentials( $this->serviceAccountEmail, $this->scope, $data->private_key ); $assertionCredentials->sub = $this->user; $client = new Google_Client(); $client->setApplicationName("PMDrive"); $client->setAssertionCredentials($assertionCredentials); return $client; } /** * New service client - Authentication google Api * * @param $credentials * @throws \Exception * @return \StdClass response. */ public function testService($credentials) { $scope = array( static::DRIVE, static::DRIVE_FILE, static::DRIVE_READONLY, static::DRIVE_METADATA, static::DRIVE_METADATA_READONLY, static::DRIVE_APPDATA, static::DRIVE_PHOTOS_READONLY ); if (file_exists($credentials->pathServiceAccountCertificate)) { $key = file_get_contents($credentials->pathServiceAccountCertificate); } else { throw new Exception(G::LoadTranslation('ID_GOOGLE_CERTIFICATE_ERROR')); } $data = json_decode($key); $assertionCredentials = new Google_Auth_AssertionCredentials( $credentials->emailServiceAccount, $scope, $data->private_key ); $assertionCredentials->sub = $this->user; $client = new Google_Client(); $client->setApplicationName("PMDrive"); $client->setAssertionCredentials($assertionCredentials); $service = new Google_Service_Drive($client); $result = new StdClass(); $result->success = true; $result->currentUserName = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'); $result->rootFolderId = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'); $result->quotaType = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'); $result->quotaBytesTotal = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'); $result->quotaBytesUsed = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'); try { $about = $service->about->get(); $result->currentUserName = $about->getName(); $result->rootFolderId = $about->getRootFolderId(); $result->quotaType = $about->getQuotaType(); $result->quotaBytesTotal = $about->getQuotaBytesTotal(); $result->quotaBytesUsed = $about->getQuotaBytesUsed(); $result->responseGmailTest = G::LoadTranslation('ID_SUCCESSFUL_CONNECTION'); } catch (Exception $e) { $result->success = false; $result->responseGmailTest = G::LoadTranslation('ID_SERVER_COMMUNICATION_ERROR'); } return $result; } }