Revision 1149
Added by aldus about 16 years ago
| branches/wb_devel/wb/CHANGELOG | ||
|---|---|---|
| 1 |
Change Log |
|
| 2 |
=============================================================================== |
|
| 3 |
Please note: This change log may not be accurate |
|
| 4 |
|
|
| 5 |
$Id: CHANGELOG 1146 2009-09-21 11:15:13Z aldus $ |
|
| 6 |
|
|
| 7 |
Legend: |
|
| 8 |
+ = Added |
|
| 9 |
- = Removed |
|
| 10 |
# = Bugfix |
|
| 11 |
! = Update/Change |
|
| 12 |
|
|
| 13 |
------------------------------------- 2.8.1 ------------------------------------- |
|
| 14 |
22-Sep-2009 Dietrich Roland Pehlke |
|
| 15 |
+ Add new Changelog to the project (maybe the place is inaccurate) |
|
| 16 |
! Changes inside the class.database.php; e.g. Logfile-support, Error-Message-Template. |
|
| 17 |
for future testings. |
|
| 18 |
- Remove the empty config.php from the project. |
|
| 19 |
! Installer files (index.php and save.php) to handle the //new// situation. |
|
| 20 |
! Modify the PHP-Version Test up to PHP 5.1 (instead of php 4.1). |
|
| 0 | 21 | |
| branches/wb_devel/wb/framework/class.database.php | ||
|---|---|---|
| 5 | 5 |
/* |
| 6 | 6 |
|
| 7 | 7 |
Website Baker Project <http://www.websitebaker.org/> |
| 8 |
Copyright (C) 2004-2009, Ryan Djurovich
|
|
| 8 |
Copyright (C) 2004-2008, Ryan Djurovich
|
|
| 9 | 9 |
|
| 10 | 10 |
Website Baker is free software; you can redistribute it and/or modify |
| 11 | 11 |
it under the terms of the GNU General Public License as published by |
| ... | ... | |
| 32 | 32 |
|
| 33 | 33 |
*/ |
| 34 | 34 |
|
| 35 |
// Stop this file from being accessed directly |
|
| 36 |
if(!defined('WB_URL')) {
|
|
| 37 |
header('Location: ../index.php');
|
|
| 38 |
exit(0); |
|
| 39 |
} |
|
| 35 |
/** |
|
| 36 |
* Stop this file from being accessed directly |
|
| 37 |
*/ |
|
| 38 |
if ( !defined('WB_URL') ) die (header('location: ../index.php') );
|
|
| 40 | 39 |
|
| 41 |
if(!defined('DB_URL')) {
|
|
| 42 |
//define('DB_URL', DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME);
|
|
| 43 |
} |
|
| 44 | 40 |
|
| 41 |
/** |
|
| 42 |
* Modifications on this file made by |
|
| 43 |
* - Dietrich Roland Pehlke (aldus) |
|
| 44 |
* |
|
| 45 |
* @version 2.2.2 |
|
| 46 |
* @date 2009-01-09 |
|
| 47 |
* @state beta |
|
| 48 |
* @require php 5.2.x |
|
| 49 |
* @package Website Baker - framework: class.database |
|
| 50 |
* |
|
| 51 |
* 0.2.2 add "type" to mysql-fetchRow method |
|
| 52 |
* |
|
| 53 |
* 0.2.1 add new class functions "copy_content" and "fetch_query". |
|
| 54 |
*/ |
|
| 45 | 55 |
define('DATABASE_CLASS_LOADED', true);
|
| 46 | 56 |
|
| 47 | 57 |
class database {
|
| 48 | 58 |
|
| 49 |
// Set DB_URL |
|
| 50 |
function database($url = '') {
|
|
| 59 |
public $mySQL_handle = 0; |
|
| 60 |
public $db_handle = 0; |
|
| 61 |
public $connected = 0; |
|
| 62 |
public $status = 0; |
|
| 63 |
public $log_querys = false; |
|
| 64 |
public $log_filename = "wb_querys.log"; |
|
| 65 |
public $log_path = ""; |
|
| 66 |
public $last_query = ""; |
|
| 67 |
public $last_jobnumber = 0; |
|
| 68 |
|
|
| 69 |
public $error_tmpl = " |
|
| 70 |
<span style='font-family:Verdana, sans-serif;font-size:11px;display:block; width:400px;'> |
|
| 71 |
An error has occured:<br /> |
|
| 72 |
Job: <b><font color='#990000'>{job}</font></b><br />
|
|
| 73 |
Message: <i><font color='#990000'>{message}</font></i><br />
|
|
| 74 |
</span>"; |
|
| 75 |
|
|
| 76 |
public $error = 0; |
|
| 77 |
|
|
| 78 |
public function __construct ($url="") {
|
|
| 79 |
$this->database($url); |
|
| 80 |
$this->mySQL_handle = new c_mysql(); |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/** |
|
| 84 |
* Set DB_URL |
|
| 85 |
*/ |
|
| 86 |
public function database($url = '') {
|
|
| 51 | 87 |
// Connect to database |
| 52 | 88 |
$this->connect(); |
| 53 | 89 |
// Check for database connection error |
| ... | ... | |
| 56 | 92 |
} |
| 57 | 93 |
} |
| 58 | 94 |
|
| 59 |
// Connect to the database |
|
| 60 |
function connect() {
|
|
| 61 |
$status = $this->db_handle = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); |
|
| 95 |
/** |
|
| 96 |
* Connect to the database |
|
| 97 |
*/ |
|
| 98 |
public function connect() {
|
|
| 99 |
$this->status = $this->db_handle = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); |
|
| 62 | 100 |
if(mysql_error()) {
|
| 63 | 101 |
$this->connected = false; |
| 64 | 102 |
$this->error = mysql_error(); |
| ... | ... | |
| 73 | 111 |
return $this->connected; |
| 74 | 112 |
} |
| 75 | 113 |
|
| 76 |
// Disconnect from the database |
|
| 77 |
function disconnect() {
|
|
| 114 |
/** |
|
| 115 |
* Disconnect from the database |
|
| 116 |
*/ |
|
| 117 |
public function disconnect() {
|
|
| 78 | 118 |
if($this->connected==true) {
|
| 79 |
mysql_close(); |
|
| 119 |
mysql_close( $this->db_handle );
|
|
| 80 | 120 |
return true; |
| 81 | 121 |
} else {
|
| 82 | 122 |
return false; |
| 83 | 123 |
} |
| 84 | 124 |
} |
| 85 | 125 |
|
| 86 |
// Run a query |
|
| 87 |
function query($statement) {
|
|
| 88 |
$mysql = new mysql(); |
|
| 89 |
$mysql->query($statement); |
|
| 90 |
$this->set_error($mysql->error()); |
|
| 91 |
if($mysql->error()) {
|
|
| 126 |
/** |
|
| 127 |
* Run a query |
|
| 128 |
*/ |
|
| 129 |
public function query( $statement="", $aJobNumber = 0 ) {
|
|
| 130 |
$this->last_query = $statement; |
|
| 131 |
$this->last_jobnumber = $aJobNumber; |
|
| 132 |
if (true == $this->log_querys) $this->__write_log(); |
|
| 133 |
$this->mySQL_handle->query($statement); |
|
| 134 |
$this->set_error($this->mySQL_handle->error()); |
|
| 135 |
if($this->mySQL_handle->error()) {
|
|
| 136 |
if (true == $this->log_querys) {
|
|
| 137 |
$this->last_query = "Error: ".$this->mySQL_handle->error(); |
|
| 138 |
$this->__write_log(); |
|
| 139 |
} |
|
| 140 |
$this->__display_error(); |
|
| 92 | 141 |
return null; |
| 93 | 142 |
} else {
|
| 94 |
return $mysql;
|
|
| 143 |
return clone $this->mySQL_handle;
|
|
| 95 | 144 |
} |
| 96 | 145 |
} |
| 97 | 146 |
|
| 98 |
// Gets the first column of the first row |
|
| 99 |
function get_one($statement) {
|
|
| 147 |
/** |
|
| 148 |
* |
|
| 149 |
* |
|
| 150 |
*/ |
|
| 151 |
public function fetch_query ($aQuery="", $aNumber=0) {
|
|
| 152 |
$result = $this->query($aQuery, $aNumber); |
|
| 153 |
if (!$result) return false; |
|
| 154 |
|
|
| 155 |
if ($result->numRows() > 0) {
|
|
| 156 |
return $result->fetchRow(); |
|
| 157 |
} else {
|
|
| 158 |
return false; |
|
| 159 |
} |
|
| 160 |
} |
|
| 161 |
|
|
| 162 |
/** |
|
| 163 |
* Gets the first column of the first row |
|
| 164 |
*/ |
|
| 165 |
public function get_one($statement) {
|
|
| 100 | 166 |
$fetch_row = mysql_fetch_row(mysql_query($statement)); |
| 101 | 167 |
$result = $fetch_row[0]; |
| 102 | 168 |
$this->set_error(mysql_error()); |
| ... | ... | |
| 107 | 173 |
} |
| 108 | 174 |
} |
| 109 | 175 |
|
| 110 |
// Set the DB error |
|
| 111 |
function set_error($message = null) {
|
|
| 176 |
/** |
|
| 177 |
* Set the DB error |
|
| 178 |
*/ |
|
| 179 |
public function set_error($message = null) {
|
|
| 112 | 180 |
global $TABLE_DOES_NOT_EXIST, $TABLE_UNKNOWN; |
| 113 | 181 |
$this->error = $message; |
| 114 | 182 |
if(strpos($message, 'no such table')) {
|
| ... | ... | |
| 118 | 186 |
} |
| 119 | 187 |
} |
| 120 | 188 |
|
| 121 |
// Return true if there was an error |
|
| 122 |
function is_error() {
|
|
| 123 |
return (!empty($this->error)) ? true : false; |
|
| 189 |
/** |
|
| 190 |
* Return true if there was an error |
|
| 191 |
*/ |
|
| 192 |
public function is_error() {
|
|
| 193 |
return ( 0 <> $this->error ) ? true : false; |
|
| 124 | 194 |
} |
| 125 | 195 |
|
| 126 |
// Return the error |
|
| 127 |
function get_error() {
|
|
| 196 |
/** |
|
| 197 |
* Return the error |
|
| 198 |
*/ |
|
| 199 |
public function get_error() {
|
|
| 128 | 200 |
return $this->error; |
| 129 | 201 |
} |
| 130 | 202 |
|
| 203 |
/** |
|
| 204 |
* Copy a content of a given table to another entry of the table |
|
| 205 |
* |
|
| 206 |
* @param string The tablename |
|
| 207 |
* @param string The source condition, e.g. "page_id=23" |
|
| 208 |
* @param string The target condition, e.g. "page_id=33" |
|
| 209 |
* @param mixed The exeptions, the field, that should not copied; e.g. "page_id". Could be also an array. |
|
| 210 |
* @param integer An optional Jobnumber for debugging. |
|
| 211 |
* @param bool Debugmode to display the final querys on screen instead of execute them |
|
| 212 |
* |
|
| 213 |
* @return bool true if all's ok. |
|
| 214 |
* |
|
| 215 |
*/ |
|
| 216 |
public function copy_content ($aTableName="", $aSourceCondition="", $aTargetCondition="", $aException="", $aJobNum=3100, $debug=false) {
|
|
| 217 |
if (!is_array($aException)) $aException = array ($aException); |
|
| 218 |
$all_fields = mysql_list_fields( DB_NAME, $aTableName); |
|
| 219 |
$n = mysql_num_fields($all_fields); |
|
| 220 |
if ($n == 0) die ("Error: no fields found in ".$aTableName);
|
|
| 221 |
$i=0; |
|
| 222 |
$all_names = array(); |
|
| 223 |
while($i < $n) {
|
|
| 224 |
$field_name = mysql_field_name($all_fields, $i++); |
|
| 225 |
if (!in_array ($field_name, $aException) ) $all_names[] = $field_name; |
|
| 226 |
} |
|
| 227 |
|
|
| 228 |
$result = $this->query ("SELECT ".implode(", ",$all_names)." from ". $aTableName ." where ".$aSourceCondition, 3000 );
|
|
| 229 |
$data = $result->fetchRow(); |
|
| 230 |
if (false === $debug) {
|
|
| 231 |
foreach ($all_names as $c => $item) $this->query ("UPDATE ". $aTableName ." set ". $item ."='" .$data[ $item ]."' where ".$aTargetCondition, ($aJobNum + (integer)$c));
|
|
| 232 |
} else {
|
|
| 233 |
foreach ($all_names as $c => $item) echo "UPDATE ". $aTableName ." set ". $item ."='" .$data[ $item ]."' where ".$aTargetCondition."<br />"; |
|
| 234 |
die(); |
|
| 235 |
} |
|
| 236 |
return true; |
|
| 237 |
} |
|
| 238 |
|
|
| 239 |
/** |
|
| 240 |
* Simple way to log the querys for debugging |
|
| 241 |
*/ |
|
| 242 |
public function __write_log () {
|
|
| 243 |
|
|
| 244 |
$path = ($this->log_path == "") ? WB_PATH."/framework/" : $this->log_path; |
|
| 245 |
$fp = fopen($path.$this->log_filename, 'a'); |
|
| 246 |
|
|
| 247 |
if ($fp) {
|
|
| 248 |
$str = "\n## ".DATE("Y-m-d H:i:s", TIME())." --------------\n".str_replace( array("\n", "\t", "\r"), array("", "", ""), $this->last_query);
|
|
| 249 |
$str .= "\n"; |
|
| 250 |
|
|
| 251 |
fwrite($fp, $str, strlen($str) ); |
|
| 252 |
fclose($fp); |
|
| 253 |
} |
|
| 254 |
} |
|
| 255 |
|
|
| 256 |
public function __display_error() {
|
|
| 257 |
ob_end_flush(); |
|
| 258 |
if ($this->last_jobnumber == 0) $this->last_jobnumber = "0 (no job-number specified)"; |
|
| 259 |
$msg = str_replace ( |
|
| 260 |
array ('{job}', '{message}'),
|
|
| 261 |
array ($this->last_jobnumber, $this->error), |
|
| 262 |
$this->error_tmpl |
|
| 263 |
); |
|
| 264 |
|
|
| 265 |
die ($msg); |
|
| 266 |
} |
|
| 267 |
|
|
| 131 | 268 |
} |
| 132 | 269 |
|
| 133 |
class mysql {
|
|
| 270 |
class c_mysql {
|
|
| 134 | 271 |
|
| 135 |
// Run a query |
|
| 136 |
function query($statement) {
|
|
| 272 |
public $result = 0; |
|
| 273 |
public $error = 0; |
|
| 274 |
|
|
| 275 |
/** |
|
| 276 |
* Run a query |
|
| 277 |
*/ |
|
| 278 |
public function query($statement) {
|
|
| 137 | 279 |
$this->result = mysql_query($statement); |
| 138 | 280 |
$this->error = mysql_error(); |
| 139 | 281 |
return $this->result; |
| 140 | 282 |
} |
| 141 | 283 |
|
| 142 |
// Fetch num rows |
|
| 143 |
function numRows() {
|
|
| 284 |
/** |
|
| 285 |
* Fetch num rows |
|
| 286 |
*/ |
|
| 287 |
public function numRows() {
|
|
| 144 | 288 |
return mysql_num_rows($this->result); |
| 145 | 289 |
} |
| 146 |
|
|
| 147 |
// Fetch row $typ = MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH |
|
| 148 |
function fetchRow($typ = MYSQL_BOTH) {
|
|
| 149 |
return mysql_fetch_array($this->result, $typ); |
|
| 290 |
|
|
| 291 |
/** |
|
| 292 |
* Fetch row |
|
| 293 |
* |
|
| 294 |
* @param string typ One of the following |
|
| 295 |
* MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH |
|
| 296 |
*/ |
|
| 297 |
public function fetchRow($typ = MYSQL_BOTH) {
|
|
| 298 |
return mysql_fetch_array($this->result); |
|
| 150 | 299 |
} |
| 151 |
|
|
| 152 |
// Get error |
|
| 153 |
function error() {
|
|
| 154 |
if(isset($this->error)) {
|
|
| 300 |
|
|
| 301 |
/** |
|
| 302 |
* Get error |
|
| 303 |
*/ |
|
| 304 |
public function error() {
|
|
| 305 |
if ( ( 0 <> $this->error ) AND (is_string($this->error) ) ) {
|
|
| 155 | 306 |
return $this->error; |
| 156 | 307 |
} else {
|
| 157 | 308 |
return null; |
| 158 | 309 |
} |
| 159 | 310 |
} |
| 160 |
|
|
| 161 | 311 |
} |
| 162 | 312 |
|
| 163 | 313 |
?> |
| branches/wb_devel/wb/index.php | ||
|---|---|---|
| 25 | 25 |
|
| 26 | 26 |
$starttime = array_sum(explode(" ",microtime()));
|
| 27 | 27 |
|
| 28 |
// Include config file |
|
| 29 |
require_once(dirname(__FILE__).'/config.php'); |
|
| 30 |
|
|
| 31 |
// Check if the config file has been set-up |
|
| 32 |
if(!defined('WB_PATH')) {
|
|
| 28 |
/** |
|
| 29 |
* looking for the config file |
|
| 30 |
*/ |
|
| 31 |
if (!file_exists(dirname(__FILE__).'/config.php')) {
|
|
| 32 |
/** |
|
| 33 |
* Config doesn't exists |
|
| 34 |
* So we've try to run the installation |
|
| 35 |
*/ |
|
| 33 | 36 |
header("Location: install/index.php");
|
| 34 | 37 |
exit(0); |
| 38 |
} else {
|
|
| 39 |
/** |
|
| 40 |
* Config file exists |
|
| 41 |
*/ |
|
| 42 |
require_once(dirname(__FILE__).'/config.php'); |
|
| 43 |
|
|
| 44 |
if (!defined(WB_PATH)) {
|
|
| 45 |
/** |
|
| 46 |
* Ups ... config seems to be corrupt |
|
| 47 |
*/ |
|
| 48 |
header("Location: install/index.php");
|
|
| 49 |
exit(0); |
|
| 50 |
} |
|
| 35 | 51 |
} |
| 36 | 52 |
|
| 37 | 53 |
require_once(WB_PATH.'/framework/class.frontend.php'); |
| branches/wb_devel/wb/install/save.php | ||
|---|---|---|
| 91 | 91 |
// Dummy class to allow modules' install scripts to call $admin->print_error |
| 92 | 92 |
class admin_dummy |
| 93 | 93 |
{
|
| 94 |
var $error=''; |
|
| 95 |
function print_error($message) |
|
| 94 |
public $error=''; |
|
| 95 |
|
|
| 96 |
public function print_error($message) |
|
| 96 | 97 |
{
|
| 97 | 98 |
$this->error=$message; |
| 98 | 99 |
} |
| ... | ... | |
| 317 | 318 |
|
| 318 | 319 |
$config_filename = '../config.php'; |
| 319 | 320 |
|
| 320 |
// Check if the file exists and is writable first. |
|
| 321 |
if(file_exists($config_filename) AND is_writable($config_filename)) {
|
|
| 322 |
if(!$handle = fopen($config_filename, 'w')) {
|
|
| 323 |
set_error("Cannot open the configuration file ($config_filename)");
|
|
| 321 |
/** |
|
| 322 |
* Looks a littel bit confuse, but in some circumstances |
|
| 323 |
* the config.php file could be corrupted - so the installer |
|
| 324 |
* is called even if the config.php file exists! |
|
| 325 |
*/ |
|
| 326 |
if (file_exists($config_filename)) unlink($config_filename); |
|
| 327 |
|
|
| 328 |
/** |
|
| 329 |
* Try to write the config file |
|
| 330 |
*/ |
|
| 331 |
$fp = fopen($config_filename, 'w'); |
|
| 332 |
if (!$fp ) {
|
|
| 333 |
set_error ("Can't create the config file.");
|
|
| 334 |
} else {
|
|
| 335 |
if (fwrite($fp, $config_content, strlen($config_content) ) === FALSE) {
|
|
| 336 |
/** |
|
| 337 |
* We have to close the file-pointer first, as |
|
| 338 |
* the following function "die's" and keep the |
|
| 339 |
* file-handle //open// |
|
| 340 |
*/ |
|
| 341 |
fclose( $fp ); |
|
| 342 |
set_error("Can't write to the configuration file [b]".$config_filename."[/b]!<br />Please check the permissions.");
|
|
| 343 |
|
|
| 324 | 344 |
} else {
|
| 325 |
if (fwrite($handle, $config_content) === FALSE) {
|
|
| 326 |
set_error("Cannot write to the configuration file ($config_filename)");
|
|
| 327 |
} |
|
| 328 |
// Close file |
|
| 329 |
fclose($handle); |
|
| 345 |
fclose($fp); |
|
| 330 | 346 |
} |
| 331 |
} else {
|
|
| 332 |
set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
|
|
| 333 | 347 |
} |
| 334 | 348 |
|
| 335 | 349 |
// Define configuration vars |
| branches/wb_devel/wb/install/index.php | ||
|---|---|---|
| 137 | 137 |
</tr> |
| 138 | 138 |
<?php } ?> |
| 139 | 139 |
<tr> |
| 140 |
<td width="160" style="color: #666666;">PHP Version > 4.1.0</td>
|
|
| 140 |
<td width="160" style="color: #666666;">PHP Version > 5.1.0</td>
|
|
| 141 | 141 |
<td width="60"> |
| 142 | 142 |
<?php |
| 143 |
$phpversion = substr(PHP_VERSION, 0, 6); |
|
| 144 |
if($phpversion > 4.1) {
|
|
| 145 |
?><font class="good">Yes</font><?php |
|
| 146 |
} else {
|
|
| 147 |
?><font class="bad">No</font><?php |
|
| 148 |
} |
|
| 149 |
?> |
|
| 143 |
echo ( true === version_compare( PHP_VERSION, "5.1", ">") ) |
|
| 144 |
? "<font class=\"good\">Yes</font>" |
|
| 145 |
: "<font class=\"bad\">No</font>" ; |
|
| 146 |
?> |
|
| 150 | 147 |
</td> |
| 151 | 148 |
<td width="140" style="color: #666666;">PHP Session Support</td> |
| 152 | 149 |
<td width="105"><?php echo $session_support; ?></td> |
| ... | ... | |
| 186 | 183 |
</tr> |
| 187 | 184 |
<tr> |
| 188 | 185 |
<td style="color: #666666;">wb/config.php</td> |
| 189 |
<td><?php if(is_writable('../config.php')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../config.php')) { echo '<font class="bad">File Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
|
|
| 186 |
<td><!--<?php if(is_writable('../config.php')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../config.php')) { echo '<font class="bad">File Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?>--></td>
|
|
| 190 | 187 |
<td style="color: #666666;">wb/pages/</td> |
| 191 | 188 |
<td><?php if(is_writable('../pages/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../pages/')) { echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
|
| 192 | 189 |
<td style="color: #666666;">wb/media/</td> |
Also available in: Unified diff
Modifications inside class.database.
Remove the empty config.php
Update index.php and save.php