[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> admin.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      // Phorum 5 Admin
  21  
  22      define("PHORUM_ADMIN", 1);
  23  
  24      // set a sane error level for our admin.
  25      // this will make the coding time faster and
  26      // the code run faster.
  27      error_reporting  (E_ERROR | E_WARNING | E_PARSE);
  28  
  29      include_once  "./common.php";
  30      include_once  "./include/users.php";
  31  
  32      // determine absolute URI for the admin
  33      if(isset($_SERVER["SCRIPT_URI"])){
  34          $PHORUM["admin_http_path"] = $_SERVER["SCRIPT_URI"];
  35      } else {
  36          $protocol = (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]!="off") ? "https" : "http";
  37          $port = ($_SERVER["SERVER_PORT"]!=443 && $_SERVER["SERVER_PORT"]!=80) ? ":".$_SERVER["SERVER_PORT"] : "";
  38          $PHORUM["admin_http_path"] = $protocol."://".$_SERVER["HTTP_HOST"].$port.$_SERVER["PHP_SELF"];
  39      }
  40  
  41      // determine http_path (at install time; after that it's in the settings)
  42      if(!isset($PHORUM["http_path"])){
  43          $PHORUM["http_path"] = dirname($_SERVER["PHP_SELF"]);
  44      }
  45  
  46      // if we are installing or upgrading, we don't need to check for a session
  47      // 2005081000 was the internal version that introduced the installed flag
  48      if(!isset($PHORUM['internal_version']) || (!isset($PHORUM['installed']) && $PHORUM['internal_version']>='2005081000')) {
  49  
  50          // this is an install
  51          $module="install";
  52  
  53      } elseif (isset($PHORUM['internal_version']) && $PHORUM['internal_version'] < PHORUMINTERNAL) {
  54  
  55          // this is an upgrade
  56          $module="upgrade";
  57  
  58      } else {
  59  
  60          // check for a session
  61          phorum_user_check_session(PHORUM_SESSION_ADMIN);
  62  
  63          if(!isset($GLOBALS["PHORUM"]["user"]) || !$GLOBALS["PHORUM"]["user"]["admin"]){
  64              // if not an admin
  65              unset($GLOBALS["PHORUM"]["user"]);
  66              $module="login";
  67          } else {
  68              // load the default module if none is specified
  69              if(!empty($_REQUEST["module"]) && is_string($_REQUEST["module"])){
  70                  $module = @basename($_REQUEST["module"]);
  71              } else {
  72                  $module = "default";
  73              }
  74  
  75          }
  76  
  77      }
  78  
  79      $module = phorum_hook( "admin_pre", $module );
  80      ob_start();
  81      if($module!="help") include_once  "./include/admin/header.php";
  82      @include_once "./include/admin/$module.php";
  83      if($module!="help") include_once  "./include/admin/footer.php";
  84      ob_end_flush();
  85  
  86  
  87  /////////////////////////////////////////////////
  88  
  89      function phorum_admin_error($error)
  90      {
  91          echo "<div class=\"PhorumAdminError\">$error</div>\n";
  92      }
  93  
  94      function phorum_admin_okmsg($error)
  95      {
  96          echo "<div class=\"PhorumAdminOkMsg\">$error</div>\n";
  97      }
  98      // phorum_get_language_info and phorum_get_template_info moved to common.php (used in the cc too)
  99  
 100      function phorum_get_folder_info()
 101      {
 102          $folders=array();
 103  
 104          $forums = phorum_db_get_forums();
 105  
 106          foreach($forums as $forum){
 107              if($forum["folder_flag"]){
 108                  $path = $forum["name"];
 109                  $parent_id=$forum["parent_id"];
 110                  while($parent_id!=0  && $parent_id!=$forum["forum_id"]){
 111                      $path=$forums[$parent_id]["name"]."::$path";
 112                      $parent_id=$forums[$parent_id]["parent_id"];
 113                  }
 114                  $folders[$forum["forum_id"]]=$path;
 115              }
 116          }
 117  
 118          asort($folders);
 119  
 120          $tmp=array("--None--");
 121  
 122          foreach($folders as $id => $folder){
 123              $tmp[$id]=$folder;
 124          }
 125  
 126          $folders=$tmp;
 127  
 128          return $folders;
 129  
 130      }
 131  
 132      /*
 133       *
 134       * $forums_only can be 0,1,2
 135       * 0 = all forums / folders
 136       * 1 = all forums
 137       * 2 = only forums + vroot-folders (used in banlists)
 138       * 3 = only vroot-folders
 139       *
 140       * $vroot can be -1,0 or > 0
 141       * -1 works as told above
 142       * 0 returns only forums / folders with vroot = 0
 143       * > 0 returns only forums / folders with the given vroot
 144       *
 145       */
 146  
 147      function phorum_get_forum_info($forums_only=0,$vroot = -1)
 148      {
 149          $folders=array();
 150  
 151          $forums = phorum_db_get_forums();
 152  
 153          foreach($forums as $forum){
 154  
 155              if( (
 156                      $forums_only == 0 ||
 157                      ($forum['folder_flag'] == 0 && $forums_only != 3) ||
 158                      ($forums_only==2 && $forum['vroot'] > 0 && $forum['vroot'] == $forum['forum_id']) ||
 159                      ($forums_only==3 && $forum['vroot'] == $forum['forum_id'])
 160                  ) && ($vroot == -1 || $vroot == $forum['vroot']) )  {
 161  
 162  
 163                  $path = $forum["name"];
 164                  $parent_id=$forum["parent_id"];
 165  
 166                  while( $parent_id!=0 ){
 167                      $path=$forums[$parent_id]["name"]."::$path";
 168                      $parent_id=$forums[$parent_id]["parent_id"];
 169                  }
 170  
 171                  if($forums_only!=3 && $forum['vroot'] && $forum['vroot']==$forum['forum_id']) {
 172                      $path.=" (Virtual Root)";
 173                  }
 174                  $folders[$forum["forum_id"]]=$path;
 175              }
 176          }
 177  
 178          asort($folders,SORT_STRING);
 179  
 180          return $folders;
 181      }
 182  
 183  
 184      /*
 185       * Sets the given vroot for the descending forums / folders
 186       * which are not yet in another descending vroot
 187       *
 188       * $folder = folder from which we should go down
 189       * $vroot  = virtual root we set the folders/forums to
 190       * $old_vroot = virtual root which should be overrideen with the new value
 191       *
 192       */
 193      function phorum_admin_set_vroot($folder,$vroot=-1,$old_vroot=0) {
 194          // which vroot
 195          if($vroot == -1) {
 196              $vroot=$folder;
 197          }
 198  
 199          // get the desc forums/folders
 200          $descending=phorum_admin_get_descending($folder);
 201          $valid=array();
 202  
 203          // collecting vroots
 204          $vroots=array();
 205          foreach($descending as $id => $data) {
 206              if($data['folder_flag'] == 1 && $data['vroot'] != 0 && $data['forum_id'] == $data['vroot']) {
 207                  $vroots[$data['vroot']]=true;
 208              }
 209          }
 210  
 211          // getting forums which are not in a vroot or not in *this* vroot
 212          foreach($descending as $id => $data) {
 213              if($data['vroot'] == $old_vroot || !isset($vroots[$data['vroot']])) {
 214                  $valid[$id]=$data;
 215              }
 216          }
 217  
 218          // $valid = forums/folders which are not in another vroot
 219          $set_ids=array_keys($valid);
 220          $set_ids[]=$folder;
 221  
 222          $new_forum_data=array('forum_id'=>$set_ids,'vroot'=>$vroot);
 223          $returnval=phorum_db_update_forum($new_forum_data);
 224  
 225          return $returnval;
 226      }
 227  
 228      function phorum_admin_get_descending($parent) {
 229  
 230          $ret_data=array();
 231          $arr_data=phorum_db_get_forums(0,$parent);
 232          foreach($arr_data as $key => $val) {
 233              $ret_data[$key]=$val;
 234              if($val['folder_flag'] == 1) {
 235                  $more_data=phorum_db_get_forums(0,$val['forum_id']);
 236                  $ret_data=$ret_data + $more_data; // array_merge reindexes the array
 237              }
 238          }
 239          return $ret_data;
 240      }
 241  
 242      function phorum_upgrade_tables($fromversion,$toversion) {
 243  
 244            $PHORUM=$GLOBALS['PHORUM'];
 245  
 246            if(empty($fromversion) || empty($toversion)){
 247                die("Something is wrong with the upgrade script.  Please contact the Phorum Dev Team. ($fromversion,$toversion)");
 248            }
 249  
 250            $msg="";
 251            $upgradepath="./include/db/upgrade/{$PHORUM['DBCONFIG']['type']}/";
 252  
 253            // read in all existing files
 254            $dh=opendir($upgradepath);
 255            $upgradefiles=array();
 256            while ($file = readdir ($dh)) {
 257                if (substr($file,-4,4) == ".php") {
 258                    $upgradefiles[]=$file;
 259                }
 260            }
 261            unset($file);
 262            closedir($dh);
 263  
 264            // sorting by number
 265            sort($upgradefiles,SORT_NUMERIC);
 266            reset($upgradefiles);
 267  
 268            // advance to current version
 269            while(list($key,$val)=each($upgradefiles)) {
 270                if($val == $fromversion.".php")
 271                break;
 272            }
 273  
 274  
 275  
 276            // get the file for the next version (which we will upgrade to)
 277            list($dump,$file) = each($upgradefiles);
 278  
 279            // extract the pure version, needed as internal version
 280            $pure_version = basename($file,".php");
 281  
 282            if(empty($pure_version)){
 283                die("Something is wrong with the upgrade script.  Please contact the Phorum Dev Team. ($fromversion,$toversion)");
 284            }
 285  
 286  
 287            $upgradefile=$upgradepath.$file;
 288  
 289            if(file_exists($upgradefile)) {
 290                if (! is_readable($upgradefile))
 291                  die("$upgradefile is not readable. Make sure the file has got the neccessary permissions and try again.");
 292  
 293                $msg.="Upgrading from db-version $fromversion to $pure_version ... ";
 294                $upgrade_queries=array();
 295                include($upgradefile);
 296                $err=phorum_db_run_queries($upgrade_queries);
 297                if($err){
 298                    $msg.= "an error occured: $err ... try to continue.<br />\n";
 299                } else {
 300                    $msg.= "done.<br />\n";
 301                }
 302                $GLOBALS["PHORUM"]["internal_version"]=$pure_version;
 303                phorum_db_update_settings(array("internal_version"=>$pure_version));
 304            } else {
 305                $msg="Ooops, the upgradefile is missing. How could this happen?";
 306            }
 307  
 308            return $msg;
 309      }
 310  
 311      function phorum_admin_gen_compare($txt) {
 312          $func = 0;
 313          if($txt == "gt") {
 314              $func = create_function('$a, $b', 'return $a > $b;');
 315          } elseif($txt == "gte") {
 316              $func = create_function('$a, $b', 'return $a >= $b;');
 317          } elseif($txt == "lt") {
 318              $func = create_function('$a, $b', 'return $a < $b;');
 319          } elseif($txt == "lte") {
 320              $func = create_function('$a, $b', 'return $a <= $b;');
 321          } elseif($txt == "eq") {
 322              $func = create_function('$a, $b', 'return $a == $b;');
 323          }
 324          if(!$func) {
 325              phorum_admin_error("Invalid posts comparison operator.");
 326              return NULL;
 327          }
 328          return $func;
 329      }
 330  
 331      function phorum_admin_filter_arr($arr,$field,$value,$cmpfn) {
 332          $new = array();
 333          foreach($arr as $item){
 334              if(isset($item[$field]) && $cmpfn($item[$field],$value)) {
 335                  array_push($new,$item);
 336              }
 337          }
 338          return $new;
 339      }
 340  
 341  ?>


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