aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/category_default.inc.php16
-rw-r--r--include/functions.inc.php81
-rw-r--r--picture.php16
3 files changed, 73 insertions, 40 deletions
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index 652f31f50..b1f7bc46a 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -49,7 +49,7 @@ SELECT *
WHERE id IN ('.implode(',', $selection).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
+ while ($row = mysql_fetch_assoc($result))
{
$row['rank'] = $page['rank_of'][ $row['id'] ];
@@ -60,19 +60,20 @@ SELECT *
}
// template thumbnail initialization
-$template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
+$template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
if (count($pictures) > 0)
{
- $template->assign_block_vars('thumbnails', array());
// first line
$template->assign_block_vars('thumbnails.line', array());
// current row displayed
$row_number = 0;
}
+trigger_action('loc_begin_index_thumbnails', $pictures);
+
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
$thumbnail_title = $row['file'];
@@ -80,7 +81,7 @@ foreach ($pictures as $row)
{
$thumbnail_title .= ' : '.$row['filesize'].' KB';
}
-
+
// link on picture.php page
$url = duplicate_picture_url(
array(
@@ -159,6 +160,9 @@ SELECT COUNT(*) AS 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 ?
if (++$row_number == $user['nb_image_line'])
{
@@ -166,6 +170,8 @@ SELECT COUNT(*) AS nb_comments
$row_number = 0;
}
}
+
+trigger_action('loc_end_index_thumbnails', $pictures);
$template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
pwg_debug('end include/category_default.inc.php');
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 973bd2fbe..68e06b579 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -681,45 +681,78 @@ function get_pwg_themes()
}
/**
- * returns thumbnail filepath (or distant URL if thumbnail is remote) for a
- * 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
+DEPRECATED use get_thumbnail_path or get_thumbnail_url
*/
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(
- get_filename_wo_extension($path),
+ $path = PHPWG_ROOT_PATH.$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'],
- strrpos($path,'/'),
+ strrpos($element_info['path'],'/'),
1
);
- $src.= '.'.$tn_ext;
- if ($with_rewrite==true and !url_is_remote($src) )
- {
- $src = get_root_url().$src;
- }
+ $path.= '.'.$element_info['tn_ext'];
}
else
{
- $src = ($with_rewrite==true) ? get_root_url() : '';
- $src .= get_themeconf('mime_icon_dir');
- $src.= strtolower(get_extension($path)).'.png';
+ $path = get_themeconf('mime_icon_dir')
+ .strtolower(get_extension($element_info['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
// error occured for the last mysql query.
function my_error($header)
diff --git a/picture.php b/picture.php
index 69b28a7cc..dd7ffa3ae 100644
--- a/picture.php
+++ b/picture.php
@@ -81,8 +81,8 @@ function default_picture_content($content, $element_info)
$my_template->assign_vars( array(
'SRC_IMG' => $element_info['image_url'],
'ALT_IMG' => $element_info['file'],
- 'WIDTH_IMG' => $element_info['scaled_width'],
- 'HEIGHT_IMG' => $element_info['scaled_height'],
+ 'WIDTH_IMG' => @$element_info['scaled_width'],
+ 'HEIGHT_IMG' => @$element_info['scaled_height'],
)
);
return $my_template->parse( 'default_content', true);
@@ -279,7 +279,7 @@ SELECT *
$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'])
{
@@ -302,13 +302,7 @@ while ($row = mysql_fetch_array($result))
$i = 'current';
}
- foreach (array_keys($row) as $key)
- {
- if (!is_numeric($key))
- {
- $picture[$i][$key] = $row[$key];
- }
- }
+ $picture[$i] = $row;
$picture[$i]['is_picture'] = false;
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'] ) )
{