From 402a66900e50f0aefebd560c4de6d77b5c708bdb Mon Sep 17 00:00:00 2001 From: genuineparts Date: Tue, 24 Jun 2025 22:46:54 +0200 Subject: [PATCH] Got rid of MySQL, fixed bugs in text module --- core/database/mysql.class.php | 190 ------------------------------- core/database/mysqli.class.php | 40 +++---- install/install.php | 4 - modules/text/admin/edit.apnl.php | 4 +- modules/text/text.ajax.php | 6 +- modules/text/text.output.php | 83 +++++++------- 6 files changed, 62 insertions(+), 265 deletions(-) delete mode 100644 core/database/mysql.class.php diff --git a/core/database/mysql.class.php b/core/database/mysql.class.php deleted file mode 100644 index 6c4299d..0000000 --- a/core/database/mysql.class.php +++ /dev/null @@ -1,190 +0,0 @@ - - * @package astat core - * @license http://opensource.org/licenses/gpl-license.php GNU Public License - * @version $Id: mysql.class.php 104 2010-02-20 19:16:12Z genuineparts $ -*/ - -$module["db"]["name"]="Database Class (mysql)"; -$module["db"]["ver"]="1.0.1"; -class db { - var $host=""; - var $user="root"; - var $password=""; - var $db="becast"; - var $encoding; - var $logging; - var $abfragen=0; - var $exception; - private $conid=FALSE; - public const ASSOC = 1; - public const NUM = 2; - public const BOTH = 3; - - function __construct($host,$user,$password,$db,$encoding="utf8",$logging=false,$exception=false) { - global $log,$config; - $this->host=$host; - $this->user=$user; - $this->password=$password; - $this->db=$db; - $this->logging=$logging; - $this->exception=$exception; - - if($this->logging==FALSE && DEBUG!=FALSE){ - $this->logger=new logger("file",dirname(dirname(dirname(__FILE__))).'/logs/mysql_debug.log',5); - }elseif($this->logging){ - $this->logger=new logger("file",dirname(dirname(dirname(__FILE__))).'/logs/mysql.log'); - } - - $this->encoding=$encoding; - $this->conid; - - if($this->logging) - $this->logger->write("mySQL Klasse instanziert", 5); - if(!$this->conid){ - if($this->logging) - $this->logger->write("Connection zu mySQL Server besteht nicht.", 5,__LINE__,__FILE__); - $this->conid=$this->connect($this->host,$this->user,$this->password,$this->db,$this->encoding); - }else{ - if($this->logging) - $this->logger->write("Connection zu mySQL Server besteht. ID ".$this->conid, 5,__LINE__,__FILE__); - } - if($this->encoding) - $this->query("SET NAMES '".$this->encoding."'"); - } - - function __destruct() { - $this->disconnect(); - } - - function connect($host, $user, $password, $db, $encoding){ - $conn = @mysql_connect($host, $user, $password); - if($this->logging) - $this->logger->write("Connect to Mysql Server", 5,__LINE__,__FILE__); - - if(!$conn){ - if($this->exception){ - throw new Exception('mySQLi Connect failed'); - }else{ - trigger_error("mySQL Connect failed",E_USER_ERROR); - - if($this->logging) - $this->logger->write("Connect Failed ". $this->error(), 5,__LINE__,__FILE__); - die(); - } - }else{ - if($this->logging) - $this->logger->write("Selecting Database ".$db, 5,__LINE__,__FILE__); - } - - $conn2 = @mysql_select_db($db,$conn); - if($this->logging) - $this->logger->write("Connect to Mysql Server", 5,__LINE__,__FILE__); - - if(!$conn2){ - include('templates/general_error.tpl'); - - if($this->logging) - $this->logger->write("Select failed ". $this->error(), 5,__LINE__,__FILE__); - die(); - }else{ - if($this->logging) - $this->logger->write("Database ".$db." selected", 5,__LINE__,__FILE__); - } - - return $conn; - } - - - function disconnect(){ - if($this->logging) - $this->logger->write("Closing Mysql Connection.", 5,__LINE__,__FILE__); - - @mysql_close($this->conid); - } - - function query($query){ - global $abfragen; - - if($this->logging) - $this->logger->write($query." ". $this->conid, 5,__LINE__,__FILE__); - - $this->abfragen++; - $res = mysql_query($query, $this->conid); - return $res; - } - - function querys(){ - return $this->abfragen; - } - - function num_rows($result){ - $rows = mysql_num_rows($result); - return $rows; - } - - function fetch_row($result){ - $row = mysql_fetch_row($result); - return $row; - } - - function fetch_array($result){ - $row = array(); - $row = mysql_fetch_array($result, MYSQL_ASSOC); - return $row; - } - - function escape($string){ - $return = mysql_real_escape_string($string); - return $return; - } - - function escape_binary($string){ - return "X'".$this->escape(bin2hex($string))."'"; - } - - function fetch_object($result){ - $row = mysql_fetch_object($result); - return $row; - } - - function error(){ - $error = mysql_error($this->conid); - return $error; - } - - function errno(){ - $errno = mysql_errno($this->conid); - return $errno ; - } - - function free_result($result){ - mysql_free_result($result); - } - - function last_id(){ - $id = mysql_insert_id($this->conid); - return $id; - } -} -?> diff --git a/core/database/mysqli.class.php b/core/database/mysqli.class.php index c72d787..04fd2c2 100644 --- a/core/database/mysqli.class.php +++ b/core/database/mysqli.class.php @@ -1,6 +1,6 @@ - * @package astat core + * @package BcWe core * @license http://opensource.org/licenses/gpl-license.php GNU Public License - * @version $Id: mysqli.class.php 126 2010-02-21 21:07:52Z genuineparts $ -*/ + * @version $Id$ + */ $module["db"]["name"]="Database Class (mysqli)"; -$module["db"]["ver"]="1.0.1"; +$module["db"]["ver"]="1.0.2"; class db { var $mysqli; var $host=""; @@ -119,31 +119,23 @@ class db { function querys(){ return $this->abfragen; - } + } function num_rows($result){ - $rows = $result->num_rows; - return $rows; - } + return $result->num_rows; + } function fetch_row($result){ - $row = $result->fetch_row(); - return $row; - } + return $result->fetch_row(); + } function fetch_array($result){ - - $row = array(); - $row = $result->fetch_array(MYSQLI_ASSOC); - return $row; - } + return $result->fetch_array(MYSQLI_ASSOC); + } function fetch_array_num($result){ - - $row = array(); - $row = $result->fetch_array(MYSQLI_NUM ); - return $row; - } + return $result->fetch_array(MYSQLI_NUM); + } function escape($string){ $return = $this->mysqli->real_escape_string($string); diff --git a/install/install.php b/install/install.php index 7b42294..22086f0 100755 --- a/install/install.php +++ b/install/install.php @@ -261,10 +261,6 @@ class install{ $status=true; $dbas[]=array('short'=>'mysqli','name'=>'MySQLi'); } - if (function_exists('mysql_connect')){ - $status=true; - $dbas[]=array('short'=>'mysql','name'=>'MySQL'); - } $this->dbas=$dbas; return $status; } diff --git a/modules/text/admin/edit.apnl.php b/modules/text/admin/edit.apnl.php index 52cc1e7..3ab99ec 100644 --- a/modules/text/admin/edit.apnl.php +++ b/modules/text/admin/edit.apnl.php @@ -131,9 +131,9 @@ class edit_text_panel extends admin_module{ }else{ $result = $db->query("SELECT a.title,a.id,a.active,a.date,a.url,u.username FROM `" . $config["prefix"] . "article` a LEFT JOIN `" . $config["prefix"] . "users` u on a.`author`=u.`uid`"); - while($row=$db->fetch_array($result, $db->ASSOC)){ + while($row=$db->fetch_array($result)){ $cresult=$db->query("SELECT a.`categoryname` FROM `" . $config["prefix"] . "article_categories` a LEFT JOIN `" . $config["prefix"] . "article_category` c on a.`id`=c.`c_id` WHERE c.`a_id`='".$row["id"]."'"); - while($crow=$db->fetch_array($cresult, $db->ASSOC)){ + while($crow=$db->fetch_array($cresult)){ if(!$row["categoryname"]){ $row["categoryname"]=$crow["categoryname"]; }else{ diff --git a/modules/text/text.ajax.php b/modules/text/text.ajax.php index 676e8fd..be48052 100644 --- a/modules/text/text.ajax.php +++ b/modules/text/text.ajax.php @@ -1,4 +1,5 @@ escape($_POST['url']); $result = $db->query("SELECT count(`id`) as `count` FROM `" . $config["prefix"] . "article` WHERE `url`='".$url."'"); - $row = $db->fetch_array($result, MYSQL_ASSOC); + $row = $db->fetch_array($result); if($row["count"]==0){ echo 0; }else{ @@ -25,5 +26,4 @@ class text extends ajax_module{ } } -} -?> +} \ No newline at end of file diff --git a/modules/text/text.output.php b/modules/text/text.output.php index 23db1f5..e0a301b 100644 --- a/modules/text/text.output.php +++ b/modules/text/text.output.php @@ -1,4 +1,4 @@ -page_begin("Text Module", FALSE); class text extends module{ - function output(){ - global $module,$config,$db,$log,$core,$error; - $textid=0; - $url=""; - if(Isset($this->get["textid"]) || Isset($this->post["textid"])){ - if(Isset($this->get["textid"])){ - $textid = intval($this->get["textid"]); - }else{ - $textid = intval($this->post["textid"]); + function output() + { + global $module, $config, $db, $log, $core, $error; + $textid = 0; + $url = ""; + if (isset($this->get["textid"]) || isset($this->post["textid"])) { + if (isset($this->get["textid"])) { + $textid = intval($this->get["textid"]); + } else { + $textid = intval($this->post["textid"]); } - $result = $db->query("SELECT a.`id` a.`text`, a.`title`, u.`username`, eu.`username` as edituser, a.`date`, a.`edittime`, a.`eid` FROM `" . $config["prefix"] . "article` a LEFT JOIN `".$config["prefix"]."users` eu on a.`eid` = eu.`uid` LEFT JOIN `".$config["prefix"]."users` u on a.`author` = u.`uid` WHERE a.`id`='".$textid."' AND a.`active`='true'") or die($db->error()); - }elseif(Isset($this->get["url"]) || Isset($this->post["url"])){ - If(Isset($this->get["url"])){ - $url=preg_replace( '/\.html($|\?)/i', "$1", $this->get["url"] ); - }else{ - $url=preg_replace( '/\.html($|\?)/i', "$1", $db->escape_string($this->post["url"])); - } - $result = $db->query("SELECT a.`id`, a.`text`, a.`title`, u.`username`, eu.`username` as edituser, a.`date`, a.`edittime`, a.`eid` FROM `" . $config["prefix"] . "article` a LEFT JOIN `".$config["prefix"]."users` eu on a.`eid` = eu.`uid` LEFT JOIN `".$config["prefix"]."users` u on a.`author` = u.`uid` WHERE a.url='".$url."' AND a.`active`='true'"); + $result = $db->query("SELECT a.`id` a.`text`, a.`title`, u.`username`, eu.`username` as edituser, a.`date`, a.`edittime`, a.`eid` FROM `" . $config["prefix"] . "article` a LEFT JOIN `" . $config["prefix"] . "users` eu on a.`eid` = eu.`uid` LEFT JOIN `" . $config["prefix"] . "users` u on a.`author` = u.`uid` WHERE a.`id`='" . $textid . "' AND a.`active`='true'") or die($db->error()); + } elseif (isset($this->get["url"]) || isset($this->post["url"])) { + if (isset($this->get["url"])) { + $url = preg_replace('/\.html($|\?)/i', "$1", $this->get["url"]); + } else { + $url = preg_replace('/\.html($|\?)/i', "$1", $db->escape_string($this->post["url"])); + } + $result = $db->query("SELECT a.`id`, a.`text`, a.`title`, u.`username`, eu.`username` as edituser, a.`date`, a.`edittime`, a.`eid` FROM `" . $config["prefix"] . "article` a LEFT JOIN `" . $config["prefix"] . "users` eu on a.`eid` = eu.`uid` LEFT JOIN `" . $config["prefix"] . "users` u on a.`author` = u.`uid` WHERE a.url='" . $url . "' AND a.`active`='true'"); - }else{ + } else { return $error->http_error("404"); - } - $fid=""; - $fid.=$textid; - $fid.=$url; - if($db->num_rows($result) > 0){ - if(!$this->tpl->isCached('textview.tpl',"textview".$fid)) { - $row = $db->fetch_array($result); - $cresult = $db->query("SELECT * FROM `" . $config["prefix"] . "article_categorys` c LEFT JOIN `" . $config["prefix"] . "article_category` s ON c.`id`=s.`c_id` WHERE s.`a_id`='".$row["id"]."'"); - while($c=$db->fetch_array($cresult)){ - if(!$cat){ - $cat=$c["categoryname"]; - }else{ - $cat.=", ".$c["categoryname"]; + } + $fid = ""; + $fid .= $textid; + $fid .= $url; + if ($db->num_rows($result) > 0) { + if (!$this->tpl->isCached('textview.tpl', "textview" . $fid)) { + $row = $db->fetch_array($result); + $cresult = $db->query("SELECT * FROM `" . $config["prefix"] . "article_categories` c LEFT JOIN `" . $config["prefix"] . "article_category` s ON c.`id`=s.`c_id` WHERE s.`a_id`='" . $row["id"] . "'"); + while ($c = $db->fetch_array($cresult)) { + if (!$cat) { + $cat = $c["categoryname"]; + } else { + $cat .= ", " . $c["categoryname"]; } } - + $editdate = date("d.m.Y, H:i", $row["edittime"]); $date = date("d.m.Y, H:i", $row["date"]); $this->tpl->assign('article', $row); $this->tpl->assign('cat', $cat); $this->tpl->assign('editdate', $editdate); $this->tpl->assign('date', $date); - } - $this->titleaddon=$row['title'].' - '; - $core->add_navbit($row['title']); - return $this->tpl->fetch('textview.tpl',"textview".$fid); - }else{ + } + $this->titleaddon = $row['title'] . ' - '; + $core->add_navbit($row['title']); + return $this->tpl->fetch('textview.tpl', "textview" . $fid); + } else { return $error->http_error("404"); - + } } - -} -?> +} \ No newline at end of file