| [ PHPXref.com ] | [ Generated: Tue Jul 29 09:36:16 2008 ] | [ Phorum 5.2.8 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 //////////////////////////////////////////////////////////////////////////////// 4 // // 5 // Copyright (C) 2007 Phorum Development Team // 6 // http://www.phorum.org // 7 // // 8 // This program is free software. You can redistribute it and/or modify // 9 // it under the terms of either the current Phorum License (viewable at // 10 // phorum.org) or the Phorum License that was distributed with this file // 11 // // 12 // This program is distributed in the hope that it will be useful, // 13 // but WITHOUT ANY WARRANTY, without even the implied warranty of // 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // 15 // // 16 // You should have received a copy of the Phorum License // 17 // along with this program. // 18 //////////////////////////////////////////////////////////////////////////////// 19 define('phorum_page','read'); 20 21 include_once ("./common.php"); 22 include_once ("./include/email_functions.php"); 23 include_once ("./include/format_functions.php"); 24 25 // for dev-purposes .. 26 //include_once('./include/timing.php'); 27 28 //timing_start(); 29 30 // set all our URL's ... we need these earlier 31 phorum_build_common_urls(); 32 33 // checking read-permissions 34 if(!phorum_check_read_common()) { 35 return; 36 } 37 38 // somehow we got to a folder 39 if($PHORUM["folder_flag"]){ 40 $dest_url = phorum_get_url(PHORUM_INDEX_URL, $PHORUM["forum_id"]); 41 phorum_redirect_by_url($dest_url); 42 exit(); 43 } 44 45 $newflagkey = $PHORUM["forum_id"]."-".$PHORUM['user']['user_id']; 46 47 if ($PHORUM["DATA"]["LOGGEDIN"]) { // reading newflags in 48 49 $PHORUM['user']['newinfo'] = null; 50 51 if($PHORUM['cache_newflags']) { 52 $PHORUM['user']['newinfo']=phorum_cache_get('newflags',$newflagkey,$PHORUM['cache_version']); 53 } 54 55 if($PHORUM['user']['newinfo'] == null) { 56 $PHORUM['user']['newinfo']=phorum_db_newflag_get_flags(); 57 if($PHORUM['cache_newflags']) { 58 phorum_cache_put('newflags',$newflagkey,$PHORUM['user']['newinfo'],86400,$PHORUM['cache_version']); 59 } 60 } 61 } 62 63 $PHORUM["DATA"]["MODERATOR"] = phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES); 64 65 // Find out how many forums this user can moderate. 66 // If the user can moderate more than one forum, then 67 // present the move message moderation link. 68 if ($PHORUM["DATA"]["MODERATOR"]) { 69 $modforums = phorum_api_user_check_access( 70 PHORUM_USER_ALLOW_MODERATE_MESSAGES, 71 PHORUM_ACCESS_LIST 72 ); 73 $build_move_url = count($modforums) >= 2; 74 } 75 76 // setup some stuff based on the url passed 77 if(empty($PHORUM["args"][1])) { 78 // we have no forum-id given, redirect to the index 79 phorum_redirect_by_url(phorum_get_url(PHORUM_LIST_URL)); 80 exit(); 81 } elseif(empty($PHORUM["args"][2]) || $PHORUM["args"][2]=="printview") { 82 $thread = (int)$PHORUM["args"][1]; 83 $message_id = (int)$PHORUM["args"][1]; 84 85 // printview is requested 86 if(isset($PHORUM["args"][2]) && $PHORUM["args"][2]=="printview") { 87 $PHORUM["DATA"]["PRINTVIEW"]=1; 88 } else { 89 $PHORUM["DATA"]["PRINTVIEW"]=0; 90 } 91 } else{ 92 if(!is_numeric($PHORUM["args"][2])) { 93 $dest_url=""; 94 $newervar=(int)$PHORUM["args"][1]; 95 96 switch($PHORUM["args"][2]) { 97 case "newer": 98 $thread = phorum_db_get_neighbour_thread($newervar, "newer"); 99 break; 100 case "older": 101 $thread = phorum_db_get_neighbour_thread($newervar, "older"); 102 break; 103 case "markthreadread": 104 105 if($PHORUM["DATA"]["LOGGEDIN"]) { 106 // thread needs to be in $thread for the redirection 107 $thread = (int)$PHORUM["args"][1]; 108 $thread_message=phorum_db_get_message($thread,'message_id'); 109 110 $mids=array(); 111 foreach($thread_message['meta']['message_ids'] as $mid) { 112 if(!isset($PHORUM['user']['newinfo'][$mid]) && $mid > $PHORUM['user']['newinfo']['min_id']) { 113 $mids[]=$mid; 114 } 115 } 116 117 $msg_count=count($mids); 118 119 // any messages left to update newinfo with? 120 if($msg_count > 0){ 121 phorum_db_newflag_add_read($mids); 122 if($PHORUM['cache_newflags']) { 123 phorum_cache_remove('newflags',$newflagkey); 124 phorum_cache_remove('newflags_index',$newflagkey); 125 } 126 unset($mids); 127 } 128 } 129 // could be called from list too 130 if(isset($PHORUM["args"][3]) && $PHORUM["args"][3] == "list") { 131 $dest_url = phorum_get_url(PHORUM_LIST_URL); 132 phorum_redirect_by_url($dest_url); 133 } 134 break; 135 case "gotonewpost": 136 // thread needs to be in $thread for the redirection 137 $thread = (int)$PHORUM["args"][1]; 138 $thread_message=phorum_db_get_message($thread,'message_id'); 139 $message_ids=$thread_message['meta']['message_ids']; 140 141 $last_id = 0; 142 foreach($message_ids as $mkey => $mid) { 143 if ($last_id < $mid) $last_id = $mid; 144 // if already read, remove it from message-array 145 if(isset($PHORUM['user']['newinfo'][$mid]) || $mid <= $PHORUM['user']['newinfo']['min_id']) { 146 unset($message_ids[$mkey]); 147 } 148 149 } 150 151 // it could happen that they are all read. In that case, 152 // we jump to the last message in the thread. 153 if (!count($message_ids)) { 154 $new_message = $last_id; 155 } else { 156 // Find the lowest unread message id. 157 asort($message_ids,SORT_NUMERIC); 158 $new_message = array_shift($message_ids); 159 } 160 161 if($PHORUM['threaded_read'] == 0) { // get new page 162 $new_page=ceil(phorum_db_get_message_index($thread,$new_message)/$PHORUM['read_length']); 163 $dest_url=phorum_get_url(PHORUM_READ_URL,$thread,$new_message,"page=$new_page"); 164 } else { // for threaded 165 $dest_url=phorum_get_url(PHORUM_READ_URL,$thread,$new_message); 166 } 167 168 break; 169 170 } 171 172 if(empty($dest_url)) { 173 if($thread > 0) { 174 $dest_url = phorum_get_url(PHORUM_READ_URL, $thread); 175 } else{ 176 // we are either at the top or the bottom, go back to the list. 177 $dest_url = phorum_get_url(PHORUM_LIST_URL); 178 } 179 } 180 181 phorum_redirect_by_url($dest_url); 182 exit(); 183 } 184 185 $thread = (int)$PHORUM["args"][1]; 186 $message_id = (int)$PHORUM["args"][2]; 187 if(isset($PHORUM["args"][3]) && $PHORUM["args"][3]=="printview") { 188 $PHORUM["DATA"]["PRINTVIEW"]=1; 189 } else { 190 $PHORUM["DATA"]["PRINTVIEW"]=0; 191 } 192 } 193 194 //timing_mark("before database"); 195 196 // determining the page if page isn't given and message_id != thread 197 $page=0; 198 if(!$PHORUM["threaded_read"]) { 199 if(isset($PHORUM['args']['page']) && is_numeric($PHORUM["args"]["page"]) && $PHORUM["args"]["page"] > 0) { 200 $page=(int)$PHORUM["args"]["page"]; 201 } elseif($message_id != $thread) { 202 $page=ceil(phorum_db_get_message_index($thread,$message_id)/$PHORUM['read_length']); 203 } else { 204 $page=1; 205 } 206 if(empty($page)) { 207 $page=1; 208 } 209 } 210 211 // fill the breadcrumbs-info 212 $PHORUM['DATA']['BREADCRUMBS'][]=array( 213 'URL'=>$page > 1 ? phorum_get_url(PHORUM_READ_URL, $thread) : '', 214 'TEXT'=>$PHORUM['DATA']['LANG']['Thread'], 215 'ID'=>$message_id, 216 'TYPE'=>'message' 217 ); 218 if ($page > 1) { 219 $PHORUM['DATA']['BREADCRUMBS'][]=array( 220 'URL'=>'', 221 'TEXT'=>$PHORUM['DATA']['LANG']['Page'] . ' ' . $page, 222 'TYPE'=>'message-page' 223 ); 224 } 225 226 /* 227 thats the caching part 228 */ 229 230 if($PHORUM['cache_messages'] && 231 (!$PHORUM['count_views'] || !$PHORUM["threaded_read"])) { 232 233 $data=array(); 234 $data['users']=array(); 235 236 // is he a moderator and gets all messages? 237 $approved=1; 238 if($PHORUM["DATA"]["MODERATOR"]) { 239 $approved = 0; 240 } 241 242 $message_index=phorum_cache_get('message_index',$PHORUM['forum_id']."-$thread-$approved"); 243 244 $skip_cache = 0; 245 246 if($message_index == null) { 247 // nothing in the cache, get it from the database and store it in the cache 248 $data[$thread] = phorum_db_get_message($thread,"message_id"); 249 250 // Check if we really have requested the thread. 251 // If not, then we redirect back to the message list. 252 if (!empty($data[$thread]['parent_id'])) { 253 $PHORUM["DATA"]["ERROR"]=$PHORUM["DATA"]["LANG"]["MessageNotFound"]; 254 $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"]; 255 $PHORUM['DATA']["BACKMSG"]=$PHORUM["DATA"]["LANG"]["BackToList"]; 256 257 $PHORUM["DATA"]["HTML_TITLE"] = htmlspecialchars($PHORUM["DATA"]["HTML_TITLE"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]); 258 phorum_output("message"); 259 return; 260 } 261 262 $data['users'][] = $data[$thread]['user_id']; 263 264 if($PHORUM["DATA"]["MODERATOR"] && isset($data[$thread]["meta"]["message_ids_moderator"])) { 265 $message_index=$data[$thread]['meta']['message_ids_moderator']; 266 } else { 267 $message_index=$data[$thread]['meta']['message_ids']; 268 } 269 270 if(is_array($data[$thread])) { 271 272 // sort it as expected 273 sort($message_index); 274 275 // put it in the cache now 276 phorum_cache_put('message_index',$PHORUM['forum_id']."-$thread-$approved",$message_index); 277 278 } else { 279 $skip_cache = 1; 280 } 281 282 } 283 284 // if we errored out in the previous condition we need to skip this whole part! 285 if(!$skip_cache) { 286 287 288 // we expect this message_index to be ordered by message-id already! 289 290 // in this case we need the reversed order 291 if($PHORUM['threaded_read'] && 292 isset($PHORUM["reverse_threading"]) && $PHORUM["reverse_threading"]) { 293 294 $message_index=array_reverse($message_index); 295 296 } 297 298 $start=$PHORUM["read_length"]*($page-1); 299 300 if(!$PHORUM['threaded_read']) { 301 // get the message-ids from this page (only in flat mode) 302 $message_ids_page = array_slice($message_index, $start,$PHORUM["read_length"]); 303 } else { 304 // we need all message in threaded read ... 305 $message_ids_page = $message_index; 306 } 307 308 // we need the threadstarter too but its not available in the additional pages 309 if($page > 1) { 310 array_unshift($message_ids_page,$thread); 311 } 312 313 314 $cache_messages = phorum_cache_get('message',$message_ids_page); 315 316 317 // check the returned messages if they were found in the cache 318 $db_messages=array(); 319 320 $msg_not_in_cache=0; 321 322 foreach($message_ids_page as $mid) { 323 if(!isset($cache_messages[$mid])) { 324 $db_messages[]=$mid; 325 $msg_not_in_cache++; 326 } else { 327 $data[$mid]=$cache_messages[$mid]; 328 $data['users'][] = $data[$mid]['user_id']; 329 } 330 } 331 332 if($msg_not_in_cache) { 333 334 $db_messages = phorum_db_get_message($db_messages,'message_id'); 335 // store the found messages in the cache 336 337 foreach($db_messages as $mid => $message) { 338 phorum_cache_put('message',$mid,$message); 339 $data[$mid]=$message; 340 $data['users'][] = $data[$mid]['user_id']; 341 } 342 343 if($PHORUM['threaded_read'] && isset($PHORUM["reverse_threading"]) && $PHORUM["reverse_threading"]) { 344 krsort($data); 345 } else { 346 ksort($data); 347 } 348 } 349 350 } else { 351 $data = array('users'=>array()); 352 } 353 354 } else { 355 // Get the thread 356 $data = phorum_db_get_messages($thread,$page); 357 } 358 359 if($page>1 && !isset($data[$thread])){ 360 $first_message = phorum_db_get_message($thread); 361 $data["users"][]=$first_message["user_id"]; 362 $data[$first_message["message_id"]] = $first_message; 363 } 364 365 //timing_mark("after database"); 366 367 if(!empty($data) && isset($data[$thread]) && isset($data[$message_id])) { 368 369 // setup the url-templates needed later 370 $read_url_template_thread = phorum_get_url(PHORUM_READ_URL, '%thread_id%'); 371 $read_url_template_both = phorum_get_url(PHORUM_READ_URL, '%thread_id%','%message_id%'); 372 $read_page_url_template = phorum_get_url(PHORUM_READ_URL, '%thread_id%','page=%page_num%'); 373 $edit_url_template = phorum_get_url(PHORUM_POSTING_URL, '%action_id%', '%message_id%'); 374 $reply_url_template = phorum_get_url(PHORUM_REPLY_URL, '%thread_id%', '%message_id%'); 375 $reply_url_template_quote = phorum_get_url(PHORUM_REPLY_URL, '%thread_id%', '%message_id%','quote=1'); 376 if($PHORUM["track_edits"]) { 377 $changes_url_template = phorum_get_url(PHORUM_CHANGES_URL, '%message_id%'); 378 } 379 if($PHORUM['DATA']['LOGGEDIN']) { 380 $follow_url_template = phorum_get_url(PHORUM_FOLLOW_URL, '%thread_id%'); 381 if ($PHORUM["enable_pm"]) { 382 $pm_url_template = phorum_get_url(PHORUM_PM_URL, "page=send", "message_id=%message_id%"); 383 } 384 $report_url_template = phorum_get_url(PHORUM_REPORT_URL, '%message_id%'); 385 } 386 387 if($PHORUM["DATA"]["MODERATOR"]) { 388 $edit_url_template = phorum_get_url(PHORUM_POSTING_URL, "moderation", '%message_id%'); 389 $moderation_url_template = phorum_get_url(PHORUM_MODERATION_URL, '%action_id%', '%message_id%'); 390 } 391 if($PHORUM["max_attachments"]>0) { 392 $attachment_url_template = phorum_get_url(PHORUM_FILE_URL, 'file=%file_id%', 'filename=%file_name%'); 393 $attachment_download_url_template = phorum_get_url(PHORUM_FILE_URL, 'file=%file_id%', 'filename=%file_name%', 'download=1'); 394 } 395 396 $fetch_user_ids = null; 397 if (isset($data['users'])) { 398 $fetch_user_ids = $data['users']; 399 unset($data['users']); 400 } 401 402 // remove the unneeded message bodies in threaded view 403 // to avoid unnecessary formatting of bodies 404 if ($PHORUM["threaded_read"] == 1 && 405 !(isset($PHORUM['TMP']['all_bodies_in_threaded_read']) && 406 !empty($PHORUM['TMP']['all_bodies_in_threaded_read']) ) ) { 407 408 $remove_threaded_bodies=1; 409 // the flag is used in the foreach-loop later on 410 } else { 411 $remove_threaded_bodies=0; 412 } 413 414 // build URL's that apply only here. 415 if($PHORUM["float_to_top"]) { 416 $PHORUM["DATA"]["URL"]["OLDERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $data[$thread]["modifystamp"], "older"); 417 $PHORUM["DATA"]["URL"]["NEWERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $data[$thread]["modifystamp"], "newer"); 418 } else{ 419 $PHORUM["DATA"]["URL"]["OLDERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $thread, "older"); 420 $PHORUM["DATA"]["URL"]["NEWERTHREAD"] = phorum_get_url(PHORUM_READ_URL, $thread, "newer"); 421 } 422 423 if ($PHORUM["DATA"]["LOGGEDIN"]) { 424 $PHORUM["DATA"]["URL"]["MARKTHREADREAD"] = phorum_get_url(PHORUM_READ_URL, $thread, "markthreadread"); 425 } 426 if($PHORUM["threaded_read"]) { 427 $PHORUM["DATA"]["URL"]["PRINTVIEW"] = phorum_get_url(PHORUM_READ_URL, $thread, $message_id, "printview"); 428 } else { 429 $PHORUM["DATA"]["URL"]["PRINTVIEW"] = phorum_get_url(PHORUM_READ_URL, $thread, "printview",'page='.$page); 430 } 431 $thread_is_closed = (bool)$data[$thread]["closed"]; 432 433 // we might have more messages for mods 434 if($PHORUM["DATA"]["MODERATOR"] && isset($data[$thread]["meta"]["message_ids_moderator"])) { 435 $threadnum=count($data[$thread]['meta']['message_ids_moderator']); 436 } else { 437 $threadnum=$data[$thread]['thread_count']; 438 } 439 440 if(!$PHORUM["threaded_read"] && $threadnum > $PHORUM["read_length"]){ 441 $pages=ceil($threadnum/$PHORUM["read_length"]); 442 443 if($pages<=11){ 444 $page_start=1; 445 } elseif($pages-$page<5) { 446 $page_start=$pages-10; 447 } elseif($pages>11 && $page>6){ 448 $page_start=$page-5; 449 } else { 450 $page_start=1; 451 } 452 453 for($x=0;$x<11 && $x<$pages;$x++){ 454 $pageno=$x+$page_start; 455 $PHORUM["DATA"]["PAGES"][] = array( 456 "pageno"=>$pageno, 457 'url'=>str_replace(array('%thread_id%','%page_num%'),array($thread,$pageno),$read_page_url_template), 458 ); 459 } 460 461 $PHORUM["DATA"]["CURRENTPAGE"]=$page; 462 $PHORUM["DATA"]["TOTALPAGES"]=$pages; 463 $PHORUM["DATA"]["URL"]["PAGING_TEMPLATE"]=str_replace('%thread_id%',$thread,$read_page_url_template); 464 465 if($page_start>1){ 466 $PHORUM["DATA"]["URL"]["FIRSTPAGE"]=str_replace(array('%thread_id%','%page_num%'),array($thread,'1'),$read_page_url_template); 467 } 468 469 if($pageno<$pages){ 470 $PHORUM["DATA"]["URL"]["LASTPAGE"]=str_replace(array('%thread_id%','%page_num%'),array($thread,$pages),$read_page_url_template); 471 } 472 473 if($pages>$page){ 474 $nextpage=$page+1; 475 $PHORUM["DATA"]["URL"]["NEXTPAGE"]=str_replace(array('%thread_id%','%page_num%'),array($thread,$nextpage),$read_page_url_template); 476 } 477 if($page>1){ 478 $prevpage=$page-1; 479 $PHORUM["DATA"]["URL"]["PREVPAGE"]=str_replace(array('%thread_id%','%page_num%'),array($thread,$prevpage),$read_page_url_template); 480 } 481 } 482 483 // fetch_user_ids filled from phorum_db_get_messages 484 if(isset($fetch_user_ids) && count($fetch_user_ids)){ 485 $user_info=phorum_api_user_get($fetch_user_ids); 486 // hook to modify user info 487 if (isset($PHORUM["hooks"]["read_user_info"])) 488 $user_info = phorum_hook("read_user_info", $user_info); 489 } 490 491 // URLS which are common for the thread 492 if($PHORUM["DATA"]["MODERATOR"]) { 493 if($build_move_url) { 494 $URLS["move_url"] = str_replace(array('%action_id%','%message_id%'),array(PHORUM_MOVE_THREAD,$thread),$moderation_url_template); 495 } 496 $URLS["merge_url"] = str_replace(array('%action_id%','%message_id%'),array(PHORUM_MERGE_THREAD,$thread),$moderation_url_template); 497 $URLS