/** * Down **/ public function down() { if ($this->db->tableExists('#__feedaggregator_posts')) { require_once PATH_CORE . DS . 'components' . DS . 'com_feedaggregator' . DS . 'models' . DS . 'post.php'; // Grab rows first $rows = Post::all()->rows(); // Convert the field $query = "ALTER TABLE `#__feedaggregator_posts` MODIFY created INT(11);"; $this->db->setQuery($query); $this->db->query(); // Convert each timestamp into SQL date format foreach ($rows as $row) { $row->set('created', Date::of($row->created)->toUnix()); $row->save(); } } }
/** * Get approved Posts from the Aggregated Feed * * @return mixed */ public function getPosts() { // Get the approved posts $posts = Post::all()->where('status', '=', '2')->rows(); return $posts; }
/** * Generates RSS feed when called by URL * * @return void */ public function generateFeedTask() { // Get the approved posts $posts = Post::all()->whereEquals('status', 2)->ordered()->limit(1000)->rows(); // Set the mime encoding for the document Document::setType('feed'); // Start a new feed object $doc = Document::instance(); $doc->title = Config::get('sitename') . ' ' . Lang::txt('COM_FEEDAGGREGATOR_AGGREGATED_FEED'); $doc->description = Lang::txt(Config::get('sitename') . ' ' . Lang::txt('COM_FEEDAGGREGATOR_AGGREGATED_FEED_SELECTED_READING')); $doc->copyright = Lang::txt(date("Y"), Config::get('sitename')); $doc->category = Lang::txt('COM_FEEDAGGREGATOR_EXTERNAL_CONTENT'); // Start outputing results if any found if (count($posts) > 0) { foreach ($posts as $post) { // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); // sanitize ouput $item->title = preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', $post->title); $item->title = preg_replace("/&#?[a-z1-9]{2,8};/i", "", $post->title); $item->title = (string) strip_tags($item->title); $item->title = html_entity_decode($item->title); $item->title = Sanitize::clean($item->title); // encapsulate link in unparseable $item->link = '<![CDATA[' . $post->link . ']]>'; $item->date = date($post->created); // sanitize ouput $item->description = preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', $post->description); $item->description = preg_replace('/[^A-Za-z0-9 ]/', '', $item->description); $item->description = preg_replace("/&#?[a-z1-9]{2,8};/i", "", $post->description); $item->description = html_entity_decode($post->description); $item->description = Sanitize::html($post->description); $doc->addItem($item); } } // Output the feed echo $doc->render(); }