aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2012-01-17 21:58:18 +0000
committerrvelices <rv-github@modusoptimus.com>2012-01-17 21:58:18 +0000
commitcc01941ed97f6c8f6790931bfc167ba45c5a8f91 (patch)
treefe465d457c034efba03cfe26d65b5467d88bfca2 /include
parente1bd64fdfc50f3ef50c0b4391c4586bbaeacb287 (diff)
feature 2548 multisize - code cleanup + better usage in category_cats + i.php logs memory usage peak
git-svn-id: http://piwigo.org/svn/trunk@12920 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/category_cats.inc.php33
-rw-r--r--include/category_default.inc.php11
-rw-r--r--include/common.inc.php6
-rw-r--r--include/functions.inc.php69
-rw-r--r--include/functions_html.inc.php70
-rw-r--r--include/functions_picture.inc.php23
-rw-r--r--include/template.class.php26
7 files changed, 115 insertions, 123 deletions
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php
index 2ecdf5ec2..cce9ac520 100644
--- a/include/category_cats.inc.php
+++ b/include/category_cats.inc.php
@@ -189,7 +189,6 @@ SELECT *
{
if ($row['level'] <= $user['level'])
{
- $row['tn_src'] = DerivativeImage::thumb_url($row);
$infos_of_image[$row['id']] = $row;
}
else
@@ -236,10 +235,15 @@ SELECT *
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
- $row['tn_src'] = DerivativeImage::thumb_url($row);
$infos_of_image[$row['id']] = $row;
}
}
+
+ foreach ($infos_of_image as &$info)
+ {
+ $info['src_image'] = new SrcImage($info);
+ }
+ unset($info);
}
if (count($user_representative_updates_for))
@@ -311,7 +315,7 @@ if (count($categories) > 0)
$tpl_var =
array(
'ID' => $category['id'],
- 'TN_SRC' => $representative_infos['tn_src'],
+ 'representative' => $representative_infos,
'TN_ALT' => strip_tags($category['name']),
'URL' => make_index_url(
@@ -333,23 +337,6 @@ if (count($categories) > 0)
@$category['comment'],
'subcatify_category_description')),
'NAME' => $name,
-
- // Extra fields for usage in extra themes
- 'FILE_PATH' => $representative_infos['path'],
- 'FILE_POSTED' => $representative_infos['date_available'],
- 'FILE_CREATED' => $representative_infos['date_creation'],
- 'FILE_DESC' => $representative_infos['comment'],
- 'FILE_AUTHOR' => $representative_infos['author'],
- 'FILE_HIT' => $representative_infos['hit'],
- 'FILE_SIZE' => $representative_infos['filesize'],
- 'FILE_WIDTH' => $representative_infos['width'],
- 'FILE_HEIGHT' => $representative_infos['height'],
- 'FILE_METADATE' => $representative_infos['date_metadata_update'],
- 'FILE_HAS_HD' => $representative_infos['has_high'],
- 'FILE_HD_WIDTH' => $representative_infos['high_width'],
- 'FILE_HD_HEIGHT' => $representative_infos['high_height'],
- 'FILE_HD_FILESIZE' => $representative_infos['high_filesize'],
- 'FILE_RATING_SCORE' => $representative_infos['rating_score'],
);
if ($conf['index_new_icon'])
{
@@ -387,8 +374,12 @@ if (count($categories) > 0)
$tpl_thumbnails_var[] = $tpl_var;
}
+ $derivative_params = trigger_event('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_SMALL) );
$tpl_thumbnails_var = trigger_event('loc_end_index_category_thumbnails', $tpl_thumbnails_var, $categories);
- $template->assign( 'category_thumbnails', $tpl_thumbnails_var);
+ $template->assign( array(
+ 'category_thumbnails' => $tpl_thumbnails_var,
+ 'derivative_params' => $derivative_params,
+ ) );
$template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
}
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index 18a4cb4bf..454d1e1e5 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -109,13 +109,15 @@ foreach ($pictures as $row)
$row['NB_COMMENTS'] = $row['nb_comments'] = (int)@$nb_comments_of[$row['id']];
}
- $name = get_picture_title($row);
+ $name = render_element_name($row);
+ $desc = render_element_description($row);
$tpl_var = array_merge( $row, array(
'TN_SRC' => DerivativeImage::thumb_url($row),
'TN_ALT' => htmlspecialchars(strip_tags($name)),
- 'TN_TITLE' => get_thumbnail_title($row),
+ 'TN_TITLE' => get_thumbnail_title($row, $name, $desc),
'URL' => $url,
+ 'DESCRIPTION' => $desc,
'src_image' => new SrcImage($row),
) );
@@ -145,12 +147,11 @@ foreach ($pictures as $row)
break;
}
}
-
$tpl_var['NAME'] = $name;
$tpl_thumbnails_var[] = $tpl_var;
}
-$derivative_params = ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) );
+$derivative_params = trigger_event('get_index_derivative_params', ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) ) );
$template->assign( array(
'derivative_params' =>$derivative_params,
@@ -161,6 +162,6 @@ $template->assign('thumbnails', $tpl_thumbnails_var);
$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
unset($pictures, $selection, $tpl_thumbnails_var);
-$template->clear_assign( array('thumbnails') );
+$template->clear_assign( array('thumbnails', 'derivative_params') );
pwg_debug('end include/category_default.inc.php');
?> \ No newline at end of file
diff --git a/include/common.inc.php b/include/common.inc.php
index 093aca08a..811a4a650 100644
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -24,9 +24,7 @@
defined('PHPWG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
// determine the initial instant to indicate the generation time of this page
-$t1 = explode( ' ', microtime() );
-$t2 = explode( '.', $t1[0] );
-$t2 = $t1[1].'.'.$t2[1];
+$t2 = microtime(true);
@set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
@@ -109,7 +107,7 @@ if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors']))
include(PHPWG_ROOT_PATH . 'include/constants.php');
include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
-include(PHPWG_ROOT_PATH .'include/template.class.php');
+
// Database connection
try
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 4647e8845..5ea5432b6 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -33,6 +33,8 @@ include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
include_once( PHPWG_ROOT_PATH .'include/derivative_params.inc.php');
include_once( PHPWG_ROOT_PATH .'include/derivative_std_params.inc.php');
include_once( PHPWG_ROOT_PATH .'include/derivative.inc.php');
+require_once( PHPWG_ROOT_PATH .'include/smarty/libs/Smarty.class.php');
+include_once( PHPWG_ROOT_PATH .'include/template.class.php');
//----------------------------------------------------------- generic functions
@@ -52,10 +54,7 @@ function micro_seconds()
// are precised : e.g. 1052343429.89276600
function get_moment()
{
- $t1 = explode( ' ', microtime() );
- $t2 = explode( '.', $t1[0] );
- $t2 = $t1[1].'.'.$t2[1];
- return $t2;
+ return microtime(true);
}
// The function get_elapsed_time returns the number of seconds (with 3
@@ -663,7 +662,7 @@ function get_query_string_diff($rejects=array(), $escape=true)
{
return '';
}
-
+
$query_string = '';
$str = $_SERVER['QUERY_STRING'];
@@ -816,50 +815,6 @@ function get_thumbnail_location($element_info)
}
/**
- * returns the title of the thumbnail based on photo properties
- */
-function get_thumbnail_title($info)
-{
- global $conf, $user;
-
- $title = get_picture_title($info);
-
- $details = array();
-
- if (!empty($info['hit']))
- {
- $details[] = $info['hit'].' '.strtolower(l10n('Visits'));
- }
-
- if ($conf['rate'] and !empty($info['rating_score']))
- {
- $details[] = strtolower(l10n('Rating score')).' '.$info['rating_score'];
- }
-
- if (isset($info['nb_comments']) and $info['nb_comments'] != 0)
- {
- $details[] = l10n_dec('%d comment', '%d comments', $info['nb_comments']);
- }
-
- if (count($details) > 0)
- {
- $title.= ' ('.implode(', ', $details).')';
- }
-
- if (!empty($info['comment']))
- {
- $info['comment'] = trigger_event('render_element_description', $info['comment']);
- $title.= ' '.substr($info['comment'], 0, 100).(strlen($info['comment']) > 100 ? '...' : '');
- }
-
- $title = htmlspecialchars(strip_tags($title));
-
- $title = trigger_event('get_thumbnail_title', $title, $info);
-
- return $title;
-}
-
-/**
* fill the current user caddie with given elements, if not already in
* caddie
*
@@ -904,18 +859,6 @@ function get_name_from_file($filename)
}
/**
- */
-function get_picture_title($info)
-{
- if (isset($info['name']) and !empty($info['name']))
- {
- return trigger_event('render_element_description', $info['name']);
- }
-
- return get_name_from_file($info['file']);
-}
-
-/**
* returns the corresponding value from $lang if existing. Else, the key is
* returned
*
@@ -1435,8 +1378,8 @@ function get_ephemeral_key($valid_after_seconds, $aditionnal_data_to_hash = '')
$time = round(microtime(true), 1);
return $time.':'.$valid_after_seconds.':'
.hash_hmac(
- 'md5',
- $time.substr($_SERVER['REMOTE_ADDR'],0,5).$valid_after_seconds.$aditionnal_data_to_hash,
+ 'md5',
+ $time.substr($_SERVER['REMOTE_ADDR'],0,5).$valid_after_seconds.$aditionnal_data_to_hash,
$conf['secret_key']);
}
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index ce327cc0c..a546f6880 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -178,7 +178,7 @@ SELECT id, name, permalink
<a href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$cat['name'].'</a>';
}
}
-
+
if ($single_link and isset($single_url))
{
$output.= '</a>';
@@ -295,7 +295,7 @@ function name_compare($a, $b)
function tag_alpha_compare($a, $b)
{
global $page;
-
+
foreach (array($a, $b) as $tag)
{
if (!isset($page[__FUNCTION__.'_cache'][ $tag['name'] ]))
@@ -533,4 +533,68 @@ function register_default_menubar_blocks( $menu_ref_arr )
$menu->register_block( new RegisteredBlock( 'mbIdentification', 'Identification', 'piwigo') );
}
+/**
+ */
+function render_element_name($info)
+{
+ $name = $info['name'];
+ if (!empty($name))
+ {
+ $name = trigger_event('render_element_description', $name);
+ return $name;
+ }
+
+ return get_name_from_file($info['file']);
+}
+
+function render_element_description($info)
+{
+ $comment = $info['comment'];
+ if (!empty($comment))
+ {
+ $comment = trigger_event('render_element_description', $comment);
+ return $comment;
+ }
+ return '';
+}
+
+/**
+ * returns the title of the thumbnail based on photo properties
+ */
+function get_thumbnail_title($info, $title, $comment)
+{
+ global $conf, $user;
+
+ $details = array();
+
+ if (!empty($info['hit']))
+ {
+ $details[] = $info['hit'].' '.strtolower(l10n('Visits'));
+ }
+
+ if ($conf['rate'] and !empty($info['rating_score']))
+ {
+ $details[] = strtolower(l10n('Rating score')).' '.$info['rating_score'];
+ }
+
+ if (isset($info['nb_comments']) and $info['nb_comments'] != 0)
+ {
+ $details[] = l10n_dec('%d comment', '%d comments', $info['nb_comments']);
+ }
+
+ if (count($details) > 0)
+ {
+ $title.= ' ('.implode(', ', $details).')';
+ }
+
+ if (!empty($comment))
+ {
+ $title.= ' '.substr($info['comment'], 0, 100).(strlen($info['comment']) > 100 ? '...' : '');
+ }
+
+ $title = htmlspecialchars(strip_tags($title));
+ $title = trigger_event('get_thumbnail_title', $title, $info);
+ return $title;
+}
+
?> \ No newline at end of file
diff --git a/include/functions_picture.inc.php b/include/functions_picture.inc.php
index 85de60b14..aac3e45b1 100644
--- a/include/functions_picture.inc.php
+++ b/include/functions_picture.inc.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -22,25 +22,6 @@
// +-----------------------------------------------------------------------+
-
-/*
- * Returns the name of a photo according to its name and its filename.
- * @param name string
- * @param filename string
- * @return string
- */
-function get_image_name($name, $filename)
-{
- if (!empty($name))
- {
- return $name;
- }
- else
- {
- return get_name_from_file($filename);
- }
-}
-
/*
* @param element_info array containing element information from db;
* at least 'id', 'path', 'has_high' should be present
@@ -249,4 +230,4 @@ function get_picture_size( $original_width, $original_height,
return $picture_size;
}
-?>
+?> \ No newline at end of file
diff --git a/include/template.class.php b/include/template.class.php
index 7bcab1150..90d7d58b8 100644
--- a/include/template.class.php
+++ b/include/template.class.php
@@ -22,9 +22,6 @@
// +-----------------------------------------------------------------------+
-require_once(PHPWG_ROOT_PATH.'include/smarty/libs/Smarty.class.php');
-
-
class Template {
var $smarty;
@@ -42,6 +39,7 @@ class Template {
// used by html_head smarty block to add content before </head>
var $html_head_elements = array();
+ private $html_style = '';
const COMBINED_SCRIPTS_TAG = '<!-- COMBINED_SCRIPTS -->';
var $scriptLoader;
@@ -112,6 +110,7 @@ class Template {
$this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') );
$this->smarty->register_modifier( 'get_extent', array(&$this, 'get_extent') );
$this->smarty->register_block('html_head', array(&$this, 'block_html_head') );
+ $this->smarty->register_block('html_style', array(&$this, 'block_html_style') );
$this->smarty->register_function('combine_script', array(&$this, 'func_combine_script') );
$this->smarty->register_function('get_combined_scripts', array(&$this, 'func_get_combined_scripts') );
$this->smarty->register_function('combine_css', array(&$this, 'func_combine_css') );
@@ -466,15 +465,21 @@ class Template {
$this->css_by_priority = array();
}
- if ( count($this->html_head_elements) )
+ if ( count($this->html_head_elements) || strlen($this->html_style) )
{
$search = "\n</head>";
$pos = strpos( $this->output, $search );
if ($pos !== false)
{
- $this->output = substr_replace( $this->output, "\n".implode( "\n", $this->html_head_elements ), $pos, 0 );
+ $rep = "\n".implode( "\n", $this->html_head_elements );
+ if (strlen($this->html_style))
+ {
+ $rep='<style type="text/css">'.$this->html_style.'</style>';
+ }
+ $this->output = substr_replace( $this->output, $rep, $pos, 0 );
} //else maybe error or warning ?
$this->html_head_elements = array();
+ $this->html_style = '';
}
echo $this->output;
@@ -532,6 +537,15 @@ class Template {
}
}
+ function block_html_style($params, $content, &$smarty, &$repeat)
+ {
+ $content = trim($content);
+ if ( !empty($content) )
+ { // second call
+ $this->html_style .= $content;
+ }
+ }
+
/**
* combine_script smarty function allows inclusion of a javascript file in the current page.
* The engine will combine several js files into a single one in order to reduce the number of
@@ -842,7 +856,7 @@ class PwgTemplateAdapter
$args = func_get_args();
return call_user_func_array('sprintf', $args );
}
-
+
function derivative_url($type, $img)
{
return DerivativeImage::url($type, $img);