Navigation Menu

Skip to content

Commit

Permalink
Feature_1255 :
Browse files Browse the repository at this point in the history
- single quotes in queries
- start using $conf['dblayer']

git-svn-id: http://piwigo.org/svn/trunk@4385 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
nikrou committed Nov 29, 2009
1 parent 13ea9d5 commit c960975
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 24 deletions.
6 changes: 3 additions & 3 deletions admin/cat_modify.php
Expand Up @@ -242,9 +242,9 @@
'status_values' => array('public','private'),

'CAT_STATUS' => $category['status'],
'CAT_VISIBLE' => $category['visible'],
'CAT_COMMENTABLE' => $category['commentable'],
'CAT_UPLOADABLE' => $category['uploadable'],
'CAT_VISIBLE' => boolean_to_string($category['visible']),
'CAT_COMMENTABLE' => boolean_to_string($category['commentable']),
'CAT_UPLOADABLE' => boolean_to_string($category['uploadable']),

'IMG_ORDER_DEFAULT' => empty($category['image_order']) ?
'checked="checked"' : '',
Expand Down
7 changes: 6 additions & 1 deletion admin/include/c13y_internal.class.php
Expand Up @@ -38,12 +38,17 @@ function c13y_internal()
*/
function c13y_version($c13y)
{
global $conf;

$check_list = array();

$check_list[] = array('type' => 'PHP', 'current' => phpversion(), 'required' => REQUIRED_PHP_VERSION);

$db_version = pwg_get_db_version();
$check_list[] = array('type' => 'MySQL', 'current' => $db_version, 'required' => REQUIRED_MYSQL_VERSION);
$check_list[] = array('type' => $conf['dblayer'],
'current' => $db_version,
'required' => constant('REQUIRED_'.strtoupper($conf['dblayer']).'_VERSION')
);

foreach ($check_list as $elem)
{
Expand Down
2 changes: 1 addition & 1 deletion admin/include/functions.php
Expand Up @@ -416,7 +416,7 @@ function get_fs_directories($path, $recursive = true)
function update_global_rank()
{
$query = '
SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat, uppercats, rank, global_rank
SELECT id, id_uppercat, uppercats, rank, global_rank
FROM '.CATEGORIES_TABLE.'
ORDER BY id_uppercat,rank,name';

Expand Down
12 changes: 6 additions & 6 deletions admin/include/plugins.class.php
Expand Up @@ -80,8 +80,8 @@ function perform_action($action, $plugin_id)
if (empty($errors))
{
$query = '
INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES ("'
. $plugin_id . '","' . $this->fs_plugins[$plugin_id]['version'] . '"
INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES (\''
. $plugin_id . '\',\'' . $this->fs_plugins[$plugin_id]['version'] . '\'
)';
pwg_query($query);
}
Expand Down Expand Up @@ -110,8 +110,8 @@ function perform_action($action, $plugin_id)
{
$query = '
UPDATE ' . PLUGINS_TABLE . '
SET state="active", version="'.$this->fs_plugins[$plugin_id]['version'].'"
WHERE id="' . $plugin_id . '"';
SET state=\'active\', version=\''.$this->fs_plugins[$plugin_id]['version'].'\'
WHERE id=\'' . $plugin_id . '\'';
pwg_query($query);
}
break;
Expand All @@ -126,7 +126,7 @@ function perform_action($action, $plugin_id)
die('invalid current state ' . $crt_db_plugin['state']);
}
$query = '
UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"';
UPDATE ' . PLUGINS_TABLE . ' SET state=\'inactive\' WHERE id=\'' . $plugin_id . '\'';
pwg_query($query);
if (file_exists($file_to_include))
{
Expand All @@ -144,7 +144,7 @@ function perform_action($action, $plugin_id)
die ('CANNOT UNINSTALL - NOT INSTALLED');
}
$query = '
DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"';
DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\'';
pwg_query($query);
if (file_exists($file_to_include))
{
Expand Down
2 changes: 1 addition & 1 deletion admin/intro.php
Expand Up @@ -196,7 +196,7 @@
'PWG_VERSION' => PHPWG_VERSION,
'OS' => PHP_OS,
'PHP_VERSION' => phpversion(),
'DB_ENGINE' => 'MySQL',
'DB_ENGINE' => $conf['dblayer'],
'DB_VERSION' => $db_version,
'DB_ELEMENTS' => l10n_dec('%d element', '%d elements', $nb_elements),
'DB_CATEGORIES' =>
Expand Down
3 changes: 2 additions & 1 deletion comments.php
Expand Up @@ -321,7 +321,8 @@
ON u.'.$conf['user_fields']['id'].' = com.author_id
WHERE '.implode('
AND ', $page['where_clauses']).'
GROUP BY comment_id
GROUP BY comment_id, com.image_id, ic.category_id, com.author,
com.author_id, com.date, com.content, com.validated
ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
if ('all' != $page['items_number'])
{
Expand Down
2 changes: 1 addition & 1 deletion include/common.inc.php
Expand Up @@ -92,7 +92,7 @@ function sanitize_mysql_kv(&$v, $k)

include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
include(PHPWG_ROOT_PATH .'include/dblayer/functions_mysql.inc.php');
include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php');

if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors']))
{
Expand Down
73 changes: 73 additions & 0 deletions include/dblayer/functions_mysql.inc.php
Expand Up @@ -538,6 +538,79 @@ function boolean_to_string($var)
}
}

/**
*
* interval and date functions
*
*/


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;
}

function pwg_db_get_date_YYYYMM($date)
{
return 'DATE_FORMAT('.$date.', \'%Y%m\')';
}

function pwg_db_get_date_MMDD($date)
{
return 'DATE_FORMAT('.$date.', \'%m%d\')';
}

function pwg_db_get_year($date)
{
return 'YEAR('.$date.')';
}

function pwg_db_get_month($date)
{
return 'MONTH('.$date.')';
}

function pwg_db_get_week($date, $mode=null)
{
if ($mode)
{
return 'WEEK('.$date.', '.$mode.')';
}
else
{
return 'WEEK('.$date.')';
}
}

function pwg_db_get_dayofmonth($date)
{
return 'DAYOFMONTH('.$date.')';
}

function pwg_db_get_dayofweek($date)
{
return 'DAYOFWEEK('.$date.')';
}

function pwg_db_get_weekday($date)
{
return 'WEEKDAY('.$date.')';
}

// my_error returns (or send to standard output) the message concerning the
// error occured for the last mysql query.
function my_error($header, $die)
Expand Down
5 changes: 2 additions & 3 deletions include/functions_calendar.inc.php
Expand Up @@ -258,7 +258,7 @@ function initialize_calendar()

if ($must_show_list)
{
$query = 'SELECT DISTINCT(id)';
$query = 'SELECT id';
$query .= $calendar->inner_sql.'
'.$calendar->get_date_where();
if ( isset($page['super_order_by']) )
Expand All @@ -284,9 +284,8 @@ function initialize_calendar()
$query .= '
'.$order_by;
}
$page['items'] = array_from_query($query, 'id');
$page['items'] = array_from_query($query, 'id');
}
pwg_debug('end initialize_calendar');
}

?>
2 changes: 1 addition & 1 deletion include/functions_user.inc.php
Expand Up @@ -642,7 +642,7 @@ function get_computed_categories($userdata, $filter_days=null)
}

