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