[ Index ]

PHP Cross Reference of E107 v0.7.22 code documentation

title

Body

[close]

/ -> page.php (source)

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


Generated: Tue Aug 3 00:19:13 2010
Open Source related documentation for developers.