mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-28 12:19:57 +03:00
feature #379 multiple format, step 1: add formats
* new table piwigo_image_format (each photo can have 0 to many formats) * only compatible with synchronization for now. Formats must be in sub-directory pwg_format * formats are visible on edition page only for now
This commit is contained in:
parent
27389102d1
commit
8e098d502a
10 changed files with 191 additions and 0 deletions
|
@ -180,6 +180,25 @@ function delete_element_files($ids)
|
|||
}
|
||||
|
||||
$new_ids = array();
|
||||
$formats_of = array();
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
image_id,
|
||||
ext
|
||||
FROM '.IMAGE_FORMAT_TABLE.'
|
||||
WHERE image_id IN ('.implode(',', $ids).')
|
||||
;';
|
||||
$result = pwg_query($query);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
if (!isset($formats_of[ $row['image_id'] ]))
|
||||
{
|
||||
$formats_of[ $row['image_id'] ] = array();
|
||||
}
|
||||
|
||||
$formats_of[ $row['image_id'] ][] = $row['ext'];
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
|
@ -205,6 +224,14 @@ SELECT
|
|||
$files[] = original_to_representative( $files[0], $row['representative_ext']);
|
||||
}
|
||||
|
||||
if (isset($formats_of[ $row['id'] ]))
|
||||
{
|
||||
foreach ($formats_of[ $row['id'] ] as $format_ext)
|
||||
{
|
||||
$files[] = original_to_format($files[0], $format_ext);
|
||||
}
|
||||
}
|
||||
|
||||
$ok = true;
|
||||
if (!isset($conf['never_delete_originals']))
|
||||
{
|
||||
|
@ -277,6 +304,13 @@ DELETE FROM '.IMAGE_CATEGORY_TABLE.'
|
|||
;';
|
||||
pwg_query($query);
|
||||
|
||||
// destruction of the formats
|
||||
$query = '
|
||||
DELETE FROM '.IMAGE_FORMAT_TABLE.'
|
||||
WHERE image_id IN ('. $ids_str .')
|
||||
;';
|
||||
pwg_query($query);
|
||||
|
||||
// destruction of the links between images and tags
|
||||
$query = '
|
||||
DELETE FROM '.IMAGE_TAG_TABLE.'
|
||||
|
@ -540,6 +574,7 @@ function get_fs_directories($path, $recursive = true)
|
|||
'.', '..', '.svn',
|
||||
'thumbnail', 'pwg_high',
|
||||
'pwg_representative',
|
||||
'pwg_format',
|
||||
)
|
||||
);
|
||||
$exclude_folders = array_flip($exclude_folders);
|
||||
|
|
|
@ -306,6 +306,25 @@ SELECT
|
|||
$intro_vars['stats'].= ', '.sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']);
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT *
|
||||
FROM '.IMAGE_FORMAT_TABLE.'
|
||||
WHERE image_id = '.$row['id'].'
|
||||
;';
|
||||
$formats = query2array($query);
|
||||
|
||||
if (!empty($formats))
|
||||
{
|
||||
$format_strings = array();
|
||||
|
||||
foreach ($formats as $format)
|
||||
{
|
||||
$format_strings[] = sprintf('%s (%.2fMB)', $format['ext'], $format['filesize']/1024);
|
||||
}
|
||||
|
||||
$intro_vars['formats'] = l10n('Formats: %s', implode(', ', $format_strings));
|
||||
}
|
||||
|
||||
$template->assign('INTRO', $intro_vars);
|
||||
|
||||
|
||||
|
|
|
@ -100,14 +100,19 @@ function get_elements($path)
|
|||
{
|
||||
$representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
|
||||
}
|
||||
|
||||
$formats = $this->get_formats($path, $filename_wo_ext);
|
||||
|
||||
$fs[ $path.'/'.$node ] = array(
|
||||
'representative_ext' => $representative_ext,
|
||||
'formats' => $formats,
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (is_dir($path.'/'.$node)
|
||||
and $node != 'pwg_high'
|
||||
and $node != 'pwg_representative'
|
||||
and $node != 'pwg_format'
|
||||
and $node != 'thumbnail' )
|
||||
{
|
||||
$subdirs[] = $node;
|
||||
|
@ -182,6 +187,32 @@ function get_representative_ext($path, $filename_wo_ext)
|
|||
return null;
|
||||
}
|
||||
|
||||
function get_formats($path, $filename_wo_ext)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$formats = array();
|
||||
|
||||
$base_test = $path.'/pwg_format/'.$filename_wo_ext.'.';
|
||||
|
||||
foreach ($conf['format_ext'] as $ext)
|
||||
{
|
||||
$test = $base_test.$ext;
|
||||
|
||||
if (is_file($test))
|
||||
{
|
||||
// $formats[] = array(
|
||||
// 'ext' => $ext,
|
||||
// 'filesize' => floor(filesize($file) / 1024),
|
||||
// );
|
||||
|
||||
// we return a "/" splitted string instead of an array with 2 keys, to reduce memory usage
|
||||
$formats[] = $ext.'/'.floor(filesize($test) / 1024);
|
||||
}
|
||||
}
|
||||
|
||||
return $formats;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -457,6 +457,7 @@ if (isset($_POST['submit']) and $_POST['sync'] == 'files'
|
|||
$start= $start_files;
|
||||
|
||||
$fs = $site_reader->get_elements($basedir);
|
||||
|
||||
$template->append('footer_elements', '<!-- get_elements: '
|
||||
. get_elapsed_time($start, get_moment())
|
||||
. ' -->' );
|
||||
|
@ -486,6 +487,7 @@ SELECT id, path
|
|||
|
||||
$inserts = array();
|
||||
$insert_links = array();
|
||||
$insert_formats = array();
|
||||
|
||||
foreach (array_diff(array_keys($fs), $db_elements) as $path)
|
||||
{
|
||||
|
@ -535,6 +537,22 @@ SELECT id, path
|
|||
'info' => l10n('added')
|
||||
);
|
||||
|
||||
foreach ($fs[$path]['formats'] as $format)
|
||||
{
|
||||
list($ext, $filesize) = explode('/', $format);
|
||||
|
||||
$insert_formats[] = array(
|
||||
'image_id' => $insert['id'],
|
||||
'ext' => $ext,
|
||||
'filesize' => $filesize,
|
||||
);
|
||||
|
||||
$infos[] = array(
|
||||
'path' => $insert['path'],
|
||||
'info' => l10n('format %s added', $ext)
|
||||
);
|
||||
}
|
||||
|
||||
$caddiables[] = $insert['id'];
|
||||
}
|
||||
|
||||
|
@ -556,6 +574,16 @@ SELECT id, path
|
|||
$insert_links
|
||||
);
|
||||
|
||||
// inserts all formats
|
||||
if (count($insert_formats) > 0)
|
||||
{
|
||||
mass_inserts(
|
||||
IMAGE_FORMAT_TABLE,
|
||||
array_keys($insert_formats[0]),
|
||||
$insert_formats
|
||||
);
|
||||
}
|
||||
|
||||
// add new photos to caddie
|
||||
if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ jQuery("a.preview-box").colorbox({
|
|||
<li>{$INTRO.add_date}</li>
|
||||
<li>{$INTRO.added_by}</li>
|
||||
<li>{$INTRO.size}</li>
|
||||
<li>{$INTRO.formats}</li>
|
||||
<li>{$INTRO.stats}</li>
|
||||
<li>{$INTRO.id}</li>
|
||||
</ul>
|
||||
|
|
|
@ -63,6 +63,10 @@ $conf['file_ext'] = array_merge(
|
|||
array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf')
|
||||
);
|
||||
|
||||
// format_ext : file extensions for formats, ie additional versions of a
|
||||
// photo (or nay other file). Formats are in sub-directory pwg_format.
|
||||
$conf['format_ext'] = array('cr2', 'tif', 'tiff', 'nef', 'dng', 'ai');
|
||||
|
||||
// top_number : number of element to display for "best rated" and "most
|
||||
// visited" categories
|
||||
$conf['top_number'] = 15;
|
||||
|
|
|
@ -105,5 +105,7 @@ if (!defined('THEMES_TABLE'))
|
|||
define('THEMES_TABLE', $prefixeTable.'themes');
|
||||
if (!defined('LANGUAGES_TABLE'))
|
||||
define('LANGUAGES_TABLE', $prefixeTable.'languages');
|
||||
if (!defined('IMAGE_FORMAT_TABLE'))
|
||||
define('IMAGE_FORMAT_TABLE', $prefixeTable.'image_format');
|
||||
|
||||
?>
|
||||
|
|
|
@ -952,6 +952,21 @@ function original_to_representative($path, $representative_ext)
|
|||
return substr_replace($path, $representative_ext, $pos+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an original path to its format
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $format_ext
|
||||
* @return string
|
||||
*/
|
||||
function original_to_format($path, $format_ext)
|
||||
{
|
||||
$pos = strrpos($path, '/');
|
||||
$path = substr_replace($path, 'pwg_format/', $pos+1, 0);
|
||||
$pos = strrpos($path, '.');
|
||||
return substr_replace($path, $format_ext, $pos+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the full path of an image
|
||||
*
|
||||
|
|
44
install/db/145-database.php
Normal file
44
install/db/145-database.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Piwigo - a PHP based photo gallery |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Copyright(C) 2008-2015 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 |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | This program is free software; you can redistribute it and/or modify |
|
||||
// | it under the terms of the GNU General Public License as published by |
|
||||
// | the Free Software Foundation |
|
||||
// | |
|
||||
// | This program is distributed in the hope that it will be useful, but |
|
||||
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU General Public License |
|
||||
// | along with this program; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
||||
// | USA. |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
||||
if (!defined('PHPWG_ROOT_PATH'))
|
||||
{
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
$upgrade_description = 'add image formats table';
|
||||
|
||||
// we use PREFIX_TABLE, in case Piwigo uses an external user table
|
||||
pwg_query('
|
||||
CREATE TABLE `'.PREFIX_TABLE.'image_format` (
|
||||
`format_id` int(11) unsigned NOT NULL auto_increment,
|
||||
`image_id` mediumint(8) unsigned NOT NULL DEFAULT \'0\',
|
||||
`ext` varchar(255) NOT NULL,
|
||||
`filesize` mediumint(9) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`format_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8
|
||||
;');
|
||||
|
||||
echo "\n".$upgrade_description."\n";
|
||||
|
||||
?>
|
|
@ -162,6 +162,18 @@ CREATE TABLE `piwigo_image_category` (
|
|||
KEY `image_category_i1` (`category_id`)
|
||||
) ENGINE=MyISAM;
|
||||
|
||||
--
|
||||
-- Table structure for table `piwigo_image_format`
|
||||
--
|
||||
|
||||
CREATE TABLE `piwigo_image_format` (
|
||||
`format_id` int(11) unsigned NOT NULL auto_increment,
|
||||
`image_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
|
||||
`ext` varchar(255) NOT NULL,
|
||||
`filesize` mediumint(9) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`format_id`)
|
||||
) ENGINE=MyISAM;
|
||||
|
||||
--
|
||||
-- Table structure for table `piwigo_image_tag`
|
||||
--
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue