Changeset 12920


Ignore:
Timestamp:
Jan 17, 2012, 10:58:18 PM (8 years ago)
Author:
rvelices
Message:

feature 2548 multisize - code cleanup + better usage in category_cats + i.php logs memory usage peak

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/i.php

    r12908 r12920  
    2929defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
    3030
    31 function get_moment()
    32 {
    33   $t1 = explode( ' ', microtime() );
    34   $t2 = explode( '.', $t1[0] );
    35   $t2 = $t1[1].'.'.$t2[1];
    36   return $t2;
    37 }
    3831function trigger_action() {}
    3932function get_extension( $filename )
     
    128121{
    129122  $tmp = $step;
    130   $step = get_moment();
     123  $step = microtime(true);
    131124  return intval(1000*($step - $tmp));
    132125}
     
    264257
    265258$page=array();
    266 $begin = $step = get_moment();
     259$begin = $step = microtime(true);
    267260$timing=array();
    268261foreach( explode(',','load,rotate,crop,scale,sharpen,watermark,save,send') as $k )
     
    415408  basename($page['src_path']), $o_size, $o_size[0]*$o_size[1],
    416409  basename($page['derivative_path']), $d_size, $d_size[0]*$d_size[1],
     410  function_exists('memory_get_peak_usage') ? round( memory_get_peak_usage()/(1024*1024), 1) : '',
    417411  time_step($begin),
    418   $timing);
     412  '|', $timing);
    419413?>
  • trunk/include/category_cats.inc.php

    r12796 r12920  
    190190    if ($row['level'] <= $user['level'])
    191191    {
    192       $row['tn_src'] = DerivativeImage::thumb_url($row);
    193192      $infos_of_image[$row['id']] = $row;
    194193    }
     
    237236    while ($row = pwg_db_fetch_assoc($result))
    238237    {
    239       $row['tn_src'] =  DerivativeImage::thumb_url($row);
    240238      $infos_of_image[$row['id']] = $row;
    241239    }
    242240  }
     241 
     242  foreach ($infos_of_image as &$info)
     243  {
     244    $info['src_image'] = new SrcImage($info);
     245  }
     246  unset($info);
    243247}
    244248
     
    312316        array(
    313317          'ID'    => $category['id'],
    314           'TN_SRC'   => $representative_infos['tn_src'],
     318          'representative'   => $representative_infos,
    315319          'TN_ALT'   => strip_tags($category['name']),
    316320
     
    334338                'subcatify_category_description')),
    335339          'NAME'  => $name,
    336          
    337           // Extra fields for usage in extra themes
    338           'FILE_PATH' => $representative_infos['path'],
    339           'FILE_POSTED' => $representative_infos['date_available'],
    340           'FILE_CREATED' => $representative_infos['date_creation'],
    341           'FILE_DESC' => $representative_infos['comment'],
    342           'FILE_AUTHOR' => $representative_infos['author'],
    343           'FILE_HIT' => $representative_infos['hit'],
    344           'FILE_SIZE' => $representative_infos['filesize'],
    345           'FILE_WIDTH' => $representative_infos['width'],
    346           'FILE_HEIGHT' => $representative_infos['height'],
    347           'FILE_METADATE' => $representative_infos['date_metadata_update'],
    348           'FILE_HAS_HD' => $representative_infos['has_high'],
    349           'FILE_HD_WIDTH' => $representative_infos['high_width'],
    350           'FILE_HD_HEIGHT' => $representative_infos['high_height'],
    351           'FILE_HD_FILESIZE' => $representative_infos['high_filesize'],
    352           'FILE_RATING_SCORE' => $representative_infos['rating_score'],
    353340        );
    354341    if ($conf['index_new_icon'])
     
    388375  }
    389376
     377  $derivative_params = trigger_event('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_SMALL) );
    390378  $tpl_thumbnails_var = trigger_event('loc_end_index_category_thumbnails', $tpl_thumbnails_var, $categories);
    391   $template->assign( 'category_thumbnails', $tpl_thumbnails_var);
     379  $template->assign( array(
     380    'category_thumbnails' => $tpl_thumbnails_var,
     381    'derivative_params' => $derivative_params,
     382    ) );
    392383
    393384  $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
  • trunk/include/category_default.inc.php

    r12908 r12920  
    110110  }
    111111
    112   $name = get_picture_title($row);
     112  $name = render_element_name($row);
     113  $desc = render_element_description($row);
    113114
    114115  $tpl_var = array_merge( $row, array(
    115116    'TN_SRC' => DerivativeImage::thumb_url($row),
    116117    'TN_ALT' => htmlspecialchars(strip_tags($name)),
    117     'TN_TITLE' => get_thumbnail_title($row),
     118    'TN_TITLE' => get_thumbnail_title($row, $name, $desc),
    118119    'URL' => $url,
     120    'DESCRIPTION' => $desc,
    119121    'src_image' => new SrcImage($row),
    120122    ) );
     
    146148    }
    147149  }
    148 
    149150  $tpl_var['NAME'] = $name;
    150151  $tpl_thumbnails_var[] = $tpl_var;
    151152}
    152153
    153 $derivative_params = ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) );
     154$derivative_params = trigger_event('get_index_derivative_params', ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) ) );
    154155
    155156$template->assign( array(
     
    162163$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
    163164unset($pictures, $selection, $tpl_thumbnails_var);
    164 $template->clear_assign( array('thumbnails') );
     165$template->clear_assign( array('thumbnails', 'derivative_params') );
    165166pwg_debug('end include/category_default.inc.php');
    166167?>
  • trunk/include/common.inc.php

    r12802 r12920  
    2525
    2626// determine the initial instant to indicate the generation time of this page
    27 $t1 = explode( ' ', microtime() );
    28 $t2 = explode( '.', $t1[0] );
    29 $t2 = $t1[1].'.'.$t2[1];
     27$t2 = microtime(true);
    3028
    3129@set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
     
    110108include(PHPWG_ROOT_PATH . 'include/constants.php');
    111109include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
    112 include(PHPWG_ROOT_PATH .'include/template.class.php');
     110
    113111
    114112// Database connection
  • trunk/include/functions.inc.php

    r12878 r12920  
    3434include_once( PHPWG_ROOT_PATH .'include/derivative_std_params.inc.php');
    3535include_once( PHPWG_ROOT_PATH .'include/derivative.inc.php');
     36require_once( PHPWG_ROOT_PATH .'include/smarty/libs/Smarty.class.php');
     37include_once( PHPWG_ROOT_PATH .'include/template.class.php');
    3638
    3739//----------------------------------------------------------- generic functions
     
    5355function get_moment()
    5456{
    55   $t1 = explode( ' ', microtime() );
    56   $t2 = explode( '.', $t1[0] );
    57   $t2 = $t1[1].'.'.$t2[1];
    58   return $t2;
     57  return microtime(true);
    5958}
    6059
     
    664663    return '';
    665664  }
    666  
     665
    667666  $query_string = '';
    668667
     
    817816
    818817/**
    819  * returns the title of the thumbnail based on photo properties
    820  */
    821 function get_thumbnail_title($info)
    822 {
    823   global $conf, $user;
    824 
    825   $title = get_picture_title($info);
    826 
    827   $details = array();
    828 
    829   if (!empty($info['hit']))
    830   {
    831     $details[] = $info['hit'].' '.strtolower(l10n('Visits'));
    832   }
    833 
    834   if ($conf['rate'] and !empty($info['rating_score']))
    835   {
    836     $details[] = strtolower(l10n('Rating score')).' '.$info['rating_score'];
    837   }
    838 
    839   if (isset($info['nb_comments']) and $info['nb_comments'] != 0)
    840   {
    841     $details[] = l10n_dec('%d comment', '%d comments', $info['nb_comments']);
    842   }
    843 
    844   if (count($details) > 0)
    845   {
    846     $title.= ' ('.implode(', ', $details).')';
    847   }
    848 
    849   if (!empty($info['comment']))
    850   {
    851     $info['comment'] = trigger_event('render_element_description', $info['comment']);
    852     $title.= ' '.substr($info['comment'], 0, 100).(strlen($info['comment']) > 100 ? '...' : '');
    853   }
    854 
    855   $title = htmlspecialchars(strip_tags($title));
    856 
    857   $title = trigger_event('get_thumbnail_title', $title, $info);
    858 
    859   return $title;
    860 }
    861 
    862 /**
    863818 * fill the current user caddie with given elements, if not already in
    864819 * caddie
     
    902857{
    903858  return str_replace('_',' ',get_filename_wo_extension($filename));
    904 }
    905 
    906 /**
    907  */
    908 function get_picture_title($info)
    909 {
    910   if (isset($info['name']) and !empty($info['name']))
    911   {
    912     return trigger_event('render_element_description', $info['name']);
    913   }
    914 
    915   return  get_name_from_file($info['file']);
    916859}
    917860
     
    14361379        return $time.':'.$valid_after_seconds.':'
    14371380                .hash_hmac(
    1438                         'md5', 
    1439                         $time.substr($_SERVER['REMOTE_ADDR'],0,5).$valid_after_seconds.$aditionnal_data_to_hash, 
     1381                        'md5',
     1382                        $time.substr($_SERVER['REMOTE_ADDR'],0,5).$valid_after_seconds.$aditionnal_data_to_hash,
    14401383                        $conf['secret_key']);
    14411384}
  • trunk/include/functions_html.inc.php

    r12761 r12920  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    179179    }
    180180  }
    181  
     181
    182182  if ($single_link and isset($single_url))
    183183  {
     
    296296{
    297297  global $page;
    298  
     298
    299299  foreach (array($a, $b) as $tag)
    300300  {
     
    534534}
    535535
     536/**
     537 */
     538function render_element_name($info)
     539{
     540  $name = $info['name'];
     541  if (!empty($name))
     542  {
     543    $name = trigger_event('render_element_description', $name);
     544    return $name;
     545  }
     546
     547  return get_name_from_file($info['file']);
     548}
     549
     550function render_element_description($info)
     551{
     552  $comment = $info['comment'];
     553  if (!empty($comment))
     554  {
     555    $comment = trigger_event('render_element_description', $comment);
     556    return $comment;
     557  }
     558  return '';
     559}
     560
     561/**
     562 * returns the title of the thumbnail based on photo properties
     563 */
     564function get_thumbnail_title($info, $title, $comment)
     565{
     566  global $conf, $user;
     567
     568  $details = array();
     569
     570  if (!empty($info['hit']))
     571  {
     572    $details[] = $info['hit'].' '.strtolower(l10n('Visits'));
     573  }
     574
     575  if ($conf['rate'] and !empty($info['rating_score']))
     576  {
     577    $details[] = strtolower(l10n('Rating score')).' '.$info['rating_score'];
     578  }
     579
     580  if (isset($info['nb_comments']) and $info['nb_comments'] != 0)
     581  {
     582    $details[] = l10n_dec('%d comment', '%d comments', $info['nb_comments']);
     583  }
     584
     585  if (count($details) > 0)
     586  {
     587    $title.= ' ('.implode(', ', $details).')';
     588  }
     589
     590  if (!empty($comment))
     591  {
     592    $title.= ' '.substr($info['comment'], 0, 100).(strlen($info['comment']) > 100 ? '...' : '');
     593  }
     594
     595  $title = htmlspecialchars(strip_tags($title));
     596  $title = trigger_event('get_thumbnail_title', $title, $info);
     597  return $title;
     598}
     599
    536600?>
  • trunk/include/functions_picture.inc.php

    r12855 r12920  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    2323
    2424
    25 
    26 /*
    27  * Returns the name of a photo according to its name and its filename.
    28  * @param name string
    29  * @param filename string
    30  * @return string
    31  */
    32 function get_image_name($name, $filename)
    33 {
    34   if (!empty($name))
    35   {
    36     return $name;
    37   }
    38   else
    39   {
    40     return get_name_from_file($filename);
    41   }
    42 }
    43 
    4425/*
    4526 * @param element_info array containing element information from db;
  • trunk/include/template.class.php

    r12908 r12920  
    2323
    2424
    25 require_once(PHPWG_ROOT_PATH.'include/smarty/libs/Smarty.class.php');
    26 
    27 
    2825class Template {
    2926
     
    4340  // used by html_head smarty block to add content before </head>
    4441  var $html_head_elements = array();
     42  private $html_style = '';
    4543
    4644  const COMBINED_SCRIPTS_TAG = '<!-- COMBINED_SCRIPTS -->';
     
    113111    $this->smarty->register_modifier( 'get_extent', array(&$this, 'get_extent') );
    114112    $this->smarty->register_block('html_head', array(&$this, 'block_html_head') );
     113    $this->smarty->register_block('html_style', array(&$this, 'block_html_style') );
    115114    $this->smarty->register_function('combine_script', array(&$this, 'func_combine_script') );
    116115    $this->smarty->register_function('get_combined_scripts', array(&$this, 'func_get_combined_scripts') );
     
    467466    }
    468467
    469     if ( count($this->html_head_elements) )
     468    if ( count($this->html_head_elements) || strlen($this->html_style) )
    470469    {
    471470      $search = "\n</head>";
     
    473472      if ($pos !== false)
    474473      {
    475         $this->output = substr_replace( $this->output, "\n".implode( "\n", $this->html_head_elements ), $pos, 0 );
     474        $rep = "\n".implode( "\n", $this->html_head_elements );
     475        if (strlen($this->html_style))
     476        {
     477          $rep='<style type="text/css">'.$this->html_style.'</style>';
     478        }
     479        $this->output = substr_replace( $this->output, $rep, $pos, 0 );
    476480      } //else maybe error or warning ?
    477481      $this->html_head_elements = array();
     482      $this->html_style = '';
    478483    }
    479484
     
    530535    { // second call
    531536      $this->html_head_elements[] = $content;
     537    }
     538  }
     539
     540  function block_html_style($params, $content, &$smarty, &$repeat)
     541  {
     542    $content = trim($content);
     543    if ( !empty($content) )
     544    { // second call
     545      $this->html_style .= $content;
    532546    }
    533547  }
     
    843857    return call_user_func_array('sprintf',  $args );
    844858  }
    845  
     859
    846860  function derivative_url($type, $img)
    847861  {
  • trunk/install.php

    r12886 r12920  
    225225
    226226//----------------------------------------------------- template initialization
    227 include( PHPWG_ROOT_PATH .'include/template.class.php');
    228227$template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'clear');
    229228$template->set_filenames( array('install' => 'install.tpl') );
  • trunk/picture.php

    r12887 r12920  
    33// | Piwigo - a PHP based photo gallery                                    |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    177177
    178178  global $page, $template;
    179  
     179
    180180  if ($show_original)
    181181  {
     
    313313      break;
    314314    }
    315     case 'toggle_metadata' :
    316     {
    317       break;
    318     }
    319315    case 'add_to_caddie' :
    320316    {
     
    335331      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
    336332      $author_id = get_comment_author_id($_GET['comment_to_edit']);
    337      
     333
    338334      if (can_manage_comment('edit', $author_id))
    339335      {
     
    365361              trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
    366362          }
    367          
     363
    368364          if ($perform_redirect)
    369365          {
     
    501497  $row['src_image'] = new SrcImage($row);
    502498  $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
    503  
     499
    504500  if ($i=='current')
    505501  {
     
    531527
    532528  $picture[$i] = $row;
    533 
    534   if ( !empty( $row['name'] ) )
    535   {
    536     $picture[$i]['name'] = $row['name'];
    537   }
    538   else
    539   {
    540     $file_wo_ext = get_filename_wo_extension($row['file']);
    541     $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
    542   }
    543 
    544   $picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
     529  $picture[$i]['TITLE'] = render_element_name($row);
    545530
    546531  if ('previous'==$i and $page['previous_item']==$page['first_item'])
     
    605590}
    606591
    607 $title =  $picture['current']['name'];
     592$title =  $picture['current']['TITLE'];
    608593$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
    609594
     
    644629        $picture[$which_image],
    645630        array(
    646           'TITLE' => $picture[$which_image]['name'],
    647631          'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(),
    648632          // Params slideshow was transmit to navigation buttons
     
    653637        )
    654638      );
    655     if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
    656     {
    657       $template->append($which_image, array('U_DOWNLOAD' => $picture['current']['download_url']), true);
    658     }
    659   }
     639  }
     640}
     641if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
     642{
     643  $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true);
    660644}
    661645
  • trunk/themes/default/template/mainpage_categories.tpl

    r12123 r12920  
     1{strip}{html_style}
     2.thumbnailCategory DIV.illustration{ldelim}
     3        width: {$derivative_params->max_width()+5}px;
     4}
    15
     6.content .thumbnailCategory .description{ldelim}
     7        height: {$derivative_params->max_height()+5}px;
     8}
     9{/html_style}{/strip}
    210<ul class="thumbnailCategories">
    311{foreach from=$category_thumbnails item=cat}
     
    614                        <div class="illustration">
    715                        <a href="{$cat.URL}">
    8                                 <img src="{$cat.TN_SRC}" alt="{$cat.TN_ALT}" title="{$cat.NAME|@replace:'"':' '|@strip_tags:false} - {'display this album'|@translate}">
     16                                <img src="{$pwg->derivative_url($derivative_params, $cat.representative.src_image)}" alt="{$cat.TN_ALT}" title="{$cat.NAME|@replace:'"':' '|@strip_tags:false} - {'display this album'|@translate}">
    917                        </a>
    1018                        </div>
  • trunk/themes/default/template/thumbnails.tpl

    r12908 r12920  
    11{if !empty($thumbnails)}{strip}
    2 {html_head}
    3 <style type="text/css">
     2{html_style}
    43{*Set some sizes according to maximum thumbnail width and height*}
    54.thumbnails SPAN,
     
    1211        height: {$derivative_params->max_height()+2}px;
    1312}
    14 
    15 </style>
    16 {/html_head}
     13{if $derivative_params->max_width() > 600}
     14.thumbLegend {ldelim}font-size: 130%}
     15{else}
     16{if $derivative_params->max_width() > 400}
     17.thumbLegend {ldelim}font-size: 110%}
     18{else}
     19.thumbLegend {ldelim}font-size: 90%}
     20{/if}
     21{/if}
     22{/html_style}
    1723{foreach from=$thumbnails item=thumbnail}
    1824        <li>
  • trunk/themes/default/theme.css

    r12908 r12920  
    264264/* Thumbnails */
    265265.thumbnails SPAN.thumbLegend {
    266         font-size: 90%;
    267266        overflow: hidden;/* oversized legend is clipped */
    268267}
  • trunk/upgrade.php

    r12768 r12920  
    217217// +-----------------------------------------------------------------------+
    218218
    219 include( PHPWG_ROOT_PATH .'include/template.class.php');
    220219$template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'clear');
    221220$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
Note: See TracChangeset for help on using the changeset viewer.