Changeset 12855


Ignore:
Timestamp:
Jan 5, 2012, 11:06:21 PM (12 years ago)
Author:
rvelices
Message:

feature 2548 multisize - improved picture.php display (original...) + code cleanup

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/action.php

    r8728 r12855  
    6161    or !is_numeric($_GET['id'])
    6262    or !isset($_GET['part'])
    63     or !in_array($_GET['part'], array('t','e','i','h') ) )
     63    or !in_array($_GET['part'], array('e','r') ) )
    6464{
    6565  do_error(400, 'Invalid request - id/part');
     
    103103switch ($_GET['part'])
    104104{
    105   case 't':
    106     $file = get_thumbnail_path($element_info);
    107     break;
    108105  case 'e':
    109     $file = get_element_path($element_info);
    110     break;
    111   case 'i':
    112     $file = get_image_path($element_info);
    113     break;
    114   case 'h':
    115106    if ( $user['enabled_high']!='true' )
    116107    {
    117108      do_error(401, 'Access denied h');
    118109    }
    119     $file = get_high_path($element_info);
     110    $file = get_element_path($element_info);
     111    break;
     112  case 'r':
     113    $file = original_to_representative( get_element_path($element_info), $element_info['representative_ext'] );
    120114    break;
    121115}
     
    176170$http_headers[] = 'Content-Type: '.$ctype;
    177171
    178 if (!isset($_GET['view']))
     172if (isset($_GET['download']))
    179173{
    180174  $http_headers[] = 'Content-Disposition: attachment; filename="'.$element_info['file'].'";';
  • trunk/admin/include/functions.php

    r12820 r12855  
    201201    $files[] = get_element_path($row);
    202202
    203     if (!empty($row['tn_ext']))
    204     {
    205       $files[] = get_thumbnail_path($row);
    206     }
    207    
    208     if (!empty($row['has_high']) and get_boolean($row['has_high']))
    209     {
    210       $files[] = get_high_path($row);
    211     }
    212    
     203   
    213204    if (!empty($row['representative_ext']))
    214205    {
    215206      $pi = pathinfo($row['path']);
    216207      $file_wo_ext = get_filename_wo_extension($pi['basename']);
    217       $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$row['representative_ext'];
     208      $files[] = original_to_representative( $files[0], $row['representative_ext']);
    218209    }
    219210
  • trunk/admin/picture_modify.php

    r12831 r12855  
    304304  );
    305305
    306 if ($row['has_high'] == 'true')
    307 {
    308   $template->assign(array(
    309     'HIGH_FILESIZE' => isset($row['high_filesize']) ? $row['high_filesize'].' KB' : l10n('unknown'),
    310     'HIGH_DIMENSIONS' => isset($row['high_width']) ? $row['high_width'].' * '.$row['high_height'] : l10n('unknown'),
    311     ));
    312 }
    313 
    314306// image level options
    315307$selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level'];
  • trunk/admin/themes/default/template/picture_modify.tpl

    r12693 r12855  
    6767      </tr>
    6868
    69 {if isset($HIGH_FILESIZE) }
    70       <tr>
    71         <td><strong>{'High dimensions'|@translate}</strong></td>
    72         <td>{$HIGH_DIMENSIONS}</td>
    73       </tr>
    74      
    75       <tr>
    76         <td><strong>{'High filesize'|@translate}</strong></td>
    77         <td>{$HIGH_FILESIZE}</td>
    78       </tr>
    79 {/if}
    80 
    8169      <tr>
    8270        <td><strong>{'Storage album'|@translate}</strong></td>
  • trunk/include/derivative.inc.php

    r12831 r12855  
    139139  }
    140140
    141   static function get_all($infos)
    142   {
    143     $src_image = new SrcImage($infos);
     141  static function get_all($src_image)
     142  {
    144143    $ret = array();
    145144    foreach (ImageStdParams::get_defined_type_map() as $type => $params)
  • trunk/include/functions.inc.php

    r12831 r12855  
    741741}
    742742
     743/**
     744 * @param element_info array containing element information from db;
     745 * at least 'id', 'path' should be present
     746 */
     747function get_element_path($element_info)
     748{
     749  $path = $element_info['path'];
     750  if ( !url_is_remote($path) )
     751  {
     752    $path = PHPWG_ROOT_PATH.$path;
     753  }
     754  return $path;
     755}
     756
    743757
    744758/* Returns the PATH to the thumbnail to be displayed. If the element does not
  • trunk/include/functions_picture.inc.php

    r9366 r12855  
    2222// +-----------------------------------------------------------------------+
    2323
    24 /**
    25  * @param element_info array containing element information from db;
    26  * at least 'id', 'path' should be present
    27  */
    28 function get_element_path($element_info)
    29 {
    30   $path = get_element_location($element_info);
    31   if ( !url_is_remote($path) )
    32   {
    33     $path = PHPWG_ROOT_PATH.$path;
    34   }
    35   return $path;
    36 }
    37 
    38 /*
    39  * @param element_info array containing element information from db;
    40  * at least 'id', 'path' should be present
    41  */
    42 function get_element_url($element_info)
    43 {
    44   $url = get_element_location($element_info);
    45   if ( !url_is_remote($url) )
    46   {
    47     $url = embellish_url(get_root_url().$url);
    48   }
    49   // plugins want another url ?
    50   return trigger_event('get_element_url', $url, $element_info);
    51 }
    52 
    53 /**
    54  * Returns the relative path of the element with regards to to the root
    55  * of PWG (not the current page). This function is not intended to be
    56  * called directly from code.
    57  * @param element_info array containing element information from db;
    58  * at least 'id', 'path' should be present
    59  */
    60 function get_element_location($element_info)
    61 {
    62   // maybe a cached watermark ?
    63   return trigger_event('get_element_location',
    64     $element_info['path'], $element_info);
    65 }
    6624
    6725
     
    8442}
    8543
    86 
    87 /**
    88  * Returns the PATH to the image to be displayed in the picture page. If the
    89  * element is not a picture, then the representative image or the default
    90  * mime image. The path can be used in the php script, but not sent to the
    91  * browser.
    92  * @param element_info array containing element information from db;
    93  * at least 'id', 'path', 'representative_ext' should be present
    94  */
    95 function get_image_path($element_info)
    96 {
    97   global $conf;
    98   $ext = get_extension($element_info['path']);
    99   if (in_array($ext, $conf['picture_ext']))
    100   {
    101     if (isset($element_info['element_path']) )
    102     {
    103       return $element_info['element_path'];
    104     }
    105     return get_element_path($element_info);
    106   }
    107 
    108   $path = get_image_location($element_info);
    109   if ( !url_is_remote($path) )
    110   {
    111     $path = PHPWG_ROOT_PATH.$path;
    112   }
    113   return $path;
    114 }
    115 
    116 /**
    117  * Returns the URL of the image to be displayed in the picture page. If the
    118  * element is not a picture, then the representative image or the default
    119  * mime image. The URL can't be used in the php script, but can be sent to the
    120  * browser.
    121  * @param element_info array containing element information from db;
    122  * at least 'id', 'path', 'representative_ext' should be present
    123  */
    124 function get_image_url($element_info)
    125 {
    126   global $conf;
    127   $ext = get_extension($element_info['path']);
    128   if (in_array($ext, $conf['picture_ext']))
    129   {
    130     if (isset($element_info['element_url']) )
    131     {
    132       return $element_info['element_url'];
    133     }
    134     return get_element_url($element_info);
    135   }
    136 
    137   $url = get_image_location($element_info);
    138   if ( !url_is_remote($url) )
    139   {
    140     $url = embellish_url(get_root_url().$url);
    141   }
    142   return $url;
    143 }
    144 
    145 /**
    146  * Returns the relative path of the image (element/representative/mimetype)
    147  * with regards to the root of PWG (not the current page). This function
    148  * is not intended to be called directly from code.
    149  * @param element_info array containing element information from db;
    150  * at least 'id', 'path', 'representative_ext' should be present
    151  */
    152 function get_image_location($element_info)
    153 {
    154     if (isset($element_info['representative_ext'])
    155           and $element_info['representative_ext'] != '')
    156     {
    157       $pi = pathinfo($element_info['path']);
    158       $file_wo_ext = get_filename_wo_extension($pi['basename']);
    159       $path =
    160         $pi['dirname'].'/pwg_representative/'
    161         .$file_wo_ext.'.'.$element_info['representative_ext'];
    162     }
    163     else
    164     {
    165       $ext = get_extension($element_info['path']);
    166       $path = get_themeconf('mime_icon_dir');
    167       $path.= strtolower($ext).'.png';
    168       if ( !file_exists(PHPWG_ROOT_PATH.$path)
    169           and !empty($element_info['tn_ext']) )
    170       {
    171         $path = get_thumbnail_location($element_info);
    172       }
    173     }
    174 
    175   // plugins want another location ?
    176   return trigger_event( 'get_image_location', $path, $element_info);
    177 }
    178 
    179 
    18044/*
    18145 * @param element_info array containing element information from db;
     
    22387
    22488
    225 /**
    226  * @param what_part string one of 't' (thumbnail), 'e' (element), 'i' (image),
    227  *   'h' (high resolution image)
    228  * @param element_info array containing element information from db;
    229  * at least 'id', 'path' should be present
    230  */
    231 function get_download_url($what_part, $element_info)
    232 {
    233   $url = get_root_url().'action.php';
    234   $url = add_url_params($url,
    235       array(
    236         'id' => $element_info['id'],
    237         'part' => $what_part,
    238       )
    239     );
    240   return trigger_event( 'get_download_url', $url, $element_info);
    241 }
    24289
    24390/*
  • trunk/include/functions_url.inc.php

    r11831 r12855  
    661661}
    662662
     663
     664/**
     665 * @param id image id
     666 * @param what_part string one of 'e' (element), 'r' (representative)
     667 */
     668function get_action_url($id, $what_part, $download)
     669{
     670  $params = array(
     671        'id' => $id,
     672        'part' => $what_part,
     673      );
     674  if ($download)
     675  {
     676    $params['download'] = null;
     677  }
     678 
     679  return add_url_params(get_root_url().'action.php', $params);
     680}
     681
     682/*
     683 * @param element_info array containing element information from db;
     684 * at least 'id', 'path' should be present
     685 */
     686function get_element_url($element_info)
     687{
     688  $url = $element_info['path'];
     689  if ( !url_is_remote($url) )
     690  {
     691    $url = embellish_url(get_root_url().$url);
     692  }
     693  return $url;
     694}
     695
     696
    663697/**
    664698 * Indicate to build url with full path
  • trunk/include/ws_functions.inc.php

    r12831 r12855  
    148148{
    149149  $ret = array();
     150 
     151  $src_image = new SrcImage($image_row);
     152
    150153  global $user;
    151154  if ($user['enabled_high'])
     
    154157  }
    155158 
    156   $derivatives = DerivativeImage::get_all($image_row);
     159  $derivatives = DerivativeImage::get_all($src_image);
    157160  $derivatives_arr = array();
    158161  foreach($derivatives as $type=>$derivative)
  • trunk/picture.php

    r12798 r12855  
    163163  $selected_derivative = $element_info['derivatives'][$deriv_type];
    164164
    165   $available_derivatives = array();
     165  $unique_derivatives = array();
     166  $show_original = isset($element_info['element_url']);
    166167  $added = array();
    167168  foreach($element_info['derivatives'] as $type => $derivative)
     
    171172      continue;
    172173    $added[$url] = 1;
    173     $available_derivatives[] = $type;
    174   }
    175 
    176   global $user, $page, $template;
     174    $show_original &= !($derivative->same_as_source());
     175    $unique_derivatives[$type]= $derivative;
     176  }
     177
     178  global $page, $template;
    177179 
     180  if ($show_original)
     181  {
     182    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
     183  }
     184
    178185  $template->append('current', array(
    179186      'selected_derivative' => $selected_derivative,
    180       'available_derivative_types' => $available_derivatives,
     187      'unique_derivatives' => $unique_derivatives,
    181188    ), true);
    182189
     
    492499  }
    493500
    494 
    495 
    496   $row['derivatives'] = DerivativeImage::get_all($row);
    497   $row['src_image'] = $row['derivatives'][IMG_THUMB]->src_image;
     501  $row['src_image'] = new SrcImage($row);
     502  $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
    498503 
    499   // ------ build element_path and element_url
    500   $row['element_path'] = get_element_path($row);
    501   $row['element_url'] = get_element_url($row);
    502 
    503504  if ($i=='current')
    504505  {
     506    $row['element_path'] = get_element_path($row);
     507
    505508    if ( $row['src_image']->is_original() )
    506     {
     509    {// we have a photo
    507510      if ( $user['enabled_high']=='true' )
    508511      {
    509         $row['download_url'] = get_download_url('e',$row);
     512        $row['element_url'] = $row['src_image']->get_url();
     513        $row['download_url'] = get_action_url($row['id'], 'e', true);
    510514      }
    511515    }
    512516    else
    513517    { // not a pic - need download link
    514       $row['download_url'] = $row['element_url'];
     518      $row['download_url'] = $row['element_url'] = get_element_url($row);;
    515519    }
    516520  }
  • trunk/themes/default/template/picture_content.tpl

    r12797 r12855  
    33        title="{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}" {else} title="{$current.TITLE|@replace:'"':' '} - {$ALT_IMG}"
    44{/if}>
    5 {if count($current.available_derivative_types)>1}
     5{if count($current.unique_derivatives)>1}
    66{footer_script}{literal}
    77function changeImgSrc(url,type,display)
     
    3535<a id="derivativeSwitchLink" onclick="toggleDerivativeSwitchBox()" style="cursor:pointer">{$current.selected_derivative->get_type()|@translate}</a>
    3636<div id="derivativeSwitchBox" onclick="toggleDerivativeSwitchBox()" style="display:none">
    37 {foreach from=$current.available_derivative_types item=derivative_type}
    38 <a onclick="changeImgSrc('{$current.derivatives[$derivative_type]->get_url()|@escape:javascript}', '{$derivative_type}', '{$derivative_type|@translate|@escape:javascript}')" style="cursor:pointer">{$derivative_type|@translate} ({$current.derivatives[$derivative_type]->get_size_hr()})</a><br>
     37{foreach from=$current.unique_derivatives item=derivative key=derivative_type}
     38<a href="javascript:changeImgSrc('{$derivative->get_url()|@escape:javascript}', '{$derivative_type}', '{$derivative->get_type()|@translate|@escape:javascript}')" style="cursor:pointer">{$derivative->get_type()|@translate} ({$derivative->get_size_hr()})</a><br>
    3939{/foreach}
     40{if isset($U_ORIGINAL)}
     41<a  href="javascript:phpWGOpenWindow('{$U_ORIGINAL}','xxx','scrollbars=yes,toolbar=no,status=no,resizable=yes')" title="{'Click on the photo to see it in high definition'|@translate}">{'original'|@translate}</a>
     42{/if}
    4043</div>
    4144{/if}
  • trunk/tools/triggers_list.php

    r12608 r12855  
    160160  'vars' => array('string' => 'url', 'array' => 'element_info'),
    161161  'files' => array('include\functions_picture.inc.php (get_download_url'),
    162 ),
    163 array(
    164   'name' => 'get_element_location',
    165   'type' => 'trigger_event',
    166   'vars' => array('string' => 'path', 'array' => 'element_info'),
    167   'files' => array('include\functions_picture.inc.php (get_element_location)'),
    168162),
    169163array(
Note: See TracChangeset for help on using the changeset viewer.