[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ©Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_plugins/forum/forum_class.php,v $ 14 | $Revision: 1.65 $ 15 | $Date: 2006/11/15 12:57:18 $ 16 | $Author: mcfly_e107 $ 17 +----------------------------------------------------------------------------+ 18 */ 19 if (!defined('e107_INIT')) { exit; } 20 21 class e107forum 22 { 23 24 function thread_postnum($thread_id) 25 { 26 global $sql; 27 $ret = array(); 28 $ret['parent'] = $thread_id; 29 $query = " 30 SELECT ft.thread_id, fp.thread_id as parent 31 FROM #forum_t AS t 32 LEFT JOIN #forum_t AS ft ON ft.thread_parent = t.thread_parent AND ft.thread_id <= ".intval($thread_id)." 33 LEFT JOIN #forum_t as fp ON fp.thread_id = t.thread_parent 34 WHERE t.thread_id = ".intval($thread_id)." AND t.thread_parent != 0 35 ORDER BY ft.thread_datestamp ASC 36 "; 37 if($ret['post_num'] = $sql->db_Select_gen($query)) 38 { 39 $row = $sql->db_Fetch(); 40 $ret['parent'] = $row['parent']; 41 } 42 return $ret; 43 } 44 45 function update_lastpost($type, $id, $update_threads = FALSE) 46 { 47 global $sql, $tp; 48 $sql2 = new db; 49 if ($type == 'thread') 50 { 51 $id = intval($id); 52 $thread_info = $this->thread_get_lastpost($id); 53 list($uid, $uname) = explode(".", $thread_info['thread_user'], 2); 54 if ($thread_info) 55 { 56 if($thread_user['user_name'] != "") 57 { 58 $thread_lastuser = $uid.".".$thread_info['user_name']; 59 } 60 else 61 { 62 $tmp = explode(chr(1), $thread_info['thread_user']); 63 $thread_lastuser = $tmp[0]; 64 } 65 $sql->db_Update('forum_t', "thread_lastpost = ".intval($thread_info['thread_datestamp']).", thread_lastuser = '".$tp -> toDB($thread_lastuser, true)."' WHERE thread_id = ".intval($id)); 66 } 67 return $thread_info; 68 } 69 if ($type == 'forum') { 70 if ($id == 'all') 71 { 72 if ($sql->db_Select('forum', 'forum_id', 'forum_parent != 0')) 73 { 74 while ($row = $sql->db_Fetch()) 75 { 76 $parentList[] = $row['forum_id']; 77 } 78 foreach($parentList as $id) 79 { 80 // echo "Updating forum #{$id}<br />"; 81 $this->update_lastpost('forum', $id, $update_threads); 82 } 83 } 84 } 85 else 86 { 87 $id = intval($id); 88 $forum_lp_user = ''; 89 $forum_lp_info = ''; 90 if($update_threads == TRUE) 91 { 92 if ($sql2->db_Select('forum_t', 'thread_id', "thread_forum_id = $id AND thread_parent = 0")) 93 { 94 while ($row = $sql2->db_Fetch()) 95 { 96 $this->update_lastpost('thread', $row['thread_id']); 97 } 98 } 99 } 100 if ($sql->db_Select("forum_t", "*", "thread_forum_id='$id' ORDER BY thread_datestamp DESC LIMIT 0,1")) 101 { 102 $row = $sql->db_Fetch(); 103 $tmp = explode(chr(1), $row['thread_user']); 104 $forum_lp_user = $tmp[0]; 105 $last_id = $row['thread_parent'] ? $row['thread_parent'] : $row['thread_id']; 106 $forum_lp_info = $row['thread_datestamp'].".".$last_id; 107 } 108 $sql->db_Update('forum', "forum_lastpost_user = '{$forum_lp_user}', forum_lastpost_info = '{$forum_lp_info}' WHERE forum_id={$id}"); 109 } 110 } 111 } 112 113 function forum_markasread($forum_id) { 114 global $sql; 115 if ($forum_id != 'all') { 116 $forum_id = intval($forum_id); 117 $extra = " AND thread_forum_id='$forum_id' "; 118 } 119 $qry = "thread_lastpost > ".USERLV." AND thread_parent = 0 {$extra} "; 120 if ($sql->db_Select('forum_t', 'thread_id', $qry)) { 121 while ($row = $sql->db_Fetch()) { 122 $u_new .= ".".$row['thread_id']."."; 123 } 124 $u_new .= USERVIEWED; 125 $sql->db_Update("user", "user_viewed='$u_new' WHERE user_id='".USERID."' "); 126 header("location:".e_SELF); 127 exit; 128 } 129 } 130 131 function thread_markasread($thread_id) 132 { 133 global $sql; 134 $thread_id = intval($thread_id); 135 $u_new = USERVIEWED.".$thread_id"; 136 return $sql->db_Update("user", "user_viewed='$u_new' WHERE user_id='".USERID."' "); 137 } 138 139 function forum_getparents() 140 { 141 global $sql; 142 if ($sql->db_Select('forum', '*', "forum_parent='0' ORDER BY forum_order ASC")) 143 { 144 while ($row = $sql->db_Fetch()) { 145 $ret[] = $row; 146 } 147 return $ret; 148 } 149 return FALSE; 150 } 151 152 function forum_getmods($uclass = e_UC_ADMIN) 153 { 154 global $sql; 155 if($uclass == e_UC_ADMIN || trim($uclass) == '') 156 { 157 $sql->db_Select('user', 'user_id, user_name',"user_admin = 1"); 158 } 159 else 160 { 161 $regex = "(^|,)(".str_replace(",", "|", $uclass).")(,|$)"; 162 $sql->db_Select("user", "user_id, user_name", "user_class REGEXP '{$regex}'"); 163 } 164 while($row = $sql->db_Fetch()) 165 { 166 $ret[$row['user_id']] = $row['user_name']; 167 } 168 return $ret; 169 } 170 171 function forum_getforums($type = 'all') 172 { 173 global $sql; 174 $qry = " 175 SELECT f.*, u.user_name FROM #forum AS f 176 LEFT JOIN #user AS u ON SUBSTRING_INDEX(f.forum_lastpost_user,'.',1) = u.user_id 177 WHERE forum_parent != 0 AND forum_sub = 0 178 ORDER BY f.forum_order ASC 179 "; 180 if ($sql->db_Select_gen($qry)) 181 { 182 while ($row = $sql->db_Fetch()) 183 { 184 if($type == 'all') 185 { 186 $ret[$row['forum_parent']][] = $row; 187 } 188 else 189 { 190 $ret[] = $row; 191 } 192 } 193 return $ret; 194 } 195 return FALSE; 196 } 197 198 function forum_getsubs($forum_id = "") 199 { 200 global $sql; 201 $where = ($forum_id != "" && $forum_id != 'bysub' ? "AND forum_sub = ".intval($forum_id) : ""); 202 $qry = " 203 SELECT f.*, u.user_name FROM #forum AS f 204 LEFT JOIN #user AS u ON SUBSTRING_INDEX(f.forum_lastpost_user,'.',1) = u.user_id 205 WHERE forum_sub != 0 {$where} 206 ORDER BY f.forum_order ASC 207 "; 208 if ($sql->db_Select_gen($qry)) 209 { 210 while ($row = $sql->db_Fetch()) 211 { 212 if($forum_id == "") 213 { 214 $ret[$row['forum_parent']][$row['forum_sub']][] = $row; 215 } 216 elseif($forum_id == 'bysub') 217 { 218 $ret[$row['forum_sub']][] = $row; 219 } 220 else 221 { 222 $ret[] = $row; 223 } 224 } 225 return $ret; 226 } 227 return FALSE; 228 } 229 230 231 function forum_newflag_list() 232 { 233 global $sql; 234 $viewed = ""; 235 if(USERVIEWED) 236 { 237 $viewed = preg_replace("#\.+#", ".", USERVIEWED); 238 $viewed = preg_replace("#^\.#", "", $viewed); 239 $viewed = preg_replace("#\.$#", "", $viewed); 240 $viewed = str_replace(".", ",", $viewed); 241 } 242 if($viewed != "") 243 { 244 $viewed = " AND thread_id NOT IN (".$viewed.")"; 245 } 246 247 $_newqry = " 248 SELECT DISTINCT ff.forum_sub, ft.thread_forum_id FROM #forum_t AS ft 249 LEFT JOIN #forum AS ff ON ft.thread_forum_id = ff.forum_id 250 WHERE thread_parent = 0 AND thread_lastpost > '".USERLV."' {$viewed} 251 "; 252 if($sql->db_Select_gen($_newqry)) 253 { 254 while($row = $sql->db_Fetch()) 255 { 256 $ret[] = $row['thread_forum_id']; 257 if($row['forum_sub']) 258 { 259 $ret[] = $row['forum_sub']; 260 } 261 } 262 return $ret; 263 } 264 else 265 { 266 return FALSE; 267 } 268 } 269 270 function thread_user($post_info) 271 { 272 if($post_info['user_name']) 273 { 274 return $post_info['user_name']; 275 } 276 else 277 { 278 $tmp = explode(".", $post_info['thread_user'], 2); 279 return $tmp[1]; 280 } 281 } 282 283 function untrack($thread_id, $from) 284 { 285 $thread_id = intval($thread_id); 286 global $sql; 287 $tmp = str_replace("-".$thread_id."-", "", USERREALM); 288 return $sql->db_Update("user", "user_realm='$tmp' WHERE user_id='".USERID."' "); 289 } 290 291 function track($thread_id, $from) 292 { 293 $thread_id = intval($thread_id); 294 global $sql; 295 return $sql->db_Update("user", "user_realm='".USERREALM."-".$thread_id."-' WHERE user_id='".USERID."' "); 296 } 297 298 function forum_get($forum_id) 299 { 300 $forum_id = intval($forum_id); 301 $qry = " 302 SELECT f.*, fp.forum_class as parent_class, fp.forum_name as parent_name, fp.forum_id as parent_id, fp.forum_postclass as parent_postclass, sp.forum_name AS sub_parent FROM #forum AS f 303 LEFT JOIN #forum AS fp ON fp.forum_id = f.forum_parent 304 LEFT JOIN #forum AS sp ON f.forum_sub = sp.forum_id AND f.forum_sub > 0 305 WHERE f.forum_id = {$forum_id} 306 "; 307 global $sql; 308 if ($sql->db_Select_gen($qry)) 309 { 310 return $sql->db_Fetch(); 311 } 312 return FALSE; 313 } 314 315 function forum_get_allowed() 316 { 317 global $sql; 318 $qry = " 319 SELECT f.forum_id, f.forum_name FROM #forum AS f 320 LEFT JOIN #forum AS fp ON fp.forum_id = f.forum_parent 321 WHERE f.forum_parent != 0 322 AND fp.forum_class IN (".USERCLASS_LIST.") 323 AND f.forum_class IN (".USERCLASS_LIST.") 324 "; 325 if ($sql->db_Select_gen($qry)) 326 { 327 while($row = $sql->db_Fetch()) 328 { 329 $ret[$row['forum_id']] = $row['forum_name']; 330 } 331 332 } 333 return $ret; 334 } 335 336 function thread_update($thread_id, $newvals) 337 { 338 global $sql, $tp; 339 foreach($newvals as $var => $val) 340 { 341 $var = $tp -> toDB($var); 342 $val = $tp -> toDB($val); 343 $newvalArray[] = "{$var} = '{$val}'"; 344 } 345 $newString = implode(', ', $newvalArray)." WHERE thread_id=".intval($thread_id); 346 return $sql->db_Update('forum_t', $newString); 347 } 348 349 function forum_get_topics($forum_id, $from, $view) 350 { 351 $forum_id = intval($forum_id); 352 global $sql; 353 $qry = " 354 SELECT t.*, u.user_name, lpu.user_name AS lastpost_username from #forum_t as t 355 LEFT JOIN #user AS u ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id 356 LEFT JOIN #user AS lpu ON SUBSTRING_INDEX(t.thread_lastuser,'.',1) = lpu.user_id 357 WHERE t.thread_forum_id = $forum_id AND t.thread_parent = 0 358 ORDER BY 359 t.thread_s DESC, 360 t.thread_lastpost DESC, 361 t.thread_datestamp DESC 362 LIMIT ".intval($from).",".intval($view)." 363 "; 364 $ret = array(); 365 if ($sql->db_Select_gen($qry)) 366 { 367 while ($row = $sql->db_Fetch()) 368 { 369 $ret[] = $row; 370 } 371 } 372 return $ret; 373 } 374 375 function thread_get_lastpost($forum_id) 376 { 377 $forum_id = intval($forum_id); 378 global $sql; 379 if ($sql->db_Count('forum_t', '(*)', "WHERE thread_parent = {$forum_id} ")) 380 { 381 $where = "WHERE t.thread_parent = $forum_id "; 382 } 383 else 384 { 385 $where = "WHERE t.thread_id = $forum_id "; 386 } 387 $qry = " 388 SELECT t.thread_user, t.thread_datestamp, u.user_name FROM #forum_t AS t 389 LEFT JOIN #user AS u ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id 390 {$where} 391 ORDER BY t.thread_datestamp DESC LIMIT 0,1 392 "; 393 if ($sql->db_Select_gen($qry)) 394 { 395 return $sql->db_Fetch(); 396 } 397 return FALSE; 398 } 399 400 function forum_get_topic_count($forum_id) 401 { 402 global $sql; 403 return $sql->db_Count("forum_t", "(*)", " WHERE thread_forum_id='".intval($forum_id)."' AND thread_parent='0' "); 404 } 405 406 function thread_getnext($thread_id, $forum_id, $from = 0, $limit = 100) 407 { 408 global $sql; 409 $forum_id = intval($forum_id); 410 global $sql; 411 $ftab = MPREFIX.'forum_t'; 412 while (!$found) 413 { 414 $qry = " 415 SELECT t.thread_id from #forum_t AS t 416 WHERE t.thread_forum_id = $forum_id 417 AND t.thread_parent = 0 418 ORDER BY 419 t.thread_s DESC, 420 t.thread_lastpost DESC, 421 t.thread_datestamp DESC 422 LIMIT ".intval($from).",".intval($limit); 423 if ($sql->db_Select_gen($qry)) 424 { 425 $i = 0; 426 while ($row = $sql->db_Fetch()) 427 { 428 $threadList[$i++] = $row['thread_id']; 429 } 430 431 if (($id = array_search($thread_id, $threadList)) !== FALSE) 432 { 433 if ($id != 99) 434 { 435 return $threadList[$id+1]; 436 } 437 else 438 { 439 return $this->thread_getnext($thread_id, $forum_id, $from+99, 2); 440 } 441 } 442 } 443 else 444 { 445 return FALSE; 446 } 447 $from += 100; 448 } 449 } 450 451 function thread_getprev($thread_id, $forum_id, $from = 0, $limit = 100) 452 { 453 global $sql; 454 $forum_id = intval($forum_id); 455 global $sql; 456 $ftab = MPREFIX.'forum_t'; 457 while (!$found) 458 { 459 $qry = " 460 SELECT t.thread_id from #forum_t AS t 461 WHERE t.thread_forum_id = $forum_id 462 AND t.thread_parent = 0 463 ORDER BY 464 t.thread_s DESC, 465 t.thread_lastpost DESC, 466 t.thread_datestamp DESC 467 LIMIT ".intval($from).",".intval($limit); 468 if ($sql->db_Select_gen($qry)) 469 { 470 $i = 0; 471 while ($row = $sql->db_Fetch()) 472 { 473 $threadList[$i++] = $row['thread_id']; 474 } 475 476 if (($id = array_search($thread_id, $threadList)) !== FALSE) 477 { 478 if ($id != 0) 479 { 480 return $threadList[$id-1]; 481 } 482 else 483 { 484 if ($from == 0) 485 { 486 return FALSE; 487 } 488 return $this->thread_getprev($thread_id, $forum_id, $from-1, 2); 489 } 490 } 491 } 492 else 493 { 494 return FALSE; 495 } 496 $from += 100; 497 } 498 } 499 500 function thread_get($thread_id, $start = 0, $limit = 10) 501 { 502 $thread_id = intval($thread_id); 503 global $sql; 504 $ftab = MPREFIX.'forum_t'; 505 $utab = MPREFIX.'user'; 506 507 if ($start === "last") 508 { 509 $tcount = $this->thread_count($thread_id); 510 $start = max(0, $tcount-$limit); 511 } 512 $start = max(0, $start); 513 if ($start != 0) 514 { 515 $array_start = 0; 516 } 517 else 518 { 519 $limit--; 520 $array_start = 1; 521 } 522 $sortdir = "ASC"; 523 524 $qry = " 525 SELECT t.*, u.*, ue.* FROM #forum_t as t 526 LEFT JOIN #user AS u 527 ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id 528 LEFT JOIN #user_extended AS ue 529 ON SUBSTRING_INDEX(t.thread_user,'.',1) = ue.user_extended_id 530 WHERE t.thread_parent = $thread_id 531 ORDER by t.thread_datestamp {$sortdir} 532 LIMIT ".intval($start).",".intval($limit); 533 $ret = array(); 534 if ($sql->db_Select_gen($qry)) 535 { 536 $i = $array_start; 537 while ($row = $sql->db_Fetch()) 538 { 539 $ret[$i] = $row; 540 $i++; 541 } 542 } 543 $qry = " 544 SELECT t.*,u.*,ue.* from #forum_t AS t 545 LEFT JOIN #user AS u 546 ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id 547 LEFT JOIN #user_extended AS ue 548 ON SUBSTRING_INDEX(t.thread_user,'.',1) = ue.user_extended_id 549 WHERE t.thread_id = $thread_id 550 LIMIT 0,1 551 "; 552 if ($sql->db_Select_gen($qry)) 553 { 554 $row = $sql->db_Fetch(); 555 $ret['head'] = $row; 556 if (!array_key_exists(0, $ret)) 557 { 558 $ret[0] = $row; 559 } 560 } 561 return $ret; 562 } 563 564 function thread_count($thread_id) 565 { 566 $thread_id = intval($thread_id); 567 global $sql; 568 return $sql->db_Count('forum_t', '(*)', "WHERE thread_parent = $thread_id")+1; 569 } 570 571 function thread_count_list($thread_list) 572 { 573 global $sql, $tp; 574 $qry = " 575 SELECT t.thread_parent, t.COUNT(*) as thread_replies 576 FROM #forum_t AS t 577 WHERE t.thread_parent 578 IN ".$tp -> toDB($thread_list, true)." 579 GROUP BY t.thread_parent 580 "; 581 if ($sql->db_Select_gen($qry)) 582 { 583 while ($row = $sql->db_Fetch()) 584 { 585 $ret[$row['thread_parent']] = $row['thread_replies']; 586 } 587 } 588 return $ret; 589 } 590 591 function thread_incview($thread_id) 592 { 593 $thread_id = intval($thread_id); 594 global $sql; 595 return $sql->db_Update("forum_t", "thread_views=thread_views+1 WHERE thread_id='$thread_id' "); 596 } 597 598 599 function thread_get_postinfo($thread_id, $head = FALSE) 600 { 601 $thread_id = intval($thread_id); 602 global $sql; 603 $ret = array(); 604 $qry = " 605 SELECT t.*, u.user_name, u.user_id, u.user_email from #forum_t AS t 606 LEFT JOIN #user AS u 607 ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id 608 WHERE t.thread_id = $thread_id 609 LIMIT 0,1 610 "; 611 if ($sql->db_Select_gen($qry)) 612 { 613 $ret[0] = $sql->db_Fetch(); 614 } 615 else 616 { 617 return FALSE; 618 } 619 if ($head == FALSE) 620 { 621 return $ret; 622 } 623 $parent_id = $ret[0]['thread_parent']; 624 if ($parent_id == 0) 625 { 626 $ret['head'] = $ret[0]; 627 } 628 else 629 { 630 $qry = " 631 SELECT t.*, u.user_name, u.user_id from #forum_t AS t 632 LEFT JOIN #user AS u 633 ON SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id 634 WHERE t.thread_id = ".intval($parent_id)." 635 LIMIT 0,1 636 "; 637 if ($sql->db_Select_gen($qry)) 638 { 639 $row = $sql->db_Fetch(); 640 $ret['head'] = $row; 641 } 642 } 643 return $ret; 644 } 645 646 647 function _forum_lp_update($lp_type, $lp_user, $lp_info, $lp_forum_id, $lp_forum_sub) 648 { 649 global $sql; 650 $sql->db_Update('forum', "{$lp_type}={$lp_type}+1, forum_lastpost_user='{$lp_user}', forum_lastpost_info = '{$lp_info}' WHERE forum_id='".intval($lp_forum_id)."' "); 651 if($lp_forum_sub) 652 { 653 $sql->db_Update('forum', "forum_lastpost_user = '{$lp_user}', forum_lastpost_info = '{$lp_info}' WHERE forum_id='".intval($lp_forum_sub)."' "); 654 } 655 } 656 657 function thread_insert($thread_name, $thread_thread, $thread_forum_id, $thread_parent, $thread_poster, $thread_active, $thread_s, $forum_sub) 658 { 659 $post_time = time(); 660 global $sql, $tp, $pref, $e107; 661 $forum_sub = intval($forum_sub); 662 $ip = $e107->getip(); 663 //Check for duplicate post 664 if ($sql->db_Count('forum_t', '(*)', "WHERE thread_thread='$thread_thread' and thread_datestamp > ".($post_time - 180))) 665 { 666 return -1; 667 } 668 669 $post_user = $thread_poster['post_userid'].".".$thread_poster['post_user_name']; 670 $thread_post_user = $post_user; 671 if($thread_poster['post_userid'] == 0) 672 { 673 $thread_post_user = $post_user.chr(1).$ip; 674 } 675 676 $post_last_user = ($thread_parent ? "" : $post_user); 677 $vals = "'0', '{$thread_name}', '{$thread_thread}', '".intval($thread_forum_id)."', '".intval($post_time)."', '".intval($thread_parent)."', '{$thread_post_user}', '0', '".intval($thread_active)."', '$post_time', '$thread_s', '0', '{$post_last_user}', '0'"; 678 $newthread_id = $sql->db_Insert('forum_t', $vals); 679 if(!$newthread_id) 680 { 681 echo "thread creation failed! <br /> 682 Values sent were: ".htmlentities($vals)."<br /><br />Please save these values for dev team for troubleshooting."; 683 exit; 684 } 685 686 // Increment user thread count and set user as viewed this thread 687 if (USER) 688 { 689 $new_userviewed = USERVIEWED.".".($thread_parent ? intval($thread_parent) : $newthread_id); 690 $sql->db_Update('user', "user_forums=user_forums+1, user_viewed='{$new_userviewed}' WHERE user_id='".USERID."' "); 691 } 692 693 //If post is a reply 694 if ($thread_parent) 695 { 696 $forum_lp_info = $post_time.".".intval($thread_parent); 697 $gen = new convert; 698 // Update main forum with last post info and increment reply count 699 $this->_forum_lp_update("forum_replies", $post_user, $forum_lp_info, $thread_forum_id, $forum_sub); 700 701 // Update head post with last post info and increment reply count 702 $sql->db_Update('forum_t', "thread_lastpost={$post_time}, thread_lastuser='{$post_user}', thread_total_replies=thread_total_replies+1 WHERE thread_id = ".intval($thread_parent)); 703 704 $parent_thread = $this->thread_get_postinfo($thread_parent); 705 global $PLUGINS_DIRECTORY; 706 $thread_name = $tp->toText($parent_thread[0]['thread_name']); 707 $datestamp = $gen->convert_date($post_time, "long"); 708 $email_post = $tp->toHTML($thread_thread, TRUE); 709 $mail_link = "<a href='".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last'>".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last</a>"; 710 if(!isset($pref['forum_eprefix'])) 711 { 712 $pref['forum_eprefix'] = "[forum]"; 713 } 714 // Send email to orinator of flagged 715 if ($parent_thread[0]['thread_active'] == 99 && $parent_thread[0]['user_id'] != USERID) 716 { 717 $gen = new convert; 718 $email_name = $parent_thread[0]['user_name']; 719 $message = LAN_384.SITENAME.".<br /><br />". LAN_382.$datestamp."<br />". LAN_94.": ".$thread_poster['post_user_name']."<br /><br />". LAN_385.$email_post."<br /><br />". LAN_383."<br /><br />".$mail_link; 720 include_once(e_HANDLER."mail.php"); 721 sendemail($parent_thread[0]['user_email'], $pref['forum_eprefix']." '".$thread_name."', ".LAN_381.SITENAME, $message); 722 } 723 724 // Send email to all users tracking thread 725 if ($sql->db_Select("user", "*", "user_realm REGEXP('-".intval($thread_parent)."-') ")) 726 { 727 include_once(e_HANDLER.'mail.php'); 728 $message = LAN_385.SITENAME.".<br /><br />". LAN_382.$datestamp."<br />". LAN_94.": ".$thread_poster['post_user_name']."<br /><br />". LAN_385.$email_post."<br /><br />". LAN_383."<br /><br />".$mail_link; 729 while ($row = $sql->db_Fetch()) 730 { 731 if ($row['user_email']) 732 { 733 sendemail($row['user_email'], $pref['forum_eprefix']." '".$thread_name."', ".LAN_381.SITENAME, $message); 734 } 735 } 736 } 737 } 738 else 739 { 740 //post is a new thread 741 $forum_lp_info = $post_time.".".$newthread_id; 742 $this->_forum_lp_update("forum_threads", $post_user, $forum_lp_info, $thread_forum_id, $forum_sub); 743 } 744 return $newthread_id; 745 } 746 747 function post_getnew($count = 50, $userviewed = USERVIEWED) 748 { 749 global $sql; 750 $viewed = ""; 751 if($userviewed) 752 { 753 $viewed = preg_replace("#\.+#", ".", $userviewed); 754 $viewed = preg_replace("#^\.#", "", $viewed); 755 $viewed = preg_replace("#\.$#", "", $viewed); 756 $viewed = str_replace(".", ",", $viewed); 757 } 758 if($viewed != "") 759 { 760 $viewed = " AND ft.thread_id NOT IN (".$viewed.")"; 761 } 762 763 $qry = " 764 SELECT ft.*, fp.thread_name as post_subject, fp.thread_total_replies as replies, u.user_id, u.user_name, f.forum_class 765 FROM #forum_t AS ft 766 LEFT JOIN #forum_t as fp ON fp.thread_id = ft.thread_parent 767 LEFT JOIN #user as u ON u.user_id = SUBSTRING_INDEX(ft.thread_user,'.',1) 768 LEFT JOIN #forum as f ON f.forum_id = ft.thread_forum_id 769 WHERE ft.thread_datestamp > ".USERLV. " 770 AND f.forum_class IN (".USERCLASS_LIST.") 771 {$viewed} 772 ORDER BY ft.thread_datestamp DESC LIMIT 0, ".intval($count); 773 if($sql->db_Select_gen($qry)) 774 { 775 $ret = $sql->db_getList(); 776 } 777 return $ret; 778 } 779 780 function forum_prune($type, $days, $forumArray) 781 { 782 global $sql; 783 $prunedate = time() - (intval($days) * 86400); 784 $forumList = implode(",", $forumArray); 785 786 if($type == 'delete') 787 { 788 //Get list of threads to prune 789 if ($sql->db_Select("forum_t", "thread_id", "thread_lastpost < $prunedate AND thread_parent=0 AND thread_s != 1 AND thread_forum_id IN ({$forumList})")) 790 { 791 $threadList = $sql->db_getList(); 792 foreach($threadList as $thread) 793 { 794 //Delete all replies 795 $reply_count += $sql->db_Delete("forum_t", "thread_parent='".intval($thread['thread_id'])."'"); 796 //Delete thread 797 $thread_count += $sql->db_Delete("forum_t", "thread_id = '".intval($thread['thread_id'])."'"); 798 //Delete poll if there is one 799 $sql->db_Delete("poll", "poll_datestamp='".intval($thread['thread_id']).""); 800 } 801 foreach($forumArray as $fid) 802 { 803 $this->update_lastpost('forum', $fid); 804 $this->forum_update_counts($fid); 805 } 806 return FORLAN_8." ( ".$thread_count." ".FORLAN_92.", ".$reply_count." ".FORLAN_93." )"; 807 } 808 else 809 { 810 return FORLAN_9; 811 } 812 } 813 else 814 { 815 $pruned = $sql->db_Update("forum_t", "thread_active=0 WHERE thread_lastpost < $prunedate AND thread_parent=0 AND thread_forum_id IN ({$forumList})"); 816 return FORLAN_8." ".$pruned." ".FORLAN_91; 817 } 818 } 819 820 function forum_update_counts($forumID, $recalc_threads = false) 821 { 822 global $sql; 823 if($forumID == 'all') 824 { 825 $sql->db_Select('forum', 'forum_id', 'forum_parent != 0'); 826 $flist = $sql->db_getList(); 827 foreach($flist as $f) 828 { 829 $this->forum_update_counts($f['forum_id']); 830 } 831 return; 832 } 833 $forumID = intval($forumID); 834 $threads = $sql->db_Count("forum_t", "(*)", "WHERE thread_forum_id=$forumID AND thread_parent = 0"); 835 $replies = $sql->db_Count("forum_t", "(*)", "WHERE thread_forum_id=$forumID AND thread_parent != 0"); 836 $sql->db_Update("forum", "forum_threads='$threads', forum_replies='$replies' WHERE forum_id='$forumID'"); 837 if($recalc_threads == true) 838 { 839 $sql->db_Select("forum_t", "thread_parent, count(*) as replies", "thread_forum_id = $forumID GROUP BY thread_parent"); 840 $tlist = $sql->db_getList(); 841 foreach($tlist as $t) 842 { 843 $tid = $t['thread_parent']; 844 $replies = intval($t['replies']); 845 $sql->db_Update("forum_t", "thread_total_replies='$replies' WHERE thread_id='$tid'"); 846 } 847 } 848 } 849 850 function get_user_counts() 851 { 852 global $sql; 853 $qry = " 854 SELECT u.user_id AS uid, count(t.thread_user) AS cnt FROM #forum_t AS t 855 LEFT JOIN #user AS u on SUBSTRING_INDEX(t.thread_user,'.',1) = u.user_id 856 WHERE u.user_id > 0 857 GROUP BY uid 858 "; 859 860 if($sql->db_Select_gen($qry)) 861 { 862 $ret = array(); 863 while($row = $sql->db_Fetch()) 864 { 865 $ret[$row['uid']] = $row['cnt']; 866 } 867 return $ret; 868 } 869 return FALSE; 870 } 871 872 /* 873 * set bread crumb 874 * $forum_href override ONLY applies when template is missing FORUM_CRUMB 875 * $thread_title is needed for post-related breadcrumbs 876 */ 877 function set_crumb($forum_href=FALSE,$thread_title="") 878 { 879 global $FORUM_CRUMB,$forum_info,$thread_info,$tp; 880 global $BREADCRUMB,$BACKLINK; // Eventually we should deprecate BACKLINK 881 882 if(is_array($FORUM_CRUMB)) 883 { 884 $search = array("{SITENAME}", "{SITENAME_HREF}"); 885 $replace = array(SITENAME, "href='".e_BASE."index.php'"); 886 $FORUM_CRUMB['sitename']['value'] = str_replace($search, $replace, $FORUM_CRUMB['sitename']['value']); 887 888 $search = array("{FORUMS_TITLE}", "{FORUMS_HREF}"); 889 $replace = array(LAN_01, "href='".e_PLUGIN."forum/forum.php'"); 890 $FORUM_CRUMB['forums']['value'] = str_replace($search, $replace, $FORUM_CRUMB['forums']['value']); 891 892 $search = "{PARENT_TITLE}"; 893 $replace = $tp->toHTML($forum_info['parent_name']); 894 $FORUM_CRUMB['parent']['value'] = str_replace($search, $replace, $FORUM_CRUMB['parent']['value']); 895 896 if($forum_info['sub_parent']) 897 { 898 $search = array("{SUBPARENT_TITLE}", "{SUBPARENT_HREF}"); 899 $forum_sub_parent = (substr($forum_info['sub_parent'], 0, 1) == "*" ? substr($forum_info['sub_parent'], 1) : $forum_info['sub_parent']); 900 $replace = array($forum_sub_parent, "href='".e_PLUGIN."forum/forum_viewforum.php?{$forum_info['forum_sub']}'"); 901 $FORUM_CRUMB['subparent']['value'] = str_replace($search, $replace, $FORUM_CRUMB['subparent']['value']); 902 } 903 else 904 { 905 $FORUM_CRUMB['subparent']['value'] = ""; 906 } 907 908 $search = array("{FORUM_TITLE}", "{FORUM_HREF}"); 909 $tmpFname = $forum_info['forum_name']; 910 if(substr($tmpFname, 0, 1) == "*") { $tmpFname = substr($tmpFname, 1); } 911 $replace = array($tmpFname,"href='".e_PLUGIN."forum/forum_viewforum.php?{$forum_info['forum_id']}'"); 912 $FORUM_CRUMB['forum']['value'] = str_replace($search, $replace, $FORUM_CRUMB['forum']['value']); 913 914 if(strlen($thread_title)) 915 { 916 $search = array("{THREAD_TITLE}"); 917 $replace = array($thread_title); 918 $FORUM_CRUMB['thread']['value'] = str_replace($search, $replace, $FORUM_CRUMB['thread']['value']); 919 } 920 else 921 { 922 $FORUM_CRUMB['thread']['value'] = ""; 923 } 924 925 $FORUM_CRUMB['fieldlist'] = "sitename,forums,parent,subparent,forum,thread"; 926 $BREADCRUMB = $tp->parseTemplate("{BREADCRUMB=FORUM_CRUMB}", true); 927 928 } 929 else 930 { 931 $dfltsep = " :: "; 932 $BREADCRUMB = "<a class='forumlink' href='".e_BASE."index.php'>".SITENAME."</a>".$dfltsep."<a class='forumlink' href='".e_PLUGIN."forum/forum.php'>".LAN_01."</a>".$dfltsep; 933 if($forum_info['sub_parent']) 934 { 935 $forum_sub_parent = (substr($forum_info['sub_parent'], 0, 1) == "*" ? substr($forum_info['sub_parent'], 1) : $forum_info['sub_parent']); 936 $BREADCRUMB .= "<a class='forumlink' href='".e_PLUGIN."forum/forum_viewforum.php?{$forum_info['forum_sub']}'>{$forum_sub_parent}</a>".$dfltsep; 937 } 938 939 $tmpFname = $forum_info['forum_name']; 940 if(substr($tmpFname, 0, 1) == "*") { $tmpFname = substr($tmpFname, 1); } 941 if ($forum_href) 942 { 943 $BREADCRUMB .= "<a class='forumlink' href='".e_PLUGIN."forum/forum_viewforum.php?{$forum_info['forum_id']}'>".$tp->toHTML($tmpFname, TRUE, 'no_hook,emotes_off')."</a>"; 944 } else 945 { 946 $BREADCRUMB .= $tmpFname; 947 } 948 949 if(strlen($thread_title)) 950 { 951 $BREADCRUMB .= $dfltsep.$thread_title; 952 } 953 } 954 $BACKLINK = $BREADCRUMB; 955 } 956 } 957 958 959 /** 960 * @return string path to and filename of forum icon image 961 * 962 * @param string $filename filename of forum image 963 * @param string $eMLANG_folder if specified, indicates its a multilanguage image being processed and 964 * gives the subfolder of the image path to the eMLANG_path() function, 965 * default = FALSE 966 * @param string $eMLANG_pref if specified, indicates that $filename may be overridden by the 967 * $pref with $eMLANG_pref as its key if that pref is TRUE, default = FALSE 968 * 969 * @desc checks for the existence of a forum icon image in the themes forum folder and if it is found 970 * returns the path and filename of that file, otherwise it returns the path and filename of the 971 * default forum icon image in e_IMAGES. The additional $eMLANG args if specfied switch the process 972 * to the sister multi-language function eMLANG_path(). 973 * 974 * @access public 975 */ 976 function img_path($filename) 977 { 978 global $pref; 979 980 $multilang = array("reply.png","newthread.png","moderator.png","main_admin.png","admin.png"); 981 $ML = (in_array($filename,$multilang)) ? TRUE : FALSE; 982 983 if(file_exists(THEME.'forum/'.$filename) || is_readable(THEME.'forum/'.e_LANGUAGE."_".$filename)) 984 { 985 $image = ($ML && is_readable(THEME.'forum/'.e_LANGUAGE."_".$filename)) ? THEME.'forum/'.e_LANGUAGE."_".$filename : THEME.'forum/'.$filename; 986 } 987 else 988 { 989 if(defined("IMODE")) 990 { 991 if($ML) 992 { 993 $image = (is_readable(e_PLUGIN."forum/images/".IMODE."/".e_LANGUAGE."_".$filename)) ? e_PLUGIN."forum/images/".IMODE."/".e_LANGUAGE."_".$filename : e_PLUGIN."forum/images/".IMODE."/English_".$filename; 994 } 995 else 996 { 997 $image = e_PLUGIN."forum/images/".IMODE."/".$filename; 998 } 999 } 1000 else 1001 { 1002 if($ML) 1003 { 1004 $image = (is_readable(e_PLUGIN."forum/images/lite/".e_LANGUAGE."_".$filename)) ? e_PLUGIN."forum/images/lite/".e_LANGUAGE."_".$filename : e_PLUGIN."forum/images/lite/English_".$filename; 1005 } 1006 else 1007 { 1008 $image = e_PLUGIN."forum/images/lite/".$filename; 1009 } 1010 1011 } 1012 } 1013 1014 return $image; 1015 } 1016 1017 1018 1019 1020 if (file_exists(THEME.'forum/forum_icons_template.php')) 1021 { 1022 require_once(THEME.'forum/forum_icons_template.php'); 1023 } 1024 else if (file_exists(THEME.'forum_icons_template.php')) 1025 { 1026 require_once(THEME.'forum_icons_template.php'); 1027 } 1028 else 1029 { 1030 require_once(e_PLUGIN.'forum/templates/forum_icons_template.php'); 1031 } 1032 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |