From b0478ef330b8f729554aec55baa81d9e3d02a063 Mon Sep 17 00:00:00 2001 From: plegall Date: Fri, 9 Mar 2007 16:28:49 +0000 Subject: New: #images.high_filesize was added so that we can sum the filesizes in the filtered history. #images.high_filesize is filled during metadata synchronization. Bug fixed: in getAttribute XML function, when asking "filesize", it was returning high_filesize. The regex was too simple. git-svn-id: http://piwigo.org/svn/trunk@1883 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/history.php | 104 +++++++++++++++++++++++++++------ admin/include/functions_metadata.php | 30 ++++++++++ admin/picture_modify.php | 12 ++++ admin/site_reader_local.php | 11 +++- admin/site_reader_remote.php | 17 ++++-- admin/site_update.php | 35 ++++++++++- include/functions_xml.inc.php | 2 +- install/db/55-database.php | 63 ++++++++++++++++++++ install/db/56-database.php | 53 +++++++++++++++++ install/phpwebgallery_structure.sql | 15 ++--- template/yoga/admin/history.tpl | 10 +++- template/yoga/admin/picture_modify.tpl | 7 +++ tools/create_listing_file.php | 3 + 13 files changed, 326 insertions(+), 36 deletions(-) create mode 100644 install/db/55-database.php create mode 100644 install/db/56-database.php diff --git a/admin/history.php b/admin/history.php index 9a0a521e5..07ecd2885 100644 --- a/admin/history.php +++ b/admin/history.php @@ -226,16 +226,6 @@ SELECT rules $clauses ); - $query = ' -SELECT COUNT(*) - FROM '.HISTORY_TABLE.' - WHERE '.$where_separator.' -;'; - - // echo '
'.$query.'
'; - - list($page['nb_lines']) = mysql_fetch_row(pwg_query($query)); - $query = ' SELECT date, @@ -249,11 +239,20 @@ SELECT image_type FROM '.HISTORY_TABLE.' WHERE '.$where_separator.' - LIMIT '.$page['start'].', '.$conf['nb_logs_page'].' ;'; + // LIMIT '.$page['start'].', '.$conf['nb_logs_page'].' + $result = pwg_query($query); - $history_lines = $user_ids = $category_ids = $image_ids = array(); + + $page['nb_lines'] = mysql_num_rows($result); + + $history_lines = array(); + $user_ids = array(); + $category_ids = array(); + $image_ids = array(); + $tag_ids = array(); + while ($row = mysql_fetch_assoc($result)) { $user_ids[$row['user_id']] = 1; @@ -314,17 +313,71 @@ SELECT id, uppercats if (count($image_ids) > 0) { $query = ' -SELECT id, IF(name IS NULL, file, name) AS label +SELECT + id, + IF(name IS NULL, file, name) AS label, + filesize, + high_filesize FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', array_keys($image_ids)).') ;'; - $label_of_image = simple_hash_from_query($query, 'id', 'label'); + // $label_of_image = simple_hash_from_query($query, 'id', 'label'); + $label_of_image = array(); + $filesize_of_image = array(); + $high_filesize_of_image = array(); + + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $label_of_image[ $row['id'] ] = $row['label']; + + if (isset($row['filesize'])) + { + $filesize_of_image[ $row['id'] ] = $row['filesize']; + } + + if (isset($row['high_filesize'])) + { + $high_filesize_of_image[ $row['id'] ] = $row['high_filesize']; + } + } + + // echo '
'; print_r($high_filesize_of_image); echo '
'; } $i = 0; + $first_line = $page['start'] + 1; + $last_line = $page['start'] + $conf['nb_logs_page']; + + $total_filesize = 0; foreach ($history_lines as $line) { + if (isset($line['image_type'])) + { + if ($line['image_type'] == 'high') + { + if (isset($high_filesize_of_image[$line['image_id']])) + { + $total_filesize+= $high_filesize_of_image[$line['image_id']]; + } + } + else + { + if (isset($filesize_of_image[$line['image_id']])) + { + $total_filesize+= $filesize_of_image[$line['image_id']]; + } + } + } + + $i++; + + if ($i < $first_line or $i > $last_line) + { + continue; + } + $template->assign_block_vars( 'detail', array( @@ -337,9 +390,17 @@ SELECT id, IF(name IS NULL, file, name) AS label 'IP' => $line['IP'], 'IMAGE' => isset($line['image_id']) ? ( isset($label_of_image[$line['image_id']]) - ? $label_of_image[$line['image_id']] - : 'deleted '.$line['image_id']) - : $line['image_id'], + ? sprintf( + '(%u) %s', + $line['image_id'], + $label_of_image[$line['image_id']] + ) + : sprintf( + '(%u) deleted ', + $line['image_id'] + ) + ) + : '', 'TYPE' => $line['image_type'], 'SECTION' => $line['section'], 'CATEGORY' => isset($line['category_id']) @@ -348,10 +409,17 @@ SELECT id, IF(name IS NULL, file, name) AS label : 'deleted '.$line['category_id'] ) : '', 'TAGS' => $line['tag_ids'], - 'T_CLASS' => ($i++ % 2) ? 'row1' : 'row2', + 'T_CLASS' => ($i % 2) ? 'row1' : 'row2', ) ); } + + $template->assign_block_vars( + 'summary', + array( + 'FILESIZE' => $total_filesize.' KB', + ) + ); } // $groups_string = preg_replace( diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php index f26184ce7..053c34afe 100644 --- a/admin/include/functions_metadata.php +++ b/admin/include/functions_metadata.php @@ -105,6 +105,28 @@ function update_metadata($files) $datas = array(); $tags_of = array(); + $has_high_images = array(); + + $image_ids = array(); + foreach ($files as $id => $file) + { + array_push($image_ids, $id); + } + + $query = ' +SELECT id + FROM '.IMAGES_TABLE.' + WHERE has_high = \'true\' + AND id IN ( +'.wordwrap(implode(', ', $image_ids), 80, "\n").' +) +;'; + + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + array_push($has_high_images, $row['id']); + } foreach ($files as $id => $file) { @@ -117,6 +139,13 @@ function update_metadata($files) $data['width'] = $image_size[0]; $data['height'] = $image_size[1]; } + + if (in_array($id, $has_high_images)) + { + $high_file = dirname($file).'/pwg_high/'.basename($file); + + $data['high_filesize'] = floor(filesize($high_file)/1024); + } if ($conf['use_exif']) { @@ -161,6 +190,7 @@ function update_metadata($files) 'filesize', 'width', 'height', + 'high_filesize', 'date_metadata_update' ); diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 0dd6a237b..052b03330 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -262,6 +262,18 @@ $template->assign_vars( ) ); +if ($row['has_high'] == 'true') +{ + $template->assign_block_vars( + 'high', + array( + 'FILESIZE' => isset($row['high_filesize']) + ? $row['high_filesize'].' KB' + : l10n('unknown'), + ) + ); +} + // creation date unset($day, $month, $year); diff --git a/admin/site_reader_local.php b/admin/site_reader_local.php index 4302d9a3e..9159a0b90 100644 --- a/admin/site_reader_local.php +++ b/admin/site_reader_local.php @@ -157,7 +157,7 @@ function get_metadata_attributes() { global $conf; - $update_fields = array('filesize', 'width', 'height'); + $update_fields = array('filesize', 'width', 'height', 'high_filesize'); if ($conf['use_exif']) { @@ -181,7 +181,7 @@ function get_metadata_attributes() } // returns a hash of attributes (metadata+filesize+width,...) for file -function get_element_metadata($file) +function get_element_metadata($file, $has_high = false) { global $conf; if (!is_file($file)) @@ -199,6 +199,13 @@ function get_element_metadata($file) $data['height'] = $image_size[1]; } + if ($has_high) + { + $high_file = dirname($file).'/pwg_high/'.basename($file); + + $data['high_filesize'] = floor(filesize($high_file)/1024); + } + if ($conf['use_exif']) { $data = array_merge($data, get_sync_exif_data($file) ); diff --git a/admin/site_reader_remote.php b/admin/site_reader_remote.php index dd0038877..9ee7916e2 100644 --- a/admin/site_reader_remote.php +++ b/admin/site_reader_remote.php @@ -47,7 +47,7 @@ function RemoteSiteReader($url, $listing_url) 'tn_ext', 'representative_ext', 'has_high', ); $this->metadata_attributes = array( - 'filesize', 'width', 'height' + 'filesize', 'width', 'height', 'high_filesize' ); if (!isset($listing_url)) @@ -88,11 +88,16 @@ function open() return false; } - $this->metadata_attributes = array_merge( - $this->metadata_attributes, - explode(',', getAttribute($info_xml_element, 'metadata')) - ); + $additional_metadata = getAttribute($info_xml_element, 'metadata'); + if ($additional_metadata != '') + { + $this->metadata_attributes = array_merge( + $this->metadata_attributes, + explode(',', $additional_metadata) + ); + } + $this->build_structure($xml_content, '', 0); return true; @@ -179,7 +184,7 @@ function get_metadata_attributes() } // returns a hash of attributes (metadata+width,...) for file -function get_element_metadata($file) +function get_element_metadata($file, $has_high = false) { return $this->get_element_attributes( $file, diff --git a/admin/site_update.php b/admin/site_update.php index baf7131af..91e4d6238 100644 --- a/admin/site_update.php +++ b/admin/site_update.php @@ -775,9 +775,40 @@ if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync']) $start = get_moment(); $datas = array(); $tags_of = array(); + + $has_high_images = array(); + + $image_ids = array(); + foreach ($files as $id => $file) + { + array_push($image_ids, $id); + } + + if (count($image_ids) > 0) + { + $query = ' +SELECT id + FROM '.IMAGES_TABLE.' + WHERE has_high = \'true\' + AND id IN ( +'.wordwrap(implode(', ', $image_ids), 80, "\n").' +) +;'; + + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + array_push($has_high_images, $row['id']); + } + } + foreach ( $files as $id=>$file ) { - $data = $site_reader->get_element_metadata($file); + $data = $site_reader->get_element_metadata( + $file, + in_array($id, $has_high_images) + ); + if ( is_array($data) ) { $data['date_metadata_update'] = CURRENT_DATE; @@ -813,6 +844,8 @@ if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync']) { if (count($datas) > 0) { + // echo '
', print_r($datas); echo '
'; + mass_updates( IMAGES_TABLE, // fields diff --git a/include/functions_xml.inc.php b/include/functions_xml.inc.php index 64df545ce..7c388d292 100644 --- a/include/functions_xml.inc.php +++ b/include/functions_xml.inc.php @@ -52,7 +52,7 @@ function getContent( $element ) function getAttribute( $element, $attribute ) { // echo htmlentities($element).'

