| [ Index ] |
PHP Cross Reference of e107 v1 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | Copyright (C) 2001-2002 Steve Dunstan (jalist@e107.org) 7 | Copyright (C) 2008-2010 e107 Inc (e107.org) 8 | 9 | Released under the terms and conditions of the 10 | GNU General Public License (http://gnu.org). 11 | 12 | $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.7/comment.php $ 13 | $Revision: 12190 $ 14 | $Id: comment.php 12190 2011-05-04 21:34:54Z e107steved $ 15 | $Author: e107steved $ 16 +----------------------------------------------------------------------------+ 17 */ 18 require_once ("class2.php"); 19 require_once(e_HANDLER."news_class.php"); 20 require_once(e_HANDLER."comment_class.php"); 21 define("PAGE_NAME", COMLAN_99); 22 23 if (!e_QUERY) 24 { 25 header("location:".e_BASE."index.php"); 26 exit; 27 } 28 29 $cobj = new comment; 30 31 $temp_query = explode(".", e_QUERY); 32 $action = $temp_query[0]; // Usually says 'comment' - may say 'reply' 33 $table = $temp_query[1]; // Table containing item associated with comment(s) 34 $id = intval(varset($temp_query[2], 0)); // ID of item associated with comments (e.g. news ID) 35 // For reply with nested comments, its the ID of the comment 36 $nid = intval(varset($temp_query[3], "")); // Action - e.g. 'edit'. Or news ID for reply with nested comments 37 $xid = intval(varset($temp_query[4], "")); // ID of target comment 38 global $comment_edit_query; 39 $comment_edit_query = $temp_query[0].".".$temp_query[1].".".$temp_query[2]; 40 unset($temp_query); 41 42 $redirectFlag = 0; 43 if (isset($_POST['commentsubmit']) || isset($_POST['editsubmit'])) 44 { // New comment, or edited comment, being posted. 45 if(!ANON && !USER) 46 { 47 header("location: ".e_BASE."index.php"); 48 exit; 49 } 50 51 switch ($table) 52 { 53 case 'poll' : 54 if (!$sql->db_Select("polls", "poll_title", "`poll_id` = '{$id}' AND `poll_comment` = 1")) 55 { 56 header("location: ".e_BASE."index.php"); 57 exit; 58 } 59 break; 60 case 'news' : 61 if (!$sql->db_Select("news", "news_allow_comments", "`news_id` = '{$id}' AND `news_allow_comments` = 0")) 62 { 63 header("location: ".e_BASE."index.php"); 64 exit; 65 } 66 break; 67 case 'user' : 68 if (!$sql->db_Select('user', 'user_name', '`user_id` ='.$id)) 69 { 70 header("location: ".e_BASE."index.php"); 71 exit; 72 } 73 break; 74 } 75 76 $pid = intval(varset($_POST['pid'], 0)); // ID of the specific comment being edited (nested comments - replies) 77 78 $editpid = intval(varset($_POST['editpid'], 0)); // ID of the specific comment being edited (in-line comments) 79 80 $clean_authorname = $_POST['author_name']; 81 $clean_comment = $_POST['comment']; 82 $clean_subject = $_POST['subject']; 83 84 $cobj->enter_comment($clean_authorname, $clean_comment, $table, $id, $pid, $clean_subject); 85 if ($table == "news") 86 { 87 $e107cache->clear("news"); 88 } 89 else 90 { 91 $e107cache->clear("comment.php?{$table}.{$id}"); 92 } 93 94 if($editpid) 95 { 96 $redirectFlag = $id; 97 /* $redir = preg_replace("#\.edit.*#si", "", e_QUERY); 98 header("Location: ".e_SELF."?{$redir}"); 99 exit; */ 100 } 101 } 102 103 104 if (isset($_POST['replysubmit'])) 105 { // Reply to nested comment being posted 106 if ($table == "news" && !$sql->db_Select("news", "news_allow_comments", "news_id='{$nid}' ")) 107 { 108 header("location:".e_BASE."index.php"); 109 exit; 110 } 111 else 112 { 113 $row = $sql->db_Fetch(); 114 if (!$row['news_id']) 115 { 116 $pid = (isset($_POST['pid']) ? $_POST['pid'] : 0); 117 $pid = intval($pid); 118 119 $clean_authorname = $_POST['author_name']; 120 $clean_comment = $_POST['comment']; 121 $clean_subject = $_POST['subject']; 122 123 $cobj->enter_comment($clean_authorname, $clean_comment, $table, $nid, $pid, $clean_subject); 124 $e107cache->clear("comment.php?{$table}.{$id}"); 125 } 126 $redirectFlag = $nid; 127 } 128 } 129 130 if ($redirectFlag) 131 { // Need to go back to original page 132 133 // Check for core tables first 134 switch ($table) 135 { 136 case "news" : 137 case "poll" : 138 echo "<script type='text/javascript'>document.location.href='".e_HTTP."comment.php?comment.{$table}.{$redirectFlag}'</script>\n"; 139 exit; 140 case "download" : 141 echo "<script type='text/javascript'>document.location.href='".e_HTTP."download.php?view.{$redirectFlag}'</script>\n"; 142 exit; 143 case "page" : 144 echo "<script type='text/javascript'>document.location.href='".e_HTTP."page.php?{$redirectFlag}'</script>\n"; 145 exit; 146 case 'user' : 147 echo "<script type='text/javascript'>document.location.href='".e_HTTP."user.php?id.{$redirectFlag}'</script>\n"; 148 exit; 149 } 150 151 // Check plugin e_comment.php files 152 $plugin_redir = false; 153 $e_comment = $cobj->get_e_comment(); 154 if ($table == $e_comment[$table]['eplug_comment_ids']) 155 { 156 $plugin_redir = TRUE; 157 $reply_location = str_replace('{NID}', $redirectFlag, $e_comment[$table]['reply_location']); 158 } 159 160 if ($plugin_redir) 161 { 162 echo "<script type='text/javascript'>document.location.href='{$reply_location}'</script>\n"; 163 exit; 164 } 165 166 // No redirect found if we get here. 167 } 168 169 $comment_ob_start = FALSE; 170 if ($action == "reply") 171 { 172 if (!$pref['nested_comments']) 173 { 174 header("Location: ".e_BASE."comment.php?comment.{$table}.{$nid}"); 175 exit; 176 } 177 178 $query = "`comment_id` = '{$id}' LIMIT 0,1"; 179 if ($sql->db_Select("comments", "comment_subject", "`comment_id` = '{$id}'")) 180 { 181 $comments = $sql->db_Fetch(); 182 $subject = $comments['comment_subject']; 183 $subject_header = $tp->toHTML($comments['comment_subject']); 184 } 185 186 if ($subject == "") 187 { 188 switch ($table) 189 { 190 case "news" : 191 if (!$sql->db_Select("news", "news_title", "news_id='{$nid}' ")) 192 { 193 header("location: ".e_BASE."index.php"); 194 exit; 195 } 196 else 197 { 198 $news = $sql->db_Fetch(); 199 $subject = $news['news_title']; 200 $title = COMLAN_100; 201 } 202 break; 203 case "poll" : 204 if (!$sql->db_Select("polls", "poll_title", "poll_id='{$nid}' ")) 205 { 206 header("location:".e_BASE."index.php"); 207 exit; 208 } 209 else 210 { 211 $poll = $sql->db_Fetch(); 212 $subject = $poll['poll_title']; 213 $title = COMLAN_101; 214 } 215 break; 216 case 'download' : 217 if ($sql->db_Select('download','download_name',"download_id={$nid} ")) 218 { 219 $row = $sql->db_Fetch(); 220 $subject = $row['download_name']; 221 $title = COMLAN_106; 222 } 223 else 224 { 225 header("location:".e_BASE."index.php"); 226 exit; 227 } 228 break; 229 case 'user' : 230 if ($sql->db_Select('user','user_name',"user_id={$nid} ")) 231 { 232 $row = $sql->db_Fetch(); 233 $subject = $row['user_name']; 234 $title = COMLAN_12; 235 } 236 else 237 { 238 header("location:".e_BASE."index.php"); 239 exit; 240 } 241 break; 242 } 243 } 244 define('e_PAGETITLE', $title." / ".COMLAN_99." / ".COMLAN_102.$subject.""); 245 require_once(HEADERF); 246 } 247 elseif ($action == 'comment') 248 { // Default code if not reply 249 250 // Check cache 251 if ($cache = $e107cache->retrieve("comment.php?{$table}.{$id}")) 252 { 253 require_once(HEADERF); 254 echo $cache; 255 require_once(FOOTERF); 256 exit; 257 } 258 else 259 { 260 switch ($table) 261 { 262 case "news" : 263 if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled']) 264 { 265 $query = "SELECT COUNT(tb.trackback_pid) AS tb_count, n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n 266 LEFT JOIN #user AS u ON n.news_author = u.user_id 267 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 268 LEFT JOIN #trackback AS tb ON tb.trackback_pid = n.news_id 269 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' 270 AND n.news_id={$id} 271 AND n.news_allow_comments=0 272 GROUP by n.news_id"; 273 } 274 else 275 { 276 $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n 277 LEFT JOIN #user AS u ON n.news_author = u.user_id 278 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 279 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' 280 AND n.news_id={$id} 281 AND n.news_allow_comments=0"; 282 } 283 284 if (!$sql->db_Select_gen($query)) 285 { 286 header("location:".e_BASE."index.php"); 287 exit; 288 } 289 else 290 { 291 $news = $sql->db_Fetch(); 292 $subject = $tp->toForm($news['news_title']); 293 define("e_PAGETITLE", COMLAN_100." / ".COMLAN_99." / {$subject}"); 294 require_once(HEADERF); 295 ob_start(); 296 $comment_ob_start = TRUE; 297 $ix = new news; 298 $ix->render_newsitem($news, "extend"); // extend so that news-title-only news text is displayed in full when viewing comments. 299 $field = $news['news_id']; 300 } 301 break; 302 case "poll" : 303 if (!$sql->db_Select("polls", "*", "poll_id='{$id}'")) 304 { 305 header("location:".e_BASE."index.php"); 306 exit; 307 } 308 else 309 { 310 $row = $sql->db_Fetch(); 311 $comments_poll = $row['poll_comment']; 312 $subject = $row['poll_title']; 313 define("e_PAGETITLE", COMLAN_101." / ".COMLAN_99." / ".$subject.""); 314 $poll_to_show = $id; // Need to pass poll number through to display routine 315 require_once(HEADERF); 316 require(e_PLUGIN."poll/poll_menu.php"); 317 $field = $row['poll_id']; 318 if(!$comments_poll) 319 { 320 require_once(FOOTERF); 321 exit; 322 } 323 } 324 break; 325 case 'download' : 326 if ($sql->db_Select('download','download_name',"download_id={$id} ")) 327 { 328 $row = $sql->db_Fetch(); 329 $subject = $row['download_name']; 330 //$title = COMLAN_106; 331 $field = $id; 332 require_once(HEADERF); 333 } 334 else 335 { 336 header("location:".e_BASE."index.php"); 337 exit; 338 } 339 break; 340 case 'user' : 341 if ($sql->db_Select('user','user_name',"user_id={$id} ")) 342 { 343 $row = $sql->db_Fetch(); 344 $subject = $row['user_name']; 345 //$title = 'Edit comment about user'; 346 $field = $id; 347 require_once(HEADERF); 348 } 349 else 350 { 351 header("location:".e_BASE."index.php"); 352 exit; 353 } 354 break; 355 default : // Hope its a plugin table 356 $e_comment = $cobj->get_e_comment(); 357 if ($table == $e_comment[$table]['eplug_comment_ids']) 358 { 359 if ($sql->db_Select($e_comment[$table]['db_table'],$e_comment[$table]['db_title'],$e_comment[$table]['db_id']."={$id} ")) 360 { 361 $row = $sql->db_Fetch(); 362 $subject = $row[$e_comment[$table]['db_title']]; 363 $title = $e_comment[$table]['plugin_name']; 364 $field = $id; 365 require_once(HEADERF); 366 } 367 else 368 { 369 header("location:".e_BASE."index.php"); 370 exit; 371 } 372 } 373 else 374 { // Error - emit some debug code 375 require_once(HEADERF); 376 if (E107_DEBUG_LEVEL) 377 { 378 echo "Comment error: {$table} Field: {$e_comment['db_id']} ID {$id} Title: {$e_comment['db_title']}<br />"; 379 echo "<pre>"; 380 var_dump($e_comment); 381 echo "</pre>"; 382 } 383 else 384 { 385 header('location:'.e_BASE.'index.php'); 386 exit; 387 } 388 } 389 } 390 } 391 } 392 else 393 { // Invalid action - just exit 394 header("location:".e_BASE."index.php"); 395 exit; 396 } 397 398 if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled'] && $table == "news") 399 { 400 echo "<span class='smalltext'><b>".$pref['trackbackString']."</b> ".SITEURLBASE.e_PLUGIN_ABS."trackback/trackback.php?pid={$id}</span>"; 401 } 402 403 $field = ($field ? $field : ($id ? $id : "")); // ID of associated source item 404 $width = (isset($width) && $width ? $width : ""); 405 $cobj->compose_comment($table, $action, $field, $width, $subject, $rate=FALSE); 406 407 408 409 if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled'] && $table == "news") 410 { 411 if($sql->db_Select("trackback", "*", "trackback_pid={$id}")) 412 { 413 $tbArray = $sql -> db_getList(); 414 415 if (file_exists(THEME."trackback_template.php")) { 416 require_once(THEME."trackback_template.php"); 417 } else { 418 require_once(e_THEME."templates/trackback_template.php"); 419 } 420 421 $text = ""; 422 423 foreach($tbArray as $trackback) 424 { 425 extract($trackback); 426 $TITLE = $trackback_title; 427 $EXCERPT = $trackback_excerpt; 428 $BLOGNAME = "<a href='{$trackback_url}' rel='external'>{$trackback_blogname}</a>"; 429 $text .= preg_replace("/\{(.*?)\}/e", '$\1', $TRACKBACK); 430 } 431 432 if($TRACKBACK_RENDER_METHOD) 433 { 434 $ns->tablerender("<a name='track'></a>".COMLAN_315, $text); 435 } 436 else 437 { 438 echo "<a name='track'></a>".$text; 439 } 440 } 441 else 442 { 443 echo "<a name='track'></a>".COMLAN_316; 444 } 445 if (ADMIN && getperms("B")) { 446 echo "<div style='text-align:right'><a href='".e_PLUGIN_ABS."trackback/modtrackback.php?".$id."'>".COMLAN_317."</a></div><br />"; 447 } 448 } 449 450 451 //if (!strstr(e_QUERY, "poll")) 452 // If output buffering started, cache the result 453 if ($comment_ob_start) 454 { 455 $cache = ob_get_contents(); 456 $e107cache->set("comment.php?{$table}.{$field}", $cache); 457 ob_end_flush(); // dump the buffer we started 458 } 459 460 461 require_once(FOOTERF); 462 463 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Mar 12 16:28:38 2012 | Cross Reference PHPXref |