source: extensions/UserCollections/include/collections.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: 11.2 KB
RevLine 
[16591]1<?php
2defined('USER_COLLEC_PATH') or die('Hacking attempt!');
3
4# this file is called on basket public page #
5
[16625]6global $page, $template, $conf, $user, $tokens, $pwg_loaded_plugins;
[16591]7
8switch ($page['sub_section'])
9{
[16597]10  /* list */
[16591]11  case 'list':
12  {
[16658]13    // security
[16597]14    if (is_a_guest()) access_denied();
15   
[16591]16    $template->set_filename('index', dirname(__FILE__) . '/../template/list.tpl');
17   
[16658]18    // actions
[17657]19    if ( isset($_GET['action']) and preg_match('#^([0-9]+)$#', $_GET['col_id']) )
[16591]20    {
21      switch ($_GET['action'])
22      {
23        // new
24        case 'new':
25        {
[16688]26          $UserCollection = new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1);
[16591]27         
[16688]28          if (isset($_GET['redirect']))
[16591]29          {
[16688]30            $redirect = USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('id');
[16591]31          }
[16688]32          else
33          {
34            $redirect = USER_COLLEC_PUBLIC;
35          }
36          redirect($redirect);
[16591]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    }
[16658]107   
108   
[16591]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'];
[17178]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']));
[16591]124     
[16625]125      if (isset($pwg_loaded_plugins['BatchDownloader']))
126      {
[17178]127        $col['U_DOWNLOAD'] = add_url_params(USER_COLLEC_PUBLIC.'view/'.$col['public_id'], array('action'=>'advdown_set'));
[16625]128      }
129     
[16658]130      // temporary collections are above save collections
[16591]131      if ($col['name'] == 'temp')
132      {
133        $col['name'] = 'temp #'.$col['id'];
[17178]134        $col['U_SAVE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'save','col_id'=>$col['id']));
[16591]135        $template->append('temp_col', $col);
136      }
137      else
138      {
139        $template->append('collections', $col);
140      }
141    }
142   
[17178]143    $template->assign('U_CREATE', add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0')));
[16591]144    break;
145  }
[16597]146 
147  /* edit */
[16591]148  case 'edit':
149  {
[16658]150    // security
[16591]151    if (empty($page['col_id']))
152    {
153      $_SESSION['page_errors'][] = l10n('Invalid collection');
154      redirect(USER_COLLEC_PUBLIC);
155    }
156   
[16658]157    $template->set_filename('index', dirname(__FILE__).'/../template/edit.tpl');
158   
[16591]159    $self_url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id'];
160    $template->assign(array(
[20090]161      'user_collections' => $conf['user_collections'],
[16591]162      'USER_COLLEC_PATH' => USER_COLLEC_PATH,
[16658]163      'F_ACTION' => $self_url,
[16625]164      'collection_toggle_url' => $self_url,
[16591]165      'U_LIST' => USER_COLLEC_PUBLIC,
[16608]166      'COL_ID' => $page['col_id'],
[16591]167      ));
168   
169    try {
170      $UserCollection = new UserCollection($page['col_id']);
171     
[16658]172      // security
173      if ( !is_admin() and $UserCollection->getParam('user_id') != $user['id'] )
[16597]174      {
175        access_denied();
176      }
177     
[16591]178      // save properties
179      if (isset($_POST['save_col']))
180      {
[19843]181        if (empty($_POST['name']))
182        {
183          array_push($page['errors'], l10n('Please give a name'));
184        }
185        else
186        {
[20090]187          $UserCollection->updateParam('name', stripslashes($_POST['name']));
[19843]188        }
[20090]189        if (!$conf['user_collections']['allow_public'])
190        {
191          $_POST['public'] = '0';
192        }
[16591]193        $UserCollection->updateParam('public', $_POST['public']);
194      }
195     
[20090]196      // send mail
197      if ( $conf['user_collections']['allow_public'] and $conf['user_collections']['allow_mails'] )
198      {
199        $contact = array(
200            'sender_name' => $user['username'],
201            'sender_email' => $user['email'],
202            'recipient_name' => null,
203            'recipient_email' => null,
204            'nb_images' => 4,
205            'message' => null,
206            );
207           
208        if ( isset($_POST['send_mail']) and (bool)$UserCollection->getParam('public') )
209        {
210          $contact = array(
211            'sender_email' => trim($_POST['sender_email']),
212            'sender_name' => trim($_POST['sender_name']),
213            'recipient_email' => trim($_POST['recipient_email']),
214            'recipient_name' => trim($_POST['recipient_name']),
215            'nb_images' => $_POST['nb_images'],
216            'message' => $_POST['message'],
217            );
218           
219          $errors = $UserCollection->sendEmail($contact, @$_POST['key']);
220          if (count($errors))
221          {
222            $template->assign('uc_mail_errors', $errors);
223          }
224        }
225       
226        $contact['KEY'] = get_ephemeral_key(3);
227        $template->assign('contact', $contact);
228      }
229     
[16688]230      // clear
231      if ( isset($_GET['action']) and $_GET['action'] == 'clear' )
232      {
233        $UserCollection->clearImages();
234      }
235     
[16591]236      // remove an element
[16625]237      if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) )
[16591]238      {
[16625]239        $UserCollection->removeImages(array($_GET['collection_toggle']));
[16688]240        unset($_GET['collection_toggle']);
[16591]241      }
242     
[20090]243      // add links for colorbox
244      add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
245     
246      // add remove item links
[16625]247      $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
[16591]248     
[16658]249      // collection content
[16688]250      $col = $UserCollection->getCollectionInfo();
[20090]251      $col['DATE_CREATION'] = format_date($col['DATE_CREATION'], true);
[16688]252      $col['U_CLEAR'] = $self_url.'&amp;action=clear';
[17178]253      $col['U_DELETE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$page['col_id']));
[16688]254      $template->assign('collection', $col);
[16591]255      $page['items'] = $UserCollection->getImages();
256     
[20090]257      // toolbar buttons
258      $buttons = null;
259      if ($conf['user_collections']['allow_public'] and $conf['user_collections']['allow_mails'])
[16591]260      {
[20090]261        $buttons.= '<li><a class="mail_colorbox_open" href="#mail_form" title="'.l10n('Send this collection my mail').'" class="pwg-state-default pwg-button" rel="nofollow" '.(!$col['PUBLIC']?'onClick="alert(\''.l10n('The collection must be public in order to send it').'\');return false;"':null).'>
262          <span class="pwg-icon user-collections-delete-icon" style="background:url(\'' . get_root_url().USER_COLLEC_PATH . 'template/resources/mail.png\') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">'.l10n('Send').'</span>
263        </a></li>';
[16591]264      }
[20090]265      $buttons.= '
266        <li><a href="'. $col['U_CLEAR'] .'" title="'.l10n('Clear this collection').'" class="pwg-state-default pwg-button" rel="nofollow" onClick="return confirm(\''.l10n('Are you sure?').'\');">
267          <span class="pwg-icon user-collections-delete-icon" style="background:url(\'' . get_root_url().USER_COLLEC_PATH . 'template/resources/bin.png\') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">'.l10n('Clear').'</span>
268        </a></li>
269        <li><a href="'. $col['U_DELETE'] .'" title="'.l10n('Delete this collection').'" class="pwg-state-default pwg-button" rel="nofollow" onClick="return confirm(\''.l10n('Are you sure?').'\');">
270          <span class="pwg-icon user-collections-delete-icon" style="background:url(\'' . get_root_url().USER_COLLEC_PATH . 'template/resources/delete.png\') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">'.l10n('Delete').'</span>
271        </a></li>';
272      $template->concat('COLLECTION_ACTIONS', $buttons);
[16591]273     
[20090]274      // thumbnails
275      define('USER_COLLEC_REMOVE_GTHUMB', true);
276      include(USER_COLLEC_PATH . '/include/display_thumbnails.inc.php');
[16597]277     
278      $template->concat('TITLE', $conf['level_separator'].$UserCollection->getParam('name'));
[16591]279    }
280    catch (Exception $e)
281    {
282      array_push($page['errors'], $e->getMessage());
283    }
284   
285    break;
286  }
287 
[16597]288  /* view */
[16591]289  case 'view':
290  {
[16658]291    // security
[20090]292    if ( empty($page['col_id']) or strlen($page['col_id']) != 10 or strpos($page['col_id'], 'uc') === false or !$conf['user_collections']['allow_public'] )
[16591]293    {
294      $_SESSION['page_errors'][] = l10n('Invalid collection');
[16658]295      redirect('index.php');
[16591]296    }
297   
[16658]298    $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl');
299   
[16591]300    $self_url = USER_COLLEC_PUBLIC . 'view/'.$page['col_id'];
301   
[16658]302    try {
[16591]303      $UserCollection = new UserCollection($page['col_id']);
[16658]304      $page['items'] = $UserCollection->getImages();
[16591]305     
[20090]306      // thumbnails
307      include(USER_COLLEC_PATH . '/include/display_thumbnails.inc.php');
[16591]308     
[20090]309      // add username in title
[16597]310      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
311      $template->concat('TITLE', 
312        $conf['level_separator'].$UserCollection->getParam('name').
313        ' ('.sprintf(l10n('by %s'), get_username($UserCollection->getParam('user_id'))).')'
314        );
[16591]315    }
316    catch (Exception $e)
317    {
[16597]318      access_denied();
[16591]319    }
320   
321    break;
322  }
323}
324
[20090]325
[17519]326$template->assign(array(
327  'USER_COLLEC_PATH' => USER_COLLEC_PATH,
328  'USER_COLLEC_ABS_PATH' => realpath(USER_COLLEC_PATH).'/',
329  ));
[16591]330
[16608]331
[16658]332function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures)
333{
334  global $template, $page;
[16591]335 
[16658]336  $template->set_filename('index_thumbnails', dirname(__FILE__).'/../template/thumbnails.tpl');
[16608]337 
[16658]338  foreach ($tpl_thumbnails_var as &$thumbnail)
339  {
340    $src_image = new SrcImage($thumbnail);
341   
342    $thumbnail['FILE_SRC'] = DerivativeImage::url(IMG_LARGE, $src_image);
343    $thumbnail['URL'] = duplicate_picture_url(
344        array(
345          'image_id' => $thumbnail['id'],
346          'image_file' => $thumbnail['file'],
347          'section' => 'none',
348        ),
349        array('start')
350      );
351  }
352 
353  return $tpl_thumbnails_var;
354}
[16591]355
356?>
Note: See TracBrowser for help on using the repository browser.