includes/dbal.php
changeset 322 5f1cd51bf1be
parent 320 112debff64bd
child 326 ab66d6d1f1f4
equal deleted inserted replaced
320:112debff64bd 322:5f1cd51bf1be
   118                       Most recent SQL query:</p>
   118                       Most recent SQL query:</p>
   119                       <pre>'.$bt.'</pre>';
   119                       <pre>'.$bt.'</pre>';
   120     return $internal_text;
   120     return $internal_text;
   121   }
   121   }
   122   
   122   
   123   function connect()
   123   function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false)
   124   {
   124   {
   125     $this->enable_errorhandler();
   125     $this->enable_errorhandler();
   126     
   126     
   127     define('ENANO_DBLAYER', 'MYSQL');
   127     define('ENANO_DBLAYER', 'MYSQL');
   128     define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
   128     define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
   129     define('ENANO_SQL_MULTISTRING_PRFIX', '');
   129     define('ENANO_SQL_MULTISTRING_PRFIX', '');
   130     define('ENANO_SQL_BOOLEAN_TRUE', 'true');
   130     define('ENANO_SQL_BOOLEAN_TRUE', 'true');
   131     define('ENANO_SQL_BOOLEAN_FALSE', 'false');
   131     define('ENANO_SQL_BOOLEAN_FALSE', 'false');
   132     
   132     
   133     if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
   133     if ( !$manual_credentials )
   134     {
   134     {
   135       @include(ENANO_ROOT.'/config.new.php');
   135       if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
   136     }
   136       {
   137     else
   137         @include(ENANO_ROOT.'/config.new.php');
   138     {
   138       }
   139       @include(ENANO_ROOT.'/config.php');
   139       else
   140     }
   140       {
       
   141         @include(ENANO_ROOT.'/config.php');
       
   142       }
       
   143         
       
   144       if ( isset($crypto_key) )
       
   145         unset($crypto_key); // Get this sucker out of memory fast
   141       
   146       
   142     if ( isset($crypto_key) )
   147       if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   143       unset($crypto_key); // Get this sucker out of memory fast
   148       {
   144     
   149         // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
   145     if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   150         if ( !defined('scriptPath') )
   146     {
       
   147       // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
       
   148       if ( !defined('scriptPath') )
       
   149       {
       
   150         if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
       
   151         {
   151         {
   152           $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
   152           if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
       
   153           {
       
   154             $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
       
   155           }
       
   156           if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
       
   157           {
       
   158             // user requested http://foo/enano as opposed to http://foo/enano/index.php
       
   159             $_SERVER['REQUEST_URI'] .= '/index.php';
       
   160           }
       
   161           $sp = dirname($_SERVER['REQUEST_URI']);
       
   162           if($sp == '/' || $sp == '\\') $sp = '';
       
   163           define('scriptPath', $sp);
       
   164           define('contentPath', "$sp/index.php?title=");
   153         }
   165         }
   154         if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
   166         $loc = scriptPath . '/install.php';
   155         {
   167         // header("Location: $loc");
   156           // user requested http://foo/enano as opposed to http://foo/enano/index.php
   168         redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
   157           $_SERVER['REQUEST_URI'] .= '/index.php';
   169         exit;
   158         }
   170       }
   159         $sp = dirname($_SERVER['REQUEST_URI']);
   171     }
   160         if($sp == '/' || $sp == '\\') $sp = '';
   172     
   161         define('scriptPath', $sp);
       
   162         define('contentPath', "$sp/index.php?title=");
       
   163       }
       
   164       $loc = scriptPath . '/install.php';
       
   165       // header("Location: $loc");
       
   166       redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
       
   167       exit;
       
   168     }
       
   169     $this->_conn = @mysql_connect($dbhost, $dbuser, $dbpasswd);
   173     $this->_conn = @mysql_connect($dbhost, $dbuser, $dbpasswd);
   170     unset($dbuser);
   174     unset($dbuser);
   171     unset($dbpasswd); // Security
   175     unset($dbpasswd); // Security
   172     
   176     
   173     if ( !$this->_conn )
   177     if ( !$this->_conn )
   869                       Most recent SQL query:</p>
   873                       Most recent SQL query:</p>
   870                       <pre>'.$bt.'</pre>';
   874                       <pre>'.$bt.'</pre>';
   871     return $internal_text;
   875     return $internal_text;
   872   }
   876   }
   873   
   877   
   874   function connect()
   878   function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false)
   875   {
   879   {
   876     $this->enable_errorhandler();
   880     $this->enable_errorhandler();
   877     
   881     
   878     define('ENANO_DBLAYER', 'PGSQL');
   882     define('ENANO_DBLAYER', 'PGSQL');
   879     define('ENANO_SQLFUNC_LOWERCASE', 'lower');
   883     define('ENANO_SQLFUNC_LOWERCASE', 'lower');
   880     define('ENANO_SQL_MULTISTRING_PRFIX', 'E');
   884     define('ENANO_SQL_MULTISTRING_PRFIX', 'E');
   881     define('ENANO_SQL_BOOLEAN_TRUE', '1');
   885     define('ENANO_SQL_BOOLEAN_TRUE', '1');
   882     define('ENANO_SQL_BOOLEAN_FALSE', '0');
   886     define('ENANO_SQL_BOOLEAN_FALSE', '0');
   883     
   887     
   884     if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
   888     if ( !$manual_credentials )
   885     {
   889     {
   886       @include(ENANO_ROOT.'/config.new.php');
   890       if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
   887     }
   891       {
   888     else
   892         @include(ENANO_ROOT.'/config.new.php');
   889     {
   893       }
   890       @include(ENANO_ROOT.'/config.php');
   894       else
   891     }
   895       {
       
   896         @include(ENANO_ROOT.'/config.php');
       
   897       }
       
   898         
       
   899       if ( isset($crypto_key) )
       
   900         unset($crypto_key); // Get this sucker out of memory fast
   892       
   901       
   893     if ( isset($crypto_key) )
   902       if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   894       unset($crypto_key); // Get this sucker out of memory fast
   903       {
   895     
   904         // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
   896     if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   905         if ( !defined('scriptPath') )
   897     {
       
   898       // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
       
   899       if ( !defined('scriptPath') )
       
   900       {
       
   901         if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
       
   902         {
   906         {
   903           $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
   907           if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
       
   908           {
       
   909             $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
       
   910           }
       
   911           if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
       
   912           {
       
   913             // user requested http://foo/enano as opposed to http://foo/enano/index.php
       
   914             $_SERVER['REQUEST_URI'] .= '/index.php';
       
   915           }
       
   916           $sp = dirname($_SERVER['REQUEST_URI']);
       
   917           if($sp == '/' || $sp == '\\') $sp = '';
       
   918           define('scriptPath', $sp);
       
   919           define('contentPath', "$sp/index.php?title=");
   904         }
   920         }
   905         if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
   921         $loc = scriptPath . '/install.php';
   906         {
   922         // header("Location: $loc");
   907           // user requested http://foo/enano as opposed to http://foo/enano/index.php
   923         redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
   908           $_SERVER['REQUEST_URI'] .= '/index.php';
   924         exit;
   909         }
   925       }
   910         $sp = dirname($_SERVER['REQUEST_URI']);
       
   911         if($sp == '/' || $sp == '\\') $sp = '';
       
   912         define('scriptPath', $sp);
       
   913         define('contentPath', "$sp/index.php?title=");
       
   914       }
       
   915       $loc = scriptPath . '/install.php';
       
   916       // header("Location: $loc");
       
   917       redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
       
   918       exit;
       
   919     }
   926     }
   920     $this->_conn = @pg_connect("host=$dbhost port=5432 dbname=$dbname user=$dbuser password=$dbpasswd");
   927     $this->_conn = @pg_connect("host=$dbhost port=5432 dbname=$dbname user=$dbuser password=$dbpasswd");
   921     unset($dbuser);
   928     unset($dbuser);
   922     unset($dbpasswd); // Security
   929     unset($dbpasswd); // Security
   923     
   930