plugins/Newsboy.php
changeset 9 162b0f10e3d0
parent 8 81693fc2f660
child 10 0d52ee49c11c
child 11 b0995e600bde
equal deleted inserted replaced
8:81693fc2f660 9:162b0f10e3d0
   110     </script>
   110     </script>
   111     </enano:no-opt>');
   111     </enano:no-opt>');
   112     
   112     
   113     $x = getConfig('nb_portal_title');
   113     $x = getConfig('nb_portal_title');
   114     
   114     
   115     $page_name = ( $paths->cpage['urlname_nons'] == 'Portal' ) ?
   115     if ( $page->page_id == 'Portal' || $page->page_id == 'Archive' )
   116           ( ( empty($x) ) ?
   116     {
   117               'Welcome to ' . getConfig('site_name') :
   117       $page_name = ( $page->page_id == 'Portal' ) ?
   118               $x ) :
   118             ( ( empty($x) ) ?
   119           'News Archive';
   119                 'Welcome to ' . getConfig('site_name') :
   120     if ( method_exists($template, 'assign_vars') )
   120                 $x ) :
   121       $template->assign_vars(array('PAGE_NAME' => $page_name));
   121             'News Archive';
   122     else
   122       if ( method_exists($template, 'assign_vars') )
   123       $template->tpl_strings['PAGE_NAME'] = $page_name;
   123       {
       
   124         $template->assign_vars(array(
       
   125             'PAGE_NAME' => $page_name
       
   126           ));
       
   127       }
       
   128       else
       
   129       {
       
   130         $template->tpl_strings['PAGE_NAME'] = $page_name;
       
   131       }
       
   132     }
   124     
   133     
   125     if ( !$page->perms->get_permissions('read') )
   134     if ( !$page->perms->get_permissions('read') )
   126     {
   135     {
   127       $page->err_access_denied();
   136       $page->err_access_denied();
   128       return false;
   137       return false;
   142       NewsBoy_archive();
   151       NewsBoy_archive();
   143       $template->footer();
   152       $template->footer();
   144     }
   153     }
   145     else if ( preg_match('/^Article\//', $page->page_id) )
   154     else if ( preg_match('/^Article\//', $page->page_id) )
   146     {
   155     {
   147       if ( !preg_match('#^Article/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.+?)$#', $page->page_id, $id_match) )
   156       if ( !preg_match('#^Article/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+?)$#', $page->page_id, $id_match) )
   148       {
   157       {
   149         return;
   158         return;
   150       }
   159       }
   151       // look around for this page
   160       // look around for this page
   152       // int mktime  ([ int $hour  [, int $minute  [, int $second  [, int $month  [, int $day  [, int $year  [, int $is_dst  ]]]]]]] )
   161       // int mktime  ([ int $hour  [, int $minute  [, int $second  [, int $month  [, int $day  [, int $year  [, int $is_dst  ]]]]]]] )
   153       $timestamp_min = mktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1]));
   162       $timestamp_min = gmmktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1]));
   154       $timestamp_max = $timestamp_min + 86400;
   163       $timestamp_max = $timestamp_min + 86400;
   155       // mysql and postgresql friendly
   164       // mysql and postgresql friendly
   156       $integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : '';
   165       $integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : '';
   157       $q = $db->sql_query('SELECT urlname, name FROM ' . table_prefix . "pages WHERE CAST(urlname AS $integer_prepend integer) >= $timestamp_min AND CAST(urlname AS $integer_prepend integer) <= $timestamp_max AND namespace = 'NewsBoy';");
   166       $q = $db->sql_query('SELECT urlname, name FROM ' . table_prefix . "pages WHERE CAST(urlname AS $integer_prepend integer) >= $timestamp_min AND CAST(urlname AS $integer_prepend integer) <= $timestamp_max AND namespace = 'NewsBoy';");
   158       if ( !$q )
   167       if ( !$q )
   159         $db->_die();
   168         $db->_die();
   160       if ( $db->numrows() < 1 )
   169       if ( $db->numrows() < 1 )
   161         return;
   170         return;
   162       // found a page
   171       // found a page
   163       $row = $db->fetchrow();
   172       $found_match = false;
   164       if ( sanitize_page_id($row['name']) === $id_match[4] )
   173       while ( $row = $db->fetchrow() )
   165       {
   174       {
   166         // we have a definitive match, send the page through
   175         if ( sanitize_page_id($row['name']) === $id_match[4] )
   167         $article = new PageProcessor($row['urlname'], 'NewsBoy');
   176         {
   168         $article->send_headers = $page->send_headers;
   177           $found_match = true;
   169         $article->password = $page->password;
   178           // we have a definitive match, send the page through
   170         $article->send(true);
   179           $article = new PageProcessor($row['urlname'], 'NewsBoy');
       
   180           $article->send_headers = $page->send_headers;
       
   181           $article->password = $page->password;
       
   182           $article->send(true);
       
   183         }
   171       }
   184       }
   172       else
   185       if ( !$found_match )
   173       {
   186       {
   174         // can't find it.
   187         // can't find it.
   175         return;
   188         return;
   176       }
   189       }
   177       return;
   190       return;
   441   }
   454   }
   442   else
   455   else
   443   {
   456   {
   444     echo '<p>No news items yet.</p>';
   457     echo '<p>No news items yet.</p>';
   445   }
   458   }
       
   459   $db->free_result();
   446   if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-portal-post.tpl" ) )
   460   if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-portal-post.tpl" ) )
   447   {
   461   {
   448     $parser_post = $template->makeParser("newsboy-portal-post.tpl");
   462     $parser_post = $template->makeParser("newsboy-portal-post.tpl");
   449     echo $parser_post->run();
   463     echo $parser_post->run();
   450   }
   464   }
  1139 
  1153 
  1140 function nb_make_article_url($timestamp, $title = false)
  1154 function nb_make_article_url($timestamp, $title = false)
  1141 {
  1155 {
  1142   if ( !$title )
  1156   if ( !$title )
  1143     return makeUrlNS('NewsBoy', $timestamp);
  1157     return makeUrlNS('NewsBoy', $timestamp);
  1144   $day = date('d', $timestamp);
  1158   $day = gmdate('d', $timestamp);
  1145   $year = date('Y', $timestamp);
  1159   $year = gmdate('Y', $timestamp);
  1146   $month = date('m', $timestamp);
  1160   $month = gmdate('m', $timestamp);
  1147   return makeUrlNS('NewsBoy', "Article/$year/$month/$day/" . sanitize_page_id($title));
  1161   return makeUrlNS('NewsBoy', "Article/$year/$month/$day/" . sanitize_page_id($title));
  1148 }
  1162 }
  1149 
  1163 
  1150 ?>
  1164 ?>