'; - $regex = '/^<\w+[^>]*'.$attribute.'\s*=\s*"('.VAL_REG.')"/i'; + $regex = '/^<\w+[^>]*\b'.$attribute.'\s*=\s*"('.VAL_REG.')"/i'; if ( preg_match( $regex, $element, $out ) ) { return html_entity_decode($out[1], ENT_QUOTES); diff --git a/install/db/55-database.php b/install/db/55-database.php new file mode 100644 index 000000000..b8d3416c0 --- /dev/null +++ b/install/db/55-database.php @@ -0,0 +1,63 @@ + diff --git a/install/db/56-database.php b/install/db/56-database.php new file mode 100644 index 000000000..3d8dba59d --- /dev/null +++ b/install/db/56-database.php @@ -0,0 +1,53 @@ + diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql index 5a9d3e544..4169f2973 100644 --- a/install/phpwebgallery_structure.sql +++ b/install/phpwebgallery_structure.sql @@ -38,10 +38,10 @@ CREATE TABLE `phpwebgallery_categories` ( `commentable` enum('true','false') NOT NULL default 'true', `global_rank` varchar(255) default NULL, `image_order` varchar(128) default NULL, - `permalink` VARCHAR(64) default NULL, + `permalink` varchar(64) default NULL, PRIMARY KEY (`id`), - KEY `categories_i2` (`id_uppercat`), - UNIQUE KEY `categories_i3` (`permalink`) + UNIQUE KEY `categories_i3` (`permalink`), + KEY `categories_i2` (`id_uppercat`) ) TYPE=MyISAM; -- @@ -196,6 +196,7 @@ CREATE TABLE `phpwebgallery_images` ( `has_high` enum('true') default NULL, `path` varchar(255) NOT NULL default '', `storage_category_id` smallint(5) unsigned default NULL, + `high_filesize` mediumint(9) unsigned default NULL, PRIMARY KEY (`id`), KEY `images_i2` (`date_available`), KEY `images_i3` (`average_rate`), @@ -210,12 +211,12 @@ CREATE TABLE `phpwebgallery_images` ( DROP TABLE IF EXISTS `phpwebgallery_old_permalinks`; CREATE TABLE `phpwebgallery_old_permalinks` ( - `cat_id` smallint(5) unsigned NOT NULL, - `permalink` VARCHAR(64) NOT NULL, - `date_deleted` datetime NOT NULL, + `cat_id` smallint(5) unsigned NOT NULL default '0', + `permalink` varchar(64) NOT NULL default '', + `date_deleted` datetime NOT NULL default '0000-00-00 00:00:00', `last_hit` datetime default NULL, `hit` int(10) unsigned NOT NULL default '0', - PRIMARY KEY (`permalink`) + PRIMARY KEY (`permalink`) ) TYPE=MyISAM; -- diff --git a/template/yoga/admin/history.tpl b/template/yoga/admin/history.tpl index 570118797..64c0f9535 100644 --- a/template/yoga/admin/history.tpl +++ b/template/yoga/admin/history.tpl @@ -65,7 +65,15 @@ -

{L_DATE_TITLE}

+ +
+ {lang:Summary} + + +
+
diff --git a/template/yoga/admin/picture_modify.tpl b/template/yoga/admin/picture_modify.tpl index 8ea3360be..283cae73a 100644 --- a/template/yoga/admin/picture_modify.tpl +++ b/template/yoga/admin/picture_modify.tpl @@ -37,6 +37,13 @@ {FILESIZE} + + + {lang:High filesize} + {high.FILESIZE} + + + {lang:Storage category} {STORAGE_CATEGORY} diff --git a/tools/create_listing_file.php b/tools/create_listing_file.php index be72e24be..6703e1843 100644 --- a/tools/create_listing_file.php +++ b/tools/create_listing_file.php @@ -714,6 +714,9 @@ function pwg_scan_file($file_full, &$line) if (pwg_get_high($file_dir, $file_base)) { $element['has_high'] = 'true'; + + $high_file = $file_dir.'/'.$conf['high'].'/'.$file_base; + $element['high_filesize'] = floor(filesize($high_file) / 1024); } // get EXIF meta datas -- cgit v1.2.3