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