1<?php 2 /** 3 * e107 website system 4 * 5 * Copyright (C) 2008-2016 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 */ 10 11 12 13// news rewrite for v2.x 14 15 16if (!defined('e107_INIT')) 17{ 18 require_once("../../class2.php"); 19} 20 21 22class news_front 23{ 24 25 private $action = null; 26 private $subAction = null; 27 private $route = null; 28 private $defaultTemplate = ''; 29 private $cacheString = 'news.php_default_'; 30 private $from = 0; 31 private $order = 'news_datestamp'; 32 private $nobody_regexp = ''; 33 private $ix = null; 34 private $newsUrlparms = array(); 35 private $text = null; 36 private $pref = array(); 37 private $debugInfo = array(); 38 private $cacheRefreshTime = false; 39 private $caption = null; 40 private $templateKey = null; 41 42 private $currentRow = array(); 43 private $dayMonth = null; 44 private $tagAuthor = null; 45 private $comments = array(); 46// private $interval = 1; 47 48 function __construct() 49 { 50 global $NEWSHEADER; 51 52 e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_'.e_PAGE); 53 e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_news.php'); // Temporary 54 e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_comment.php'); // Temporary 55 56 $this->pref = e107::getPref(); 57 58 $this->cacheRefreshTime = vartrue($this->pref['news_cache_timeout'],false); 59 // $this->interval = $this->pref['newsposts']-$this>pref['newsposts_archive']; 60 61 require_once(e_HANDLER."news_class.php"); 62 63 if(isset($NEWSHEADER)) 64 { 65 return false; 66 } 67 68 $this->nobody_regexp = "'(^|,)(".str_replace(",", "|", e_UC_NOBODY).")(,|$)'"; 69 $this->ix = new news; 70 71 $this->setConstants(); 72 $this->setActions(); 73 $this->setRoute(); 74 $this->detect(); 75 $this->setBreadcrumb(); 76 77 return null; 78 } 79 80 81 private function setBreadcrumb() 82 { 83 84 $breadcrumb = array(); 85 86 $breadcrumb[] = array('text'=> PAGE_NAME, 'url'=>e107::url('news', 'index')); 87 88 $categoryName = e107::getParser()->toHTML($this->currentRow['category_name'],true, 'TITLE'); 89 90 switch($this->route) 91 { 92 case "news/list/all": 93 case "news/list/item": 94 $breadcrumb[0]['url'] = null; 95 break; 96 97 case "news/view": 98 99 $itemName = e107::getParser()->toHTML($this->currentRow['news_title'],true, 'TITLE'); 100 101 $breadcrumb[] = array('text'=> $categoryName, 'url'=>e107::getUrl()->create('news/list/category', $this->currentRow)); 102 $breadcrumb[] = array('text'=> $itemName, 'url'=> null); 103 break; 104 105 106 case 'news/list/category': 107 case 'news/list/short': 108 $breadcrumb[] = array('text'=> $categoryName, 'url'=>null); 109 break; 110 111 case 'news/list/tag': 112 $breadcrumb[] = array('text'=> defset('LAN_NEWS_309', "Tag"), 'url'=>null); 113 $breadcrumb[] = array('text'=> $this->tagAuthor, 'url'=>null); 114 break; 115 116 117 case 'news/list/author': 118 $breadcrumb[] = array('text'=> LAN_AUTHOR, 'url'=>null); 119 $breadcrumb[] = array('text'=> $this->tagAuthor, 'url'=>null); 120 break; 121 122 case 'news/list/month': 123 case 'news/list/day': 124 $breadcrumb[] = array('text'=> LAN_DATE, 'url'=>null); 125 $breadcrumb[] = array('text' => $this->dayMonth, 'url'=>null); 126 break; 127 128 default: 129 if(ADMIN) 130 { 131 $breadcumb[] = array('text'=> "Missing News breadcrumb for route: ".$this->route); 132 } 133 break; 134 } 135 136 e107::breadcrumb($breadcrumb); 137 138 } 139 140 141 private function detect() 142 { 143 144 if ($this->action === 'cat' || $this->action === 'all' || $this->action === 'tag' || $this->action === 'author') 145 { // --> Cache 146 $this->text = $this->renderListTemplate(); 147 $this->text .= $this->render_newscats(); 148 return null; 149 } 150 151 if ($this->action == 'extend') 152 { // --> Cache 153 $this->text = $this->renderViewTemplate(); 154 $this->text .= $this->render_newscats(); 155 return null; 156 } 157 158 if(!empty($this->pref['nfp_display']) && intval($this->pref['nfp_display']) === 1) // top position 159 { 160 $this->text .= $this->renderNewForumPosts(); 161 } 162 163 $this->text .= $this->renderDefaultTemplate(); 164 165 if(!empty($this->pref['nfp_display']) && intval($this->pref['nfp_display']) === 2) // bottom position 166 { 167 $this->text .= $this->renderNewForumPosts(); 168 } 169 170 $this->text .= $this->show_newsarchive(); 171 $this->text .= $this->render_newscats(); 172 return null; 173 174 } 175 176 177 /** 178 * BC replacement for newforumposts_main 179 * @return string 180 */ 181 private function renderNewForumPosts() 182 { 183 if(deftrue('THEME_LEGACY') && !empty($this->pref['nfp_display'])) 184 { 185 $parms = array('layout'=>'main', 'display'=>$this->pref['nfp_amount']); 186 187 if(!empty($this->pref['nfp_layer']) && !empty($this->pref['nfp_layer_height'])) 188 { 189 $parms['scroll'] = $this->pref['nfp_layer_height']; 190 } 191 192 return e107::getMenu()->renderMenu('forum','newforumposts_menu', $parms, true); 193 } 194 195 } 196 197 198 199 private function getRenderId() 200 { 201 $tmp = explode('/',$this->route); 202 203 if(!empty($this->templateKey)) 204 { 205 $tmp[] = $this->templateKey; 206 } 207 208 $unique = implode('-',$tmp); 209 210 return $unique; 211 212 } 213 214 215 /** 216 * When the template contains a 'caption' - tablerender() is used, otherwise a simple echo is used. 217 * @return bool 218 */ 219 public function render($return = false) 220 { 221 222 $unique = $this->getRenderId(); 223 224 if($this->caption !== null) 225 { 226 227 228 $this->addDebug("tablerender ID", $unique); 229 230 231 232 e107::getRender()->setUniqueId($unique)->tablerender($this->caption, $this->text, 'news'); 233 234 if(!empty($this->comments)) 235 { 236 echo $this->renderComments($this->comments); 237 } 238 239 return true; 240 } 241 242 243 $this->addDebug("tablerender ID (not used)", $unique); 244 245 echo $this->text; 246 247 if(!empty($this->comments)) 248 { 249 echo $this->renderComments($this->comments); 250 } 251 } 252 253 private function setActions() 254 { 255 256 $this->defaultTemplate = e107::getPref('news_default_template'); 257 258 $opt = array('default'=>'', 'list'=>'all'); 259 260 if (e_QUERY) //TODO add support for $_GET['cat'] and $_GET['mode'] and phase-out the x.x.x format. 261 { 262 263 $tmp = explode(".",e_QUERY); 264 $action = $tmp[0]; // At least one parameter here 265 $sub_action = varset($tmp[1],''); // Usually a numeric category, or numeric news item number, but don't presume yet 266 // $id = varset($tmp[2],''); // ID of specific news item where required 267 $this->from = intval(varset($tmp[2],0)); // Item number for first item on multi-page lists 268 $this->cacheString = 'news.php_'.e_QUERY; 269 270 if($action === 'default') 271 { 272 $action = $action = varset($opt[$this->defaultTemplate],''); 273 } 274 } 275 else 276 { 277 278 $action = varset($opt[$this->defaultTemplate],''); 279 $sub_action = ''; 280 $tmp = array(); 281 282 } 283 284 //$newsfrom = (!is_numeric($action) || !e_QUERY ? 0 : ($action ? $action : e_QUERY)); 285 286 // Usually the first query parameter is the action. 287 // For any of the 'list' modes (inc month, day), the action being second is a legacy situation 288 // .... which can hopefully go sometime 289 //SecretR: Gone, gone... 290 if (is_numeric($action) && isset($tmp[1]) && (($tmp[1] == 'list') || ($tmp[1] == 'month') || ($tmp[1] == 'day'))) 291 { 292 $action = $tmp[1]; 293 $sub_action = varset($tmp[0],''); 294 } 295 296 297 298 if ($action == 'all' || $action == 'cat') 299 { 300 $sub_action = intval(varset($tmp[1],0)); 301 } 302 303 if(!empty($_GET['tag'])) 304 { 305 $action = 'tag'; 306 $sub_action = $_GET['tag']; 307 } 308 309 if(!empty($_GET['author'])) 310 { 311 $action = 'author'; 312 $sub_action = $_GET['author']; 313 } 314 315 $this->action = $action; 316 $this->subAction= e107::getParser()->filter($sub_action); 317 318 if(defined('NEWS_LAYOUT')) 319 { 320 $this->templateKey = NEWS_LAYOUT; 321 } 322 323 324 } 325 326 327 private function setRoute() 328 { 329 $this->newsUrlparms = array('page' => '--FROM--'); 330 if($this->subAction) 331 { 332 333 switch ($this->action) 334 { 335 case 'list': 336 $this->newsUrlparms['id'] = $this->subAction; 337 $newsRoute = 'list/category'; 338 break; 339 340 case 'cat': 341 $this->newsUrlparms['id'] = $this->subAction; 342 $newsRoute = 'list/short'; 343 break; 344 345 case 'day': 346 case 'month': 347 $this->newsUrlparms['id'] = $this->subAction; 348 $newsRoute = 'list/'.$this->action; 349 break; 350 351 default: 352 $newsRoute = 'list/items'; 353 break; 354 } 355 } 356 elseif($this->action == 'all') 357 { 358 $newsRoute = 'list/all'; 359 $this->newsUrlparms['id'] = $this->subAction; 360 } 361 else 362 { 363 $newsRoute = 'list/items'; 364 } 365 366 367 368 $this->route = 'news/'.$newsRoute; 369 370 $tp = e107::getParser(); 371 372 if(vartrue($_GET['tag']) || substr($this->action,0,4) == 'tag=') 373 { 374 375 $this->route = 'news/list/tag'; 376 if(!vartrue($_GET['tag'])) 377 { 378 list($this->action,$word) = explode("=",$this->action,2); 379 $_GET['tag'] = $word; 380 unset($word,$tmp); 381 } 382 383 $this->newsUrlparms['tag'] = $tp->filter($_GET['tag']); 384 $this->from = intval(varset($_GET['page'],0)); 385 } 386 387 if(!empty($_GET['author']) || substr($this->action,0,4) == 'author=') 388 { 389 390 $this->route = 'news/list/author'; 391 if(!vartrue($_GET['author'])) 392 { 393 list($action,$author) = explode("=",$this->action,2); 394 $_GET['author'] = $author; 395 unset($author,$tmp); 396 } 397 398 $this->newsUrlparms['author'] = $tp->filter($_GET['author']); 399 $this->from = intval(varset($_GET['page'],0)); 400 401 } 402 } 403 404 405 private function setConstants() 406 { 407 408 409 if (!defined('ITEMVIEW')) 410 { 411 define('ITEMVIEW', varset($this->pref['newsposts'],15)); 412 } 413 414 // ?all and ?cat.x and ?tag are the same listing functions - just filtered differently. 415 // NEWSLIST_LIMIT is suitable for all 416 417 if(!defined("NEWSLIST_LIMIT")) 418 { 419 define("NEWSLIST_LIMIT", varset($this->pref['news_list_limit'],15)); 420 } 421 422 423 } 424 425 public function debug() 426 { 427 echo "<div class='alert alert-info'>"; 428 echo "<h4>News Debug Info</h4>"; 429 echo "<table class='table table-striped table-bordered'>"; 430 echo "<tr><td><b>action:</b></td><td>".$this->action."</td></tr>"; 431 echo "<tr><td><b>subaction:</b></td><td>".$this->subAction."</td></tr>"; 432 echo "<tr><td><b>route:</b></td><td>".$this->route."</td></tr>"; 433 echo "<tr><td><b>e_QUERY:</b></td><td>".e_QUERY."</td></tr>"; 434 echo "<tr><td><b>e_PAGETITLE:</b></td><td>".defset('e_PAGETITLE','(unassigned)')."</td></tr>"; 435 echo "<tr><td><b>PAGE_NAME:</b></td><td>".defset('PAGE_NAME','(unassigned)')."</td></tr>"; 436 echo "<tr><td><b>CacheTimeout:</b></td><td>".$this->cacheRefreshTime."</td></tr>"; 437 echo "<tr><td><b>_GET:</b></td><td>".print_r($_GET,true)."</td></tr>"; 438 439 foreach($this->debugInfo as $key=>$val) 440 { 441 echo "<tr><td><b>".$key.":</b></td><td>".$val."</tr>"; 442 } 443 444 echo "</table></div>"; 445 446 447 } 448 449 450 private function addDebug($key,$message) 451 { 452 if(is_array($message)) 453 { 454 $this->debugInfo[$key] = print_a($message,true); 455 } 456 else 457 { 458 $this->debugInfo[$key] = $message; 459 } 460 461 } 462 463 // ----------- old functions ------------------------ 464 465 466 private function show_newsarchive() 467 { 468 469 // do not show the news archive on the news.php?item.X page (but only on the news mainpage) 470 if(empty($this->defaultTemplate) || !empty($this->action) || empty($this->pref['newsposts_archive'])) 471 { 472 return null; 473 } 474 475 476 global $NEWSARCHIVE; 477 478 $sql = e107::getDb(); 479 $tp = e107::getParser(); 480 $ns = e107::getRender(); 481 482 $query = $this->getQuery(); 483 484 if($newsarchive = $this->checkCache('newsarchive')) 485 { 486 $this->addDebug("News Archive Cache", 'active'); 487 return $newsarchive; 488 } 489 490 $newsAr = array(); 491 492 if ($sql->gen($query)) 493 { 494 $newsAr = $sql -> db_getList(); 495 } 496 497 $i = $this->interval; 498 499 500 // require_once(e_CORE.'shortcodes/batch/news_archives.php'); 501 $sc = e107::getScBatch('news_archive'); 502 503 if(!$NEWSARCHIVE) 504 { 505 $NEWSARCHIVE ="<div> 506 <table style='width:100%;'> 507 <tr> 508 <td> 509 <div>{ARCHIVE_BULLET} <b>{ARCHIVE_LINK}</b> <span class='smalltext'><i>{ARCHIVE_AUTHOR} @ ({ARCHIVE_DATESTAMP}) ({ARCHIVE_CATEGORY})</i></span></div> 510 </td> 511 </tr> 512 </table> 513 </div>"; 514 } 515 516 $text = ''; 517 518 foreach($newsAr as $row) 519 { 520 $sc->setVars($row); 521 $text .= $tp->parseTemplate($NEWSARCHIVE, FALSE, $sc); 522 } 523 524 525 526 $ret = $ns->tablerender($this->pref['newsposts_archive_title'], $text, 'news_archive', true); 527 528 $this->setNewsCache('newsarchive', $ret); 529 530 return $ret; 531 532 } 533 534 535 private function setNewsFrontMeta($news, $type='news') 536 { 537 538 $tp = e107::getParser(); 539 540 $this->addDebug('setNewsFrontMeta (type)',$type); 541 // $this->addDebug('setNewsFrontMeta (data)',$news); 542 543 switch($type) 544 { 545 546 case "all": 547 e107::meta('robots', 'noindex'); 548 break; 549 550 case "tag": 551 case "author": 552 if(!defined('e_PAGETITLE')) 553 { 554 define('e_PAGETITLE', $this->subAction); 555 e107::meta('og:title', $this->subAction); 556 } 557 e107::meta('robots', 'noindex'); 558 559 break; 560 561 case "list": 562 $title = $tp->toHTML($news['category_name'],false,'TITLE_PLAIN'); 563 if(!defined('e_PAGETITLE')) 564 { 565 define('e_PAGETITLE', $title ); 566 e107::meta('og:title', $title); 567 } 568 e107::meta('robots', 'noindex'); 569 break; 570 571 case "day": 572 case "month": 573 $item = intval($this->subAction).'20000101'; 574 $year = substr($item, 0, 4); 575 $month = substr($item, 4,2); 576 $day = substr($item, 6, 2); 577 578 $unix = strtotime($year.'-'.$month.'-'.$day); 579 580 $format = ($type === 'day') ? 'dd MM yyyy' : 'MM yyyy'; 581 582 $title = e107::getParser()->toDate($unix, $format); 583 584 585 586 $title = strip_tags($title); 587 588 $this->dayMonth = $title; 589 590 if(!defined('e_PAGETITLE')) 591 { 592 define('e_PAGETITLE', $title ); 593 e107::meta('og:title', $title); 594 } 595 e107::meta('robots', 'noindex'); 596 break; 597 598 case "news": 599 600 break; 601 602 603 default: 604 e107::meta('robots', 'noindex'); 605 } 606 607 608 if($type == 'news') 609 { 610 611 if(!empty($news['news_meta_robots'])) 612 { 613 e107::meta('robots', $news['news_meta_robots']); 614 } 615 616 if($news['news_title'] && !defined('e_PAGETITLE')) 617 { 618 define('e_PAGETITLE', $news['news_title']); 619 e107::meta('og:title',$news['news_title']); 620 e107::meta('og:type','article'); 621 e107::meta('twitter:card', 'summary'); 622 } 623 624 if($news['news_meta_description'] && !defined('META_DESCRIPTION')) 625 { 626 e107::meta('description',$news['news_meta_description']); 627 e107::meta('og:description',$news['news_meta_description']); 628 //define('META_DESCRIPTION', $news['news_meta_description']); // deprecated 629 } 630 elseif($news['news_summary']) // BC compatibility 631 { 632 e107::meta('og:description',$news['news_summary']); 633 } 634 635 // include news-thumbnail/image in meta. - always put this one first. 636 if($news['news_thumbnail']) 637 { 638 $iurl = (substr($news['news_thumbnail'],0,3)=="{e_") ? $news['news_thumbnail'] : SITEURL.e_IMAGE."newspost_images/".$news['news_thumbnail']; 639 $tmp = explode(",", $iurl); 640 foreach($tmp as $mimg) 641 { 642 if(substr($mimg,-8) == '.youtube' || empty($mimg)) 643 { 644 continue; 645 } 646 e107::meta('og:image',$tp->thumbUrl($mimg,'w=500',false,true) ); 647 // e107::meta('og:image',$mimg); 648 } 649 650 } 651 652 // grab all images in news-body and add to meta. 653 $images = e107::getBB()->getContent('img',$news['news_body'],SITEURL.e_IMAGE."newspost_images/"); 654 $c =1; 655 foreach($images as $im) 656 { 657 if($c == 4){ break; } 658 e107::meta('og:image',$im); 659 $c++; 660 } 661 662 // grab all youtube videos in news-body and add thumbnails to meta. 663 $youtube = e107::getBB()->getContent('youtube',$news['news_body']); 664 $c = 1; 665 foreach($youtube as $yt) 666 { 667 if($c == 3){ break; } 668 list($img,$tmp) = explode("?",$yt); 669 e107::meta('og:image',"http://img.youtube.com/vi/".$img."/0.jpg"); 670 $c++; 671 } 672 673 674 675 $url = e107::getUrl()->create('news/view/item', $news,'full=1'); 676 e107::meta('og:url',$url); 677 678 e107::meta('article:section',$news['category_name']); 679 680 if($news['news_meta_keywords'] && !defined('META_KEYWORDS')) 681 { 682 e107::meta('keywords',$news['news_meta_keywords']); 683 $tmp = explode(",",$news['news_meta_keywords']); 684 foreach($tmp as $t) 685 { 686 e107::meta('article:tag', trim($t)); 687 } 688 689 // define('META_KEYWORDS', $news['news_meta_keywords']); // deprecated 690 } 691 692 693 /* Facebook reference. 694 * http://developers.facebook.com/docs/opengraph/objects/builtin/ 695 */ 696 697 return; 698 } 699 700 701 702 if($news['category_name'] && !defined('e_PAGETITLE') && $type == 'cat') 703 { 704 define('e_PAGETITLE', $tp->toHTML($news['category_name'],false,'TITLE_PLAIN')); 705 } 706 707 if($news['category_meta_keywords'] && !defined('META_KEYWORDS')) 708 { 709 define('META_KEYWORDS', $news['category_meta_keywords']); 710 } 711 712 if($news['category_meta_description'] && !defined('META_DESCRIPTION')) 713 { 714 define('META_DESCRIPTION', $news['category_meta_description']); 715 } 716 717 718 719 } 720 721 722 723 private function setNewsCache($cache_tag, $cache_data, $rowData=array()) 724 { 725 $e107cache = e107::getCache(); 726 $e107cache->setMD5(null,true); 727 728 $e107cache->set($cache_tag, $cache_data); 729 $e107cache->set($cache_tag."_caption", $this->caption); 730 $e107cache->set($cache_tag."_title", defined("e_PAGETITLE") ? e_PAGETITLE : ''); 731 $e107cache->set($cache_tag."_diz", defined("META_DESCRIPTION") ? META_DESCRIPTION : ''); 732 733 $e107cache->set($cache_tag."_rows", e107::serialize($rowData,'json')); 734 735 } 736 737 738 /** 739 * @param $cache_tag 740 * @param string $type 'title' or 'diz' or 'rows' or empty for html. 741 */ 742 private function getNewsCache($cachetag, $type=null) 743 { 744 if(!empty($type)) 745 { 746 $cachetag .= "_".$type; 747 } 748 $this->addDebug('CaheString lookup', $cachetag); 749 e107::getDebug()->log('Retrieving cache string:' . $cachetag); 750 751 $ret = e107::getCache()->setMD5(null)->retrieve($cachetag); 752 753 if($type == 'rows') 754 { 755 return e107::unserialize($ret); 756 } 757 758 return $ret; 759 } 760 761 /** 762 * @param $cacheString 763 * @return bool|string 764 */ 765 private function checkCache($cacheString) 766 { 767 $e107cache = e107::getCache(); 768 $this->addDebug("checkCache", 'true'); 769 $e107cache->setMD5(null); 770 771 $cache_data = $e107cache->retrieve($cacheString, $this->cacheRefreshTime); 772 $cache_title = $e107cache->retrieve($cacheString."_title", $this->cacheRefreshTime); 773 $cache_diz = $e107cache->retrieve($cacheString."_diz", $this->cacheRefreshTime); 774 $etitle = ($cache_title != "e_PAGETITLE") ? $cache_title : ""; 775 $ediz = ($cache_diz != "META_DESCRIPTION") ? $cache_diz : ""; 776 777 if($etitle) 778 { 779 define('e_PAGETITLE', $etitle); 780 } 781 782 if($ediz) 783 { 784 define("META_DESCRIPTION",$ediz); 785 } 786 787 if ($cache_data) 788 { 789 return $cache_data; 790 } 791 else 792 { 793 return false; 794 } 795 } 796 797 798 private function renderCache($caption, $text) 799 { 800 global $pref,$tp,$sql,$CUSTOMFOOTER, $FOOTER,$cust_footer,$ph; 801 global $db_debug,$ns,$eTimingStart, $error_handler, $db_time, $sql2, $mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb,$e107; 802 803 $this->text = $text; 804 $this->caption = $caption; 805 $this->addDebug("Cache", 'active'); 806 807 return $this->text; 808 } 809 810 811 private function render_newscats() // -- CNN Style Categories. ---- 812 { 813 $tp = e107::getParser(); 814 $ns = e107::getRender(); 815 816 if (isset($this->pref['news_cats']) && $this->pref['news_cats'] == '1') 817 { 818 $text3 = $tp->toHTML("{NEWS_CATEGORIES}", TRUE, 'TITLE'); 819 return $ns->tablerender(LAN_NEWS_23, $text3, 'news_cat', true); 820 } 821 } 822 823 824 825 private function renderListTemplate() 826 { 827 $this->addDebug("Method",'renderListTemplate()'); 828 $sql = e107::getDb(); 829 $tp = e107::getParser(); 830 831 global $NEWSLISTSTYLE, $NEWSLISTTITLE; 832 833 834 if($newsCachedPage = $this->checkCache($this->cacheString)) 835 { 836 837 $caption = $this->getNewsCache($this->cacheString,'caption'); 838 return $this->renderCache($caption, $newsCachedPage); 839 } 840 else 841 { 842 $this->addDebug("Cache", 'inactive: '.$this->cacheString); 843 } 844 845 $category = intval($this->subAction); 846 if ($this->action == 'cat' && $category != 0) 847 { 848 849 $gen = new convert; 850 $sql->select("news_category", "*", "category_id='{$category}'"); 851 $row = $sql->fetch(); 852 extract($row); // still required for the table-render. :( 853 } 854 855 if ($this->action == 'all') // show archive of all news items using list-style template. 856 { 857 $renTypeQry = ''; 858 859 if(!empty($this->pref['news_list_templates']) && is_array($this->pref['news_list_templates'])) 860 { 861 $renTypeQry = " AND (n.news_render_type REGEXP '(^|,)(".implode("|", $this->pref['news_list_templates']).")(,|$)')"; 862 } 863 864 // $news_total = $sql->count("news", "(*)", "WHERE news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().")". str_replace("n.news", "news", $renTypeQry)); 865 $query = " 866 SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon, 867 nc.category_meta_keywords, nc.category_meta_description 868 FROM #news AS n 869 LEFT JOIN #user AS u ON n.news_author = u.user_id 870 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 871 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") AND n.news_start < ".time()." 872 AND (n.news_end=0 || n.news_end>".time().") "; 873 874 $query .= $renTypeQry; 875 876 $query .= " 877 ORDER BY n.news_sticky DESC, n.news_datestamp DESC 878 LIMIT ".intval($this->from).",".deftrue('NEWSALL_LIMIT', NEWSLIST_LIMIT); // NEWSALL_LIMIT just for BC. NEWSLIST_LIMIT is sufficient. 879 $category_name = ($this->defaultTemplate == 'list') ? PAGE_NAME : "All"; 880 unset($renTypeQry); 881 } 882 elseif ($this->action == 'cat') // show archive of all news items in a particular category using list-style template. 883 { 884 885 // $news_total = $sql->count("news", "(*)", "WHERE news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().") AND news_category=".intval($sub_action)); 886 887 $query = " 888 SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon, nc.category_meta_keywords, 889 nc.category_meta_description 890 FROM #news AS n 891 LEFT JOIN #user AS u ON n.news_author = u.user_id 892 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 893 WHERE n.news_category=".intval($this->subAction)." 894 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 895 AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 896 ORDER BY n.news_datestamp DESC 897 LIMIT ".intval($this->from).",".NEWSLIST_LIMIT; 898 } 899 elseif($this->action === 'tag') 900 { 901 $tagsearch = e107::getParser()->filter($_GET['tag']); 902 903 $query = " 904 SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon, nc.category_meta_keywords, 905 nc.category_meta_description 906 FROM #news AS n 907 LEFT JOIN #user AS u ON n.news_author = u.user_id 908 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 909 WHERE n.news_meta_keywords LIKE '%".$tagsearch."%' 910 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 911 AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 912 ORDER BY n.news_datestamp DESC 913 LIMIT ".intval($this->from).",".NEWSLIST_LIMIT; 914 $category_name = defset('LAN_NEWS_309','Tag').': "'.$tagsearch.'"'; 915 916 $this->tagAuthor = $tagsearch; 917 918 } 919 elseif($this->action === 'author') 920 { 921 $authorSearch = e107::getParser()->filter($_GET['author']); 922 923 $query = " 924 SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon, nc.category_meta_keywords, 925 nc.category_meta_description 926 FROM #news AS n 927 LEFT JOIN #user AS u ON n.news_author = u.user_id 928 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 929 WHERE u.user_name = '".$authorSearch."' 930 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 931 AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 932 ORDER BY n.news_datestamp DESC 933 LIMIT ".intval($this->from).",".NEWSLIST_LIMIT; 934 $category_name = LAN_AUTHOR.': "'.$authorSearch.'"'; 935 936 $this->tagAuthor = $authorSearch; 937 938 } 939 940 $newsList = array(); 941 942 if(!empty($query) && $sql->gen($query)) 943 { 944 $news_total = $sql->foundRows(); 945 $newsList = $sql->db_getList(); 946 $ogImageCount = 0; 947 foreach($newsList as $row) 948 { 949 if(!empty($row['news_thumbnail'])) 950 { 951 $iurl = (substr($row['news_thumbnail'],0,3)=="{e_") ? $row['news_thumbnail'] : SITEURL.e_IMAGE."newspost_images/".$row['news_thumbnail']; 952 $tmp = explode(",", $iurl); 953 954 if($tp->isImage($tmp[0])) 955 { 956 if($ogImageCount > 6) 957 { 958 break; 959 } 960 961 e107::meta('og:image',$tp->thumbUrl($tmp[0],'w=500',false,true) ); 962 $ogImageCount++; 963 964 } 965 } 966 967 } 968 } 969 else 970 { 971 972 $this->addDebug("Query",str_replace('#',MPREFIX, $query)); 973 } 974 975 976 $this->setNewsFrontMeta($newsList[1], $this->action); 977 978 979 // elseif($category_name) 980 // { 981 // define('e_PAGETITLE', $tp->toHTML($category_name,FALSE,'TITLE')); 982 // } 983 e107::getDebug()->log("PageTitle: ".e_PAGETITLE); 984 $currentNewsAction = $this->action; 985 986 $action = $currentNewsAction; 987 988 if(!deftrue('THEME_LEGACY')) // v2.x 989 { 990 $template = e107::getTemplate('news', 'news', 'list'); 991 } 992 else // v1.x 993 { 994 if(empty($NEWSLISTSTYLE)) 995 { 996 $NEWSLISTSTYLE = " 997 <div style='padding:3px;width:100%'> 998 <table style='border-bottom:1px solid black;width:100%' cellpadding='0' cellspacing='0'> 999 <tr> 1000 <td style='vertical-align:top;padding:3px;width:20px'> 1001 {NEWS_CATEGORY_ICON} 1002 </td><td style='text-align:left;padding:3px'> 1003 {NEWSTITLELINK=extend} 1004 <br /> 1005 {NEWS_SUMMARY} 1006 <span class='smalltext'> 1007 {NEWS_DATE} 1008 {NEWSCOMMENTS} 1009 </span> 1010 </td><td style='width:55px'> 1011 {SETIMAGE: w=55&h=55&crop=1} 1012 {NEWSTHUMBNAIL} 1013 </td></tr></table> 1014 </div>\n"; 1015 } 1016 1017 $template = array('start'=>'', 'item'=>$NEWSLISTSTYLE, 'end'=>''); 1018 1019 } 1020 1021 // Legacy Styling.. 1022 $param = array(); 1023 $param['itemlink'] = (defined("NEWSLIST_ITEMLINK")) ? NEWSLIST_ITEMLINK : ""; 1024 $param['thumbnail'] =(defined("NEWSLIST_THUMB")) ? NEWSLIST_THUMB : "border:0px"; 1025 $param['catlink'] = (defined("NEWSLIST_CATLINK")) ? NEWSLIST_CATLINK : ""; 1026 $param['caticon'] = (defined("NEWSLIST_CATICON")) ? NEWSLIST_CATICON : defset('ICONSTYLE',''); 1027 $param['current_action'] = $action; 1028 $param['template_key'] = 'news/list'; 1029 1030 // NEW - allow news batch shortcode override (e.g. e107::getScBatch('news', 'myplugin', true); ) 1031 e107::getEvent()->trigger('news_list_parse', $newsList); 1032 1033 $text = ''; 1034 1035 if(!empty($template['start'])) 1036 { 1037 $text .= $tp->parseTemplate($template['start'], true); 1038 } 1039 1040 if(!empty($newsList)) 1041 { 1042 $c = 1; 1043 foreach($newsList as $row) 1044 { 1045 $tpl = ($c === 1 && !empty($template['first']) && $this->from === 0) ? $template['first'] : $template['item']; 1046 1047 $text .= $this->ix->render_newsitem($row, 'return', '', $tpl, $param); 1048 $this->currentRow = $row; 1049 $c++; 1050 } 1051 } 1052 else // No News - empty. 1053 { 1054 $text .= "<div class='news-empty'><div class='alert alert-info'>".(strstr(e_QUERY, "month") ? LAN_NEWS_462 : LAN_NEWS_83)."</div></div>"; 1055 } 1056 1057 if(!empty($template['end'])) 1058 { 1059 $text .= $tp->parseTemplate($template['end'], true); 1060 } 1061 1062 $icon = ($row['category_icon']) ? "<img src='".e_IMAGE."icons/".$row['category_icon']."' alt='' />" : ""; 1063 1064 1065 $amount = NEWSLIST_LIMIT; 1066 $nitems = defined('NEWS_NEXTPREV_NAVCOUNT') ? '&navcount='.NEWS_NEXTPREV_NAVCOUNT : '' ; 1067 $url = rawurlencode(e107::getUrl()->create($this->route, $this->newsUrlparms)); 1068 $parms = 'tmpl_prefix='.deftrue('NEWS_NEXTPREV_TMPL', 'default').'&total='.$news_total.'&amount='.$amount.'¤t='.$this->from.$nitems.'&url='.$url; 1069 1070 1071 $this->addDebug('newsUrlParms',$this->newsUrlparms); 1072 1073 $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); 1074 1075 1076 if(isset($template['caption'])) // v2.x 1077 { 1078 $NEWSLISTTITLE = str_replace("{NEWSCATEGORY}",$tp->toHTML($category_name,FALSE,'TITLE'), $template['caption']); 1079 } 1080 elseif(empty($NEWSLISTTITLE)) // default 1081 { 1082 $NEWSLISTTITLE = LAN_NEWS_82." '".$tp->toHTML($category_name,FALSE,'TITLE')."'"; 1083 } 1084 else // v1.x 1085 { 1086 $NEWSLISTTITLE = str_replace("{NEWSCATEGORY}",$tp->toHTML($category_name,FALSE,'TITLE'),$NEWSLISTTITLE); 1087 } 1088 1089 if($this->defaultTemplate != 'list') 1090 { 1091 $text .= "<div class='center news-list-footer'><a class='btn btn-default' href='".e107::getUrl()->create('news/list/all')."'>".LAN_NEWS_84."</a></div>"; 1092 } 1093 1094 $this->caption = $NEWSLISTTITLE; 1095 $this->templateKey = 'list'; 1096 $cache_data = $text; // e107::getRender()->tablerender($NEWSLISTTITLE, $text, 'news', true); 1097 1098 $this->setNewsCache($this->cacheString, $cache_data); 1099 1100 1101 return $cache_data; 1102 1103 1104 } 1105 1106 1107 private function renderViewTemplate() 1108 { 1109 global $NEWSSTYLE; // v1.x backward compatibility. 1110 1111 1112 $this->addDebug("Method",'renderViewTemplate()'); 1113 1114 if($newsCachedPage = $this->checkCache($this->cacheString)) 1115 { 1116 $this->addDebug("Cache",'active'); 1117 $rows = $this->getNewsCache($this->cacheString,'rows'); 1118 $caption = $this->getNewsCache($this->cacheString,'caption'); 1119 e107::getEvent()->trigger('user_news_item_viewed', $rows); 1120 $this->addDebug("Event-triggered:user_news_item_viewed", $rows); 1121 $this->setNewsFrontMeta($rows); 1122 $text = $this->renderCache($caption, $newsCachedPage); // This exits if cache used 1123 $this->comments = $rows; 1124 return $text; 1125 } 1126 else 1127 { 1128 $this->addDebug("Cache",'inactive'); 1129 } 1130 1131 $sql = e107::getDb(); 1132 // <-- Cache 1133 1134 if(isset($this->pref['trackbackEnabled']) && $this->pref['trackbackEnabled']) 1135 { 1136 $query = " 1137 SELECT COUNT(tb.trackback_pid) AS tb_count, n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, 1138 nc.category_icon, nc.category_meta_keywords, nc.category_meta_description 1139 FROM #news AS n 1140 LEFT JOIN #user AS u ON n.news_author = u.user_id 1141 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1142 LEFT JOIN #trackback AS tb ON tb.trackback_pid = n.news_id 1143 WHERE n.news_id=".intval($this->subAction)." AND n.news_class REGEXP '".e_CLASS_REGEXP."' 1144 AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1145 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 1146 GROUP by n.news_id"; 1147 } 1148 else 1149 { 1150 $query = " 1151 SELECT n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon, nc.category_meta_keywords, 1152 nc.category_meta_description 1153 FROM #news AS n 1154 LEFT JOIN #user AS u ON n.news_author = u.user_id 1155 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1156 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' 1157 AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1158 AND n.news_start < ".time()." 1159 AND (n.news_end=0 || n.news_end>".time().") 1160 AND n.news_id=".intval($this->subAction); 1161 } 1162 1163 1164 if ($sql->gen($query)) 1165 { 1166 $news = $sql->fetch(); 1167 $id = $news['news_category']; // Use category of this news item to generate next/prev links 1168 1169 e107::getEvent()->trigger('user_news_item_viewed', $news); 1170 $this->addDebug("Event-triggered:user_news_item_viewed", $news); 1171 1172 //***NEW [SecretR] - comments handled inside now 1173 e107::setRegistry('news/page_allow_comments', !$news['news_allow_comments']); 1174 if(!$news['news_allow_comments'] && isset($_POST['commentsubmit'])) 1175 { 1176 $pid = intval(varset($_POST['pid'], 0)); // ID of the specific comment being edited (nested comments - replies) 1177 1178 $clean_authorname = $_POST['author_name']; 1179 $clean_comment = $_POST['comment']; 1180 $clean_subject = $_POST['subject']; 1181 1182 e107::getSingleton('comment')->enter_comment($clean_authorname, $clean_comment, 'news', $this->subAction, $pid, $clean_subject); 1183 } 1184 1185 //More SEO 1186 $this->setNewsFrontMeta($news); 1187 1188 $currentNewsAction = $this->action; 1189 1190 $action = $currentNewsAction; 1191 1192 $param = array(); 1193 $param['current_action'] = $action; 1194 $param['template_key'] = 'news/view'; 1195 $param['return'] = true; 1196 1197 $caption = null; 1198 $render = false; 1199 1200 if(deftrue('THEME_LEGACY') && !empty($NEWSSTYLE)) 1201 { 1202 $template = $NEWSSTYLE; 1203 } 1204 elseif(deftrue('THEME_LEGACY') && function_exists("news_style")) // BC 1205 { 1206 $template = news_style($news, 'extend', $param); 1207 } 1208 else 1209 { 1210 $tmp = e107::getTemplate('news', 'news', 'view'); 1211 1212 if(empty($tmp)) 1213 { 1214 $newsViewTemplate = !empty($news['news_template']) ? $news['news_template'] : 'default'; 1215 $tmp = e107::getTemplate('news', 'news_view', $newsViewTemplate); 1216 $param['template_key'] = 'news_view/'.$newsViewTemplate; 1217 } 1218 1219 $template = $tmp['item']; 1220 1221 1222 1223 if(isset($tmp['caption']) && $tmp['caption'] !== null) // to initiate tablerender() usage. 1224 { 1225 $this->addDebug('Internal Route', $this->route); 1226 $this->route = 'news/view'; // used for tablerender id. 1227 $this->templateKey = $newsViewTemplate; // used for tablerender id. 1228 1229 $nsc = e107::getScBatch('news')->setScVar('news_item', $news); // Allow any news shortcode to be used in the 'caption'. 1230 $caption = e107::getParser()->parseTemplate($tmp['caption'], true, $nsc); 1231 1232 $render = true; 1233 } 1234 1235 unset($tmp); 1236 } 1237 1238 1239 $this->currentRow = $news; 1240 1241 $cache_data = $this->ix->render_newsitem($news, 'extend', '', $template, $param); 1242 1243 $this->setNewsCache($this->cacheString, $cache_data, $news); 1244 1245 if($render === true) 1246 { 1247 1248 1249 $unique = $this->getRenderId(); 1250 1251 1252 $ns = e107::getRender(); 1253 $ns->setUniqueId($unique); 1254 $ns->setContent('title', $news['news_title']); 1255 $ns->setContent('text', $news['news_summary']); 1256 $ns->setUniqueId(null); // prevent other tablerenders from using this content. 1257 1258 // TODO add 'image' and 'icon'? 1259 $this->caption = $caption; 1260 $text = $cache_data; 1261 1262 } 1263 else 1264 { 1265 $text = $cache_data; 1266 } 1267 1268 $this->comments = $news; 1269 1270 return $text; 1271 } 1272 else 1273 { 1274 1275 header("HTTP/1.0 404 Not Found",true,404); 1276 require_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_error.php"); 1277 $text = e107::getMessage()->setTitle(LAN_ERROR_7, E_MESSAGE_INFO)->addInfo(LAN_NEWS_308)->render(); // Perhaps you're looking for one of the news items below? 1278 1279 $this->action = 'all'; 1280 $text .= $this->renderListTemplate(); 1281 1282 return $text; 1283 1284 } 1285 1286 1287 } 1288 1289 1290 private function renderComments($news) 1291 { 1292 $this->addDebug("Calling", "renderComments()"); 1293 1294 // if(e107::getRegistry('news/page_allow_comments')) 1295 if(isset($news['news_allow_comments']) && empty($news['news_allow_comments'])) // ie. comments active 1296 { 1297 global $comment_edit_query; //FIXME - kill me 1298 $comment_edit_query = 'comment.news.'.$news['news_id']; 1299 $text = e107::getComment()->compose_comment('news', 'comment', $news['news_id'], null, $news['news_title'], false, 'html'); 1300 1301 if(!empty($text)) 1302 { 1303 return $text; 1304 } 1305 } 1306 else 1307 { 1308 // Only show message if global comments are enabled, but current news item comments are disabled 1309 if(e107::getPref('comments_disabled') == 0 && $news['news_allow_comments'] == 1) 1310 { 1311 if(BOOTSTRAP) 1312 { 1313 return e107::getMessage()->addInfo(LAN_NEWS_13)->render(); 1314 } 1315 else 1316 { 1317 return "<br /><div style='text-align:center'><b>".LAN_NEWS_13."</b></div>"; 1318 } 1319 } 1320 } 1321 1322 $this->addDebug("Failed", "renderComments()"); 1323 1324 return ''; 1325 } 1326 1327 1328 private function getQuery() 1329 { 1330 $query = " 1331 SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon, 1332 nc.category_meta_keywords, nc.category_meta_description, nc.category_template 1333 FROM #news AS n 1334 LEFT JOIN #user AS u ON n.news_author = u.user_id 1335 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1336 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1337 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 1338 AND (FIND_IN_SET('0', n.news_render_type) OR FIND_IN_SET(1, n.news_render_type)) 1339 ORDER BY n.news_sticky DESC, ".$this->order." DESC LIMIT ".intval($this->from).",".ITEMVIEW; 1340 1341 return $query; 1342 1343 1344 } 1345 1346 1347 1348 private function renderDefaultTemplate() 1349 { 1350 $this->addDebug("Method",'renderDefaultTemplate()'); 1351 $tp = e107::getParser(); 1352 $sql = e107::getDb(); 1353 1354 $interval = $this->pref['newsposts']; 1355 1356 global $NEWSSTYLE; 1357 1358 switch ($this->action) 1359 { 1360 case "list" : 1361 $sub_action = intval($this->subAction); 1362 // $news_total = $sql->db_Count("news", "(*)", "WHERE news_category={$sub_action} AND news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().")"); 1363 $query = " 1364 SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, 1365 nc.category_icon, nc.category_meta_keywords, nc.category_meta_description, nc.category_template 1366 FROM #news AS n 1367 LEFT JOIN #user AS u ON n.news_author = u.user_id 1368 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1369 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1370 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 1371 AND n.news_category={$sub_action} 1372 ORDER BY n.news_sticky DESC,".$this->order." DESC LIMIT ".intval($this->from).",".ITEMVIEW; 1373 1374 $noNewsMessage = LAN_NEWS_463; 1375 break; 1376 1377 1378 case "item" : 1379 $sub_action = intval($this->subAction); 1380 $news_total = 1; 1381 if(isset($this->pref['trackbackEnabled']) && $this->pref['trackbackEnabled']) 1382 { 1383 $query = " 1384 SELECT COUNT(tb.trackback_pid) AS tb_count, n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, 1385 nc.category_icon, nc.category_meta_keywords, nc.category_meta_description, nc.category_template 1386 FROM #news AS n 1387 LEFT JOIN #user AS u ON n.news_author = u.user_id 1388 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1389 LEFT JOIN #trackback AS tb ON tb.trackback_pid = n.news_id 1390 WHERE n.news_id=".$this->subAction." AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1391 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 1392 GROUP by n.news_id"; 1393 } 1394 else 1395 { 1396 $query = " 1397 SELECT n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon, 1398 nc.category_meta_keywords, nc.category_meta_description, nc.category_template 1399 FROM #news AS n 1400 LEFT JOIN #user AS u ON n.news_author = u.user_id 1401 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1402 WHERE n.news_id=".$this->subAction." AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1403 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")"; 1404 } 1405 1406 $noNewsMessage = LAN_NEWS_83; 1407 break; 1408 1409 1410 case "month" : 1411 case "day" : 1412 $item = $tp -> toDB($this->subAction).'20000101'; 1413 $year = substr($item, 0, 4); 1414 $month = substr($item, 4,2); 1415 1416 1417 1418 if ($this->action == 'day') 1419 { 1420 $day = substr($item, 6, 2); 1421 $lastday = $day; 1422 $startdate = mktime(0, 0, 0, $month, $day, $year); 1423 } 1424 else 1425 { // A month's worth 1426 $day = 1; 1427 $startdate = mktime(0, 0, 0, $month, $day, $year); 1428 $lastday = date("t", $startdate); 1429 } 1430 1431 1432 $enddate = mktime(23, 59, 59, $month, $lastday, $year); 1433 1434 $query = " 1435 SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, nc.category_name, nc.category_sef, 1436 nc.category_icon, nc.category_meta_keywords, nc.category_meta_description, nc.category_template 1437 FROM #news AS n 1438 LEFT JOIN #user AS u ON n.news_author = u.user_id 1439 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1440 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1441 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 1442 AND (FIND_IN_SET('0', n.news_render_type) OR FIND_IN_SET(1, n.news_render_type)) AND n.news_datestamp BETWEEN {$startdate} AND {$enddate} 1443 ORDER BY ".$this->order." DESC LIMIT ".intval($this->from).",".ITEMVIEW; 1444 1445 if($this->action == 'month') 1446 { 1447 $noNewsMessage = LAN_NEWS_462; 1448 } 1449 else 1450 { 1451 $noNewsMessage = LAN_NEWS_464; 1452 } 1453 1454 break; 1455 1456 case 'default' : 1457 default : 1458 //$action = ''; 1459 $this->cacheString = 'news.php_default_'; // Make sure its sensible 1460 // $news_total = $sql->db_Count("news", "(*)", "WHERE news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().") AND news_render_type<2" ); 1461 1462 if(!isset($this->pref['newsposts_archive'])) 1463 { 1464 $this->pref['newsposts_archive'] = 0; 1465 } 1466 $interval = $this->pref['newsposts']-$this->pref['newsposts_archive']; // Number of 'full' posts to show 1467 1468 // Get number of news item to show 1469 if(isset($this->pref['trackbackEnabled']) && $this->pref['trackbackEnabled']) { 1470 $query = " 1471 SELECT SQL_CALC_FOUND_ROWS COUNT(tb.trackback_pid) AS tb_count, n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, nc.category_id, 1472 nc.category_name, nc.category_sef, nc.category_icon, nc.category_meta_keywords, nc.category_meta_description, nc.category_template, 1473 COUNT(*) AS tbcount 1474 FROM #news AS n 1475 LEFT JOIN #user AS u ON n.news_author = u.user_id 1476 LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id 1477 LEFT JOIN #trackback AS tb ON tb.trackback_pid = n.news_id 1478 WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$this->nobody_regexp.") 1479 AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 1480 AND (FIND_IN_SET('0', n.news_render_type) OR FIND_IN_SET(1, n.news_render_type)) 1481 GROUP by n.news_id 1482 ORDER BY news_sticky DESC, ".$this->order." DESC LIMIT ".intval($this->from).",".ITEMVIEW; 1483 } 1484 else 1485 { 1486 $query = $this->getQuery(); 1487 1488 1489 } 1490 1491 $noNewsMessage = LAN_NEWS_83; 1492 } // END - switch($action) 1493 1494 1495 if($newsCachedPage = $this->checkCache($this->cacheString)) // normal news front-page - with cache. 1496 { 1497 1498 1499 if(!$this->action) 1500 { 1501 // Removed, themes should use {FEATUREBOX} shortcode instead 1502 // if (isset($this->pref['fb_active'])) 1503 // { 1504 // require_once(e_PLUGIN."featurebox/featurebox.php"); 1505 // } 1506 // Removed, legacy 1507 // if (isset($this->pref['nfp_display']) && $this->pref['nfp_display'] == 1) 1508 // { 1509 // require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php"); 1510 // } 1511 1512 } 1513 1514 //news archive 1515 if ($this->action != "item" && $this->action != 'list' && $this->pref['newsposts_archive']) 1516 { 1517 $sql = e107::getDb(); 1518 1519 if ($sql->gen($query)) 1520 { 1521 1522 $newsAr = $sql -> db_getList(); 1523 1524 if($newsarchive = $this->checkCache('newsarchive')) 1525 { 1526 $newsCachedPage = $newsCachedPage.$newsarchive; 1527 } 1528 else 1529 { 1530 // $this->show_newsarchive($newsAr,$interval); 1531 } 1532 } 1533 } 1534 1535 $this->renderCache($this->caption, $newsCachedPage); 1536 return null; 1537 } 1538 1539 1540 if (!($news_total = $sql->gen($query))) // No news items 1541 { 1542 $this->setNewsFrontMeta(null,$this->action); 1543 return "<div class='news-empty'><div class='alert alert-info' style='text-align:center'>".$noNewsMessage."</div></div>"; 1544 1545 } 1546 1547 $newsAr = $sql -> db_getList(); 1548 $news_total=$sql->total_results; 1549 // Get number of entries 1550 //$sql -> db_Select_gen("SELECT FOUND_ROWS()"); 1551 // $frows = $sql -> db_Fetch(); 1552 //$news_total = $frows[0]; 1553 1554 //echo "<br />Total ".$news_total." items found, ".count($newsAr)." displayed, Interval = {$interval}<br /><br />"; 1555 1556 $p_title = ($this->action == "item") ? $newsAr[1]['news_title'] : $tp->toHTML($newsAr[1]['category_name'],FALSE,'TITLE'); 1557 1558 switch($this->action) 1559 { 1560 case 'item': 1561 $this->setNewsFrontMeta($newsAr[1]); 1562 break; 1563 1564 1565 case 'list': 1566 default: 1567 $this->setNewsFrontMeta($newsAr[1], $this->action); 1568 break; 1569 } 1570 1571 /*if($action != "" && !is_numeric($action)) 1572 { 1573 if($action == "item" && $this->pref['meta_news_summary'] && $newsAr[1]['news_title']) 1574 { 1575 define("META_DESCRIPTION",SITENAME.": ".$newsAr[1]['news_title']." - ".$newsAr[1]['news_summary']); 1576 } 1577 define("e_PAGETITLE", $p_title); 1578 }*/ 1579 1580 $currentNewsAction = $this->action; 1581 1582 $action = $currentNewsAction; 1583 1584 if(!$action) 1585 { 1586 // Removed, themes should use {FEATUREBOX} shortcode instead 1587 // if (isset($this->pref['fb_active'])){ // --->feature box 1588 // require_once(e_PLUGIN."featurebox/featurebox.php"); 1589 // } 1590 1591 // Removed, legacy 1592 // if (isset($this->pref['nfp_display']) && $this->pref['nfp_display'] == 1){ 1593 // require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php"); 1594 // } 1595 } 1596 1597 /** 1598 * @deprecated - for BC only. May be removed in future without further notice. 1599 */ 1600 if(isset($this->pref['news_unstemplate']) && $this->pref['news_unstemplate'] && file_exists(THEME."news_template.php")) 1601 { 1602 // theme specific template required ... 1603 $this->addDebug("Template Mode",'News Preferences: Non-standard Template (Legacy)'); 1604 1605 $ALTERNATECLASSES = null; 1606 $NEWSCLAYOUT = null; 1607 1608 require_once(THEME."news_template.php"); 1609 1610 if(!empty($ALTERNATECLASS1)) 1611 { 1612 return true; 1613 } 1614 1615 $newscolumns = (isset($NEWSCOLUMNS) ? $NEWSCOLUMNS : 1); 1616 $newspercolumn = (isset($NEWSITEMSPERCOLUMN) ? $NEWSITEMSPERCOLUMN : 10); 1617 $newsdata = array(); 1618 $loop = 1; 1619 $param = array(); 1620 $param['current_action'] = $action; 1621 1622 foreach($newsAr as $news) 1623 { 1624 1625 if(is_array($ALTERNATECLASSES)) 1626 { 1627 $newsdata[$loop] .= "<div class='{$ALTERNATECLASSES[0]}'>".$this->ix->render_newsitem($news, "return", '', '', $param)."</div>"; 1628 $ALTERNATECLASSES = array_reverse($ALTERNATECLASSES); 1629 } 1630 else 1631 { 1632 $newsdata[$loop] .= $this->ix->render_newsitem($news, 'return', '', '', $param); 1633 } 1634 $loop ++; 1635 if($loop > $newscolumns) 1636 { 1637 $loop = 1; 1638 } 1639 } 1640 1641 $loop = 1; 1642 1643 $items = array(); 1644 1645 foreach($newsdata as $data) 1646 { 1647 $var = "ITEMS".$loop; 1648 // $$var = $data; 1649 $items[$var] = $data; 1650 $loop ++; 1651 } 1652 1653 1654 $text = $tp->parseTemplate($NEWSCLAYOUT, false, $items); 1655 1656 // $text = preg_replace("/\{(.*?)\}/e", '$\1', $NEWSCLAYOUT); 1657 1658 1659 // Deprecated 1660 // $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".$e107->url->getUrl('core:news', 'main', "action=nextprev&to_action=".($action ? $action : 'default' )."&subaction=".($sub_action ? $sub_action : "0")); 1661 1662 // $sub_action = intval($sub_action); 1663 // $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'.($action ? $action : 'default' ).($sub_action ? ".".$sub_action : ".0").".[FROM]"; 1664 1665 $amount = ITEMVIEW; 1666 $nitems = defined('NEWS_NEXTPREV_NAVCOUNT') ? '&navcount='.NEWS_NEXTPREV_NAVCOUNT : '' ; 1667 $url = rawurlencode(e107::getUrl()->create($this->route, $this->newsUrlparms)); 1668 $parms = 'tmpl_prefix='.deftrue('NEWS_NEXTPREV_TMPL', 'default').'&total='.$news_total.'&amount='.$amount.'¤t='.$this->from.$nitems.'&url='.$url; 1669 1670 $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); 1671 1672 // $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}"); 1673 // $text .= ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : ""); 1674 // $text=''.$text.'<center>'.$nextprev.'</center>'; 1675 1676 // echo $text; 1677 $this->setNewsCache($this->cacheString, $text); 1678 return $text; 1679 } 1680 else 1681 { 1682 ob_start(); 1683 1684 $newpostday = 0; 1685 $thispostday = 0; 1686 $this->pref['newsHeaderDate'] = 1; 1687 $gen = new convert(); 1688 /* 1689 if(vartrue($NEWSLISTSTYLE)) $template = $NEWSLISTSTYLE; v1.x doesn't do this.. so no point doing it here. 1690 else 1691 { 1692 $tmp = e107::getTemplate('news', 'news', 'list'); 1693 $template = $tmp['item']; 1694 unset($tmp); 1695 } 1696 */ 1697 //@todo remove 1698 if (!defined("DATEHEADERCLASS")) { 1699 define("DATEHEADERCLASS", "nextprev"); 1700 // if not defined in the theme, default class nextprev will be used for new date header 1701 } 1702 1703 // #### normal newsitems, rendered via render_newsitem(), the $query is changed above (no other changes made) --------- 1704 $param = array(); 1705 $param['current_action'] = $action; 1706 $param['template_key'] = 'news/default'; 1707 1708 // Get Correct Template 1709 // XXX we use $NEWSLISTSTYLE above - correct as we are currently in list mode - XXX No this is not NEWSLISTSTYLE - which provides only summaries. 1710 // TODO requires BC testing if we comment this one 1711 if(vartrue($NEWSSTYLE)) 1712 { 1713 $template = $NEWSSTYLE; 1714 } 1715 else // v2.x 1716 { 1717 $layout = e107::getTemplate('news', 'news'); 1718 $catTemplate = $newsAr[1]['category_template']; 1719 1720 // v2.1.7 load the category template if found. 1721 if(!empty($this->templateKey)) // predefined by NEWS_LAYOUT; 1722 { 1723 $this->addDebug("Template Mode",'NEWS_LAYOUT constant'); 1724 $tmpl = $layout[$this->templateKey]; 1725 $param['template_key'] = 'news/'.$this->templateKey; 1726 } 1727 elseif(!empty($newsAr[1]['category_template']) && !empty($layout[$catTemplate])) // defined by news_category field. 1728 { 1729 $this->addDebug("Template Mode",'news_category database field'); 1730 $this->templateKey = $catTemplate; 1731 $tmpl = $layout[$this->templateKey]; 1732 $param['template_key'] = 'news/'.$this->templateKey; 1733 } 1734 elseif($this->action === 'list' && isset($layout['category']) && !isset($layout['category']['body'])) // make sure it's not old news_categories.sc 1735 { 1736 $this->addDebug("Template Mode","'category' key defined in template file"); 1737 $tmpl = $layout['category']; 1738 $this->templateKey = 'category'; 1739 $param['template_key'] = 'news/category'; 1740 } 1741 elseif(!empty($layout[$this->defaultTemplate])) // defined by default template 'news' pref. (newspost.php?mode=main&action=settings) 1742 { 1743 $this->addDebug("Template Mode",'News Preferences: Default template'); 1744 $tmpl = $layout[$this->defaultTemplate]; 1745 $this->templateKey = $this->defaultTemplate; 1746 } 1747 else // fallback. 1748 { 1749 $this->addDebug("Template Mode",'Fallback'); 1750 $tmpl = $layout['default'] ; 1751 $this->defaultTemplate = 'default'; 1752 $this->templateKey = 'default'; 1753 } 1754 1755 $this->currentRow = $newsAr[1]; 1756 1757 $this->addDebug('Template key',$this->templateKey); 1758 1759 $template = $tmpl['item']; 1760 1761 } 1762 1763 1764 if(isset($tmpl['caption'])) 1765 { 1766 $row = $newsAr[1]; 1767 1768 $this->currentRow = $row; 1769 1770 if(empty($this->action)) // default page. 1771 { 1772 $row['category_name'] = PAGE_NAME; 1773 } 1774 1775 $nsc = e107::getScBatch('news')->setScVar('news_item', $row)->setScVar('param', $param); 1776 $this->caption = $tp->parseTemplate($tmpl['caption'], true, $nsc); 1777 1778 } 1779 1780 if(!empty($tmpl['start'])) //v2.1.5 1781 { 1782 $nsc = e107::getScBatch('news')->setScVar('news_item', $newsAr[1])->setScVar('param', $param); 1783 echo $tp->parseTemplate($tmpl['start'],true,$nsc); 1784 } 1785 elseif($sub_action && 'list' == $action && vartrue($newsAr[1]['category_name'])) //old v1.x stuff 1786 { 1787 // we know category name - pass it to the nexprev url 1788 $category_name = $newsAr[1]['category_name']; 1789 1790 if(vartrue($newsAr[1]['category_sef'])) $newsUrlparms['name'] = $newsAr[1]['category_sef']; 1791 if(!isset($NEWSLISTCATTITLE)) 1792 { 1793 $NEWSLISTCATTITLE = "<h1 class='newscatlist-title'>".$tp->toHTML($category_name,FALSE,'TITLE')."</h1>"; 1794 } 1795 else 1796 { 1797 $NEWSLISTCATTITLE = str_replace("{NEWSCATEGORY}",$tp->toHTML($category_name,FALSE,'TITLE'),$NEWSLISTCATTITLE); 1798 } 1799 echo $NEWSLISTCATTITLE; 1800 } 1801 1802 1803 $i= 1; 1804 1805 $socialInstalled = e107::isInstalled('social'); 1806 1807 while(isset($newsAr[$i]) && $i <= $interval) 1808 { 1809 $news = $newsAr[$i]; 1810 1811 if(!isset($this->newsUrlparms['category_sef']) && !empty($news['category_sef'])) 1812 { 1813 $this->newsUrlparms['category_sef'] = $news['category_sef']; 1814 } 1815 1816 // Set the Values for the social shortcode usage. 1817 if($socialInstalled == true) 1818 { 1819 $socialArray = array('url'=>e107::getUrl()->create('news/view/item', $news, 'full=1'), 'title'=>$tp->toText($news['news_title']), 'tags'=>$news['news_meta_keywords']); 1820 $socialObj = e107::getScBatch('social'); 1821 1822 if(is_object($socialObj)) 1823 { 1824 $socialObj->setVars($socialArray); 1825 } 1826 } 1827 1828 if(function_exists("news_style")) // BC 1829 { 1830 $template = news_style($news, $action, $param); 1831 } 1832 1833 1834 // render new date header if pref selected ... 1835 $thispostday = strftime("%j", $news['news_datestamp']); 1836 if ($newpostday != $thispostday && (isset($this->pref['news_newdateheader']) && $this->pref['news_newdateheader'])) 1837 { 1838 echo "<div class='".DATEHEADERCLASS."'>".strftime("%A %d %B %Y", $news['news_datestamp'])."</div>"; 1839 } 1840 $newpostday = $thispostday; 1841 $news['category_id'] = $news['news_category']; 1842 if ($action == "item") 1843 { 1844 unset($news['news_render_type']); 1845 e107::getEvent()->trigger('user_news_item_viewed', $news); 1846 //e107::getDebug()->log($news); 1847 } 1848 // $template = false; 1849 1850 1851 1852 $this->ix->render_newsitem($news, 'default', '', $template, $param); 1853 1854 1855 $i++; 1856 } 1857 1858 if(!empty($tmpl['end'])) 1859 { 1860 $nsc = e107::getScBatch('news')->setScVar('news_item', $newsAr[1])->setScVar('param', $param); 1861 echo $tp->parseTemplate($tmpl['end'], true, $nsc); 1862 } 1863 1864 1865 1866 1867 $amount = ITEMVIEW; 1868 $nitems = defined('NEWS_NEXTPREV_NAVCOUNT') ? '&navcount='.NEWS_NEXTPREV_NAVCOUNT : '' ; 1869 $url = rawurlencode(e107::getUrl()->create($this->route, $this->newsUrlparms)); 1870 1871 // Example of passing route data instead building the URL outside the shortcode - for a reference only 1872 // $url = rawurlencode('url::'.$newsRoute.'::'.http_build_query($newsUrlparms, null, '&')); 1873 $parms = 'tmpl_prefix='.deftrue('NEWS_NEXTPREV_TMPL', 'default').'&total='.$news_total.'&amount='.$amount.'¤t='.$this->from.$nitems.'&url='.$url; 1874 1875 echo $tp->parseTemplate("{NEXTPREV={$parms}}"); 1876 1877 // $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'.($action ? $action : 'default' ).($sub_action ? ".".$sub_action : ".0").".[FROM]"; 1878 // $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}"); 1879 // echo ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : ""); 1880 1881 $cache_data = ob_get_clean(); 1882 1883 $this->setNewsCache($this->cacheString, $cache_data); 1884 1885 return $cache_data; 1886 } 1887 1888 } 1889} 1890 1891$newsObj = new news_front; 1892//$content = e107::getRender()->getContent(); // get tablerender content 1893require_once(HEADERF); 1894//e107::getRender()->setContent($content,null); // reassign tablerender content if HEADERF uses render. 1895$newsObj->render(); 1896if(E107_DBG_BASIC && ADMIN) 1897{ 1898 $newsObj->debug(); 1899} 1900require_once(FOOTERF); 1901exit; 1902 1903 1904 1905 1906//require_once(e_HANDLER."comment_class.php"); 1907//$cobj = new comment; 1908 1909 1910 1911//------------------------------------------------------ 1912// DISPLAY NEWS IN 'CATEGORY' LIST FORMAT HERE 1913//------------------------------------------------------ 1914// Just title and a few other details 1915 1916 1917 1918 1919 1920//------------------------------------------------------ 1921// DISPLAY SINGLE ITEM IN EXTENDED FORMAT HERE 1922//------------------------------------------------------ 1923 1924 1925 1926//------------------------------------------------------ 1927// DISPLAY NEWS IN LIST FORMAT HERE 1928//------------------------------------------------------ 1929// Show title, author, first part of news item... 1930 1931 1932// ##### -------------------------------------------------------------------------------------------------------------- 1933 1934 1935// #### new: news archive --------------------------------------------------------------------------------------------- 1936 1937// #### END ----------------------------------------------------------------------------------------------------------- 1938 1939if ($action != "item") { 1940 if (is_numeric($action)){ 1941 $action = ""; 1942 } 1943 // $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'."[FROM].".$action.(isset($sub_action) ? ".".$sub_action : ""); 1944 // $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}"); 1945 // echo ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : ""); 1946} 1947 1948if(is_dir("remotefile")) { 1949 require_once(e_HANDLER."file_class.php"); 1950 $file = new e_file; 1951 // $reject = array('$.','$..','/','CVS','thumbs.db','*._$', 'index', 'null*', 'Readme.txt'); 1952 // $crem = $file -> get_files(e_BASE."remotefile", "", $reject); 1953 $crem = $file -> get_files(e_BASE."remotefile", '~Readme\.txt'); 1954 if(count($crem)) { 1955 foreach($crem as $loadrem) { 1956 if(strstr($loadrem['fname'], "load_")) { 1957 require_once(e_BASE."remotefile/".$loadrem['fname']); 1958 } 1959 } 1960 } 1961} 1962 1963if (isset($this->pref['nfp_display']) && $this->pref['nfp_display'] == 2 && is_readable(e_PLUGIN."newforumposts_main/newforumposts_main.php")) 1964{ 1965 require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php"); 1966} 1967 1968render_newscats(); 1969 1970require_once(FOOTERF); 1971 1972 1973// ========================================================================= 1974 1975 1976