plugins/gallery/viewimage.php
changeset 18 c1c398349651
parent 11 3c4304fae21e
child 19 08bf8aa2f0ab
equal deleted inserted replaced
15:ac7d3dedcc44 18:c1c398349651
    34   if ( preg_match('/^[0-9]+$/', $page->page_id) )
    34   if ( preg_match('/^[0-9]+$/', $page->page_id) )
    35   {
    35   {
    36     $img_id = intval($page->page_id);
    36     $img_id = intval($page->page_id);
    37     if ( !$img_id )
    37     if ( !$img_id )
    38       return false;
    38       return false;
    39     $q = $db->sql_query('SELECT img_id, img_title, img_desc, print_sizes, img_time_upload, img_time_mod, img_filename, folder_parent FROM '.table_prefix.'gallery WHERE img_id=' . $img_id . ';');
    39     $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 . ';');
    40     if ( !$q )
    40     if ( !$q )
    41       $db->_die();
    41       $db->_die();
    42   }
    42   }
    43   else
    43   else
    44   {
    44   {
    59     }
    59     }
    60     unset($folder);
    60     unset($folder);
    61     
    61     
    62     $folders = array_reverse($folders);
    62     $folders = array_reverse($folders);
    63     // 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
    63     // 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
    64     $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 FROM '.table_prefix.'gallery AS g0';
    64     $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';
    65     $where = "\n  " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\'';
    65     $where = "\n  " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\'';
    66     foreach ( $folders as $i => $folder )
    66     foreach ( $folders as $i => $folder )
    67     {
    67     {
    68       if ( $i == 0 )
    68       if ( $i == 0 )
    69         continue;
    69         continue;
   164     $prev_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $prev_sanitized ) : makeUrlNS('Gallery', $prev);
   164     $prev_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $prev_sanitized ) : makeUrlNS('Gallery', $prev);
   165   }
   165   }
   166   
   166   
   167   $db->free_result();
   167   $db->free_result();
   168   
   168   
       
   169   $perms = $session->fetch_page_acl(strval($img_id), 'Gallery');
       
   170   
       
   171   if ( isset($_POST['ajax']) && @$_POST['ajax'] === 'true' && isset($_POST['act']) )
       
   172   {
       
   173     $mode =& $_POST['act'];
       
   174     $response = array();
       
   175     switch($mode)
       
   176     {
       
   177       case 'add_tag':
       
   178         if ( !$perms->get_permissions('snapr_add_tag') )
       
   179         {
       
   180           die(snapr_json_encode(array(
       
   181               'mode' => 'error',
       
   182               'error' => 'You don\'t have permission to add tags.'
       
   183             )));
       
   184         }
       
   185         if ( empty($row['img_tags']) )
       
   186         {
       
   187           $row['img_tags'] = '[]';
       
   188         }
       
   189         $row['img_tags'] = snapr_json_decode($row['img_tags']);
       
   190         
       
   191         $canvas_data = snapr_json_decode($_POST['canvas_params']);
       
   192         $tag_data = array(
       
   193             'tag' => sanitize_html($_POST['tag']),
       
   194             'canvas_data' => $canvas_data
       
   195           );
       
   196         $row['img_tags'][] = $tag_data;
       
   197         $tag_data['note_id'] = count($row['img_tags']) - 1;
       
   198         $tag_data['mode'] = 'add';
       
   199         $tag_data['initial_hide'] = false;
       
   200         $tag_data['auth_delete'] = true;
       
   201         
       
   202         $row['img_tags'] = snapr_json_encode($row['img_tags']);
       
   203         $row['img_tags'] = $db->escape($row['img_tags']);
       
   204         $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;");
       
   205         if ( !$q )
       
   206           $db->die_json();
       
   207         
       
   208         $response[] = $tag_data;
       
   209         break;
       
   210       case 'del_tag':
       
   211         if ( !$perms->get_permissions('snapr_add_tag') )
       
   212         {
       
   213           die(snapr_json_encode(array(
       
   214               'mode' => 'error',
       
   215               'error' => 'You don\'t have permission to add tags.'
       
   216             )));
       
   217         }
       
   218         if ( empty($row['img_tags']) )
       
   219         {
       
   220           $row['img_tags'] = '[]';
       
   221         }
       
   222         $row['img_tags'] = snapr_json_decode($row['img_tags']);
       
   223         
       
   224         $tag_id = intval(@$_POST['tag_id']);
       
   225         if ( isset($row['img_tags'][$tag_id]) )
       
   226           unset($row['img_tags'][$tag_id]);
       
   227         
       
   228         $row['img_tags'] = snapr_json_encode($row['img_tags']);
       
   229         $row['img_tags'] = $db->escape($row['img_tags']);
       
   230         $q = $db->sql_query('UPDATE ' . table_prefix . "gallery SET img_tags = '{$row['img_tags']}' WHERE img_id = $img_id;");
       
   231         if ( !$q )
       
   232           $db->die_json();
       
   233         
       
   234         $response[] = array(
       
   235             'mode' => 'remove',
       
   236             'note_id' => $tag_id
       
   237           );
       
   238         break;
       
   239       case 'get_tags':
       
   240         $response = snapr_json_decode($row['img_tags']);
       
   241         foreach ( $response as $key => $_ )
       
   242         {
       
   243           unset($_);
       
   244           $tag =& $response[$key];
       
   245           $tag['note_id'] = $key;
       
   246           $tag['mode'] = 'add';
       
   247           $tag['initial_hide'] = true;
       
   248           $tag['auth_delete'] = $perms->get_permissions('snapr_add_tag');
       
   249         }
       
   250         unset($tag);
       
   251         break;
       
   252     }
       
   253     echo snapr_json_encode($response);
       
   254     return true;
       
   255   }
       
   256   
       
   257   $have_notes = ( empty($row['img_tags']) ) ? false : ( count(snapr_json_decode($row['img_tags'])) > 0 );
       
   258   
       
   259   $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/canvas.js"></script>');
       
   260   $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/tagging.js"></script>');
       
   261   
   169   $template->tpl_strings['PAGE_NAME'] = 'Gallery image: ' . htmlspecialchars($row['img_title']);
   262   $template->tpl_strings['PAGE_NAME'] = 'Gallery image: ' . htmlspecialchars($row['img_title']);
   170   $title_spacey = strtolower(htmlspecialchars($row['img_title']));
   263   $title_spacey = strtolower(htmlspecialchars($row['img_title']));
   171   
       
   172   $perms = $session->fetch_page_acl(strval($img_id), 'Gallery');
       
   173   
   264   
   174   $template->header();
   265   $template->header();
   175   
   266   
   176   $img_id = intval($img_id);
   267   $img_id = intval($img_id);
   177   $bc_folders = gallery_imgid_to_folder($img_id);
   268   $bc_folders = gallery_imgid_to_folder($img_id);
   196   
   287   
   197   echo '<div style="text-align: center; margin: 10px auto; border: 1px solid #DDDDDD; padding: 7px 10px; display: table;">';
   288   echo '<div style="text-align: center; margin: 10px auto; border: 1px solid #DDDDDD; padding: 7px 10px; display: table;">';
   198   $img_url  = makeUrlNS('Special', 'GalleryFetcher/preview/' . $img_id);
   289   $img_url  = makeUrlNS('Special', 'GalleryFetcher/preview/' . $img_id);
   199   $img_href = makeUrlNS('Special', 'GalleryFetcher/full/' . $img_id);
   290   $img_href = makeUrlNS('Special', 'GalleryFetcher/full/' . $img_id);
   200   
   291   
   201   if ( $perms->get_permissions('gal_full_res') )
   292   echo '<div snapr:imgid="' . $img_id . '"><img alt="Image preview (640px max width)" src="' . $img_url . '" id="snapr_preview_img" style="border-width: 0; margin-bottom: 5px; display: block;" /></div>';
   202   {
       
   203     echo '<a href="' . $img_href . '" title="Click to view this image at full resolution, right click to save image" onclick="window.open(this.href, \'\', \'toolbar=no,address=no,menus=no,status=no,scrollbars=yes\'); return false;">';
       
   204   }
       
   205   
       
   206   echo '<img alt="Image preview (640px max width)" src="' . $img_url . '" style="border-width: 0; margin-bottom: 5px; display: block;" />';
       
   207   
       
   208   if ( $perms->get_permissions('gal_full_res') )
       
   209   {
       
   210     echo '</a>';
       
   211   }
       
   212   
   293   
   213   echo '<table border="0" width="100%"><tr><td style="text-align: left; width: 24px;">';
   294   echo '<table border="0" width="100%"><tr><td style="text-align: left; width: 24px;">';
   214   
   295   
   215   // Prev button
   296   // Prev button
   216   if ( $prev )
   297   if ( $prev )
   233   if ( $next )
   314   if ( $next )
   234     echo '<a href="' . $next_url . '"><img style="border-width: 0px;" alt="&lt; Previous" src="' . scriptPath . '/plugins/gallery/next.gif" /></a>';
   315     echo '<a href="' . $next_url . '"><img style="border-width: 0px;" alt="&lt; Previous" src="' . scriptPath . '/plugins/gallery/next.gif" /></a>';
   235   
   316   
   236   echo '</td></tr>';
   317   echo '</td></tr>';
   237   echo '<tr><td colspan="3">' . "image $folder_this of $folder_total" . '</td></tr>';
   318   echo '<tr><td colspan="3">' . "image $folder_this of $folder_total" . '</td></tr>';
       
   319   if ( $perms->get_permissions('gal_full_res') || $have_notes )
       
   320   {
       
   321     echo '<tr><td colspan="3"><small>';
       
   322     
       
   323     if ( $perms->get_permissions('gal_full_res') )
       
   324       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>";
       
   325     
       
   326     if ( $perms->get_permissions('gal_full_res') && $have_notes )
       
   327       echo ' :: ';
       
   328     
       
   329     if ( $have_notes )
       
   330       echo 'Mouse over photo to view tags';
       
   331     
       
   332     echo '</small></td></tr>';
       
   333   }
   238   echo '</table>';
   334   echo '</table>';
   239   echo '</div>';
   335   echo '</div>';
   240   
   336   
   241   if ( $session->user_level >= USER_LEVEL_ADMIN )
   337   if ( $session->user_level >= USER_LEVEL_ADMIN || $perms->get_permissions('snapr_add_tag') )
   242   {
   338   {
   243     echo '<div style="float: right;">[ <a href="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $img_id, true) . '">edit image</a> ]</div>';
   339     echo '<div style="float: right;">';
       
   340     if ( $session->user_level >= USER_LEVEL_ADMIN )
       
   341       echo '[ <a href="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $img_id, true) . '">edit image</a> ] ';
       
   342     if ( $perms->get_permissions('snapr_add_tag') )
       
   343       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> ] ';
       
   344     echo '</div>';
   244   }
   345   }
   245   
   346   
   246   if ( !empty($row['img_desc']) )
   347   if ( !empty($row['img_desc']) )
   247   {
   348   {
   248     echo '<h2>Image description</h2>';
   349     echo '<h2>Image description</h2>';