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 | define('USER_COLLEC_PUBLIC', make_index_url(array('section' => 'collections')) . '/'); |
---|
19 | |
---|
20 | if ($tokens[0] == 'collections') |
---|
21 | { |
---|
22 | $page['section'] = 'collections'; |
---|
23 | $page['title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>'; |
---|
24 | |
---|
25 | if (in_array(@$tokens[1], array('edit','view','list'))) |
---|
26 | { |
---|
27 | $page['sub_section'] = $tokens[1]; |
---|
28 | } |
---|
29 | else |
---|
30 | { |
---|
31 | $page['sub_section'] = 'list'; |
---|
32 | } |
---|
33 | |
---|
34 | if (!empty($tokens[2])) |
---|
35 | { |
---|
36 | $page['col_id'] = $tokens[2]; |
---|
37 | } |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | /* collections section */ |
---|
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 | { |
---|
56 | if (is_a_guest()) return; |
---|
57 | |
---|
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 | { |
---|
74 | if (is_a_guest()) return $tpl_thumbnails_var; |
---|
75 | |
---|
76 | global $page, $template, $UserCollection; |
---|
77 | |
---|
78 | // the prefilter is different on collection page |
---|
79 | if (isset($page['section']) and ($page['section'] == 'collections' or $page['section'] == 'download')) return $tpl_thumbnails_var; |
---|
80 | |
---|
81 | // get existing collections |
---|
82 | $col_id = get_current_collection_id(false); |
---|
83 | if (empty($UserCollection) and $col_id !== false) |
---|
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 | |
---|
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 | } |
---|
102 | |
---|
103 | |
---|
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, |
---|
118 | 'collection_toggle_url' => add_url_params($self_url, array('collection_toggle'=>'')), |
---|
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 | { |
---|
127 | // add links |
---|
128 | $search = '<span class="wrap1">'; |
---|
129 | $replace = $search.' |
---|
130 | {strip}<a class="addCollection" href="{$collection_toggle_url}{$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow"> |
---|
131 | {if $COL_ID or $thumbnail.COLLECTION_SELECTED} |
---|
132 | {\'Remove from collection\'|@translate} <img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/image_delete.png" title="{\'Remove from collection\'|@translate}"> |
---|
133 | {else} |
---|
134 | {\'Add to collection\'|@translate} <img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/image_add.png" title="{\'Add to collection\'|@translate}"> |
---|
135 | {/if} |
---|
136 | </a>{/strip}'; |
---|
137 | |
---|
138 | // custom CSS and AJAX request |
---|
139 | $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl'); |
---|
140 | |
---|
141 | return str_replace($search, $replace, $content); |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | /* add button on picture page */ |
---|
146 | function user_collections_picture_page() |
---|
147 | { |
---|
148 | if (is_a_guest()) return; |
---|
149 | |
---|
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 | |
---|
179 | $url = add_url_params(duplicate_picture_url(), array('action'=>'collection_toggle')); |
---|
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"> |
---|
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> |
---|
184 | <span class="pwg-button-text">'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'</span> |
---|
185 | </a>'; |
---|
186 | // $template->add_picture_button($button, 50); |
---|
187 | $template->concat('PLUGIN_PICTURE_ACTIONS', $button); |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | /* menu block */ |
---|
192 | function user_collections_add_menublock($menu_ref_arr) |
---|
193 | { |
---|
194 | if (is_a_guest()) return; |
---|
195 | |
---|
196 | $menu = &$menu_ref_arr[0]; |
---|
197 | if ($menu->get_id() != 'menubar') return; |
---|
198 | |
---|
199 | $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection')); |
---|
200 | } |
---|
201 | |
---|
202 | function user_collections_applymenu($menu_ref_arr) |
---|
203 | { |
---|
204 | $max = 6; |
---|
205 | |
---|
206 | if (!defined('USER_COLLEC_PUBLIC')) define('USER_COLLEC_PUBLIC', make_index_url(array('section' => 'collections')) . '/'); |
---|
207 | |
---|
208 | global $template, $conf, $user, $UserCollection; |
---|
209 | $menu = &$menu_ref_arr[0]; |
---|
210 | |
---|
211 | if (($block = $menu->get_block('mbUserCollection')) != null) |
---|
212 | { |
---|
213 | $query = ' |
---|
214 | SELECT * |
---|
215 | FROM '.COLLECTIONS_TABLE.' |
---|
216 | WHERE user_id = '.$user['id'].' |
---|
217 | ORDER BY |
---|
218 | active DESC, |
---|
219 | date_creation DESC |
---|
220 | ;'; |
---|
221 | $collections = array_values(hash_from_query($query, 'id')); |
---|
222 | |
---|
223 | $data['collections'] = array(); |
---|
224 | for ($i=0; $i<$max && $i<count($collections); $i++) |
---|
225 | { |
---|
226 | $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id']; |
---|
227 | array_push($data['collections'], $collections[$i]); |
---|
228 | } |
---|
229 | |
---|
230 | $data['NB_COL'] = count($collections); |
---|
231 | if ($data['NB_COL'] > $max) |
---|
232 | { |
---|
233 | $data['MORE'] = count($collections)-$max; |
---|
234 | } |
---|
235 | |
---|
236 | $data['U_LIST'] = USER_COLLEC_PUBLIC; |
---|
237 | $data['U_CREATE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0','redirect'=>'true')); |
---|
238 | |
---|
239 | $template->set_template_dir(USER_COLLEC_PATH . 'template/'); |
---|
240 | $block->set_title('<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>'); |
---|
241 | $block->template = 'menublock_user_collec.tpl'; |
---|
242 | $block->data = $data; |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | ?> |
---|