[16591] | 1 | <?php |
---|
| 2 | defined('USER_COLLEC_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | # this file contains all functions directly called by the triggers # |
---|
| 5 | |
---|
| 6 | |
---|
| 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 | { |
---|
| 14 | $page['section'] = 'collections'; |
---|
[16608] | 15 | $page['title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>'; |
---|
[16591] | 16 | |
---|
[16597] | 17 | if (in_array(@$tokens[1], array('edit','view','list'))) |
---|
[16591] | 18 | { |
---|
[16597] | 19 | $page['sub_section'] = $tokens[1]; |
---|
[16591] | 20 | } |
---|
[16597] | 21 | else |
---|
| 22 | { |
---|
| 23 | $page['sub_section'] = 'list'; |
---|
| 24 | } |
---|
[16591] | 25 | |
---|
| 26 | if (!empty($tokens[2])) |
---|
| 27 | { |
---|
| 28 | $page['col_id'] = $tokens[2]; |
---|
| 29 | } |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | |
---|
[16625] | 33 | /* collections section */ |
---|
[16591] | 34 | function user_collections_page() |
---|
| 35 | { |
---|
| 36 | global $page; |
---|
| 37 | |
---|
| 38 | if (isset($page['section']) and $page['section'] == 'collections') |
---|
| 39 | { |
---|
| 40 | include(USER_COLLEC_PATH . '/include/collections.inc.php'); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /* add buttons on thumbnails list */ |
---|
| 46 | function user_collections_index_actions() |
---|
| 47 | { |
---|
[16597] | 48 | if (is_a_guest()) return; |
---|
| 49 | |
---|
[16591] | 50 | global $page, $UserCollection; |
---|
| 51 | |
---|
| 52 | // add image to collection list |
---|
| 53 | if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) ) |
---|
| 54 | { |
---|
| 55 | if (empty($UserCollection)) |
---|
| 56 | { |
---|
| 57 | $UserCollection = new UserCollection(get_current_collection_id(true)); |
---|
| 58 | } |
---|
| 59 | $UserCollection->toggleImage($_GET['collection_toggle']); |
---|
| 60 | redirect(duplicate_index_url(array(), array('collection_toggle'))); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures) |
---|
| 65 | { |
---|
[16597] | 66 | if (is_a_guest()) return $tpl_thumbnails_var; |
---|
| 67 | |
---|
[16591] | 68 | global $page, $template, $UserCollection; |
---|
| 69 | |
---|
| 70 | // the prefilter is different on collection page |
---|
[16599] | 71 | if (isset($page['section']) and ($page['section'] == 'collections' or $page['section'] == 'download')) return $tpl_thumbnails_var; |
---|
[16591] | 72 | |
---|
| 73 | // get existing collections |
---|
[16698] | 74 | $col_id = get_current_collection_id(false); |
---|
| 75 | if (empty($UserCollection) and $col_id !== false) |
---|
[16591] | 76 | { |
---|
| 77 | $UserCollection = new UserCollection($col_id); |
---|
| 78 | $collection = $UserCollection->getImages(); |
---|
| 79 | } |
---|
| 80 | else if (!empty($UserCollection)) |
---|
| 81 | { |
---|
| 82 | $collection = $UserCollection->getImages(); |
---|
| 83 | } |
---|
| 84 | else |
---|
| 85 | { |
---|
| 86 | $collection = array(); |
---|
| 87 | } |
---|
| 88 | |
---|
[16698] | 89 | // if the collection is created we don't use AJAX to force menu refresh |
---|
| 90 | if ($col_id === false) |
---|
| 91 | { |
---|
| 92 | $template->assign('NO_AJAX', true); |
---|
| 93 | } |
---|
[16591] | 94 | |
---|
[16698] | 95 | |
---|
[16591] | 96 | $self_url = duplicate_index_url(array(), array('collection_toggle')); |
---|
| 97 | |
---|
| 98 | foreach ($tpl_thumbnails_var as &$thumbnail) |
---|
| 99 | { |
---|
| 100 | if (in_array($thumbnail['id'], $collection)) |
---|
| 101 | { |
---|
| 102 | $thumbnail['COLLECTION_SELECTED'] = true; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | unset($thumbnail); |
---|
| 106 | |
---|
| 107 | // thumbnails buttons |
---|
| 108 | $template->assign(array( |
---|
| 109 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
[17178] | 110 | 'collection_toggle_url' => add_url_params($self_url, array('collection_toggle'=>'')), |
---|
[16591] | 111 | )); |
---|
| 112 | $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter'); |
---|
| 113 | |
---|
| 114 | return $tpl_thumbnails_var; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | function user_collections_thumbnails_list_prefilter($content, &$smarty) |
---|
| 118 | { |
---|
[16625] | 119 | // add links |
---|
| 120 | $search = '<span class="wrap1">'; |
---|
| 121 | $replace = $search.' |
---|
[17178] | 122 | {strip}<a class="addCollection" href="{$collection_toggle_url}{$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow"> |
---|
[16625] | 123 | {if $COL_ID or $thumbnail.COLLECTION_SELECTED} |
---|
[17178] | 124 | {\'Remove from collection\'|@translate} <img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/image_delete.png" title="{\'Remove from collection\'|@translate}"> |
---|
[16591] | 125 | {else} |
---|
[17178] | 126 | {\'Add to collection\'|@translate} <img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/image_add.png" title="{\'Add to collection\'|@translate}"> |
---|
[16591] | 127 | {/if} |
---|
[16608] | 128 | </a>{/strip}'; |
---|
[16591] | 129 | |
---|
[16625] | 130 | // custom CSS and AJAX request |
---|
| 131 | $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl'); |
---|
[16608] | 132 | |
---|
| 133 | return str_replace($search, $replace, $content); |
---|
[16591] | 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | /* add button on picture page */ |
---|
| 138 | function user_collections_picture_page() |
---|
| 139 | { |
---|
[16597] | 140 | if (is_a_guest()) return; |
---|
| 141 | |
---|
[16591] | 142 | global $template, $picture, $UserCollection; |
---|
| 143 | |
---|
| 144 | // add image to collection list |
---|
| 145 | if ( isset($_GET['action']) and $_GET['action'] == 'collection_toggle' ) |
---|
| 146 | { |
---|
| 147 | if (empty($UserCollection)) |
---|
| 148 | { |
---|
| 149 | $UserCollection = new UserCollection(get_current_collection_id(true)); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | $UserCollection->toggleImage($picture['current']['id']); |
---|
| 153 | redirect(duplicate_picture_url()); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | // get existing collection |
---|
| 157 | if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false) |
---|
| 158 | { |
---|
| 159 | $UserCollection = new UserCollection($col_id); |
---|
| 160 | $collection = $UserCollection->isInSet($picture['current']['id']); |
---|
| 161 | } |
---|
| 162 | else if (!empty($UserCollection)) |
---|
| 163 | { |
---|
| 164 | $collection = $UserCollection->isInSet($picture['current']['id']); |
---|
| 165 | } |
---|
| 166 | else |
---|
| 167 | { |
---|
| 168 | $collection = false; |
---|
| 169 | } |
---|
| 170 | |
---|
[17178] | 171 | $url = add_url_params(duplicate_picture_url(), array('action'=>'collection_toggle')); |
---|
[16591] | 172 | |
---|
| 173 | $button = ' |
---|
| 174 | <a href="'.$url.'" title="'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'" class="pwg-state-default pwg-button" rel="nofollow"> |
---|
[17178] | 175 | <span class="pwg-icon" style="background:url(\''.get_root_url().USER_COLLEC_PATH.'template/image_'.($collection?'delete':'add').'.png\') center center no-repeat;"> </span> |
---|
[16591] | 176 | <span class="pwg-button-text">'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'</span> |
---|
| 177 | </a>'; |
---|
[17178] | 178 | // $template->add_picture_button($button, 50); |
---|
[16591] | 179 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | /* menu block */ |
---|
| 184 | function user_collections_add_menublock($menu_ref_arr) |
---|
| 185 | { |
---|
[16597] | 186 | if (is_a_guest()) return; |
---|
| 187 | |
---|
[16591] | 188 | $menu = &$menu_ref_arr[0]; |
---|
| 189 | if ($menu->get_id() != 'menubar') return; |
---|
[16698] | 190 | |
---|
[16597] | 191 | $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection')); |
---|
[16591] | 192 | } |
---|
| 193 | |
---|
| 194 | function user_collections_applymenu($menu_ref_arr) |
---|
| 195 | { |
---|
[16688] | 196 | $max = 6; |
---|
| 197 | |
---|
| 198 | global $template, $conf, $user, $UserCollection; |
---|
[16591] | 199 | $menu = &$menu_ref_arr[0]; |
---|
| 200 | |
---|
| 201 | if (($block = $menu->get_block('mbUserCollection')) != null) |
---|
| 202 | { |
---|
[16688] | 203 | $query = ' |
---|
| 204 | SELECT * |
---|
| 205 | FROM '.COLLECTIONS_TABLE.' |
---|
| 206 | WHERE user_id = '.$user['id'].' |
---|
| 207 | ORDER BY |
---|
| 208 | active DESC, |
---|
| 209 | date_creation DESC |
---|
| 210 | ;'; |
---|
| 211 | $collections = array_values(hash_from_query($query, 'id')); |
---|
| 212 | |
---|
| 213 | $data['collections'] = array(); |
---|
| 214 | for ($i=0; $i<$max && $i<count($collections); $i++) |
---|
[16591] | 215 | { |
---|
[16688] | 216 | $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id']; |
---|
| 217 | array_push($data['collections'], $collections[$i]); |
---|
| 218 | } |
---|
[16591] | 219 | |
---|
[16688] | 220 | $data['NB_COL'] = count($collections); |
---|
| 221 | if ($data['NB_COL'] > $max) |
---|
| 222 | { |
---|
| 223 | $data['MORE'] = count($collections)-$max; |
---|
[16591] | 224 | } |
---|
[16597] | 225 | |
---|
| 226 | $data['U_LIST'] = USER_COLLEC_PUBLIC; |
---|
[17178] | 227 | $data['U_CREATE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0','redirect'=>'true')); |
---|
[16599] | 228 | |
---|
[16591] | 229 | $template->set_template_dir(USER_COLLEC_PATH . 'template/'); |
---|
[16688] | 230 | $block->set_title('<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>'); |
---|
[16599] | 231 | $block->template = 'menublock_user_collec.tpl'; |
---|
[16591] | 232 | $block->data = $data; |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | ?> |
---|