[ Index ]

PHP Cross Reference of e107 v1


title

Body

[close]

/ -> page.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     Steve Dunstan 2001-2002
   7  |     Copyright (C) 2008-2010 e107 Inc (e107.org)
   8  |
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.7/page.php $
  14  |     $Revision: 12466 $
  15  |     $Id: page.php 12466 2011-12-22 13:41:27Z e107steved $
  16  |     $Author: e107steved $
  17  |
  18  +----------------------------------------------------------------------------+
  19  */
  20  
  21  // Experimental e-token
  22  if(isset($_POST['submit_page_pw']) && !isset($_POST['e-token']))
  23  {
  24      // set e-token so it can be processed by class2
  25      $_POST['e-token'] = '';
  26  }
  27  
  28  require_once ("class2.php");
  29  $page = new pageClass();
  30  
  31  if(!e_QUERY)
  32  {
  33      require_once(HEADERF);
  34      $tmp = $page -> listPages();
  35      if(is_array($tmp))
  36      {
  37          $ns -> tablerender($tmp['title'], $tmp['text']);
  38          require_once(FOOTERF);
  39          exit;
  40      }
  41  }
  42  else
  43  {
  44  
  45      $cacheString = 'page_'.$page->pageID;
  46      $cachePageTitle = 'page-t_'.$page->pageID;
  47  
  48      if($cacheData = $e107cache->retrieve($cacheString))
  49      {
  50          list($pagetitle,$comment_flag) = explode("^",$e107cache->retrieve($cachePageTitle));
  51          define("e_PAGETITLE", $pagetitle);
  52          require_once(HEADERF);
  53          echo $cacheData;
  54  
  55      }
  56      else
  57      {
  58          $e107_core_custom_pages = $page -> showPage();
  59          define("e_PAGETITLE", $e107_core_custom_pages['title']);
  60          require_once(HEADERF);
  61          if ($e107_core_custom_pages['err'])        // Need to display error block after header defined
  62          {
  63              $ns -> tablerender($e107_core_custom_pages['title'], $e107_core_custom_pages['text'],"cpage");
  64              require_once(FOOTERF);
  65              exit;
  66          }
  67          if ($e107_core_custom_pages['cachecontrol'] == TRUE)
  68          {
  69              ob_start();
  70              $ns -> tablerender($e107_core_custom_pages['title'], $e107_core_custom_pages['text'],"cpage");
  71              $cache_data = ob_get_flush();
  72              $e107cache->set($cacheString, $cache_data);
  73              $e107cache->set($cachePageTitle, $e107_core_custom_pages['title']."^".$e107_core_custom_pages['comment_flag']);
  74              $comment_flag = $e107_core_custom_pages['comment_flag'];
  75          }
  76          else
  77          {
  78              $ns -> tablerender($e107_core_custom_pages['title'], $e107_core_custom_pages['text'],"cpage");
  79              $comment_flag = $e107_core_custom_pages['comment_flag'];
  80          }
  81      }
  82  
  83      $page -> title = $e107_core_custom_pages['title'];
  84      if($com = $page -> pageComment($comment_flag))
  85      {
  86          echo $com['comment'].$com['comment_form'];
  87      }
  88  }
  89  
  90  require_once(FOOTERF);
  91  
  92  /* EOF */
  93  
  94  class pageClass
  95  {
  96  
  97      var $bullet;                        /* bullet image */
  98      var $pageText;                      /* main text of selected page, not parsed */
  99      var $multipageFlag;                 /* flag - true if multiple page page, false if not */
 100      var $pageTitles;                    /* array containing page titles */
 101      var $pageID;                        /* id number of page to be displayed */
 102      var $pageSelected;                  /* selected page of multiple page page */
 103      var $pageToRender;                  /* parsed page to be sent to screen */
 104      var $debug;                         /* temp debug flag */
 105      var $title;                         /* title of page, it if has one (as defined in [newpage=title] tag */
 106  
 107  
 108  	function pageClass($debug = FALSE)
 109      {
 110          /* constructor */
 111  
 112          $tmp = explode(".", e_QUERY);
 113          $this -> pageID = intval($tmp[0]);
 114          $this -> pageSelected = (isset($tmp[1]) ? intval($tmp[1]) : 0);
 115          $this -> pageTitles = array();
 116          $this->bullet = '';
 117          if(defined('BULLET'))
 118          {
 119              $this->bullet = '<img src="'.THEME.'images/'.BULLET.'" alt="" style="vertical-align: middle;" />';
 120          }
 121          elseif(file_exists(THEME.'images/bullet2.gif'))
 122          {
 123              $this->bullet = '<img src="'.THEME.'images/bullet2.gif" alt="" style="vertical-align: middle;" />';
 124          }
 125  
 126          $this -> debug = $debug;
 127  
 128          if($this -> debug)
 129          {
 130              $this -> debug = "<b>PageID</b> ".$this -> pageID." <br />";
 131              $this -> debug .= "<b>pageSelected</b> ".$this -> pageSelected." <br />";
 132          }
 133      }
 134  
 135  	function listPages()
 136      {
 137          global $pref, $sql, $ns;
 138  
 139          if(!isset($pref['listPages']) || !$pref['listPages'])
 140          {
 141              message_handler("MESSAGE", LAN_PAGE_1);
 142          }
 143          else
 144          {
 145              if(!$sql -> db_Select("page", "*", "page_theme='' AND page_class IN (".USERCLASS_LIST.") "))
 146              {
 147                  $text = LAN_PAGE_2;
 148              }
 149              else
 150              {
 151                  $pageArray = $sql -> db_getList();
 152                  foreach($pageArray as $page)
 153                  {
 154                      extract($page);
 155                      $text .= $this -> bullet." <a href='".e_BASE."page.php?".$page_id."'>".$page_title."</a><br />";
 156                  }
 157                  $ns -> tablerender(LAN_PAGE_11, $text,"cpage_list");
 158              }
 159          }
 160      }
 161  
 162  
 163  	function showPage()
 164      {
 165          global $sql, $ns;
 166          $query = "SELECT p.*, u.user_id, u.user_name FROM #page AS p
 167          LEFT JOIN #user AS u ON p.page_author = u.user_id
 168          WHERE p.page_id='".intval($this -> pageID)."' AND p.page_class IN (".USERCLASS_LIST.") ";
 169  
 170          if(!$sql -> db_Select_gen($query) && !$_GET['elan'])
 171          {
 172              $ret['title'] = LAN_PAGE_12;            // ***** CHANGED
 173              $ret['text'] = LAN_PAGE_3;
 174              $ret['comment_flag'] = '';
 175              $ret['err'] = TRUE;
 176              return $ret;
 177          }
 178  
 179          extract($sql -> db_Fetch());
 180  
 181          $this -> pageText = $page_text;
 182  
 183          $this -> pageCheckPerms($page_class, $page_password, $page_title);
 184  
 185          if($this -> debug)
 186          {
 187              echo "<b>pageText</b> ".$this -> pageText." <br />";
 188          }
 189  
 190          $this -> parsePage();
 191  
 192          $gen = new convert;
 193  
 194          $text = '';    // Notice removal
 195          $ptitle = "";
 196  
 197          if($page_author)
 198          {
 199              $text .= "<div class='smalltext cpage_author' style='text-align:right'>".$user_name.", ".$gen->convert_date($page_datestamp, "long")."</div><br />";
 200          }
 201  
 202          if($this -> title)
 203          {
 204              $ptitle = "<div class='cpage_title'>".$this -> title."</div>";
 205          }
 206          
 207  
 208          if(ADMIN && getperms("5"))
 209          {
 210               $text .= "<a href='".e_ADMIN_ABS."cpage.php?create.edit.".$this -> pageID."'>
 211              <img src='".e_IMAGE_ABS."/admin_images/edit_16.png' alt='edit' title='Edit' style='border: 0px none; height: 16px; width: 16px;' />
 212              </a><br />";
 213          }
 214  
 215          $text .= $this -> pageToRender;
 216          $text .= $this -> pageIndex();
 217          $text .= $this -> pageRating($page_rating_flag);
 218  
 219          $ret['title'] = $page_title;
 220          $ret['text'] = $ptitle."<div class='cpage_body'>".$text."</div>";
 221          $ret['comment_flag'] = $page_comment_flag;
 222          $ret['err'] = FALSE;
 223          $ret['cachecontrol'] = (isset($page_password) && !$page_password);      // Don't cache password protected pages
 224  
 225          return $ret;
 226      }
 227  
 228  	function parsePage()
 229      {
 230          global $tp;
 231          $this -> pageTitles = array();      // Notice removal
 232  
 233          if(preg_match_all("/\[newpage.*?\]/si", $this -> pageText, $pt))
 234          {
 235              if (substr($this->pageText, 0, 6) == '[html]')
 236              {    // Need to strip html bbcode from wysiwyg on multi-page docs (handled automatically on single pages)
 237                  if (substr($this->pageText, -7, 7) == '[/html]')
 238                  {
 239                      $this->pageText = substr($this->pageText, 6, -7);
 240                  }
 241                  else
 242                  {
 243                      $this->pageText = substr($this->pageText, 6);
 244                  }
 245              }
 246              $pages = preg_split("/\[newpage.*?\]/si", $this -> pageText, -1, PREG_SPLIT_NO_EMPTY);
 247              $this -> multipageFlag = TRUE;
 248          }
 249          else
 250          {
 251              $this -> pageToRender = $tp -> toHTML($this -> pageText, TRUE, 'BODY');
 252              return;
 253          }
 254  
 255          foreach($pt[0] as $title)
 256          {
 257              $this -> pageTitles[] = $title;
 258          }
 259  
 260  
 261          if(!trim($pages[0]))
 262          {
 263              $count = 0;
 264              foreach($pages as $page)
 265              {
 266                  $pages[$count] = $pages[($count+1)];
 267                  $count++;
 268              }
 269              unset($pages[(count($pages)-1)]);
 270          }
 271  
 272          $pageCount = count($pages);
 273          $titleCount = count($this -> pageTitles);
 274          /* if the vars above don't match, page 1 has no [newpage] tag, so we need to create one ... */
 275  
 276          if($pageCount != $titleCount)
 277          {
 278              array_unshift($this -> pageTitles, "[newpage]");
 279          }
 280  
 281          /* ok, titles now match pages, rename the titles if needed ... */
 282  
 283          $count =0;
 284          foreach($this -> pageTitles as $title)
 285          {
 286              $titlep = preg_replace("/\[newpage=(.*?)\]/", "\\1", $title);
 287              $this -> pageTitles[$count] = ($titlep == "[newpage]" ? LAN_PAGE_13." ".($count+1)."&nbsp;" : $tp -> toHTML($titlep, TRUE, 'TITLE'));
 288              $count++;
 289          }
 290  
 291          $this -> pageToRender = $tp -> toHTML($pages[$this -> pageSelected], TRUE, 'BODY');
 292          $this -> title = (substr($this -> pageTitles[$this -> pageSelected], -1) == ";" ? "" : $this -> pageTitles[$this -> pageSelected]);
 293  
 294          if($this -> debug)
 295          {
 296              echo "<b>multipageFlag</b> ".$this -> multipageFlag." <br />";
 297              if($this -> multipageFlag)
 298              {
 299                  echo "<pre>"; print_r($pages); echo "</pre>";
 300                  echo "<b>pageCount</b> ".$pageCount." <br />";
 301                  echo "<b>titleCount</b> ".$titleCount." <br />";
 302                  echo "<pre>"; print_r($this -> pageTitles); echo "</pre>";
 303              }
 304          }
 305      }
 306  
 307  	function pageIndex()
 308      {
 309          global $tp,$pref;
 310          $itext = '';
 311          if(isset($pref['old_np']) && $pref['old_np'])
 312          {
 313              $count = 0;
 314              foreach($this -> pageTitles as $title)
 315              {
 316                  if (!$count) { $itext = "<br /><br />"; }
 317                  $itext .= $this -> bullet." ".($count == $this -> pageSelected ? $title : "<a href='".e_SELF."?".$this -> pageID.".".$count."'>".$title."</a>")."<br />\n";
 318                  $count++;
 319              }
 320          }
 321          else
 322          {
 323              $titles = implode("|",$this -> pageTitles);
 324              $total_items = count($this -> pageTitles);
 325              $parms = $total_items.",1,".$this -> pageSelected.",".e_SELF."?".$this -> pageID.".[FROM],,$titles";
 326              $itext = ($total_items) ? "<div class='nextprev nextprev_custom'>".$tp->parseTemplate("{NEXTPREV={$parms}}")."</div>" : "";
 327          }
 328          return $itext;
 329      }
 330  
 331  	function pageRating($page_rating_flag)
 332      {
 333          $rate_text = '';      // Notice removal
 334          if($page_rating_flag)
 335          {
 336              require_once(e_HANDLER."rate_class.php");
 337              $rater = new rater;
 338              $rate_text = "<br /><table style='width:100%'><tr><td style='width:50%'>";
 339  
 340              if ($ratearray = $rater->getrating("page", $this -> pageID))
 341              {
 342                  if ($ratearray[2] == "")
 343                  {
 344                      $ratearray[2] = 0;
 345                  }
 346                  $rate_text .= "<img src='".e_IMAGE."rate/box/box".$ratearray[1].".png' alt='' style='vertical-align:middle;' />\n";
 347                  $rate_text .= "&nbsp;".$ratearray[1].".".$ratearray[2]." - ".$ratearray[0]."&nbsp;";
 348                  $rate_text .= ($ratearray[0] == 1 ? "vote" : "votes");
 349              }
 350              else
 351              {
 352                  $rating .= LAN_PAGE_dl_13;
 353              }
 354              $rate_text .= "</td><td style='width:50%; text-align:right'>";
 355  
 356              if (!$rater->checkrated("page", $this -> pageID) && USER)
 357              {
 358                  $rate_text .= $rater->rateselect("&nbsp;&nbsp;&nbsp;&nbsp; <b>".LAN_PAGE_4."</b>", "page", $this -> pageID);
 359              }
 360              else if(!USER)
 361              {
 362                  $rate_text .= "&nbsp;";
 363              }
 364              else
 365              {
 366                  $rate_text .= LAN_PAGE_5;
 367              }
 368              $rate_text .= "</td></tr></table>";
 369          }
 370          return $rate_text;
 371      }
 372  
 373  	function pageComment($page_comment_flag)
 374      {
 375          global $sql, $ns, $e107cache, $tp, $comment_shortcodes,$cacheString;
 376  
 377          if($page_comment_flag)
 378          {
 379              require_once(e_HANDLER."comment_class.php");
 380              $cobj = new comment;
 381  
 382              if (isset($_POST['commentsubmit']))
 383              {
 384                  $cobj->enter_comment($_POST['author_name'], $_POST['comment'], "page", $this -> pageID, $pid, $_POST['subject']);
 385                  $e107cache->clear("comment.page.".$this -> pageID);
 386                  $e107cache->clear($cacheString);
 387              }
 388              return $cobj->compose_comment("page", "comment", $this -> pageID, 0, $this -> title);
 389          }
 390      }
 391  
 392  	function pageCheckPerms($page_class, $page_password, $page_title="&nbsp;")
 393      {
 394          global $ns, $tp, $pref, $HEADER, $FOOTER, $sql;     // $tp added - also $pref - used by footer
 395  
 396  
 397          if (!check_class($page_class))
 398          {
 399              define("e_PAGETITLE", $page_title);
 400              // HEADERF requires that $tp is defined - hence declared as global above.
 401              require_once(HEADERF);      // Do header now in case wrong password was entered
 402              message_handler("MESSAGE", LAN_PAGE_6);
 403              require_once(FOOTERF); exit;
 404          }
 405  
 406          if (!$page_password)
 407          {
 408              return TRUE;
 409          }
 410  
 411          if(isset($_POST['page_pw']))
 412          {
 413              if($_POST['page_pw'] == $page_password)
 414              {
 415                  $this -> setPageCookie();
 416              }
 417          }
 418          else
 419          {
 420              $cookiename = "e107page_".$this -> pageID;
 421  
 422              if(isset($_COOKIE[$cookiename]) && ($_COOKIE[$cookiename] == md5($page_password.USERID)))
 423              {
 424                  return TRUE;
 425              }
 426              // Invalid/empty password here
 427          }
 428  
 429          define("e_PAGETITLE", $page_title);
 430          // HEADERF requires that $tp is defined - hence declared as global above.
 431          require_once(HEADERF);      // Do header now in case wrong password was entered
 432  
 433          // Need to prompt for password here
 434          if (isset($_POST['page_pw']))
 435          {
 436              message_handler("MESSAGE", LAN_PAGE_7);     // Invalid password
 437          }
 438  
 439          $pw_entry_text = "
 440          <div style='text-align:center; margin-left:auto; margin-right: auto;'>
 441          <form method='post' action='".e_SELF."?".e_QUERY."' id='pwform'>
 442          <table style='width:100%;' class='fborder'>
 443          <tr>
 444          <td class='forumheader' colspan='3' style='text-align:center; white-space:nowrap'>".LAN_PAGE_8."</td>
 445          </tr>
 446          <tr>
 447          <td class='forumheader3' style='width:20%;'>".LAN_PAGE_9.":</td>
 448          <td class='forumheader3' style='width: 60%;'><input type='password' id='page_pw' name='page_pw' style='width: 90%;'/></td>
 449          <td class='forumheader3' style='width:20%; vertical-align:middle; margin-left:auto; margin-right:auto; text-align:center;'><img src='".e_IMAGE."generic/".IMODE."/password.png' alt='' /></td>
 450          </tr>
 451          <tr>
 452          <td class='forumheader' colspan='3' style='text-align:center;'><input class='button' type='submit' name='submit_page_pw' value='".LAN_PAGE_10."' />
 453          <input type='hidden' name='e-token' value='".e_TOKEN."' /></td>
 454          </tr>
 455          </table>
 456          </form>
 457          </div>
 458          ";
 459          // Mustn't return to higher level code here
 460  
 461          $ns->tablerender($page_title, $pw_entry_text,"cpage_pw");       // HEADERF also clears $text - hence different variable
 462          require_once(FOOTERF);
 463          exit;
 464      }
 465  
 466  	function setPageCookie()
 467      {
 468          global $pref;
 469          $pref['pageCookieExpire'] = max($pref['pageCookieExpire'], 120);
 470          $hash = md5($_POST['page_pw'].USERID);
 471          cookie("e107page_".e_QUERY, $hash, (time() + $pref['pageCookieExpire']));
 472          header("location:".e_SELF."?".e_QUERY);
 473          exit;
 474      }
 475  }


Generated: Mon Mar 12 16:28:38 2012 Cross Reference PHPXref