/** * Get items for the field. * * @param string $fragment Optional. Search fragment. * @return array {value} => {text for display} */ public function get_items($fragment = null) { $items = Datasource_RSS_Settings()->get_feed_items(); if (empty($items)) { return $items; } foreach ($items as $item) { $value = json_encode($item); if ($fragment && false === stripos($value, $fragment)) { continue; } $ret[$value] = sprintf(_x('%s (%s)', 'rss item title and source', 'fm-datasource-rss'), $item['title'], $item['source']); } return $ret; }
* @param array $b * @return int */ public function sort_items_by_date($a, $b) { if ($a['date'] == $b['date']) { return 0; } return $a['date'] > $b['date'] ? -1 : 1; } /** * Modify the default cache duration time for our feeds. * * @param int $duration Number of seconds to cache. * @param string $url Feed URL. * @return int Filtered cache duration. */ public function cache_duration($duration, $url) { if (in_array($url, $this->get_urls())) { return $this->rss_cache_duration; } return $duration; } } function Datasource_RSS_Settings() { return Datasource_RSS_Settings::instance(); } Datasource_RSS_Settings();