a few fixes here and there, imporved autoloader, updated database-class (ugly old php4 style), removed two functions which will be included in the following updated installer

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-10-13 10:39:11 +02:00
parent 72fcad5007
commit b480a0be57
6 changed files with 134 additions and 353 deletions

View File

@@ -149,6 +149,10 @@ elseif($page == 'phpinfo'
eval("\$phpinfoentries .= \"" . getTemplate("settings/phpinfo/phpinfo_1") . "\";"); eval("\$phpinfoentries .= \"" . getTemplate("settings/phpinfo/phpinfo_1") . "\";");
} }
} }
// first header -> show actual php version
if (strtolower($name) == "phpinfo") {
$name = "PHP ".PHP_VERSION;
}
eval("\$phpinfohtml .= \"" . getTemplate("settings/phpinfo/phpinfo_table") . "\";"); eval("\$phpinfohtml .= \"" . getTemplate("settings/phpinfo/phpinfo_table") . "\";");
} }
$phpinfo = $phpinfohtml; $phpinfo = $phpinfohtml;

View File

@@ -21,63 +21,54 @@
* Class to manage the connection to the Database * Class to manage the connection to the Database
* @package Functions * @package Functions
*/ */
class db {
class db
{
/** /**
* Link ID for every connection * Link ID for every connection
* @var int * @var int
*/ */
public $link_id = 0; public $link_id = 0;
/** /**
* Query ID for every query * Query ID for every query
* @var int * @var int
*/ */
private $query_id = 0; private $query_id = 0;
/** /**
* Errordescription, if an error occures * Errordescription, if an error occures
* @var string * @var string
*/ */
public $errdesc = ''; public $errdesc = '';
/** /**
* Errornumber, if an error occures * Errornumber, if an error occures
* @var int * @var int
*/ */
public $errno = 0; public $errno = 0;
/** /**
* Servername * Servername
* @var string * @var string
*/ */
private $server = ''; private $server = '';
/** /**
* Username * Username
* @var string * @var string
*/ */
private $user = ''; private $user = '';
/** /**
* Password * Password
* @var string * @var string
*/ */
private $password = ''; private $password = '';
/** /**
* Database * Database
* @var string * @var string
*/ */
private $database = ''; private $database = '';
/** /**
@@ -88,14 +79,11 @@ class db
* @param string Password * @param string Password
* @param string Database * @param string Database
*/ */
public function __construct($server, $user, $password, $database = '') {
function db($server, $user, $password, $database = '')
{
// check for mysql extension // check for mysql extension
if (!extension_loaded('mysql')) {
if(!extension_loaded('mysql')) $this->_showerror('You should install the PHP MySQL extension!', false);
{
$this->showerror('You should install the PHP MySQL extension!', false);
} }
$this->server = $server; $this->server = $server;
@@ -104,34 +92,25 @@ class db
$this->database = $database; $this->database = $database;
$this->link_id = @mysql_connect($this->server, $this->user, $this->password, 1); $this->link_id = @mysql_connect($this->server, $this->user, $this->password, 1);
if(!$this->link_id) if (!$this->link_id) {
{
//try to connect with no password and change it afterwards. only for root user
if($this->user == 'root') //try to connect with no password and change it afterwards. only for root user
{ if ($this->user == 'root') {
$this->link_id = @mysql_connect($this->server, $this->user, '', 1); $this->link_id = @mysql_connect($this->server, $this->user, '', 1);
if($this->link_id) if ($this->link_id) {
{
$this->query("SET PASSWORD = PASSWORD('" . $this->escape($this->password) . "')"); $this->query("SET PASSWORD = PASSWORD('" . $this->escape($this->password) . "')");
} else {
$this->_showerror('Establishing connection failed, exiting');
} }
else } else {
{ $this->_showerror('Establishing connection failed, exiting');
$this->showerror('Establishing connection failed, exiting');
}
}
else
{
$this->showerror('Establishing connection failed, exiting');
} }
} }
if($this->database != '') if ($this->database != '') {
{ if (!@mysql_select_db($this->database, $this->link_id)) {
if(!@mysql_select_db($this->database, $this->link_id)) $this->_showerror('Trying to use database ' . $this->database . ' failed, exiting');
{
$this->showerror('Trying to use database ' . $this->database . ' failed, exiting');
} }
} }
@@ -141,14 +120,11 @@ class db
/** /**
* Closes connection to Databaseserver * Closes connection to Databaseserver
*/ */
public function close() {
function close()
{
return @mysql_close($this->link_id); return @mysql_close($this->link_id);
} }
function getDbName() public function getDbName() {
{
return $this->database; return $this->database;
} }
@@ -158,19 +134,12 @@ class db
* @param string $input * @param string $input
* @return string escaped string * @return string escaped string
*/ */
public function escape($input) {
function escape($input) if (is_int($input)) {
{
if(is_int($input))
{
return (int)$input; return (int)$input;
} } elseif(is_float($input)) {
elseif(is_float($input))
{
return (float)$input; return (float)$input;
} } else {
else
{
return mysql_real_escape_string($input, $this->link_id); return mysql_real_escape_string($input, $this->link_id);
} }
} }
@@ -182,54 +151,40 @@ class db
* @param bool Unbuffered query? * @param bool Unbuffered query?
* @return string RessourceId * @return string RessourceId
*/ */
public function query($query_str, $unbuffered = false, $suppress_error = false) {
function query($query_str, $unbuffered = false, $suppress_error = false)
{
global $numbqueries, $theme; global $numbqueries, $theme;
if (!mysql_ping($this->link_id)) // check if connection is still alive
{ if (!mysql_ping($this->link_id)) {
$this->link_id = mysql_connect($this->server,$this->user,$this->password); $this->link_id = mysql_connect($this->server,$this->user,$this->password);
if(!$this->database) if (!$this->database) {
{
return false; return false;
} }
mysql_select_db($this->database); mysql_select_db($this->database);
} }
if(!$unbuffered) if (!$unbuffered) {
{ if ($suppress_error) {
if($suppress_error)
{
$this->query_id = @mysql_query($query_str, $this->link_id); $this->query_id = @mysql_query($query_str, $this->link_id);
} else { } else {
$this->query_id = mysql_query($query_str, $this->link_id); $this->query_id = mysql_query($query_str, $this->link_id);
} }
} } else {
else if ($suppress_error) {
{
if($suppress_error)
{
$this->query_id = @mysql_unbuffered_query($query_str, $this->link_id); $this->query_id = @mysql_unbuffered_query($query_str, $this->link_id);
} else { } else {
$this->query_id = mysql_unbuffered_query($query_str, $this->link_id); $this->query_id = mysql_unbuffered_query($query_str, $this->link_id);
} }
} }
if(!$this->query_id && !$suppress_error) if (!$this->query_id && !$suppress_error) {
{ $this->_showerror('Invalid SQL: ' . $query_str);
$this->showerror('Invalid SQL: ' . $query_str); } elseif(!$this->query_id && $suppress_error) {
}
elseif(!$this->query_id && $suppress_error)
{
return false; return false;
} }
$numbqueries++; $numbqueries++;
//echo $query_str.' '.$numbqueries.'<br />';
return $this->query_id; return $this->query_id;
} }
@@ -240,22 +195,15 @@ class db
* @param string Datatype, num or assoc * @param string Datatype, num or assoc
* @return array The row * @return array The row
*/ */
public function fetch_array($query_id = - 1, $_datatype = 'assoc') {
function fetch_array($query_id = - 1, $datatype = 'assoc') if ($query_id != - 1) {
{
if($query_id != - 1)
{
$this->query_id = $query_id; $this->query_id = $query_id;
} }
if($datatype == 'num') $datatype = MYSQL_ASSOC;
{ if ($_datatype == 'num') {
$datatype = MYSQL_NUM; $datatype = MYSQL_NUM;
} }
else
{
$datatype = MYSQL_ASSOC;
}
$this->record = mysql_fetch_array($this->query_id, $datatype); $this->record = mysql_fetch_array($this->query_id, $datatype);
return $this->record; return $this->record;
@@ -268,9 +216,7 @@ class db
* @param string Datatype, num or assoc * @param string Datatype, num or assoc
* @return array The first row * @return array The first row
*/ */
public function query_first($query_string, $datatype = 'assoc') {
function query_first($query_string, $datatype = 'assoc')
{
$this->query($query_string); $this->query($query_string);
return $this->fetch_array($this->query_id, $datatype); return $this->fetch_array($this->query_id, $datatype);
} }
@@ -281,14 +227,10 @@ class db
* @param string RessourceId * @param string RessourceId
* @return int Number of rows * @return int Number of rows
*/ */
public function num_rows($query_id = - 1) {
function num_rows($query_id = - 1) if ($query_id != - 1) {
{
if($query_id != - 1)
{
$this->query_id = $query_id; $this->query_id = $query_id;
} }
return mysql_num_rows($this->query_id); return mysql_num_rows($this->query_id);
} }
@@ -297,9 +239,7 @@ class db
* *
* @return int auto_incremental-Value * @return int auto_incremental-Value
*/ */
public function insert_id() {
function insert_id()
{
return mysql_insert_id($this->link_id); return mysql_insert_id($this->link_id);
} }
@@ -308,9 +248,7 @@ class db
* *
* @return int affected rows * @return int affected rows
*/ */
public function affected_rows() {
function affected_rows()
{
return mysql_affected_rows($this->link_id); return mysql_affected_rows($this->link_id);
} }
@@ -319,22 +257,15 @@ class db
* *
* @return int Errornumber * @return int Errornumber
*/ */
private function _geterrdescno() {
function geterrdescno() if ($this->link_id != 0) {
{
if($this->link_id != 0)
{
$this->errdesc = mysql_error($this->link_id); $this->errdesc = mysql_error($this->link_id);
$this->errno = mysql_errno($this->link_id); $this->errno = mysql_errno($this->link_id);
} } else {
else
{
// Maybe we don't have any linkid so let's try to catch at least anything // Maybe we don't have any linkid so let's try to catch at least anything
$this->errdesc = mysql_error(); $this->errdesc = mysql_error();
$this->errno = mysql_errno(); $this->errno = mysql_errno();
} }
return $this->errno; return $this->errno;
} }
@@ -343,24 +274,19 @@ class db
* *
* @param string Errormessage * @param string Errormessage
*/ */
private function _showerror($errormsg, $mysqlActive = true) {
function showerror($errormsg, $mysqlActive = true)
{
global $filename, $theme; global $filename, $theme;
$text = 'MySQL - Error: ' . str_replace("\n", "\t", $errormsg); $text = 'MySQL - Error: ' . str_replace("\n", "\t", $errormsg);
if($mysqlActive)
{ if ($mysqlActive) {
$this->geterrdescno(); $this->_geterrdescno();
$text .= "; ErrNo: " . $this->errno . "; Desc: " . $this->errdesc; $text .= "; ErrNo: " . $this->errno . "; Desc: " . $this->errdesc;
} }
if($filename != 'cronscript.php') if ($filename != 'froxlor_master_cronjob.php') {
{
$text .= "; Script: " . getenv('REQUEST_URI') . "; Ref: " . getenv('HTTP_REFERER'); $text .= "; Script: " . getenv('REQUEST_URI') . "; Ref: " . getenv('HTTP_REFERER');
} } else {
else
{
$text .= "; Script: cronscript"; $text .= "; Script: cronscript";
} }
$md5 = md5($text . time()); $md5 = md5($text . time());
@@ -384,5 +310,3 @@ class db
die("We are sorry, but a MySQL - error occurred. The administrator may find more information in syslog with the ID ".$md5." or in the sql-error.log in the logs/ directory"); die("We are sorry, but a MySQL - error occurred. The administrator may find more information in syslog with the ID ".$md5." or in the sql-error.log in the logs/ directory");
} }
} }
?>

View File

@@ -42,39 +42,87 @@ function includeFunctions($dirname)
closedir($dirhandle); closedir($dirhandle);
} }
function __autoload($classname)
{
global $libdirname, $theme;
findIncludeClass($libdirname . '/classes/', $classname);
}
spl_autoload_register('__autoload');
function findIncludeClass($dirname, $classname)
{
$dirhandle = opendir($dirname);
while(false !== ($filename = readdir($dirhandle)))
{
if($filename != '.' && $filename != '..' && $filename != '')
{
if($filename == 'class.' . $classname . '.php' || $filename == 'abstract.' . $classname . '.php' || $filename == 'interface.' . $classname . '.php')
{
include($dirname . $filename);
return;
}
if(is_dir($dirname . $filename))
{
findIncludeClass($dirname . $filename . '/', $classname);
}
}
}
closedir($dirhandle);
}
function exportDetails($fielddata, $newfieldvalue) function exportDetails($fielddata, $newfieldvalue)
{ {
print_r($newfieldvalue); print_r($newfieldvalue);
} }
Autoloader::init();
/**
* Class Autoloader
*
* iterates through given directory and includes
* the file which matches $classname
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2013-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Autoloader
* @since 0.9.29.1
*/
class Autoloader {
/**
* returns a new AutoLoader-object
* @return Autoloader
*/
public static function init() {
return new self();
}
/**
* class constructor
*
* @return null
*/
public function __construct() {
// register autoload.function
spl_autoload_register(array($this, 'doAutoload'));
}
/**
* gets the class to load as parameter, searches the library-paths
* recursively for this class and includes it
*
* @param string $class
*
* @throws Exception
* @return boolean
*/
public function doAutoload($class) {
// define the paths where to look for classes
$paths = array(
dirname(__FILE__) . '/',
dirname(dirname(__FILE__)) . '/scripts/',
dirname(dirname(__FILE__)) . '/install/',
);
// now iterate through the paths
foreach ($paths as $path) {
// valid directory?
if (is_dir($path)) {
// create RecursiveIteratorIterator
$its = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path)
);
// check every file
foreach ($its as $fullFileName => $it ) {
// does it match the Filename pattern?
if (preg_match("/^(class|module|interface|abstract|)\.?$class\.php$/i", $it->getFilename())) {
// include the file and return from the loop
include_once $fullFileName;
return true;
}
}
} else {
// yikes - no valid directory to check
throw new Exception("Cannot autoload from directory '".$path."'. No such directory.");
}
}
// yikes - class not found
throw new Exception("Could not find class '".$class."'");
}
}

