- deprecated get_thumbnail_src (still there for compatibility). use rather

get_thumbnail_path or get_thumbnail_url (these allow plugins to override)
- plugins can hook into index thumbnail display (items only so far)

git-svn-id: http://piwigo.org/svn/trunk@1596 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2006-11-07 03:37:57 +00:00
parent eb4214096f
commit 8f52e36a6f
3 changed files with 73 additions and 40 deletions

View file

@ -49,7 +49,7 @@ SELECT *
WHERE id IN ('.implode(',', $selection).') WHERE id IN ('.implode(',', $selection).')
;'; ;';
$result = pwg_query($query); $result = pwg_query($query);
while ($row = mysql_fetch_array($result)) while ($row = mysql_fetch_assoc($result))
{ {
$row['rank'] = $page['rank_of'][ $row['id'] ]; $row['rank'] = $page['rank_of'][ $row['id'] ];
@ -63,16 +63,17 @@ SELECT *
$template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',)); $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
if (count($pictures) > 0) if (count($pictures) > 0)
{ {
$template->assign_block_vars('thumbnails', array());
// first line // first line
$template->assign_block_vars('thumbnails.line', array()); $template->assign_block_vars('thumbnails.line', array());
// current row displayed // current row displayed
$row_number = 0; $row_number = 0;
} }
trigger_action('loc_begin_index_thumbnails', $pictures);
foreach ($pictures as $row) foreach ($pictures as $row)
{ {
$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']); $thumbnail_url = get_thumbnail_url($row);
// message in title for the thumbnail // message in title for the thumbnail
$thumbnail_title = $row['file']; $thumbnail_title = $row['file'];
@ -159,6 +160,9 @@ SELECT COUNT(*) AS nb_comments
array('NB_COMMENTS'=>$row['nb_comments'])); array('NB_COMMENTS'=>$row['nb_comments']));
} }
//plugins need to add/modify sth in this loop ?
trigger_action('loc_index_thumbnail', $row, 'thumbnails.line.thumbnail' );
// create a new line ? // create a new line ?
if (++$row_number == $user['nb_image_line']) if (++$row_number == $user['nb_image_line'])
{ {
@ -166,6 +170,8 @@ SELECT COUNT(*) AS nb_comments
$row_number = 0; $row_number = 0;
} }
} }
trigger_action('loc_end_index_thumbnails', $pictures);
$template->assign_var_from_handle('THUMBNAILS', 'thumbnails'); $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
pwg_debug('end include/category_default.inc.php'); pwg_debug('end include/category_default.inc.php');

View file

