aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2004-10-30 15:42:29 +0000
committerz0rglub <z0rglub@piwigo.org>2004-10-30 15:42:29 +0000
commit7cd9b65e3299fb8bc6a83e65f89fcecca62f3178 (patch)
treee068090892b16db654a2bf0c2886b65eaf44a14f /include
parent3730c810f254267ab1fb49f4cad55866e780ad6e (diff)
- function mysql_query replaced by pwg_query : the same with debugging
features - by default, DEBUG is set to 0 (off) git-svn-id: http://piwigo.org/svn/trunk@587 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/category_calendar.inc.php16
-rw-r--r--include/category_default.inc.php4
-rw-r--r--include/category_recent_cats.inc.php4
-rw-r--r--include/category_subcats.inc.php6
-rw-r--r--include/common.inc.php2
-rw-r--r--include/config.inc.php2
-rw-r--r--include/constants.php4
-rw-r--r--include/functions.inc.php40
-rw-r--r--include/functions_category.inc.php38
-rw-r--r--include/functions_group.inc.php6
-rw-r--r--include/functions_session.inc.php4
-rw-r--r--include/functions_user.inc.php20
-rw-r--r--include/user.inc.php6
13 files changed, 80 insertions, 72 deletions
diff --git a/include/category_calendar.inc.php b/include/category_calendar.inc.php
index fddf1b2cf..60851e692 100644
--- a/include/category_calendar.inc.php
+++ b/include/category_calendar.inc.php
@@ -39,7 +39,7 @@ SELECT YEAR('.$conf['calendar_datefield'].') AS year, COUNT(id) AS count
AND id = image_id
GROUP BY year
;';
-$result = mysql_query($query);
+$result = pwg_query($query);
$calendar_years = array();
while ($row = mysql_fetch_array($result))
{
@@ -92,7 +92,7 @@ SELECT DISTINCT(MONTH('.$conf['calendar_datefield'].')) AS month
AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
GROUP BY MONTH('.$conf['calendar_datefield'].')
;';
- $result = mysql_query($query);
+ $result = pwg_query($query);
$calendar_months = array();
while ($row = mysql_fetch_array($result))
{
@@ -164,7 +164,7 @@ SELECT DISTINCT('.$conf['calendar_datefield'].') AS day, COUNT(id) AS count
AND MONTH('.$conf['calendar_datefield'].') = '.$page['calendar_month'].'
GROUP BY day
;';
- $result = mysql_query($query);
+ $result = pwg_query($query);
$calendar_days = array();
while ($row = mysql_fetch_array($result))
{
@@ -188,7 +188,7 @@ SELECT category_id AS category, COUNT(id) AS count
AND id = image_id
GROUP BY category_id
;';
- $result = mysql_query($query);
+ $result = pwg_query($query);
$calendar_categories = array();
// special category 0 : gathering all available categories (0 cannot be a
// oregular category identifier)
@@ -227,7 +227,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
ORDER BY RAND()
LIMIT 0,1
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
$thumbnail_src = get_thumbnail_src($row['file'],
$row['storage_category_id'],
@@ -275,7 +275,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
ORDER BY RAND()
LIMIT 0,1
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
$thumbnail_src = get_thumbnail_src($row['file'],
$row['storage_category_id'],
@@ -330,7 +330,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
ORDER BY RAND()
LIMIT 0,1
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
$thumbnail_src = get_thumbnail_src($row['file'],
$row['storage_category_id'],
@@ -399,7 +399,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
ORDER BY RAND()
LIMIT 0,1
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
$thumbnail_src = get_thumbnail_src($row['file'],
$row['storage_category_id'],
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index 0bed31a36..58ec78dde 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -47,7 +47,7 @@ SELECT DISTINCT(id),file,date_available,category_id
LIMIT '.$page['start'].','.$page['nb_image_page'].'
;';
// echo '<pre>'.$query.'</pre>';
-$result = mysql_query($query);
+$result = pwg_query($query);
// template thumbnail initialization
if ( mysql_num_rows($result) > 0 )
@@ -128,7 +128,7 @@ SELECT COUNT(*) AS nb_comments
WHERE image_id = '.$row['id'].'
AND validated = \'true\'
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
$template->assign_block_vars(
'thumbnails.line.thumbnail.nb_comments',
array('NB_COMMENTS'=>$row['nb_comments']));
diff --git a/include/category_recent_cats.inc.php b/include/category_recent_cats.inc.php
index a71148353..3f11f81c1 100644
--- a/include/category_recent_cats.inc.php
+++ b/include/category_recent_cats.inc.php
@@ -46,7 +46,7 @@ if ( $user['forbidden_categories'] != '' )
}
$query.= '
;';
-$result = mysql_query( $query );
+$result = pwg_query( $query );
// template thumbnail initialization
if (mysql_num_rows($result) > 0)
@@ -75,7 +75,7 @@ SELECT id,file,tn_ext,storage_category_id
ORDER BY RAND()
LIMIT 0,1
;';
- $subrow = mysql_fetch_array( mysql_query( $query ) );
+ $subrow = mysql_fetch_array( pwg_query( $query ) );
$thumbnail_src = get_thumbnail_src($subrow['file'],
$subrow['storage_category_id'],
diff --git a/include/category_subcats.inc.php b/include/category_subcats.inc.php
index 6758f9e9a..34e86a93d 100644
--- a/include/category_subcats.inc.php
+++ b/include/category_subcats.inc.php
@@ -50,7 +50,7 @@ if (count($subcats) > 0)
// current row displayed
$row_number = 0;
}
-
+
foreach ($subcats as $subcat_id => $non_empty_id)
{
$name = $page['plain_structure'][$subcat_id]['name'];
@@ -61,7 +61,7 @@ SELECT representative_picture_id
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$non_empty_id.'
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
$query = '
SELECT file,tn_ext,storage_category_id
@@ -83,7 +83,7 @@ SELECT file,tn_ext,storage_category_id
}
$query.= '
;';
- $image_result = mysql_query($query);
+ $image_result = pwg_query($query);
$image_row = mysql_fetch_array($image_result);
$thumbnail_link = get_thumbnail_src($image_row['file'],
diff --git a/include/common.inc.php b/include/common.inc.php
index 8853e67f1..76c983134 100644
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -171,7 +171,7 @@ $query = '
SELECT param,value
FROM '.CONFIG_TABLE.'
;';
-if( !( $result = mysql_query( $query ) ) )
+if( !( $result = pwg_query( $query ) ) )
{
die("Could not query config information");
}
diff --git a/include/config.inc.php b/include/config.inc.php
index baf2ef2db..e1a9acfa2 100644
--- a/include/config.inc.php
+++ b/include/config.inc.php
@@ -121,7 +121,7 @@ $conf['show_exif_fields'] = array('Make',
// calendar_datefield : date field of table "images" used for calendar
// catgory
-$conf['calendar_datefield'] = 'date_available';
+$conf['calendar_datefield'] = 'date_creation';
// rate : enable feature for rating elements
$conf['rate'] = true;
diff --git a/include/constants.php b/include/constants.php
index be641fd10..f9b9044fe 100644
--- a/include/constants.php
+++ b/include/constants.php
@@ -32,8 +32,8 @@ define('PHPWG_URL', 'http://www.phpwebgallery.net');
define('PHPWG_FORUM_URL', 'http://forum.phpwebgallery.net');
// Debug Level
-define('DEBUG', 1); // Debugging on
-//define('DEBUG', 0); // Debugging off
+//define('DEBUG', 1); // Debugging on
+define('DEBUG', 0); // Debugging off
// User level
define('ANONYMOUS', 2);
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 82577b66e..af2c6d6b3 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -51,7 +51,7 @@ function get_enums( $table, $field )
{
// retrieving the properties of the table. Each line represents a field :
// columns are 'Field', 'Type'
- $result=mysql_query("desc $table");
+ $result=pwg_query("desc $table");
while ( $row = mysql_fetch_array( $result ) )
{
// we are only interested in the the field given in parameter for the
@@ -350,7 +350,7 @@ function pwg_log( $file, $category, $picture = '' )
$query.= " (NOW(), '".$user['username']."'";
$query.= ",'".$_SERVER['REMOTE_ADDR']."'";
$query.= ",'".$file."','".$category."','".$picture."');";
- mysql_query( $query );
+ pwg_query( $query );
}
}
@@ -408,7 +408,7 @@ function notify( $type, $infos = '' )
$query.= " WHERE status = 'admin'";
$query.= ' AND mail_address IS NOT NULL';
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$to = $row['mail_address'];
@@ -444,22 +444,26 @@ function pwg_write_debug()
fclose( $fp );
}
-function pwg_query( $query )
+function pwg_query($query)
{
- global $count_queries,$queries_time;
-
$start = get_moment();
- $output = '';
-
- $count_queries++;
- $output.= '<br /><br />['.$count_queries.'] '.$query;
- $result = mysql_query( $query );
- $time = get_moment() - $start;
- $queries_time+= $time;
- $output.= '<b>('.number_format( $time, 3, '.', ' ').' s)</b>';
- $output.= '('.number_format( $queries_time, 3, '.', ' ').' s)';
-
- // echo $output;
+ $result = mysql_query($query);
+
+ if (DEBUG)
+ {
+ global $count_queries,$queries_time;
+
+ $time = get_moment() - $start;
+ $count_queries++;
+
+ $output = '';
+ $output.= '<pre>['.$count_queries.'] '."\n".$query;
+ $queries_time+= $time;
+ $output.= "\n".'(this query time : '.number_format( $time, 3, '.', ' ').' s)</b>';
+ $output.= "\n".'(total SQL time : '.number_format( $queries_time, 3, '.', ' ').' s)';
+ $output.= '</pre>';
+ echo $output;
+ }
return $result;
}
@@ -594,4 +598,4 @@ function get_thumbnail_src($file, $storage_category_id, $tn_ext = '')
return $src;
}
-?> \ No newline at end of file
+?>
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 6171b562c..f924d5c83 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -88,7 +88,7 @@ function check_cat_id( $cat )
{
$query = 'SELECT id';
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat.';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
if ( mysql_num_rows( $result ) != 0 )
{
$page['cat'] = $cat;
@@ -139,7 +139,7 @@ function get_user_plain_structure()
$query.= ';';
$plain_structure = array();
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$category = array();
@@ -270,7 +270,7 @@ function count_user_total_images()
// $query = '
// ;';
- $row = mysql_fetch_array( mysql_query( $query ) );
+ $row = mysql_fetch_array( pwg_query( $query ) );
if ( !isset( $row['total'] ) ) $row['total'] = 0;
@@ -306,7 +306,7 @@ function get_cat_info( $id )
$query.= ' WHERE a.id = '.$id;
$query.= ' AND a.site_id = b.id';
$query.= ';';
- $row = mysql_fetch_array( mysql_query( $query ) );
+ $row = mysql_fetch_array( pwg_query( $query ) );
$cat = array();
// affectation of each field of the table "config" to an information of the
@@ -329,7 +329,7 @@ function get_cat_info( $id )
$query.= ' WHERE id IN ('.$cat['uppercats'].')';
$query.= ' ORDER BY id ASC';
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while( $row = mysql_fetch_array( $result ) )
{
$cat['name'][$row['id']] = $row['name'];
@@ -368,7 +368,7 @@ function get_local_dir( $category_id )
$query = 'SELECT uppercats';
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
$query.= ';';
- $row = mysql_fetch_array( mysql_query( $query ) );
+ $row = mysql_fetch_array( pwg_query( $query ) );
$uppercats = $row['uppercats'];
}
@@ -378,7 +378,7 @@ function get_local_dir( $category_id )
$query = 'SELECT id,dir';
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while( $row = mysql_fetch_array( $result ) )
{
$database_dirs[$row['id']] = $row['dir'];
@@ -403,7 +403,7 @@ SELECT galleries_url
WHERE s.id = c.site_id
AND c.id = '.$category_id.'
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
return $row['galleries_url'];
}
@@ -593,7 +593,7 @@ SELECT DISTINCT(id) AS id
FROM '.CATEGORIES_TABLE.'
WHERE '.implode(' OR ', $search_cat_clauses).'
;';
- $result = mysql_query($query);
+ $result = pwg_query($query);
$cat_ids = array();
while ($row = mysql_fetch_array($result))
{
@@ -668,9 +668,13 @@ SELECT COUNT(DISTINCT(id)) AS nb_total_images
else if ( $page['cat'] == 'most_visited' )
{
$page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
-
- if ( isset( $forbidden ) ) $page['where'] = ' WHERE '.$forbidden;
- else $page['where'] = '';
+
+ $page['where'] = 'WHERE hit > 0';
+ if (isset($forbidden))
+ {
+ $page['where'] = "\n".' AND '.$forbidden;
+ }
+
$conf['order_by'] = ' ORDER BY hit DESC, file ASC';
$page['cat_nb_images'] = $conf['top_number'];
if ( isset( $page['start'] )
@@ -749,7 +753,7 @@ SELECT COUNT(1) AS count
FROM '.IMAGES_TABLE.'
'.$page['where'].'
;';
- $row = mysql_fetch_array(mysql_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
if ($row['count'] < $conf['top_number'])
{
$page['cat_nb_images'] = $row['count'];
@@ -788,7 +792,7 @@ SELECT COUNT(1) AS count
if (isset($query))
{
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
$row = mysql_fetch_array( $result );
$page['cat_nb_images'] = $row['nb_total_images'];
}
@@ -843,7 +847,7 @@ function get_non_empty_subcat_ids( $id_uppercat )
$query.= ' ORDER BY rank';
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
// only categories with findable picture in any of its subcats is
@@ -874,7 +878,7 @@ function get_first_non_empty_cat_id( $id_uppercat )
}
$query.= ' ORDER BY RAND()';
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
if ( $row['nb_images'] > 0 )
@@ -882,7 +886,7 @@ function get_first_non_empty_cat_id( $id_uppercat )
return $row['id'];
}
}
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
// recursive call
diff --git a/include/functions_group.inc.php b/include/functions_group.inc.php
index 12e85bd49..0a4356e3a 100644
--- a/include/functions_group.inc.php
+++ b/include/functions_group.inc.php
@@ -34,7 +34,7 @@ function get_group_restrictions( $group_id )
$query.= ' FROM '.PREFIX_TABLE.'categories';
$query.= " WHERE status = 'private'";
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
$privates = array();
while ( $row = mysql_fetch_array( $result ) )
{
@@ -46,7 +46,7 @@ function get_group_restrictions( $group_id )
$query.= ' FROM '.PREFIX_TABLE.'group_access';
$query.= ' WHERE group_id = '.$group_id;
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
array_push( $authorized, $row['cat_id'] );
@@ -92,7 +92,7 @@ function is_group_allowed( $category_id, $restrictions )
$query.= ' FROM '.PREFIX_TABLE.'categories';
$query.= ' WHERE id = '.$category_id;
$query.= ';';
- $row = mysql_fetch_array( mysql_query( $query ) );
+ $row = mysql_fetch_array( pwg_query( $query ) );
if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = '';
if ( $row['id_uppercat'] == '' ) $is_root = true;
$category_id = $row['id_uppercat'];
diff --git a/include/functions_session.inc.php b/include/functions_session.inc.php
index bb0fca11c..f67c60116 100644
--- a/include/functions_session.inc.php
+++ b/include/functions_session.inc.php
@@ -79,7 +79,7 @@ SELECT id
FROM '.SESSIONS_TABLE.'
WHERE id = \''.$generated_id.'\'
;';
- $result = mysql_query($query);
+ $result = pwg_query($query);
if (mysql_num_rows($result) == 0)
{
$id_found = true;
@@ -94,7 +94,7 @@ INSERT INTO '.SESSIONS_TABLE.'
(\''.$generated_id.'\','.$userid.','.$expiration.',
\''.$_SERVER['REMOTE_ADDR'].'\')
;';
- mysql_query($query);
+ pwg_query($query);
setcookie('id', $generated_id, $expiration, cookie_path());
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index e14d0c627..0d4a5f1a6 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -69,7 +69,7 @@ function register_user( $login, $password, $password_conf,
$query.= ' FROM '.USERS_TABLE;
$query.= " WHERE username = '".$login."'";
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
if ( mysql_num_rows($result) > 0 ) $error[$i++] = $lang['reg_err_login5'];
}
// given password must be the same as the confirmation
@@ -94,7 +94,7 @@ function register_user( $login, $password, $password_conf,
$query.= ' FROM '.USERS_TABLE;
$query.= " WHERE username = 'guest'";
$query.= ';';
- $row = mysql_fetch_array( mysql_query( $query ) );
+ $row = mysql_fetch_array( pwg_query( $query ) );
// 2. adding new user
$query = 'INSERT INTO '.USERS_TABLE;
$query.= ' (';
@@ -115,12 +115,12 @@ function register_user( $login, $password, $password_conf,
else $query.= "'".$row[$info]."'";
}
$query.= ');';
- mysql_query( $query );
+ pwg_query( $query );
// 3. retrieving the id of the newly created user
$query = 'SELECT id';
$query.= ' FROM '.USERS_TABLE;
$query.= " WHERE username = '".$login."';";
- $row = mysql_fetch_array( mysql_query( $query ) );
+ $row = mysql_fetch_array( pwg_query( $query ) );
$user_id = $row['id'];
// 4. adding access to the new user, the same as the user "guest"
$query = 'SELECT cat_id';
@@ -128,13 +128,13 @@ function register_user( $login, $password, $password_conf,
$query.= ','.PREFIX_TABLE.'users as u ';
$query.= ' where u.id = ua.user_id';
$query.= " and u.username = 'guest';";
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while( $row = mysql_fetch_array( $result ) )
{
$query = 'INSERT INTO '.PREFIX_TABLE.'user_access';
$query.= ' (user_id,cat_id) VALUES';
$query.= ' ('.$user_id.','.$row['cat_id'].');';
- mysql_query ( $query );
+ pwg_query ( $query );
}
// 5. associate new user to the same groups that the guest
$query = 'SELECT group_id';
@@ -143,14 +143,14 @@ function register_user( $login, $password, $password_conf,
$query.= " WHERE u.username = 'guest'";
$query.= ' AND ug.user_id = u.id';
$query.= ';';
- $result = mysql_query( $query );
+ $result = pwg_query( $query );
while( $row = mysql_fetch_array( $result ) )
{
$query = 'INSERT INTO '.PREFIX_TABLE.'user_group';
$query.= ' (user_id,group_id) VALUES';
$query.= ' ('.$user_id.','.$row['group_id'].')';
$query.= ';';
- mysql_query ( $query );
+ pwg_query ( $query );
}
}
return $error;
@@ -187,7 +187,7 @@ function update_user( $user_id, $mail_address, $status,
}
$query.= ' WHERE id = '.$user_id;
$query.= ';';
- mysql_query( $query );
+ pwg_query( $query );
}
return $error;
}
@@ -270,7 +270,7 @@ function getuserdata($user)
$sql = "SELECT * FROM " . USERS_TABLE;
$sql.= " WHERE ";
$sql .= ( ( is_integer($user) ) ? "id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND id <> " . ANONYMOUS;
- $result = mysql_query($sql);
+ $result = pwg_query($sql);
return ( $row = mysql_fetch_array($result) ) ? $row : false;
}
?>
diff --git a/include/user.inc.php b/include/user.inc.php
index a39441bb2..039b7a448 100644
--- a/include/user.inc.php
+++ b/include/user.inc.php
@@ -63,7 +63,7 @@ SELECT user_id,expiration,ip
FROM '.SESSIONS_TABLE.'
WHERE id = \''.$page['session_id'].'\'
;';
- $result = mysql_query($query);
+ $result = pwg_query($query);
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array($result);
@@ -76,7 +76,7 @@ SELECT user_id,expiration,ip
$delete_query = 'DELETE FROM '.SESSIONS_TABLE;
$delete_query.= " WHERE id = '".$page['session_id']."'";
$delete_query.= ';';
- mysql_query($delete_query);
+ pwg_query($delete_query);
}
else if ($_SERVER['REMOTE_ADDR'] == $row['ip'])
{
@@ -97,7 +97,7 @@ if (!$query_done)
$user['is_the_guest'] = true;
}
$query_user .= ';';
-$row = mysql_fetch_array(mysql_query($query_user));
+$row = mysql_fetch_array(pwg_query($query_user));
// affectation of each value retrieved in the users table into a variable
// of the array $user.