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

Last change on this file since 16625 was 16625, checked in by mistic100, 12 years ago

-add download link if BatchDownloader is installed
-merge two prefilters
-better support of Stripped

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