aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/include/functions.php2
-rw-r--r--admin/include/functions_permalinks.php4
-rw-r--r--admin/permalinks.php2
-rw-r--r--include/calendar_base.class.php6
-rw-r--r--include/dblayer/functions_mysql.inc.php6
-rw-r--r--include/dblayer/functions_pgsql.inc.php6
-rw-r--r--include/dblayer/functions_sqlite.inc.php30
-rw-r--r--include/functions_calendar.inc.php44
8 files changed, 75 insertions, 25 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 881a87e5b..d77b2cb81 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -948,7 +948,7 @@ SELECT DISTINCT(storage_category_id)
{
$query = '
UPDATE '.IMAGES_TABLE.'
- SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
+ SET path = '.pwg_db_concat(array($fulldirs[$cat_id],'\'/\'','file')).'
WHERE storage_category_id = '.$cat_id.'
;';
pwg_query($query);
diff --git a/admin/include/functions_permalinks.php b/admin/include/functions_permalinks.php
index f619e3b08..94c13be31 100644
--- a/admin/include/functions_permalinks.php
+++ b/admin/include/functions_permalinks.php
@@ -192,8 +192,8 @@ DELETE FROM '.OLD_PERMALINKS_TABLE.'
$query = '
UPDATE '.CATEGORIES_TABLE.'
SET permalink="'.$permalink.'"
- WHERE id='.$cat_id.'
- LIMIT 1';
+ WHERE id='.$cat_id;
+ // LIMIT 1';
pwg_query($query);
unset( $cache['cat_names'] ); //force regeneration
diff --git a/admin/permalinks.php b/admin/permalinks.php
index b937a8016..bb9dc4934 100644
--- a/admin/permalinks.php
+++ b/admin/permalinks.php
@@ -109,7 +109,7 @@ $template->set_filename('permalinks', 'permalinks.tpl' );
$query = '
SELECT
id,
- CONCAT(id, " - ", name, IF(permalink IS NULL, "", " √") ) AS name,
+ '.pwg_db_concat(array('id', '\' - \'', 'name', 'IF(permalink IS NULL, \'\', \' √\')')).' AS name,
uppercats, global_rank
FROM '.CATEGORIES_TABLE;
diff --git a/include/calendar_base.class.php b/include/calendar_base.class.php
index 4424c62f9..ee1fe7bea 100644
--- a/include/calendar_base.class.php
+++ b/include/calendar_base.class.php
@@ -220,6 +220,7 @@ $this->get_date_where($level).'
;';
$level_items = simple_hash_from_query($query, 'period', 'nb_images');
+ $level_items = array_to_int($level_items);
if ( count($level_items)==1 and
count($page['chronology_date'])<count($this->calendar_levels)-1)
@@ -291,13 +292,14 @@ GROUP BY period';
$current = implode('-', $page['chronology_date'] );
$upper_items = array_from_query( $query, 'period');
+ $upper_items = array_to_int($upper_items);
- usort($upper_items, 'date_compare');
+ usort($upper_items, 'version_compare');
$upper_items_rank = array_flip($upper_items);
if ( !isset($upper_items_rank[$current]) )
{
array_push($upper_items, $current);// just in case (external link)
- usort($upper_items, 'date_compare');
+ usort($upper_items, 'version_compare');
$upper_items_rank = array_flip($upper_items);
}
$current_rank = $upper_items_rank[$current];
diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php
index 80c172a36..6a29a0e40 100644
--- a/include/dblayer/functions_mysql.inc.php
+++ b/include/dblayer/functions_mysql.inc.php
@@ -458,6 +458,12 @@ function do_maintenance_all_tables()
}
}
+function pwg_db_concat($array)
+{
+ $string = implode($array, ',');
+ return 'CONCAT('. $string.')';
+}
+
function pwg_db_concat_ws($array, $separator)
{
$string = implode($array, ',');
diff --git a/include/dblayer/functions_pgsql.inc.php b/include/dblayer/functions_pgsql.inc.php
index afbb635cd..a04da9620 100644
--- a/include/dblayer/functions_pgsql.inc.php
+++ b/include/dblayer/functions_pgsql.inc.php
@@ -392,6 +392,12 @@ WHERE tablename like \''.$prefixeTable.'%\'';
);
}
+function pwg_db_concat($array)
+{
+ $string = implode($array, ',');
+ return 'ARRAY_TO_STRING(ARRAY['.$string.'])';
+}
+
function pwg_db_concat_ws($array, $separator)
{
$string = implode($array, ',');
diff --git a/include/dblayer/functions_sqlite.inc.php b/include/dblayer/functions_sqlite.inc.php
index 6acef3afd..1e25305e9 100644
--- a/include/dblayer/functions_sqlite.inc.php
+++ b/include/dblayer/functions_sqlite.inc.php
@@ -54,7 +54,9 @@ function pwg_db_connect($host, $user, $password, $database)
}
$link->createFunction('now', 'pwg_now', 0);
+ $link->createFunction('unix_timestamp', 'pwg_unix_timestamp', 0);
$link->createFunction('md5', 'md5', 1);
+ $link->createFunction('if', 'pwg_if', 3);
$link->createAggregate('std', 'pwg_std_step', 'pwg_std_finalize');
$link->createFunction('regexp', 'pwg_regexp', 2);
@@ -401,6 +403,11 @@ WHERE name LIKE \''.$prefixeTable.'%\'';
);
}
+function pwg_db_concat($array)
+{
+ return implode($array, ' || ');
+}
+
function pwg_db_concat_ws($array, $separator)
{
$glue = sprintf(' || \'%s\' || ', $separator);
@@ -468,7 +475,7 @@ function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE')
$date = '\''.$date.'\'';
}
- return 'date('.$date.',\''.$period.' DAY\')';
+ return 'date('.$date.',\''.-$period.' DAY\')';
}
function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
@@ -511,12 +518,12 @@ function pwg_db_get_dayofmonth($date)
function pwg_db_get_dayofweek($date)
{
- return 'strftime(\'%w\','.$date.')+1';
+ return 'strftime(\'%w\','.$date.')';
}
function pwg_db_get_weekday($date)
{
- return 'strftime(\'%w\','.$date.')';
+ return 'strftime(\'%w\',date('.$date.',\'-1 DAY\'))';
}
// my_error returns (or send to standard output) the message concerning the
@@ -548,6 +555,23 @@ function pwg_now()
return date('Y-m-d H:i:s');
}
+function pwg_unix_timestamp()
+{
+ return time();
+}
+
+function pwg_if($expression, $value1, $value2)
+{
+ if ($expression)
+ {
+ return $value1;
+ }
+ else
+ {
+ return $value2;
+ }
+}
+
function pwg_regexp($pattern, $string)
{
$pattern = sprintf('`%s`', $pattern);
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index 73df86fbb..cc55578f6 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -290,23 +290,35 @@ WHERE id IN (' . implode(',',$page['items']) .')';
pwg_debug('end initialize_calendar');
}
-/*
- * callback to sort array with date comparaison
- *
- **/
-function date_compare(&$a, &$b)
+function array_to_int($array)
{
- $parts = explode('-', $a);
- foreach ($parts as &$p) {
- $p = (int)$p;
- }
- $a = implode('-', $parts);
- $parts = explode('-', $b);
- foreach ($parts as &$p) {
- $p = (int)$p;
+ foreach ($array as $k => $v)
+ {
+ if ((int)$k==$k)
+ {
+ $key = (int) $k;
+ }
+ else
+ {
+ $key = $k;
+ }
+ if (is_array($v))
+ {
+ $result[$key] = array_to_int($v);
+ }
+ else
+ {
+ if (is_int($v))
+ {
+ $value = (int) $v;
+ }
+ else
+ {
+ $value = $v;
+ }
+ $result[$key] = $value;
+ }
}
- $b = implode('-', $parts);
-
- return strcmp($a, $b);
+ return $result;
}
?> \ No newline at end of file