plugins/Newsboy.php
changeset 9 162b0f10e3d0
parent 8 81693fc2f660
child 10 0d52ee49c11c
child 11 b0995e600bde
--- a/plugins/Newsboy.php	Mon Dec 22 13:32:08 2008 -0500
+++ b/plugins/Newsboy.php	Mon Dec 22 14:30:59 2008 -0500
@@ -112,15 +112,24 @@
     
     $x = getConfig('nb_portal_title');
     
-    $page_name = ( $paths->cpage['urlname_nons'] == 'Portal' ) ?
-          ( ( empty($x) ) ?
-              'Welcome to ' . getConfig('site_name') :
-              $x ) :
-          'News Archive';
-    if ( method_exists($template, 'assign_vars') )
-      $template->assign_vars(array('PAGE_NAME' => $page_name));
-    else
-      $template->tpl_strings['PAGE_NAME'] = $page_name;
+    if ( $page->page_id == 'Portal' || $page->page_id == 'Archive' )
+    {
+      $page_name = ( $page->page_id == 'Portal' ) ?
+            ( ( empty($x) ) ?
+                'Welcome to ' . getConfig('site_name') :
+                $x ) :
+            'News Archive';
+      if ( method_exists($template, 'assign_vars') )
+      {
+        $template->assign_vars(array(
+            'PAGE_NAME' => $page_name
+          ));
+      }
+      else
+      {
+        $template->tpl_strings['PAGE_NAME'] = $page_name;
+      }
+    }
     
     if ( !$page->perms->get_permissions('read') )
     {
@@ -144,13 +153,13 @@
     }
     else if ( preg_match('/^Article\//', $page->page_id) )
     {
-      if ( !preg_match('#^Article/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.+?)$#', $page->page_id, $id_match) )
+      if ( !preg_match('#^Article/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+?)$#', $page->page_id, $id_match) )
       {
         return;
       }
       // look around for this page
       // int mktime  ([ int $hour  [, int $minute  [, int $second  [, int $month  [, int $day  [, int $year  [, int $is_dst  ]]]]]]] )
-      $timestamp_min = mktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1]));
+      $timestamp_min = gmmktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1]));
       $timestamp_max = $timestamp_min + 86400;
       // mysql and postgresql friendly
       $integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : '';
@@ -160,16 +169,20 @@
       if ( $db->numrows() < 1 )
         return;
       // found a page
-      $row = $db->fetchrow();
-      if ( sanitize_page_id($row['name']) === $id_match[4] )
+      $found_match = false;
+      while ( $row = $db->fetchrow() )
       {
-        // we have a definitive match, send the page through
-        $article = new PageProcessor($row['urlname'], 'NewsBoy');
-        $article->send_headers = $page->send_headers;
-        $article->password = $page->password;
-        $article->send(true);
+        if ( sanitize_page_id($row['name']) === $id_match[4] )
+        {
+          $found_match = true;
+          // we have a definitive match, send the page through
+          $article = new PageProcessor($row['urlname'], 'NewsBoy');
+          $article->send_headers = $page->send_headers;
+          $article->password = $page->password;
+          $article->send(true);
+        }
       }
-      else
+      if ( !$found_match )
       {
         // can't find it.
         return;
@@ -443,6 +456,7 @@
   {
     echo '<p>No news items yet.</p>';
   }
+  $db->free_result();
   if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-portal-post.tpl" ) )
   {
     $parser_post = $template->makeParser("newsboy-portal-post.tpl");
@@ -1141,9 +1155,9 @@
 {
   if ( !$title )
     return makeUrlNS('NewsBoy', $timestamp);
-  $day = date('d', $timestamp);
-  $year = date('Y', $timestamp);
-  $month = date('m', $timestamp);
+  $day = gmdate('d', $timestamp);
+  $year = gmdate('Y', $timestamp);
+  $month = gmdate('m', $timestamp);
   return makeUrlNS('NewsBoy', "Article/$year/$month/$day/" . sanitize_page_id($title));
 }