コード例 #1
0
 public function getSendDate()
 {
     $timezone = \Craft\craft()->getTimezone();
     $now = Carbon::now($timezone);
     if (!empty($this->settings->sendDateSpecific)) {
         $now = Carbon::parse($this->settings->sendDateSpecific, $timezone);
     }
     if (!empty($this->settings->sendDateRelative)) {
         $now->modify($this->settings->sendDateRelative);
     }
     return $now;
 }
コード例 #2
0
 /**
  * @return string
  * @throws \Exception
  */
 private function getPluginRoot()
 {
     return \Craft\craft()->path->getPluginsPath();
 }
コード例 #3
0
 public function initializeService($scopes = array())
 {
     $this->getStorage();
     // try {
     $handle = $this->getHandle();
     $serviceFactory = new \OAuth\ServiceFactory();
     $callbackUrl = \Craft\craft()->oauth->callbackUrl($handle);
     $credentials = new Credentials($this->clientId, $this->clientSecret, $callbackUrl);
     if (!$scopes) {
         $scopes = array();
     }
     $this->service = $serviceFactory->createService($handle, $credentials, $this->storage, $scopes);
     // }
     // catch(\Exception $e)
     // {
     // }
 }
コード例 #4
0
 public function __construct($attributes = null)
 {
     parent::__construct($attributes);
     $this->now = Carbon::now(new \DateTimeZone(\Craft\craft()->getTimezone()));
 }
コード例 #5
0
 public function tokenRefresh()
 {
     $difference = $this->_providerSource->token->expires - time();
     // token expired : we need to refresh it
     if ($difference < 1) {
         Craft::log(__METHOD__ . " : Refresh token ", LogLevel::Info, true);
         $encodedToken = base64_encode(serialize($this->_providerSource->token));
         $token = \Craft\craft()->oauth->getTokenEncoded($encodedToken);
         if (method_exists($this->_providerSource, 'access') && $this->_providerSource->token->refresh_token) {
             $accessToken = $this->_providerSource->access($this->_providerSource->token->refresh_token, array('grant_type' => 'refresh_token'));
             if (!$accessToken) {
                 Craft::log(__METHOD__ . " : Could not refresh token", LogLevel::Info, true);
             }
             // save token
             $this->_providerSource->token->access_token = $accessToken->access_token;
             $this->_providerSource->token->expires = $accessToken->expires;
             $token->token = base64_encode(serialize($this->_providerSource->token));
             if (\Craft\craft()->oauth->tokenSave($token)) {
                 Craft::log(__METHOD__ . " : Token saved", LogLevel::Info, true);
             }
         } else {
             Craft::log(__METHOD__ . " : Access method (for refresh) doesn't exists for this provider", LogLevel::Info, true);
         }
     }
 }