[16591] | 1 | <?php |
---|
| 2 | defined('USER_COLLEC_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | # this file is called on basket public page # |
---|
| 5 | |
---|
[16625] | 6 | global $page, $template, $conf, $user, $tokens, $pwg_loaded_plugins; |
---|
[16591] | 7 | |
---|
| 8 | switch ($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 = ' |
---|
| 44 | DELETE 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 = ' |
---|
| 68 | UPDATE '.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 = ' |
---|
| 87 | UPDATE '.COLLECTIONS_TABLE.' |
---|
| 88 | SET active = 0 |
---|
| 89 | WHERE user_id = '.$user['id'].' |
---|
| 90 | ;'; |
---|
| 91 | pwg_query($query); |
---|
| 92 | |
---|
| 93 | $query = ' |
---|
| 94 | UPDATE '.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 = ' |
---|
| 111 | SELECT * |
---|
| 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( |
---|
| 161 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
[16658] | 162 | 'F_ACTION' => $self_url, |
---|
[16625] | 163 | 'collection_toggle_url' => $self_url, |
---|
[16591] | 164 | 'U_LIST' => USER_COLLEC_PUBLIC, |
---|
[16608] | 165 | 'COL_ID' => $page['col_id'], |
---|
[16591] | 166 | )); |
---|
| 167 | |
---|
| 168 | try { |
---|
| 169 | $UserCollection = new UserCollection($page['col_id']); |
---|
| 170 | |
---|
[16658] | 171 | // security |
---|
| 172 | if ( !is_admin() and $UserCollection->getParam('user_id') != $user['id'] ) |
---|
[16597] | 173 | { |
---|
| 174 | access_denied(); |
---|
| 175 | } |
---|
| 176 | |
---|
[16591] | 177 | // save properties |
---|
| 178 | if (isset($_POST['save_col'])) |
---|
| 179 | { |
---|
[19843] | 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 | } |
---|
[16591] | 188 | $UserCollection->updateParam('public', $_POST['public']); |
---|
| 189 | } |
---|
| 190 | |
---|
[16688] | 191 | // clear |
---|
| 192 | if ( isset($_GET['action']) and $_GET['action'] == 'clear' ) |
---|
| 193 | { |
---|
| 194 | $UserCollection->clearImages(); |
---|
| 195 | } |
---|
| 196 | |
---|
[16591] | 197 | // remove an element |
---|
[16625] | 198 | if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) ) |
---|
[16591] | 199 | { |
---|
[16625] | 200 | $UserCollection->removeImages(array($_GET['collection_toggle'])); |
---|
[16688] | 201 | unset($_GET['collection_toggle']); |
---|
[16591] | 202 | } |
---|
| 203 | |
---|
[16658] | 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+ |
---|
[16625] | 206 | $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter'); |
---|
[16591] | 207 | |
---|
[16658] | 208 | // collection content |
---|
[16688] | 209 | $col = $UserCollection->getCollectionInfo(); |
---|
| 210 | $col['U_CLEAR'] = $self_url.'&action=clear'; |
---|
[17178] | 211 | $col['U_DELETE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$page['col_id'])); |
---|
[16688] | 212 | $template->assign('collection', $col); |
---|
| 213 | |
---|
[16591] | 214 | $page['items'] = $UserCollection->getImages(); |
---|
| 215 | |
---|
[16658] | 216 | // navigation bar |
---|
| 217 | $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; |
---|
[16591] | 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 | |
---|
[16658] | 230 | // display |
---|
[16591] | 231 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
[16597] | 232 | |
---|
| 233 | $template->concat('TITLE', $conf['level_separator'].$UserCollection->getParam('name')); |
---|
[16591] | 234 | } |
---|
| 235 | catch (Exception $e) |
---|
| 236 | { |
---|
| 237 | array_push($page['errors'], $e->getMessage()); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | break; |
---|
| 241 | } |
---|
| 242 | |
---|
[16597] | 243 | /* view */ |
---|
[16591] | 244 | case 'view': |
---|
| 245 | { |
---|
[16658] | 246 | // security |
---|
| 247 | if ( empty($page['col_id']) or strlen($page['col_id']) != 10 or strpos($page['col_id'], 'uc') === false ) |
---|
[16591] | 248 | { |
---|
| 249 | $_SESSION['page_errors'][] = l10n('Invalid collection'); |
---|
[16658] | 250 | redirect('index.php'); |
---|
[16591] | 251 | } |
---|
| 252 | |
---|
[16658] | 253 | $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl'); |
---|
| 254 | |
---|
[16591] | 255 | $self_url = USER_COLLEC_PUBLIC . 'view/'.$page['col_id']; |
---|
| 256 | |
---|
[16658] | 257 | try { |
---|
[16591] | 258 | $UserCollection = new UserCollection($page['col_id']); |
---|
| 259 | |
---|
[16658] | 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(); |
---|
[16591] | 265 | |
---|
[16658] | 266 | // navigation bar |
---|
[16591] | 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 | |
---|
[16658] | 280 | // display |
---|
[16591] | 281 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
[16597] | 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 | ); |
---|
[16591] | 288 | } |
---|
| 289 | catch (Exception $e) |
---|
| 290 | { |
---|
[16597] | 291 | access_denied(); |
---|
[16591] | 292 | } |
---|
| 293 | |
---|
| 294 | break; |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | |
---|
[17519] | 298 | $template->assign(array( |
---|
| 299 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
| 300 | 'USER_COLLEC_ABS_PATH' => realpath(USER_COLLEC_PATH).'/', |
---|
| 301 | )); |
---|
[16591] | 302 | |
---|
[16608] | 303 | |
---|
[16658] | 304 | function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures) |
---|
| 305 | { |
---|
| 306 | global $template, $page; |
---|
[16591] | 307 | |
---|
[16658] | 308 | $template->set_filename('index_thumbnails', dirname(__FILE__).'/../template/thumbnails.tpl'); |
---|
[16608] | 309 | |
---|
[16658] | 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 | } |
---|
[16591] | 327 | |
---|
| 328 | ?> |
---|