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