$query.= '
GROUP BY c.id';
GROUP BY c.id, c.global_rank';

$result = pwg_query($query);

Expand Down
4 changes: 1 addition & 3 deletions include/section_init.inc.php
Expand Up @@ -122,6 +122,7 @@
}

$page = array_merge( $page, parse_section_url( $tokens, $next_token) );

if ( !isset($page['section']) )
{
$page['section'] = 'categories';
Expand Down Expand Up @@ -156,10 +157,7 @@
}
}


$page = array_merge( $page, parse_well_known_params_url( $tokens, $next_token) );


if ( script_basename()=='picture' and 'categories'==$page['section'] and
!isset($page['category']) and !isset($page['chronology_field']) )
{ //access a picture only by id, file or id-file without given section
Expand Down
1 change: 1 addition & 0 deletions install.php
Expand Up @@ -292,6 +292,7 @@ function execute_sqlfile($filepath, $replaced, $replacing)
{
$step = 2;
$file_content = '<?php
$conf[\'dblayer\'] = \'mysql\';
$conf[\'db_base\'] = \''.$dbname.'\';
$conf[\'db_user\'] = \''.$dbuser.'\';
$conf[\'db_password\'] = \''.$dbpasswd.'\';
Expand Down
2 changes: 1 addition & 1 deletion random.php
Expand Up @@ -38,7 +38,7 @@
// +-----------------------------------------------------------------------+

$query = '
SELECT DISTINCT(id)
SELECT id
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
'.get_sql_condition_FandF
Expand Down
2 changes: 1 addition & 1 deletion upgrade.php
Expand Up @@ -43,7 +43,7 @@
include(PHPWG_ROOT_PATH.'include/config_database.inc.php');
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
include(PHPWG_ROOT_PATH .'include/dblayer/functions_mysql.inc.php');
include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php');

prepare_conf_upgrade();

Expand Down
2 changes: 1 addition & 1 deletion upgrade_feed.php
Expand Up @@ -35,7 +35,7 @@
include(PHPWG_ROOT_PATH.'include/config_database.inc.php');
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
include(PHPWG_ROOT_PATH .'include/dblayer/functions_mysql.inc.php');
include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php');

// +-----------------------------------------------------------------------+
// | Check Access and exit when it is not ok |
Expand Down

0 comments on commit c960975

Please sign in to comment.