[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> common.php (source)

   1  <?php
   2  
   3  ////////////////////////////////////////////////////////////////////////////////
   4  //                                                                            //
   5  //   Copyright (C) 2006  Phorum Development Team                              //
   6  //   http://www.phorum.org                                                    //
   7  //                                                                            //
   8  //   This program is free software. You can redistribute it and/or modify     //
   9  //   it under the terms of either the current Phorum License (viewable at     //
  10  //   phorum.org) or the Phorum License that was distributed with this file    //
  11  //                                                                            //
  12  //   This program is distributed in the hope that it will be useful,          //
  13  //   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
  14  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
  15  //                                                                            //
  16  //   You should have received a copy of the Phorum License                    //
  17  //   along with this program.                                                 //
  18  ////////////////////////////////////////////////////////////////////////////////
  19  
  20  // Check that this file is not loaded directly.
  21  if ( basename( __FILE__ ) == basename( $_SERVER["PHP_SELF"] ) ) exit();
  22  
  23  // all other constants in ./include/constants.php
  24  define( "PHORUM", "5.1.25" );
  25  
  26  // our internal version in format of year-month-day-serial
  27  define( "PHORUMINTERNAL", "2007031400" );
  28  
  29  define( "DEBUG", 0 );
  30  
  31  include_once ( "./include/constants.php" );
  32  
  33  // setup the PHORUM var
  34  $PHORUM = array();
  35  
  36  // temp member to hold arrays and such in templates
  37  $PHORUM["TMP"] = array();
  38  
  39  // The data member is the data the templates can access
  40  $PHORUM["DATA"] = array();
  41  $PHORUM["DATA"]["GET_VARS"] = array();
  42  $PHORUM["DATA"]["POST_VARS"] = "";
  43  
  44  // get the forum id if set with a post
  45  if ( isset( $_REQUEST["forum_id"] ) && is_numeric( $_REQUEST["forum_id"] ) ) {
  46      $PHORUM["forum_id"] = $_REQUEST["forum_id"];
  47  }
  48  
  49  // strip the slashes off of POST data if magic_quotes is on
  50  if ( get_magic_quotes_gpc() && count( $_REQUEST ) ) {
  51      foreach( $_POST as $key => $value ) {
  52          if ( !is_array( $value ) )
  53              $_POST[$key] = stripslashes( $value );
  54          else
  55              $_POST[$key] = phorum_recursive_stripslashes( $value );
  56      }
  57      foreach( $_GET as $key => $value ) {
  58          if ( !is_array( $value ) )
  59              $_GET[$key] = stripslashes( $value );
  60          else
  61              $_GET[$key] = phorum_recursive_stripslashes( $value );
  62      }
  63  }
  64  
  65  // look for and parse the QUERY_STRING
  66  // this only applies to urls that we create.
  67  // scrips using urls from forms (search) should use $_GET or $_POST
  68  if ( !defined( "PHORUM_ADMIN" ) ) {
  69      if ( isset( $_SERVER["QUERY_STRING"] ) || isset( $PHORUM["CUSTOM_QUERY_STRING"] ) ) {
  70          $Q_STR = empty( $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"] ) ? $_SERVER["QUERY_STRING"]: $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"];
  71  
  72          // ignore stuff past a #
  73          if ( strstr( $Q_STR, "#" ) ) list( $Q_STR, $other ) = explode( "#", $Q_STR );
  74  
  75          // explode it on comma
  76          $PHORUM["args"] = explode( ",", $Q_STR );
  77  
  78          // check for any assigned values
  79          if ( strstr( $Q_STR, "=" ) ) {
  80              foreach( $PHORUM["args"] as $key => $arg ) {
  81  
  82                  // if an arg has an = create an element in args
  83                  // with left part as key and right part as value
  84                  if ( strstr( $arg, "=" ) ) {
  85                      list( $var, $value ) = explode( "=", $arg );
  86                      $PHORUM["args"][$var] = urldecode( $value );
  87                      // get rid of the numbered arg, it is useless.
  88                      unset( $PHORUM["args"][$key] );
  89                  }
  90              }
  91          }
  92  
  93          // set forum_id if not set already by
  94          if ( empty( $PHORUM["forum_id"] ) && isset( $PHORUM["args"][0] ) ) {
  95              $PHORUM["forum_id"] = ( int )$PHORUM["args"][0];
  96          }
  97      }
  98  }
  99  
 100  // set the forum_id to 0 if not set by now.
 101  if ( empty( $PHORUM["forum_id"] ) ) $PHORUM["forum_id"] = 0;
 102  
 103  // Get the database settings.
 104  if ( empty( $GLOBALS["PHORUM_ALT_DBCONFIG"] ) || $GLOBALS["PHORUM_ALT_DBCONFIG"]==$_REQUEST["PHORUM_ALT_DBCONFIG"] || !defined("PHORUM_WRAPPER") ) {
 105      // Backup display_errors setting.
 106      $orig = ini_get("display_errors");
 107      @ini_set("display_errors", 0);
 108  
 109      // Load configuration.
 110      if (! include_once( "./include/db/config.php" )) {
 111          print '<html><head><title>Phorum error</title></head><body>';
 112          print '<h2>Phorum database configuration error</h2>';
 113  
 114          // No database configuration found.
 115          if (!file_exists("./include/db/config.php")) { ?>
 116              Phorum has been installed on this server, but the configuration<br/>
 117              for the database connection has not yet been made. Please read<br/>
 118              <a href="docs/install.txt">docs/install.txt</a> for installation instructions. <?php
 119          } else {
 120              $fp = fopen("./include/db/config.php", "r");
 121              // Unable to read the configuration file.
 122              if (!$fp) { ?>
 123                  A database configuration file was found in ./include/db/config.php,<br/>
 124                  but Phorum was unable to read it. Please check the file permissions<br/>
 125                  for this file. <?php
 126              // Unknown error.
 127              } else {
 128                  fclose($fp); ?>
 129                  A database configuration file was found in ./include/dbconfig.php,<br/>
 130                  but it could not be loaded. It possibly contains one or more errors.<br/>
 131                  Please check your configuration file. <?php
 132              }
 133          }
 134  
 135          print '</body></html>';
 136          exit(1);
 137      }
 138  
 139      // Restore original display_errors setting.
 140      @ini_set("display_errors", $orig);
 141  } else {
 142      $PHORUM["DBCONFIG"] = $GLOBALS["PHORUM_ALT_DBCONFIG"];
 143  }
 144  
 145  // Load the database layer.
 146  $PHORUM['DBCONFIG']['type'] = basename($PHORUM['DBCONFIG']['type']);
 147  include_once( "./include/db/{$PHORUM['DBCONFIG']['type']}.php" );
 148  
 149  if(!phorum_db_check_connection()){
 150      if(isset($PHORUM["DBCONFIG"]["down_page"])){
 151          header("Location: ".$PHORUM["DBCONFIG"]["down_page"]);
 152          exit();
 153      } else {
 154          echo "The database connection failed. Please check your database configuration in include/db/config.php. If the configuration is okay, check if the database server is running.";
 155          exit();
 156      }
 157  }
 158  
 159  // get the Phorum settings
 160  phorum_db_load_settings();
 161  
 162  // If we have no private key for signing data, generate one now.
 163  if (isset($PHORUM['internal_version']) && $PHORUM['internal_version'] >= PHORUMINTERNAL && (! isset($PHORUM["private_key"]) || empty($PHORUM["private_key"]))) {
 164     $chars = "0123456789!@#$%&abcdefghijklmnopqr".
 165              "stuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 166     $private_key = "";
 167     for ($i = 0; $i<40; $i++) {
 168         $private_key .= substr($chars, rand(0, strlen($chars)-1), 1);
 169     }
 170     $PHORUM["private_key"] = $private_key;
 171     phorum_db_update_settings(array("private_key" => $PHORUM["private_key"]));
 172  }
 173  
 174  include_once ( "./include/cache.php" );
 175  
 176  // a hook for rewriting vars at the beginning of common.php,
 177  //right after loading the settings from the database
 178  phorum_hook( "common_pre", "" );
 179  
 180  
 181  // stick some stuff from the settings into the DATA member
 182  $PHORUM["DATA"]["TITLE"] = ( isset( $PHORUM["title"] ) ) ? $PHORUM["title"] : "";
 183  $PHORUM["DATA"]["HTML_TITLE"] = ( !empty( $PHORUM["html_title"] ) ) ? $PHORUM["html_title"] : $PHORUM["DATA"]["TITLE"];
 184  $PHORUM["DATA"]["HEAD_TAGS"] = ( isset( $PHORUM["head_tags"] ) ) ? $PHORUM["head_tags"] : "";
 185  $PHORUM["DATA"]["FORUM_ID"] = $PHORUM["forum_id"];
 186  
 187  ////////////////////////////////////////////////////////////
 188  // only do this stuff if we are not in the admin
 189  
 190  if ( !defined( "PHORUM_ADMIN" ) ) {
 191  
 192      // if the Phorum is disabled, display a message.
 193      if(isset($PHORUM["status"]) && $PHORUM["status"]=="disabled"){
 194          if(!empty($PHORUM["disabled_url"])){
 195              header("Location: ".$PHORUM["disabled_url"]);
 196              exit();
 197          } else {
 198              echo "This Phorum is currently disabled.  Please contact the web site owner at ".$PHORUM['system_email_from_address']." for more information.\n";
 199              exit();
 200          }
 201      }
 202  
 203      // checking for upgrade or new install
 204      if ( !isset( $PHORUM['internal_version'] ) ) {
 205          echo "<html><head><title>Phorum error</title></head><body>No Phorum settings were found. Either this is a brand new installation of Phorum or there is an error with your database server. If this is a new install, please <a href=\"admin.php\">go to the admin page</a> to complete the installation. If not, check your database server.</body></html>";
 206          exit();
 207      } elseif ( $PHORUM['internal_version'] < PHORUMINTERNAL ) {
 208          echo "<html><head><title>Error</title></head><body>Looks like you have installed a new version. Go to the admin to complete the upgrade!</body></html>";
 209          exit();
 210      }
 211  
 212      // load the forum's settings
 213      if ( !empty( $PHORUM["forum_id"] ) ) {
 214          $forum_settings = phorum_db_get_forums( $PHORUM["forum_id"] );
 215          if ( empty( $forum_settings[$PHORUM["forum_id"]] ) ) {
 216              phorum_hook( "common_no_forum", "" );
 217              phorum_redirect_by_url( phorum_get_url( PHORUM_INDEX_URL ) );
 218              exit();
 219          }
 220          $PHORUM = array_merge( $PHORUM, $forum_settings[$PHORUM["forum_id"]] );
 221      } else {
 222          // some defaults we might need if no forum is set (i.e. on the index-page)
 223          $PHORUM['vroot']=0;
 224          $PHORUM['parent_id']=0;
 225          $PHORUM['active']=1;
 226          $PHORUM['folder_flag']=1;
 227      }
 228  
 229  
 230      // handling vroots
 231      if(!empty($PHORUM['vroot'])) {
 232          $vroot_folders = phorum_db_get_forums($PHORUM['vroot']);
 233  
 234          $PHORUM["title"] = $vroot_folders[$PHORUM['vroot']]['name'];
 235          $PHORUM["DATA"]["TITLE"] = $PHORUM["title"];
 236          $PHORUM["DATA"]["HTML_TITLE"] = $PHORUM["title"];
 237  
 238          if($PHORUM['vroot'] == $PHORUM['forum_id']) {
 239              // unset the forum-name if we are in the vroot-index
 240              // otherwise the NAME and TITLE would be the same and still shown twice
 241              unset($PHORUM['name']);
 242          }
 243      }
 244  
 245      // stick some stuff from the settings into the DATA member
 246      $PHORUM["DATA"]["NAME"] = ( isset( $PHORUM["name"] ) ) ? $PHORUM["name"] : "";
 247      $PHORUM["DATA"]["DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? $PHORUM["description"] : "";
 248      $PHORUM["DATA"]["ENABLE_PM"] = ( isset( $PHORUM["enable_pm"] ) ) ? $PHORUM["enable_pm"] : "";
 249      if ( !empty( $PHORUM["DATA"]["HTML_TITLE"] ) && !empty( $PHORUM["DATA"]["NAME"] ) ) {
 250          $PHORUM["DATA"]["HTML_TITLE"] .= PHORUM_SEPARATOR;
 251      }
 252      $PHORUM["DATA"]["HTML_TITLE"] .= $PHORUM["DATA"]["NAME"];
 253  
 254      // check the user session
 255      include_once ( "./include/users.php" );
 256      if ( phorum_user_check_session() ) {
 257          $PHORUM["DATA"]["LOGGEDIN"] = true;
 258  
 259          if(!$PHORUM["tight_security"] || phorum_user_check_session( PHORUM_SESSION_SHORT_TERM )){
 260              $PHORUM["DATA"]["FULLY_LOGGEDIN"] = true;
 261          } else {
 262              $PHORUM["DATA"]["FULLY_LOGGEDIN"] = false;
 263          }
 264  
 265          // Let the templates know whether we have new private messages.
 266          $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] = 0;
 267          if ( $PHORUM["enable_pm"] && isset($PHORUM["user"]["new_private_messages"]) ) {
 268               $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] = $PHORUM["user"]["new_private_messages"];
 269          }
 270  
 271          $PHORUM["DATA"]["notice_messages"] = false;
 272          $PHORUM["DATA"]["notice_users"] = false;
 273          $PHORUM["DATA"]["notice_groups"] = false;
 274  
 275          // if moderator notifications are on and the person is a mod, lets find out if anything is new
 276          if ( $PHORUM["enable_moderator_notifications"] ) {
 277              $forummodlist = phorum_user_access_list( PHORUM_USER_ALLOW_MODERATE_MESSAGES );
 278              if ( count( $forummodlist ) > 0 ) {
 279                  $PHORUM["DATA"]["notice_messages"] = ( phorum_db_get_unapproved_list( $forummodlist, true,0,true ) > 0 );
 280                  $PHORUM["DATA"]["notice_messages_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_UNAPPROVED );
 281              }
 282              if ( phorum_user_access_allowed( PHORUM_USER_ALLOW_MODERATE_USERS ) ) {
 283                  $PHORUM["DATA"]["notice_users"] = ( count( phorum_db_user_get_unapproved() ) > 0 );
 284                  $PHORUM["DATA"]["notice_users_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_USERS );
 285              }
 286              if ( phorum_user_allow_moderate_group() ) {
 287                  $groups = phorum_user_get_moderator_groups();
 288                  if ( count( $groups ) > 0 ) {
 289                      $PHORUM["DATA"]["notice_groups"] = count( phorum_db_get_group_members( array_keys( $groups ), PHORUM_USER_GROUP_UNAPPROVED ) );
 290                      $PHORUM["DATA"]["notice_groups_url"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MODERATION );
 291                  }
 292              }
 293          }
 294  
 295          $PHORUM["DATA"]["notice_all"] = ( $PHORUM["enable_pm"] && phorum_page!="pm" && $PHORUM["DATA"]["NEW_PRIVATE_MESSAGES"] ) || $PHORUM["DATA"]["notice_messages"] || $PHORUM["DATA"]["notice_users"] || $PHORUM["DATA"]["notice_groups"];
 296  
 297          // if the user has overridden thread settings, change it here.
 298          if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) {
 299              if ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_ON ) {
 300                  $PHORUM["threaded_list"] = true;
 301              } elseif ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_OFF ) {
 302                  $PHORUM["threaded_list"] = false;
 303              }
 304              if ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_ON ) {
 305                  $PHORUM["threaded_read"] = true;
 306              } elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_OFF ) {
 307                  $PHORUM["threaded_read"] = false;
 308              }
 309          }
 310      }
 311  
 312      // set up the blank user if not logged in
 313      if ( empty( $PHORUM["user"] ) ) {
 314          $PHORUM["user"] = array( "user_id" => 0, "username" => "", "admin" => false, "newinfo" => array() );
 315          $PHORUM["DATA"]["LOGGEDIN"] = false;
 316      }
 317  
 318  
 319      // a hook for rewriting vars in common.php after loading the user
 320      phorum_hook( "common_post_user", "" );
 321  
 322  
 323      // set up the template
 324  
 325      // check for a template being passed on the url
 326      // only use valid template names
 327      if ( !empty( $PHORUM["args"]["template"] ) ) {
 328          $template = basename( $PHORUM["args"]["template"] );
 329          if ($template != '..') {
 330              $PHORUM["template"] = $template;
 331          }
 332      }
 333  
 334      // user output buffering so we don't get header errors
 335      // not loaded if we are running an external or scheduled script
 336      if (! defined('PHORUM_SCRIPT')) {
 337          ob_start();
 338          include_once( phorum_get_template( "settings" ) );
 339          ob_end_clean();
 340      }
 341  
 342      // get the language file
 343      if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_language'] ) && !empty($PHORUM['user']['user_language']) )
 344          $PHORUM['language'] = $PHORUM['user']['user_language'];
 345  
 346      if ( !isset( $PHORUM["language"] ) || empty( $PHORUM["language"] ) || !file_exists( "./include/lang/$PHORUM[language].php" ) )
 347          $PHORUM["language"] = $PHORUM["default_language"];
 348  
 349      $PHORUM['language'] = basename($PHORUM['language']);
 350  
 351      if ( file_exists( "./include/lang/$PHORUM[language].php" ) ) {
 352          include_once( "./include/lang/$PHORUM[language].php" );
 353      }
 354  
 355      // load languages for localized modules
 356      if ( isset( $PHORUM["hooks"]["lang"] ) && is_array($PHORUM["hooks"]["lang"]) ) {
 357          foreach( $PHORUM["hooks"]["lang"]["mods"] as $mod ) {
 358              // load mods for this hook
 359              $mod = basename($mod);
 360              if ( file_exists( "./mods/$mod/lang/$PHORUM[language].php" ) ) {
 361                  include_once "./mods/$mod/lang/$PHORUM[language].php";
 362              }
 363              elseif ( file_exists( "./mods/$mod/lang/english.php" ) ) {
 364                  include_once "./mods/$mod/lang/english.php";
 365              }
 366          }
 367      }
 368  
 369      // HTML titles can't contain HTML code, so we strip HTML tags
 370      // and HTML escape the title.
 371      $PHORUM["DATA"]["HTML_TITLE"] = htmlentities(strip_tags($PHORUM["DATA"]["HTML_TITLE"]), ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
 372  
 373      // if the Phorum is disabled, display a message.
 374      if(isset($PHORUM["status"]) && $PHORUM["status"]=="admin-only" && !$PHORUM["user"]["admin"]){
 375          // set all our URL's
 376          phorum_build_common_urls();
 377  
 378          $PHORUM["DATA"]["MESSAGE"]=$PHORUM["DATA"]["LANG"]["AdminOnlyMessage"];
 379          include phorum_get_template("header");
 380          phorum_hook("after_header");
 381          include phorum_get_template("message");
 382          phorum_hook("before_footer");
 383          include phorum_get_template("footer");
 384          exit();
 385  
 386      }
 387  
 388  
 389      // a hook for rewriting vars at the end of common.php
 390      phorum_hook( "common", "" );
 391  
 392      $PHORUM['DATA']['USERINFO'] = $PHORUM['user'];
 393      $PHORUM['DATA']['PHORUM_PAGE'] = phorum_page;
 394      $PHORUM['DATA']['USERTRACK'] = $PHORUM['track_user_activity'];
 395  }
 396  
 397  
 398  //////////////////////////////////////////////////////////
 399  // functions
 400  
 401  /**
 402   * A common function to check that a user is logged in
 403   */
 404  function phorum_require_login()
 405  {
 406      $PHORUM = $GLOBALS['PHORUM'];
 407      if ( !$PHORUM["user"]["user_id"] ) {
 408          $url = phorum_get_url( PHORUM_LOGIN_URL, "redir=" . urlencode( $PHORUM["http_path"] . "/" . basename( $_SERVER["PHP_SELF"] ) . "?" . $_SERVER["QUERY_STRING"] ) );
 409          phorum_redirect_by_url( $url );
 410          exit();
 411      }
 412  }
 413  
 414  /**
 415   * A common function for checking the read-permissions for a forum-page
 416   * returns false if access is not allowed and an error page-was output
 417   */
 418  function phorum_check_read_common()
 419  {
 420      $PHORUM = $GLOBALS['PHORUM'];
 421  
 422      $retval = true;
 423  
 424      if ( $PHORUM["forum_id"] > 0 && !$PHORUM["folder_flag"] && !phorum_user_access_allowed( PHORUM_USER_ALLOW_READ ) ) {
 425          if ( $PHORUM["DATA"]["LOGGEDIN"] ) {
 426              // if they are logged in and not allowed, they don't have rights
 427              $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["NoRead"];
 428          } else {
 429              // check if they could read if logged in.
 430              // if so, let them know to log in.
 431              if ( ( empty( $PHORUM["DATA"]["POST"]["parentid"] ) && $PHORUM["reg_perms"] &PHORUM_USER_ALLOW_READ ) ) {
 432                  $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["PleaseLoginRead"];
 433              } else {
 434                  $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["NoRead"];
 435              }
 436          }
 437  
 438          phorum_build_common_urls();
 439  
 440          include phorum_get_template( "header" );
 441          phorum_hook( "after_header" );
 442          include phorum_get_template( "message" );
 443          phorum_hook( "before_footer" );
 444          include phorum_get_template( "footer" );
 445  
 446          $retval = false;
 447      }
 448  
 449      return $retval;
 450  }
 451  
 452  // used for all url creation.
 453  function phorum_get_url()
 454  {
 455      $PHORUM = $GLOBALS["PHORUM"];
 456  
 457      $args = "";
 458      $url = "";
 459      $suffix = "";
 460      $add_forum_id = false;
 461      $add_get_vars = true;
 462  
 463      $argv = func_get_args();
 464      $type = array_shift( $argv );
 465  
 466      switch ( $type ) {
 467          case PHORUM_LIST_URL:
 468              $page = "list";
 469              if ( empty( $argv ) ) $add_forum_id = true;
 470              break;
 471          case PHORUM_READ_URL:
 472              $page = "read";
 473              $add_forum_id = true;
 474              if ( !empty( $argv[1] ) && is_numeric( $argv[1] ) ) $suffix = "#msg-$argv[1]";
 475              break;
 476          case PHORUM_FOREIGN_READ_URL:
 477              $page = "read";
 478              if ( !empty( $argv[2] ) && is_numeric( $argv[2] ) ) $suffix = "#msg-$argv[2]";
 479              break;
 480          case PHORUM_REPLY_URL:
 481              if(isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]){
 482                  $page = "read";
 483                  $suffix = "#REPLY";
 484              } else {
 485                  $page = "posting";
 486                  // For reply on a separate page, we call posting.php on its own.
 487                  // In that case argv[0] is the editor mode we want to use
 488                  // (reply in this case). Currently, the thread id is in argv[0],
 489                  // but we don't need that one for posting.php. So we simply
 490                  // replace argv[0] with the correct argument.
 491                  $argv[0] = "reply";
 492              }
 493              $add_forum_id = true;
 494              break;
 495          case PHORUM_POSTING_URL:
 496              $page = "posting";
 497              $add_forum_id = true;
 498              break;
 499          case PHORUM_REDIRECT_URL:
 500              $page = "redirect";
 501              $add_forum_id = false;
 502              break;
 503          case PHORUM_SEARCH_URL:
 504              $page = "search";
 505              $add_forum_id = true;
 506              break;
 507          case PHORUM_SEARCH_ACTION_URL:
 508              $page = "search";
 509              $add_get_vars = true;
 510              break;
 511          case PHORUM_DOWN_URL:
 512              $page = "down";
 513              $add_forum_id = true;
 514              break;
 515          case PHORUM_VIOLATION_URL:
 516              $page = "violation";
 517              $add_forum_id = true;
 518              break;
 519          case PHORUM_INDEX_URL:
 520              $page = "index";
 521              break;
 522          case PHORUM_LOGIN_URL:
 523              $page = "login";
 524              $add_forum_id = true;
 525              break;
 526          case PHORUM_LOGIN_ACTION_URL:
 527              $page = "login";
 528              break;
 529          case PHORUM_REGISTER_URL:
 530              $page = "register";
 531              $add_forum_id = true;
 532              break;
 533          case PHORUM_REGISTER_ACTION_URL:
 534              $page = "register";
 535              break;
 536          case PHORUM_PROFILE_URL:
 537              $page = "profile";
 538              $add_forum_id = true;
 539              break;
 540          case PHORUM_SUBSCRIBE_URL:
 541              $page = "subscribe";
 542              $add_forum_id = true;
 543              break;
 544          case PHORUM_MODERATION_URL:
 545              $page = "moderation";
 546              $add_forum_id = true;
 547              break;
 548          case PHORUM_MODERATION_ACTION_URL:
 549              $page = "moderation";
 550              $add_get_vars = false;
 551              break;
 552          case PHORUM_PREPOST_URL:
 553              $page = "control";
 554              $argv[] = "panel=messages";
 555              $add_forum_id = true;
 556              break;
 557          case PHORUM_CONTROLCENTER_URL:
 558              $page = "control";
 559              $add_forum_id = true;
 560              break;
 561          case PHORUM_CONTROLCENTER_ACTION_URL:
 562              $page = "control";
 563              $add_forum_id = true;
 564              break;
 565          case PHORUM_PM_URL:
 566              $page = "pm";
 567              $add_forum_id = true;
 568              break;
 569          case PHORUM_PM_ACTION_URL:
 570              $page = "pm";
 571              break;
 572          case PHORUM_FILE_URL:
 573              $page = "file";
 574              $add_forum_id = true;
 575              break;
 576          case PHORUM_FOLLOW_URL:
 577              $page = "follow";
 578              $add_forum_id = true;
 579              break;
 580          case PHORUM_FOLLOW_ACTION_URL:
 581              $page = "follow";
 582              $add_forum_id = false;
 583              break;
 584          case PHORUM_REPORT_URL:
 585              $page = "report";
 586              $add_forum_id = true;
 587              break;
 588          case PHORUM_RSS_URL:
 589              switch(phorum_page){
 590                  case "list":
 591                      $add_forum_id = true;
 592                      break;
 593                  case "read":
 594                      $add_forum_id = true;
 595                      $thread_id = (int)$PHORUM["args"][1];
 596                      array_push($argv, $thread_id);
 597                      break;
 598              }
 599              $page = "rss";
 600              break;
 601          // this is for adding own generic urls
 602          case PHORUM_CUSTOM_URL:
 603              $page = array_shift($argv); // first arg is our page
 604              $add_forum_id_tmp=array_shift($argv); // second determining if we should add the forum_id
 605              $add_forum_id = $add_forum_id_tmp?true:false;
 606              break;
 607  
 608          case PHORUM_ADDON_URL:
 609              $page = "addon";
 610              $add_forum_id = true;
 611              if (!isset($argv[0])) {
 612                 trigger_error('Missing "module" argument for PHORUM_ADDON_URL');
 613              }
 614              if (substr($argv[0], 0, 7) != "module=") {
 615                  $argv[0] = "module={$argv[0]}";
 616              }
 617              break;
 618  
 619          case PHORUM_BASE_URL:
 620              // only to flag phorum_custom_get_url() that base url is requested
 621              $page = '';
 622              break;
 623  
 624          default:
 625              trigger_error( "Unhandled page type.", E_USER_WARNING );
 626              break;
 627      }
 628  
 629      // build the query string
 630      $query_items = array();
 631  
 632      if ( $add_forum_id ) {
 633          $query_items[] = ( int )$PHORUM["forum_id"];
 634      }
 635  
 636      if ( count( $argv ) > 0 ) {
 637          $query_items = array_merge( $query_items, $argv );
 638      }
 639  
 640      if ( !empty( $PHORUM["DATA"]["GET_VARS"] ) && $add_get_vars ) {
 641          $query_items = array_merge( $query_items, $PHORUM["DATA"]["GET_VARS"] );
 642      }
 643      // build the url
 644      if ( !function_exists( "phorum_custom_get_url" ) ) {
 645          if ($type == PHORUM_BASE_URL) return $PHORUM["http_path"] . '/';
 646  
 647          $url = "$PHORUM[http_path]/$page." . PHORUM_FILE_EXTENSION;
 648  
 649          if ( count( $query_items ) ) $url .= "?" . implode( ",", $query_items );
 650  
 651          if ( !empty( $suffix ) ) $url .= $suffix;
 652      } else {
 653          $url = phorum_custom_get_url( $page, $query_items, $suffix );
 654      }
 655  
 656      return $url;
 657  }
 658  
 659  // retrieve the appropriate template file name
 660  function phorum_get_template( $page, $is_include = false )
 661  {
 662      $PHORUM = $GLOBALS["PHORUM"];
 663  
 664      $page = basename($page);
 665  
 666      // Check for a module reference in the page name.
 667      $module = NULL;
 668      $fullpage = $page;
 669      $prefix = "./templates";
 670      if (($pos = strpos($fullpage, "::", 1)) !== false) {
 671          $module = substr($fullpage, 0, $pos);
 672          $page = substr($fullpage, $pos+2);
 673          $prefix = "./mods/$module/templates";
 674      }
 675  
 676      if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_template'] ) && !empty($PHORUM['user']['user_template'])) {
 677          $PHORUM['template'] = $PHORUM['user']['user_template'];
 678      }
 679  
 680      // If no user template is set or if the template folder cannot be found,
 681      // fallback to the default template.
 682      if (empty($PHORUM["template"]) || !file_exists("$prefix/{$PHORUM['template']}")) {
 683          $PHORUM["template"] = $PHORUM["default_template"];
 684          if ($PHORUM["template"] != "default" && !file_exists("$prefix/{$PHORUM['template']}")) {
 685              $PHORUM["template"] = "default";
 686          }
 687      }
 688  
 689      $tpl = "$prefix/$PHORUM[template]/$page";
 690      // check for straight PHP file
 691      if ( file_exists( "$tpl.php" ) ) {
 692          $phpfile = "$tpl.php";
 693      } else {
 694          // not there, look for a template
 695          $tplfile = "$tpl.tpl";
 696          $safetemplate = str_replace(array("-",":"), array("_","_"), $PHORUM["template"]);
 697          if ($module !== NULL) $page = "$module::$page";
 698          $safepage = str_replace(array("-",":"), array("_","_"), $page);
 699          $phpfile = "$PHORUM[cache]/tpl-$safetemplate-$safepage-" .
 700                 ($is_include ? "include" : "toplevel") . "-" .
 701                 md5( dirname( __FILE__ . $prefix) ) . ".php";
 702  
 703          if ( $is_include || !file_exists( $phpfile ) ) {
 704              include_once  "./include/templates.php";
 705              phorum_import_template( $tplfile, $phpfile, $page );
 706          }
 707      }
 708  
 709      return $phpfile;
 710  }
 711  
 712  // creates URLs used on most pages
 713  function phorum_build_common_urls()
 714  {
 715      $PHORUM=$GLOBALS['PHORUM'];
 716  
 717      $GLOBALS["PHORUM"]["DATA"]["URL"]["TOP"] = phorum_get_url( PHORUM_LIST_URL );
 718      // those links are only needed in forums, not in folders
 719      if(isset($PHORUM['folder_flag']) && !$PHORUM['folder_flag']) {
 720          $GLOBALS["PHORUM"]["DATA"]["URL"]["MARKREAD"] = phorum_get_url( PHORUM_LIST_URL, "markread=1" );
 721          $GLOBALS["PHORUM"]["DATA"]["URL"]["POST"] = phorum_get_url( PHORUM_POSTING_URL );
 722          $GLOBALS["PHORUM"]["DATA"]["URL"]["SUBSCRIBE"] = phorum_get_url( PHORUM_SUBSCRIBE_URL );
 723      }
 724  
 725      // those are general urls, needed nearly everywhere
 726      $GLOBALS["PHORUM"]["DATA"]["URL"]["SEARCH"] = phorum_get_url( PHORUM_SEARCH_URL );
 727  
 728      // RSS-Url only makes sense on a couple of pages
 729      if(isset($PHORUM['use_rss']) && $PHORUM['use_rss']
 730          && (phorum_page=="index" || phorum_page=="list" || phorum_page=="read")){
 731          $GLOBALS["PHORUM"]["DATA"]["URL"]["RSS"] = phorum_get_url( PHORUM_RSS_URL );
 732      }
 733  
 734      $index_id=-1;
 735      // in a folder
 736  
 737      if( $PHORUM['folder_flag'] && phorum_page != 'index'
 738      && ($PHORUM['forum_id'] == 0 || $PHORUM['vroot'] == $PHORUM['forum_id'])) {
 739          // folder where we usually don't show the index-link but on
 740          // additional pages like search and login its shown
 741          $index_id=$PHORUM['forum_id'];
 742  
 743      } elseif( ( $PHORUM['folder_flag'] &&
 744      ($PHORUM['forum_id'] != 0 && $PHORUM['vroot'] != $PHORUM['forum_id'])) ||
 745      (!$PHORUM['folder_flag'] && $PHORUM['active'])) {
 746          // either a folder where the link should be shown (not vroot or root)
 747          // or an active forum where the link should be shown
 748  
 749          if(isset($PHORUM["use_new_folder_style"]) && $PHORUM["use_new_folder_style"] ) {
 750              // go to root or vroot
 751              $index_id=$PHORUM["vroot"]; // vroot is either 0 (root) or another id
 752  
 753          } else {
 754              // go to parent
 755              $index_id=$PHORUM["parent_id"]; // parent_id is always set now
 756  
 757          }
 758  
 759      }
 760      if($index_id > -1) {
 761          // check if its the full root, avoid adding an id in this case (SE-optimized ;))
 762          if (!empty($index_id))
 763              $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL, $index_id );
 764          else
 765              $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL );
 766      }
 767  
 768      // these urls depend on the login-status of a user
 769      if ( $GLOBALS["PHORUM"]["DATA"]["LOGGEDIN"] ) {
 770          $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL, "logout=1" );
 771          $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_CONTROLCENTER_URL );
 772          $GLOBALS["PHORUM"]["DATA"]["URL"]["PM"] = phorum_get_url( PHORUM_PM_URL );
 773      } else {
 774          $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL );
 775          $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_REGISTER_URL );
 776      }
 777  }
 778  
 779  // calls phorum mod functions
 780  function phorum_hook( $hook )
 781  {
 782      $PHORUM = $GLOBALS["PHORUM"];
 783  
 784      // get arguments passed to the function
 785      $args = func_get_args();
 786  
 787      // shift off hook name
 788      array_shift($args);
 789  
 790      if ( isset( $PHORUM["hooks"][$hook] ) && is_array($PHORUM["hooks"][$hook])) {
 791  
 792          foreach( $PHORUM["hooks"][$hook]["mods"] as $mod ) {
 793              // load mods for this hook
 794              $mod = basename($mod);
 795              if ( file_exists( "./mods/$mod/$mod.php" ) ) {
 796                  include_once "./mods/$mod/$mod.php";
 797              } elseif ( file_exists( "./mods/$mod.php" ) ) {
 798                  include_once "./mods/$mod.php";
 799              }
 800          }
 801  
 802          foreach( $PHORUM["hooks"][$hook]["funcs"] as $func ) {
 803              // call functions for this hook
 804              if ( function_exists( $func ) ) {
 805                  if(count($args)){
 806                      $args[0] = call_user_func_array( $func, $args );
 807                  } else {
 808                      call_user_func( $func );
 809                  }
 810              }
 811          }
 812      }
 813  
 814      if(isset($args[0])){
 815          return $args[0];
 816      }
 817  }
 818  
 819  // HTML encodes a string
 820  function phorum_html_encode( $string )
 821  {
 822      $ret_string = "";
 823      $len = strlen( $string );
 824      for( $x = 0;$x < $len;$x++ ) {
 825          $ord = ord( $string[$x] );
 826          $ret_string .= "&#$ord;";
 827      }
 828      return $ret_string;
 829  }
 830  
 831  // removes slashes from all array-entries
 832  function phorum_recursive_stripslashes( $array )
 833  {
 834      if ( !is_array( $array ) ) {
 835          return $array;
 836      } else {
 837          foreach( $array as $key => $value ) {
 838              if ( !is_array( $value ) )
 839                  $array[$key] = stripslashes( $value );
 840              else
 841                  $array[$key] = phorum_recursive_stripslashes( $value );
 842          }
 843      }
 844      return $array;
 845  }
 846  
 847  // returns the available templates as an array
 848  function phorum_get_template_info()
 849  {
 850      $tpls = array();
 851  
 852      $d = dir( "./templates" );
 853      while ( false !== ( $entry = $d->read() ) ) {
 854          if ( $entry != "." && $entry != ".." && file_exists( "./templates/$entry/info.php" ) ) {
 855              include "./templates/$entry/info.php";
 856              if ( !isset( $template_hide ) || empty( $template_hide ) || defined( "PHORUM_ADMIN" ) ) {
 857                  $tpls[$entry] = "$name $version";
 858              } else {
 859                  unset( $template_hide );
 860              }
 861          }
 862      }
 863  
 864      return $tpls;
 865  }
 866  
 867  // returns the available languages as an array
 868  function phorum_get_language_info()
 869  {
 870      $langs = array();
 871  
 872      $d = dir( "./include/lang" );
 873      while ( false !== ( $entry = $d->read() ) ) {
 874          if ( substr( $entry, -4 ) == ".php" && is_file( "./include/lang/$entry" ) ) {
 875              @include "./include/lang/$entry";
 876              if ( !isset( $language_hide ) || empty( $language_hide ) || defined( "PHORUM_ADMIN" ) ) {
 877                  $langs[str_replace( ".php", "", $entry )] = $language;
 878              } else {
 879                  unset( $language_hide );
 880              }
 881          }
 882      }
 883  
 884      asort($langs, SORT_STRING);
 885  
 886      return $langs;
 887  }
 888  
 889  function phorum_redirect_by_url( $redir_url )
 890  {
 891      // check for response splitting and valid http(s) URLs
 892      if(preg_match("/\s/", $redir_url) || !preg_match("!^https?://!i", $redir_url)){
 893          $redir_url = phorum_get_url(PHORUM_INDEX_URL);
 894      }
 895  
 896      if ( stristr( $_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS" ) ) {
 897          // the ugly IIS-hack to avoid crashing IIS
 898          print "<html><head>\n<title>Redirecting ...</title>\n";
 899          print "<meta http-equiv=\"refresh\" content=\"0; URL=$redir_url\">";
 900          print "</head>\n";
 901          print "<body><a href=\"$redir_url\">Redirecting ...</a></body>\n";
 902          print "</html>";
 903      } else {
 904          // our standard-way
 905          header( "Location: $redir_url" );
 906      }
 907      exit(0);
 908  }
 909  
 910  // might remove these, might not.  Need it for debugging.
 911  function print_var( $var )
 912  {
 913      echo "<xmp>";
 914      print_r( $var );
 915      echo "</xmp>";
 916  }
 917  
 918  /**
 919   * Generates an MD5 signature for a piece of data using Phorum's secret
 920   * private key. This can be used to sign data which travels an unsafe path
 921   * (for example data that is sent to a user's browser and then back to
 922   * Phorum) and for which tampering should be prevented.
 923   *
 924   * @param $data The data to sign.
 925   * @return $signature The signature for the data.
 926   */
 927  function phorum_generate_data_signature($data)
 928  {
 929     $signature = md5($data . $GLOBALS["PHORUM"]["private_key"]);
 930     return $signature;
 931  }
 932  
 933  /**
 934   * Checks whether the signature for a piece of data is valid.
 935   *
 936   * @param $data The signed data.
 937   * @param $signature The signature for the data.
 938   * @return True in case the signature is okay, false otherwise.
 939   */
 940  function phorum_check_data_signature($data, $signature)
 941  {
 942      return md5($data . $GLOBALS["PHORUM"]["private_key"]) == $signature;
 943  }
 944  
 945  /**
 946   * Generate a debug back trace. 
 947   *
 948   * @param $skip       - The amount of back trace levels to skip. The call
 949   *                      to this function is skipped by default, so you don't
 950   *                      have to count that in.
 951   * @param $hidepath   - NULL to not hide paths or a string to replace the
 952   *                      Phorum path with.
 953   *
 954   * @return $backtrace - The back trace in text format or NULL if no back trace
 955   *                      was generated.
 956   */
 957  function phorum_generate_backtrace($skip = 0, $hidepath = "{path to Phorum}")
 958  {
 959      // Allthough Phorum 4.3.0 is the required PHP version
 960      // for Phorum at the time of writing, people might still be running
 961      // Phorum on older PHP versions. For those people, we'll skip
 962      // creation of a back trace.
 963  
 964      $backtrace = NULL;
 965  
 966      if (function_exists("debug_backtrace"))
 967      {
 968          $bt = debug_backtrace();
 969          $mypath = dirname(__FILE__);
 970          $backtrace = '';
 971  
 972          foreach ($bt as $id => $step)
 973          {
 974              // Don't include the call to this function.
 975              if ($id == 0) continue;
 976  
 977              // Skip the required number of steps. 
 978              if ($id <= $skip) continue;
 979  
 980              if ($hidepath !== NULL && isset($step["file"])) {
 981                  $file = str_replace($mypath, $hidepath, $step["file"]);
 982              }
 983              $backtrace .= "Function " . $step["function"] . " called" .
 984                            (!empty($step["line"])
 985                             ? " at\n" .  $file . ":" . $step["line"]
 986                             : "") . "\n----\n";
 987          }
 988      }
 989  
 990      return $backtrace;
 991  }
 992  
 993  ?>


Généré le : Thu Nov 29 12:22:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics