Got rid of MySQL, fixed bugs in text module
This commit is contained in:
parent
98a80154e9
commit
402a66900e
6 changed files with 62 additions and 265 deletions
|
@ -1,190 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Project: astat - simple site engine
|
||||
* File: /core/database/mysql.class.php
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @link http://www.astat.org SVN: $URL: http://svn.astat.org/astat/trunk/core/database/mysql.class.php $
|
||||
* @copyright 2025 becast.at
|
||||
* @author Bernhard Jaud <bernhard at becast dot at>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Project: astat - simple site engine
|
||||
* Project: BeCast WebEngine - simple site engine
|
||||
* File: /core/database/mysqli.class.php
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
|
@ -17,16 +17,16 @@
|
|||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @link http://www.astat.org SVN: $URL: http://svn.astat.org/astat/trunk/core/database/mysqli.class.php $
|
||||
* @copyright 2025 becast.at
|
||||
* @link http://www.becast.at
|
||||
* @copyright 2009-2025 becast.at
|
||||
* @author Bernhard Jaud <bernhard at becast dot at>
|
||||
* @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="";
|
||||
|
@ -122,27 +122,19 @@ class db {
|
|||
}
|
||||
|
||||
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){
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
global $session;
|
||||
If (!defined("INBCWE")) {
|
||||
die("Dieses Script kann nicht ausserhalb des Frameworks laufen!");
|
||||
}
|
||||
|
@ -15,7 +16,7 @@ class text extends ajax_module{
|
|||
if(isset($_POST['url'])&& $_POST['url']!=""){
|
||||
$url=$db->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{
|
||||
|
@ -26,4 +27,3 @@ class text extends ajax_module{
|
|||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php global $session;
|
||||
/**
|
||||
* Project: BeCast WebEngine - simple site engine
|
||||
* File: /modules/text/text.output.php
|
||||
|
@ -32,42 +32,43 @@ $session->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"])){
|
||||
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{
|
||||
} 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.`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.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)) {
|
||||
$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"];
|
||||
$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"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,14 +79,12 @@ class text extends module{
|
|||
$this->tpl->assign('editdate', $editdate);
|
||||
$this->tpl->assign('date', $date);
|
||||
}
|
||||
$this->titleaddon=$row['title'].' - ';
|
||||
$this->titleaddon = $row['title'] . ' - ';
|
||||
$core->add_navbit($row['title']);
|
||||
return $this->tpl->fetch('textview.tpl',"textview".$fid);
|
||||
}else{
|
||||
return $this->tpl->fetch('textview.tpl', "textview" . $fid);
|
||||
} else {
|
||||
return $error->http_error("404");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue