public function __construct()
 {
     if (!$this->prepared) {
         if (!defined('YOUTUBE_API_KEY')) {
             define('YOUTUBE_API_KEY', SiteConfig::current_site_config()->YoutubeApiKey);
         }
         if (YOUTUBE_API_KEY == '') {
             user_error('Please specify a valid Youtube Api Key in the site config.', E_USER_ERROR);
         }
         // Create the service
         $this->service = RestfulService::create('https://www.googleapis.com/youtube/v3/');
         $this->prepared = true;
     }
 }
 public function getLicenceText()
 {
     $licence = $this->owner->Licence()->URI;
     if (!$licence) {
         $licence = SiteConfig::current_site_config()->Licence()->URI;
     }
     $licence_url = $this->owner->config()->get('api_url') . $this->owner->config()->get('api_version') . '/details?license-uri=' . $licence;
     $expiry = 7 * (24 * 60 * 60);
     $request = RestfulService::create($licence_url, $expiry)->request()->getBody();
     $pattern = "/<html ?.*>(.*)<\\/html>/";
     preg_match($pattern, $request, $matches);
     if ($matches) {
         return $matches[0];
     }
 }
 /**
  * Set up the factory if not already happened
  * Creates the RestfulService, gets the needed information from the SiteConfig
  * and fetches the users id from the given username (if not already stored in the config)
  */
 public function __construct()
 {
     if (!$this->prepared) {
         // Create the service
         $this->service = RestfulService::create('https://api.instagram.com/v1/');
         $this->prepared = true;
         // Get the current SiteConfig
         $conf = SiteConfig::current_site_config();
         if (!$conf->InstagramUserName || !$conf->InstagramClientID) {
             user_error('Please specify instagram username and client id in the cms settings tab.', E_USER_ERROR);
         }
         $this->clientID = $conf->InstagramClientID;
         $this->userName = $conf->InstagramUserName;
         // Get the user id and store it in the site conf if not already there
         if (!$conf->InstagramUserID) {
             $conf->InstagramUserID = $this->getUserIdByUserName($this->userName);
             $conf->write();
         }
         $this->userID = $conf->InstagramUserID;
     }
 }