source: extensions/UserCollections/include/collections.inc.php @ 19843

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

text collection name, absolute path for zClip inclusion

File size: 9.0 KB
Line 
1<?php
2defined('USER_COLLEC_PATH') or die('Hacking attempt!');
3
4# this file is called on basket public page #
5
6global $page, $template, $conf, $user, $tokens, $pwg_loaded_plugins;
7
8switch ($page['sub_section'])
9{
10  /* list */
11  case 'list':
12  {
13    // security
14    if (is_a_guest()) access_denied();
15   
16    $template->set_filename('index', dirname(__FILE__) . '/../template/list.tpl');
17   
18    // actions
19    if ( isset($_GET['action']) and preg_match('#^([0-9]+)$#', $_GET['col_id']) )
20    {
21      switch ($_GET['action'])
22      {
23        // new
24        case 'new':
25        {
26          $UserCollection = new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1);
27         
28          if (isset($_GET['redirect']))
29          {
30            $redirect = USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('id');
31          }
32          else
33          {
34            $redirect = USER_COLLEC_PUBLIC;
35          }
36          redirect($redirect);
37          break;
38        }
39         
40        // delete
41        case 'delete':
42        {
43          $query = '
44DELETE ci, c
45  FROM '.COLLECTION_IMAGES_TABLE.' AS ci
46    RIGHT JOIN '.COLLECTIONS_TABLE.' AS c
47    ON ci.col_id = c.id
48  WHERE
49    c.user_id = '.$user['id'].'
50    AND c.id = '.$_GET['col_id'].'
51;';
52          pwg_query($query);
53     
54          redirect(USER_COLLEC_PUBLIC);
55          break;
56        }
57       
58        // save
59        case 'save':
60        {
61          if (empty($_GET['name']))
62          {
63            array_push($page['errors'], l10n('Please give a name'));
64          }
65          else
66          {
67            $query = '
68UPDATE '.COLLECTIONS_TABLE.'
69  SET
70    name = "'.pwg_db_real_escape_string($_GET['name']).'",
71    active = 0
72  WHERE
73    user_id = '.$user['id'].'
74    AND id = '.$_GET['col_id'].'
75;';
76            pwg_query($query);
77           
78            redirect(USER_COLLEC_PUBLIC);
79          }
80          break;
81        }
82       
83        // set active
84        case 'set_active':
85        {
86          $query = '
87UPDATE '.COLLECTIONS_TABLE.'
88  SET active = 0
89  WHERE user_id = '.$user['id'].'
90;';
91          pwg_query($query);
92         
93          $query = '
94UPDATE '.COLLECTIONS_TABLE.'
95  SET active = 1
96  WHERE
97    user_id = '.$user['id'].'
98    AND id = '.$_GET['col_id'].'
99;';
100          pwg_query($query);
101         
102          redirect(USER_COLLEC_PUBLIC);
103          break;
104        }
105      }
106    }
107   
108   
109    // get collections
110    $query = '
111SELECT *
112  FROM '.COLLECTIONS_TABLE.'
113  WHERE user_id = '.$user['id'].'
114  ORDER BY date_creation DESC
115';
116    $collections = hash_from_query($query, 'id');
117   
118    foreach ($collections as $col)
119    {
120      $col['date_creation'] = format_date($col['date_creation'], true);
121      $col['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$col['id'];
122      $col['U_ACTIVE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'set_active','col_id'=>$col['id']));
123      $col['U_DELETE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$col['id']));
124     
125      if (isset($pwg_loaded_plugins['BatchDownloader']))
126      {
127        $col['U_DOWNLOAD'] = add_url_params(USER_COLLEC_PUBLIC.'view/'.$col['public_id'], array('action'=>'advdown_set'));
128      }
129     
130      // temporary collections are above save collections
131      if ($col['name'] == 'temp')
132      {
133        $col['name'] = 'temp #'.$col['id'];
134        $col['U_SAVE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'save','col_id'=>$col['id']));
135        $template->append('temp_col', $col);
136      }
137      else
138      {
139        $template->append('collections', $col);
140      }
141    }
142   
143    $template->assign('U_CREATE', add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0')));
144    break;
145  }
146 
147  /* edit */
148  case 'edit':
149  {
150    // security
151    if (empty($page['col_id']))
152    {
153      $_SESSION['page_errors'][] = l10n('Invalid collection');
154      redirect(USER_COLLEC_PUBLIC);
155    }
156   
157    $template->set_filename('index', dirname(__FILE__).'/../template/edit.tpl');
158   
159    $self_url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id'];
160    $template->assign(array(
161      'USER_COLLEC_PATH' => USER_COLLEC_PATH,
162      'F_ACTION' => $self_url,
163      'collection_toggle_url' => $self_url,
164      'U_LIST' => USER_COLLEC_PUBLIC,
165      'COL_ID' => $page['col_id'],
166      ));
167   
168    try {
169      $UserCollection = new UserCollection($page['col_id']);
170     
171      // security
172      if ( !is_admin() and $UserCollection->getParam('user_id') != $user['id'] )
173      {
174        access_denied();
175      }
176     
177      // save properties
178      if (isset($_POST['save_col']))
179      {
180        if (empty($_POST['name']))
181        {
182          array_push($page['errors'], l10n('Please give a name'));
183        }
184        else
185        {
186          $UserCollection->updateParam('name', $_POST['name']);
187        }
188        $UserCollection->updateParam('public', $_POST['public']);
189      }
190     
191      // clear
192      if ( isset($_GET['action']) and $_GET['action'] == 'clear' )
193      {
194        $UserCollection->clearImages();
195      }
196     
197      // remove an element
198      if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) )
199      {
200        $UserCollection->removeImages(array($_GET['collection_toggle']));
201        unset($_GET['collection_toggle']);
202      }
203     
204      // special template
205      add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 2); // +10 to overload GThumb+
206      $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
207     
208      // collection content
209      $col = $UserCollection->getCollectionInfo();
210      $col['U_CLEAR'] = $self_url.'&amp;action=clear';
211      $col['U_DELETE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$page['col_id']));
212      $template->assign('collection', $col);
213     
214      $page['items'] = $UserCollection->getImages();
215     
216      // navigation bar
217      $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0;
218      if (count($page['items']) > $page['nb_image_page'])
219      {
220        $page['navigation_bar'] = create_navigation_bar(
221          $self_url,
222          count($page['items']),
223          $page['start'],
224          $page['nb_image_page'],
225          false
226          );
227        $template->assign('navbar', $page['navigation_bar']);
228      }
229     
230      // display
231      include(PHPWG_ROOT_PATH . 'include/category_default.inc.php');
232     
233      $template->concat('TITLE', $conf['level_separator'].$UserCollection->getParam('name'));
234    }
235    catch (Exception $e)
236    {
237      array_push($page['errors'], $e->getMessage());
238    }
239   
240    break;
241  }
242 
243  /* view */
244  case 'view':
245  {
246    // security
247    if ( empty($page['col_id']) or strlen($page['col_id']) != 10 or strpos($page['col_id'], 'uc') === false )
248    {
249      $_SESSION['page_errors'][] = l10n('Invalid collection');
250      redirect('index.php');
251    }
252   
253    $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl');
254   
255    $self_url = USER_COLLEC_PUBLIC . 'view/'.$page['col_id'];
256   
257    try {
258      $UserCollection = new UserCollection($page['col_id']);
259     
260      // special template
261      add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 2); // +10 to overload GThumb+
262     
263      // collection content
264      $page['items'] = $UserCollection->getImages();
265     
266      // navigation bar
267      $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0;
268      if (count($page['items']) > $page['nb_image_page'])
269      {
270        $page['navigation_bar'] = create_navigation_bar(
271          $self_url,
272          count($page['items']),
273          $page['start'],
274          $page['nb_image_page'],
275          false
276          );
277        $template->assign('navbar', $page['navigation_bar']);
278      }
279     
280      // display
281      include(PHPWG_ROOT_PATH . 'include/category_default.inc.php');
282     
283      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
284      $template->concat('TITLE', 
285        $conf['level_separator'].$UserCollection->getParam('name').
286        ' ('.sprintf(l10n('by %s'), get_username($UserCollection->getParam('user_id'))).')'
287        );
288    }
289    catch (Exception $e)
290    {
291      access_denied();
292    }
293   
294    break;
295  }
296}
297
298$template->assign(array(
299  'USER_COLLEC_PATH' => USER_COLLEC_PATH,
300  'USER_COLLEC_ABS_PATH' => realpath(USER_COLLEC_PATH).'/',
301  ));
302
303
304function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures)
305{
306  global $template, $page;
307 
308  $template->set_filename('index_thumbnails', dirname(__FILE__).'/../template/thumbnails.tpl');
309 
310  foreach ($tpl_thumbnails_var as &$thumbnail)
311  {
312    $src_image = new SrcImage($thumbnail);
313   
314    $thumbnail['FILE_SRC'] = DerivativeImage::url(IMG_LARGE, $src_image);
315    $thumbnail['URL'] = duplicate_picture_url(
316        array(
317          'image_id' => $thumbnail['id'],
318          'image_file' => $thumbnail['file'],
319          'section' => 'none',
320        ),
321        array('start')
322      );
323  }
324 
325  return $tpl_thumbnails_var;
326}
327
328?>
Note: See TracBrowser for help on using the repository browser.