plugins/Newsboy.php
changeset 19 93c01ea4366b
parent 18 8205e4ca237e
child 20 1cbefc789a46
child 21 af40ef1982dd
equal deleted inserted replaced
18:8205e4ca237e 19:93c01ea4366b
   437   else
   437   else
   438   {
   438   {
   439     echo '<h2>Latest news</h2>';
   439     echo '<h2>Latest news</h2>';
   440   }
   440   }
   441     
   441     
   442   $q = $db->sql_unbuffered_query('SELECT p.*, COUNT(c.comment_id) AS num_comments, t.page_text, l.time_id, l.author, u.user_level FROM '.table_prefix.'pages AS p
   442   $num_articles = intval(getConfig('nb_portal_num_articles', 5));
       
   443   
       
   444   $q = $db->sql_query('SELECT p.*, COUNT(c.comment_id) AS num_comments, t.page_text, l.time_id, l.author, u.user_level FROM '.table_prefix.'pages AS p
   443          LEFT JOIN '.table_prefix.'comments AS c
   445          LEFT JOIN '.table_prefix.'comments AS c
   444            ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
   446            ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
   445          LEFT JOIN '.table_prefix.'page_text AS t
   447          LEFT JOIN '.table_prefix.'page_text AS t
   446            ON ( t.page_id=p.urlname AND t.namespace=p.namespace )
   448            ON ( t.page_id=p.urlname AND t.namespace=p.namespace )
   447          LEFT JOIN '.table_prefix.'logs AS l
   449          LEFT JOIN '.table_prefix.'logs AS l
   451          WHERE p.namespace=\'NewsBoy\'
   453          WHERE p.namespace=\'NewsBoy\'
   452            AND l.action=\'create\'
   454            AND l.action=\'create\'
   453            AND p.urlname!=\'Announce\'
   455            AND p.urlname!=\'Announce\'
   454            AND p.visible=1
   456            AND p.visible=1
   455          GROUP BY p.urlname
   457          GROUP BY p.urlname
   456          ORDER BY urlname DESC;');
   458          ORDER BY urlname DESC
       
   459          LIMIT ' . ($num_articles + 1) . ';');
   457   if ( !$q )
   460   if ( !$q )
   458     $db->_die();
   461     $db->_die();
   459   
   462   
   460   $num_articles = intval(getConfig('nb_portal_num_articles', 5));
   463   if ( $row = $db->fetchrow($q) )
   461   
       
   462   if ( $row = $db->fetchrow() )
       
   463   {
   464   {
   464     $i = 0;
   465     $i = 0;
   465     do
   466     do
   466     {
   467     {
   467       if ( $i < $num_articles )
   468       if ( $i < $num_articles )
   512       {
   513       {
   513         echo '<p><a href="'.makeUrlNS('NewsBoy', 'Archive').'">Older news...</a></p>';
   514         echo '<p><a href="'.makeUrlNS('NewsBoy', 'Archive').'">Older news...</a></p>';
   514         break;
   515         break;
   515       }
   516       }
   516       $i++;
   517       $i++;
   517     } while ( $row = $db->fetchrow() );
   518     } while ( $row = $db->fetchrow($q) );
   518   }
   519   }
   519   else
   520   else
   520   {
   521   {
   521     echo '<p>No news items yet.</p>';
   522     echo '<p>No news items yet.</p>';
   522   }
   523   }