diff options
Diffstat (limited to '')
-rw-r--r-- | admin/configuration.php | 47 | ||||
-rw-r--r-- | admin/include/functions_metadata.php | 363 | ||||
-rw-r--r-- | admin/update.php | 289 |
3 files changed, 551 insertions, 148 deletions
diff --git a/admin/configuration.php b/admin/configuration.php index 871784758..1d8356444 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -166,24 +166,38 @@ if ( isset( $_POST['submit'] ) ) array_push( $error, $lang['err_maxheight'] ); }*/ // updating configuraiton if no error found - if ( count( $error ) == 0 ) + if (count($error) == 0) { - $result = mysql_query( "SELECT * FROM ".CONFIG_TABLE ); - while ( $row = mysql_fetch_array( $result ) ) - { - $config_name = $row['param']; - $conf[$config_name] = ( isset($_POST[$config_name]) ) ? $_POST[$config_name] : $row['value']; - if ( isset( $_POST[$config_name] ) ) + $result = mysql_query('SELECT * FROM '.CONFIG_TABLE); + while ($row = mysql_fetch_array($result)) + { + $config_name = $row['param']; + if (isset($_POST[$config_name])) + { + $conf[$config_name] = $_POST[$config_name]; + } + else { - $query = 'UPDATE '.CONFIG_TABLE; - $query.= " SET value = '". str_replace("\'", "''", $conf[$config_name]) ; - $query.= "' WHERE param = '$config_name'"; - mysql_query( $query ); + $conf[$config_name] = $row['value']; + } + + if (isset($_POST[$config_name])) + { + $query = ' +UPDATE '.CONFIG_TABLE.' + SET value = \''. str_replace("\'", "''", $conf[$config_name]).'\' + WHERE param = \''.$config_name.'\' +;'; + mysql_query($query); } } } } +// echo '<pre>'; +// print_r($conf); +// echo '</pre>'; + $access = ($conf['access']=='free')?'ACCESS_FREE':'ACCESS_RESTRICTED'; $log = ($conf['log']=='true')?'HISTORY_YES':'HISTORY_NO'; $mail_notif = ($conf['mail_notification']=='true')?'MAIL_NOTIFICATION_YES':'MAIL_NOTIFICATION_NO'; @@ -194,6 +208,8 @@ $expand = ($conf['auto_expand']=='true')?'EXPAND_TREE_YES':'EXPAND_TREE_NO'; $nb_comments = ($conf['show_nb_comments']=='true')?'NB_COMMENTS_YES':'NB_COMMENTS_NO'; $upload = ($conf['upload_available']=='true')?'UPLOAD_YES':'UPLOAD_NO'; $cookie = ($conf['authorize_cookies']=='true')?'COOKIE_YES':'COOKIE_NO'; +$use_exif = ($conf['use_exif']=='true')?'USE_EXIF_YES':'USE_EXIF_NO'; +$use_iptc = ($conf['use_iptc']=='true')?'USE_IPTC_YES':'USE_IPTC_NO'; //----------------------------------------------------- template initialization $template->set_filenames( array('config'=>'admin/configuration.tpl') ); @@ -226,6 +242,8 @@ $template->assign_vars(array( $nb_comments=>'checked="checked"', $upload=>'checked="checked"', $cookie=>'checked="checked"', + $use_exif=>'checked="checked"', + $use_iptc=>'checked="checked"', 'L_CONFIRM'=>$lang['conf_confirmation'], 'L_CONF_GENERAL'=>$lang['conf_general_title'], @@ -290,9 +308,14 @@ $template->assign_vars(array( 'L_YES'=>$lang['yes'], 'L_NO'=>$lang['no'], 'L_SUBMIT'=>$lang['submit'], + 'L_CONF_METADATA'=>$lang['conf_metadata_title'], + 'L_USE_EXIF'=>$lang['conf_use_exif'], + 'L_USE_EXIF_INFO'=>$lang['conf_use_exif_info'], + 'L_USE_IPTC'=>$lang['conf_use_iptc'], + 'L_USE_IPTC_INFO'=>$lang['conf_use_iptc_info'], 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=configuration') - )); + )); //-------------------------------------------------------------- errors display if ( sizeof( $error ) != 0 ) diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php new file mode 100644 index 000000000..9a7d45193 --- /dev/null +++ b/admin/include/functions_metadata.php @@ -0,0 +1,363 @@ +<?php +// +-----------------------------------------------------------------------+ +// | functions_metadata.php | +// +-----------------------------------------------------------------------+ +// | application : PhpWebGallery <http://phpwebgallery.net> | +// | branch : BSF (Best So Far) | +// +-----------------------------------------------------------------------+ +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | 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. | +// +-----------------------------------------------------------------------+ + +/** + * returns informations from IPTC metadata, mapping is done at the beginning + * of the function + * + * @param string $filename + * @return array + */ +function get_iptc_data($filename) +{ + global $getimagesize_time; + + $map = array( + 'keywords' => '2#025', + 'date_creation' => '2#055', + 'author' => '2#122', + 'name' => '2#085', + 'comment' => '2#120' + ); + $datefields = array('date_creation', 'date_available'); + + $result = array(); + + // Read IPTC data + $iptc = array(); + + $start = get_moment(); + getimagesize($filename, &$imginfo); + $getimagesize_time+= get_moment() - $start; + + if (is_array($imginfo) and isset($imginfo['APP13'])) + { + $iptc = iptcparse($imginfo['APP13']); + if (is_array($iptc)) + { + $rmap = array_flip($map); + foreach (array_keys($rmap) as $iptc_key) + { + if (isset($iptc[$iptc_key][0]) and $value = $iptc[$iptc_key][0]) + { + // strip leading zeros (weird Kodak Scanner software) + while ($value[0] == chr(0)) + { + $value = substr($value, 1); + } + // remove binary nulls + $value = str_replace(chr(0x00), ' ', $value); + + foreach (array_keys($map, $iptc_key) as $pwg_key) + { + if (in_array($pwg_key, $datefields)) + { + if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches)) + { + $value = $matches[1].'-'.$matches[2].'-'.$matches[3]; + } + else + { + continue; + } + } + $result[$pwg_key] = $value; + } + } + } + } + } + return $result; +} + +function update_metadata($files) +{ + global $conf; + +// $conf['use_iptc'] = true; +// $conf['use_exif'] = true; + + $inserts = array(); + + foreach ($files as $id => $file) + { + $insert = array(); + $insert['id'] = $id; + $insert['filesize'] = floor(filesize($file)/1024); + + if ($image_size = @getimagesize($file)) + { + $insert['width'] = $image_size[0]; + $insert['height'] = $image_size[1]; + } + + if ($conf['use_exif']) + { + if ($exif = @read_exif_data($file)) + { + if (isset($exif['DateTime'])) + { + preg_match('/^(\d{4}).(\d{2}).(\d{2})/' + ,$exif['DateTime'] + ,$matches); + $insert['date_creation'] = + "'".$matches[1].'-'.$matches[2].'-'.$matches[3]."'"; + } + } + } + + if ($conf['use_iptc']) + { + $iptc = get_iptc_data($file); + foreach (array_keys($iptc) as $key) + { + $insert[$key] = "'".addslashes($iptc[$key])."'"; + } + } + + $insert['date_metadata_update'] = CURRENT_DATE; + + array_push($inserts, $insert); + } + + if (count($inserts) > 0) + { + $dbfields = array( + 'id','filesize','width','height','name','author','comment' + ,'date_creation','keywords','date_metadata_update' + ); + + // depending on the MySQL version, we use the multi table update or N + // update queries + $query = 'SELECT VERSION() AS version;'; + $row = mysql_fetch_array(mysql_query($query)); + if (version_compare($row['version'],'4.0.4') < 0) + { + // MySQL is prior to version 4.0.4, multi table update feature is not + // available + echo 'MySQL is prior to version 4.0.4, multi table update feature is not available<br />'; + foreach ($inserts as $insert) + { + $query = ' +UPDATE '.IMAGES_TABLE.' + SET '; + foreach (array_diff(array_keys($insert),array('id')) as $num => $key) + { + if ($num > 1) + { + $query.= ', '; + } + $query.= $key.' = '.$insert[$key]; + } + $query.= ' + WHERE id = '.$insert['id'].' +;'; + // echo '<pre>'.$query.'</pre>'; + mysql_query($query); + } + } + else + { + // creation of the temporary table + $query = ' +DESCRIBE '.IMAGES_TABLE.' +;'; + $result = mysql_query($query); + $columns = array(); + while ($row = mysql_fetch_array($result)) + { + if (in_array($row['Field'], $dbfields)) + { + $column = $row['Field']; + $column.= ' '.$row['Type']; + if (!isset($row['Null']) or $row['Null'] == '') + { + $column.= ' NOT NULL'; + } + if (isset($row['Default'])) + { + $column.= " default '".$row['Default']."'"; + } + array_push($columns, $column); + } + } + $query = ' +CREATE TEMPORARY TABLE '.IMAGE_METADATA_TABLE.' +( +'.implode(",\n", $columns).', +PRIMARY KEY (id) +) +;'; + // echo '<pre>'.$query.'</pre>'; + mysql_query($query); + // inserts all found pictures + $query = ' +INSERT INTO '.IMAGE_METADATA_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.= ' +;'; + // echo '<pre>'.$query.'</pre>'; + mysql_query($query); + // update of images table by joining with temporary table + $query = ' +UPDATE '.IMAGES_TABLE.' AS images, '.IMAGE_METADATA_TABLE.' as metadata + SET '.implode("\n , ", + array_map( + create_function('$s', 'return "images.$s = metadata.$s";') + , array_diff($dbfields, array('id')))).' + WHERE images.id = metadata.id +;'; + echo '<pre>'.$query.'</pre>'; + mysql_query($query); + } + } +} + +/** + * returns an array associating element id (images.id) with its complete + * path in the filesystem + * + * @param int id_uppercat + * @param boolean recursive ? + * @param boolean only newly added files ? + * @return array + */ +function get_filelist($category_id = '', $recursive = false, $only_new = false) +{ + $files = array(); + + $query = ' +SELECT id, dir + FROM '.CATEGORIES_TABLE.' +;'; + $result = mysql_query($query); + $cat_dirs = array(); + while ($row = mysql_fetch_array($result)) + { + $cat_dirs[$row['id']] = $row['dir']; + } + + // filling $uppercats_array : to each category id the uppercats list is + // associated + $uppercats_array = array(); + + $query = ' +SELECT id, uppercats + FROM '.CATEGORIES_TABLE; + if (is_numeric($category_id)) + { + if ($recursive) + { + $query.= ' + WHERE uppercats REGEXP \'(^|,)'.$category_id.'(,|$)\' +'; + } + else + { + $query.= ' + WHERE id = '.$category_id.' +'; + } + } + $query.= ' +;'; + $result = mysql_query($query); + while ($row = mysql_fetch_array($result)) + { + $uppercats_array[$row['id']] = $row['uppercats']; + } + + $query = ' +SELECT galleries_url + FROM '.SITES_TABLE.' + WHERE id = 1 +'; + $row = mysql_fetch_array(mysql_query($query)); + $basedir = $row['galleries_url']; + + // filling $cat_fulldirs + $cat_fulldirs = array(); + foreach ($uppercats_array as $cat_id => $uppercats) + { + $uppercats = str_replace(',', '/', $uppercats); + $cat_fulldirs[$cat_id] = $basedir.preg_replace('/(\d+)/e', + "\$cat_dirs['$1']", + $uppercats); + } + + $query = ' +SELECT id, file, storage_category_id + FROM '.IMAGES_TABLE.' + WHERE storage_category_id IN ('.implode(',' + ,array_keys($uppercats_array)).')'; + if ($only_new) + { + $query.= ' + AND date_metadata_update IS NULL +'; + } + $query.= ' +;'; + $result = mysql_query($query); + while ($row = mysql_fetch_array($result)) + { + $files[$row['id']] + = $cat_fulldirs[$row['storage_category_id']].'/'.$row['file']; + } + + return $files; +} +?>
\ No newline at end of file diff --git a/admin/update.php b/admin/update.php index ba4f823ac..a99b58e62 100644 --- a/admin/update.php +++ b/admin/update.php @@ -26,33 +26,43 @@ // +-----------------------------------------------------------------------+ include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); + +define('CURRENT_DATE', "'".date('Y-m-d')."'"); //------------------------------------------------------------------- functions -function ordering( $id_uppercat) +/** + * order categories (update categories.rank database field) + * + * the purpose of this function is to give a rank for all categories + * (insides its sub-category), even the newer that have none at te + * beginning. For this, ordering function selects all categories ordered by + * rank ASC then name ASC for each uppercat. + * + * @returns void + */ +function ordering() { - $rank = 1; + $current_rank = 0; + $current_uppercat = ''; - $query = 'SELECT id'; - $query.= ' FROM '.CATEGORIES_TABLE; - if ( !is_numeric( $id_uppercat)) - { - $query.= ' WHERE id_uppercat IS NULL'; - } - else - { - $query.= ' WHERE id_uppercat = '.$id_uppercat; - } - $query.= ' ORDER BY rank ASC, dir ASC'; - $query.= ';'; - $result = mysql_query( $query); - while ( $row = mysql_fetch_array( $result)) + $query = ' +SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat + FROM '.CATEGORIES_TABLE.' + ORDER BY id_uppercat,rank,name +;'; + $result = mysql_query($query); + while ($row = mysql_fetch_array($result)) { - $query = 'UPDATE '.CATEGORIES_TABLE; - $query.= ' SET rank = '.$rank; - $query.= ' WHERE id = '.$row['id']; - $query.= ';'; - mysql_query( $query); - $rank++; - ordering( $row['id']); + if ($row['id_uppercat'] != $current_uppercat) + { + $current_rank = 0; + $current_uppercat = $row['id_uppercat']; + } + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET rank = '.++$current_rank.' + WHERE id = '.$row['id'].' +;'; + mysql_query($query); } } @@ -110,7 +120,7 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' } } - $sub_dirs = get_category_directories($cat_directory); + $fs_subdirs = get_category_directories($cat_directory); $sub_category_dirs = array(); $query = ' @@ -136,29 +146,34 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' } // 3. we have to remove the categories of the database not present anymore + $to_delete_categories = array(); foreach ($sub_category_dirs as $id => $dir) { - if (!in_array($dir, $sub_dirs)) + if (!in_array($dir, $fs_subdirs)) { - delete_category($id); + array_push($to_delete_categories,$id); } } + if (count($to_delete_categories) > 0) + { + delete_categories($to_delete_categories); + } // array of new categories to insert $inserts = array(); - foreach ($sub_dirs as $sub_dir) + foreach ($fs_subdirs as $fs_subdir) { // 5. Is the category already existing ? we create a subcat if not // existing - $category_id = array_search($sub_dir, $sub_category_dirs); + $category_id = array_search($fs_subdir, $sub_category_dirs); if (!is_numeric($category_id)) { - if (preg_match('/^[a-zA-Z0-9-_.]+$/', $sub_dir)) + if (preg_match('/^[a-zA-Z0-9-_.]+$/', $fs_subdir)) { - $name = str_replace('_', ' ', $sub_dir); + $name = str_replace('_', ' ', $fs_subdir); - $value = "('".$sub_dir."','".$name."',1"; + $value = "('".$fs_subdir."','".$name."',1"; if (!is_numeric($id_uppercat)) { $value.= ',NULL'; @@ -173,7 +188,7 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' } else { - $output.= '<span style="color:red;">"'.$sub_dir.'" : '; + $output.= '<span style="color:red;">"'.$fs_subdir.'" : '; $output.= $lang['update_wrong_dirname'].'</span><br />'; } } @@ -250,7 +265,7 @@ SELECT id function insert_local_element($dir, $category_id) { - global $lang,$conf,$count_new, $count_deleted; + global $lang,$conf,$count_new; $output = ''; @@ -308,8 +323,7 @@ SELECT id,file,tn_ext } $to_delete_elements = array_unique($to_delete_elements); - $count_deleted+= count($to_delete_elements); - if ($count_deleted > 0) + if (count($to_delete_elements) > 0) { delete_elements($to_delete_elements); } @@ -325,27 +339,20 @@ SELECT file FROM '.IMAGES_TABLE.' array_push($registered_elements, $row['file']); } - // validated pictures are picture uploaded by users, validated by an admin - // and not registered (visible) yet - $validated_pictures = array(); + // unvalidated pictures are picture uploaded by users, but not validated + // by an admin (so not registered truly visible yet) $unvalidated_pictures = array(); $query = ' -SELECT file,infos,validated +SELECT file FROM '.WAITING_TABLE.' WHERE storage_category_id = '.$category_id.' + AND validated = \'false\' ;'; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { - if ($row['validated'] == 'true') - { - $validated_pictures[$row['file']] = $row['infos']; - } - else - { - array_push($unvalidated_pictures, $row['file']); - } + array_push($unvalidated_pictures, $row['file']); } // we only search among the picture present in the filesystem and not @@ -385,64 +392,23 @@ SELECT file,infos,validated // if we found a thumnbnail corresponding to our picture... if ($tn_ext != '') { - $image_size = @getimagesize($dir.$unregistered_element); - // (file, storage_category_id, date_available, tn_ext, filesize, - // width, height, name, author, comment, date_creation, - // representative_ext)' - $value = '('; - $value.= "'".$unregistered_element."'"; - $value.= ','.$category_id; - $value.= ",'".date('Y-m-d')."'"; - $value.= ",'".$tn_ext."'"; - $value.= ','.floor(filesize($dir.$unregistered_element) / 1024); - $value.= ','.$image_size[0]; - $value.= ','.$image_size[1]; - if (isset($validated_pictures[$unregistered_element])) - { - // retrieving infos from the XML description from waiting table - $infos = nl2br($validated_pictures[$unregistered_element]); - - $unixtime = getAttribute($infos, 'date_creation'); - if ($unixtime != '') - { - $date_creation ="'".date('Y-m-d',$unixtime)."'"; - } - else - { - $date_creation = 'NULL'; - } - - $value.= ",'".getAttribute($infos, 'name')."'"; - $value.= ",'".getAttribute($infos, 'author')."'"; - $value.= ",'".getAttribute($infos, 'comment')."'"; - $value.= ','.$date_creation; - - // deleting the waiting element - $query = ' -DELETE FROM '.WAITING_TABLE.' - WHERE file = \''.$unregistered_element.'\' - AND storage_category_id = '.$category_id.' -;'; - mysql_query($query); - } - else - { - $value.= ",'','','',NULL"; - } - $value.= ',NULL'; // representative_ext - $value.= ')'; - + $insert = array(); + $insert['file'] = "'".$unregistered_element."'"; + $insert['storage_category_id'] = $category_id; + $insert['date_available'] = CURRENT_DATE; + $insert['tn_ext'] = "'".$tn_ext."'"; + $count_new++; $output.= $unregistered_element; $output.= ' <span style="font-weight:bold;">'; $output.= $lang['update_research_added'].'</span>'; $output.= ' ('.$lang['update_research_tn_ext'].' '.$tn_ext.')'; $output.= '<br />'; - array_push($inserts, $value); + array_push($inserts, $insert); } else { - $output.= '<span style="color:red;">'; + $output.= '<span style="color:orange;">'; $output.= $lang['update_missing_tn'].' : '.$unregistered_element; $output.= ' (<span style="font-weight:bold;">'; $output.= $conf['prefix_thumbnail']; @@ -470,44 +436,25 @@ DELETE FROM '.WAITING_TABLE.' } } - // (file, storage_category_id, date_available, tn_ext, filesize, - // width, height, name, author, comment, date_creation, - // representative_ext)' - $value = '('; - $value.= "'".$unregistered_element."'"; - $value.= ','.$category_id; - $value.= ",'".date('Y-m-d')."'"; + $insert = array(); + $insert['file'] = "'".$unregistered_element."'"; + $insert['storage_category_id'] = $category_id; + $insert['date_available'] = CURRENT_DATE; if ( $tn_ext != '' ) { - $value.= ",'".$tn_ext."'"; - } - else - { - $value.= ',NULL'; + $insert['tn_ext'] = "'".$tn_ext."'"; } - $value.= ','.floor(filesize($dir.$unregistered_element) / 1024); - $value.= ',NULL'; - $value.= ',NULL'; - $value.= ',NULL'; - $value.= ',NULL'; - $value.= ',NULL'; - $value.= ',NULL'; if ( $representative_ext != '' ) { - $value.= ",'".$representative_ext."'"; - } - else - { - $value.= ',NULL'; + $insert['representative_ext'] = "'".$representative_ext."'"; } - $value.= ')'; $count_new++; $output.= $unregistered_element; $output.= ' <span style="font-weight:bold;">'; $output.= $lang['update_research_added'].'</span>'; $output.= '<br />'; - array_push($inserts, $value); + array_push($inserts, $insert); } } else @@ -520,13 +467,45 @@ DELETE FROM '.WAITING_TABLE.' if (count($inserts) > 0) { // inserts all found pictures + $dbfields = array( + 'file','storage_category_id','date_available','tn_ext' + ,'representative_ext' + ); $query = ' INSERT INTO '.IMAGES_TABLE.' - (file,storage_category_id,date_available,tn_ext,filesize,width,height - ,name,author,comment,date_creation,representative_ext) + ('.implode(',', $dbfields).') VALUES - '.implode(',', $inserts).' + '; + 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.= ' ;'; + mysql_query($query); // what are the ids of the pictures in the $category_id ? @@ -575,11 +554,11 @@ $template->assign_vars(array( 'L_RESULT_UPDATE'=>$lang['update_part_research'], 'L_NEW_CATEGORY'=>$lang['update_research_conclusion'], 'L_DEL_CATEGORY'=>$lang['update_deletion_conclusion'], + 'L_UPDATE_SYNC_METADATA_QUESTION'=>$lang['update_sync_metadata_question'], 'U_CAT_UPDATE'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=update&update=cats'), 'U_ALL_UPDATE'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=update&update=all') )); - //-------------------------------------------- introduction : choices of update // Display choice if "update" var is not specified if (!isset($_GET['update'])) @@ -587,7 +566,7 @@ if (!isset($_GET['update'])) $template->assign_block_vars('introduction',array()); } //-------------------------------------------------- local update : ./galleries -else +else if (!isset($_GET['metadata'])) { check_cat_id($_GET['update']); $start = get_moment(); @@ -602,25 +581,63 @@ else { $categories = insert_local_category('NULL'); } - $end = get_moment(); - //echo get_elapsed_time($start, $end).' for update <br />'; + echo get_elapsed_time($start,get_moment()).' for scanning directories<br />'; $template->assign_block_vars('update',array( 'CATEGORIES'=>$categories, 'NEW_CAT'=>$count_new, 'DEL_CAT'=>$count_deleted )); + if ($count_new > 0) + { + $url = PHPWG_ROOT_PATH.'admin.php?page=update&metadata=1'; + if (isset($page['cat'])) + { + $url.= '&update='.$page['cat']; + } + $template->assign_block_vars( + 'update.sync_metadata', + array( + 'U_URL' => add_session_id($url) + )); + } } //---------------------------------------- update informations about categories -if (isset($_GET['update']) - or isset($page['cat']) - or @is_file('./listing.xml') && DEBUG) +if (!isset($_GET['metadata']) + and (isset($_GET['update']) + or isset($page['cat']) + or @is_file('./listing.xml') && DEBUG)) { $start = get_moment(); update_category('all'); - ordering('NULL'); - $end = get_moment(); - echo get_elapsed_time($start, $end).' for update_category(all)<br />'; + echo get_elapsed_time($start,get_moment()).' for update_category(all)<br />'; + $start = get_moment(); + ordering(); + echo get_elapsed_time($start, get_moment()).' for ordering categories<br />'; +} +//---------------------------------------------------- metadata synchronization +if (isset($_GET['metadata'])) +{ + if (isset($_GET['update'])) + { + check_cat_id($_GET['update']); + } + + $start = get_moment(); + // $files = get_filelist(1464); + if (isset($page['cat'])) + { + $files = get_filelist($page['cat'],true,true); + } + else + { + $files = get_filelist('',true,true); + } + echo get_elapsed_time($start, get_moment()).' for get_filelist<br />'; + + $start = get_moment(); + update_metadata($files); + echo get_elapsed_time($start, get_moment()).' for metadata update<br />'; } //----------------------------------------------------------- sending html code $template->assign_var_from_handle('ADMIN_CONTENT', 'update'); -?> +?>
\ No newline at end of file |