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