Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28619
Modified Files:
NEWS htaccess.errordocs.tpl htaccess.normal.tpl
htaccess.rewrite.tpl serendipity_config.inc.php
serendipity_config_local.tpl serendipity_db_sqlite.inc.php
serendipity_functions.inc.php
serendipity_functions_installer.inc.php
Log Message:
Made SQLite work.
Index: NEWS
===================================================================
RCS file: /cvsroot/php-blog/serendipity/NEWS,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -d -r1.154 -r1.155
--- NEWS 19 Jun 2004 19:28:52 -0000 1.154
+++ NEWS 21 Jun 2004 14:55:31 -0000 1.155
@@ -3,7 +3,10 @@
Version 0.7 ()
------------------------------------------------------------------------
- * Fixed Bug #963248 - Calendar cannot calculate LastRow CSS class if
+ * SQLite support now works. Only basic functionality tested (posting,
+ installation, browsing) but it looks very good! (garvinhicking)
+
+ * Fixed Bug #963248 - Calendar cannot calculate LastRow CSS class if
there are more than 4 rows (tomsommer)
* Use the right HTML code for trackback-link detection when using
@@ -208,7 +211,7 @@
* Configuration is now language-dependant. (garvinhicking)
-Version 0.6-pl3 ()
+Version 0.6-pl3 (June 20th, 2004)
------------------------------------------------------------------------
* WYSIWYG-Editor: Links were prefixed with '/' wrongly (IE only).
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- serendipity_config.inc.php 20 Jun 2004 19:52:00 -0000 1.81
+++ serendipity_config.inc.php 21 Jun 2004 14:55:31 -0000 1.82
@@ -195,5 +195,6 @@
. 'X-Engine: PHP/'. phpversion();
serendipity_plugin_api::hook_event('frontend_configure', $serendipity);
+
/* vim: set sts=4 ts=4 expandtab : */
?>
Index: serendipity_config_local.tpl
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config_local.tpl,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- serendipity_config_local.tpl 16 Jun 2004 18:28:58 -0000 1.39
+++ serendipity_config_local.tpl 21 Jun 2004 14:55:32 -0000 1.40
@@ -2,7 +2,7 @@
// INSTALL_CAT_DB
# INSTALL_CAT_DB_DESC
-$serendipity['dbType'] = '{INSTALL_DBTYPE|dbType|list|mysql=>MySQL,postgres=>PostgreSQL,mysqli=>MySQLi|255}'; // INSTALL_DBTYPE_DESC
+$serendipity['dbType'] = '{INSTALL_DBTYPE|dbType|list|mysql=>MySQL,postgres=>PostgreSQL,mysqli=>MySQLi,sqlite=>SQLite|255}'; // INSTALL_DBTYPE_DESC
$serendipity['dbHost'] = '{INSTALL_DBHOST|dbHost|string|localhost|255}'; // INSTALL_DBHOST_DESC
$serendipity['dbUser'] = '{INSTALL_DBUSER|dbUser|string|serendipity|255}'; // INSTALL_DBUSER_DESC
$serendipity['dbPass'] = '{INSTALL_DBPASS|dbPass|protected||255}'; // INSTALL_DBPASS_DESC
@@ -44,6 +44,6 @@
# INSTALL_CAT_IMAGECONV_DESC
$serendipity['magick'] = '{INSTALL_IMAGEMAGICK|magick|bool|0|255}'; // INSTALL_IMAGEMAGICK_DESC
$serendipity['convert'] = '{INSTALL_IMAGEMAGICKPATH|convert|string|/usr/local/bin/convert|255}'; // INSTALL_IMAGEMAGICKPATH_DESC
-$serendipity['thumbSuffix'] = '{INSTALL_THUMBSUFFIX|thumbSuffix|string|serendipityThumb|255}'; // INSTALL_THUMBSUFFIX_DESC
+$serendipity['thumbSuffix'] = '{INSTALL_THUMBSUFFIX|thumbSuffix|string|serendipityThumb|255}'; // INSTALL_THUMBSUFFIX_DESC
$serendipity['thumbSize'] = '{INSTALL_THUMBWIDTH|thumbSize|int|110|255}'; // INSTALL_THUMBWIDTH_DESC
?>
Index: htaccess.errordocs.tpl
===================================================================
RCS file: /cvsroot/php-blog/serendipity/htaccess.errordocs.tpl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- htaccess.errordocs.tpl 3 Jun 2004 09:53:29 -0000 1.5
+++ htaccess.errordocs.tpl 21 Jun 2004 14:55:31 -0000 1.6
@@ -16,7 +16,7 @@
deny from all
</Files>
-<Files sqlite.db>
+<Files *.db>
deny from all
</Files>
Index: htaccess.normal.tpl
===================================================================
RCS file: /cvsroot/php-blog/serendipity/htaccess.normal.tpl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- htaccess.normal.tpl 3 Jun 2004 09:53:29 -0000 1.5
+++ htaccess.normal.tpl 21 Jun 2004 14:55:31 -0000 1.6
@@ -14,7 +14,7 @@
deny from all
</Files>
-<Files sqlite.db>
+<Files *.db>
deny from all
</Files>
Index: htaccess.rewrite.tpl
===================================================================
RCS file: /cvsroot/php-blog/serendipity/htaccess.rewrite.tpl,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- htaccess.rewrite.tpl 3 Jun 2004 09:53:29 -0000 1.9
+++ htaccess.rewrite.tpl 21 Jun 2004 14:55:31 -0000 1.10
@@ -31,7 +31,7 @@
deny from all
</Files>
-<Files sqlite.db>
+<Files *.db>
deny from all
</Files>
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.298
retrieving revision 1.299
diff -u -d -r1.298 -r1.299
--- serendipity_functions.inc.php 21 Jun 2004 08:01:36 -0000 1.298
+++ serendipity_functions.inc.php 21 Jun 2004 14:55:32 -0000 1.299
@@ -768,6 +768,7 @@
WHERE ec.entryid IN (" . implode(', ', $search_ids) . ")";
$search_ret = serendipity_db_query($query);
+
if (is_array($search_ret)) {
foreach($search_ret AS $i => $entry) {
$ret[$assoc_ids[$entry['entryid']]]['categories'][] = $entry;
@@ -2709,7 +2710,7 @@
}
if ($username != '') {
- if ($is_md5 === false) {
+ if ($is_md5 === false && !empty($password)) {
$password = md5($password);
}
Index: serendipity_functions_installer.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions_installer.inc.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- serendipity_functions_installer.inc.php 16 Jun 2004 22:21:55 -0000 1.14
+++ serendipity_functions_installer.inc.php 21 Jun 2004 14:55:32 -0000 1.15
@@ -16,6 +16,10 @@
return $errs;
}
+ if (isset($_POST['sqlitedbName']) && !empty($_POST['sqlitedbName'])) {
+ $dbName = $_POST['sqlitedbName'];
+ }
+
fwrite($configfp, "<?php\n");
fwrite($configfp, "\t/*\n");
@@ -48,7 +52,7 @@
switch ($optname) {
- case 'dbType' :
+ case 'dbType' :
if ( extension_loaded('mysqli') ) {
$type = 'mysqli';
}
@@ -167,10 +171,10 @@
case '$':
// Grep out the name, type and default
preg_match('#\{([^|]+\|[^|]+\|([^}]+)?)\}[^/]+/{2}(.+)#msi', $l, $match);
-
+
// Make vars containing the elements in the | list
list($constant, $name, $type, $distdefault, $permission, $flags) = explode('|', $match[1]);
-
+
// Only show directives which are destined for this user. On installation, show everyting.
if (IS_installed === false || $serendipity['serendipityUserlevel'] >= $permission) {
$cdef = ($get_defaults ? serendipity_query_default($name, $distdefault, $usertemplate, $type) : '');
@@ -356,7 +360,7 @@
?>
<table width="100%" cellspacing="2">
<?php
- if ( sizeof($t['categories']) > 1 ) {
+ if ( sizeof($t['categories']) > 1 ) {
?>
<tr>
<th align="left" colspan="2" style="padding-left: 15px;">
@@ -378,7 +382,7 @@
/* Check for installOnly flag */
if ( in_array('installOnly', $value[$x]['flags']) && IS_installed === true ) {
continue;
- }
+ }
/* If we have a valuelist, then use the value from there */
@@ -486,6 +490,12 @@
$errs[] = sprintf(CANT_EXECUTE_BINARY, 'convert imagemagick');
}
+ if ($_POST['dbType'] == 'sqlite') {
+ // We don't want that our SQLite db file can be guessed from other applications on a server
+ // and have access to our's. So we randomize the SQLite dbname.
+ $_POST['sqlitedbName'] = $_POST['dbName'] . '_' . md5(time());
+ }
+
$serendipity['dbType'] = $_POST['dbType'];
// Probe database
// (do it after the dir stuff, as we need to be able to create the sqlite database)
Index: serendipity_db_sqlite.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_db_sqlite.inc.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- serendipity_db_sqlite.inc.php 25 Jul 2003 01:03:18 -0000 1.6
+++ serendipity_db_sqlite.inc.php 21 Jun 2004 14:55:32 -0000 1.7
@@ -1,129 +1,163 @@
<?php # $Id$
+if (!function_exists('sqlite_open')) {
+ @dl('sqlite.so');
+ @dl('sqlite.dll');
+}
+
function serendipity_db_connect()
{
global $serendipity;
-
- $serendipity['dbConn'] = sqlite_open($serendipity['serendipityPath'] . 'sqlite.db');
+
+ if (isset($serendipity['dbConn'])) {
+ return $serendipity['dbConn'];
+ }
+
+ $serendipity['dbConn'] = sqlite_open($serendipity['serendipityPath'] . $serendipity['dbName'] . '.db');
+
+ return $serendipity['dbConn'];
}
function serendipity_db_escape_string($string)
{
- static $search = array("\x00", '%', '\'', '\"');
- static $replace = array('%00', '%25', '\\\'', '\\\"');
-
+ static $search = array("\x00", '%', "'", '\"');
+ static $replace = array('%00', '%25', "''", '\\\"');
+
return str_replace($search, $replace, $string);
}
function serendipity_db_affected_rows()
{
- return sqlite_changes($GLOBALS['serendipity']['dbConn']);
+ global $serendipity;
+
+ return sqlite_changes($serendipity['dbConn']);
}
function serendipity_db_insert_id()
{
- return sqlite_last_insert_rowid($GLOBALS['serendipity']['dbConn']);
+ global $serendipity;
+
+ return sqlite_last_insert_rowid($serendipity['dbConn']);
}
-function serendipity_db_sqlite_fetch_array($res)
+function serendipity_db_sqlite_fetch_array($res, $type = SQLITE_BOTH)
{
static $search = array('%00', '%25');
static $replace = array("\x00", '%');
-
- $row = sqlite_fetch_array($res);
+
+ $row = sqlite_fetch_array($res, $type);
if (!is_array($row)) {
return $row;
}
-
- /* strip any slashes */
- $r = array();
+
+ /* strip any slashes, correct fieldname */
foreach ($row as $i => $v) {
- $r[$i] = str_replace($search, $replace, $v);
+ // TODO: If a query of the format 'SELECT a.id, b.text FROM table' is used,
+ // the sqlite extension will give us key indizes 'a.id' and 'b.text'
+ // instead of just 'id' and 'text' like in mysql/postgresql extension.
+ // To fix that, we use a preg-regex; but that is quite performance costy.
+ // Either we always need to use 'SELECT a.id AS id, b.text AS text' in query,
+ // or the sqlite extension may get fixed. :-)
+ $row[preg_replace('@^.+\.(.*)@', '\1', $i)] = str_replace($search, $replace, $v);
}
- return $r;
+ return $row;
}
-function serendipity_db_query($sql, $single = false, $result_type = "both")
+function serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr=false)
{
global $serendipity;
-
- $res = sqlite_exec($sql, $serendipity['dbConn']);
+ static $type_map = array(
+ 'assoc' => SQLITE_ASSOC,
+ 'num' => SQLITE_NUM,
+ 'both' => SQLITE_BOTH
+ );
+
+ static $debug = false;
+
+ if ($debug) $fp = @fopen('sqlite.log', 'a');
+
+ $res = sqlite_query($sql, $serendipity['dbConn']);
if (!$res) {
if (!$serendipity['production']) {
var_dump($res);
var_dump($sql);
return "problem with query";
}
+ if ($debug) fwrite($fp, '[' . date('d.m.Y H:i') . '] [ERROR] SQLITE QUERY: ' . $sql . "\n\n");
+
return false;
+ } elseif ($debug) {
+ fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE QUERY: ' . $sql . "\n\n");
}
-
+
if ($res === true) {
return true;
}
-
- $rows = array();
-
- if ($result_type == 'num') {
- while (($row = serendipity_db_sqlite_fetch_array($res))) {
- $rows[] = $row;
+
+ if (sqlite_num_rows($res) == 0) {
+ if ($single) {
+ return false;
}
+ return true;
} else {
-
- $field_names = serendipity_db_sqlite_fetch_array($res);
-
- if ($result_type == 'both') {
- while (($row = sqlite_fetch_array($res))) {
- foreach ($field_names as $i => $name) {
- $row[$name] = $row[$i];
- }
- $rows[] = $row;
- }
- } else {
+ $rows = array();
- /* string keys only */
- while (($row = serendipity_db_sqlite_fetch_array($res))) {
- $r = array();
- foreach ($field_names as $i => $name) {
- $r[$name] = $row[$i];
- }
- $rows[] = $r;
- }
+ while (($row = serendipity_db_sqlite_fetch_array($res, $type_map[$result_type]))) {
+ $rows[] = $row;
}
+
+ if ($debug) fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE RESULT: ' . print_r($rows, true). "\n\n");
+ if ($debug) fclose($fp);
+
+ if ($single && count($rows) == 1) {
+ return $rows[0];
+ }
+
+ return $rows;
}
-
- if ($single && count($rows) == 0) {
- return false;
- }
-
- if ($single && count($rows) == 1) {
- return $rows[0];
- }
-
- return $rows;
}
function serendipity_db_probe($hash, &$errs)
{
global $serendipity;
-
- $serendipity['dbConn'] = sqlite_open($serendipity['serendipityPath'] . 'sqlite.db');
+
+ $dbName = (isset($hash['sqlitedbName']) ? $hash['sqlitedbName'] : $hash['dbName']);
+
+ if (!function_exists('sqlite_open')) {
+ $errs[] = "SQLite extension not installed. Use \"pear install sqlite\" on your webserver.";
+ return false;
+ }
+
+ $serendipity['dbConn'] = sqlite_open($serendipity['serendipityPath'] . $dbName . '.db');
if ($serendipity['dbConn']) {
return true;
}
- $errs[] = "Unable to open \"{$serendipity['serendipityPath']}sqlite.db\" - check permissions!";
+ $errs[] = "Unable to open \"{$serendipity['serendipityPath']}$dbName.db\" - check permissions (directory needs to be writeable for webserver)!";
return false;
}
function serendipity_db_schema_import($query)
{
- static $search = array('{AUTOINCREMENT}', '{PRIMARY}', '{UNSIGNED}', '{FULLTEXT}');
- static $replace = array('INTEGER', 'PRIMARY KEY', '', '');
+ static $search = array('{AUTOINCREMENT}', '{PRIMARY}', '{UNSIGNED}', '{FULLTEXT}', '{BOOLEAN}');
+ static $replace = array('INTEGER', 'PRIMARY KEY', '', '', 'BOOLEAN NOT NULL');
return serendipity_db_query(str_replace($search, $replace, $query));
}
+function serendipity_db_limit($start, $offset) {
+ return $start . ', ' . $offset;
+}
+
+function serendipity_db_limit_sql($limitstring) {
+ return ' LIMIT ' . $limitstring;
+}
+
+function serendipity_db_concat($string) {
+ return 'concat(' . $string . ')';
+}
+
/* vim: set sts=4 ts=4 expandtab : */
?>
|