"Fossies" - the Fresh Open Source Software Archive

Member "impresscms-1.4.2/htdocs/install/class/settingmanager.php" (24 Dec 2020, 12767 Bytes) of package /linux/www/impresscms-1.4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "settingmanager.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 1.4.2_rc_vs_1.4.2 or 1.4.1_vs_1.4.2.

    1 <?php
    2 //  ------------------------------------------------------------------------ //
    3 //                XOOPS - PHP Content Management System                      //
    4 //                    Copyright (c) 2000 XOOPS.org                           //
    5 //                       <http://www.xoops.org/>                             //
    6 //  ------------------------------------------------------------------------ //
    7 //  This program is free software; you can redistribute it and/or modify     //
    8 //  it under the terms of the GNU General Public License as published by     //
    9 //  the Free Software Foundation; either version 2 of the License, or        //
   10 //  (at your option) any later version.                                      //
   11 //                                                                           //
   12 //  You may not change or alter any portion of this comment or credits       //
   13 //  of supporting developers from this source code or any supporting         //
   14 //  source code which is considered copyrighted (c) material of the          //
   15 //  original comment or credit authors.                                      //
   16 //                                                                           //
   17 //  This program is distributed in the hope that it will be useful,          //
   18 //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
   19 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
   20 //  GNU General Public License for more details.                             //
   21 //                                                                           //
   22 //  You should have received a copy of the GNU General Public License        //
   23 //  along with this program; if not, write to the Free Software              //
   24 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
   25 //  ------------------------------------------------------------------------ //
   26 
   27 /**
   28  * Settings manager Class
   29  *
   30  * @copyright   http://www.xoops.org/ The XOOPS Project
   31  * @copyright   XOOPS_copyrights.txt
   32  * @copyright   http://www.impresscms.org/ The ImpressCMS Project
   33  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
   34  * @package installer
   35  * @since   XOOPS
   36  * @author  http://www.xoops.org The XOOPS Project
   37  * @author  modified by UnderDog <underdog@impresscms.org>
   38  * @version $Id: settingmanager.php 12329 2013-09-19 13:53:36Z skenow $
   39  */
   40 
   41 /**
   42  * setting manager for XOOPS installer
   43  *
   44  * @author Haruki Setoyama  <haruki@planewave.org>
   45  * @version $Id: settingmanager.php 12329 2013-09-19 13:53:36Z skenow $
   46  * @access public
   47  **/
   48 class setting_manager {
   49 
   50     var $database;
   51     var $dbhost;
   52     var $dbuname;
   53     var $dbpass;
   54     var $dbname;
   55     var $prefix;
   56     var $db_pconnect;
   57     var $root_path;
   58     var $xoops_url;
   59 
   60     var $sanitizer;
   61 
   62     function __construct($post=false) {
   63 
   64         $this->sanitizer =& icms_core_Textsanitizer::getInstance();
   65         if ($post) {
   66             $this->readPost();
   67         } else {
   68             $this->database = 'mysql';
   69             $this->dbhost = 'localhost';
   70 
   71             $this->db_pconnect = 0;
   72 
   73             $this->root_path = str_replace("\\","/",getcwd()); // "
   74             $this->root_path = str_replace("/install", "", $this->root_path);
   75 
   76             $filepath = (! empty($_SERVER['REQUEST_URI']))
   77             ? dirname($_SERVER['REQUEST_URI'])
   78             : dirname($_SERVER['SCRIPT_NAME']);
   79 
   80             $filepath = str_replace("\\", "/", $filepath); // "
   81             $filepath = str_replace("/install", "", $filepath);
   82             if (substr($filepath, 0, 1) == "/") {
   83                 $filepath = substr($filepath,1);
   84             }
   85             if (substr($filepath, -1) == "/") {
   86                 $filepath = substr($filepath, 0, -1);
   87             }
   88             $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
   89             $this->xoops_url = (!empty($filepath)) ? $protocol.$_SERVER['HTTP_HOST']."/".$filepath : $protocol.$_SERVER['HTTP_HOST'];
   90 
   91             $this->prefix = $this->generatePrefix();
   92         }
   93     }
   94 
   95     function readPost() {
   96         if (isset($_POST['database']))
   97         $this->database = $this->sanitizer->stripSlashesGPC($_POST['database']);
   98         if (isset($_POST['dbhost']))
   99         $this->dbhost = $this->sanitizer->stripSlashesGPC($_POST['dbhost']);
  100         if (isset($_POST['dbuname']))
  101         $this->dbuname = $this->sanitizer->stripSlashesGPC($_POST['dbuname']);
  102         if (isset($_POST['dbpass']))
  103         $this->dbpass = $this->sanitizer->stripSlashesGPC($_POST['dbpass']);
  104         if (isset($_POST['dbname']))
  105         $this->dbname = $this->sanitizer->stripSlashesGPC($_POST['dbname']);
  106         if (isset($_POST['prefix']))
  107         $this->prefix = $this->sanitizer->stripSlashesGPC($_POST['prefix']);
  108         if (isset($_POST['db_pconnect']))
  109         $this->db_pconnect = (int) ($_POST['db_pconnect']) > 0 ? 1 : 0;
  110         if (isset($_POST['root_path']))
  111         $this->root_path = $this->sanitizer->stripSlashesGPC($_POST['root_path']);
  112         if (isset($_POST['xoops_url']))
  113         $this->xoops_url = $this->sanitizer->stripSlashesGPC($_POST['xoops_url']);
  114     }
  115 
  116     function readConstant() {
  117         if (defined('XOOPS_DB_TYPE'))
  118         $this->database = XOOPS_DB_TYPE;
  119         if (defined('XOOPS_DB_HOST'))
  120         $this->dbhost = XOOPS_DB_HOST;
  121         if (defined('XOOPS_DB_USER'))
  122         $this->dbuname = XOOPS_DB_USER;
  123         if (defined('XOOPS_DB_PASS'))
  124         $this->dbpass = XOOPS_DB_PASS;
  125         if (defined('XOOPS_DB_NAME'))
  126         $this->dbname = XOOPS_DB_NAME;
  127         if (defined('XOOPS_DB_PREFIX'))
  128         $this->prefix = XOOPS_DB_PREFIX;
  129         if (defined('XOOPS_DB_PCONNECT'))
  130         $this->db_pconnect = (int) (XOOPS_DB_PCONNECT) > 0 ? 1 : 0;
  131         if (defined('XOOPS_ROOT_PATH'))
  132         $this->root_path = XOOPS_ROOT_PATH;
  133         if (defined('XOOPS_URL'))
  134         $this->xoops_url = XOOPS_URL;
  135     }
  136 
  137     function checkData() {
  138         $ret = '';
  139         $error = array();
  140 
  141         if (empty($this->dbhost)) {
  142             $error[] = sprintf(_INSTALL_L57, _INSTALL_L27);
  143         }
  144         if (empty($this->dbname)) {
  145             $error[] = sprintf(_INSTALL_L57, _INSTALL_L29);
  146         }
  147         if (empty($this->prefix)) {
  148             $error[] = sprintf(_INSTALL_L57, _INSTALL_L30);
  149         }
  150         if (empty($this->root_path)) {
  151             $error[] = sprintf(_INSTALL_L57, _INSTALL_L55);
  152         }
  153         if (empty($this->xoops_url)) {
  154             $error[] = sprintf(_INSTALL_L57, _INSTALL_L56);
  155         }
  156 
  157         if (!empty($error)) {
  158             foreach ( $error as $err) {
  159                 $ret .=  "<p><span style='color:#ff0000;'><b>".$err."</b></span></p>\n";
  160             }
  161         }
  162 
  163         return $ret;
  164     }
  165 
  166     function editform() {
  167         $ret =
  168             "<table width='100%' class='outer' cellspacing='5'>
  169                 <tr>
  170                     <th colspan='2'></th>
  171                 </tr>
  172                 <tr valign='top' align='left'>
  173                     <td class='head'>
  174                         <b>"._INSTALL_L51."</b><br />
  175                         <span style='font-size:85%;'>"._INSTALL_L66."</span>
  176                     </td>
  177                     <td class='even'>
  178                         <select  size='1' name='database' id='database'>";
  179         $dblist = $this->getDBList();
  180         foreach ($dblist as $val) {
  181             $ret .= "<option value='$val'";
  182             if ($val == $this->database) $ret .= " selected='selected'";
  183             $ret .= "'>$val</option>";
  184         }
  185         $ret .=         "</select>
  186                     </td>
  187                 </tr>
  188                 ";
  189         $ret .= $this->editform_sub(_INSTALL_L27, _INSTALL_L67, 'dbhost', $this->sanitizer->htmlSpecialChars($this->dbhost));
  190         $ret .= $this->editform_sub(_INSTALL_L28, _INSTALL_L65, 'dbuname', $this->sanitizer->htmlSpecialChars($this->dbuname));
  191         $ret .= $this->editform_sub(_INSTALL_L52, _INSTALL_L68, 'dbpass', $this->sanitizer->htmlSpecialChars($this->dbpass));
  192         $ret .= $this->editform_sub(_INSTALL_L29, _INSTALL_L64, 'dbname', $this->sanitizer->htmlSpecialChars($this->dbname));
  193         $ret .= $this->editform_sub(_INSTALL_L30, _INSTALL_L63, 'prefix', $this->sanitizer->htmlSpecialChars($this->prefix));
  194 
  195         $ret .= "<tr valign='top' align='left'>
  196                     <td class='head'>
  197                         <b>"._INSTALL_L54."</b><br />
  198                         <span style='font-size:85%;'>"._INSTALL_L69."</span>
  199                     </td>
  200                     <td class='even'>
  201                         <input type='radio' name='db_pconnect' value='1'".($this->db_pconnect == 1 ? " checked='checked'" : "" )." />"._INSTALL_L23."
  202                         <input type='radio' name='db_pconnect' value='0'".($this->db_pconnect != 1 ? " checked='checked'" : "" )." />"._INSTALL_L24."
  203                     </td>
  204                 </tr>
  205                 ";
  206 
  207         $ret .= $this->editform_sub(_INSTALL_L55, _INSTALL_L59, 'root_path', $this->sanitizer->htmlSpecialChars($this->root_path));
  208         $ret .= $this->editform_sub(_INSTALL_L56, _INSTALL_L58, 'xoops_url', $this->sanitizer->htmlSpecialChars($this->xoops_url));
  209 
  210         $ret .= "</table>";
  211         return $ret;
  212     }
  213 
  214     function editform_sub($title, $desc, $name, $value) {
  215         $inputType = 'text';
  216         return  "<tr valign='top' align='left'>
  217                     <td class='head'>
  218                         <b>".$title."</b><br />
  219                         <span style='font-size:85%;'>".$desc."</span>
  220                     </td>
  221                     <td class='even'>
  222                         <input type='$inputType' name='".$name."' id='".$name."' size='30' maxlength='100' value='".htmlspecialchars($value)."' />
  223                     </td>
  224                 </tr>
  225                 ";
  226     }
  227 
  228     function confirmForm() {
  229         $yesno = empty($this->db_pconnect) ? _INSTALL_L24 : _INSTALL_L23;
  230         $ret =
  231             "<table border='0' cellpadding='0' cellspacing='0' valign='top' width='90%'><tr><td class='bg2'>
  232                 <table width='100%' border='0' cellpadding='4' cellspacing='1'>
  233                     <tr>
  234                         <td class='bg3'><b>"._INSTALL_L51."</b></td>
  235                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->database)."</td>
  236                     </tr>
  237                     <tr>
  238                         <td class='bg3'><b>"._INSTALL_L27."</b></td>
  239                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->dbhost)."</td>
  240                     </tr>
  241                     <tr>
  242                         <td class='bg3'><b>"._INSTALL_L28."</b></td>
  243                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->dbuname)."</td>
  244                     </tr>
  245                     <tr>
  246                         <td class='bg3'><b>"._INSTALL_L52."</b></td>
  247                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->dbpass)."</td>
  248                     </tr>
  249                     <tr>
  250                         <td class='bg3'><b>"._INSTALL_L29."</b></td>
  251                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->dbname)."</td>
  252                     </tr>
  253                     <tr>
  254                         <td class='bg3'><b>"._INSTALL_L30."</b></td>
  255                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->prefix)."</td>
  256                     </tr>
  257                     <tr>
  258                         <td class='bg3'><b>"._INSTALL_L54."</b></td>
  259                         <td class='bg1'>".$yesno."</td>
  260                     </tr>
  261                     <tr>
  262                         <td class='bg3'><b>"._INSTALL_L55."</b></td>
  263                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->root_path)."</td>
  264                     </tr>
  265                     <tr>
  266                         <td class='bg3'><b>"._INSTALL_L56."</b></td>
  267                         <td class='bg1'>".$this->sanitizer->htmlSpecialChars($this->xoops_url)."</td>
  268                     </tr>
  269                 </table></td></tr>
  270             </table>
  271             <input type='hidden' name='database' value='".$this->sanitizer->htmlSpecialChars($this->database)."' />
  272             <input type='hidden' name='dbhost' value='".$this->sanitizer->htmlSpecialChars($this->dbhost)."' />
  273             <input type='hidden' name='dbuname' value='".$this->sanitizer->htmlSpecialChars($this->dbuname)."' />
  274             <input type='hidden' name='dbpass' value='".$this->sanitizer->htmlSpecialChars($this->dbpass)."' />
  275             <input type='hidden' name='dbname' value='".$this->sanitizer->htmlSpecialChars($this->dbname)."' />
  276             <input type='hidden' name='prefix' value='".$this->sanitizer->htmlSpecialChars($this->prefix)."' />
  277             <input type='hidden' name='db_pconnect' value='". (int) ($this->db_pconnect)."' />
  278             <input type='hidden' name='root_path' value='".$this->sanitizer->htmlSpecialChars($this->root_path)."' />
  279             <input type='hidden' name='xoops_url' value='".$this->sanitizer->htmlSpecialChars($this->xoops_url)."' />
  280             ";
  281         return $ret;
  282     }
  283 
  284     function getDBList()
  285     {
  286         $dirname = '../class/database/drivers';
  287         $list = icms_core_Filesystem::getDirList($dirname);
  288         // TODO: Add any verification of compatibility between the database drivers and the system.
  289         return $list;
  290     }
  291 
  292     function generatePrefix() {
  293         include_once $this->root_path."/include/functions.php";
  294         return icms_core_Password::createSalt(5);;
  295     }
  296 }