source: extensions/UserCollections/include/events.inc.php @ 24421

Last change on this file since 24421 was 24421, checked in by mistic100, 11 years ago

new system for shares : password protection, link timeout, management popup + for mails
handle lightbox conflicts
menublock is visible by AMM

File size: 8.0 KB
Line 
1<?php
2defined('USER_COLLEC_PATH') or die('Hacking attempt!');
3
4// +-----------------------------------------------------------------------+
5// | SECTION INIT
6// +-----------------------------------------------------------------------+
7/* define page section from url */
8function user_collections_section_init()
9{
10  global $tokens, $page, $conf;
11
12  if ($tokens[0] == 'collections')
13  {
14    add_event_handler('loc_begin_page_header', 'user_collections_page_header');
15   
16    $page['section'] = 'collections';
17    $page['title'] = l10n('Collections');
18   
19    $page['section_title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'];
20    if (is_a_guest()) $page['section_title'].= l10n('Collections');
21    else $page['section_title'].= '<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>';
22   
23    if (in_array(@$tokens[1], array('edit','view','list')))
24    {
25      $page['sub_section'] = $tokens[1];
26      if ($tokens[1]=='edit' && isset($conf['GThumb']) && is_array($conf['GThumb']))
27      {
28        $conf['GThumb']['big_thumb'] = false; // big thumb is buggy with removes
29      }
30    }
31    else
32    {
33      $page['sub_section'] = 'list';
34    }
35   
36    if (!empty($tokens[2]))
37    {
38      $page['col_id'] = $tokens[2];
39    }
40  }
41}
42
43function user_collections_page_header()
44{
45  global $page;
46  $page['body_id'] = 'theCollectionPage';
47}
48
49function uc_anti_lightbox($tpl_thumbnails_var)
50{
51  global $template, $page;
52 
53  if ($page['section'] == 'collections' && !empty($template->css_by_priority[0]))
54  {
55    foreach ($template->css_by_priority[0] as $file)
56    {
57      if (strpos($file[0], 'colorbox.css') !== false)
58      {
59        $template->assign('UC_NO_LIGHTBOX', true);
60        break;
61      }
62    }
63  }
64 
65  return $tpl_thumbnails_var;
66}
67
68/* collections section */
69function user_collections_page()
70{
71  global $page, $template;
72
73  if (isset($page['section']) and $page['section'] == 'collections')
74  {
75    include(USER_COLLEC_PATH . '/include/collections.inc.php');
76  }
77 
78  if (!is_a_guest() && count($page['items']))
79  {
80    $template->set_filename('uc_tumbnails_cssjs', realpath(USER_COLLEC_PATH . 'template/thumbnails_css_js.tpl'));
81    $template->parse('uc_tumbnails_cssjs');
82  }
83}
84
85
86// +-----------------------------------------------------------------------+
87// | CATEGORY PAGE
88// +-----------------------------------------------------------------------+
89/* add buttons on thumbnails list */
90function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures)
91{
92  if (is_a_guest()) return $tpl_thumbnails_var;
93 
94  global $page, $template, $user;
95 
96  // the content is different on collection edition page and no button on batch downloader set edition page
97  if ( empty($pictures) or (@$page['section'] == 'collections' and @$page['sub_section']=='edit') or @$page['section'] == 'download')
98  {
99    return $tpl_thumbnails_var;
100  }
101 
102  $image_ids = array_map(create_function('$i', 'return $i["id"];'), $pictures);
103 
104  // get collections for each picture
105  $query = '
106SELECT
107    image_id,
108    GROUP_CONCAT(col_id) AS col_ids
109  FROM '.COLLECTION_IMAGES_TABLE.'
110  WHERE col_id IN (
111      SELECT id
112      FROM '.COLLECTIONS_TABLE.'
113      WHERE user_id = '.$user['id'].'
114    )
115    AND image_id IN('.implode(',', $image_ids).')
116  GROUP BY image_id
117;';
118  $image_collections = simple_hash_from_query($query, 'image_id', 'col_ids');
119 
120  foreach ($tpl_thumbnails_var as &$thumbnail)
121  {
122    $thumbnail['COLLECTIONS'] = @$image_collections[ $thumbnail['id'] ];
123  }
124  unset($thumbnail);
125 
126  // get all collections
127  $query = '
128SELECT id, name, nb_images
129  FROM '.COLLECTIONS_TABLE.'
130  WHERE user_id = '.$user['id'].'
131  ORDER BY name ASC
132;';
133  $collections = hash_from_query($query, 'id');
134 
135  foreach ($collections as &$col)
136  {
137    $col["name"] = trigger_event("render_category_name", $col["name"]);
138  }
139  unset($col);
140 
141  $template->assign(array(
142    'COLLECTIONS' => $collections,
143    'USER_COLLEC_PATH' => USER_COLLEC_PATH,
144    ));
145 
146  // thumbnails buttons
147  $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_button');
148 
149  return $tpl_thumbnails_var;
150}
151
152// add links
153function user_collections_thumbnails_list_button($content, &$smarty)
154{
155  $search = '#(<li>|<li class="gthumb">)#';
156  $replace = '$1
157{strip}<a class="addCollection" data-id="{$thumbnail.id}" data-cols="[{$thumbnail.COLLECTIONS}]" rel="nofollow">
158{if not $UC_IN_EDIT}
159{\'Add to collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_add.png" alt="[+]">
160{else}
161{\'Remove from collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_delete.png" alt="[+]">
162{/if}
163</a>{/strip}';
164 
165  return preg_replace($search, $replace, $content);
166}
167
168
169// +-----------------------------------------------------------------------+
170// | PICTURE PAGE
171// +-----------------------------------------------------------------------+
172/* add button on picture page */
173function user_collections_picture_page()
174{
175  if (is_a_guest()) return;
176 
177  global $template, $picture, $user;
178 
179  // get collections for this picture
180  $query = '
181SELECT GROUP_CONCAT(col_id)
182  FROM '.COLLECTION_IMAGES_TABLE.'
183  WHERE col_id IN (
184      SELECT id
185      FROM '.COLLECTIONS_TABLE.'
186      WHERE user_id = '.$user['id'].'
187    )
188    AND image_id = '.$picture['current']['id'].'
189  GROUP BY image_id
190;';
191  list($image_collections) = pwg_db_fetch_row(pwg_query($query));
192 
193  // get all collections
194  $query = '
195SELECT id, name, nb_images
196  FROM '.COLLECTIONS_TABLE.'
197  WHERE user_id = '.$user['id'].'
198  ORDER BY name ASC
199;';
200  $collections = hash_from_query($query, 'id');
201 
202  foreach ($collections as &$col)
203  {
204    $col["name"] = trigger_event("render_category_name", $col["name"]);
205  }
206  unset($col);
207 
208  $template->assign(array(
209    'CURRENT_COLLECTIONS' => $image_collections,
210    'COLLECTIONS' => $collections,
211    'USER_COLLEC_PATH' => USER_COLLEC_PATH,
212    'USER_COLLEC_ABS_PATH' => realpath(USER_COLLEC_PATH).'/',
213    'IN_PICTURE' => true,
214    ));
215 
216  // toolbar button
217  $template->set_filename('usercol_button', realpath(USER_COLLEC_PATH.'template/picture_button.tpl'));
218  $button = $template->parse('usercol_button', true);
219  $template->add_picture_button($button, 50);
220}
221
222
223// +-----------------------------------------------------------------------+
224// | MENU BLOCK
225// +-----------------------------------------------------------------------+
226/* register block */
227function user_collections_add_menublock($menu_ref_arr)
228{
229  if (is_a_guest()) return;
230 
231  $menu = &$menu_ref_arr[0];
232  if ($menu->get_id() != 'menubar') return;
233   
234  $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection'));
235}
236
237/* fill block */
238function user_collections_applymenu($menu_ref_arr)
239{
240  $max = 6;
241 
242  global $template, $page, $conf, $user;
243  $menu = &$menu_ref_arr[0];
244 
245  if (($block = $menu->get_block('mbUserCollection')) != null)
246  {
247    $query = '
248SELECT id, name, nb_images
249  FROM '.COLLECTIONS_TABLE.'
250  WHERE user_id = '.$user['id'].'
251  ORDER BY date_creation DESC
252;';
253    $collections = array_values(hash_from_query($query, 'id'));
254   
255    $data['collections'] = array();
256    for ($i=0; $i<$max && $i<count($collections); $i++)
257    {
258      $collections[$i]['name'] = trigger_event('render_category_name', $collections[$i]['name']);
259      $collections[$i]['u_edit'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id'];
260      $data['collections'][] = $collections[$i];
261    }
262   
263    $data['NB_COL'] = count($collections);
264    if ($data['NB_COL'] > $max)
265    {
266      $data['MORE'] = count($collections)-$max;
267    }
268   
269    $data['U_LIST'] = USER_COLLEC_PUBLIC;
270   
271    $block->set_title('<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>');
272    $block->template = realpath(USER_COLLEC_PATH . 'template/menublock.tpl');
273    $block->data = $data;
274  }
275}
276
277?>
Note: See TracBrowser for help on using the repository browser.