[16591] | 1 | <?php |
---|
| 2 | defined('USER_COLLEC_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
[20097] | 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | SECTION INIT |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
[16591] | 7 | /* define page section from url */ |
---|
| 8 | function user_collections_section_init() |
---|
| 9 | { |
---|
| 10 | global $tokens, $page, $conf; |
---|
[17178] | 11 | |
---|
[16591] | 12 | if ($tokens[0] == 'collections') |
---|
| 13 | { |
---|
[21382] | 14 | add_event_handler('loc_begin_page_header', 'user_collections_page_header'); |
---|
| 15 | |
---|
[16591] | 16 | $page['section'] = 'collections'; |
---|
[21382] | 17 | $page['section_title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>'; |
---|
| 18 | $page['title'] = l10n('Collections'); |
---|
[16591] | 19 | |
---|
[16597] | 20 | if (in_array(@$tokens[1], array('edit','view','list'))) |
---|
[16591] | 21 | { |
---|
[16597] | 22 | $page['sub_section'] = $tokens[1]; |
---|
[16591] | 23 | } |
---|
[16597] | 24 | else |
---|
| 25 | { |
---|
| 26 | $page['sub_section'] = 'list'; |
---|
| 27 | } |
---|
[16591] | 28 | |
---|
| 29 | if (!empty($tokens[2])) |
---|
| 30 | { |
---|
| 31 | $page['col_id'] = $tokens[2]; |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
[21382] | 36 | function user_collections_page_header() |
---|
| 37 | { |
---|
| 38 | global $page; |
---|
| 39 | $page['body_id'] = 'theCollectionPage'; |
---|
| 40 | } |
---|
| 41 | |
---|
[16625] | 42 | /* collections section */ |
---|
[16591] | 43 | function 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 | |
---|
[20097] | 54 | // +-----------------------------------------------------------------------+ |
---|
| 55 | // | CATEGORY PAGE |
---|
| 56 | // +-----------------------------------------------------------------------+ |
---|
| 57 | /* toggle an image, in case of no javascript or first call (must create the collection) */ |
---|
[16591] | 58 | function user_collections_index_actions() |
---|
| 59 | { |
---|
[16597] | 60 | if (is_a_guest()) return; |
---|
| 61 | |
---|
[16591] | 62 | global $page, $UserCollection; |
---|
| 63 | |
---|
| 64 | // add image to collection list |
---|
| 65 | if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) ) |
---|
| 66 | { |
---|
| 67 | if (empty($UserCollection)) |
---|
| 68 | { |
---|
| 69 | $UserCollection = new UserCollection(get_current_collection_id(true)); |
---|
| 70 | } |
---|
| 71 | $UserCollection->toggleImage($_GET['collection_toggle']); |
---|
| 72 | redirect(duplicate_index_url(array(), array('collection_toggle'))); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
[20097] | 76 | /* add buttons on thumbnails list */ |
---|
[16591] | 77 | function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures) |
---|
| 78 | { |
---|
[16597] | 79 | if (is_a_guest()) return $tpl_thumbnails_var; |
---|
| 80 | |
---|
[16591] | 81 | global $page, $template, $UserCollection; |
---|
| 82 | |
---|
[20097] | 83 | // the content is different on collection edition page and no button on batch downloader set edition page |
---|
| 84 | if ( (@$page['section'] == 'collections' and @$page['sub_section']=='edit') or @$page['section'] == 'download') |
---|
| 85 | { |
---|
| 86 | return $tpl_thumbnails_var; |
---|
| 87 | } |
---|
[16591] | 88 | |
---|
| 89 | // get existing collections |
---|
[16698] | 90 | $col_id = get_current_collection_id(false); |
---|
| 91 | if (empty($UserCollection) and $col_id !== false) |
---|
[16591] | 92 | { |
---|
| 93 | $UserCollection = new UserCollection($col_id); |
---|
| 94 | $collection = $UserCollection->getImages(); |
---|
| 95 | } |
---|
| 96 | else if (!empty($UserCollection)) |
---|
| 97 | { |
---|
| 98 | $collection = $UserCollection->getImages(); |
---|
| 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
| 102 | $collection = array(); |
---|
| 103 | } |
---|
| 104 | |
---|
[20097] | 105 | // if the collection doesn't exists we don't use AJAX to force menu refresh |
---|
[16698] | 106 | if ($col_id === false) |
---|
| 107 | { |
---|
| 108 | $template->assign('NO_AJAX', true); |
---|
| 109 | } |
---|
[20141] | 110 | else |
---|
| 111 | { |
---|
| 112 | $template->assign('AJAX_COL_ID', $col_id ); |
---|
| 113 | } |
---|
[16591] | 114 | |
---|
[20097] | 115 | // template vars |
---|
[20141] | 116 | $url = duplicate_index_url(array(), array('collection_toggle')); |
---|
[16698] | 117 | |
---|
[16591] | 118 | foreach ($tpl_thumbnails_var as &$thumbnail) |
---|
| 119 | { |
---|
| 120 | if (in_array($thumbnail['id'], $collection)) |
---|
| 121 | { |
---|
| 122 | $thumbnail['COLLECTION_SELECTED'] = true; |
---|
| 123 | } |
---|
[20141] | 124 | $thumbnail['COLLECTION_TOGGLE_URL'] = add_url_params($url, array('collection_toggle'=>$thumbnail['id'])); |
---|
[16591] | 125 | } |
---|
| 126 | unset($thumbnail); |
---|
| 127 | |
---|
| 128 | $template->assign(array( |
---|
| 129 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
| 130 | )); |
---|
[20097] | 131 | |
---|
| 132 | // thumbnails buttons |
---|
[16591] | 133 | $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter'); |
---|
| 134 | |
---|
| 135 | return $tpl_thumbnails_var; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | function user_collections_thumbnails_list_prefilter($content, &$smarty) |
---|
| 139 | { |
---|
[16625] | 140 | // add links |
---|
[20099] | 141 | $search = '#(<li>|<li class="gthumb">)#'; |
---|
[20097] | 142 | $replace = '$1 |
---|
[20141] | 143 | {strip}<a class="addCollection" href="{$thumbnail.COLLECTION_TOGGLE_URL}" data-id="{$thumbnail.id}" data-stat="{if $thumbnail.COLLECTION_SELECTED}remove{else}add{/if}" rel="nofollow"> |
---|
| 144 | <span class="uc_remove" {if not $thumbnail.COLLECTION_SELECTED}style="display:none;"{/if}> |
---|
[20090] | 145 | {\'Remove from collection\'|@translate} <img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_delete.png" title="{\'Remove from collection\'|@translate}"> |
---|
[20097] | 146 | </span> |
---|
[20141] | 147 | <span class="uc_add" {if $thumbnail.COLLECTION_SELECTED}style="display:none;"{/if}> |
---|
[20090] | 148 | {\'Add to collection\'|@translate} <img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_add.png" title="{\'Add to collection\'|@translate}"> |
---|
[20097] | 149 | </span> |
---|
[16608] | 150 | </a>{/strip}'; |
---|
[16591] | 151 | |
---|
[16625] | 152 | // custom CSS and AJAX request |
---|
| 153 | $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl'); |
---|
[20097] | 154 | |
---|
| 155 | return preg_replace($search, $replace, $content); |
---|
[16591] | 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
[20097] | 159 | // +-----------------------------------------------------------------------+ |
---|
| 160 | // | PICTURE PAGE |
---|
| 161 | // +-----------------------------------------------------------------------+ |
---|
[16591] | 162 | /* add button on picture page */ |
---|
| 163 | function user_collections_picture_page() |
---|
| 164 | { |
---|
[16597] | 165 | if (is_a_guest()) return; |
---|
| 166 | |
---|
[16591] | 167 | global $template, $picture, $UserCollection; |
---|
| 168 | |
---|
| 169 | // add image to collection list |
---|
| 170 | if ( isset($_GET['action']) and $_GET['action'] == 'collection_toggle' ) |
---|
| 171 | { |
---|
| 172 | if (empty($UserCollection)) |
---|
| 173 | { |
---|
| 174 | $UserCollection = new UserCollection(get_current_collection_id(true)); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | $UserCollection->toggleImage($picture['current']['id']); |
---|
| 178 | redirect(duplicate_picture_url()); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | // get existing collection |
---|
| 182 | if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false) |
---|
| 183 | { |
---|
| 184 | $UserCollection = new UserCollection($col_id); |
---|
| 185 | $collection = $UserCollection->isInSet($picture['current']['id']); |
---|
| 186 | } |
---|
| 187 | else if (!empty($UserCollection)) |
---|
| 188 | { |
---|
| 189 | $collection = $UserCollection->isInSet($picture['current']['id']); |
---|
| 190 | } |
---|
| 191 | else |
---|
| 192 | { |
---|
| 193 | $collection = false; |
---|
| 194 | } |
---|
| 195 | |
---|
[17178] | 196 | $url = add_url_params(duplicate_picture_url(), array('action'=>'collection_toggle')); |
---|
[16591] | 197 | |
---|
| 198 | $button = ' |
---|
| 199 | <a href="'.$url.'" title="'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'" class="pwg-state-default pwg-button" rel="nofollow"> |
---|
[20093] | 200 | <span class="pwg-icon" style="background:url(\''.get_root_url().USER_COLLEC_PATH.'template/resources/image_'.($collection?'delete':'add').'.png\') center center no-repeat;"> </span> |
---|
[16591] | 201 | <span class="pwg-button-text">'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'</span> |
---|
| 202 | </a>'; |
---|
[17178] | 203 | // $template->add_picture_button($button, 50); |
---|
[16591] | 204 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | |
---|
[20097] | 208 | // +-----------------------------------------------------------------------+ |
---|
| 209 | // | MENU BLOCK |
---|
| 210 | // +-----------------------------------------------------------------------+ |
---|
| 211 | /* register block */ |
---|
[16591] | 212 | function user_collections_add_menublock($menu_ref_arr) |
---|
| 213 | { |
---|
[16597] | 214 | if (is_a_guest()) return; |
---|
| 215 | |
---|
[16591] | 216 | $menu = &$menu_ref_arr[0]; |
---|
| 217 | if ($menu->get_id() != 'menubar') return; |
---|
[16698] | 218 | |
---|
[16597] | 219 | $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection')); |
---|
[16591] | 220 | } |
---|
| 221 | |
---|
[20097] | 222 | /* fill block */ |
---|
[16591] | 223 | function user_collections_applymenu($menu_ref_arr) |
---|
| 224 | { |
---|
[16688] | 225 | $max = 6; |
---|
| 226 | |
---|
[20097] | 227 | global $template, $page, $conf, $user, $UserCollection; |
---|
[16591] | 228 | $menu = &$menu_ref_arr[0]; |
---|
| 229 | |
---|
[20097] | 230 | // the editable counter is for the active collection, except if we are currently editing a collection |
---|
| 231 | $col_in_edit = 0; |
---|
| 232 | if ( @$page['section'] == 'collections' and @$page['sub_section']=='edit' and !empty($page['col_id']) ) |
---|
| 233 | { |
---|
| 234 | $col_in_edit = $page['col_id']; |
---|
| 235 | } |
---|
| 236 | |
---|
[16591] | 237 | if (($block = $menu->get_block('mbUserCollection')) != null) |
---|
| 238 | { |
---|
[16688] | 239 | $query = ' |
---|
| 240 | SELECT * |
---|
| 241 | FROM '.COLLECTIONS_TABLE.' |
---|
| 242 | WHERE user_id = '.$user['id'].' |
---|
| 243 | ORDER BY |
---|
| 244 | active DESC, |
---|
| 245 | date_creation DESC |
---|
| 246 | ;'; |
---|
| 247 | $collections = array_values(hash_from_query($query, 'id')); |
---|
| 248 | |
---|
| 249 | $data['collections'] = array(); |
---|
| 250 | for ($i=0; $i<$max && $i<count($collections); $i++) |
---|
[16591] | 251 | { |
---|
[20097] | 252 | $collections[$i]['count_handler'] = $col_in_edit!=0 ? $collections[$i]['id']==$col_in_edit : $collections[$i]['active']; |
---|
[16688] | 253 | $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id']; |
---|
| 254 | array_push($data['collections'], $collections[$i]); |
---|
| 255 | } |
---|
[16591] | 256 | |
---|
[16688] | 257 | $data['NB_COL'] = count($collections); |
---|
| 258 | if ($data['NB_COL'] > $max) |
---|
| 259 | { |
---|
| 260 | $data['MORE'] = count($collections)-$max; |
---|
[16591] | 261 | } |
---|
[16597] | 262 | |
---|
| 263 | $data['U_LIST'] = USER_COLLEC_PUBLIC; |
---|
[17178] | 264 | $data['U_CREATE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0','redirect'=>'true')); |
---|
[16599] | 265 | |
---|
[16591] | 266 | $template->set_template_dir(USER_COLLEC_PATH . 'template/'); |
---|
[16688] | 267 | $block->set_title('<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>'); |
---|
[16599] | 268 | $block->template = 'menublock_user_collec.tpl'; |
---|
[16591] | 269 | $block->data = $data; |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | ?> |
---|