234 $response[] = array( |
234 $response[] = array( |
235 'mode' => 'remove', |
235 'mode' => 'remove', |
236 'note_id' => $tag_id |
236 'note_id' => $tag_id |
237 ); |
237 ); |
238 break; |
238 break; |
|
239 case 'edit_tag': |
|
240 if ( !$perms->get_permissions('snapr_add_tag') ) |
|
241 { |
|
242 die(snapr_json_encode(array( |
|
243 'mode' => 'error', |
|
244 'error' => 'You don\'t have permission to edit tags.' |
|
245 ))); |
|
246 } |
|
247 if ( empty($row['img_tags']) ) |
|
248 { |
|
249 $row['img_tags'] = '[]'; |
|
250 } |
|
251 $row['img_tags'] = snapr_json_decode($row['img_tags']); |
|
252 |
|
253 $tag_id = intval(@$_POST['tag_id']); |
|
254 if ( isset($row['img_tags'][$tag_id]) ) |
|
255 { |
|
256 $row['img_tags'][$tag_id]['tag'] = sanitize_html($_POST['tag']); |
|
257 // copy it |
|
258 $tag_return = $row['img_tags'][$tag_id]; |
|
259 unset($tag); |
|
260 } |
|
261 else |
|
262 { |
|
263 die(snapr_json_encode(array( |
|
264 'mode' => 'error', |
|
265 'error' => 'That tag doesn\'t exist.' |
|
266 ))); |
|
267 } |
|
268 |
|
269 $row['img_tags'] = snapr_json_encode($row['img_tags']); |
|
270 $row['img_tags'] = $db->escape($row['img_tags']); |
|
271 $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;"); |
|
272 if ( !$q ) |
|
273 $db->die_json(); |
|
274 |
|
275 $tag_return['mode'] = 'add'; |
|
276 $tag_return['canvas_data'] = snapr_json_decode($_POST['canvas_params']); |
|
277 $tag_return['auth_delete'] = $perms->get_permissions('snapr_add_tag'); |
|
278 $tag_return['initial_hide'] = false; |
|
279 $tag_return['note_id'] = $tag_id; |
|
280 $response = array($tag_return); |
|
281 |
|
282 break; |
239 case 'get_tags': |
283 case 'get_tags': |
240 $response = snapr_json_decode($row['img_tags']); |
284 $response = snapr_json_decode($row['img_tags']); |
241 foreach ( $response as $key => $_ ) |
285 foreach ( $response as $key => $_ ) |
242 { |
286 { |
243 unset($_); |
287 unset($_); |
244 $tag = $response[$key]; |
288 $tag = $response[$key]; |
245 unset($response[$key]); |
289 unset($response[$key]); |
246 $tag['note_id'] = $key; |
290 $tag['note_id'] = intval($key); |
247 $tag['mode'] = 'add'; |
291 $tag['mode'] = 'add'; |
248 $tag['initial_hide'] = true; |
292 $tag['initial_hide'] = true; |
249 $tag['auth_delete'] = $perms->get_permissions('snapr_add_tag'); |
293 $tag['auth_delete'] = $perms->get_permissions('snapr_add_tag'); |
250 $response[intval($key)] = $tag; |
294 $response[intval($key)] = $tag; |
251 } |
295 } |
|
296 $response = array_values($response); |
252 unset($tag); |
297 unset($tag); |
253 break; |
298 break; |
254 } |
299 } |
255 echo snapr_json_encode($response); |
300 $encoded = snapr_json_encode($response); |
|
301 header('Content-type: text/plain'); |
|
302 echo $encoded; |
256 return true; |
303 return true; |
257 } |
304 } |
258 |
305 |
259 $have_notes = ( empty($row['img_tags']) ) ? false : ( count(snapr_json_decode($row['img_tags'])) > 0 ); |
306 $have_notes = ( empty($row['img_tags']) ) ? false : ( count(snapr_json_decode($row['img_tags'])) > 0 ); |
260 |
307 |