@ -681,45 +681,78 @@ function get_pwg_themes()
} }
/** /**
* returns thumbnail filepath (or distant URL if thumbnail is remote) for a DEPRECATED use get_thumbnail_path or get_thumbnail_url
* given element
*
* the returned string can represente the filepath of the thumbnail or the
* filepath to the corresponding icon for non picture elements
*
* @param string path
* @param string tn_ext
* @param bool with_rewrite if true returned path can't be used from the script
* @return string
*/ */
function get_thumbnail_src($path, $tn_ext = '', $with_rewrite = true) function get_thumbnail_src($path, $tn_ext = '', $with_rewrite = true)
{ {
global $conf, $user; if ($with_rewrite)
return get_thumbnail_url( array('path'=>$path, 'tn_ext'=>$tn_ext) );
else
return get_thumbnail_path( array('path'=>$path, 'tn_ext'=>$tn_ext) );
}
if ($tn_ext != '') /* Returns the PATH to the thumbnail to be displayed. If the element does not
* have a thumbnail, the default mime image path is returned. The PATH can be
* used in the php script, but not sent to the browser.
* @param array element_info assoc array containing element info from db
* at least 'path', 'tn_ext' and 'id' should be present
*/
function get_thumbnail_path($element_info)
{
$path = get_thumbnail_location($element_info);
if ( !url_is_remote($path) )
{ {
$src = substr_replace( $path = PHPWG_ROOT_PATH.$path;
get_filename_wo_extension($path), }
return $path;
}
/* Returns the URL of the thumbnail to be displayed. If the element does not
* have a thumbnail, the default mime image url is returned. The URL can be
* sent to the browser, but not used in the php script.
* @param array element_info assoc array containing element info from db
* at least 'path', 'tn_ext' and 'id' should be present
*/
function get_thumbnail_url($element_info)
{
$path = get_thumbnail_location($element_info);
if ( !url_is_remote($path) )
{
$path = get_root_url().$path;
}
// plugins want another url ?
$path = trigger_event('get_thumbnail_url', $path, $element_info);
return $path;
}
/* returns the relative path of the thumnail with regards to to the root
of phpwebgallery (not the current page!).This function is not intended to be
called directly from code.*/
function get_thumbnail_location($element_info)
{
global $conf;
if ( !empty( $element_info['tn_ext'] ) )
{
$path = substr_replace(
get_filename_wo_extension($element_info['path']),
'/thumbnail/'.$conf['prefix_thumbnail'], '/thumbnail/'.$conf['prefix_thumbnail'],
strrpos($path,'/'), strrpos($element_info['path'],'/'),
1 1
); );
$src.= '.'.$tn_ext; $path.= '.'.$element_info['tn_ext'];
if ($with_rewrite==true and !url_is_remote($src) )
{
$src = get_root_url().$src;
}
} }
else else
{ {
$src = ($with_rewrite==true) ? get_root_url() : ''; $path = get_themeconf('mime_icon_dir')
$src .= get_themeconf('mime_icon_dir'); .strtolower(get_extension($element_info['path'])).'.png';
$src.= strtolower(get_extension($path)).'.png';
} }
return $src; // plugins want another location ?
$path = trigger_event( 'get_thumbnail_location', $path, $element_info);
return $path;
} }
// my_error returns (or send to standard output) the message concerning the // my_error returns (or send to standard output) the message concerning the
// error occured for the last mysql query. // error occured for the last mysql query.
function my_error($header) function my_error($header)

View file

@ -81,8 +81,8 @@ function default_picture_content($content, $element_info)
$my_template->assign_vars( array( $my_template->assign_vars( array(
'SRC_IMG' => $element_info['image_url'], 'SRC_IMG' => $element_info['image_url'],
'ALT_IMG' => $element_info['file'], 'ALT_IMG' => $element_info['file'],
'WIDTH_IMG' => $element_info['scaled_width'], 'WIDTH_IMG' => @$element_info['scaled_width'],
'HEIGHT_IMG' => $element_info['scaled_height'], 'HEIGHT_IMG' => @$element_info['scaled_height'],
) )
); );
return $my_template->parse( 'default_content', true); return $my_template->parse( 'default_content', true);
@ -279,7 +279,7 @@ SELECT *
$result = pwg_query($query); $result = pwg_query($query);
while ($row = mysql_fetch_array($result)) while ($row = mysql_fetch_assoc($result))
{ {
if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
{ {
@ -302,13 +302,7 @@ while ($row = mysql_fetch_array($result))
$i = 'current'; $i = 'current';
} }
foreach (array_keys($row) as $key) $picture[$i] = $row;
{
if (!is_numeric($key))
{
$picture[$i][$key] = $row[$key];
}
}
$picture[$i]['is_picture'] = false; $picture[$i]['is_picture'] = false;
if (in_array(get_extension($row['file']), $conf['picture_ext'])) if (in_array(get_extension($row['file']), $conf['picture_ext']))
@ -380,7 +374,7 @@ while ($row = mysql_fetch_array($result))
} }
} }
$picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']); $picture[$i]['thumbnail'] = get_thumbnail_url($row);
if ( !empty( $row['name'] ) ) if ( !empty( $row['name'] ) )
{ {