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 | |
---|
18 | if ($tokens[0] == 'collections') |
---|
19 | { |
---|
20 | $page['section'] = 'collections'; |
---|
21 | $page['title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>'; |
---|
22 | |
---|
23 | if (in_array(@$tokens[1], array('edit','view','list'))) |
---|
24 | { |
---|
25 | $page['sub_section'] = $tokens[1]; |
---|
26 | } |
---|
27 | else |
---|
28 | { |
---|
29 | $page['sub_section'] = 'list'; |
---|
30 | } |
---|
31 | |
---|
32 | if (!empty($tokens[2])) |
---|
33 | { |
---|
34 | $page['col_id'] = $tokens[2]; |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | // if ( script_basename() == 'picture' and @$tokens[1] == 'collections' and preg_match('#^[0-9]+$#', @$tokens[2]) ) |
---|
39 | // { |
---|
40 | // try |
---|
41 | // { |
---|
42 | // $UserCollection = new UserCollection($tokens[2]); |
---|
43 | // $page['title'].= $conf['level_separator'].l10n('Collection').': <a href="'.USER_COLLEC_PUBLIC . 'view/'.$tokens[2].'">'.$UserCollection->getParam('name').'</a>'; |
---|
44 | // $page['items'] = $UserCollection->getImages(); |
---|
45 | // $page['col_id'] = $tokens[2]; |
---|
46 | // } catch (Exception $e) {} |
---|
47 | // } |
---|
48 | } |
---|
49 | |
---|
50 | /* collections section */ |
---|
51 | function user_collections_page() |
---|
52 | { |
---|
53 | global $page; |
---|
54 | |
---|
55 | if (isset($page['section']) and $page['section'] == 'collections') |
---|
56 | { |
---|
57 | include(USER_COLLEC_PATH . '/include/collections.inc.php'); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | /* add buttons on thumbnails list */ |
---|
63 | function user_collections_index_actions() |
---|
64 | { |
---|
65 | if (is_a_guest()) return; |
---|
66 | |
---|
67 | global $page, $UserCollection; |
---|
68 | |
---|
69 | // add image to collection list |
---|
70 | if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) ) |
---|
71 | { |
---|
72 | if (empty($UserCollection)) |
---|
73 | { |
---|
74 | $UserCollection = new UserCollection(get_current_collection_id(true)); |
---|
75 | } |
---|
76 | $UserCollection->toggleImage($_GET['collection_toggle']); |
---|
77 | redirect(duplicate_index_url(array(), array('collection_toggle'))); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures) |
---|
82 | { |
---|
83 | if (is_a_guest()) return $tpl_thumbnails_var; |
---|
84 | |
---|
85 | global $page, $template, $UserCollection; |
---|
86 | |
---|
87 | // the prefilter is different on collection page |
---|
88 | if (isset($page['section']) and ($page['section'] == 'collections' or $page['section'] == 'download')) return $tpl_thumbnails_var; |
---|
89 | |
---|
90 | // get existing collections |
---|
91 | if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false) |
---|
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 | |
---|
105 | |
---|
106 | $self_url = duplicate_index_url(array(), array('collection_toggle')); |
---|
107 | |
---|
108 | foreach ($tpl_thumbnails_var as &$thumbnail) |
---|
109 | { |
---|
110 | if (in_array($thumbnail['id'], $collection)) |
---|
111 | { |
---|
112 | $thumbnail['COLLECTION_SELECTED'] = true; |
---|
113 | } |
---|
114 | } |
---|
115 | unset($thumbnail); |
---|
116 | |
---|
117 | // thumbnails buttons |
---|
118 | $template->assign(array( |
---|
119 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
120 | 'collection_toggle_url' => $self_url, |
---|
121 | )); |
---|
122 | $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter'); |
---|
123 | |
---|
124 | return $tpl_thumbnails_var; |
---|
125 | } |
---|
126 | |
---|
127 | function user_collections_thumbnails_list_prefilter($content, &$smarty) |
---|
128 | { |
---|
129 | // add links |
---|
130 | $search = '<span class="wrap1">'; |
---|
131 | $replace = $search.' |
---|
132 | {strip}<a class="addCollection" href="{$collection_toggle_url}&collection_toggle={$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow"> |
---|
133 | {if $COL_ID or $thumbnail.COLLECTION_SELECTED} |
---|
134 | {\'Remove from collection\'|@translate} <img src="{$USER_COLLEC_PATH}template/image_delete.png" title="{\'Remove from collection\'|@translate}"> |
---|
135 | {else} |
---|
136 | {\'Add to collection\'|@translate} <img src="{$USER_COLLEC_PATH}template/image_add.png" title="{\'Add to collection\'|@translate}"> |
---|
137 | {/if} |
---|
138 | </a>{/strip}'; |
---|
139 | |
---|
140 | // custom CSS and AJAX request |
---|
141 | $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl'); |
---|
142 | |
---|
143 | return str_replace($search, $replace, $content); |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | /* add button on picture page */ |
---|
148 | function user_collections_picture_page() |
---|
149 | { |
---|
150 | if (is_a_guest()) return; |
---|
151 | |
---|
152 | global $template, $picture, $UserCollection; |
---|
153 | |
---|
154 | // add image to collection list |
---|
155 | if ( isset($_GET['action']) and $_GET['action'] == 'collection_toggle' ) |
---|
156 | { |
---|
157 | if (empty($UserCollection)) |
---|
158 | { |
---|
159 | $UserCollection = new UserCollection(get_current_collection_id(true)); |
---|
160 | } |
---|
161 | |
---|
162 | $UserCollection->toggleImage($picture['current']['id']); |
---|
163 | redirect(duplicate_picture_url()); |
---|
164 | } |
---|
165 | |
---|
166 | // get existing collection |
---|
167 | if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false) |
---|
168 | { |
---|
169 | $UserCollection = new UserCollection($col_id); |
---|
170 | $collection = $UserCollection->isInSet($picture['current']['id']); |
---|
171 | } |
---|
172 | else if (!empty($UserCollection)) |
---|
173 | { |
---|
174 | $collection = $UserCollection->isInSet($picture['current']['id']); |
---|
175 | } |
---|
176 | else |
---|
177 | { |
---|
178 | $collection = false; |
---|
179 | } |
---|
180 | |
---|
181 | $url = duplicate_picture_url().'&action=collection_toggle'; |
---|
182 | |
---|
183 | $button = ' |
---|
184 | <a href="'.$url.'" title="'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'" class="pwg-state-default pwg-button" rel="nofollow"> |
---|
185 | <span class="pwg-icon" style="background:url(\''.USER_COLLEC_PATH.'template/image_'.($collection?'delete':'add').'.png\') center center no-repeat;"> </span> |
---|
186 | <span class="pwg-button-text">'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'</span> |
---|
187 | </a>'; |
---|
188 | |
---|
189 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | /* menu block */ |
---|
194 | function user_collections_add_menublock($menu_ref_arr) |
---|
195 | { |
---|
196 | if (is_a_guest()) return; |
---|
197 | |
---|
198 | global $user; |
---|
199 | |
---|
200 | $menu = &$menu_ref_arr[0]; |
---|
201 | if ($menu->get_id() != 'menubar') return; |
---|
202 | |
---|
203 | $query = ' |
---|
204 | SELECT id |
---|
205 | FROM '.COLLECTIONS_TABLE.' |
---|
206 | WHERE user_id = '.$user['id'].' |
---|
207 | LIMIT 1 |
---|
208 | ;'; |
---|
209 | $result = pwg_query($query); |
---|
210 | |
---|
211 | if (!pwg_db_num_rows($result)) return; |
---|
212 | |
---|
213 | $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection')); |
---|
214 | } |
---|
215 | |
---|
216 | function user_collections_applymenu($menu_ref_arr) |
---|
217 | { |
---|
218 | global $template, $conf, $UserCollection; |
---|
219 | $menu = &$menu_ref_arr[0]; |
---|
220 | |
---|
221 | if (($block = $menu->get_block('mbUserCollection')) != null) |
---|
222 | { |
---|
223 | if (($col_id = get_current_collection_id(false)) !== false) |
---|
224 | { |
---|
225 | if (empty($UserCollection)) |
---|
226 | { |
---|
227 | $UserCollection = new UserCollection($col_id); |
---|
228 | } |
---|
229 | |
---|
230 | $data = array( |
---|
231 | 'current' => array( |
---|
232 | 'NAME' => $UserCollection->getParam('name'), |
---|
233 | 'NB_IMAGES' => $UserCollection->getParam('nb_images'), |
---|
234 | ), |
---|
235 | 'links' => array(), |
---|
236 | ); |
---|
237 | |
---|
238 | if ($data['current']['NB_IMAGES'] > 0) |
---|
239 | { |
---|
240 | $data['links'] = array( |
---|
241 | array( |
---|
242 | 'URL' => USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('col_id'), |
---|
243 | 'NAME' => l10n('Display collection'), |
---|
244 | ), |
---|
245 | array( |
---|
246 | 'URL' => USER_COLLEC_PUBLIC.'&action=clear&col_id='.$UserCollection->getParam('col_id'), |
---|
247 | 'NAME' => l10n('Clear collection'), |
---|
248 | ), |
---|
249 | ); |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | $data['U_LIST'] = USER_COLLEC_PUBLIC; |
---|
254 | |
---|
255 | $template->set_template_dir(USER_COLLEC_PATH . 'template/'); |
---|
256 | $block->set_title(l10n('Collections')); |
---|
257 | $block->template = 'menublock_user_collec.tpl'; |
---|
258 | $block->data = $data; |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | ?> |
---|