mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 11:49:56 +03:00
Feature 1255: modification in sql queries
- manage random function - manage regex syntax - manage quote (single instead of double) - manage interval git-svn-id: http://piwigo.org/svn/trunk@4367 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
d30639ec98
commit
13ea9d50e3
20 changed files with 134 additions and 112 deletions
|
@ -67,7 +67,7 @@ if (isset($_POST['submit']))
|
||||||
array(
|
array(
|
||||||
'id' => $_GET['cat_id'],
|
'id' => $_GET['cat_id'],
|
||||||
'name' => @$_POST['name'],
|
'name' => @$_POST['name'],
|
||||||
'commentable' => $_POST['commentable'],
|
'commentable' => isset($_POST['commentable'])?$_POST['commentable']:'false',
|
||||||
'uploadable' =>
|
'uploadable' =>
|
||||||
isset($_POST['uploadable']) ? $_POST['uploadable'] : 'false',
|
isset($_POST['uploadable']) ? $_POST['uploadable'] : 'false',
|
||||||
'comment' =>
|
'comment' =>
|
||||||
|
|
|
@ -196,7 +196,7 @@ elseif ('recent'== $_GET['cat'])
|
||||||
{
|
{
|
||||||
$query = 'SELECT id
|
$query = 'SELECT id
|
||||||
FROM '.IMAGES_TABLE.'
|
FROM '.IMAGES_TABLE.'
|
||||||
WHERE date_available BETWEEN DATE_SUB("'.$row['date'].'", INTERVAL 1 DAY) AND "'.$row['date'].'"';
|
WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'';
|
||||||
$page['cat_elements_id'] = array_from_query($query, 'id');
|
$page['cat_elements_id'] = array_from_query($query, 'id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ SELECT id
|
||||||
if ($recursive)
|
if ($recursive)
|
||||||
{
|
{
|
||||||
$query.= '
|
$query.= '
|
||||||
AND uppercats REGEXP \'(^|,)'.$category_id.'(,|$)\'
|
AND uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$category_id.'(,|$)\'
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -69,8 +69,8 @@ if ( isset($_POST['reset']) and !is_adviser())
|
||||||
$mb_conf = array();
|
$mb_conf = array();
|
||||||
$query = '
|
$query = '
|
||||||
UPDATE '.CONFIG_TABLE.'
|
UPDATE '.CONFIG_TABLE.'
|
||||||
SET value=""
|
SET value=\'\'
|
||||||
WHERE param="blk_'.addslashes($menu->get_id()).'"
|
WHERE param=\'blk_'.addslashes($menu->get_id()).'\'
|
||||||
LIMIT 1';
|
LIMIT 1';
|
||||||
pwg_query($query);
|
pwg_query($query);
|
||||||
}
|
}
|
||||||
|
@ -143,9 +143,9 @@ if ( isset($_POST['submit']) and !is_adviser() )
|
||||||
*/
|
*/
|
||||||
$query = '
|
$query = '
|
||||||
UPDATE '.CONFIG_TABLE.'
|
UPDATE '.CONFIG_TABLE.'
|
||||||
SET value="'.addslashes(serialize($mb_conf_db)).'"
|
SET value=\''.addslashes(serialize($mb_conf_db)).'\'
|
||||||
WHERE param="blk_'.addslashes($menu->get_id()).'"
|
WHERE param=\'blk_'.addslashes($menu->get_id()).'\'
|
||||||
LIMIT 1';
|
';
|
||||||
pwg_query($query);
|
pwg_query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ SELECT id, uppercats, global_rank, status, visible
|
||||||
if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
|
if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
|
||||||
{
|
{
|
||||||
$query.= '
|
$query.= '
|
||||||
AND uppercats REGEXP \'(^|,)'.$_POST['cat'].'(,|$)\'
|
AND uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$_POST['cat'].'(,|$)\'
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -207,10 +207,7 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
|
||||||
}
|
}
|
||||||
|
|
||||||
// next category id available
|
// next category id available
|
||||||
$query = '
|
$next_id = pwg_db_nextval('id', CATEGORIES_TABLE);
|
||||||
SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
|
|
||||||
FROM '.CATEGORIES_TABLE;
|
|
||||||
list($next_id) = pwg_db_fetch_row(pwg_query($query));
|
|
||||||
|
|
||||||
// retrieve sub-directories fulldirs from the site reader
|
// retrieve sub-directories fulldirs from the site reader
|
||||||
$fs_fulldirs = $site_reader->get_full_directories($basedir);
|
$fs_fulldirs = $site_reader->get_full_directories($basedir);
|
||||||
|
@ -399,10 +396,7 @@ SELECT file,storage_category_id
|
||||||
}
|
}
|
||||||
|
|
||||||
// next element id available
|
// next element id available
|
||||||
$query = '
|
$next_element_id = pwg_db_nextval('id', IMAGES_TABLE);
|
||||||
SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
|
|
||||||
FROM '.IMAGES_TABLE;
|
|
||||||
list($next_element_id) = pwg_db_fetch_row(pwg_query($query));
|
|
||||||
|
|
||||||
$start = get_moment();
|
$start = get_moment();
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,11 @@ $items_number = array(5,10,20,50,'all');
|
||||||
//
|
//
|
||||||
$since_options = array(
|
$since_options = array(
|
||||||
1 => array('label' => l10n('today'),
|
1 => array('label' => l10n('today'),
|
||||||
'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 1 DAY)'),
|
'clause' => 'date > '.pwg_db_get_recent_period_expression(1)),
|
||||||
2 => array('label' => sprintf(l10n('last %d days'), 7),
|
2 => array('label' => sprintf(l10n('last %d days'), 7),
|
||||||
'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 7 DAY)'),
|
'clause' => 'date > '.pwg_db_get_recent_period_expression(7)),
|
||||||
3 => array('label' => sprintf(l10n('last %d days'), 30),
|
3 => array('label' => sprintf(l10n('last %d days'), 30),
|
||||||
'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 30 DAY)'),
|
'clause' => 'date > '.pwg_db_get_recent_period_expression(30)),
|
||||||
4 => array('label' => l10n('the beginning'),
|
4 => array('label' => l10n('the beginning'),
|
||||||
'clause' => '1=1') // stupid but generic
|
'clause' => '1=1') // stupid but generic
|
||||||
);
|
);
|
||||||
|
@ -138,7 +138,7 @@ $page['where_clauses'][] = $since_options[$page['since']]['clause'];
|
||||||
// which status to filter on ?
|
// which status to filter on ?
|
||||||
if ( !is_admin() )
|
if ( !is_admin() )
|
||||||
{
|
{
|
||||||
$page['where_clauses'][] = 'validated="true"';
|
$page['where_clauses'][] = 'validated=\'true\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
$page['where_clauses'][] = get_sql_condition_FandF
|
$page['where_clauses'][] = get_sql_condition_FandF
|
||||||
|
|
2
feed.php
2
feed.php
|
@ -156,7 +156,7 @@ if ( !empty($feed_id) and empty($news) )
|
||||||
{
|
{
|
||||||
$query = '
|
$query = '
|
||||||
UPDATE '.USER_FEED_TABLE.'
|
UPDATE '.USER_FEED_TABLE.'
|
||||||
SET last_check = DATE_ADD(\''.$dbnow.'\', INTERVAL -15 DAY )
|
SET last_check = '.pwg_db_get_recent_period_expression(-15, $dbnow).'
|
||||||
WHERE id = \''.$feed_id.'\'
|
WHERE id = \''.$feed_id.'\'
|
||||||
;';
|
;';
|
||||||
pwg_query($query);
|
pwg_query($query);
|
||||||
|
|
|
@ -268,7 +268,7 @@ $this->get_date_where($level).'
|
||||||
$prev = $next =null;
|
$prev = $next =null;
|
||||||
if ( empty($page['chronology_date']) )
|
if ( empty($page['chronology_date']) )
|
||||||
return;
|
return;
|
||||||
$query = 'SELECT CONCAT_WS("-"';
|
$query = 'SELECT CONCAT_WS(\'-\'';
|
||||||
for ($i=0; $i<count($page['chronology_date']); $i++)
|
for ($i=0; $i<count($page['chronology_date']); $i++)
|
||||||
{
|
{
|
||||||
if ( 'any' === $page['chronology_date'][$i] )
|
if ( 'any' === $page['chronology_date'][$i] )
|
||||||
|
|
|
@ -347,7 +347,7 @@ SELECT id, file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 a
|
||||||
$query.= $this->inner_sql;
|
$query.= $this->inner_sql;
|
||||||
$query.= $this->get_date_where();
|
$query.= $this->get_date_where();
|
||||||
$query.= '
|
$query.= '
|
||||||
ORDER BY RAND()
|
ORDER BY '.DB_RANDOM_FUNCTION.'()
|
||||||
LIMIT 1';
|
LIMIT 1';
|
||||||
unset ( $page['chronology_date'][CDAY] );
|
unset ( $page['chronology_date'][CDAY] );
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,7 @@ SELECT
|
||||||
c.*, nb_images, date_last, max_date_last, count_images, count_categories
|
c.*, nb_images, date_last, max_date_last, count_images, count_categories
|
||||||
FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
|
FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
|
||||||
ON id = cat_id and user_id = '.$user['id'].'
|
ON id = cat_id and user_id = '.$user['id'].'
|
||||||
WHERE date_last >= SUBDATE(
|
WHERE date_last >= '.pwg_db_get_recent_period_expression($user['recent_period']).'
|
||||||
CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
|
|
||||||
)
|
|
||||||
'.get_sql_condition_FandF
|
'.get_sql_condition_FandF
|
||||||
(
|
(
|
||||||
array
|
array
|
||||||
|
@ -104,7 +102,7 @@ SELECT image_id
|
||||||
),
|
),
|
||||||
"\n AND"
|
"\n AND"
|
||||||
).'
|
).'
|
||||||
ORDER BY RAND()
|
ORDER BY '.DB_RANDOM_FUNCTION.'()
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
;';
|
;';
|
||||||
$subresult = pwg_query($query);
|
$subresult = pwg_query($query);
|
||||||
|
@ -132,7 +130,7 @@ SELECT image_id
|
||||||
),
|
),
|
||||||
"\n AND"
|
"\n AND"
|
||||||
).'
|
).'
|
||||||
ORDER BY RAND()
|
ORDER BY '.DB_RANDOM_FUNCTION.'()
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
;';
|
;';
|
||||||
$subresult = pwg_query($query);
|
$subresult = pwg_query($query);
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
// | USA. |
|
// | USA. |
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
||||||
|
define('DB_ENGINE', 'MySQL');
|
||||||
|
|
||||||
|
define('DB_REGEX_OPERATOR', 'REGEXP');
|
||||||
|
define('DB_RANDOM_FUNCTION', 'RAND');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* simple functions
|
* simple functions
|
||||||
|
@ -107,6 +112,16 @@ function pwg_query($query)
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pwg_db_nextval($column, $table)
|
||||||
|
{
|
||||||
|
$query = '
|
||||||
|
SELECT IF(MAX('.$column.')+1 IS NULL, 1, MAX('.$column.')+1)
|
||||||
|
FROM '.$table;
|
||||||
|
list($next) = pwg_db_fetch_row(pwg_query($query));
|
||||||
|
|
||||||
|
return $next;
|
||||||
|
}
|
||||||
|
|
||||||
function pwg_db_changes($result)
|
function pwg_db_changes($result)
|
||||||
{
|
{
|
||||||
return mysql_affected_rows($result);
|
return mysql_affected_rows($result);
|
||||||
|
@ -443,6 +458,86 @@ function do_maintenance_all_tables()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE')
|
||||||
|
{
|
||||||
|
if ($date!='CURRENT_DATE')
|
||||||
|
{
|
||||||
|
$date = '\''.$date.'\'';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'SUBDATE('.$date.',INTERVAL '.$period.' DAY)';
|
||||||
|
}
|
||||||
|
|
||||||
|
function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
|
||||||
|
{
|
||||||
|
$query = '
|
||||||
|
SELECT '.pwg_db_get_recent_period_expression($period);
|
||||||
|
list($d) = pwg_db_fetch_row(pwg_query($query));
|
||||||
|
|
||||||
|
return $d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns an array containing the possible values of an enum field
|
||||||
|
*
|
||||||
|
* @param string tablename
|
||||||
|
* @param string fieldname
|
||||||
|
*/
|
||||||
|
function get_enums($table, $field)
|
||||||
|
{
|
||||||
|
// retrieving the properties of the table. Each line represents a field :
|
||||||
|
// columns are 'Field', 'Type'
|
||||||
|
$result = pwg_query('desc '.$table);
|
||||||
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
|
{
|
||||||
|
// we are only interested in the the field given in parameter for the
|
||||||
|
// function
|
||||||
|
if ($row['Field'] == $field)
|
||||||
|
{
|
||||||
|
// retrieving possible values of the enum field
|
||||||
|
// enum('blue','green','black')
|
||||||
|
$options = explode(',', substr($row['Type'], 5, -1));
|
||||||
|
foreach ($options as $i => $option)
|
||||||
|
{
|
||||||
|
$options[$i] = str_replace("'", '',$option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pwg_db_free_result($result);
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get_boolean transforms a string to a boolean value. If the string is
|
||||||
|
// "false" (case insensitive), then the boolean value false is returned. In
|
||||||
|
// any other case, true is returned.
|
||||||
|
function get_boolean( $string )
|
||||||
|
{
|
||||||
|
$boolean = true;
|
||||||
|
if ( 'false' == strtolower($string) )
|
||||||
|
{
|
||||||
|
$boolean = false;
|
||||||
|
}
|
||||||
|
return $boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns boolean string 'true' or 'false' if the given var is boolean
|
||||||
|
*
|
||||||
|
* @param mixed $var
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function boolean_to_string($var)
|
||||||
|
{
|
||||||
|
if (is_bool($var))
|
||||||
|
{
|
||||||
|
return $var ? 'true' : 'false';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// my_error returns (or send to standard output) the message concerning the
|
// my_error returns (or send to standard output) the message concerning the
|
||||||
// error occured for the last mysql query.
|
// error occured for the last mysql query.
|
||||||
function my_error($header, $die)
|
function my_error($header, $die)
|
||||||
|
|
|
@ -96,8 +96,7 @@ WHERE ';
|
||||||
category_id IN ('.$filter['visible_categories'].') and';
|
category_id IN ('.$filter['visible_categories'].') and';
|
||||||
}
|
}
|
||||||
$query.= '
|
$query.= '
|
||||||
date_available >= SUBDATE(
|
date_available >= '.pwg_db_get_recent_period_expression($filter['recent_period']);
|
||||||
CURRENT_DATE,INTERVAL '.$filter['recent_period'].' DAY)';
|
|
||||||
|
|
||||||
$filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
|
$filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
|
||||||
|
|
||||||
|
|
|
@ -33,67 +33,6 @@ include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
|
||||||
|
|
||||||
//----------------------------------------------------------- generic functions
|
//----------------------------------------------------------- generic functions
|
||||||
|
|
||||||
/**
|
|
||||||
* returns an array containing the possible values of an enum field
|
|
||||||
*
|
|
||||||
* @param string tablename
|
|
||||||
* @param string fieldname
|
|
||||||
*/
|
|
||||||
function get_enums($table, $field)
|
|
||||||
{
|
|
||||||
// retrieving the properties of the table. Each line represents a field :
|
|
||||||
// columns are 'Field', 'Type'
|
|
||||||
$result = pwg_query('desc '.$table);
|
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
|
||||||
{
|
|
||||||
// we are only interested in the the field given in parameter for the
|
|
||||||
// function
|
|
||||||
if ($row['Field'] == $field)
|
|
||||||
{
|
|
||||||
// retrieving possible values of the enum field
|
|
||||||
// enum('blue','green','black')
|
|
||||||
$options = explode(',', substr($row['Type'], 5, -1));
|
|
||||||
foreach ($options as $i => $option)
|
|
||||||
{
|
|
||||||
$options[$i] = str_replace("'", '',$option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pwg_db_free_result($result);
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get_boolean transforms a string to a boolean value. If the string is
|
|
||||||
// "false" (case insensitive), then the boolean value false is returned. In
|
|
||||||
// any other case, true is returned.
|
|
||||||
function get_boolean( $string )
|
|
||||||
{
|
|
||||||
$boolean = true;
|
|
||||||
if ( 'false' == strtolower($string) )
|
|
||||||
{
|
|
||||||
$boolean = false;
|
|
||||||
}
|
|
||||||
return $boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns boolean string 'true' or 'false' if the given var is boolean
|
|
||||||
*
|
|
||||||
* @param mixed $var
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function boolean_to_string($var)
|
|
||||||
{
|
|
||||||
if (is_bool($var))
|
|
||||||
{
|
|
||||||
return $var ? 'true' : 'false';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $var;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The function get_moment returns a float value coresponding to the number
|
// The function get_moment returns a float value coresponding to the number
|
||||||
// of seconds since the unix epoch (1st January 1970) and the microseconds
|
// of seconds since the unix epoch (1st January 1970) and the microseconds
|
||||||
// are precised : e.g. 1052343429.89276600
|
// are precised : e.g. 1052343429.89276600
|
||||||
|
@ -540,8 +479,8 @@ INSERT INTO '.HISTORY_TABLE.'
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
(
|
(
|
||||||
CURDATE(),
|
CURRENT_DATE,
|
||||||
CURTIME(),
|
CURRENT_TIME,
|
||||||
'.$user['id'].',
|
'.$user['id'].',
|
||||||
\''.$_SERVER['REMOTE_ADDR'].'\',
|
\''.$_SERVER['REMOTE_ADDR'].'\',
|
||||||
'.(isset($page['section']) ? "'".$page['section']."'" : 'NULL').',
|
'.(isset($page['section']) ? "'".$page['section']."'" : 'NULL').',
|
||||||
|
@ -1497,9 +1436,7 @@ function get_icon($date, $is_child_date = false)
|
||||||
if (!isset($cache['get_icon']['sql_recent_date']))
|
if (!isset($cache['get_icon']['sql_recent_date']))
|
||||||
{
|
{
|
||||||
// Use MySql date in order to standardize all recent "actions/queries"
|
// Use MySql date in order to standardize all recent "actions/queries"
|
||||||
list($cache['get_icon']['sql_recent_date']) =
|
$cache['get_icon']['sql_recent_date'] = pwg_db_get_recent_period($user['recent_period']);
|
||||||
pwg_db_fetch_row(pwg_query('select SUBDATE(
|
|
||||||
CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache['get_icon'][$date] = $date > $cache['get_icon']['sql_recent_date'];
|
$cache['get_icon'][$date] = $date > $cache['get_icon']['sql_recent_date'];
|
||||||
|
|
|
@ -377,7 +377,7 @@ SELECT DISTINCT(id)
|
||||||
$query.= '
|
$query.= '
|
||||||
OR ';
|
OR ';
|
||||||
}
|
}
|
||||||
$query.= 'uppercats REGEXP \'(^|,)'.$category_id.'(,|$)\'';
|
$query.= 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$category_id.'(,|$)\'';
|
||||||
}
|
}
|
||||||
$query.= '
|
$query.= '
|
||||||
;';
|
;';
|
||||||
|
|
|
@ -463,7 +463,7 @@ SELECT DISTINCT id, path, name, tn_ext, file
|
||||||
'.$where_sql.'
|
'.$where_sql.'
|
||||||
AND date_available="'.$dates[$i]['date_available'].'"
|
AND date_available="'.$dates[$i]['date_available'].'"
|
||||||
AND tn_ext IS NOT NULL
|
AND tn_ext IS NOT NULL
|
||||||
ORDER BY RAND(NOW())
|
ORDER BY '.DB_RANDOM_FUNCTION.'())
|
||||||
LIMIT '.$max_elements.'
|
LIMIT '.$max_elements.'
|
||||||
;';
|
;';
|
||||||
$dates[$i]['elements'] = array();
|
$dates[$i]['elements'] = array();
|
||||||
|
|
|
@ -224,7 +224,7 @@ SELECT * FROM '.PLUGINS_TABLE;
|
||||||
$clauses = array();
|
$clauses = array();
|
||||||
if (!empty($state))
|
if (!empty($state))
|
||||||
{
|
{
|
||||||
$clauses[] = 'state="'.$state.'"';
|
$clauses[] = 'state=\''.$state.'\'';
|
||||||
}
|
}
|
||||||
if (!empty($id))
|
if (!empty($id))
|
||||||
{
|
{
|
||||||
|
|
|
@ -385,8 +385,8 @@ INSERT INTO '.USER_CACHE_TABLE.'
|
||||||
VALUES
|
VALUES
|
||||||
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\','
|
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\','
|
||||||
.$userdata['cache_update_time'].',\''
|
.$userdata['cache_update_time'].',\''
|
||||||
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
|
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',\''
|
||||||
.$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")';
|
.$userdata['image_access_type'].'\',\''.$userdata['image_access_list'].'\')';
|
||||||
pwg_query($query);
|
pwg_query($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -632,7 +632,7 @@ FROM '.CATEGORIES_TABLE.' as c
|
||||||
|
|
||||||
if ( isset($filter_days) )
|
if ( isset($filter_days) )
|
||||||
{
|
{
|
||||||
$query .= ' AND i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
|
$query .= ' AND i.date_available > '.pwg_db_get_recent_period_expression($filter_days);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($userdata['forbidden_categories']) )
|
if ( !empty($userdata['forbidden_categories']) )
|
||||||
|
@ -1039,7 +1039,7 @@ function try_log_user($username, $password, $remember_me)
|
||||||
SELECT '.$conf['user_fields']['id'].' AS id,
|
SELECT '.$conf['user_fields']['id'].' AS id,
|
||||||
'.$conf['user_fields']['password'].' AS password
|
'.$conf['user_fields']['password'].' AS password
|
||||||
FROM '.USERS_TABLE.'
|
FROM '.USERS_TABLE.'
|
||||||
WHERE '.$conf['user_fields']['username'].' = \''.mysql_real_escape_string($username).'\'
|
WHERE '.$conf['user_fields']['username'].' = \''.pwg_db_real_escape_string($username).'\'
|
||||||
;';
|
;';
|
||||||
$row = pwg_db_fetch_assoc(pwg_query($query));
|
$row = pwg_db_fetch_assoc(pwg_query($query));
|
||||||
if ($row['password'] == $conf['pass_convert']($password))
|
if ($row['password'] == $conf['pass_convert']($password))
|
||||||
|
|
|
@ -449,8 +449,7 @@ SELECT DISTINCT(id)
|
||||||
FROM '.IMAGES_TABLE.'
|
FROM '.IMAGES_TABLE.'
|
||||||
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
|
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
|
||||||
WHERE
|
WHERE
|
||||||
date_available >= SUBDATE(
|
date_available >= '.pwg_db_get_recent_period_expression($user['recent_period']).'
|
||||||
CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)
|
|
||||||
'.$forbidden.'
|
'.$forbidden.'
|
||||||
'.$conf['order_by'].'
|
'.$conf['order_by'].'
|
||||||
;';
|
;';
|
||||||
|
|
|
@ -121,15 +121,15 @@ function ws_std_image_sql_order( $params, $tbl_name='' )
|
||||||
case 'date_posted':
|
case 'date_posted':
|
||||||
$matches[1][$i] = 'date_available'; break;
|
$matches[1][$i] = 'date_available'; break;
|
||||||
case 'rand': case 'random':
|
case 'rand': case 'random':
|
||||||
$matches[1][$i] = 'RAND()'; break;
|
$matches[1][$i] = DB_RANDOM_FUNCTION.'()'; break;
|
||||||
}
|
}
|
||||||
$sortable_fields = array('id', 'file', 'name', 'hit', 'average_rate',
|
$sortable_fields = array('id', 'file', 'name', 'hit', 'average_rate',
|
||||||
'date_creation', 'date_available', 'RAND()' );
|
'date_creation', 'date_available', DB_RANDOM_FUNCTION.'()' );
|
||||||
if ( in_array($matches[1][$i], $sortable_fields) )
|
if ( in_array($matches[1][$i], $sortable_fields) )
|
||||||
{
|
{
|
||||||
if (!empty($ret))
|
if (!empty($ret))
|
||||||
$ret .= ', ';
|
$ret .= ', ';
|
||||||
if ($matches[1][$i] != 'RAND()' )
|
if ($matches[1][$i] != DB_RANDOM_FUNCTION.'()' )
|
||||||
{
|
{
|
||||||
$ret .= $tbl_name;
|
$ret .= $tbl_name;
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ function ws_categories_getImages($params, &$service)
|
||||||
continue;
|
continue;
|
||||||
if ($params['recursive'])
|
if ($params['recursive'])
|
||||||
{
|
{
|
||||||
$where_clauses[] = 'uppercats REGEXP \'(^|,)'.$cat_id.'(,|$)\'';
|
$where_clauses[] = 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$cat_id.'(,|$)\'';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -377,7 +377,7 @@ function ws_categories_getList($params, &$service)
|
||||||
}
|
}
|
||||||
else if ($params['cat_id']>0)
|
else if ($params['cat_id']>0)
|
||||||
{
|
{
|
||||||
$where[] = 'uppercats REGEXP \'(^|,)'.
|
$where[] = 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.
|
||||||
(int)($params['cat_id'])
|
(int)($params['cat_id'])
|
||||||
.'(,|$)\'';
|
.'(,|$)\'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ SELECT DISTINCT(id)
|
||||||
),
|
),
|
||||||
'WHERE'
|
'WHERE'
|
||||||
).'
|
).'
|
||||||
ORDER BY RAND(NOW())
|
ORDER BY '.DB_RANDOM_FUNCTION.'()
|
||||||
LIMIT '.min(50, $conf['top_number'],$user['nb_image_page']).'
|
LIMIT '.min(50, $conf['top_number'],$user['nb_image_page']).'
|
||||||
;';
|
;';
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue