source: extensions/SmartAlbums/include/init_page_items.php @ 12523

Last change on this file since 12523 was 11334, checked in by mistic100, 13 years ago

private items are not displayed in SmartAlbums (according to user permissions)

File size: 2.6 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4/**
5 * Remove form $page['items'] picture that musn't be displayed
6 *
7 * here we get all pictures that current user could see
8 * if SmartAlbums doesn't exist, and make intersect with pictures
9 * actually displayed
10 */
11function smart_init_page_items()
12{
13  global $user, $page, $conf;
14
15  if (
16    ('categories' == $page['section']) and
17    (!isset($page['chronology_field'])) and
18    (
19      (isset($page['category'])) or
20      (isset($page['flat']))
21    )
22  ) {
23 
24    $query = '
25SELECT DISTINCT(cat.id) AS id
26  FROM '.CATEGORIES_TABLE.' AS cat
27    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS img
28    ON img.category_id = cat.id
29  WHERE img.smart = "true"
30;';
31    $smart_albums = array_from_query($query, 'id');
32     
33    if (count($smart_albums) > 0 and !is_admin())
34    {
35      // add SmartAlbums to forbidden categories
36      $user['forbidden_categories_old'] = $user['forbidden_categories'];
37      $user['forbidden_categories'] = explode(',', $user['forbidden_categories']);
38      $user['forbidden_categories'] = array_unique(array_merge($user['forbidden_categories'], $smart_albums));
39      $user['forbidden_categories'] = implode(',', $user['forbidden_categories']);
40   
41      if ( isset($page['category']) )
42      {
43        $query = '
44SELECT id
45  FROM '.CATEGORIES_TABLE.'
46  WHERE
47    '.get_sql_condition_FandF(
48      array(
49        'forbidden_categories' => 'id',
50        'visible_categories' => 'id',
51        )
52      );
53        $subcat_ids = array_from_query($query, 'id');
54        $subcat_ids[] = 0;
55        $where_sql = 'category_id IN ('.implode(',',$subcat_ids).')';
56        // remove categories from forbidden because just checked above
57        $forbidden = get_sql_condition_FandF(
58          array( 
59            'visible_images' => 'id'
60            ),
61          'AND'
62          );
63      }
64      else
65      {
66        $where_sql = '1=1';
67        $forbidden = get_sql_condition_FandF(
68          array(
69            'forbidden_categories' => 'category_id',
70            'visible_categories' => 'category_id',
71            'visible_images' => 'id'
72            ),
73          'AND'
74          );
75      }
76
77      // Main query
78      $query = '
79SELECT DISTINCT(image_id)
80  FROM '.IMAGE_CATEGORY_TABLE.'
81    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
82  WHERE
83    '.$where_sql.'
84'.$forbidden.'
85  '.$conf['order_by'].'
86;';
87
88      $page['items_wo_sa'] = array_from_query($query, 'image_id');
89      $page['items'] = array_intersect($page['items'], $page['items_wo_sa']);
90     
91      // restore forbidden categories
92      $user['forbidden_categories'] = $user['forbidden_categories_old'];
93    }
94  }
95}
96
97?>
Note: See TracBrowser for help on using the repository browser.