View File

@@ -1,55 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
//
// remove_remarks will strip the sql comment lines out of an uploaded sql file
// The whole function has been taken from the phpbb installer, copyright by the phpbb team, phpbb in summer 2004.
//
function remove_remarks($sql)
{
$lines = explode("\n", $sql);
// try to keep mem. use down
$sql = "";
$linecount = count($lines);
$output = "";
for ($i = 0;$i < $linecount;$i++)
{
if(($i != ($linecount - 1))
|| (strlen($lines[$i]) > 0))
{
if(substr($lines[$i], 0, 1) != "#")
{
$output.= $lines[$i] . "\n";
}
else
{
$output.= "\n";
}
// Trading a bit of speed for lower mem. use here.
$lines[$i] = "";
}
}
return $output;
}

View File

@@ -1,140 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
//
// split_sql_file will split an uploaded sql file into single sql statements.
// Note: expects trim() to have already been run on $sql
// The whole function has been taken from the phpbb installer, copyright by the phpbb team, phpbb in summer 2004.
//
function split_sql_file($sql, $delimiter)
{
// Split up our string into "possible" SQL statements.
$tokens = explode($delimiter, $sql);
// try to save mem.
$sql = "";
$output = array();
// we don't actually care about the matches preg gives us.
$matches = array();
// this is faster than calling count($oktens) every time thru the loop.
$token_count = count($tokens);
for ($i = 0;$i < $token_count;$i++)
{
// Don't wanna add an empty string as the last thing in the array.
if(($i != ($token_count - 1))
|| (strlen($tokens[$i] > 0)))
{
// This is the total number of single quotes in the token.
$total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
// Counts single quotes that are preceded by an odd number of backslashes,
// which means they're escaped quotes.
$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);
$unescaped_quotes = $total_quotes - $escaped_quotes;
// If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.
if(($unescaped_quotes % 2) == 0)
{
// It's a complete sql statement.
$output[] = $tokens[$i];
// save memory.
$tokens[$i] = "";
}
else
{
// incomplete sql statement. keep adding tokens until we have a complete one.
// $temp will hold what we have so far.
$temp = $tokens[$i] . $delimiter;
// save memory..
$tokens[$i] = "";
// Do we have a complete statement yet?
$complete_stmt = false;
for ($j = $i + 1;(!$complete_stmt && ($j < $token_count));$j++)
{
// This is the total number of single quotes in the token.
$total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
// Counts single quotes that are preceded by an odd number of backslashes,
// which means they're escaped quotes.
$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
$unescaped_quotes = $total_quotes - $escaped_quotes;
if(($unescaped_quotes % 2) == 1)
{
// odd number of unescaped quotes. In combination with the previous incomplete
// statement(s), we now have a complete statement. (2 odds always make an even)
$output[] = $temp . $tokens[$j];
// save memory.
$tokens[$j] = "";
$temp = "";
// exit the loop.
$complete_stmt = true;
// make sure the outer loop continues at the right point.
$i = $j;
}
else
{
// even number of unescaped quotes. We still don't have a complete statement.
// (1 odd and 1 even always make an odd)
$temp.= $tokens[$j] . $delimiter;
// save memory.
$tokens[$j] = "";
}
}
// for..
}
// else
}
}
return $output;
}

View File

@@ -1290,7 +1290,7 @@ $lng['cronmgmt']['days'] = 'Tage';
$lng['cronmgmt']['weeks'] = 'Wochen'; $lng['cronmgmt']['weeks'] = 'Wochen';
$lng['cronmgmt']['months'] = 'Monate'; $lng['cronmgmt']['months'] = 'Monate';
$lng['admin']['cronjob_edit'] = 'Cronjob bearbeiten'; $lng['admin']['cronjob_edit'] = 'Cronjob bearbeiten';
$lng['cronjob']['cronjobsettings'] = 'Cronjob-instellungen'; $lng['cronjob']['cronjobsettings'] = 'Cronjob-Einstellungen';
$lng['cronjob']['cronjobintervalv'] = 'Laufzeit-Intervall Wert'; $lng['cronjob']['cronjobintervalv'] = 'Laufzeit-Intervall Wert';
$lng['cronjob']['cronjobinterval'] = 'Laufzeit-Intervall'; $lng['cronjob']['cronjobinterval'] = 'Laufzeit-Intervall';
$lng['panel']['options'] = 'Optionen'; $lng['panel']['options'] = 'Optionen';