Changeset 12797


Ignore:
Timestamp:
Dec 27, 2011, 9:26:49 PM (12 years ago)
Author:
rvelices
Message:

feature 2541 multisize

  • nicer presentation on picture.php
  • added a maintenance purge derivatives action
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r12763 r12797  
    22472247  return array_from_query($query, 'user_id');
    22482248}
     2249
     2250function clear_derivative_cache($type='all')
     2251{
     2252  $pattern='#.*-';
     2253  if ($type == 'all')
     2254  {
     2255    $type_urls = array();
     2256    foreach(ImageStdParams::get_all_types() as $dtype)
     2257    {
     2258      $type_urls[] = derivative_to_url($dtype);
     2259    }
     2260    $type_urls[] = derivative_to_url(IMG_CUSTOM);
     2261    $pattern .= '(' . implode('|',$type_urls) . ')';
     2262  }
     2263  else
     2264  {
     2265    $pattern .= derivative_to_url($type);
     2266  }
     2267  $pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#';
     2268  if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR))
     2269  {
     2270    while (($node = readdir($contents)) !== false)
     2271    {
     2272      if ($node != '.'
     2273          and $node != '..'
     2274          and is_dir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node))
     2275      {
     2276        clear_derivative_cache_rec(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node, $pattern);
     2277      }
     2278    }
     2279    closedir($contents);
     2280  }
     2281}
     2282
     2283function clear_derivative_cache_rec($path, $pattern)
     2284{
     2285  $rmdir = true;
     2286  $rm_index = false;
     2287
     2288  if ($contents = opendir($path))
     2289  {
     2290    while (($node = readdir($contents)) !== false)
     2291    {
     2292      if ($node == '.' or $node == '..')
     2293        continue;
     2294      if (is_dir($path.'/'.$node))
     2295      {
     2296        $rmdir &= clear_derivative_cache_rec($path.'/'.$node, $pattern);
     2297      }
     2298      else
     2299      {
     2300        if (preg_match($pattern, $node))
     2301        {
     2302          unlink($path.'/'.$node);
     2303        }
     2304        elseif ($node=='index.htm')
     2305        {
     2306          $rm_index = true;
     2307        }
     2308        else
     2309        {
     2310          $rmdir = false;
     2311        }
     2312      }
     2313    }
     2314    closedir($contents);
     2315   
     2316    if ($rmdir)
     2317    {
     2318      if ($rm_index)
     2319      {
     2320        unlink($path.'/index.htm');
     2321      }
     2322      clearstatcache();
     2323      rmdir($path);
     2324    }
     2325    return $rmdir;
     2326  }
     2327}
    22492328?>
  • trunk/admin/maintenance.php

    r11827 r12797  
    122122    break;
    123123  }
    124   case 'compiled-templates' :
     124  case 'compiled-templates':
    125125  {
    126126    $template->delete_compiled_templates();
    127127    FileCombiner::clear_combined_files();
     128    break;
     129  }
     130  case 'derivatives':
     131  {
     132    clear_derivative_cache();
    128133    break;
    129134  }
     
    155160    'U_MAINT_SEARCH' => sprintf($url_format, 'search'),
    156161    'U_MAINT_COMPILED_TEMPLATES' => sprintf($url_format, 'compiled-templates'),
     162    'U_MAINT_DERIVATIVES' => sprintf($url_format, 'derivatives'),
    157163    'U_HELP' => get_root_url().'admin/popuphelp.php?page=maintenance',
    158164    )
  • trunk/admin/rating.php

    r12796 r12797  
    173173    i.path,
    174174    i.file,
    175     i.tn_ext,
     175    i.representative_ext,
    176176    i.rating_score       AS score,
    177177    MAX(r.date)          AS recently_rated,
  • trunk/admin/themes/default/template/maintenance.tpl

    r10133 r12797  
    3030        <li><a href="{$U_MAINT_SEARCH}"onclick="return confirm('{'Purge search history'|@translate|@escape:'javascript'}');">{'Purge search history'|@translate}</a></li>
    3131        <li><a href="{$U_MAINT_COMPILED_TEMPLATES}">{'Purge compiled templates'|@translate}</a></li>
     32        <li><a href="{$U_MAINT_DERIVATIVES}">{'Purge derivative image cache'|@translate}</a></li>
    3233</ul>
  • trunk/i.php

    r12796 r12797  
    136136  foreach (ImageStdParams::get_defined_type_map() as $type => $params)
    137137  {
    138     if (substr($type,0,2) == $deriv[0])
     138    if ( derivative_to_url($type) == $deriv[0])
    139139    {
    140140      $page['derivative_type'] = $type;
     
    146146  if (!isset($page['derivative_type']))
    147147  {
    148     if (substr(IMG_CUSTOM,0,2) == $deriv[0])
     148    if (derivative_to_url(IMG_CUSTOM) == $deriv[0])
    149149    {
    150150      $page['derivative_type'] = IMG_CUSTOM;
     
    289289
    290290fpassthru($fp);
    291 exit;
     291fclose($fp);
    292292?>
  • trunk/include/derivative.inc.php

    r12796 r12797  
    2222final class SrcImage
    2323{
     24  const IS_ORIGINAL = 0x01;
     25  const IS_MIMETYPE = 0x02;
     26
    2427  public $rel_path;
    25  
     28
    2629  public $coi=null;
    2730  private $size=null;
     31  private $flags=0;
    2832
    2933  function __construct($infos)
     
    3539    {
    3640      $this->rel_path = $infos['path'];
     41      $this->flags |= self::IS_ORIGINAL;
    3742    }
    3843    elseif (!empty($infos['representative_ext']))
     
    4550    else
    4651    {
    47       $this->rel_path = get_themeconf('mime_icon_dir').strtolower($ext).'.png';
     52      $ext = strtolower($ext);
     53      $this->rel_path = trigger_event('get_mimetype_location', get_themeconf('mime_icon_dir').$ext.'.png', $ext );
     54      $this->flags |= self::IS_MIMETYPE;
     55      $this->size = @getimagesize(PHPWG_ROOT_PATH.$this->rel_path);
    4856    }
    4957
    5058    $this->coi = @$infos['coi'];
    51     if (isset($infos['width']) && isset($infos['height']))
     59    if (!$this->size && isset($infos['width']) && isset($infos['height']))
    5260    {
    5361      $this->size = array($infos['width'], $infos['height']);
    5462    }
     63  }
     64
     65  function is_original()
     66  {
     67    return $this->flags & self::IS_ORIGINAL;
     68  }
     69
     70  function is_mimetype()
     71  {
     72    return $this->flags & self::IS_MIMETYPE;
     73  }
     74
     75  function get_path()
     76  {
     77    return PHPWG_ROOT_PATH.$this->rel_path;
     78  }
     79
     80  function get_url()
     81  {
     82    return get_root_url().$this->rel_path;
    5583  }
    5684
     
    127155      $ret[$type] = $ret[$type2];
    128156    }
    129    
     157
    130158    return $ret;
    131159  }
     
    145173    $tokens[] = substr($params->type,0,2);
    146174
    147     if (!empty($src->coi))
     175    if ($params->sizing->max_crop != 0 and !empty($src->coi))
    148176    {
    149177      $tokens[] = 'ci'.$src->coi;
     
    207235
    208236
     237  function get_type()
     238  {
     239    if ($this->flags & self::SAME_AS_SRC)
     240      return 'original';
     241    return $this->params->type;
     242  }
     243
    209244  /* returns the size of the derivative image*/
    210245  function get_size()
  • trunk/include/derivative_params.inc.php

    r12796 r12797  
    2020// +-----------------------------------------------------------------------+
    2121
     22function derivative_to_url($t)
     23{
     24  return substr($t, 0, 2);
     25}
     26
    2227function size_to_url($s)
    2328{
  • trunk/include/picture_metadata.inc.php

    r12796 r12797  
    3737  }
    3838
    39   $exif = get_exif_data($picture['current']['image_path'], $exif_mapping);
     39  $exif = get_exif_data($picture['current']['src_image']->get_path(), $exif_mapping);
    4040 
    4141  if (count($exif) > 0)
     
    8080if ($conf['show_iptc'])
    8181{
    82   $iptc = get_iptc_data($picture['current']['image_path'], $conf['show_iptc_mapping']);
     82  $iptc = get_iptc_data($picture['current']['src_image']->get_path(), $conf['show_iptc_mapping']);
    8383
    8484  if (count($iptc) > 0)
  • trunk/picture.php

    r12796 r12797  
    475475    $i = 'previous';
    476476  }
    477   else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
     477  elseif (isset($page['next_item']) and $row['id'] == $page['next_item'])
    478478  {
    479479    $i = 'next';
    480480  }
    481   else if (isset($page['first_item']) and $row['id'] == $page['first_item'])
     481  elseif (isset($page['first_item']) and $row['id'] == $page['first_item'])
    482482  {
    483483    $i = 'first';
    484484  }
    485   else if (isset($page['last_item']) and $row['id'] == $page['last_item'])
     485  elseif (isset($page['last_item']) and $row['id'] == $page['last_item'])
    486486  {
    487487    $i = 'last';
     
    492492  }
    493493
    494   $picture[$i] = $row;
    495 
    496   $picture[$i]['is_picture'] = false;
    497   if (in_array(get_extension($row['file']), $conf['picture_ext']))
    498   {
    499     $picture[$i]['is_picture'] = true;
    500   }
    501 
    502   $picture[$i]['derivatives'] = DerivativeImage::get_all($row);
    503   $picture[$i]['src_image'] = $picture[$i]['derivatives'][IMG_THUMB]->src_image;
    504   $picture[$i]['thumbnail'] = $picture[$i]['derivatives'][IMG_THUMB]->get_url();
     494
     495
     496  $row['derivatives'] = DerivativeImage::get_all($row);
     497  $row['src_image'] = $row['derivatives'][IMG_THUMB]->src_image;
    505498 
    506499  // ------ build element_path and element_url
    507   $picture[$i]['element_path'] = get_element_path($picture[$i]);
    508   $picture[$i]['element_url'] = get_element_url($picture[$i]);
    509 
    510   // ------ build image_path and image_url
    511   if ($i=='current' or $i=='next')
    512   {
    513     $picture[$i]['image_path'] = get_image_path( $picture[$i] );
    514     $picture[$i]['image_url'] = get_image_url( $picture[$i] );
    515   }
     500  $row['element_path'] = get_element_path($row);
     501  $row['element_url'] = get_element_url($row);
    516502
    517503  if ($i=='current')
    518504  {
    519     if ( $picture[$i]['is_picture'] )
     505    if ( $row['src_image']->is_original() )
    520506    {
    521507      if ( $user['enabled_high']=='true' )
    522508      {
    523         $picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
     509        $row['download_url'] = get_download_url('e',$row);
    524510      }
    525511    }
    526512    else
    527513    { // not a pic - need download link
    528       $picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
    529     }
    530   }
    531 
    532 
    533   if ( !empty( $row['name'] ) )
    534   {
    535     $picture[$i]['name'] = $row['name'];
    536   }
    537   else
    538   {
    539     $file_wo_ext = get_filename_wo_extension($row['file']);
    540     $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
    541   }
    542 
    543   $picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
    544 
    545   $picture[$i]['url'] = duplicate_picture_url(
     514      $row['download_url'] = $row['element_url'];
     515    }
     516  }
     517
     518  $row['url'] = duplicate_picture_url(
    546519    array(
    547520      'image_id' => $row['id'],
     
    553526    );
    554527
     528  $picture[$i] = $row;
     529
     530  if ( !empty( $row['name'] ) )
     531  {
     532    $picture[$i]['name'] = $row['name'];
     533  }
     534  else
     535  {
     536    $file_wo_ext = get_filename_wo_extension($row['file']);
     537    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
     538  }
     539
     540  $picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
     541
    555542  if ('previous'==$i and $page['previous_item']==$page['first_item'])
    556543  {
     
    560547  {
    561548    $picture['last'] = $picture[$i];
    562   }
    563 }
    564 
    565 // calculation of width and height for the current picture
    566 if (empty($picture['current']['width']))
    567 {
    568   $taille_image = @getimagesize($picture['current']['image_path']);
    569   if ($taille_image!==false)
    570   {
    571     $picture['current']['width'] = $taille_image[0];
    572     $picture['current']['height']= $taille_image[1];
    573549  }
    574550}
     
    638614  (
    639615    ($conf['show_exif'] or $conf['show_iptc'])
    640     and isset($picture['current']['image_path'])
     616    and !$picture['current']['src_image']->is_mimetype()
    641617    ),
    642   $picture['current']['path']
     618  $picture['current']
    643619  );
    644620
     
    653629// allow plugins to change what we computed before passing data to template
    654630$picture = trigger_event('picture_pictures_data', $picture);
    655 
    656 
    657 if (isset($picture['next']['image_url'])
    658     and $picture['next']['is_picture']
    659     and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
    660 {
    661   $template->assign('U_PREFETCH', $picture['next']['image_url'] );
    662 }
    663631
    664632//------------------------------------------------------- navigation management
     
    673641        array(
    674642          'TITLE' => $picture[$which_image]['name'],
    675           'THUMB_SRC' => $picture[$which_image]['thumbnail'],
     643          'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(),
    676644          // Params slideshow was transmit to navigation buttons
    677645          'U_IMG' =>
     
    889857
    890858// size in pixels
    891 if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
     859if ($picture['current']['src_image']->is_original() and isset($picture['current']['width']) )
    892860{
    893861  $infos['INFO_DIMENSIONS'] =
     
    981949$template->assign( 'ELEMENT_CONTENT', $element_content );
    982950
     951if (isset($picture['next'])
     952    and $picture['next']['src_image']->is_original()
     953    and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
     954{
     955  $template->assign('U_PREFETCH', $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', IMG_LARGE)]->get_url() );
     956}
     957
     958
    983959// +-----------------------------------------------------------------------+
    984960// |                               sub pages                               |
  • trunk/themes/clear/theme.css

    r8306 r12797  
    1515}
    1616
    17 #menubar DL, .content, #imageToolBar, .header_notes {
     17#menubar DL, .content, #imageToolBar, #derivativeSwitchLink, #derivativeSwitchBox, .header_notes {
    1818  background-color: #eeeeee;
    1919}
    2020
    2121/* borders */
    22 #menubar DL, .content, #imageToolBar {
     22#menubar DL, .content, #imageToolBar, #derivativeSwitchLink, #derivativeSwitchBox {
    2323  border: 1px solid #d3d3d3;
    2424}
  • trunk/themes/dark/theme.css

    r11992 r12797  
    1717}
    1818
    19 #menubar DL, .content, #imageToolBar, #imageHeaderBar, .header_notes {
     19#menubar DL, .content, #imageToolBar, #imageHeaderBar, #derivativeSwitchLink, #derivativeSwitchBox, .header_notes {
    2020        background-color: #505050;
    2121}
     
    3535
    3636/* borders */
    37 #menubar DL, .content{
     37#menubar DL, .content, #derivativeSwitchLink, #derivativeSwitchBox{
    3838        border: 1px solid #000;
    3939}
  • trunk/themes/default/template/picture_content.tpl

    r12796 r12797  
    55{if count($current.available_derivative_types)>1}
    66{footer_script}{literal}
    7 function changeImgSrc(url,type)
     7function changeImgSrc(url,type,display)
    88{
    99        var theImg = document.getElementById("theMainImage");
     
    1212                theImg.removeAttribute("width");theImg.removeAttribute("height");
    1313                theImg.src = url;
     14                var elt = document.getElementById("derivativeSwitchLink");
     15                if (elt) elt.innerHTML = display;
    1416        }
    1517        document.cookie = 'picture_deriv=' + type;
    1618}
     19
     20function toggleDerivativeSwitchBox()
     21{
     22        var elt = document.getElementById("derivativeSwitchBox"),
     23                ePos = document.getElementById("derivativeSwitchLink");
     24        if (elt.style.display==="none")
     25        {
     26                elt.style.position = "absolute";
     27                elt.style.left = (ePos.offsetLeft + 10) + "px";
     28                elt.style.top = (ePos.offsetTop + ePos.offsetHeight) + "px";
     29                elt.style.display="";
     30        }
     31        else
     32                elt.style.display="none";
     33}
    1734{/literal}{/footer_script}
    18 <p>
     35<a id="derivativeSwitchLink" onclick="toggleDerivativeSwitchBox()" style="cursor:pointer">{$current.selected_derivative->get_type()|@translate}</a>
     36<div id="derivativeSwitchBox" onclick="toggleDerivativeSwitchBox()" style="display:none">
    1937{foreach from=$current.available_derivative_types item=derivative_type}
    20 <a onclick="changeImgSrc('{$current.derivatives[$derivative_type]->get_url()|@escape:javascript}', '{$derivative_type}')" title="{$current.derivatives[$derivative_type]->get_size_hr()}">{$derivative_type}</a>
     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>
    2139{/foreach}
    22 </p>
     40</div>
    2341{/if}
  • trunk/themes/default/theme.css

    r12764 r12797  
    338338#imageToolBar .pwg-button {width:42px;}
    339339
     340
     341#derivativeSwitchLink {
     342        padding: 0.2em;
     343        position: absolute;
     344        left: 5px;
     345        top: 100px;
     346}
     347
     348#derivativeSwitchBox {
     349        padding: 0.5em;
     350        border-radius: 4px;
     351        z-index: 100;
     352}
    340353
    341354#theImage {
Note: See TracChangeset for help on using the changeset viewer.