Пример #1
0
 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();
 }
Пример #2
0
     $blog_twitter = $settings->get('blog_twitter');
     // Get the index template file.
     ob_start();
     include_once $index_file;
     $html = ob_get_clean();
     echo $html;
     // Now that we have the whole index page generated, put it in cache folder
     if ($settings->get('index_cache') != 'off') {
         $fp = fopen($cachefile, 'w');
         fwrite($fp, ob_get_contents());
         fclose($fp);
     }
 } else {
     if ($filename == 'rss' || $filename == 'atom') {
         $filename == 'rss' ? $feed = new \FeedWriter\RSS2() : ($feed = new \FeedWriter\ATOM());
         $feed->setTitle($blog_title);
         $feed->setLink($blog_url);
         if ($filename == '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 = get_all_posts();
         if ($posts) {
             $c = 0;
             foreach ($posts as $post) {
                 if ($c < $feed_max_items) {
                     $item = $feed->createNewItem();