Source for file admin.comment.php

Documentation is available at admin.comment.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @subpackage Comment
  5. @copyright  Refer to copyright.php
  6. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. @author Mambo Foundation Inc see README.php
  8. */
  9.  
  10. /** ensure this file is being included by a parent file */
  11. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  12.  
  13. require_once$mosConfig_absolute_path."/administrator/components/com_comment/class.comment.php");
  14. require_once$mainframe->getPath'admin_html' ) );
  15.  
  16. switch ($task{
  17.  
  18.     case "new":
  19.         editComment$option);
  20.         break;
  21.  
  22.     case "edit":
  23.         editComment$option$cid[0);
  24.         break;
  25.  
  26.     case 'editA':
  27.         editComment$optionintval$id ) );
  28.         break;
  29.  
  30.     case "save":
  31.         saveComment$option );
  32.         break;
  33.  
  34.     case "remove":
  35.         removeComments$cid$option );
  36.         break;
  37.  
  38.     case "publish":
  39.         publishComments$cid1$option );
  40.         break;
  41.  
  42.     case "unpublish":
  43.         publishComments$cid0$option );
  44.         break;
  45.  
  46.     case "settings":
  47.         showConfig$option );
  48.         break;
  49.  
  50.     case "savesettings":
  51.         $allow_comments_in_sections implode(',',$_POST['mcselections']);
  52.         saveConfig ($option$auto_publish_comments$allow_anonymous_entries$notify_new_entries$allow_comments_in_sections$comments_per_page$admin_comments_length);
  53.         break;
  54.  
  55.     default:
  56.         showComments$option );
  57.         break;
  58.  
  59. }
  60.  
  61. /**
  62.  * @param option 
  63.  * @return list of comments
  64.  */
  65. function showComments $option {
  66.     global $database$mainframe;
  67.     $limit      $mainframe->getUserStateFromRequest"viewlistlimit"'limit'10 );
  68.     $limitstart $mainframe->getUserStateFromRequest"view{$option}limitstart"'limitstart');
  69.     $search     $mainframe->getUserStateFromRequest"search{$option}"'search''' );
  70.     $search     $database->getEscapedtrimstrtolower$search ) ) );
  71.     $where array();
  72.     if ($search{
  73.         $where["LOWER(comments) LIKE '%$search%'";
  74.     }
  75.     $database->setQuery"SELECT count(*) FROM #__comment AS a" (count$where "\nWHERE " implode' AND '$where "") );
  76.     $total $database->loadResult();
  77.     echo $database->getErrorMsg();
  78.     include_once"includes/pageNavigation.php" );
  79.     $pageNav new mosPageNav$total$limitstart$limit  );
  80.     $database->setQuery"SELECT c.title, a.* FROM #__comment as a"
  81.         . "\n LEFT JOIN #__content AS c ON a.articleid = c.id"
  82.         . (count$where "\n WHERE " implode' AND '$where "")
  83.         . "\n ORDER BY a.id DESC"
  84.         . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
  85.     );
  86.     $rows $database->loadObjectList();
  87.     if ($database->getErrorNum()) {
  88.         echo $database->stderr();
  89.         return false;
  90.     }
  91.     HTML_comment::showComments$option$rows$search$pageNav );
  92. }
  93.  
  94. /**
  95.  * @param option 
  96.  * @param id 
  97.  * @return edit box for article or new comment box
  98.  */
  99. function editComment$option$uid {
  100.     global $database$my;
  101.     $row new moscomment$database );
  102.     $row->load$uid );
  103.     $contentitem[mosHTML::makeOption'0''Select Content Item' );
  104.     $database->setQuery"SELECT id AS value, title AS text FROM #__content ORDER BY title" );
  105.     $contentitem array_merge$contentitem$database->loadObjectList() );
  106.     if (count$contentitem 1{
  107.         mosRedirect"index2.php?option=com_sections&scope=content"'You must add sections first.' );
  108.     }
  109.     $clist mosHTML::selectList$contentitem'articleid''class="inputbox" size="1"''value''text'intval$row->articleid ) );
  110.     if ($uid{
  111.         $row->checkout$my->id );
  112.     else {
  113.         $row->published 0;
  114.     }
  115.     $publist mosHTML::yesnoRadioList'published''class="inputbox"'$row->published );
  116.     HTML_comment::editComment$option$row$clist$publist );
  117. }
  118.  
  119. /**
  120.  * @param option 
  121.  * @return saves comment
  122.  */
  123. function saveComment$option {
  124.     global $database;
  125.     $row new moscomment$database );
  126.     if (!$row->bind$_POST )) {
  127.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  128.         exit();
  129.     }
  130.     $row->startdate date"Y-m-d H:i:s" );
  131.     $row->ip   getenv('REMOTE_ADDR');
  132.     if (!$row->store()) {
  133.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  134.         exit();
  135.     }
  136.     $row->updateOrder"articleid='$row->articleid');
  137.     mosRedirect"index2.php?option=$option);
  138. }
  139.  
  140.  
  141. /**
  142.  * @param cid 
  143.  * @param publish 
  144.  * @param option 
  145.  * @return publishes / unpublishes article comment
  146.  */
  147. function publishComments$cid=null$publish=1,  $option {
  148.   global $database;
  149.   if (!is_array$cid || count$cid 1{
  150.     $action $publish 'publish' 'unpublish';
  151.     echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n";
  152.     exit;
  153.   }
  154.   $cids implode','$cid );
  155.   $database->setQuery"UPDATE #__comment SET published='$publish' WHERE id IN ($cids));
  156.   if (!$database->query()) {
  157.     echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  158.     exit();
  159.   }
  160.   mosRedirect"index2.php?option=$option);
  161. }
  162.  
  163. /**
  164.  * @param option 
  165.  * @return builds admin configuration options
  166.  */
  167. function showConfig$option {
  168.     global $mosConfig_absolute_path$database$mosConfig_mailfrom;
  169.     require($mosConfig_absolute_path."/administrator/components/com_comment/config.comment.php");
  170.     ?>
  171.     <script language="javascript" type="text/javascript">
  172.         function submitbutton(pressbutton) {
  173.         var form = document.adminForm;
  174.         if (pressbutton == 'cancel') {
  175.             submitform( pressbutton );
  176.             return;
  177.         }
  178.         submitform( pressbutton );
  179.         }
  180.     </script>
  181.   <form action="index2.php" method="POST" name="adminForm">
  182.   <?php
  183.   $gbtabs new mosTabs);
  184.   $gbtabs->startPane"_comment" );
  185.   $gbtabs->startTab(T_("General"),"General-page");
  186.   ?>
  187.   <table width="100%" border="0" cellpadding="4" cellspacing="2" class="adminForm">
  188.     <tr align="center" valign="middle">
  189.       <td align="right" valign="top"><strong><?php echo T_('Sections available')?>:</strong></td>
  190.       <td align="right" valign="top"><select size="5" name="mcselections[]" class="inputbox" multiple="multiple">
  191.       <?php
  192.         $seclistarray explode (","$allow_comments_in_sections);
  193.         $database -> setQuery("SELECT id,title FROM #__sections ORDER BY title ASC");
  194.         $dbsectionlist $database -> loadObjectList();
  195.                 echo "<option value='0' ";
  196.                 if (in_array (0$seclistarray)) echo "selected";
  197.                 echo ">Static Content</option>";
  198.         foreach ($dbsectionlist as $slrow){
  199.           echo "<option value='$slrow->id";
  200.           if (in_array ($slrow->id$seclistarray)) echo "selected";
  201.           echo ">$slrow->title</option>";
  202.         }
  203.       ?>
  204.         </select>
  205.       </td>
  206.       <td width="50%" align="right" valign="top"><?php echo T_("Choose which section(s) should use the comment system. Hold down [CTRL] to make multiple selections.")?></td>
  207.     </tr>
  208.     <tr align="center" valign="middle">
  209.       <td align="right" valign="top"><strong><?php echo T_('Autopublish Comments'?>:</strong></td>
  210.       <td align="right" valign="top">
  211.       <?php echo mosHTML::yesnoRadioList'auto_publish_comments''class="inputbox"'$auto_publish_comments )?>
  212.       </td>
  213.       <td align="right" valign="top"><?php echo T_('Automatically publish new comments'?></td>
  214.     </tr>
  215.     <tr align="center" valign="middle">
  216.       <td align="right" valign="top"><strong><?php echo T_('Anonymous Comments'?>:</strong></td>
  217.       <td align="right" valign="top">
  218.       <?php echo mosHTML::yesnoRadioList'allow_anonymous_entries''class="inputbox"'$allow_anonymous_entries )?>
  219.       </td>
  220.       <td align="right" valign="top"><?php echo T_('Allow unregistered users to post comments'?></td>
  221.     </tr>
  222.      <tr align="center" valign="middle">
  223.       <td align="right" valign="top"><strong><?php echo T_('Comments Per Page')?>:</strong></td>
  224.       <td align="right" valign="top">
  225.       <?php
  226.             $pp array(
  227.             mosHTML::makeOption(5,5),
  228.             mosHTML::makeOption(10,10),
  229.             mosHTML::makeOption(15,15),
  230.             mosHTML::makeOption(20,20),
  231.             mosHTML::makeOption(25,25),
  232.             mosHTML::makeOption(30,30),
  233.             mosHTML::makeOption(50,50),
  234.             );
  235.             echo mosHTML::selectList$pp'comments_per_page',    'class="inputbox" size="1"''value''text'$comments_per_page);
  236.       ?>
  237.       </td>
  238.       <td align="right" valign="top"><?php echo T_('When comments exceed the set level the page will automatically paginate'?></td>
  239.     </tr>
  240.   </table>
  241.     <?php
  242.     $gbtabs->endTab();
  243.     $gbtabs->startTab(T_("Notification"),"Notification-page");
  244.     ?>
  245.     <table width="100%" border="0" cellpadding="4" cellspacing="2" class="adminForm">
  246.     <tr align="center" valign="middle">
  247.       <td align="right" valign="top"><strong><?php echo T_('Notify Admin')?>:</strong></td>
  248.       <td align="right" valign="top">
  249.       <?php
  250.         echo mosHTML::yesnoRadioList'notify_new_entries''class="inputbox"'$notify_new_entries );
  251.       ?>
  252.       </td>
  253.       <td align="right" valign="top" width="50%"><?php echo T_('Notify the administrator by email upon new comments')?></td>
  254.     </tr>
  255.     <tr align="center" valign="middle">
  256.       <td align="right" valign="top"><strong><?php echo T_('Administrator Email')?>:</strong></td>
  257.       <td align="right" valign="top"><?php echo $mosConfig_mailfrom?></td>
  258.       <td align="right" valign="top"><?php echo T_('set in Global Configuration / Mail')?></td>
  259.     </tr>
  260.   </table>
  261.   <?php
  262.   $gbtabs->endTab();
  263.   $gbtabs->startTab(T_("Admin"),"Admin-page");
  264.     ?>
  265.     <table width="100%" border="0" cellpadding="4" cellspacing="2" class="adminForm">
  266.         <tr align="center" valign="middle">
  267.             <td align="right" valign="top"><strong><?php echo T_('Comment Length')?>:</strong></td>
  268.             <td align="right" valign="top">
  269.             <input name="admin_comments_length" type="text" size="5" value="<?php echo $admin_comments_length?>" />
  270.             </td>
  271.             <td align="right" valign="top" width="50%"><?php echo T_('The length of comment to show in the admin screen before it is truncated.')?></td>
  272.         </tr>
  273.     </table>
  274.   <?php
  275.   $gbtabs->endTab();
  276.   $gbtabs->endPane();
  277.   ?>
  278.   <input type="hidden" name="option" value="<?php echo $option?>">
  279.   <input type="hidden" name="task" value="">
  280.   <input type="hidden" name="boxchecked" value="0">
  281.     </form>
  282.     <?php
  283. }
  284.  
  285. /**
  286.  * @param option 
  287.  * @param auto_publish_comments 
  288.  * @param allow_anonymous_entries 
  289.  * @param notify_new_entries 
  290.  * @param allow_comments_in_sections 
  291.  * @param comments_per_page 
  292.  * @param admin_comments_length 
  293.  * @return saves configuration file
  294.  */
  295. function saveConfig ($option$auto_publish_comments$allow_anonymous_entries$notify_new_entries$allow_comments_in_sections$comments_per_page$admin_comments_length{
  296.     $configfile "components/com_comment/config.comment.php";
  297.     @chmod ($configfile0766);
  298.     $permission is_writable($configfile);
  299.     if (!$permission{
  300.         $mosmsg "Config file not writeable!";
  301.         mosRedirect("index2.php?option=$option&act=config",$mosmsg);
  302.         break;
  303.     }
  304.     $config  "<?php\n";
  305.     $config .= "\$auto_publish_comments = \"$auto_publish_comments\";\n";
  306.     $config .= "\$allow_anonymous_entries = \"$allow_anonymous_entries\";\n";
  307.     $config .= "\$notify_new_entries = \"$notify_new_entries\";\n";
  308.     $config .= "\$allow_comments_in_sections = \"$allow_comments_in_sections\";\n";
  309.     $config .= "\$comments_per_page = \"$comments_per_page\";\n";
  310.     $config .= "\$admin_comments_length = \"$admin_comments_length\";\n";
  311.     $config .= "?>";
  312.     if ($fp fopen("$configfile""w")) {
  313.         fputs($fp$configstrlen($config));
  314.         fclose ($fp);
  315.     }
  316.     mosRedirect("index2.php?option=$option&task=settings"T_("Settings saved"));
  317. }
  318.  
  319. /**
  320.  * @param cid 
  321.  * @param option 
  322.  * @return deletes selected article
  323.  */
  324. function removeComments$cid$option {
  325.     global $database;
  326.     if (count$cid )) {
  327.         $cids implode','$cid );
  328.         $database->setQuery"DELETE FROM #__comment WHERE id IN ($cids));
  329.         if (!$database->query()) {
  330.             echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  331.         }
  332.     }
  333.     mosRedirect"index2.php?option=$option);
  334. }

Documentation generated on Mon, 05 May 2008 16:12:57 +0400 by phpDocumentor 1.4.0