aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php47
-rw-r--r--admin/infos_images.php4
-rw-r--r--admin/picture_modify.php4
-rw-r--r--admin/remote_site.php52
-rw-r--r--admin/update.php53
-rw-r--r--comments.php6
-rw-r--r--include/category_calendar.inc.php24
-rw-r--r--include/category_default.inc.php6
-rw-r--r--include/category_recent_cats.inc.php8
-rw-r--r--include/category_subcats.inc.php5
-rw-r--r--include/functions.inc.php35
-rw-r--r--install/dbscheme.txt1
-rw-r--r--install/phpwebgallery_structure.sql1
-rw-r--r--picture.php15
-rw-r--r--tools/create_listing_file.php12
15 files changed, 103 insertions, 170 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 54ec9d8b2..63f59471b 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -784,4 +784,51 @@ function my_error($header, $echo = true)
return $error;
}
}
+
+/**
+ * inserts multiple lines in a table
+ *
+ * @param string table_name
+ * @param array dbields
+ * @param array inserts
+ * @return void
+ */
+function mass_inserts($table_name, $dbfields, $inserts)
+{
+ // inserts all found categories
+ $query = '
+INSERT INTO '.$table_name.'
+ ('.implode(',', $dbfields).')
+ VALUES';
+ foreach ($inserts as $insert_id => $insert)
+ {
+ $query.= '
+ ';
+ if ($insert_id > 0)
+ {
+ $query.= ',';
+ }
+ $query.= '(';
+ foreach ($dbfields as $field_id => $dbfield)
+ {
+ if ($field_id > 0)
+ {
+ $query.= ',';
+ }
+
+ if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
+ {
+ $query.= 'NULL';
+ }
+ else
+ {
+ $query.= "'".$insert[$dbfield]."'";
+ }
+ }
+ $query.=')';
+ }
+ $query.= '
+;';
+ pwg_query($query);
+}
?>
diff --git a/admin/infos_images.php b/admin/infos_images.php
index 0f13b829e..9c055a830 100644
--- a/admin/infos_images.php
+++ b/admin/infos_images.php
@@ -319,9 +319,7 @@ SELECT *
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
- $thumbnail_url = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+ $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
$template->assign_block_vars(
'picture',
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index 90d99d5fa..476ddb359 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -199,9 +199,7 @@ else
$current_category = get_cat_info($row['storage_category_id']);
$dir_path = get_cat_display_name($current_category['name'], '->', '');
-$thumbnail_url = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
$url_img .= '&cat='.$row['storage_category_id'];
diff --git a/admin/remote_site.php b/admin/remote_site.php
index 5aaf1a08f..082658ab0 100644
--- a/admin/remote_site.php
+++ b/admin/remote_site.php
@@ -112,53 +112,6 @@ SELECT id,dir
}
/**
- * inserts multiple lines in a table
- *
- * @param string table_name
- * @param array dbields
- * @param array inserts
- * @return void
- */
-function mass_inserts($table_name, $dbfields, $inserts)
-{
- // inserts all found categories
- $query = '
-INSERT INTO '.$table_name.'
- ('.implode(',', $dbfields).')
- VALUES';
- foreach ($inserts as $insert_id => $insert)
- {
- $query.= '
- ';
- if ($insert_id > 0)
- {
- $query.= ',';
- }
- $query.= '(';
- foreach ($dbfields as $field_id => $dbfield)
- {
- if ($field_id > 0)
- {
- $query.= ',';
- }
-
- if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
- {
- $query.= 'NULL';
- }
- else
- {
- $query.= "'".$insert[$dbfield]."'";
- }
- }
- $query.=')';
- }
- $query.= '
-;';
- pwg_query($query);
-}
-
-/**
* read $listing_file and update a remote site according to its id
*
* @param string listing_file
@@ -418,7 +371,8 @@ SELECT file
'author',
'keywords',
'name',
- 'comment');
+ 'comment',
+ 'path');
foreach ($optional_atts as $att)
{
if (getAttribute($xml_element, $att) != '')
@@ -434,7 +388,7 @@ SELECT file
{
$dbfields = array('file','storage_category_id','date_available','tn_ext',
'filesize','width','height','date_creation','author',
- 'keywords','name','comment');
+ 'keywords','name','comment','path');
mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
$counts{'new_elements'}+= count($inserts);
diff --git a/admin/update.php b/admin/update.php
index fc920ebb6..817a67aae 100644
--- a/admin/update.php
+++ b/admin/update.php
@@ -31,7 +31,7 @@ if( !defined("PHPWG_ROOT_PATH") )
}
include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
-define('CURRENT_DATE', "'".date('Y-m-d')."'");
+define('CURRENT_DATE', date('Y-m-d'));
// +-----------------------------------------------------------------------+
// | functions |
// +-----------------------------------------------------------------------+
@@ -407,10 +407,11 @@ SELECT file
if ($tn_ext != '')
{
$insert = array();
- $insert['file'] = "'".$unregistered_element."'";
+ $insert['file'] = $unregistered_element;
$insert['storage_category_id'] = $category_id;
$insert['date_available'] = CURRENT_DATE;
- $insert['tn_ext'] = "'".$tn_ext."'";
+ $insert['tn_ext'] = $tn_ext;
+ $insert['path'] = $dir.$unregistered_element;
$counts['new_elements']++;
array_push($inserts, $insert);
@@ -446,16 +447,17 @@ SELECT file
}
$insert = array();
- $insert['file'] = "'".$unregistered_element."'";
+ $insert['file'] = $unregistered_element;
+ $insert['path'] = $dir.$unregistered_element;
$insert['storage_category_id'] = $category_id;
$insert['date_available'] = CURRENT_DATE;
if ( $tn_ext != '' )
{
- $insert['tn_ext'] = "'".$tn_ext."'";
+ $insert['tn_ext'] = $tn_ext;
}
if ( $representative_ext != '' )
{
- $insert['representative_ext'] = "'".$representative_ext."'";
+ $insert['representative_ext'] = $representative_ext;
}
$counts['new_elements']++;
@@ -475,44 +477,9 @@ SELECT file
// inserts all found pictures
$dbfields = array(
'file','storage_category_id','date_available','tn_ext'
- ,'representative_ext'
+ ,'representative_ext','path'
);
- $query = '
-INSERT INTO '.IMAGES_TABLE.'
- ('.implode(',', $dbfields).')
- VALUES
- ';
- foreach ($inserts as $insert_id => $insert)
- {
- $query.= '
-';
- if ($insert_id > 0)
- {
- $query.= ',';
- }
- $query.= '(';
- foreach ($dbfields as $field_id => $dbfield)
- {
- if ($field_id > 0)
- {
- $query.= ',';
- }
-
- if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
- {
- $query.= 'NULL';
- }
- else
- {
- $query.= $insert[$dbfield];
- }
- }
- $query.=')';
- }
- $query.= '
-;';
-
- pwg_query($query);
+ mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
// what are the ids of the pictures in the $category_id ?
$ids = array();
diff --git a/comments.php b/comments.php
index d3f699e25..230de3406 100644
--- a/comments.php
+++ b/comments.php
@@ -140,7 +140,7 @@ while ($row = mysql_fetch_array($result))
// for each picture, getting informations for displaying thumbnail and
// link to the full size picture
$query = '
-SELECT name,file,storage_category_id as cat_id,tn_ext
+SELECT name,file,storage_category_id as cat_id,tn_ext,path
FROM '.IMAGES_TABLE.'
WHERE id = '.$row['image_id'].'
;';
@@ -166,9 +166,7 @@ SELECT name,file,storage_category_id as cat_id,tn_ext
}
$name.= ' [ '.$subrow['file'].' ]';
// source of the thumbnail picture
- $thumbnail_src = get_thumbnail_src($subrow['file'],
- $subrow['cat_id'],
- @$subrow['tn_ext']);
+ $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
// link to the full size picture
$url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
$url.= '&image_id='.$row['image_id'];
diff --git a/include/category_calendar.inc.php b/include/category_calendar.inc.php
index ad0ca1b3c..5c13e940a 100644
--- a/include/category_calendar.inc.php
+++ b/include/category_calendar.inc.php
@@ -219,7 +219,7 @@ if (!isset($page['calendar_year']))
foreach ($calendar_years as $calendar_year => $nb_pics)
{
$query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
'.$page['where'].'
AND YEAR('.$conf['calendar_datefield'].') = '.$calendar_year.'
@@ -229,9 +229,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
;';
$row = mysql_fetch_array(pwg_query($query));
- $thumbnail_src = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+ $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
$name = $calendar_year.' ('.$nb_pics.')';
@@ -266,7 +264,7 @@ elseif (!isset($page['calendar_month']))
foreach ($calendar_months as $calendar_month => $nb_pics)
{
$query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
'.$page['where'].'
AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
@@ -277,9 +275,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
;';
$row = mysql_fetch_array(pwg_query($query));
- $thumbnail_src = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+ $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
$name = $lang['month'][$calendar_month];
$name.= ' '.$page['calendar_year'];
@@ -322,7 +318,7 @@ elseif (!isset($page['calendar_day']))
foreach ($calendar_days as $calendar_day => $nb_pics)
{
$query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
'.$page['where'].'
AND '.$conf['calendar_datefield'].' = \''.$calendar_day.'\'
@@ -332,9 +328,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
;';
$row = mysql_fetch_array(pwg_query($query));
- $thumbnail_src = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+ $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
list($year,$month,$day) = explode('-', $calendar_day);
$unixdate = mktime(0,0,0,$month,$day,$year);
@@ -385,7 +379,7 @@ elseif (isset($page['calendar_day']))
$name.= ' ('.$nb_pics.')';
$query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
'.$page['where'].'
AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'';
@@ -401,9 +395,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
;';
$row = mysql_fetch_array(pwg_query($query));
- $thumbnail_src = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+ $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
$thumbnail_title = $lang['calendar_picture_hint'].$name;
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index b092f3c7a..2e89be05b 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -38,7 +38,7 @@
$array_cat_directories = array();
$query = '
-SELECT DISTINCT(id),file,date_available,category_id
+SELECT DISTINCT(id),path,file,date_available,category_id
,tn_ext,name,filesize,storage_category_id,average_rate
FROM '.IMAGES_TABLE.' AS i
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id
@@ -80,9 +80,7 @@ while ($row = mysql_fetch_array($result))
$name = replace_search($name, $_GET['search']);
}
- $thumbnail_url = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+ $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
// message in title for the thumbnail
$thumbnail_title = $row['file'];
diff --git a/include/category_recent_cats.inc.php b/include/category_recent_cats.inc.php
index 7d4de1c57..3da82c1f8 100644
--- a/include/category_recent_cats.inc.php
+++ b/include/category_recent_cats.inc.php
@@ -66,7 +66,7 @@ while ( $row = mysql_fetch_array( $result ) )
$name = get_cat_display_name($cat_infos['name'],'<br />','',false);
$query = '
-SELECT id,file,tn_ext,storage_category_id
+SELECT path,file,tn_ext
FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$row['category_id'].'
AND date_available > SUBDATE(CURRENT_DATE
@@ -75,11 +75,9 @@ SELECT id,file,tn_ext,storage_category_id
ORDER BY RAND()
LIMIT 0,1
;';
- $subrow = mysql_fetch_array( pwg_query( $query ) );
+ $subrow = mysql_fetch_array(pwg_query($query));
- $thumbnail_src = get_thumbnail_src($subrow['file'],
- $subrow['storage_category_id'],
- @$subrow['tn_ext']);
+ $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
$url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id'];
diff --git a/include/category_subcats.inc.php b/include/category_subcats.inc.php
index 53e4f7f0d..6fe0eece7 100644
--- a/include/category_subcats.inc.php
+++ b/include/category_subcats.inc.php
@@ -64,7 +64,7 @@ SELECT representative_picture_id
$row = mysql_fetch_array(pwg_query($query));
$query = '
-SELECT file,tn_ext,storage_category_id
+SELECT file,path,tn_ext
FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$non_empty_id.'
AND id = image_id';
@@ -86,8 +86,7 @@ SELECT file,tn_ext,storage_category_id
$image_result = pwg_query($query);
$image_row = mysql_fetch_array($image_result);
- $thumbnail_link = get_thumbnail_src($image_row['file'],
- $image_row['storage_category_id'],
+ $thumbnail_link = get_thumbnail_src($image_row['path'],
@$image_row['tn_ext']);
$thumbnail_title = $lang['hint_category'];
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 8903c28d5..860811c3c 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -570,47 +570,32 @@ function get_templates()
* returns thumbnail filepath (or distant URL if thumbnail is remote) for a
* given element
*
- * this function could have taken only the element id as parameter but to
- * optimize database access we directly ask file, storage category
- * identifier and extension since when this function is called,
- * PhpWebGallery should have all these infos. No need to retrieve them
- * another time in the database.
- *
* the returned string can represente the filepath of the thumbnail or the
* filepath to the corresponding icon for non picture elements
*
- * complete directories are cached to be used more than once during a page
- * generation (many thumbnails of the same category on the same page)
- *
- * @param string file
- * @param int storage_category_id
+ * @param string path
* @param string tn_ext
* @return string
*/
-function get_thumbnail_src($file, $storage_category_id, $tn_ext = '')
+function get_thumbnail_src($path, $tn_ext = '')
{
- global $conf, $user, $array_cat_directories;
-
- if (!isset($array_cat_directories[$storage_category_id]))
- {
- $array_cat_directories[$storage_category_id] =
- get_complete_dir($storage_category_id);
- }
-
+ global $conf, $user;
+
if ($tn_ext != '')
{
- $src = $array_cat_directories[$storage_category_id];
- $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
- $src.= get_filename_wo_extension($file);
+ $src = substr_replace(get_filename_wo_extension($path),
+ '/thumbnail/'.$conf['prefix_thumbnail'],
+ strrpos($path,'/'),
+ 1);
$src.= '.'.$tn_ext;
}
else
{
$src = PHPWG_ROOT_PATH;
$src.= 'template/'.$user['template'].'/mimetypes/';
- $src.= strtolower(get_extension($file)).'.png';
+ $src.= strtolower(get_extension($path)).'.png';
}
-
+
return $src;
}
?>
diff --git a/install/dbscheme.txt b/install/dbscheme.txt
index b190134b5..070f7f0bc 100644
--- a/install/dbscheme.txt
+++ b/install/dbscheme.txt
@@ -71,6 +71,7 @@ column:storage_category_id table:images type:smallint
column:representative_ext table:images type:varchar nullable:Y length:4 binary:N
column:date_metadata_update table:images type:date nullable:Y
column:average_rate table:images type:float nullable:Y length:5,2 signed:N
+column:path table:images type:varchar nullable:N length:255 binary:N
column:user_id table:rate type:smallint nullable:N length:5 signed:N
column:element_id table:rate type:mediumint nullable:N length:8 signed:N
column:rate table:rate type:tinyint nullable:N length:2 signed:N
diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql
index b45845675..d9dbf2161 100644
--- a/install/phpwebgallery_structure.sql
+++ b/install/phpwebgallery_structure.sql
@@ -140,6 +140,7 @@ CREATE TABLE phpwebgallery_images (
representative_ext varchar(4) default NULL,
date_metadata_update date default NULL,
average_rate float(5,2) unsigned default NULL,
+ path varchar(255) NOT NULL default '',
PRIMARY KEY (id),
KEY images_i2 (date_available),
KEY images_i1 (storage_category_id),
diff --git a/picture.php b/picture.php
index 8698a0167..7e1af41d2 100644
--- a/picture.php
+++ b/picture.php
@@ -142,12 +142,7 @@ foreach (array('prev', 'current', 'next') as $i)
$picture[$i]['is_picture'] = true;
}
- if ( !isset($array_cat_directories[$row['storage_category_id']]))
- {
- $array_cat_directories[$row['storage_category_id']] =
- get_complete_dir( $row['storage_category_id'] );
- }
- $cat_directory = $array_cat_directories[$row['storage_category_id']];
+ $cat_directory = dirname($row['path']);
$file_wo_ext = get_filename_wo_extension($row['file']);
$icon = './template/'.$user['template'].'/mimetypes/';
@@ -165,7 +160,7 @@ foreach (array('prev', 'current', 'next') as $i)
// special case for picture files
if ($picture[$i]['is_picture'])
{
- $picture[$i]['src'] = $cat_directory.$row['file'];
+ $picture[$i]['src'] = $row['path'];
// if we are working on the "current" element, we search if there is a
// high quality picture
// FIXME : with remote pictures, this "remote fopen" takes long...
@@ -181,12 +176,10 @@ foreach (array('prev', 'current', 'next') as $i)
// if picture is not a file, we need the download link
if (!$picture[$i]['is_picture'])
{
- $picture[$i]['download'] = $cat_directory.$row['file'];
+ $picture[$i]['download'] = $row['path'];
}
- $picture[$i]['thumbnail'] = get_thumbnail_src($row['file'],
- $row['storage_category_id'],
- @$row['tn_ext']);
+ $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
if ( !empty( $row['name'] ) )
{
diff --git a/tools/create_listing_file.php b/tools/create_listing_file.php
index 569f5f5d8..63c992cea 100644
--- a/tools/create_listing_file.php
+++ b/tools/create_listing_file.php
@@ -310,7 +310,7 @@ function get_filename_wo_extension($filename)
function get_pictures($dir, $indent)
{
- global $conf;
+ global $conf, $page;
// fs means FileSystem : $fs_files contains files in the filesystem found
// in $dir that can be managed by PhpWebGallery (see get_pwg_files
@@ -321,11 +321,15 @@ function get_pictures($dir, $indent)
$fs_representatives = get_representative_files($dir);
$elements = array();
+
+ $print_dir = preg_replace('/^\.\//', '', $dir);
+ $print_dir = preg_replace('/\/*$/', '/', $print_dir);
foreach ($fs_files as $fs_file)
{
$element = array();
$element['file'] = $fs_file;
+ $element['path'] = $page['url'].$print_dir.$fs_file;
$element['filesize'] = floor(filesize($dir.'/'.$fs_file) / 1024);
$file_wo_ext = get_filename_wo_extension($fs_file);
@@ -420,7 +424,7 @@ function get_pictures($dir, $indent)
$xml = "\n".$indent.'<root>';
$attributes = array('file','tn_ext','representative_ext','filesize',
'width','height','date_creation','author','keywords',
- 'name','comment');
+ 'name','comment','path');
foreach ($elements as $element)
{
$xml.= "\n".$indent.' ';
@@ -463,9 +467,9 @@ switch ($page['action'])
$end = strrpos($_SERVER['PHP_SELF'], '/') + 1;
$local_folder = substr($_SERVER['PHP_SELF'], 0, $end);
- $url = 'http://'.$_SERVER['HTTP_HOST'].$local_folder;
+ $page['url'] = 'http://'.$_SERVER['HTTP_HOST'].$local_folder;
- $listing.= ' url="'.$url.'"';
+ $listing.= ' url="'.$page['url'].'"';
$listing.= '/>'."\n";
$listing.= get_dirs('.', '', 0);