[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

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


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7