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