Beispiel #1
0
 public function getProviderSources()
 {
     $providerSources = array();
     $providersPath = CRAFT_PLUGINS_PATH . 'oauth/providers/';
     $providersFolderContents = IOHelper::getFolderContents($providersPath, false);
     if ($providersFolderContents) {
         foreach ($providersFolderContents as $path) {
             $path = IOHelper::normalizePathSeparators($path);
             $fileName = IOHelper::getFileName($path, false);
             if ($fileName == 'BaseOAuthProviderSource') {
                 continue;
             }
             // Chop off the "OAuthProviderSource" suffix
             $handle = substr($fileName, 0, strlen($fileName) - 19);
             $providerSources[] = $this->getProviderSource($handle);
         }
     }
     return $providerSources;
 }
 /**
  * Loads the configured providers.
  */
 private function _loadProviders()
 {
     Craft::log(__METHOD__, LogLevel::Info, true);
     if ($this->_providersLoaded) {
         return;
     }
     // providerSources
     $providerSources = array();
     $providersPath = CRAFT_PLUGINS_PATH . 'oauth/providers/';
     $providersFolderContents = IOHelper::getFolderContents($providersPath, false);
     if ($providersFolderContents) {
         foreach ($providersFolderContents as $path) {
             $path = IOHelper::normalizePathSeparators($path);
             $fileName = IOHelper::getFileName($path, false);
             if ($fileName == 'BaseOAuthProviderSource') {
                 continue;
             }
             // Chop off the "OAuthProviderSource" suffix
             $handle = substr($fileName, 0, strlen($fileName) - 19);
             $providerSource = $this->getProviderSource($handle);
             array_push($providerSources, $providerSource);
         }
     }
     // providers
     foreach ($providerSources as $providerSource) {
         $lcHandle = strtolower($providerSource->getHandle());
         $record = $this->_getProviderRecordByHandle($providerSource->getHandle());
         $provider = Oauth_ProviderModel::populateModel($record);
         $provider->class = $providerSource->getHandle();
         if ($record && !empty($provider->clientId)) {
             $providerSource->setClient($provider->clientId, $provider->clientSecret);
             $provider->providerSource = $providerSource;
             $this->_configuredProviders[$lcHandle] = $provider;
         } else {
             $provider->providerSource = $providerSource;
         }
         $this->_allProviders[$lcHandle] = $provider;
     }
     $this->_providersLoaded = true;
 }