aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/filter.inc.php3
-rw-r--r--include/functions_user.inc.php84
-rw-r--r--include/picture_comment.inc.php4
3 files changed, 38 insertions, 53 deletions
diff --git a/include/filter.inc.php b/include/filter.inc.php
index fb0474bbd..f373ca1cd 100644
--- a/include/filter.inc.php
+++ b/include/filter.inc.php
@@ -3,7 +3,6 @@
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
@@ -75,7 +74,7 @@ if ($filter['enabled'])
{
// Need to compute dats
$filter['check_key'] = get_filter_check_key();
- $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $filter['recent_period']);
+ $filter['categories'] = get_computed_categories($user, (int)$filter['recent_period']);
$filter['visible_categories'] = implode(',', array_keys($filter['categories']));
if (empty($filter['visible_categories']))
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 8be4f03cb..72754ca33 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -272,7 +272,7 @@ SELECT ui.*, uc.*
$userdata['forbidden_categories'] =
calculate_permissions($userdata['id'], $userdata['status']);
- update_user_cache_categories($userdata['id'], $userdata['forbidden_categories']);
+ update_user_cache_categories($userdata);
// Set need update are done
$userdata['need_update'] = false;
@@ -533,116 +533,104 @@ function compute_categories_data(&$cats)
/**
* get computed array of categories
*
- * @param int user_id
- * @param list user_forbidden_categories
- * @param bool filter_enabled
- * @param int recent_period
+ * @param array userdata
+ * @param int filter_days number of recent days to filter on or null
* @return array
*/
-function get_computed_categories($user_id, $user_forbidden_categories, $filter_enabled, $recent_period = 0)
+function get_computed_categories($userdata, $filter_days=null)
{
- $query = '
-SELECT
- c.id cat_id,
- date_last max_date_last,
- nb_images count_images,
- global_rank';
+ $group_by = '';
- if (!$filter_enabled)
+ $query = 'SELECT c.id cat_id, global_rank';
+ if ( !isset($filter_days) )
{
- $query.= '
-FROM '.CATEGORIES_TABLE.' as c';
+ $query .= ',
+ date_last cat_date_last,
+ nb_images cat_nb_images
+ FROM '.CATEGORIES_TABLE.' as c';
}
else
{
// Count by date_available to avoid count null
- $query.= ',
- count(date_available) filtered_count_images,
- max(date_available) max_date_available
-FROM '.CATEGORIES_TABLE.' as c
+ $query .= ',
+ MAX(date_available) cat_date_last,
+ COUNT(date_available) cat_nb_images
+ FROM '.CATEGORIES_TABLE.' as c
LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
LEFT JOIN '.IMAGES_TABLE.' AS i
- ON ic.image_id = i.id AND
- i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$recent_period.' DAY)';
+ ON ic.image_id = i.id AND
+ i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
+ $group_by = 'c.id';
}
- if ($user_forbidden_categories != '')
+ if ( !empty($userdata['forbidden_categories']) )
{
$query.= '
-WHERE
- c.id NOT IN ('.$user_forbidden_categories.')';
+ WHERE c.id NOT IN ('.$userdata['forbidden_categories'].')';
}
- if ($filter_enabled)
+ if ( !empty($group_by) )
{
$query.= '
-GROUP BY
- c.id';
+ GROUP BY '.$group_by;
}
- $query.= ';';
$result = pwg_query($query);
$cats = array();
while ($row = mysql_fetch_assoc($result))
{
- $row['user_id'] = $user_id;
+ $row['user_id'] = $userdata['id'];
$row['count_categories'] = 0;
- if ($filter_enabled)
- {
- $row['nb_images'] = $row['filtered_count_images'];
- $row['count_images'] = $row['filtered_count_images'];
- $row['max_date_last'] = $row['max_date_available'];
- }
+ $row['count_images'] = $row['cat_nb_images'];
+ $row['max_date_last'] = $row['cat_date_last'];
+
$cats += array($row['cat_id'] => $row);
}
usort($cats, 'global_rank_compare');
compute_categories_data($cats);
- if ($filter_enabled)
+ if ( isset($filter_days) )
{
$cat_tmp = $cats;
$cats = array();
-
+
foreach ($cat_tmp as $category)
{
if (!empty($category['max_date_last']))
{
// Re-init counters
$category['count_categories'] = 0;
- $category['nb_images'] = $category['filtered_count_images'];
- $category['count_images'] = $category['filtered_count_images'];
+ $category['count_images'] = $category['cat_nb_images'];
+ // next line for update_cats_with_filtered_data
+ $category['nb_images'] = $category['cat_nb_images'];
// Keep category
$cats[$category['cat_id']] = $category;
-
}
}
// Compute a second time
compute_categories_data($cats);
}
-
return $cats;
}
/**
* update data of user_cache_categories
*
- * @param int user_id
- * @param list user_forbidden_categories
- * @param bool filter_enabled
+ * @param array userdata
* @return null
*/
-function update_user_cache_categories($user_id, $user_forbidden_categories)
+function update_user_cache_categories($userdata)
{
// delete user cache
$query = '
DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
- WHERE user_id = '.$user_id.'
+ WHERE user_id = '.$userdata['id'].'
;';
pwg_query($query);
- $cats = get_computed_categories($user_id, $user_forbidden_categories, false);
+ $cats = get_computed_categories($userdata, null);
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
mass_inserts
@@ -1184,4 +1172,4 @@ function get_sql_condition_FandF(
return $sql;
}
-?>
+?> \ No newline at end of file
diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php
index 424fd3fd3..c84f2a629 100644
--- a/include/picture_comment.inc.php
+++ b/include/picture_comment.inc.php
@@ -56,9 +56,7 @@ if ( $page['show_comments'] and isset( $_POST['content'] ) )
include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
- $comment_action = insert_user_comment(
- $comm, @$_POST['key'], $page['image_id'], $infos
- );
+ $comment_action = insert_user_comment($comm, @$_POST['key'], $infos );
switch ($comment_action)
{