Source of file InstagramFeedPage.php
Size: 1,606 Bytes - Last Modified: 2021-12-23T10:01:56+00:00
/var/www/docs.ssmods.com/process/src/code/InstagramFeedPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | <?php class InstagramFeedPage extends Page { private static $singular_name = 'Instagram Feed'; private static $description = 'Basic page for an instagram feed.'; private static $db = array( 'PostsLimit' => 'Int' ); public function getCMSFields(){ $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Main', NumericField::create('PostsLimit', _t('InstagramFeed.POSTS_LIMIT', 'Post Limit'))); return $fields; } public function getPosts(){ // Get a instance of the factory $f = Injector::inst()->get('InstagramFactory'); // Set the limit - take it from the backend if set, otherwise take 5 as default $limit = ($this->PostsLimit) ? $this->PostsLimit : 5; // Get the posts return $f->getUsersRecentMedia($limit); } // Get the caption without the hashtags and optional limited by $limit letters public function stripCaption($caption, $limit = null){ // Remove the hash tags $caption = substr($caption, 0, strpos($caption, '#')); // Create a HTMLText $sf = HTMLText::create('Caption'); $sf->setValue($caption); // Optional: limit the characters if ($limit != null) return $sf->LimitCharacters($limit, '...'); return $sf; } // Get the date from given timestamp, formatted with strftime public function getDate($timestamp, $format = "%Y/%m/%d, %H:%M") { return strftime($format, $timestamp); } } class InstagramFeedPage_Controller extends Page_Controller {} |