Added backend RSS2 support, as long as Feed Me is there somewhere
authorDan
Tue, 29 Jul 2008 06:48:19 -0600
changeset 13 421242ebbece
parent 12 f0ddbf48c978
child 14 58840db7b472
Added backend RSS2 support, as long as Feed Me is there somewhere
plugins/nuggie/planet.php
plugins/nuggie/postbit.php
--- a/plugins/nuggie/planet.php	Thu Jul 17 00:37:09 2008 -0400
+++ b/plugins/nuggie/planet.php	Tue Jul 29 06:48:19 2008 -0600
@@ -108,16 +108,45 @@
   
   $db->free_result($sql);
   
+  // RSS check - do we have support for Feed Me and did the user request an RSS feed?
+  $do_rss = defined('ENANO_FEEDBURNER_INCLUDED') && ( isset($_GET['feed']) && $_GET['feed'] === 'rss2' );
+  $query_limit = $do_rss ? 50 : 10;
+  if ( $do_rss )
+  {
+    $offset = 0;
+  }
+  
   // pass 2: production run
   $columns = 'p.post_id, p.post_title, p.post_title_clean, p.post_author, p.post_timestamp, p.post_text, b.blog_name, b.blog_subtitle, b.blog_type, b.allowed_users, u.username, u.user_level, COUNT(c.comment_id) AS num_comments, \'' . $db->escape($planet_id) . '\' AS referring_planet';
   $sql = str_replace('<columns>', $columns, $sql_base);
-  $sql = str_replace('<limit>', "LIMIT $offset, 10", $sql);
+  $sql = str_replace('<limit>', "LIMIT $offset, $query_limit", $sql);
   
   // yea. that was one query.
   $q = $db->sql_query($sql);
   if ( !$q )
     $db->_die();
   
+  // RSS feed?
+  if ( $do_rss )
+  {
+    header('Content-type: text/xml; charset=utf-8');
+    global $aggressive_optimize_html;
+    $aggressive_optimize_html = false;
+    $rss = new RSS(
+      getConfig('site_name') . ': ' . $planet_data['planet_name'],
+      $planet_data['planet_subtitle'],
+      makeUrlComplete('Planet', $planet_id)
+    );
+    while ( $row = $db->fetchrow($q) )
+    {
+      $permalink = makeUrlNS('Blog', sanitize_page_id($row['username']) . date('/Y/n/j/', intval($row['post_timestamp'])) . $row['post_title_clean'], false, true);
+      $post = RenderMan::render($row['post_text']);
+      $rss->add_item($row['post_title'], $permalink, $post, intval($row['post_timestamp']));
+    }
+    echo $rss->render();
+    return;
+  }
+  
   // just let the paginator do the rest
   $postbit = new NuggiePostbit();
   // $q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = ''
--- a/plugins/nuggie/postbit.php	Thu Jul 17 00:37:09 2008 -0400
+++ b/plugins/nuggie/postbit.php	Tue Jul 29 06:48:19 2008 -0600
@@ -174,7 +174,7 @@
     }
     else
     {
-      $strings['USER_LINK'] = '<a href="' . makeUrlNS('User', $this->post_author, false, true) . '" style="' . $rank_data['rank_style'] . '">' . htmlspecialchars($this->post_author) . '</a>';
+      $strings['USER_LINK'] = '<a href="' . makeUrlNS('User', $this->post_author, false, true) . '">' . htmlspecialchars($this->post_author) . '</a>';
     }
     
     if ( $this->num_comments == 0 )
@@ -348,6 +348,8 @@
     return $page->err_page_not_existent();
   }
   
+  $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/nuggie/style.css" />');
+  
   // using page_id is SAFE. It's checked with a regex above.
   $q = $db->sql_query("SELECT p.post_id, p.post_title, p.post_title_clean, p.post_author, p.post_timestamp, p.post_text, b.blog_name,\n"
                     . "       b.blog_subtitle, b.blog_type, b.allowed_users, u.username, u.user_level, COUNT(c.comment_id) AS num_comments\n"
@@ -502,6 +504,30 @@
     return false;
   }
   
+  // RSS check - do we have support for Feed Me and did the user request an RSS feed?
+  $do_rss = defined('ENANO_FEEDBURNER_INCLUDED') && ( isset($_GET['feed']) && $_GET['feed'] === 'rss2' );
+  
+  // RSS feed?
+  if ( $do_rss )
+  {
+    header('Content-type: text/xml; charset=utf-8');
+    global $aggressive_optimize_html;
+    $aggressive_optimize_html = false;
+    $rss = new RSS(
+      $blog_name,
+      $blog_subtitle,
+      makeUrlComplete('Blog', $username)
+    );
+    while ( $row = $db->fetchrow($q) )
+    {
+      $permalink = makeUrlNS('Blog', sanitize_page_id($row['username']) . date('/Y/n/j/', intval($row['post_timestamp'])) . $row['post_title_clean'], false, true);
+      $post = RenderMan::render($row['post_text']);
+      $rss->add_item($row['post_title'], $permalink, $post, intval($row['post_timestamp']));
+    }
+    echo $rss->render();
+    return;
+  }
+  
   $page_name = htmlspecialchars($blog_name) . ' &raquo; ' . htmlspecialchars($blog_subtitle);
   if ( method_exists($template, 'assign_vars') )
   {