aboutsummaryrefslogtreecommitdiffstats
path: root/include/section_init.inc.php
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2006-12-21 21:38:20 +0000
committerrub <rub@piwigo.org>2006-12-21 21:38:20 +0000
commitcab8f98c4ab88a0ad05f2359099c883675319084 (patch)
treea8224615d63c1330fd8744e3abd5195eb5763476 /include/section_init.inc.php
parenta7ce26153185c274a08fb52b07402c8afba6f128 (diff)
Feature Issue ID 0000601: Filter all public pages with only recent elements
It's a finalized version. Obsolete code of draft are removed. You can filter categories and images with recent date period on your screen selection. In the future, filter could be easy done on other type data (plugin?) You can flat categories and sub-categories with a recent date period of your choice. Next, perhaps, a panel to choice recent date for the 2 features. On draft, there have problem with MySql 5, be careful! Css problem not resolved: - Menu "Categories" is bad centered - Icon on dark too on the top git-svn-id: http://piwigo.org/svn/trunk@1677 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/section_init.inc.php')
-rw-r--r--include/section_init.inc.php171
1 files changed, 130 insertions, 41 deletions
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index 416d98849..d5bbce645 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -267,6 +267,12 @@ while (isset($tokens[$i]))
$page['start'] = $matches[1];
}
+ if (preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches))
+ {
+ // indicate a special list of images
+ $page['flat_recent_cat'] = $matches[1];
+ }
+
if (preg_match('/^(posted|created)/', $tokens[$i] ))
{
$chronology_tokens = explode('-', $tokens[$i] );
@@ -325,59 +331,134 @@ if ('categories' == $page['section'])
$page = array_merge(
$page,
array(
- 'comment' => $result['comment'],
- 'cat_dir' => $result['dir'],
- 'cat_name' => $result['name'],
- 'cat_site_id' => $result['site_id'],
- 'cat_uploadable' => $result['uploadable'],
- 'cat_commentable' => $result['commentable'],
- 'cat_id_uppercat' => $result['id_uppercat'],
- 'uppercats' => $result['uppercats'],
-
- 'title' => get_cat_display_name($result['name'], '', false),
+ 'comment' => $result['comment'],
+ 'cat_dir' => $result['dir'],
+ 'cat_name' => $result['name'],
+ 'cat_site_id' => $result['site_id'],
+ 'cat_uploadable' => $result['uploadable'],
+ 'cat_commentable' => $result['commentable'],
+ 'cat_id_uppercat' => $result['id_uppercat'],
+ 'uppercats' => $result['uppercats'],
+ 'title' =>
+ get_cat_display_name($result['name'], '', false),
+ 'thumbnails_include' =>
+ (($result['nb_images'] > 0) or (isset($page['flat_recent_cat'])))
+ ? 'include/category_default.inc.php'
+ : 'include/category_cats.inc.php'
)
);
+ }
+ else
+ {
+ $page['title'] = $lang['no_category'];
+ $page['thumbnails_include'] =
+ (isset($page['flat_recent_cat']))
+ ? 'include/category_default.inc.php'
+ : 'include/category_cats.inc.php';
+ }
+
+ if (isset($page['flat_recent_cat']))
+ {
+ $page['title'] = $lang['recent_pics_cat'].' : '.$page['title'] ;
+ }
+
+ if
+ (
+ (!isset($page['chronology_field'])) and
+ (
+ (isset($page['category'])) or
+ (isset($page['flat_recent_cat']))
+ )
+ )
+ {
+ if ( !empty($result['image_order']) and !isset($page['super_order_by']) )
+ {
+ $conf[ 'order_by' ] = ' ORDER BY '.$result['image_order'];
+ }
- if (!isset($page['chronology_field']))
+ if (isset($page['flat_recent_cat']))
{
- if ( !empty($result['image_order']) and !isset($page['super_order_by']) )
+ // flat recent categories mode
+ $query = '
+SELECT
+ DISTINCT(ic.image_id)
+FROM '.IMAGES_TABLE.' AS i
+ INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id
+ INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id
+WHERE
+ date_available > SUBDATE(
+ CURRENT_DATE,INTERVAL '.$page['flat_recent_cat'].' DAY)'.
+ (isset($page['category']) ? '
+ AND uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '' ).'
+'.get_sql_condition_FandF
+ (
+ array
+ (
+ 'forbidden_categories' => 'category_id',
+ 'visible_categories' => 'category_id',
+ 'visible_images' => 'image_id'
+ ),
+ 'AND'
+ ).'
+;';
+
+ $where_sql = array_from_query($query, 'image_id');
+ if (!empty($where_sql))
{
- $conf[ 'order_by' ] = ' ORDER BY '.$result['image_order'];
+ $where_sql = 'image_id in ('.implode(',', $where_sql).')';
}
+ }
+ else
+ {
+ // Normal mode
+ $where_sql = 'category_id = '.$page['category'];
+ }
+ if (!empty($where_sql))
+ {
+ // Main query
$query = '
SELECT image_id
FROM '.IMAGE_CATEGORY_TABLE.'
INNER JOIN '.IMAGES_TABLE.' ON id = image_id
- WHERE category_id = '.$page['category'].'
+ WHERE
+ '.$where_sql.'
+'.get_sql_condition_FandF
+ (
+ array
+ (
+ 'forbidden_categories' => 'category_id',
+ 'visible_categories' => 'category_id',
+ 'visible_images' => 'image_id'
+ ),
+ 'AND'
+ ).'
'.$conf['order_by'].'
;';
- $page['items'] = array_from_query($query, 'image_id');
- $page['thumbnails_include'] =
- $result['nb_images'] > 0
- ? 'include/category_default.inc.php'
- : 'include/category_cats.inc.php';
- } //otherwise the calendar will requery all subitems
- }
- else
- {
- $page['title'] = $lang['no_category'];
- $page['thumbnails_include'] = 'include/category_cats.inc.php';
- }
+ $page['items'] = array_from_query($query, 'image_id');
+ }
+ else
+ {
+ $page['items'] = array();
+ }
+ } //otherwise the calendar will requery all subitems
}
// special sections
else
{
- if (!empty($user['forbidden_categories']))
- {
- $forbidden =
- ' category_id NOT IN ('.$user['forbidden_categories'].')';
- }
- else
- {
- $forbidden = ' 1 = 1';
- }
+ $forbidden =
+ get_sql_condition_FandF
+ (
+ array
+ (
+ 'forbidden_categories' => 'category_id',
+ 'visible_categories' => 'category_id',
+ 'visible_images' => 'image_id'
+ ),
+ 'AND'
+ );
+
// +-----------------------------------------------------------------------+
// | tags section |
// +-----------------------------------------------------------------------+
@@ -400,7 +481,7 @@ else
SELECT image_id
FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id
WHERE image_id IN ('.implode(',', $items).')
- AND '.$forbidden.
+ '.$forbidden.
$conf['order_by'].'
;';
$items = array_unique(
@@ -434,7 +515,7 @@ SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE id IN ('.implode(',', $search_result['items']).')
- AND '.$forbidden.'
+ '.$forbidden.'
'.$conf['order_by'].'
;';
$page['items'] = array_from_query($query, 'id');
@@ -464,6 +545,14 @@ SELECT image_id
FROM '.FAVORITES_TABLE.'
INNER JOIN '.IMAGES_TABLE.' ON image_id = id
WHERE user_id = '.$user['id'].'
+'.get_sql_condition_FandF
+ (
+ array
+ (
+ 'visible_images' => 'image_id'
+ ),
+ 'AND'
+ ).'
'.$conf['order_by'].'
;';
@@ -487,7 +576,7 @@ SELECT DISTINCT(id)
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE date_available > \''.
date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\'
- AND '.$forbidden.'
+ '.$forbidden.'
'.$conf['order_by'].'
;';
@@ -526,7 +615,7 @@ SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE hit > 0
- AND '.$forbidden.'
+ '.$forbidden.'
'.$conf['order_by'].'
LIMIT 0, '.$conf['top_number'].'
;';
@@ -554,7 +643,7 @@ SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE average_rate IS NOT NULL
- AND '.$forbidden.'
+ '.$forbidden.'
'.$conf['order_by'].'
LIMIT 0, '.$conf['top_number'].'
;';
@@ -578,7 +667,7 @@ SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE image_id IN ('.implode(',', $page['list']).')
- AND '.$forbidden.'
+ '.$forbidden.'
'.$conf['order_by'].'
;';