public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldsToTab('Root.Main', new LiteralField('sf_html_1', '<h4>To get the necessary Twitter API credentials you\'ll need to create a <a href="https://apps.twitter.com" target="_blank">Twitter App.</a></h4>'), 'Label');
     $fields->addFieldsToTab('Root.Main', new LiteralField('sf_html_2', '<p>You can manually grant permissions to the Twitter App, this will give you an Access Token and Access Token Secret.</h5><p>&nbsp;</p>'), 'Label');
     return $fields;
 }
 public function onBeforeInit()
 {
     // Allow easy clearing of the cache in dev mode
     if (Director::isDev() && isset($_GET['socialfeedclearcache']) && $_GET['socialfeedclearcache'] == 1) {
         foreach (SocialFeedProvider::get() as $prov) {
             $prov->clearFeedCache();
         }
     }
 }
 public function onBeforeWrite()
 {
     if ($this->FacebookAppID && $this->FacebookAppSecret) {
         $this->AccessToken = $this->FacebookAppID . '|' . $this->FacebookAppSecret;
     } else {
         if ($this->AccessToken) {
             $this->AccessToken = '';
         }
     }
     parent::onBeforeWrite();
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldsToTab('Root.Main', new LiteralField('sf_html_1', '<h4>To get the necessary Instagram API credentials you\'ll need to create an <a href="https://www.instagram.com/developer/clients/manage/" target="_blank">Instagram Client.</a></h4>'), 'Label');
     $fields->addFieldsToTab('Root.Main', new LiteralField('sf_html_2', '<p>You\'ll need to add the following redirect URI <code>' . $this->getRedirectUri() . '</code> in the settings for the Instagram App.</p>'), 'Label');
     if ($this->ClientID && $this->ClientSecret) {
         $url = $this->authBaseURL . '?client_id=' . $this->ClientID . '&response_type=code&redirect_uri=' . $this->getRedirectUri() . '?provider_id=' . $this->ID;
         $fields->addFieldsToTab('Root.Main', new LiteralField('sf_html_3', '<p><a href="' . $url . '"><button type="button">Authorize App to get Access Token</a></button>'), 'Label');
     }
     return $fields;
 }
 /**
  * Gets the feed for each provider and updates the cache with it.
  */
 public function run($request)
 {
     $providers = SocialFeedProvider::get();
     $providers = $providers->toArray();
     if ($providers) {
         foreach ($providers as $prov) {
             $this->log('Getting feed for #' . $prov->ID . ' (' . $prov->ClassName . ')');
             $feed = $prov->getFeedUncached();
             $prov->setFeedCache($feed);
             $this->log('Updated feed cache for #' . $prov->ID . ' (' . $prov->ClassName . ')');
         }
     } else {
         $this->log('No SocialFeedProvider exist to be updated.');
     }
 }