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

Last change on this file since 20090 was 20090, checked in by mistic100, 11 years ago
  • add webservices
  • add mail function
  • add admin list
  • add admin export function
  • try to deal with Gthumb+
  • activate multisize dropdown menu of collection page

TODO : use webservices instead of toggle_image.php

File size: 7.3 KB
Line 
1<?php
2defined('USER_COLLEC_PATH') or die('Hacking attempt!');
3
4# this file contains all functions directly called by the triggers #
5
6/* compatibility fix with Gthumb+ */
7function user_collections_save_pagination()
8{
9  global $user, $page, $uc_nb_image_page_save;
10   
11  $uc_nb_image_page_save['user'] = $user['nb_image_page'];
12  $uc_nb_image_page_save['page'] = $page['nb_image_page'];
13}
14
15
16/* define page section from url */
17function user_collections_section_init()
18{
19  global $tokens, $page, $conf;
20
21  if ($tokens[0] == 'collections')
22  {
23    $page['section'] = 'collections';
24    $page['title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>';
25   
26    if (in_array(@$tokens[1], array('edit','view','list')))
27    {
28       $page['sub_section'] = $tokens[1];
29    }
30    else
31    {
32      $page['sub_section'] = 'list';
33    }
34   
35    if (!empty($tokens[2]))
36    {
37      $page['col_id'] = $tokens[2];
38    }
39  }
40}
41
42/* collections section */
43function user_collections_page()
44{
45  global $page;
46
47  if (isset($page['section']) and $page['section'] == 'collections')
48  {
49    include(USER_COLLEC_PATH . '/include/collections.inc.php');
50  }
51}
52
53
54/* add buttons on thumbnails list */
55function user_collections_index_actions()
56{
57  if (is_a_guest()) return;
58 
59  global $page, $UserCollection;
60     
61  // add image to collection list
62  if ( isset($_GET['collection_toggle']) and  preg_match('#^[0-9]+$#', $_GET['collection_toggle']) )
63  {
64    if (empty($UserCollection))
65    {
66      $UserCollection = new UserCollection(get_current_collection_id(true));
67    }
68    $UserCollection->toggleImage($_GET['collection_toggle']);
69    redirect(duplicate_index_url(array(), array('collection_toggle')));
70  }
71}
72
73function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures)
74{
75  if (is_a_guest()) return $tpl_thumbnails_var;
76 
77  global $page, $template, $UserCollection;
78 
79  // the prefilter is different on collection page
80  if (isset($page['section']) and ($page['section'] == 'collections' or $page['section'] == 'download')) return $tpl_thumbnails_var;
81 
82  // get existing collections
83  $col_id = get_current_collection_id(false);
84  if (empty($UserCollection) and $col_id !== false)
85  {
86    $UserCollection = new UserCollection($col_id);
87    $collection = $UserCollection->getImages();
88  }
89  else if (!empty($UserCollection))
90  {
91    $collection = $UserCollection->getImages();
92  }
93  else
94  {
95    $collection = array();
96  }
97 
98  // if the collection is created we don't use AJAX to force menu refresh
99  if ($col_id === false)
100  {
101    $template->assign('NO_AJAX', true);
102  }
103 
104 
105  $self_url = duplicate_index_url(array(), array('collection_toggle')); 
106 
107  foreach ($tpl_thumbnails_var as &$thumbnail)
108  {
109    if (in_array($thumbnail['id'], $collection))
110    {
111      $thumbnail['COLLECTION_SELECTED'] = true;
112    }
113  }
114  unset($thumbnail);
115 
116  // thumbnails buttons
117  $template->assign(array(
118    'USER_COLLEC_PATH' => USER_COLLEC_PATH,
119    'collection_toggle_url' =>  add_url_params($self_url, array('collection_toggle'=>'')),
120    ));
121  $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
122 
123  return $tpl_thumbnails_var;
124}
125
126function user_collections_thumbnails_list_prefilter($content, &$smarty)
127{
128  // add links
129  $search = '<span class="wrap1">';
130  $replace = $search.'
131{strip}<a class="addCollection" href="{$collection_toggle_url}{$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow">
132{if $COL_ID or $thumbnail.COLLECTION_SELECTED}
133{\'Remove from collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_delete.png" title="{\'Remove from collection\'|@translate}">
134{else}
135{\'Add to collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_add.png" title="{\'Add to collection\'|@translate}">
136{/if}
137</a>{/strip}';
138
139  // custom CSS and AJAX request
140  $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl');
141
142  return str_replace($search, $replace, $content);
143}
144
145
146/* add button on picture page */
147function user_collections_picture_page()
148{
149  if (is_a_guest()) return;
150 
151  global $template, $picture, $UserCollection;
152 
153  // add image to collection list
154  if ( isset($_GET['action']) and $_GET['action'] == 'collection_toggle' )
155  {
156    if (empty($UserCollection))
157    {
158      $UserCollection = new UserCollection(get_current_collection_id(true));
159    }
160   
161    $UserCollection->toggleImage($picture['current']['id']);
162    redirect(duplicate_picture_url());
163  }
164 
165  // get existing collection
166  if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false)
167  {
168    $UserCollection = new UserCollection($col_id);
169    $collection = $UserCollection->isInSet($picture['current']['id']);
170  }
171  else if (!empty($UserCollection))
172  {
173    $collection = $UserCollection->isInSet($picture['current']['id']);
174  }
175  else
176  {
177    $collection = false;
178  } 
179 
180  $url = add_url_params(duplicate_picture_url(), array('action'=>'collection_toggle'));   
181 
182  $button = '
183<a href="'.$url.'" title="'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'" class="pwg-state-default pwg-button" rel="nofollow">
184  <span class="pwg-icon" style="background:url(\''.get_root_url().USER_COLLEC_PATH.'template/image_'.($collection?'delete':'add').'.png\') center center no-repeat;"> </span>
185  <span class="pwg-button-text">'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'</span>
186</a>';
187  // $template->add_picture_button($button, 50);
188  $template->concat('PLUGIN_PICTURE_ACTIONS', $button);
189}
190
191
192/* menu block */
193function user_collections_add_menublock($menu_ref_arr)
194{
195  if (is_a_guest()) return;
196 
197  $menu = &$menu_ref_arr[0];
198  if ($menu->get_id() != 'menubar') return;
199   
200  $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection'));
201}
202
203function user_collections_applymenu($menu_ref_arr)
204{
205  $max = 6;
206 
207  global $template, $conf, $user, $UserCollection;
208  $menu = &$menu_ref_arr[0];
209 
210  if (($block = $menu->get_block('mbUserCollection')) != null)
211  {
212    $query = '
213SELECT *
214  FROM '.COLLECTIONS_TABLE.'
215  WHERE user_id = '.$user['id'].'
216  ORDER BY
217    active DESC,
218    date_creation DESC
219;';
220    $collections = array_values(hash_from_query($query, 'id'));
221   
222    $data['collections'] = array();
223    for ($i=0; $i<$max && $i<count($collections); $i++)
224    {
225      $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id'];
226      array_push($data['collections'], $collections[$i]);
227    }
228   
229    $data['NB_COL'] = count($collections);
230    if ($data['NB_COL'] > $max)
231    {
232      $data['MORE'] = count($collections)-$max;
233    }
234   
235    $data['U_LIST'] = USER_COLLEC_PUBLIC;
236    $data['U_CREATE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0','redirect'=>'true'));
237   
238    $template->set_template_dir(USER_COLLEC_PATH . 'template/');
239    $block->set_title('<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>');
240    $block->template = 'menublock_user_collec.tpl';
241    $block->data = $data;
242  }
243}
244
245?>
Note: See TracBrowser for help on using the repository browser.