1<?php 2/* 3 * e107 website system 4 * 5 * Copyright (C) 2008-2014 e107 Inc (e107.org) 6 * Released under the terms and conditions of the 7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) 8 * 9 * Forum View Topic 10 * 11*/ 12 13if(!defined('e107_INIT')) 14{ 15 require_once('../../class2.php'); 16} 17 18e107::lan('forum', "front", true); 19 20if(!deftrue('BOOTSTRAP')) 21{ 22 $bcDefs = array( 23 'LAN_413' => 'LAN_FORUM_2046', 24 'LAN_400' => 'LAN_EDIT', 25 'LAN_401' => 'LAN_FORUM_2041', 26 'LAN_406' => 'LAN_EDIT', 27 'LAN_435' => 'LAN_DELETE', 28 'LAN_397' => 'LAN_FORUM_2044', 29 'LAN_398' => 'LAN_FORUM_4007' 30 31 ); 32 33 e107::getLanguage()->bcDefs($bcDefs); 34} 35 36 37define('NAVIGATION_ACTIVE','forum'); 38 39$e107 = e107::getInstance(); 40$tp = e107::getParser(); 41$ns = e107::getRender(); 42 43if (!e107::isInstalled('forum')) 44{ 45 e107::redirect(); 46 exit; 47} 48 49//---- orphan $highlight_search?????? 50$highlight_search = isset($_POST['highlight_search']); 51 52if (!e_QUERY) 53{ 54 //No parameters given, redirect to forum home 55 $url = e107::url('forum','index','full'); 56 e107::getRedirect()->go($url); 57 exit; 58} 59 60include_once(e_PLUGIN.'forum/forum_class.php'); 61 62$forum = new e107forum(); 63$thread = new e107ForumThread(); 64 65// check if user wants to download a file 66if(vartrue($_GET['id']) && isset($_GET['dl'])) 67{ 68 $forum->sendFile($_GET); 69 exit; 70} 71 72if (isset($_GET['last'])) 73{ 74 $_GET['f'] = 'last'; 75} 76 77if(isset($_GET['f']) && $_GET['f'] == 'post') 78{ 79 $thread->processFunction(); 80} 81 82$thread->init(); 83 84 85/* Check if use has moderator permissions for this thread */ 86$moderatorUserIds = $forum->getModeratorUserIdsByThreadId($thread->threadInfo['thread_id']); 87define('MODERATOR', (USER && in_array(USERID, $moderatorUserIds))); 88 89 90if(e_AJAX_REQUEST) 91{ 92 if(varset($_POST['action']) == 'quickreply') 93 { 94 $forum->ajaxQuickReply(); 95 } 96 97 if(varset($_POST['action']) == 'track') 98 { 99 $forum->ajaxTrack(); 100 } 101 102 if(MODERATOR) 103 { 104 $forum->ajaxModerate(); 105 } 106 else if(varset($_POST['action']) == 'deletepost') 107 { 108 $forum->usersLastPostDeletion(); 109 } 110} 111 112 113/* 114if(isset($_POST['track_toggle'])) 115{ 116 $thread->toggle_track(); 117 exit; 118}*/ 119 120 121 122if(!empty($_GET['f'])) 123{ 124 $retext = $thread->processFunction(); 125 126 if($retext) 127 { 128 require_once(HEADERF); 129 // e107::getMessage()->addWarning($retext); 130 // echo e107::getmessage()->render(); 131 echo $retext; 132 require_once(FOOTERF); 133 exit; 134 } 135 136 if($_GET['f'] != 'last') { $thread->init(); } 137} 138 139 140//---- getScBatch here?????? 141e107::getScBatch('view', 'forum')->setScVar('thread', $thread); 142 143//---- orphan $pm_installed?????? 144$pm_installed = e107::isInstalled('pm'); 145 146//Only increment thread views if not being viewed by thread starter 147if (USER && (USERID != $thread->threadInfo['thread_user'] || $thread->threadInfo['thread_total_replies'] > 0) || !$thread->noInc) 148{ 149 $forum->threadIncview($thread->threadInfo['thread_id']); 150} 151 152define('e_PAGETITLE', strip_tags($tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off')).' / '.$tp->toHTML($thread->threadInfo['forum_name'], true, 'no_hook, emotes_off').' / '.LAN_FORUM_1001); 153 154$forum->modArray = $forum->forumGetMods($thread->threadInfo['forum_moderators']); 155 156 157e107::getScBatch('view', 'forum')->setScVar('forum', $forum); 158//var_dump(e107::getScBatch('forum', 'forum')); 159 160 161if(MODERATOR && isset($_POST['mod'])) 162{ 163 require_once(e_PLUGIN."forum/forum_mod.php"); 164 $thread->message = forum_thread_moderate($_POST); 165 $thread->threadInfo = $forum->threadGet($thread->threadId); 166} 167 168$num = $thread->page ? $thread->page - 1 : 0; 169$postList = $forum->PostGet($thread->threadId, $num * $thread->perPage, $thread->perPage); 170 171// SEO - meta description (auto) 172if(count($postList)) 173{ 174 define("META_DESCRIPTION", $tp->text_truncate( 175 str_replace( 176 //array('"', "'"), '', strip_tags($tp->toHTML($postList[0]['post_entry'])) 177 array('"', "'"), '', $tp->toText($postList[0]['post_entry']) 178 ), 250, '...')); 179} 180 181//---- Orphan $gen???? 182$gen = new convert; 183if($thread->message) 184{ 185 //$ns->tablerender('', $thread->message, array('forum_viewtopic', 'msg')); 186 e107::getMessage()->add($thread->message); 187} 188 189 190 191//if (isset($thread->threadInfo['thread_options']['poll'])) //XXX Currently Failing - misconfigured thread-options. 192//{ 193if(e107::isInstalled('poll')) 194{ 195 $_qry = 'SELECT p.*, u.user_id, u.user_name FROM `#polls` AS p LEFT JOIN `#user` AS u ON p.poll_admin_id = u.user_id WHERE p.poll_datestamp = ' . $thread->threadId; 196 if($sql->gen($_qry)) 197 { 198 if (!defined('POLLCLASS')) 199 { 200 include_once(e_PLUGIN . 'poll/poll_class.php'); 201 } 202 $poll = new poll; 203 $pollstr = "<div class='spacer'>" . $poll->render_poll($_qry, 'forum', 'query', true) . '</div>'; 204 } 205} 206//} 207 208//Load forum templates 209// FIXME - new template paths! 210if(file_exists(THEME.'forum_design.php')) // legacy file 211{ 212 include_once (THEME.'forum_design.php'); 213} 214 215 216 217// New in v2.x 218if(THEME_LEGACY !== true) 219{ 220 $FORUM_VIEWTOPIC_TEMPLATE = e107::getTemplate('forum','forum_viewtopic'); 221 222 // print_a($FORUM_VIEWTOPIC_TEMPLATE); 223 224 $FORUMCAPTION = $FORUM_VIEWTOPIC_TEMPLATE['caption']; 225 $FORUMSTART = $FORUM_VIEWTOPIC_TEMPLATE['start']; 226 $FORUMTHREADSTYLE = $FORUM_VIEWTOPIC_TEMPLATE['thread']; 227 $FORUMEND = $FORUM_VIEWTOPIC_TEMPLATE['end']; 228 $FORUMREPLYSTYLE = $FORUM_VIEWTOPIC_TEMPLATE['replies']; 229 $FORUMDELETEDSTYLE = $FORUM_VIEWTOPIC_TEMPLATE['deleted']; 230} 231else 232{ 233 if (empty($FORUMSTART)) 234 { 235 if(file_exists(THEME.'forum_viewtopic_template.php')) 236 { 237 require_once(THEME.'forum_viewtopic_template.php'); 238 } 239 elseif(file_exists(THEME.'templates/forum/forum_viewtopic_template.php')) 240 { 241 require_once(THEME.'templates/forum/forum_viewtopic_template.php'); 242 } 243 elseif(file_exists(THEME.'forum_template.php')) 244 { 245 require_once(THEME.'forum_template.php'); 246 } 247 else 248 { 249 require_once(e_PLUGIN.'forum/templates/forum_viewtopic_template.php'); 250 } 251 } 252 253} 254 255//TODO Clean up this mess!! 256 257// get info for main thread ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 258//---- Moved here to enclose $tVars..... 259$sc = e107::getScBatch('view', 'forum'); 260 261//---- $tVars = new e_vars; 262//---- $forum->set_crumb(true, '', $tVars); // Set $BREADCRUMB (and BACKLINK) 263$forum->set_crumb(true, '', $thread->threadInfo); // Set $BREADCRUMB (and BACKLINK) 264//$tVars->BREADCRUMB = $crumbs['breadcrumb']; 265//$tVars->BACKLINK = $tVars->BREADCRUMB; 266//$tVars->FORUM_CRUMB = $crumbs['forum_crumb']; 267//---- $tVars->THREADNAME = $tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off'); 268 269 270/*---- 271 $prev = $forum->threadGetNextPrev('prev', $thread->threadId,$thread->threadInfo['forum_id'], $thread->threadInfo['thread_lastpost']); 272 $next = $forum->threadGetNextPrev('next', $thread->threadId,$thread->threadInfo['forum_id'], $thread->threadInfo['thread_lastpost']); 273 274 $options = array(); 275 276 if($prev !== false) 277 { 278 $options[] = "<a class='btn btn-default btn-sm btn-small' href='" . e107::url('forum','topic', $prev) . "'>« " . LAN_FORUM_2001 . "</a>"; 279 } 280 if($next !== false) 281 { 282 $options[] = "<a class='btn btn-default btn-sm btn-small' href='" . e107::url('forum','topic', $next) . "'>" . LAN_FORUM_2002 . " »</a>"; 283 } 284 285 $tVars->NEXTPREV = implode(" | ", $options); 286----*/ 287 288/* 289$tVars->NEXTPREV = "<a class='btn btn-default btn-sm btn-small' href='" . $e107->url->create('forum/thread/prev', array('id' => $thread->threadId)) . "'>« " . LAN_FORUM_2001 . "</a>"; 290$tVars->NEXTPREV .= ' | '; // enabled to make it look better on v1 templates 291$tVars->NEXTPREV .= "<a class='btn btn-default btn-sm btn-small' href='" . $e107->url->create('forum/thread/prev', array('id' => $thread->threadId)) . "'>" . LAN_FORUM_2002 . " »</a>"; 292*/ 293 294/*---- 295if ($forum->prefs->get('track') && USER) 296{ 297 // BC Fix for old template. 298 if(!defined('IMAGE_track')) 299 { 300 define('IMAGE_track', '<img src="'.img_path('track.png').'" alt="'.LAN_FORUM_4009.'" title="'.LAN_FORUM_4009.'" class="icon S16 action" />'); 301 } 302 303 if(!defined('IMAGE_untrack')) 304 { 305 define('IMAGE_untrack', '<img src="'.img_path('untrack.png').'" alt="'.LAN_FORUM_4010.'" title="'.LAN_FORUM_4010.'" class="icon S16 action" />'); 306 } 307 308 309 $img = ($thread->threadInfo['track_userid'] ? IMAGE_track : IMAGE_untrack); 310 311 312/* 313 $url = $e107->url->create('forum/thread/view', array('id' => $thread->threadId), 'encode=0'); // encoding could break AJAX call 314 315 $url = e107::url('forum','index'); 316 317 $tVars->TRACK .= " 318 <span id='forum-track-trigger-container'> 319 <a class='btn btn-default btn-sm btn-small e-ajax' data-target='forum-track-trigger' href='{$url}' id='forum-track-trigger'>{$img}</a> 320 </span> 321 <script type='text/javascript'> 322 e107.runOnLoad(function(){ 323 $('forum-track-trigger').observe('click', function(e) { 324 e.stop(); 325 new e107Ajax.Updater('forum-track-trigger-container', '{$url}', { 326 method: 'post', 327 parameters: { //send query parameters here 328 'track_toggle': 1 329 }, 330 overlayPage: $(document.body) 331 }); 332 }); 333 }, document, true); 334 </script> 335 ";*/ 336 337 338/*---- 339 $trackDiz = ($forum->prefs->get('trackemail',true)) ? LAN_FORUM_3040 : LAN_FORUM_3041; 340 341 $tVars->TRACK = "<a id='forum-track-button' href='#' title=\"".$trackDiz."\" data-token='".deftrue('e_TOKEN','')."' data-forum-insert='forum-track-button' data-forum-post='".$thread->threadInfo['thread_forum_id']."' data-forum-thread='".$thread->threadInfo['thread_id']."' data-forum-action='track' name='track' class='e-tip btn btn-default' >".$img."</a> 342"; 343 344} 345----*/ 346 347/*---- 348$modUser = array(); 349foreach ( $forum->modArray as $user) 350{ 351 $modUser[] = "<a href='".e107::getUrl()->create('user/profile/view', $user)."'>".$user['user_name']."</a>"; 352} 353 354$tVars->MODERATORS = LAN_FORUM_2003.": ". implode(', ', $modUser); 355unset($modUser); 356----*/ 357 358//---- $tVars->THREADSTATUS = (!$thread->threadInfo['thread_active'] ? LAN_FORUM_2004 : ''); 359 360/*---- 361if ($thread->pages > 1) 362{ 363 if(!$thread->page) $thread->page = 1; 364// $url = rawurlencode(e107::getUrl()->create('forum/thread/view', array('name' => $thread->threadInfo['thread_name'], 'id' => $thread->threadId, 'page' => '[FROM]'))); 365 366// $url = e_REQUEST_SELF."?p=[FROM]"; // SEF URL Friendly. 367 $url = e107::url('forum','topic', $thread->threadInfo)."&p=[FROM]"; 368 369 $parms = "total={$thread->pages}&type=page¤t={$thread->page}&url=".urlencode($url)."&caption=off&tmpl=default&navcount=4&glyphs=1"; 370 371 //XXX FIXME - pull-down template not practical here. Can we force another? 372 373 $tVars->GOTOPAGES = $tp->parseTemplate("{NEXTPREV={$parms}}"); 374/* 375 $parms = ($thread->pages).",1,{$thread->page},url::forum::thread::func=view&id={$thread->threadId}&page=[FROM],off"; 376 $tVars->GOTOPAGES = $tp->parseTemplate("{NEXTPREV={$parms}}"); 377} 378----*/ 379 380/*---- 381$tVars->BUTTONS = ''; 382if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'post') && $thread->threadInfo['thread_active']) 383{ 384 // print_a($thread->threadInfo); 385 $url = e107::url('forum','post')."?f=rp&id=".$thread->threadInfo['thread_id']."&post=".$thread->threadId; 386// $url = $e107->url->create('forum/thread/reply', array('id' => $thread->threadId)); 387 $tVars->BUTTONS .= "<a href='" . $url . "'>" . IMAGE_reply . "</a>"; 388} 389if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'thread')) 390{ 391 $ntUrl = e107::url('forum','post')."?f=nt&id=". $thread->threadInfo['thread_forum_id']; 392// $ntUrl = $e107->url->create('forum/thread/new', array('id' => $thread->threadInfo['thread_forum_id'])); 393 $tVars->BUTTONS .= "<a href='" . $ntUrl . "'>" . IMAGE_newthread . "</a>"; 394} 395----*/ 396/*---- 397$tVars->BUTTONSX = forumbuttons($thread); 398 399function forumbuttons($thread) 400{ 401 global $forum; 402 403 404 if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'post') && $thread->threadInfo['thread_active']) 405 { 406 $url = e107::url('forum','post')."?f=rp&id=".$thread->threadInfo['thread_id']."&post=".$thread->threadId; 407 // $url = e107::getUrl()->create('forum/thread/reply', array('id' => $thread->threadId)); 408 $replyUrl = "<a class='btn btn-primary' href='".$url."'>".LAN_FORUM_2006."</a>"; 409 } 410 if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'thread')) 411 { 412 $ntUrl = e107::url('forum','post')."?f=nt&id=". $thread->threadInfo['thread_forum_id']; 413 // $ntUrl = e107::getUrl()->create('forum/thread/new', array('id' => $thread->threadInfo['thread_forum_id'])); 414 $options[] = " <a href='".$ntUrl."'>".LAN_FORUM_2005."</a>"; 415 } 416 417// $options[] = "<a href='" . e107::getUrl()->create('forum/thread/prev', array('id' => $thread->threadId)) . "'>".LAN_FORUM_1017." ".LAN_FORUM_2001."</a>"; 418// $options[] = "<a href='" . e107::getUrl()->create('forum/thread/prev', array('id' => $thread->threadId)) . "'>".LAN_FORUM_1017." ".LAN_FORUM_2002."</a>"; 419 420 $prev = $forum->threadGetNextPrev('prev', $thread->threadId,$thread->threadInfo['forum_id'], $thread->threadInfo['thread_lastpost']); 421 $next = $forum->threadGetNextPrev('next', $thread->threadId,$thread->threadInfo['forum_id'], $thread->threadInfo['thread_lastpost']); 422 423 if($prev !== false) 424 { 425 $options[] = "<a href='" . e107::url('forum','topic', $prev) . "'>".LAN_FORUM_1017." ".LAN_FORUM_2001."</a>"; 426 } 427 if($next !== false) 428 { 429 $options[] = "<a href='" . e107::url('forum','topic', $next) . "'>".LAN_FORUM_1017." ".LAN_FORUM_2002."</a>"; 430 } 431 432 433 $text = '<div class="btn-group"> 434 '.$replyUrl.' 435 <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> 436 <span class="caret"></span> 437 </button> 438 <ul class="dropdown-menu pull-right"> 439 '; 440 441 foreach($options as $key => $val) 442 { 443 $text .= '<li>'.$val.'</li>'; 444 } 445 446 $jumpList = $forum->forumGetAllowed(); 447 448 $text .= "<li class='divider'></li>"; 449 450 foreach($jumpList as $key=>$val) 451 { 452 $text .= '<li><a href ="'.e107::url('forum','forum',$val).'">'.LAN_FORUM_1017." ".$val['forum_name'].'</a></li>'; 453 } 454 455 $text .= ' 456 </ul> 457 </div>'; 458 459 460 return $text; 461 462} 463----*/ 464 465 466//---- $tVars->POLL = vartrue($pollstr); 467 468//---- $tVars->FORUMJUMP = forumjump(); 469 470//---- $tVars->MESSAGE = $thread->message; 471 472 $sc->setVars($thread->threadInfo); 473 $sc->setScVar('threadInfo', $thread->threadInfo); 474//$forum->set_crumb(true, '', $sc); // Set $BREADCRUMB (and BACKLINK) 475 476//---- $forstr = $tp->simpleParse($FORUMSTART, $tVars); 477 $forstr = $tp->parseTemplate($FORUMSTART, true, $sc); 478 479unset($forrep); 480if (!$FORUMREPLYSTYLE) $FORUMREPLYSTYLE = $FORUMTHREADSTYLE; 481$alt = false; 482 483$i = $thread->page; 484 485//---- Moved upwards, to enclose $tVars... 486//---- $sc = e107::getScBatch('view', 'forum'); 487 488 $mes = e107::getMessage(); 489// $sc->setVars($thread->threadInfo); 490//--->$forend = $tp->simpleParse($FORUMEND, $tVars); 491$sc->wrapper('forum_viewtopic/end'); 492$forend = $tp->parseTemplate($FORUMEND, true, $sc); 493 494$lastPostDetectionCounter = count($postList); 495$sc->setScVar('thisIsTheLastPost', false); 496 497foreach ($postList as $c => $postInfo) 498{ 499 if($postInfo['post_options']) 500 { 501 $postInfo['post_options'] = unserialize($postInfo['post_options']); 502 } 503 $loop_uid = (int)$postInfo['post_user']; 504 505 $lastPostDetectionCounter--; 506 if ($lastPostDetectionCounter == 0) $sc->setScVar('thisIsTheLastPost', true); 507 508//---- Orphan $tnum???? 509 $tnum = $i; 510 511 $i++; 512 513 //TODO: Look into fixing this, to limit to a single query per pageload 514 $threadId = $thread->threadInfo['thread_id']; 515 $e_hide_query = "SELECT post_id FROM `#forum_post` WHERE (`post_thread` = {$threadId} AND post_user= " . USERID . ' LIMIT 1'; 516 $e_hide_hidden = LAN_FORUM_2008; 517 $e_hide_allowed = USER; 518 519 520 $sc->wrapper('forum_viewtopic/replies'); // default. 521 522 if($thread->page ==1 && $c == 0) 523 { 524 $postInfo['thread_start'] = true; 525 $sc->setScVar('postInfo', $postInfo); 526 $sc->setVars($postInfo); // compatibility 527 $sc->wrapper('forum_viewtopic/thread'); 528 529 // $forum_shortcodes = e107::getScBatch('view', 'forum')->setScVar('postInfo', $postInfo)->wrapper('forum/viewtopic'); 530 $forthr = $tp->parseTemplate($FORUMTHREADSTYLE, true, $sc) . "\n"; 531 532 } 533 else 534 { 535 536 $postInfo['thread_start'] = false; 537 $alt = !$alt; 538 539 $sc->setScVar('postInfo', $postInfo); 540 $sc->setVars($postInfo); // compatibility 541 542 if($postInfo['post_status']) 543 { 544 $_style = (isset($FORUMDELETEDSTYLE_ALT) && $alt ? $FORUMDELETEDSTYLE_ALT : $FORUMDELETEDSTYLE); 545 $sc->wrapper('forum_viewtopic/deleted'); 546 } 547 else 548 { 549 $_style = (isset($FORUMREPLYSTYLE_ALT) && $alt ? $FORUMREPLYSTYLE_ALT : $FORUMREPLYSTYLE); 550 $sc->wrapper('forum_viewtopic/replies'); 551 } 552 553 // $forum_shortcodes = e107::getScBatch('view', 'forum')->setScVar('postInfo', $postInfo)->wrapper('forum/viewtopic'); 554 $forrep .= $tp->parseTemplate($_style, true, $sc) . "\n"; 555 556 } 557 558 559 560} 561unset($loop_uid); 562 563/*----> 564if ($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'post') && $thread->threadInfo['thread_active']) 565{ 566 //XXX Show only on the last page?? 567 if (!vartrue($forum_quickreply)) 568 { 569 $ajaxInsert = ($thread->pages == $thread->page || $thread->pages == 0) ? 1 : 0; 570 // $ajaxInsert = 1; 571 // echo "AJAX-INSERT=".$ajaxInsert ."(".$thread->pages." vs ".$thread->page.")"; 572 $frm = e107::getForm(); 573 574 $urlParms = array('f'=>'rp','id'=>$thread->threadInfo['thread_id'], 'post'=>$thread->threadInfo['thread_id']); 575 $url = e107::url('forum','post', null, array('query'=>$urlParms));; // ."?f=rp&id=".$thread->threadInfo['thread_id']."&post=".$thread->threadInfo['thread_id']; 576 577 $tVars->QUICKREPLY = " 578 <form action='" . $url . "' method='post'> 579 <div class='form-group'> 580 <textarea cols='80' placeholder='".LAN_FORUM_2007."' rows='4' id='forum-quickreply-text' class='tbox input-xxlarge form-control' name='post' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'></textarea> 581 </div> 582 <div class='center text-center form-group'> 583 <input type='submit' data-token='".e_TOKEN."' data-forum-insert='".$ajaxInsert."' data-forum-post='".$thread->threadInfo['thread_forum_id']."' data-forum-thread='".$threadId."' data-forum-action='quickreply' name='reply' value='".LAN_FORUM_2006. "' class='btn btn-success button' /> 584 <input type='hidden' name='thread_id' value='".$threadId."' /> 585 </div> 586 587 </form>"; 588 589 if(E107_DEBUG_LEVEL > 0) 590 { 591 // echo "<div class='alert alert-info'>Thread id: ".$threadId."</div>"; 592 // print_a($this); 593 } 594 595 596 597 // Preview should be reserved for the full 'Post reply' page. <input type='submit' name='fpreview' value='" . Preview . "' /> 598 } 599 else 600 { 601 $tVars->QUICKREPLY = $forum_quickreply; 602 } 603} 604<----*/ 605 606/*---> 607 $mes = e107::getMessage(); 608 $sc->setVars($thread->threadInfo); 609//--->$forend = $tp->simpleParse($FORUMEND, $tVars); 610$forend = $tp->parseTemplate($FORUMEND, true, $sc); 611<---*/ 612$forumstring = $forstr . $forthr . vartrue($forrep) . $forend; 613 614//If last post came after USERLV and not yet marked as read, mark the thread id as read 615//---- Orphan $currentUser??? 616$threadsViewed = explode(',', $currentUser['user_plugin_forum_viewed']); 617 618if ($thread->threadInfo['thread_lastpost'] > USERLV && !in_array($thread->threadId, $threadsViewed)) 619{ 620 $tst = $forum->threadMarkAsRead($thread->threadId); 621 $mes->addDebug("Marking Forum as read: ".$thread->threadId." result: ".$tst); 622} 623else 624{ 625 $ret = array('lastpost'=>$thread->threadInfo['thread_lastpost'], 'lastvisit'=>USERLV, 'thread'=>$thread->threadId, 'viewed'=>$threadsViewed); 626 e107::getDebug()->log($ret); 627 unset($ret); 628} 629 630 631require_once (HEADERF); 632 633 634if ($forum->prefs->get('enclose')) 635{ 636 $forumTitle = empty($FORUMCAPTION) ? e107::pref('forum','title', LAN_PLUGIN_FORUM_NAME) : $tp->parseTemplate($FORUMCAPTION, true, $sc); 637 $ns->tablerender($forumTitle, $mes->render().$forumstring, 'forum-viewtopic'); 638} 639else 640{ 641 echo $mes->render() . $forumstring; 642} 643 644// end ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 645 646echo "<script type=\"text/javascript\"> 647 function confirm_(mode, forum_id, thread_id, thread) { 648 if (mode == 'Thread') { 649 return confirm(\"" . $tp->toJS(LAN_FORUM_2009) . "\"); 650 } else { 651 return confirm(\"" . $tp->toJS(LAN_FORUM_2010) . " [ " . $tp->toJS(LAN_FORUM_0074) . " \" + thread + \" ]\"); 652 } 653 } 654 </script>"; 655require_once (FOOTERF); 656 657function showmodoptions() 658{ 659 global $thread, $postInfo; 660 661 $e107 = e107::getInstance(); 662//---- Orphan $forum_id???? 663 $forum_id = $thread->threadInfo['forum_id']; 664 if ($postInfo['thread_start']) 665 { 666 667 $type = 'Thread'; 668 // XXX _URL_ thread name? 669 // $formUrl = $e107->url->create('forum/thread/view', array('id' => $postInfo['post_thread'])); 670 $formUrl = e_REQUEST_URI; // e107::url('forum', 'topic', 671 $ret = "<form method='post' action='" . $formUrl."' id='frmMod_{$postInfo['post_forum']}_{$postInfo['post_thread']}'>"; 672 $delId = $postInfo['post_thread']; 673 } 674 else 675 { 676 $type = 'Post'; 677 $ret = "<form method='post' action='" . e_SELF . '?' . e_QUERY . "' id='frmMod_{$postInfo['post_thread']}_{$postInfo['post_id']}'>"; 678 $delId = $postInfo['post_id']; 679 } 680 681 $editQRY = array('f'=>'edit', 'id'=>$postInfo['post_thread'], 'post'=>$postInfo['post_id']); 682 $editURL = e107::url('forum','post','', array('query'=> $editQRY)); 683// $e107->url->create('forum/thread/edit', array('id' => $postInfo['post_id'])) 684 $ret .= " 685 <div> 686 <a class='e-tip' href='" . $editURL."' title=\"".LAN_EDIT."\">" . IMAGE_admin_edit . "</a> 687 <input type='image' " . IMAGE_admin_delete . " name='delete{$type}_{$delId}' value='thread_action' onclick=\"return confirm_('{$type}', {$postInfo['post_forum']}, {$postInfo['post_thread']}, '{$postInfo['user_name']}')\" /> 688 <input type='hidden' name='mod' value='1'/> 689 "; 690 if ($type == 'Thread') 691 { 692 $moveUrl = e107::url('forum','move', array('thread_id'=>$postInfo['post_thread'])); 693 $ret .= "<a href='" . $moveUrl."'>" . IMAGE_admin_move2 . "</a>"; 694 } 695 else 696 { 697 // $splitUrl = $e107->url->create('forum/thread/split', array('id' => $postInfo['post_id'])); 698 $splitUrl = e107::url('forum','split', array('thread_id'=>$postInfo['post_thread'], 'post_id'=>$postInfo['post_id'])); 699 $ret .= "<a href='" .$splitUrl ."'>" . defset('IMAGE_admin_split') . '</a>'; 700 701 } 702 $ret .= " 703 </div> 704 </form>"; 705 return $ret; 706} 707 708/*---- 709function forumjump() 710{ 711 global $forum; 712 $jumpList = $forum->forumGetAllowed(); 713 $text = "<form method='post' action='".e_SELF."'><p>".LAN_FORUM_1017.": <select name='forumjump' class='tbox'>"; 714 foreach ($jumpList as $key => $val) 715 { 716 $text .= "\n<option value='" . e107::url('forum','forum',$val) . "'>" . $val['forum_name'] . "</option>"; 717 } 718 $text .= "</select> <input class='btn btn-default button' type='submit' name='fjsubmit' value='" . LAN_GO . "' /></p></form>"; 719 return $text; 720} 721----*/ 722function rpg($user_join, $user_forums) 723{ 724 global $FORUMTHREADSTYLE; 725 if (strpos($FORUMTHREADSTYLE, '{RPG}') === false) 726 { 727 return ''; 728 } 729 // rpg mod by Ikari ( kilokan1@yahoo.it | http://artemanga.altervista.org ) 730 731 $lvl_post_mp_cost = 2.5; 732 $lvl_mp_regen_per_day = 4; 733 $lvl_avg_ppd = 5; 734 $lvl_bonus_redux = 5; 735 $lvl_user_days = max(1, round((time() - $user_join) / 86400)); 736 $lvl_ppd = $user_forums / $lvl_user_days; 737 if ($user_forums < 1) 738 { 739 $lvl_level = 0; 740 } 741 else 742 { 743 $lvl_level = floor(pow(log10($user_forums), 3)) + 1; 744 } 745 if ($lvl_level < 1) 746 { 747 $lvl_hp = "0 / 0"; 748 $lvl_hp_percent = 0; 749 } 750 else 751 { 752 $lvl_max_hp = floor((pow($lvl_level, (1 / 4))) * (pow(10, pow($lvl_level + 2, (1 / 3)))) / (1.5)); 753 754 if ($lvl_ppd >= $lvl_avg_ppd) 755 { 756 $lvl_hp_percent = floor((.5 + (($lvl_ppd - $lvl_avg_ppd) / ($lvl_bonus_redux * 2))) * 100); 757 } 758 else 759 { 760 $lvl_hp_percent = floor($lvl_ppd / ($lvl_avg_ppd / 50)); 761 } 762 if ($lvl_hp_percent > 100) 763 { 764 $lvl_max_hp += floor(($lvl_hp_percent - 100) * pi()); 765 $lvl_hp_percent = 100; 766 } 767 else 768 { 769 $lvl_hp_percent = max(0, $lvl_hp_percent); 770 } 771 $lvl_cur_hp = floor($lvl_max_hp * ($lvl_hp_percent / 100)); 772 $lvl_cur_hp = max(0, $lvl_cur_hp); 773 $lvl_cur_hp = min($lvl_max_hp, $lvl_cur_hp); 774 $lvl_hp = $lvl_cur_hp . '/' . $lvl_max_hp; 775 } 776 if ($lvl_level < 1) 777 { 778 $lvl_mp = '0 / 0'; 779 $lvl_mp_percent = 0; 780 } 781 else 782 { 783 $lvl_max_mp = floor((pow($lvl_level, (1 / 4))) * (pow(10, pow($lvl_level + 2, (1 / 3)))) / (pi())); 784 $lvl_mp_cost = $user_forums * $lvl_post_mp_cost; 785 $lvl_mp_regen = max(1, $lvl_user_days * $lvl_mp_regen_per_day); 786 $lvl_cur_mp = floor($lvl_max_mp - $lvl_mp_cost + $lvl_mp_regen); 787 $lvl_cur_mp = max(0, $lvl_cur_mp); 788 $lvl_cur_mp = min($lvl_max_mp, $lvl_cur_mp); 789 $lvl_mp = $lvl_cur_mp . '/' . $lvl_max_mp; 790 $lvl_mp_percent = floor($lvl_cur_mp / $lvl_max_mp * 100); 791 } 792 if ($lvl_level < 1) 793 { 794 $lvl_exp = "0 / 0"; 795 $lvl_exp_percent = 100; 796 } 797 else 798 { 799 $lvl_posts_for_next = floor(pow(10, pow($lvl_level, (1 / 3)))); 800 if ($lvl_level == 1) 801 { 802 $lvl_posts_for_this = max(1, floor(pow(10, (($lvl_level - 1))))); 803 } 804 else 805 { 806 $lvl_posts_for_this = max(1, floor(pow(10, pow(($lvl_level - 1), (1 / 3))))); 807 } 808 $lvl_exp = ($user_forums - $lvl_posts_for_this) . "/" . ($lvl_posts_for_next - $lvl_posts_for_this); 809 $lvl_exp_percent = floor((($user_forums - $lvl_posts_for_this) / max(1, ($lvl_posts_for_next - $lvl_posts_for_this))) * 100); 810 } 811 812 $bar_image = THEME . "images/bar.jpg"; 813 if (!is_readable($bar_image)) 814 { 815 $bar_image = e_PLUGIN . "forum/images/" . IMODE . "/bar.jpg"; 816 } 817 818 $rpg_info = "<div style='padding:2px; white-space:nowrap'>"; 819 $rpg_info .= "<b>Level = " . $lvl_level . "</b><br />"; 820 $rpg_info .= "HP = " . $lvl_hp . "<br /><img src='{$bar_image}' alt='' style='border:#345487 1px solid; height:10px; width:" . $lvl_hp_percent . "%'><br />"; 821 $rpg_info .= "EXP = " . $lvl_exp . "<br /><img src='{$bar_image}' alt='' style='border:#345487 1px solid; height:10px; width:" . $lvl_exp_percent . "%'><br />"; 822 $rpg_info .= "MP = " . $lvl_mp . "<br /><img src='{$bar_image}' alt='' style='border:#345487 1px solid; height:10px; width:" . $lvl_mp_percent . "%'><br />"; 823 $rpg_info .= "</div>"; 824 return $rpg_info; 825} 826 827class e107ForumThread 828{ 829 830 public $message; 831 public $threadId; 832 public $forumId; 833 public $perPage; 834 public $noInc; 835 public $pages; 836 public $page; 837 838 839 function init() 840 { 841 global $forum; 842 $e107 = e107::getInstance(); 843 $this->threadId = (int)varset($_GET['id']); 844 $this->perPage = (varset($_GET['perpage']) ? (int)$_GET['perpage'] : $forum->prefs->get('postspage')); 845 $this->page = (varset($_GET['p']) ? (int)$_GET['p'] : 1); 846 847 848 if(!$this->threadId && e_QUERY) //BC Links fix. 849 { 850 list($id,$page) = explode(".",e_QUERY); 851 $this->threadId = intval($id); 852 $this->page = intval($page); 853 } 854 855 856 //If threadId doesn't exist, or not given, redirect to main forum page 857 if (!$this->threadId || !$this->threadInfo = $forum->threadGet($this->threadId)) 858 { 859 if(E107_DEBUG_LEVEL > 0) 860 { 861 e107::getMessage()->addError("Thread not found or query error: ". __METHOD__ .' Line: '.__LINE__ ); 862 return; 863 // exit; 864 } 865 866 $url = e107::url('forum','index','full'); 867 e107::getRedirect()->go($url); 868 869 // header('Location:' . $e107->url->create('forum/forum/main', array(), 'encode=0&full=1')); 870 exit; 871 } 872 873 //If not permitted to view forum, redirect to main forum page 874 if (!$forum->checkPerm($this->threadInfo['thread_forum_id'], 'view')) 875 { 876 877 if(E107_DEBUG_LEVEL > 0) 878 { 879 echo __METHOD__ .' Line: '.__LINE__; 880 exit; 881 } 882 $url = e107::url('forum','index','full'); 883 e107::getRedirect()->go($url); 884 885 // header('Location:' . $e107->url->create('forum/forum/main', array(), 'encode=0&full=1')); 886 exit; 887 } 888 889 $totalPosts = $this->threadInfo['thread_total_replies'] + 1; // add +1 for the original post. ie. not a reply. 890 $this->pages = ceil(($totalPosts) / $this->perPage); 891 $this->noInc = false; 892 } 893 894/* 895 896 function toggle_track() 897 { 898 global $forum, $thread; 899 $e107 = e107::getInstance(); 900 if (!USER || !isset($_GET['id'])) { return; } 901 if($thread->threadInfo['track_userid']) 902 { 903 $forum->track('del', USERID, $_GET['id']); 904 $img = IMAGE_untrack; 905 } 906 else 907 { 908 $forum->track('add', USERID, $_GET['id']); 909 $img = IMAGE_track; 910 } 911 if(e_AJAX_REQUEST) 912 { 913 $url = $e107->url->create('forum/thread/view', array('name' => $this->threadInfo['thread_name'], 'id' => $thread->threadId)); 914 echo "<a href='{$url}' id='forum-track-trigger'>{$img}</a>"; 915 exit(); 916 } 917 } 918*/ 919 920 /** 921 * @return bool|null|string|void 922 */ 923 function processFunction() 924 { 925 926 927 928 global $forum, $thread; 929 // $e107 = e107::getInstance(); 930 $ns = e107::getRender(); 931 $sql = e107::getDb(); 932 $tp = e107::getParser(); 933//Orphan $frm variable???? $frm = e107::getForm(); 934 935 if (empty($_GET['f'])) 936 { 937 return; 938 } 939 940 $function = trim($_GET['f']); 941 switch ($function) 942 { 943 case 'post': 944 $postId = varset($_GET['id']); 945 $postInfo = $forum->postGet($postId,'post'); 946 $postNum = $forum->postGetPostNum($postInfo['post_thread'], $postId); 947 $postPage = ceil($postNum / $forum->prefs->get('postspage')); 948 949 $url = e107::url('forum', 'topic', $postInfo, array( 950 'query' => array( 951 'p' => $postPage, // proper page number 952 ), 953 'fragment' => 'post-' . $postId, // jump page to post 954 'mode'=>'full' 955 )); 956 957 e107::redirect($url); 958 exit; 959 break; 960 961 case 'last': 962 $pages = ceil(($thread->threadInfo['thread_total_replies'] + 1) / $thread->perPage); 963 $thread->page = $_GET['p'] = $pages; 964 break; 965 966/* // Now linked directly - no more redirect. 967 case 'next': 968 $next = $forum->threadGetNextPrev('next', $this->threadId, $this->threadInfo['forum_id'], $this->threadInfo['thread_lastpost']); 969 if ($next) 970 { 971 $url = e107::getUrl()->create('forum/thread/view', array('id' => $next), array('encode' => false, 'full' => 1)); // no thread name info at this time 972 header("location: {$url}"); 973 exit; 974 } 975 $this->message = LAN_FORUM_2013; 976 break; 977 978 case 'prev': 979 $prev = $forum->threadGetNextPrev('prev', $this->threadId, $this->threadInfo['forum_id'], $this->threadInfo['thread_lastpost']); 980 if ($prev) 981 { 982 $url = e107::getUrl()->create('forum/thread/view', array('id' => $prev), array('encode' => false, 'full' => 1));// no thread name info at this time 983 header("location: {$url}"); 984 exit; 985 } 986 $this->message = LAN_FORUM_2012; 987 break; 988*/ 989 990 // Moved to form_post.php 991 /* 992 case 'report': 993 $threadId = (int)$_GET['id']; 994 $postId = (int)$_GET['post']; 995 $postInfo = $forum->postGet($postId, 'post'); 996 997 if(!empty($_POST['report_thread'])) 998 { 999 $report_add = $tp->toDB($_POST['report_add']); 1000 1001 if($forum->prefs->get('reported_post_email')) 1002 { 1003 require_once(e_HANDLER.'mail.php'); 1004 $report = LAN_FORUM_2018." ".SITENAME." : ".(substr(SITEURL, -1) == "/" ? SITEURL : SITEURL."/") . $e107->getFolder('plugins') . "forum/forum_viewtopic.php?" . $this->threadId . ".post\n 1005 ".LAN_FORUM_2019.": ".USERNAME. "\n" . $report_add; 1006 $subject = LAN_FORUM_2020." ". SITENAME; 1007 sendemail(SITEADMINEMAIL, $subject, $report); 1008 } 1009 // no reference of 'head' $threadInfo['head']['thread_name'] 1010 1011 $insert = array( 1012 'gen_id' => 0, 1013 'gen_type' => 'reported_post', 1014 'gen_datestamp' => time(), 1015 'gen_user_id' => USERID, 1016 'gen_ip' => $tp->toDB($postInfo['thread_name']), 1017 'gen_intdata' => intval($this->threadId), 1018 'gen_chardata' => $report_add, 1019 1020 1021 1022 ); 1023 1024 $url = e107::getUrl()->create('forum/thread/post', array('id' => $postId, 'name' => $postInfo['thread_name'], 'thread' => $threadId)); // both post info and thread info contain thread name 1025 1026 $result = $sql->insert('generic', $insert); 1027 1028 if($result) 1029 { 1030 $text = "<div class='alert alert-block alert-success'><h4>".LAN_FORUM_2021 . "</h4><a href='{$url}'>".LAN_FORUM_2022.'</a></div>'; 1031 } 1032 else 1033 { 1034 $text = "<div class='alert alert-block alert-error'><h4>".LAN_FORUM_2021 . "</h4><a href='{$url}'>".LAN_FORUM_2022.'</a></div>'; 1035 } 1036 1037 define('e_PAGETITLE', LAN_FORUM_1001 . " / " . LAN_FORUM_2021); 1038 1039 return $ns->tablerender(LAN_FORUM_2023, $text, array('forum_viewtopic', 'report'), true); 1040 } 1041 else 1042 { 1043 $thread_name = e107::getParser()->toHTML($postInfo['thread_name'], true, 'no_hook, emotes_off'); 1044 define('e_PAGETITLE', LAN_FORUM_1001.' / '.LAN_FORUM_2024.': '.$thread_name); 1045 $url = e107::getUrl()->create('forum/thread/post', array('id' => $postId, 'name' => $postInfo['thread_name'], 'thread' => $threadId)); 1046 $actionUrl = e107::getUrl()->create('forum/thread/report', "id={$threadId}&post={$postId}"); 1047 1048 1049 if(deftrue('BOOTSTRAP')) //v2.x 1050 { 1051 $text = $frm->open('forum-report-thread','post'); 1052 $text .= " 1053 <div> 1054 <div class='alert alert-block alert-warning'> 1055 <h4>".LAN_FORUM_2025.': '.$thread_name."</h4> 1056 ".LAN_FORUM_2027."<br />".str_replace(array('[', ']'), array('<b>', '</b>'), LAN_FORUM_2028)." 1057 <a class='pull-right btn btn-xs btn-primary e-expandit' href='#post-info'>View Post</a> 1058 </div> 1059 <div id='post-info' class='e-hideme alert alert-block alert-danger'> 1060 ".$tp->toHTML($postInfo['post_entry'],true)." 1061 </div> 1062 <div class='form-group' > 1063 <div class='col-md-12'> 1064 ".$frm->textarea('report_add','',10,35,array('size'=>'xxlarge'))." 1065 </div> 1066 </div> 1067 <div class='form-group'> 1068 <div class='col-md-12'> 1069 ".$frm->button('report_thread',1,'submit',LAN_FORUM_2029)." 1070 </div> 1071 </div> 1072 1073 </div>"; 1074 1075 $text .= $frm->close(); 1076 // $text .= print_a($postInfo['post_entry'],true); 1077 1078 } 1079 else //v1.x legacy layout. 1080 { 1081 $text = "<form action='".$actionUrl."' method='post'> 1082 <table class='table' style='width:100%'> 1083 <tr> 1084 <td style='width:50%'> 1085 ".LAN_FORUM_2025.': '.$thread_name." <a href='".$url."'><span class='smalltext'>".LAN_FORUM_2026."</span></a> 1086 </td> 1087 <td style='text-align:center;width:50%'></td> 1088 </tr> 1089 <tr> 1090 <td>".LAN_FORUM_2027."<br />".str_replace(array('[', ']'), array('<b>', '</b>'), LAN_FORUM_2028)."</td> 1091 </tr> 1092 <tr> 1093 <td style='text-align:center;'><textarea cols='40' rows='10' class='tbox' name='report_add'></textarea></td> 1094 </tr> 1095 <tr> 1096 <td colspan='2' style='text-align:center;'><br /><input class='btn btn-default button' type='submit' name='report_thread' value='".LAN_FORUM_2029."' /></td> 1097 </tr> 1098 </table> 1099 </form>"; 1100 1101 1102 1103 } 1104 1105 1106 return e107::getRender()->tablerender(LAN_FORUM_2023, $text, array('forum_viewtopic', 'report2'), true); 1107 } 1108 1109 exit; 1110 break;*/ 1111 1112 } 1113 } 1114} 1115 1116 1117