19 $plugins->attachHook('page_not_found', 'gallery_namespace_handler($this);'); |
19 $plugins->attachHook('page_not_found', 'gallery_namespace_handler($this);'); |
20 $plugins->attachHook('page_type_string_set', 'if ( $local_namespace == "Gallery" ) $this->namespace_string = \'image\';'); |
20 $plugins->attachHook('page_type_string_set', 'if ( $local_namespace == "Gallery" ) $this->namespace_string = \'image\';'); |
21 |
21 |
22 function gallery_namespace_handler(&$page) |
22 function gallery_namespace_handler(&$page) |
23 { |
23 { |
24 global $db, $session, $paths, $template, $plugins; // Common objects |
24 global $db, $session, $paths, $template, $plugins; // Common objects |
25 |
25 |
26 if ( $page->namespace != 'Gallery' ) |
26 if ( $page->namespace != 'Gallery' ) |
27 return false; |
27 return false; |
28 |
28 |
29 if ( $page->page_id == 'Root' ) |
29 if ( $page->page_id == 'Root' ) |
30 { |
30 { |
31 page_Special_Gallery(); |
31 page_Special_Gallery(); |
32 return true; |
32 return true; |
33 } |
33 } |
34 |
34 |
35 $row =& $page->image_info; |
35 $row =& $page->image_info; |
36 |
36 |
37 $db->free_result(); |
37 $db->free_result(); |
38 |
38 |
39 $img_id = $row['img_id']; |
39 $img_id = $row['img_id']; |
40 |
40 |
41 if ( !$row['folder_parent'] ) |
41 if ( !$row['folder_parent'] ) |
42 $row['folder_parent'] = ' IS NULL'; |
42 $row['folder_parent'] = ' IS NULL'; |
43 else |
43 else |
44 $row['folder_parent'] = '=' . $row['folder_parent']; |
44 $row['folder_parent'] = '=' . $row['folder_parent']; |
45 |
45 |
46 // Fetch image parent properties |
46 // Fetch image parent properties |
47 $q = $db->sql_query('SELECT img_id, img_title FROM '.table_prefix.'gallery WHERE folder_parent' . $row['folder_parent'] . ' AND is_folder!=1 ORDER BY img_title ASC;'); |
47 $q = $db->sql_query('SELECT img_id, img_title FROM '.table_prefix.'gallery WHERE folder_parent' . $row['folder_parent'] . ' AND is_folder!=1 ORDER BY img_title ASC;'); |
48 if ( !$q ) |
48 if ( !$q ) |
49 $db->_die(); |
49 $db->_die(); |
50 |
50 |
51 $folder_total = $db->numrows(); |
51 $folder_total = $db->numrows(); |
52 $folder_this = 0; |
52 $folder_this = 0; |
53 $prev = false; |
53 $prev = false; |
54 $next = false; |
54 $next = false; |
55 $next_title = ''; |
55 $next_title = ''; |
56 $prev_title = ''; |
56 $prev_title = ''; |
57 |
57 |
58 $i = 0; |
58 $i = 0; |
59 |
59 |
60 while ( $r = $db->fetchrow() ) |
60 while ( $r = $db->fetchrow() ) |
61 { |
61 { |
62 $i++; |
62 $i++; |
63 if ( $i == $folder_total && $r['img_id'] == $img_id ) |
63 if ( $i == $folder_total && $r['img_id'] == $img_id ) |
64 { |
64 { |
65 $folder_this = $i; |
65 $folder_this = $i; |
66 $next = false; |
66 $next = false; |
67 } |
67 } |
68 else if ( $i < $folder_total && $r['img_id'] == $img_id ) |
68 else if ( $i < $folder_total && $r['img_id'] == $img_id ) |
69 { |
69 { |
70 $folder_this = $i; |
70 $folder_this = $i; |
71 $next = true; |
71 $next = true; |
72 } |
72 } |
73 else |
73 else |
74 { |
74 { |
75 if ( $next ) |
75 if ( $next ) |
76 { |
76 { |
77 $next = $r['img_id']; |
77 $next = $r['img_id']; |
78 $next_title = $r['img_title']; |
78 $next_title = $r['img_title']; |
79 break; |
79 break; |
80 } |
80 } |
81 $prev = $r['img_id']; |
81 $prev = $r['img_id']; |
82 $prev_title = $r['img_title']; |
82 $prev_title = $r['img_title']; |
83 } |
83 } |
84 } |
84 } |
85 |
85 |
86 if ( $next ) |
86 if ( $next ) |
87 { |
87 { |
88 $next_sanitized = sanitize_page_id($next_title); |
88 $next_sanitized = sanitize_page_id($next_title); |
89 $next_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $next_sanitized ) : makeUrlNS('Gallery', $next); |
89 $next_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $next_sanitized ) : makeUrlNS('Gallery', $next); |
90 } |
90 } |
91 if ( $prev ) |
91 if ( $prev ) |
92 { |
92 { |
93 $prev_sanitized = sanitize_page_id($prev_title); |
93 $prev_sanitized = sanitize_page_id($prev_title); |
94 $prev_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $prev_sanitized ) : makeUrlNS('Gallery', $prev); |
94 $prev_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $prev_sanitized ) : makeUrlNS('Gallery', $prev); |
95 } |
95 } |
96 |
96 |
97 $db->free_result(); |
97 $db->free_result(); |
98 |
98 |
99 $perms = $session->fetch_page_acl(strval($img_id), 'Gallery'); |
99 $perms = $session->fetch_page_acl(strval($img_id), 'Gallery'); |
100 |
100 |
101 if ( isset($_POST['ajax']) && @$_POST['ajax'] === 'true' && isset($_POST['act']) ) |
101 if ( isset($_POST['ajax']) && @$_POST['ajax'] === 'true' && isset($_POST['act']) ) |
102 { |
102 { |
103 $mode =& $_POST['act']; |
103 $mode =& $_POST['act']; |
104 $response = array(); |
104 $response = array(); |
105 switch($mode) |
105 switch($mode) |
106 { |
106 { |
107 case 'add_tag': |
107 case 'add_tag': |
108 if ( !$perms->get_permissions('snapr_add_tag') ) |
108 if ( !$perms->get_permissions('snapr_add_tag') ) |
109 { |
109 { |
110 die(snapr_json_encode(array( |
110 die(snapr_json_encode(array( |
111 'mode' => 'error', |
111 'mode' => 'error', |
112 'error' => 'You don\'t have permission to add tags.' |
112 'error' => 'You don\'t have permission to add tags.' |
113 ))); |
113 ))); |
114 } |
114 } |
115 if ( empty($row['img_tags']) ) |
115 if ( empty($row['img_tags']) ) |
116 { |
116 { |
117 $row['img_tags'] = '[]'; |
117 $row['img_tags'] = '[]'; |
118 } |
118 } |
119 $row['img_tags'] = snapr_json_decode($row['img_tags']); |
119 $row['img_tags'] = snapr_json_decode($row['img_tags']); |
120 |
120 |
121 $canvas_data = snapr_json_decode($_POST['canvas_params']); |
121 $canvas_data = snapr_json_decode($_POST['canvas_params']); |
122 $tag_data = array( |
122 $tag_data = array( |
123 'tag' => sanitize_html($_POST['tag']), |
123 'tag' => sanitize_html($_POST['tag']), |
124 'canvas_data' => $canvas_data |
124 'canvas_data' => $canvas_data |
125 ); |
125 ); |
126 $row['img_tags'][] = $tag_data; |
126 $row['img_tags'][] = $tag_data; |
127 $tag_data['note_id'] = count($row['img_tags']) - 1; |
127 $tag_data['note_id'] = count($row['img_tags']) - 1; |
128 $tag_data['mode'] = 'add'; |
128 $tag_data['mode'] = 'add'; |
129 $tag_data['initial_hide'] = false; |
129 $tag_data['initial_hide'] = false; |
130 $tag_data['auth_delete'] = true; |
130 $tag_data['auth_delete'] = true; |
131 |
131 |
132 $row['img_tags'] = snapr_json_encode($row['img_tags']); |
132 $row['img_tags'] = snapr_json_encode($row['img_tags']); |
133 $row['img_tags'] = $db->escape($row['img_tags']); |
133 $row['img_tags'] = $db->escape($row['img_tags']); |
134 $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;"); |
134 $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;"); |
135 if ( !$q ) |
135 if ( !$q ) |
136 $db->die_json(); |
136 $db->die_json(); |
137 |
137 |
138 $response[] = $tag_data; |
138 $response[] = $tag_data; |
139 break; |
139 break; |
140 case 'del_tag': |
140 case 'del_tag': |
141 if ( !$perms->get_permissions('snapr_add_tag') ) |
141 if ( !$perms->get_permissions('snapr_add_tag') ) |
142 { |
142 { |
143 die(snapr_json_encode(array( |
143 die(snapr_json_encode(array( |
144 'mode' => 'error', |
144 'mode' => 'error', |
145 'error' => 'You don\'t have permission to add tags.' |
145 'error' => 'You don\'t have permission to add tags.' |
146 ))); |
146 ))); |
147 } |
147 } |
148 if ( empty($row['img_tags']) ) |
148 if ( empty($row['img_tags']) ) |
149 { |
149 { |
150 $row['img_tags'] = '[]'; |
150 $row['img_tags'] = '[]'; |
151 } |
151 } |
152 $row['img_tags'] = snapr_json_decode($row['img_tags']); |
152 $row['img_tags'] = snapr_json_decode($row['img_tags']); |
153 |
153 |
154 $tag_id = intval(@$_POST['tag_id']); |
154 $tag_id = intval(@$_POST['tag_id']); |
155 if ( isset($row['img_tags'][$tag_id]) ) |
155 if ( isset($row['img_tags'][$tag_id]) ) |
156 unset($row['img_tags'][$tag_id]); |
156 unset($row['img_tags'][$tag_id]); |
157 |
157 |
158 $row['img_tags'] = snapr_json_encode($row['img_tags']); |
158 $row['img_tags'] = snapr_json_encode($row['img_tags']); |
159 $row['img_tags'] = $db->escape($row['img_tags']); |
159 $row['img_tags'] = $db->escape($row['img_tags']); |
160 $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;"); |
160 $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;"); |
161 if ( !$q ) |
161 if ( !$q ) |
162 $db->die_json(); |
162 $db->die_json(); |
163 |
163 |
164 $response[] = array( |
164 $response[] = array( |
165 'mode' => 'remove', |
165 'mode' => 'remove', |
166 'note_id' => $tag_id |
166 'note_id' => $tag_id |
167 ); |
167 ); |
168 break; |
168 break; |
169 case 'edit_tag': |
169 case 'edit_tag': |
170 if ( !$perms->get_permissions('snapr_add_tag') ) |
170 if ( !$perms->get_permissions('snapr_add_tag') ) |
171 { |
171 { |
172 die(snapr_json_encode(array( |
172 die(snapr_json_encode(array( |
173 'mode' => 'error', |
173 'mode' => 'error', |
174 'error' => 'You don\'t have permission to edit tags.' |
174 'error' => 'You don\'t have permission to edit tags.' |
175 ))); |
175 ))); |
176 } |
176 } |
177 if ( empty($row['img_tags']) ) |
177 if ( empty($row['img_tags']) ) |
178 { |
178 { |
179 $row['img_tags'] = '[]'; |
179 $row['img_tags'] = '[]'; |
180 } |
180 } |
181 $row['img_tags'] = snapr_json_decode($row['img_tags']); |
181 $row['img_tags'] = snapr_json_decode($row['img_tags']); |
182 |
182 |
183 $tag_id = intval(@$_POST['tag_id']); |
183 $tag_id = intval(@$_POST['tag_id']); |
184 if ( isset($row['img_tags'][$tag_id]) ) |
184 if ( isset($row['img_tags'][$tag_id]) ) |
185 { |
185 { |
186 $row['img_tags'][$tag_id]['tag'] = sanitize_html($_POST['tag']); |
186 $row['img_tags'][$tag_id]['tag'] = sanitize_html($_POST['tag']); |
187 // copy it |
187 // copy it |
188 $tag_return = $row['img_tags'][$tag_id]; |
188 $tag_return = $row['img_tags'][$tag_id]; |
189 unset($tag); |
189 unset($tag); |
190 } |
190 } |
191 else |
191 else |
192 { |
192 { |
193 die(snapr_json_encode(array( |
193 die(snapr_json_encode(array( |
194 'mode' => 'error', |
194 'mode' => 'error', |
195 'error' => 'That tag doesn\'t exist.' |
195 'error' => 'That tag doesn\'t exist.' |
196 ))); |
196 ))); |
197 } |
197 } |
198 |
198 |
199 $row['img_tags'] = snapr_json_encode($row['img_tags']); |
199 $row['img_tags'] = snapr_json_encode($row['img_tags']); |
200 $row['img_tags'] = $db->escape($row['img_tags']); |
200 $row['img_tags'] = $db->escape($row['img_tags']); |
201 $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;"); |
201 $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;"); |
202 if ( !$q ) |
202 if ( !$q ) |
203 $db->die_json(); |
203 $db->die_json(); |
204 |
204 |
205 $tag_return['mode'] = 'add'; |
205 $tag_return['mode'] = 'add'; |
206 $tag_return['canvas_data'] = snapr_json_decode($_POST['canvas_params']); |
206 $tag_return['canvas_data'] = snapr_json_decode($_POST['canvas_params']); |
207 $tag_return['auth_delete'] = $perms->get_permissions('snapr_add_tag'); |
207 $tag_return['auth_delete'] = $perms->get_permissions('snapr_add_tag'); |
208 $tag_return['initial_hide'] = false; |
208 $tag_return['initial_hide'] = false; |
209 $tag_return['note_id'] = $tag_id; |
209 $tag_return['note_id'] = $tag_id; |
210 $response = array($tag_return); |
210 $response = array($tag_return); |
211 |
211 |
212 break; |
212 break; |
213 case 'get_tags': |
213 case 'get_tags': |
214 if ( empty($row['img_tags']) ) |
214 if ( empty($row['img_tags']) ) |
215 { |
215 { |
216 $row['img_tags'] = '[]'; |
216 $row['img_tags'] = '[]'; |
217 } |
217 } |
218 $response = snapr_json_decode($row['img_tags']); |
218 $response = snapr_json_decode($row['img_tags']); |
219 foreach ( $response as $key => $_ ) |
219 foreach ( $response as $key => $_ ) |
220 { |
220 { |
221 unset($_); |
221 unset($_); |
222 $tag = $response[$key]; |
222 $tag = $response[$key]; |
223 unset($response[$key]); |
223 unset($response[$key]); |
224 $tag['note_id'] = intval($key); |
224 $tag['note_id'] = intval($key); |
225 $tag['mode'] = 'add'; |
225 $tag['mode'] = 'add'; |
226 $tag['initial_hide'] = true; |
226 $tag['initial_hide'] = true; |
227 $tag['auth_delete'] = $perms->get_permissions('snapr_add_tag'); |
227 $tag['auth_delete'] = $perms->get_permissions('snapr_add_tag'); |
228 $response[intval($key)] = $tag; |
228 $response[intval($key)] = $tag; |
229 } |
229 } |
230 $response = array_values($response); |
230 $response = array_values($response); |
231 unset($tag); |
231 unset($tag); |
232 break; |
232 break; |
233 } |
233 } |
234 $encoded = snapr_json_encode($response); |
234 $encoded = snapr_json_encode($response); |
235 header('Content-type: text/plain'); |
235 header('Content-type: text/plain'); |
236 echo $encoded; |
236 echo $encoded; |
237 return true; |
237 return true; |
238 } |
238 } |
239 |
239 |
240 $have_notes = ( empty($row['img_tags']) ) ? false : ( count(snapr_json_decode($row['img_tags'])) > 0 ); |
240 $have_notes = ( empty($row['img_tags']) ) ? false : ( count(snapr_json_decode($row['img_tags'])) > 0 ); |
241 |
241 |
242 $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/canvas.js"></script>'); |
242 $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/canvas.js"></script>'); |
243 $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/tagging.js"></script>'); |
243 $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/tagging.js"></script>'); |
244 |
244 |
245 $template->tpl_strings['PAGE_NAME'] = 'Gallery image: ' . htmlspecialchars($row['img_title']); |
245 $template->tpl_strings['PAGE_NAME'] = 'Gallery image: ' . htmlspecialchars($row['img_title']); |
246 if ( is_object(@$GLOBALS['output']) ) |
246 if ( is_object(@$GLOBALS['output']) ) |
247 { |
247 { |
248 global $output; |
248 global $output; |
249 $output->set_title('Gallery image: ' . $row['img_title']); |
249 $output->set_title('Gallery image: ' . $row['img_title']); |
250 } |
250 } |
251 else if ( method_exists($template, 'assign_vars') ) |
251 else if ( method_exists($template, 'assign_vars') ) |
252 { |
252 { |
253 $template->assign_vars(array( |
253 $template->assign_vars(array( |
254 'PAGE_NAME' => 'Gallery image: ' . htmlspecialchars($row['img_title']) |
254 'PAGE_NAME' => 'Gallery image: ' . htmlspecialchars($row['img_title']) |
255 )); |
255 )); |
256 } |
256 } |
257 $title_spacey = strtolower(htmlspecialchars($row['img_title'])); |
257 $title_spacey = strtolower(htmlspecialchars($row['img_title'])); |
258 |
258 |
259 $template->header(); |
259 $template->header(); |
260 |
260 |
261 $img_id = intval($img_id); |
261 $img_id = intval($img_id); |
262 $bc_folders = gallery_imgid_to_folder($img_id); |
262 $bc_folders = gallery_imgid_to_folder($img_id); |
263 $bc_folders = array_reverse($bc_folders); |
263 $bc_folders = array_reverse($bc_folders); |
264 $bc_url = ''; |
264 $bc_url = ''; |
265 $breadcrumbs = array(); |
265 $breadcrumbs = array(); |
266 $breadcrumbs[] = '<a href="' . makeUrlNS('Special', 'Gallery') . '">Gallery index</a>'; |
266 $breadcrumbs[] = '<a href="' . makeUrlNS('Special', 'Gallery') . '">Gallery index</a>'; |
267 |
267 |
268 foreach ( $bc_folders as $folder ) |
268 foreach ( $bc_folders as $folder ) |
269 { |
269 { |
270 $bc_url .= '/' . dirtify_page_id($folder); |
270 $bc_url .= '/' . dirtify_page_id($folder); |
271 $breadcrumbs[] = '<a href="' . makeUrlNS('Special', 'Gallery' . $bc_url, false, true) . '">' . htmlspecialchars($folder) . '</a>'; |
271 $breadcrumbs[] = '<a href="' . makeUrlNS('Special', 'Gallery' . $bc_url, false, true) . '">' . htmlspecialchars($folder) . '</a>'; |
272 } |
272 } |
273 |
273 |
274 $breadcrumbs[] = htmlspecialchars($row['img_title']); |
274 $breadcrumbs[] = htmlspecialchars($row['img_title']); |
275 |
275 |
276 // From here, this breadcrumb stuff is a piece of... sourdough French bread :-) *smacks lips* |
276 // From here, this breadcrumb stuff is a piece of... sourdough French bread :-) *smacks lips* |
277 echo '<div class="breadcrumbs" style="padding: 4px; margin-bottom: 7px;">'; |
277 echo '<div class="breadcrumbs" style="padding: 4px; margin-bottom: 7px;">'; |
278 // The actual breadcrumbs |
278 // The actual breadcrumbs |
279 echo '<small>' . implode(' » ', $breadcrumbs) . '</small>'; |
279 echo '<small>' . implode(' » ', $breadcrumbs) . '</small>'; |
280 echo '</div>'; |
280 echo '</div>'; |
281 |
281 |
282 echo '<div style="text-align: center; margin: 10px auto; border: 1px solid #DDDDDD; padding: 7px 10px; display: table;">'; |
282 echo '<div style="text-align: center; margin: 10px auto; border: 1px solid #DDDDDD; padding: 7px 10px; display: table;">'; |
283 $img_url = makeUrlNS('Special', 'GalleryFetcher/preview/' . $img_id); |
283 $img_url = makeUrlNS('Special', 'GalleryFetcher/preview/' . $img_id); |
284 $img_href = makeUrlNS('Special', 'GalleryFetcher/full/' . $img_id); |
284 $img_href = makeUrlNS('Special', 'GalleryFetcher/full/' . $img_id); |
285 |
285 |
286 // The actual image |
286 // The actual image |
287 $iehack = ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ? ' style="width: 1px;"' : ''; |
287 $iehack = ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ? ' style="width: 1px;"' : ''; |
288 echo '<div snapr:imgid="' . $img_id . '"' . $iehack . '><img onload="snapr_lock_onload_img = false; snapr_tags_onload_real();" alt="Image preview (640px max width)" src="' . $img_url . '" id="snapr_preview_img" style="border-width: 0; margin-bottom: 5px; display: block;" /></div>'; |
288 echo '<div snapr:imgid="' . $img_id . '"' . $iehack . '><img onload="snapr_lock_onload_img = false; snapr_tags_onload_real();" alt="Image preview (640px max width)" src="' . $img_url . '" id="snapr_preview_img" style="border-width: 0; margin-bottom: 5px; display: block;" /></div>'; |
289 |
289 |
290 echo '<table border="0" width="100%"><tr><td style="text-align: left; width: 24px;">'; |
290 echo '<table border="0" width="100%"><tr><td style="text-align: left; width: 24px;">'; |
291 |
291 |
292 // Prev button |
292 // Prev button |
293 if ( $prev ) |
293 if ( $prev ) |
294 echo '<a href="' . $prev_url . '"><img style="border-width: 0px;" alt="< Previous" src="' . scriptPath . '/plugins/gallery/prev.gif" /></a>'; |
294 echo '<a href="' . $prev_url . '"><img style="border-width: 0px;" alt="< Previous" src="' . scriptPath . '/plugins/gallery/prev.gif" /></a>'; |
295 //echo '</td><td style="text-align: left;">'; |
295 //echo '</td><td style="text-align: left;">'; |
296 // if ( $prev ) |
296 // if ( $prev ) |
297 // echo '<a href="' . $prev_url . '">previous image</a>'; |
297 // echo '<a href="' . $prev_url . '">previous image</a>'; |
298 |
298 |
299 echo '</td><td style="text-align: center; letter-spacing: 5px;">'; |
299 echo '</td><td style="text-align: center; letter-spacing: 5px;">'; |
300 |
300 |
301 // Image title |
301 // Image title |
302 echo $title_spacey; |
302 echo $title_spacey; |
303 |
303 |
304 echo '</td><td style="text-align: right; width: 24px;">'; |
304 echo '</td><td style="text-align: right; width: 24px;">'; |
305 |
305 |
306 // Next button |
306 // Next button |
307 if ( $next ) |
307 if ( $next ) |
308 // echo '<a href="' . $next_url . '">next image</a>'; |
308 // echo '<a href="' . $next_url . '">next image</a>'; |
309 //echo '</td><td style="text-align: right;">'; |
309 //echo '</td><td style="text-align: right;">'; |
310 if ( $next ) |
310 if ( $next ) |
311 echo '<a href="' . $next_url . '"><img style="border-width: 0px;" alt="< Previous" src="' . scriptPath . '/plugins/gallery/next.gif" /></a>'; |
311 echo '<a href="' . $next_url . '"><img style="border-width: 0px;" alt="< Previous" src="' . scriptPath . '/plugins/gallery/next.gif" /></a>'; |
312 |
312 |
313 echo '</td></tr>'; |
313 echo '</td></tr>'; |
314 echo '<tr><td colspan="3">' . "image $folder_this of $folder_total" . '</td></tr>'; |
314 echo '<tr><td colspan="3">' . "image $folder_this of $folder_total" . '</td></tr>'; |
315 if ( $perms->get_permissions('gal_full_res') || $have_notes ) |
315 if ( $perms->get_permissions('gal_full_res') || $have_notes ) |
316 { |
316 { |
317 echo '<tr><td colspan="3"><small>'; |
317 echo '<tr><td colspan="3"><small>'; |
318 |
318 |
319 if ( $perms->get_permissions('gal_full_res') ) |
319 if ( $perms->get_permissions('gal_full_res') ) |
320 echo "<a href=\"$img_href\" onclick=\"window.open(this.href, '', 'toolbar=no,address=no,menus=no,status=no,scrollbars=yes'); return false;\">View in original resolution</a>"; |
320 echo "<a href=\"$img_href\" onclick=\"window.open(this.href, '', 'toolbar=no,address=no,menus=no,status=no,scrollbars=yes'); return false;\">View in original resolution</a>"; |
321 |
321 |
322 if ( $perms->get_permissions('gal_full_res') && $have_notes ) |
322 if ( $perms->get_permissions('gal_full_res') && $have_notes ) |
323 echo ' :: '; |
323 echo ' :: '; |
324 |
324 |
325 if ( $have_notes ) |
325 if ( $have_notes ) |
326 echo 'Mouse over photo to view tags'; |
326 echo 'Mouse over photo to view tags'; |
327 |
327 |
328 echo '</small></td></tr>'; |
328 echo '</small></td></tr>'; |
329 } |
329 } |
330 echo '</table>'; |
330 echo '</table>'; |
331 echo '</div>'; |
331 echo '</div>'; |
332 |
332 |
333 if ( $session->user_level >= USER_LEVEL_ADMIN || $perms->get_permissions('snapr_add_tag') ) |
333 if ( $session->user_level >= USER_LEVEL_ADMIN || $perms->get_permissions('snapr_add_tag') ) |
334 { |
334 { |
335 echo '<div style="float: right;">'; |
335 echo '<div style="float: right;">'; |
336 if ( $session->user_level >= USER_LEVEL_ADMIN ) |
336 if ( $session->user_level >= USER_LEVEL_ADMIN ) |
337 echo '[ <a href="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $img_id, true) . '">edit image</a> ] '; |
337 echo '[ <a href="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $img_id, true) . '">edit image</a> ] '; |
338 if ( $perms->get_permissions('snapr_add_tag') ) |
338 if ( $perms->get_permissions('snapr_add_tag') ) |
339 echo '[ <a href="#" onclick="snapr_add_tag(); return false;"><img alt=" " src="' . scriptPath . '/plugins/gallery/tag-image.gif" style="border-width: 0;" /> add a tag</a> ] '; |
339 echo '[ <a href="#" onclick="snapr_add_tag(); return false;"><img alt=" " src="' . scriptPath . '/plugins/gallery/tag-image.gif" style="border-width: 0;" /> add a tag</a> ] '; |
340 echo '</div>'; |
340 echo '</div>'; |
341 } |
341 } |
342 |
342 |
343 if ( !empty($row['img_desc']) ) |
343 if ( !empty($row['img_desc']) ) |
344 { |
344 { |
345 echo '<h2>Image description</h2>'; |
345 echo '<h2>Image description</h2>'; |
346 |
346 |
347 $desc = RenderMan::render($row['img_desc']); |
347 $desc = RenderMan::render($row['img_desc']); |
348 echo $desc; |
348 echo $desc; |
349 } |
349 } |
350 |
350 |
351 echo '<div class="tblholder" style="font-size: smaller; display: table;' . ( empty($row['img_desc']) ? '' : 'margin: 0 auto;' ) . '"> |
351 echo '<div class="tblholder" style="font-size: smaller; display: table;' . ( empty($row['img_desc']) ? '' : 'margin: 0 auto;' ) . '"> |
352 <table border="0" cellspacing="1" cellpadding="3">'; |
352 <table border="0" cellspacing="1" cellpadding="3">'; |
353 |
353 |
354 // By the time I got to this point, it was 1:32AM (I was on vacation) and my 5-hour playlist on my iPod had been around about 3 times today. |
354 // By the time I got to this point, it was 1:32AM (I was on vacation) and my 5-hour playlist on my iPod had been around about 3 times today. |
355 // So I'm glad this is like the last thing on the list tonight. |
355 // So I'm glad this is like the last thing on the list tonight. |
356 |
356 |
357 $ext = get_file_extension($row['img_filename']); |
357 $ext = get_file_extension($row['img_filename']); |
358 $ext = strtoupper($ext); |
358 $ext = strtoupper($ext); |
359 |
359 |
360 echo '<tr><th colspan="2">Image details</th></tr>'; |
360 $user_link = ''; |
361 echo '<tr><td class="row2">Uploaded:</td><td class="row1">' . date('F d, Y h:i a', $row['img_time_upload']) . '</td></tr>'; |
361 |
362 echo '<tr><td class="row2">Last modified:</td><td class="row1">' . date('F d, Y h:i a', $row['img_time_mod']) . '</td></tr>'; |
362 echo '<tr><th colspan="2">Image details</th></tr>'; |
363 echo '<tr><td class="row2">Original format:</td><td class="row1">' . $ext . '</td></tr>'; |
363 echo '<tr><td class="row2">Uploaded:</td><td class="row1">' . date('F d, Y h:i a', $row['img_time_upload']) . '</td></tr>'; |
364 echo '<tr><td class="row3" colspan="2" style="text-align: center;"><a href="' . makeUrlNS('Special', 'GalleryFetcher/full/' . $img_id, 'download', 'true') . '">Download image</a></td></tr>'; |
364 echo '<tr><td class="row2">Last modified:</td><td class="row1">' . date('F d, Y h:i a', $row['img_time_mod']) . '</td></tr>'; |
365 |
365 echo '<tr><td class="row2">Original format:</td><td class="row1">' . $ext . '</td></tr>'; |
366 echo '</table></div>'; |
366 echo '<tr><td class="row2">Author:</td><td class="row1">' . $user_link . '</td></tr>'; |
367 |
367 echo '<tr><td class="row3" colspan="2" style="text-align: center;"><a href="' . makeUrlNS('Special', 'GalleryFetcher/full/' . $img_id, 'download', 'true') . '">Download image</a></td></tr>'; |
368 $template->footer(); |
368 |
|
369 echo '</table></div>'; |
|
370 |
|
371 $template->footer(); |
369 } |
372 } |
370 |
373 |
371 /** |
374 /** |
372 * This is for Enano 1.1.6 and up. |
375 * This is for Enano 1.1.6 and up. |
373 */ |
376 */ |
374 |
377 |
375 class Namespace_Gallery extends Namespace_Default |
378 class Namespace_Gallery extends Namespace_Default |
376 { |
379 { |
377 public $image_info; |
380 public $image_info; |
378 |
381 |
379 function __construct($page_id, $namespace, $revision_id = 0) |
382 function __construct($page_id, $namespace, $revision_id = 0) |
380 { |
383 { |
381 global $db, $session, $paths, $template, $plugins; // Common objects |
384 global $db, $session, $paths, $template, $plugins; // Common objects |
382 |
385 |
383 $this->page_id = sanitize_page_id($page_id); |
386 $this->page_id = sanitize_page_id($page_id); |
384 $this->namespace = $namespace; |
387 $this->namespace = $namespace; |
385 $this->revision_id = intval($revision_id); |
388 $this->revision_id = intval($revision_id); |
386 |
389 |
387 // only do this if calling from the (very heavily feature filled) abstract |
390 // only do this if calling from the (very heavily feature filled) abstract |
388 // this will still be called if you're using your own handler but not replacing the constructor |
391 // this will still be called if you're using your own handler but not replacing the constructor |
389 if ( __CLASS__ == 'Namespace_Gallery' ) |
392 if ( __CLASS__ == 'Namespace_Gallery' ) |
390 { |
393 { |
391 $this->exists = false; |
394 $this->exists = false; |
392 // NOTE! These should already be WELL sanitized before we reach this stage. |
395 // NOTE! These should already be WELL sanitized before we reach this stage. |
393 |
396 |
394 if ( preg_match('/^[0-9]+$/', $this->page_id) ) |
397 if ( preg_match('/^[0-9]+$/', $this->page_id) ) |
395 { |
398 { |
396 $img_id = intval($this->page_id); |
399 $img_id = intval($this->page_id); |
397 if ( !$img_id ) |
400 if ( !$img_id ) |
398 { |
401 { |
399 $this->exists = false; |
402 $this->exists = false; |
400 return; |
403 return; |
401 } |
404 } |
402 $q = $db->sql_query('SELECT img_id, img_title, img_desc, print_sizes, img_time_upload, img_time_mod, img_filename, folder_parent, img_tags FROM '.table_prefix.'gallery WHERE img_id=' . $img_id . ';'); |
405 $q = $db->sql_query('SELECT img_id, img_title, img_desc, print_sizes, img_time_upload, img_time_mod, img_filename, folder_parent, img_tags FROM '.table_prefix.'gallery WHERE img_id=' . $img_id . ';'); |
403 if ( !$q ) |
406 if ( !$q ) |
404 $db->_die(); |
407 $db->_die(); |
405 } |
408 } |
406 else |
409 else |
407 { |
410 { |
408 // Ech... he sent us a string... parse it and see what we get |
411 // Ech... he sent us a string... parse it and see what we get |
409 if ( strstr($this->page_id, '/') ) |
412 if ( strstr($this->page_id, '/') ) |
410 { |
413 { |
411 $folders = explode('/', $this->page_id); |
414 $folders = explode('/', $this->page_id); |
412 } |
415 } |
413 else |
416 else |
414 { |
417 { |
415 $folders = array($this->page_id); |
418 $folders = array($this->page_id); |
416 } |
419 } |
417 foreach ( $folders as $i => $_crap ) |
420 foreach ( $folders as $i => $_crap ) |
418 { |
421 { |
419 $folder =& $folders[$i]; |
422 $folder =& $folders[$i]; |
420 $folder = dirtify_page_id($folder); |
423 $folder = dirtify_page_id($folder); |
421 $folder = str_replace('_', ' ', $folder); |
424 $folder = str_replace('_', ' ', $folder); |
422 } |
425 } |
423 unset($folder); |
426 unset($folder); |
424 |
427 |
425 $folders = array_reverse($folders); |
428 $folders = array_reverse($folders); |
426 // This is one of the best MySQL tricks on the market. We're going to reverse-travel a folder path using LEFT JOIN and the incredible power of metacoded SQL |
429 // This is one of the best MySQL tricks on the market. We're going to reverse-travel a folder path using LEFT JOIN and the incredible power of metacoded SQL |
427 $sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.img_filename, g0.folder_parent, g0.img_tags FROM '.table_prefix.'gallery AS g0'; |
430 $sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.img_filename, g0.folder_parent, g0.img_tags FROM '.table_prefix.'gallery AS g0'; |
428 $where = "\n " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\''; |
431 $where = "\n " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\''; |
429 foreach ( $folders as $i => $folder ) |
432 foreach ( $folders as $i => $folder ) |
430 { |
433 { |
431 if ( $i == 0 ) |
434 if ( $i == 0 ) |
432 continue; |
435 continue; |
433 $i_dec = $i - 1; |
436 $i_dec = $i - 1; |
434 $folder = $db->escape($folder); |
437 $folder = $db->escape($folder); |
435 $sql .= "\n LEFT JOIN ".table_prefix."gallery AS g{$i}\n ON ( g{$i}.img_id=g{$i_dec}.folder_parent AND g{$i}.img_title='$folder' )"; |
438 $sql .= "\n LEFT JOIN ".table_prefix."gallery AS g{$i}\n ON ( g{$i}.img_id=g{$i_dec}.folder_parent AND g{$i}.img_title='$folder' )"; |
436 $where .= "\n ".'AND g'.$i.'.img_id IS NOT NULL'; |
439 $where .= "\n ".'AND g'.$i.'.img_id IS NOT NULL'; |
437 } |
440 } |
438 $where .= "\n AND g{$i}.folder_parent IS NULL"; |
441 $where .= "\n AND g{$i}.folder_parent IS NULL"; |
439 $sql .= $where . ';'; |
442 $sql .= $where . ';'; |
440 |
443 |
441 if ( !$db->sql_query($sql) ) |
444 if ( !$db->sql_query($sql) ) |
442 { |
445 { |
443 $db->_die('The image metadata could not be loaded.'); |
446 $db->_die('The image metadata could not be loaded.'); |
444 } |
447 } |
445 |
448 |
446 // Now that the folder data is no longer needed, we can fool around with it a little |
449 // Now that the folder data is no longer needed, we can fool around with it a little |
447 $folders = $this->page_id; |
450 $folders = $this->page_id; |
448 if ( !strstr($folders, '/') ) |
451 if ( !strstr($folders, '/') ) |
449 { |
452 { |
450 $hier = '/'; |
453 $hier = '/'; |
451 } |
454 } |
452 else |
455 else |
453 { |
456 { |
454 $hier = preg_replace('/\/([^\/]+)$/', '/', $folders); |
457 $hier = preg_replace('/\/([^\/]+)$/', '/', $folders); |
455 $hier = sanitize_page_id($hier); |
458 $hier = sanitize_page_id($hier); |
456 } |
459 } |
457 |
460 |
458 } |
461 } |
459 if ( $db->numrows() < 1 ) |
462 if ( $db->numrows() < 1 ) |
460 { |
463 { |
461 // Image not found |
464 // Image not found |
462 $this->exists = false; |
465 $this->exists = false; |
463 $this->cdata = array( |
466 $this->cdata = array( |
464 'urlname' => $this->page_id, |
467 'urlname' => $this->page_id, |
465 'namespace' => $this->namespace, |
468 'namespace' => $this->namespace, |
466 'name' => 'Image not found', |
469 'name' => 'Image not found', |
467 'special' => 0, |
470 'special' => 0, |
468 'visible' => 0, |
471 'visible' => 0, |
469 'comments_on' => 0, |
472 'comments_on' => 0, |
470 'protected' => 0, |
473 'protected' => 0, |
471 'delvotes' => 0, |
474 'delvotes' => 0, |
472 'delvote_ips' => '', |
475 'delvote_ips' => '', |
473 'wiki_mode' => 0, |
476 'wiki_mode' => 0, |
474 'page_exists' => false, |
477 'page_exists' => false, |
475 'page_format' => getConfig('default_page_format', 'wikitext') |
478 'page_format' => getConfig('default_page_format', 'wikitext') |
476 ); |
479 ); |
477 } |
480 } |
478 else |
481 else |
479 { |
482 { |
480 $this->image_info = $db->fetchrow(); |
483 $this->image_info = $db->fetchrow(); |
481 $this->exists = true; |
484 $this->exists = true; |
482 $this->cdata = array( |
485 $this->cdata = array( |
483 'urlname' => $this->page_id, |
486 'urlname' => $this->page_id, |
484 'namespace' => $this->namespace, |
487 'namespace' => $this->namespace, |
485 'name' => $this->image_info['img_title'], |
488 'name' => $this->image_info['img_title'], |
486 'special' => 1, |
489 'special' => 1, |
487 'visible' => 1, |
490 'visible' => 1, |
488 'comments_on' => 1, |
491 'comments_on' => 1, |
489 'protected' => 0, |
492 'protected' => 0, |
490 'delvotes' => 0, |
493 'delvotes' => 0, |
491 'delvote_ips' => '', |
494 'delvote_ips' => '', |
492 'wiki_mode' => 0, |
495 'wiki_mode' => 0, |
493 'page_exists' => true, |
496 'page_exists' => true, |
494 'page_format' => getConfig('default_page_format', 'wikitext') |
497 'page_format' => getConfig('default_page_format', 'wikitext') |
495 ); |
498 ); |
496 } |
499 } |
497 $this->title =& $this->cdata['name']; |
500 $this->title =& $this->cdata['name']; |
498 $this->cdata = Namespace_Default::bake_cdata($this->cdata); |
501 $this->cdata = Namespace_Default::bake_cdata($this->cdata); |
499 |
502 |
500 $db->free_result(); |
503 $db->free_result(); |
501 } |
504 } |
502 } |
505 } |
503 |
506 |
504 function send() |
507 function send() |
505 { |
508 { |
506 if ( $this->exists ) |
509 if ( $this->exists ) |
507 { |
510 { |
508 gallery_namespace_handler($this); |
511 gallery_namespace_handler($this); |
509 } |
512 } |
510 else |
513 else |
511 { |
514 { |
512 global $output; |
515 global $output; |
513 $output->header(); |
516 $output->header(); |
514 $this->error_404(); |
517 $this->error_404(); |
515 $output->footer(); |
518 $output->footer(); |
516 } |
519 } |
517 } |
520 } |
518 |
521 |
519 function error_404() |
522 function error_404() |
520 { |
523 { |
521 echo '<h3>There is no image in the gallery with this ID.</h3>'; |
524 echo '<h3>There is no image in the gallery with this ID.</h3>'; |
522 echo '<p>You have requested an image that couldn\'t be looked up. Please check the URL and try again, or visit the <a href="' . makeUrlNS('Special', 'Gallery') . '">Gallery index</a>.</p>'; |
525 echo '<p>You have requested an image that couldn\'t be looked up. Please check the URL and try again, or visit the <a href="' . makeUrlNS('Special', 'Gallery') . '">Gallery index</a>.</p>'; |
523 } |
526 } |
524 } |
527 } |
525 |
528 |
526 ?> |
529 ?> |