aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2006-12-01 23:31:19 +0000
committerrub <rub@piwigo.org>2006-12-01 23:31:19 +0000
commit63638b9b6dcdcef8baf5363419f0f6c5130c62df (patch)
treecf53c156032a7565dc7db3842cbd10952a920812 /include
parentb2de3c32ee635788f2f34c98d529fdc167ca6a51 (diff)
Resolved Issue ID 0000299:
o Add (new) icon of parent category with children categories including new images o Improved display text for images count o Improved (a little) mass_* functions More explications on the forum. You must call directly upgrade_feep.php (http://127.0.0.1/BSF/upgrade_feed.php for example) git-svn-id: http://piwigo.org/svn/trunk@1624 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/category_cats.inc.php33
-rw-r--r--include/constants.php1
-rw-r--r--include/functions_category.inc.php63
-rw-r--r--include/functions_html.inc.php47
-rw-r--r--include/functions_user.inc.php138
5 files changed, 241 insertions, 41 deletions
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php
index 9a3cccceb..86e47cc09 100644
--- a/include/category_cats.inc.php
+++ b/include/category_cats.inc.php
@@ -33,22 +33,28 @@
if ($page['section']=='recent_cats')
{
+ // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
$query = '
-SELECT id,name,date_last,representative_picture_id,comment,nb_images,uppercats
- FROM '.CATEGORIES_TABLE.'
+SELECT
+ id,name, representative_picture_id, comment, nb_images, uppercats,
+ max_date_last, is_child_date_last, count_images, count_categories
+ FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
+ ON id = cat_id and user_id = '.$user['id'].'
WHERE date_last > SUBDATE(
CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
- )
- AND id NOT IN ('.$user['forbidden_categories'].')';
+ );';
}
else
{
+ // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
$query = '
-SELECT id,name,date_last,representative_picture_id,comment,nb_images
- FROM '.CATEGORIES_TABLE.'
+SELECT
+ id,name, representative_picture_id, comment, nb_images,
+ max_date_last, is_child_date_last, count_images, count_categories
+ FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
+ ON id = cat_id and user_id = '.$user['id'].'
WHERE id_uppercat '.
(!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
- AND id NOT IN ('.$user['forbidden_categories'].')
ORDER BY rank
;';
}
@@ -59,6 +65,8 @@ $image_ids = array();
while ($row = mysql_fetch_assoc($result))
{
+ $row['is_child_date_last'] = get_boolean($row['is_child_date_last']);
+
if (isset($row['representative_picture_id'])
and is_numeric($row['representative_picture_id']))
{ // if a representative picture is set, it has priority
@@ -145,7 +153,7 @@ if (count($categories) > 0)
else
{
$name = $category['name'];
- $icon_ts = get_icon(@$category['date_last']);
+ $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
}
$template->assign_block_vars(
@@ -162,7 +170,12 @@ if (count($categories) > 0)
'cat_name' => $category['name'],
)
),
- 'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
+ 'CAPTION_NB_IMAGES' => get_display_images_count
+ (
+ $category['nb_images'],
+ $category['count_images'],
+ $category['count_categories']
+ ),
'DESCRIPTION' => @$comment,
'NAME' => $name,
)
@@ -213,7 +226,7 @@ if (count($categories) > 0)
$template->merge_block_vars(
'thumbnails.line.thumbnail',
array(
- 'IMAGE_TS' => get_icon(@$category['date_last']),
+ 'IMAGE_TS' => get_icon($category['max_date_last'], $category['is_child_date_last']),
)
);
}
diff --git a/include/constants.php b/include/constants.php
index ab4afe630..c874205b7 100644
--- a/include/constants.php
+++ b/include/constants.php
@@ -65,6 +65,7 @@ define('WAITING_TABLE', $prefixeTable.'waiting');
define('IMAGE_METADATA_TABLE', $prefixeTable.'image_metadata');
define('RATE_TABLE', $prefixeTable.'rate');
define('USER_CACHE_TABLE', $prefixeTable.'user_cache');
+define('USER_CACHE_CATEGORIES_TABLE', $prefixeTable.'user_cache_categories');
define('CADDIE_TABLE', $prefixeTable.'caddie');
define('UPGRADE_TABLE', $prefixeTable.'upgrade');
define('SEARCH_TABLE', $prefixeTable.'search');
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index ceef3025d..ae8b617f7 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -52,29 +52,31 @@ function check_restrictions($category_id)
function get_categories_menu()
{
- global $page,$user;
-
- $infos = array('');
+ global $page, $user;
$query = '
-SELECT name,id,date_last,nb_images,global_rank
- FROM '.CATEGORIES_TABLE.'
- WHERE 1 = 1'; // stupid but permit using AND after it !
+SELECT ';
+ // From CATEGORIES_TABLE
+ $query.= '
+ name, id, nb_images, global_rank,';
+ // From USER_CACHE_CATEGORIES_TABLE
+ $query.= '
+ max_date_last, is_child_date_last, count_images, count_categories';
+
+ // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
+ $query.= '
+ FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
+ ON id = cat_id and user_id = '.$user['id'];
if (!$user['expand'])
{
$query.= '
- AND (id_uppercat is NULL';
+ WHERE (id_uppercat is NULL';
if (isset($page['category']))
{
$query.= ' OR id_uppercat IN ('.$page['uppercats'].')';
}
$query.= ')';
}
- if ($user['forbidden_categories'] != '')
- {
- $query.= '
- AND id NOT IN ('.$user['forbidden_categories'].')';
- }
$query.= '
;';
@@ -82,6 +84,7 @@ SELECT name,id,date_last,nb_images,global_rank
$cats = array();
while ($row = mysql_fetch_array($result))
{
+ $row['is_child_date_last'] = get_boolean($row['is_child_date_last']);
array_push($cats, $row);
}
usort($cats, 'global_rank_compare');
@@ -89,6 +92,7 @@ SELECT name,id,date_last,nb_images,global_rank
return get_html_menu_category($cats);
}
+
/**
* Retrieve informations about a category in the database
*
@@ -352,4 +356,39 @@ function rank_compare($a, $b)
return ($a['rank'] < $b['rank']) ? -1 : 1;
}
+
+/**
+ * returns display text for information images of category
+ *
+ * @param array categories
+ * @return string
+ */
+function get_display_images_count($cat_nb_images, $cat_count_images, $cat_count_categories, $short_message = true)
+{
+ $display_text = '';
+
+ // Count of category is main
+ // if not picture on categorie, test on sub-categories
+ $count = ($cat_nb_images > 0 ? $cat_nb_images : $cat_count_images);
+
+ if ($count > 0)
+ {
+ $display_text.= sprintf(l10n(($count > 1 ? 'images_available' : 'image_available')), $count);
+
+ if ($cat_nb_images > 0)
+ {
+ if (! $short_message)
+ {
+ $display_text.= ' '.l10n('images_available_cpl');
+ }
+ }
+ else
+ {
+ $display_text.= ' '.sprintf(l10n(($cat_count_categories > 1 ? 'images_available_cats' : 'images_available_cat')), $cat_count_categories);
+ }
+ }
+
+ return $display_text;
+}
+
?> \ No newline at end of file
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index 3bc9a4706..6c69b0fb0 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -24,7 +24,7 @@
// | USA. |
// +-----------------------------------------------------------------------+
-function get_icon($date)
+function get_icon($date, $is_child_date = false)
{
global $page, $user, $conf, $lang;
@@ -33,16 +33,16 @@ function get_icon($date)
$date = 'NULL';
}
- if (isset($page['get_icon_cache'][$date]))
+ if (isset($page['get_icon_cache'][$is_child_date][$date]))
{
- return $page['get_icon_cache'][$date];
+ return $page['get_icon_cache'][$is_child_date][$date];
}
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})/', $date, $matches))
{
// date can be empty, no icon to display
- $page['get_icon_cache'][$date] = '';
- return $page['get_icon_cache'][$date];
+ $page['get_icon_cache'][$is_child_date][$date] = '';
+ return $page['get_icon_cache'][$is_child_date][$date];
}
list($devnull, $year, $month, $day) = $matches;
@@ -51,8 +51,8 @@ function get_icon($date)
if ($unixtime === false // PHP 5.1.0 and above
or $unixtime === -1) // PHP prior to 5.1.0
{
- $page['get_icon_cache'][$date] = '';
- return $page['get_icon_cache'][$date];
+ $page['get_icon_cache'][$is_child_date][$date] = '';
+ return $page['get_icon_cache'][$is_child_date][$date];
}
$diff = time() - $unixtime;
@@ -61,7 +61,7 @@ function get_icon($date)
$title = $lang['recent_image'].'&nbsp;';
if ( $diff < $user['recent_period'] * $day_in_seconds )
{
- $icon_url = get_themeconf('icon_dir').'/recent.png';
+ $icon_url = get_themeconf('icon_dir').'/'.($is_child_date ? 'recent_by_child.png' : 'recent.png');
$title .= $user['recent_period'];
$title .= '&nbsp;'.$lang['days'];
$size = getimagesize( PHPWG_ROOT_PATH.$icon_url );
@@ -70,9 +70,9 @@ function get_icon($date)
$output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />';
}
- $page['get_icon_cache'][$date] = $output;
+ $page['get_icon_cache'][$is_child_date][$date] = $output;
- return $page['get_icon_cache'][$date];
+ return $page['get_icon_cache'][$is_child_date][$date];
}
function create_navigation_bar(
@@ -392,7 +392,8 @@ SELECT id,name
*
* HTML code generated uses logical list tags ul and each category is an
* item li. The paramter given is the category informations as an array,
- * used keys are : id, name, nb_images, date_last
+ * used keys are : id, name, nb_images, max_date_last, is_child_date_last,
+ * count_images, count_categories
*
* @param array categories
* @return string
@@ -453,15 +454,27 @@ function get_html_menu_category($categories)
}
$menu.= '>'.$category['name'].'</a>';
- if ($category['nb_images'] > 0)
+ // Count of category is main
+ // if not picture on categorie, test on sub-categories
+ if (($category['nb_images'] > 0) or ($category['count_images'] > 0))
{
- $menu.= "\n".'<span class="menuInfoCat"';
- $menu.= ' title="'.$category['nb_images'];
- $menu.= ' '.$lang['images_available'].'">';
- $menu.= '['.$category['nb_images'].']';
+ $menu.= "\n".'<span class="';
+ $menu.= ($category['nb_images'] > 0 ? "menuInfoCat"
+ : "menuInfoCatByChild").'"';
+ $menu.= ' title="';
+ $menu.= ' '.get_display_images_count
+ (
+ $category['nb_images'],
+ $category['count_images'],
+ $category['count_categories'],
+ false
+ ).'">';
+ $menu.= '['.($category['nb_images'] > 0 ? $category['nb_images']
+ : $category['count_images']).']';
$menu.= '</span>';
- $menu.= get_icon($category['date_last']);
}
+
+ $menu.= get_icon($category['max_date_last'], $category['is_child_date_last']);
}
$menu.= str_repeat("\n</li></ul>",($level));
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 595215266..e1a84e1b6 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -272,6 +272,11 @@ SELECT ui.*, uc.*
$userdata['forbidden_categories'] =
calculate_permissions($userdata['id'], $userdata['status']);
+ update_user_cache_categorie($userdata['id'], $userdata['forbidden_categories']);
+
+ // Set need update are done
+ $userdata['need_update'] = false;
+
$query = '
SELECT COUNT(DISTINCT(image_id)) as total
FROM '.IMAGE_CATEGORY_TABLE.'
@@ -288,13 +293,16 @@ DELETE FROM '.USER_CACHE_TABLE.'
$query = '
INSERT INTO '.USER_CACHE_TABLE.'
- (user_id,need_update,forbidden_categories,nb_total_images)
+ (user_id, need_update, forbidden_categories, nb_total_images)
VALUES
- ('.$userdata['id'].',\'false\',\''
+ ('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\''
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].')
;';
pwg_query($query);
}
+
+ {
+ }
}
return $userdata;
@@ -440,6 +448,132 @@ SELECT id
}
/**
+ * update data of user_cache_categorie
+ *
+ * @param int user_id
+ * @return null
+ */
+function update_user_cache_categorie($user_id, $user_forbidden_categories)
+{
+ function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level)
+ {
+ $date = '';
+ $count_images = 0;
+ $count_categories = 0;
+ do
+ {
+ $cat_id = array_pop($list_cat_id);
+ if (!is_null($cat_id))
+ {
+ // Count images and categories
+ $cats[$cat_id]['count_images'] += $count_images;
+ $cats[$cat_id]['count_categories'] += $count_categories;
+ $count_images = $cats[$cat_id]['count_images'];
+ $count_categories = $cats[$cat_id]['count_categories'] + 1;
+
+ if ((empty($cats[$cat_id]['max_date_last'])) or ($cats[$cat_id]['max_date_last'] < $date))
+ {
+ $cats[$cat_id]['max_date_last'] = $date;
+ $cats[$cat_id]['is_child_date_last'] = true;
+ }
+ else
+ {
+ $date = $cats[$cat_id]['max_date_last'];
+ }
+ $ref_level = substr_count($cats[$cat_id]['global_rank'], '.') + 1;
+ }
+ else
+ {
+ $ref_level = 0;
+ }
+ } while ($level <= $ref_level);
+
+ // Last cat updating must be added to list for next branch
+ if ($ref_level <> 0)
+ {
+ array_push($list_cat_id, $cat_id);
+ }
+ }
+
+ // delete user cache
+ $query = '
+ delete from '.USER_CACHE_CATEGORIES_TABLE.'
+ where user_id = '.$user_id.'
+;';
+ pwg_query($query);
+
+ $query = '
+ select
+ id cat_id, date_last,
+ nb_images, global_rank
+ from '.CATEGORIES_TABLE;
+ if ($user_forbidden_categories != '')
+ {
+ $query.= '
+ where id not in ('.$user_forbidden_categories.')';
+ }
+ $query.= ';';
+
+ $result = pwg_query($query);
+
+ $cats = array();
+ while ($row = mysql_fetch_array($result))
+ {
+ $cats += array($row['cat_id'] => $row);
+ }
+ usort($cats, 'global_rank_compare');
+
+ $ref_level = 0;
+ $level = 0;
+ $list_cat_id = array();
+
+ foreach ($cats as $id => $category)
+ {
+ // Update field
+ $cats[$id]['user_id'] = $user_id;
+ $cats[$id]['is_child_date_last'] = false;
+ $cats[$id]['max_date_last'] = $cats[$id]['date_last'];
+ $cats[$id]['count_images'] = $cats[$id]['nb_images'];
+ $cats[$id]['count_categories'] = 0;
+
+ // Compute
+ $level = substr_count($category['global_rank'], '.') + 1;
+ if ($level > $ref_level)
+ {
+ array_push($list_cat_id, $id);
+ }
+ else
+ {
+ compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
+ array_push($list_cat_id, $id);
+ }
+ $ref_level = $level;
+ }
+
+ $level = 1;
+ compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
+
+ foreach ($cats as $id => $category)
+ {
+ // Convert field
+ $cats[$id]['is_child_date_last'] = boolean_to_string($cats[$id]['is_child_date_last']);
+ }
+
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+ mass_inserts
+ (
+ USER_CACHE_CATEGORIES_TABLE,
+ array
+ (
+ 'user_id', 'cat_id',
+ 'is_child_date_last', 'max_date_last',
+ 'count_images', 'count_categories'
+ ),
+ $cats
+ );
+}
+
+/**
* returns the username corresponding to the given user identifier if exists
*
* @param int user_id