public function rss($type = null) { $type == 'rss' ? $feed = new \FeedWriter\RSS2() : ($feed = new \FeedWriter\ATOM()); // Variables for template $blog_title = $this->settings->get('blog_title'); $blog_url = $this->settings->get('blog_url'); $blog_email = $this->settings->get('blog_email'); $meta_description = $this->settings->get('meta_description'); $language = $this->settings->get('language'); $feed_max_items = $this->settings->get('feed_max_items'); if (!$feed_max_items) { $feed_max_items = 10; } if (!$language) { $language = "en-gb"; } $feed->setTitle($blog_title); $feed->setLink($blog_url); if ($type == 'rss') { $feed->setDescription($meta_description); $feed->setChannelElement('language', $language); $feed->setChannelElement('pubDate', date(DATE_RSS, time())); } else { $feed->setChannelElement('author', $blog_title . ' - ' . $blog_email); $feed->setChannelElement('updated', date(DATE_RSS, time())); } $posts = $this->posts->get_all_posts(); if ($posts) { $c = 0; foreach ($posts as $post) { if ($c < $feed_max_items) { $item = $feed->createNewItem(); // Remove HTML from the RSS feed. $item->setTitle(substr($post['post_title'], 4, -6)); $item->setLink(rtrim($blog_url, '/') . '/' . str_replace($this->settings->get('file_ext'), '', $post['fname'])); $item->setDate($post['post_date']); // Remove Meta from the RSS feed. $remove_metadata_from = file(rtrim($this->settings->posts_dir, '/') . '/' . $post['fname']); if ($type == 'rss') { $item->addElement('author', $blog_email . ' (' . str_replace('-', '', $remove_metadata_from[1]) . ')'); $item->addElement('guid', rtrim($blog_url, '/') . '/' . str_replace($this->settings->get('file_ext'), '', $post['fname'])); } // Remove the metadata from the RSS feed. unset($remove_metadata_from[0], $remove_metadata_from[1], $remove_metadata_from[2], $remove_metadata_from[3], $remove_metadata_from[4], $remove_metadata_from[5]); $remove_metadata_from = array_values($remove_metadata_from); $item->setDescription(\Michelf\Markdown::defaultTransform(implode($remove_metadata_from))); $feed->addItem($item); $c++; } } } echo $feed->generateFeed(); }
$item = $feed->createNewItem(); // Remove HTML from the RSS feed. $item->setTitle(substr($post['post_title'], 4, -6)); $item->setLink(rtrim($blog_url, '/') . '/' . str_replace($settings->get('file_ext'), '', $post['fname'])); $item->setDate($post['post_date']); // Remove Meta from the RSS feed. $remove_metadata_from = file(rtrim(POSTS_DIR, '/') . '/' . $post['fname']); if ($filename == 'rss') { $item->addElement('author', $blog_email . ' (' . str_replace('-', '', $remove_metadata_from[1]) . ')'); $item->addElement('guid', rtrim($blog_url, '/') . '/' . str_replace($settings->get('file_ext'), '', $post['fname'])); } // Remove the metadata from the RSS feed. unset($remove_metadata_from[0], $remove_metadata_from[1], $remove_metadata_from[2], $remove_metadata_from[3], $remove_metadata_from[4], $remove_metadata_from[5]); $remove_metadata_from = array_values($remove_metadata_from); $item->setDescription(\Michelf\Markdown::defaultTransform(implode($remove_metadata_from))); $feed->addItem($item); $c++; } } } echo $feed->generateFeed(); } else { ob_start(); // Define the post file. $fcontents = file($filename); $slug_array = explode("/", $filename); $slug_len = count($slug_array); // This was hardcoded array index, it should always return the last index. $slug = str_replace(array($settings->get('file_ext')), '', $slug_array[$slug_len - 1]); // Define the cached file. $cachefile = $settings->config("cache_dir") . $slug . '.html';