plugins/Newsboy.php
changeset 2 66b299fdb9ca
parent 1 540d077b7612
child 3 8ae9acb2e919
equal deleted inserted replaced
1:540d077b7612 2:66b299fdb9ca
   284     $s = false;
   284     $s = false;
   285   }
   285   }
   286   if ( $s )
   286   if ( $s )
   287   {
   287   {
   288     $stuff = RenderMan::strToPageID($s);
   288     $stuff = RenderMan::strToPageID($s);
       
   289     // Hackish fix to prevent the categorization button and other stuff from being displayed
       
   290     $paths->pages[$s]['special'] = 1;
   289     $page = new PageProcessor($stuff[0], $stuff[1]);
   291     $page = new PageProcessor($stuff[0], $stuff[1]);
   290     $page->send();
   292     $content = $page->fetch_text();
   291     echo $p;
   293     $content = '?>' . RenderMan::render($content);
       
   294     eval($content);
   292   }
   295   }
   293   
   296   
   294   echo '<h2>Latest news</h2>';
   297   echo '<h2>Latest news</h2>';
   295     
   298     
   296   $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
   299   $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
   317     $parser = $template->makeParserText($news_template);
   320     $parser = $template->makeParserText($news_template);
   318     do
   321     do
   319     {
   322     {
   320       if ( $i < 5 )
   323       if ( $i < 5 )
   321       {
   324       {
       
   325         $content = $row['page_text'];
       
   326         
       
   327         $trimmed = false;
       
   328         if ( $pos = strpos($content, '<!--BREAK-->' ) )
       
   329         {
       
   330           $content = substr($content, 0, $pos);
       
   331           $trimmed = true;
       
   332         }
       
   333         
   322         $title = htmlspecialchars($row['name']);
   334         $title = htmlspecialchars($row['name']);
   323         $content = RenderMan::render($row['page_text']);
   335         $content = RenderMan::render($content);
   324         if ( strlen($content) > 400 )
   336         
       
   337         if ( strlen($content) > 400 && !$trimmed )
   325         {
   338         {
   326           $content = nb_trim_paragraph($content, 400, $trimmed);
   339           $content = nb_trim_paragraph($content, 400, $trimmed);
   327         }
   340         }
   328         if ( $trimmed )
   341         if ( $trimmed )
   329         {
   342         {
   330           $content .= ' <a href="' . makeUrlNS('NewsBoy', $row['urlname'], false, true) . '">Read more...</a>';
   343           $link = ' <a href="' . makeUrlNS('NewsBoy', $row['urlname'], false, true) . '">Read more...</a>';
       
   344           $content = preg_replace('/(.+?)<\/(p|ul|table|div|pre)>([\s]*?)$/Usi', '\\1' . $link . '</\\2>\\3', $content, 1);
       
   345           if ( !strstr($content, $link) )
       
   346           {
       
   347             $content .= $link;
       
   348           }
   331         }
   349         }
   332         $user_link = nb_make_username_link($row['author'], $row['user_level']);
   350         $user_link = nb_make_username_link($row['author'], $row['user_level']);
   333         $date = date('F d, Y h:i:s a', $row['urlname']);
   351         $date = date('F d, Y h:i:s a', $row['urlname']);
   334         $num_comments = $row['num_comments'];
   352         $num_comments = $row['num_comments'];
   335         $comment_s = ( $num_comments == 1 ) ? '' : 's';
   353         $comment_s = ( $num_comments == 1 ) ? '' : 's';
   362   {
   380   {
   363     echo '<div class="tblholder" style="margin: 10px auto 0 auto; display: table;">
   381     echo '<div class="tblholder" style="margin: 10px auto 0 auto; display: table;">
   364             <table border="0" cellspacing="1" cellpadding="4">
   382             <table border="0" cellspacing="1" cellpadding="4">
   365               <tr>
   383               <tr>
   366                 <th>Administrative tools:</th>
   384                 <th>Administrative tools:</th>
   367                 <td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS($stuff[1], $stuff[0], '', true) . '#do:edit">Edit announcement &raquo;</a></td>
   385                 <td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS('NewsBoy', 'Announce', '', true) . '#do:edit">Edit announcement &raquo;</a></td>
   368                 <td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'NewsboyItemManager', true) . '" onclick="newsboy_open_admin(); return false;">Portal Administration</a></td>
   386                 <td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'NewsboyItemManager', true) . '" onclick="newsboy_open_admin(); return false;">Portal Administration</a></td>
   369               </tr>
   387               </tr>
   370             </table>
   388             </table>
   371           </div><br />';
   389           </div><br />';
   372   }
   390   }
       
   391   show_category_info();
   373 }
   392 }
   374 
   393 
   375 /**
   394 /**
   376  * Formats row data in the archive.
   395  * Formats row data in the archive.
   377  * @package Enano
   396  * @package Enano
   771           
   790           
   772           if ( $second < 0 || $second > 60 )
   791           if ( $second < 0 || $second > 60 )
   773             $errors[] = 'Invalid second.';
   792             $errors[] = 'Invalid second.';
   774           
   793           
   775           $name = $_POST['article_name'];
   794           $name = $_POST['article_name'];
   776           $name = $db->escape($name);
   795           // This is db-escaped by PageUtils
   777           
   796           
   778           $author = $_POST['author'];
   797           $author = $_POST['author'];
   779           $author = $db->escape($author);
   798           $author = $db->escape($author);
   780           
   799           
   781           if ( count($errors) < 1 )
   800           if ( count($errors) < 1 )
   787             $errors[] = 'You cannot have two news articles with the same publish time.';
   806             $errors[] = 'You cannot have two news articles with the same publish time.';
   788           
   807           
   789           if ( count($errors) < 1 )
   808           if ( count($errors) < 1 )
   790           {
   809           {
   791             $publ = ( isset($_POST['published']) ) ? 1 : 0;
   810             $publ = ( isset($_POST['published']) ) ? 1 : 0;
       
   811             
   792             $result = PageUtils::createpage( (string)$time, 'NewsBoy', $name, $publ );
   812             $result = PageUtils::createpage( (string)$time, 'NewsBoy', $name, $publ );
   793             
   813             
   794             // Set content
   814             if ( $result == 'good' )
   795             $content = RenderMan::preprocess_text($_POST['content'], true); // this also SQL-escapes it
   815             {
   796             
   816               // Set content
   797             $q = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_text=\'' . $content . '\' WHERE page_id=\'' . $time . '\' AND namespace=\'NewsBoy\';');
   817               $content = RenderMan::preprocess_text($_POST['content'], true); // this also SQL-escapes it
   798             if ( !$q )
   818               
   799               $db->_die();
   819               $q = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_text=\'' . $content . '\' WHERE page_id=\'' . $time . '\' AND namespace=\'NewsBoy\';');
   800             
   820               if ( !$q )
   801             if ( $result )
   821                 $db->_die();
   802               echo '<div class="info-box">Your changes have been saved.</div>';
   822               
       
   823               if ( $result )
       
   824                 echo '<div class="info-box">Your changes have been saved.</div>';
       
   825               else
       
   826                 $errors[] = 'PageUtils::createpage returned an error.';
       
   827             }
   803             else
   828             else
   804               $errors[] = 'PageUtils::createpage returned an error.';
   829             {
       
   830               $errors[] = 'PageUtils::createpage returned an error: ' . htmlspecialchars($result);
       
   831             }
   805             
   832             
   806             break;
   833             break;
   807           }
   834           }
   808         }
   835         }
   809         
   836         
   810         if ( count($errors) > 0 )
   837         if ( count($errors) > 0 )
   811           echo '<div class="warning-box">Errors encountered while preparing data:<ul><li>' . implode('</li><li>', $errors) . '</li></ul></div>';
   838           echo '<div class="warning-box">Errors encountered while preparing data:<ul><li>' . implode('</li><li>', $errors) . '</li></ul></div>';
   812         
   839         
   813         $time = time();;
   840         $time = time();
   814         
   841         
   815         // Get author
   842         // Get author
   816         $author = $session->username;
   843         $author = $session->username;
   817         
   844         
   818         if ( empty($author) )
   845         if ( empty($author) )
   824         $day    = date('j', $time);
   851         $day    = date('j', $time);
   825         $hour   = date('G', $time);
   852         $hour   = date('G', $time);
   826         $minute = date('m', $time);
   853         $minute = date('m', $time);
   827         $second = date('s', $time);
   854         $second = date('s', $time);
   828         
   855         
   829         echo '<form id="nb_create_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&amp;' : '') .'module='.$paths->cpage['module'] . '&act=create').'" method="post" onsubmit="if ( !submitAuthorized ) return false;">';
   856         echo '<form id="nb_create_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&' : '') .'module='.$paths->cpage['module'] . '&act=create').'" method="post" onsubmit="if ( !submitAuthorized ) return false;">';
   830         echo '<div class="tblholder">
   857         echo '<div class="tblholder">
   831                 <table border="0" cellspacing="1" cellpadding="4">
   858                 <table border="0" cellspacing="1" cellpadding="4">
   832                   <tr>
   859                   <tr>
   833                     <th colspan="2">Creating news article</th>
   860                     <th colspan="2">Creating news article</th>
   834                   </tr>
   861                   </tr>
  1008  * @param string The text to trim
  1035  * @param string The text to trim
  1009  * @param int The maximum length to trim the text to.
  1036  * @param int The maximum length to trim the text to.
  1010  * @param bool Reference. Set to true if the text was trimmed, otherwise set to false.
  1037  * @param bool Reference. Set to true if the text was trimmed, otherwise set to false.
  1011  */
  1038  */
  1012 
  1039 
  1013 function nb_trim_paragraph($text, $len = 500, &$trimmed = false)
  1040 function nb_trim_paragraph($text, $len = 500, &$trimmed)
  1014 {
  1041 {
  1015   $trimmed = false;
  1042   $trimmed = false;
  1016   if ( strlen($text) <= $len )
  1043   if ( strlen($text) <= $len )
  1017     return $text;
  1044     return $text;
  1018   $trimmed = true;
  1045   $trimmed = true;