diff options
author | rvelices <rv-github@modusoptimus.com> | 2006-02-28 01:13:16 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2006-02-28 01:13:16 +0000 |
commit | 4cd5b05d406a9820a0523ac26f254f4ce4fd5147 (patch) | |
tree | b47f717b8fe3bc3e8a3357b112e22cea96bf9188 /admin | |
parent | d4646f39d2259d4b4ba619b8f2b8aa61f9be74b5 (diff) |
remake of Remote sites and synchronize: final integration and old code cleanup
fix: xml getAttribute always decodes html entities and added encodeAttribute
function
git-svn-id: http://piwigo.org/svn/trunk@1058 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r-- | admin/cat_modify.php | 11 | ||||
-rw-r--r-- | admin/remote_site.php | 746 | ||||
-rw-r--r-- | admin/site_manager.php | 516 | ||||
-rw-r--r-- | admin/site_reader_local.php | 506 | ||||
-rw-r--r-- | admin/site_reader_remote.php | 382 | ||||
-rw-r--r-- | admin/site_update.php | 1639 | ||||
-rw-r--r-- | admin/update.php | 770 |
7 files changed, 1536 insertions, 3034 deletions
diff --git a/admin/cat_modify.php b/admin/cat_modify.php index 8291e9030..309425c91 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ @@ -258,7 +258,6 @@ if (!$category['is_virtual']) //!empty($category['dir'])) array('CATEGORY_DIR'=>preg_replace('/\/$/', '', get_complete_dir($category['id'])))); - $template->assign_block_vars('upload' ,array()); } else { @@ -300,7 +299,8 @@ SELECT id,name,uppercats,global_rank ); } -if (is_numeric($category['site_id']) and $category['site_id'] != 1) +$category['cat_dir'] = get_complete_dir($_GET['cat_id']); +if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) ) { $query = ' SELECT galleries_url @@ -311,6 +311,11 @@ SELECT galleries_url $template->assign_block_vars('server', array('SITE_URL' => $galleries_url)); } +if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) ) +{ + $template->assign_block_vars('upload' ,array()); +} + //----------------------------------------------------------- sending html code $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); ?> diff --git a/admin/remote_site.php b/admin/remote_site.php deleted file mode 100644 index 86fd6383f..000000000 --- a/admin/remote_site.php +++ /dev/null @@ -1,746 +0,0 @@ -<?php -// +-----------------------------------------------------------------------+ -// | PhpWebGallery - a PHP based picture gallery | -// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - 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. | -// +-----------------------------------------------------------------------+ - -if (!defined('PHPWG_ROOT_PATH')) -{ - die ("Hacking attempt!"); -} -include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); - -list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); -define('CURRENT_DATE', $dbnow); -// +-----------------------------------------------------------------------+ -// | functions | -// +-----------------------------------------------------------------------+ - -/** - * requests the given $url (a remote create_listing_file.php) and fills a - * list of lines corresponding to request output - * - * @param string $url - * @return void - */ -function remote_output($url) -{ - global $template, $page, $lang; - - if($lines = @file($url)) - { - $template->assign_block_vars('remote_output', array()); - // cleaning lines from HTML tags - foreach ($lines as $line) - { - $line = trim(strip_tags($line)); - if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches)) - { - $template->assign_block_vars( - 'remote_output.remote_line', - array( - 'CLASS' => 'remote'.ucfirst(strtolower($matches[1])), - 'CONTENT' => $line - ) - ); - } - } - } - else - { - array_push($page['errors'], $lang['remote_site_file_not_found']); - } -} - -/** - * returns an array where are linked the sub-categories id and there - * directories corresponding to the given uppercat id - * - * @param int site_id - * @param mixed id_uppercat - * @return array - */ -function database_subdirs($site_id, $id_uppercat) -{ - $database_dirs = array(); - - $query = ' -SELECT id,dir - FROM '.CATEGORIES_TABLE.' - WHERE site_id = '.$site_id; - if (!is_numeric($id_uppercat)) - { - $query.= ' - AND id_uppercat IS NULL'; - } - else - { - $query.= ' - AND id_uppercat = '.$id_uppercat; - } - // virtual categories not taken - $query.= ' - AND dir IS NOT NULL -;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - $database_dirs[$row['id']] = $row['dir']; - } - - return $database_dirs; -} - -/** - * read $listing_file and update a remote site according to its id - * - * @param string listing_file - * @param int site_id - * @return void - */ -function update_remote_site($listing_file, $site_id) -{ - global $lang, $counts, $template, $removes, $page; - - if (@fopen($listing_file, 'r')) - { - $counts = array( - 'new_elements' => 0, - 'new_categories' => 0, - 'del_elements' => 0, - 'del_categories' => 0 - ); - $removes = array(); - - $xml_content = getXmlCode($listing_file); - insert_remote_category($xml_content, $site_id, 'NULL', 0); - update_category(); - ordering(); - update_global_rank(); - - $template->assign_block_vars( - 'update', - array( - 'NB_NEW_CATEGORIES'=>$counts['new_categories'], - 'NB_DEL_CATEGORIES'=>$counts['del_categories'], - 'NB_NEW_ELEMENTS'=>$counts['new_elements'], - 'NB_DEL_ELEMENTS'=>$counts['del_elements'] - )); - - if (count($removes) > 0) - { - $template->assign_block_vars('update.removes', array()); - } - foreach ($removes as $remove) - { - $template->assign_block_vars('update.removes.remote_remove', - array('NAME'=>$remove)); - } - } - else - { - array_push($page['errors'], $lang['remote_site_listing_not_found']); - } -} - -/** - * searchs the "dir" node of the xml_dir given and insert the contained - * categories if the are not in the database yet. The function also deletes - * the categories that are in the database and not in the xml_file. - * - * @param string xml_content - * @param int site_id - * @param mixed id_uppercat - * @param int level - * @return void - */ -function insert_remote_category($xml_content, $site_id, $id_uppercat, $level) -{ - global $counts, $removes, $conf; - - $uppercats = ''; - // 0. retrieving informations on the category to display - - if (is_numeric($id_uppercat)) - { - $query = ' -SELECT id,name,uppercats,dir,status,visible - FROM '.CATEGORIES_TABLE.' - WHERE id = '.$id_uppercat.' -;'; - $row = mysql_fetch_array(pwg_query($query)); - $parent = array('id' => $row['id'], - 'name' => $row['name'], - 'dir' => $row['dir'], - 'uppercats' => $row['uppercats'], - 'visible' => $row['visible'], - 'status' => $row['status']); - - insert_remote_element($xml_content, $id_uppercat); - } - - // $xml_dirs contains dir names contained in the xml file for this - // id_uppercat - $xml_dirs = array(); - $temp_dirs = getChildren($xml_content, 'dir'.$level); - foreach ($temp_dirs as $temp_dir) - { - array_push($xml_dirs, getAttribute($temp_dir, 'name')); - } - - // $database_dirs contains dir names contained in the database for this - // id_uppercat and site_id - $database_dirs = database_subdirs($site_id, $id_uppercat); - - // 3. we have to remove the categories of the database not present anymore - $to_delete = array(); - foreach ($database_dirs as $id => $dir) - { - if (!in_array($dir, $xml_dirs)) - { - array_push($to_delete, $id); - array_push($removes, get_complete_dir($id)); - } - } - delete_categories($to_delete); - - // array of new categories to insert - $inserts = array(); - - // calculate default value at category creation - $create_values = array(); - if (isset($parent)) - { - // at creation, must a category be visible or not ? Warning : if - // the parent category is invisible, the category is automatically - // create invisible. (invisible = locked) - if ('false' == $parent['visible']) - { - $create_values{'visible'} = 'false'; - } - else - { - $create_values{'visible'} = $conf['newcat_default_visible']; - } - // at creation, must a category be public or private ? Warning : - // if the parent category is private, the category is - // automatically create private. - if ('private' == $parent['status']) - { - $create_values{'status'} = 'private'; - } - else - { - $create_values{'status'} = $conf['newcat_default_status']; - } - } - else - { - $create_values{'visible'} = $conf['newcat_default_visible']; - $create_values{'status'} = $conf['newcat_default_status']; - } - - foreach ($xml_dirs as $xml_dir) - { - // 5. Is the category already existing ? we create a subcat if not - // existing - $category_id = array_search($xml_dir, $database_dirs); - if (!is_numeric($category_id)) - { - $name = str_replace('_', ' ', $xml_dir); - - $insert = array(); - - $insert{'dir'} = $xml_dir; - $insert{'name'} = $name; - $insert{'site_id'} = $site_id; - $insert{'uppercats'} = 'undef'; - $insert{'commentable'} = $conf['newcat_default_commentable']; - $insert{'uploadable'} = 'false'; - $insert{'status'} = $create_values{'status'}; - $insert{'visible'} = $create_values{'visible'}; - if (isset($parent)) - { - $insert{'id_uppercat'} = $parent['id']; - } - array_push($inserts, $insert); - } - } - - // we have to create the category - if (count($inserts) > 0) - { - // inserts all found categories - $dbfields = array('dir','name','site_id','uppercats','id_uppercat', - 'commentable','uploadable','status','visible'); - mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); - $counts{'new_categories'}+= count($inserts); - - // updating uppercats field - $query = ' -UPDATE '.CATEGORIES_TABLE; - if (isset($parent)) - { - $query.= " - SET uppercats = CONCAT('".$parent['uppercats']."',',',id) - WHERE id_uppercat = ".$id_uppercat; - } - else - { - $query.= ' - SET uppercats = id - WHERE id_uppercat IS NULL'; - } - $query.= ' -;'; - pwg_query($query); - } - - // Recursive call on the sub-categories (not virtual ones) - $database_dirs = database_subdirs($site_id, $id_uppercat); - - foreach ($temp_dirs as $temp_dir) - { - $dir = getAttribute($temp_dir, 'name'); - $id_uppercat = array_search($dir, $database_dirs); - insert_remote_category($temp_dir, $site_id, $id_uppercat, $level+1); - } -} - -/** - * searchs the "root" node of $xml_dir (xml string), inserts elements in the - * database if new - * - * @param string xml_dir - * @param int category_id - * @return void - */ -function insert_remote_element($xml_dir, $category_id) -{ - global $counts, $lang, $removes; - - $output = ''; - $root = getChild($xml_dir, 'root'); - - $xml_files = array(); - $xml_elements = getChildren($root, 'element'); - foreach ($xml_elements as $xml_element) - { - array_push($xml_files, getAttribute($xml_element,'file')); - } - - // we have to delete all the images from the database that are not in the - // directory anymore (not in the XML anymore) - $query = ' -SELECT id,file - FROM '.IMAGES_TABLE.' - WHERE storage_category_id = '.$category_id.' -;'; - $result = pwg_query($query); - $to_delete = array(); - while ($row = mysql_fetch_array($result)) - { - if (!in_array($row['file'], $xml_files)) - { - // local_dir is cached - if (!isset($local_dir)) - { - $local_dir = get_local_dir($category_id); - } - array_push($removes, $local_dir.$row['file']); - array_push($to_delete, $row['id']); - } - } - delete_elements($to_delete); - - $database_elements = array(); - $query = ' -SELECT file - FROM '.IMAGES_TABLE.' - WHERE storage_category_id = '.$category_id.' -;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($database_elements, $row['file']); - } - - $inserts = array(); - foreach ($xml_elements as $xml_element) - { - // minimal tag : <element file="albatros.jpg"/> - $file = getAttribute($xml_element, 'file'); - - // is the picture already existing in the database ? - if (!in_array($file, $database_elements)) - { - $insert = array(); - $insert{'file'} = $file; - $insert{'storage_category_id'} = $category_id; - $insert{'date_available'} = CURRENT_DATE; - $optional_atts = array('tn_ext', - 'representative_ext', - 'filesize', - 'width', - 'height', - 'date_creation', - 'author', - 'keywords', - 'name', - 'comment', - 'has_high', - 'path'); - foreach ($optional_atts as $att) - { - if (getAttribute($xml_element, $att) != '') - { - $insert{$att} = getAttribute($xml_element, $att); - } - } - array_push($inserts, $insert); - } - } - - if (count($inserts) > 0) - { - $dbfields = array('file','storage_category_id','date_available','tn_ext', - 'filesize','width','height','date_creation','author', - 'keywords','name','comment','has_high','path'); - mass_inserts(IMAGES_TABLE, $dbfields, $inserts); - $counts{'new_elements'}+= count($inserts); - - // what are the ids of the pictures in the $category_id ? - $ids = array(); - - $query = ' -SELECT id - FROM '.IMAGES_TABLE.' - WHERE storage_category_id = '.$category_id.' -;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($ids, $row['id']); - } - - // recreation of the links between this storage category pictures and - // its storage category - $query = ' -DELETE FROM '.IMAGE_CATEGORY_TABLE.' - WHERE category_id = '.$category_id.' - AND image_id IN ('.implode(',', $ids).') -;'; - pwg_query($query); - - $query = ' -INSERT INTO '.IMAGE_CATEGORY_TABLE.' - (category_id,image_id) - VALUES'; - foreach ($ids as $num => $image_id) - { - $query.= ' - '; - if ($num > 0) - { - $query.= ','; - } - $query.= '('.$category_id.','.$image_id.')'; - } - $query.= ' -;'; - pwg_query($query); - // set a new representative element for this category - $query = ' -SELECT image_id - FROM '.IMAGE_CATEGORY_TABLE.' - WHERE category_id = '.$category_id.' - ORDER BY RAND() - LIMIT 0,1 -;'; - list($representative) = mysql_fetch_array(pwg_query($query)); - $query = ' -UPDATE '.CATEGORIES_TABLE.' - SET representative_picture_id = '.$representative.' - WHERE id = '.$category_id.' -;'; - pwg_query($query); - } -} -// +-----------------------------------------------------------------------+ -// | template init | -// +-----------------------------------------------------------------------+ -$template->set_filenames(array('remote_site'=>'admin/remote_site.tpl')); - -$template->assign_vars( - array( - 'L_SUBMIT'=>$lang['submit'], - 'L_REMOTE_SITE_CREATE'=>$lang['remote_site_create'], - 'L_REMOTE_SITE_GENERATE'=>$lang['remote_site_generate'], - 'L_REMOTE_SITE_GENERATE_HINT'=>$lang['remote_site_generate_hint'], - 'L_REMOTE_SITE_UPDATE'=>$lang['remote_site_update'], - 'L_REMOTE_SITE_UPDATE_HINT'=>$lang['remote_site_update_hint'], - 'L_REMOTE_SITE_CLEAN'=>$lang['remote_site_clean'], - 'L_REMOTE_SITE_CLEAN_HINT'=>$lang['remote_site_clean_hint'], - 'L_REMOTE_SITE_DELETE'=>$lang['remote_site_delete'], - 'L_REMOTE_SITE_DELETE_HINT'=>$lang['remote_site_delete_hint'], - 'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'], - 'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'], - 'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'], - 'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'], - 'L_REMOTE_SITE_REMOVED_TITLE'=>$lang['remote_site_removed_title'], - 'L_REMOTE_SITE_REMOVED'=>$lang['remote_site_removed'], - 'L_REMOTE_SITE_LOCAL_FOUND'=>$lang['remote_site_local_found'], - 'L_REMOTE_SITE_LOCAL_NEW'=>$lang['remote_site_local_new'], - 'L_REMOTE_SITE_LOCAL_UPDATE'=>$lang['remote_site_local_update'], - - 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=remote_site', - - 'F_ACTION'=>PHPWG_ROOT_PATH.'admin.php?page=remote_site' - ) - ); - -// +-----------------------------------------------------------------------+ -// | new site creation form | -// +-----------------------------------------------------------------------+ -if (isset($_POST['submit'])) -{ - // site must start by http:// or https:// - if (!preg_match('/^https?:\/\/[~\/\.\w-]+$/', $_POST['galleries_url'])) - { - array_push($page['errors'], $lang['remote_site_uncorrect_url']); - } - else - { - $page['galleries_url'] = preg_replace('/[\/]*$/', - '', - $_POST['galleries_url']); - $page['galleries_url'].= '/'; - // site must not exists - $query = ' -SELECT COUNT(id) AS count - FROM '.SITES_TABLE.' - WHERE galleries_url = \''.$page['galleries_url'].'\' -;'; - $row = mysql_fetch_array(pwg_query($query)); - if ($row['count'] > 0) - { - array_push($page['errors'], $lang['remote_site_already_exists']); - } - } - - if (count($page['errors']) == 0) - { - $url = $page['galleries_url'].'create_listing_file.php'; - $url.= '?action=test'; - $url.= '&version='.PHPWG_VERSION; - if ($lines = @file($url)) - { - $first_line = strip_tags($lines[0]); - if (!preg_match('/^PWG-INFO-2:/', $first_line)) - { - array_push($page['errors'], - $lang['remote_site_error'].' : '.$first_line); - } - } - else - { - array_push($page['errors'], $lang['remote_site_file_not_found']); - } - } - - if (count($page['errors']) == 0) - { - $query = ' -INSERT INTO '.SITES_TABLE.' - (galleries_url) - VALUES - (\''.$page['galleries_url'].'\') -;'; - pwg_query($query); - - array_push($page['infos'], - $page['galleries_url'].' '.$lang['remote_site_created']); - } -} -// +-----------------------------------------------------------------------+ -// | actions on site | -// +-----------------------------------------------------------------------+ -if (isset($_GET['site']) and is_numeric($_GET['site'])) -{ - $page['site'] = $_GET['site']; -} - -if (isset($_GET['action'])) -{ - if (isset($page['site'])) - { - $query = ' -SELECT galleries_url - FROM '.SITES_TABLE.' - WHERE id = '.$page['site'].' -;'; - list($galleries_url) = mysql_fetch_array(pwg_query($query)); - } - - switch($_GET['action']) - { - case 'delete' : - { - delete_site($page['site']); - array_push($page['infos'], - $galleries_url.' '.$lang['remote_site_deleted']); - break; - } - case 'generate' : - { - $title = $galleries_url.' : '.$lang['remote_site_generate']; - $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); - remote_output($galleries_url.'create_listing_file.php?action=generate'); - break; - } - case 'update' : - { - $title = $galleries_url.' : '.$lang['remote_site_update']; - $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); - update_remote_site($galleries_url.'listing.xml', $page['site']); - break; - } - case 'clean' : - { - $title = $galleries_url.' : '.$lang['remote_site_clean']; - $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); - remote_output($galleries_url.'create_listing_file.php?action=clean'); - break; - } - case 'local_update' : - { - $local_listing = PHPWG_ROOT_PATH.'listing.xml'; - $xml_content = getXmlCode($local_listing); - $url = getAttribute(getChild($xml_content, 'informations'), 'url'); - - // is the site already existing ? - $query = ' -SELECT id - FROM '.SITES_TABLE.' - WHERE galleries_url = \''.addslashes($url).'\' -;'; - $result = pwg_query($query); - if (mysql_num_rows($result) == 0) - { - // we have to register this site in the database - $query = ' -INSERT INTO '.SITES_TABLE.' - (galleries_url) - VALUES - (\''.$url.'\') -;'; - pwg_query($query); - $site_id = mysql_insert_id(); - } - else - { - // we get the already registered id - $row = mysql_fetch_array($result); - $site_id = $row['id']; - } - - $title = $url.' : '.$lang['remote_site_local_update']; - $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); - update_remote_site($local_listing, $site_id); - break; - } - } -} -else -{ - // we search a "local" listing.xml file - $local_listing = PHPWG_ROOT_PATH.'listing.xml'; - if (is_file($local_listing)) - { - $xml_content = getXmlCode($local_listing); - $url = getAttribute(getChild($xml_content, 'informations'), 'url'); - - $base_url = PHPWG_ROOT_PATH.'admin.php?page=remote_site&action='; - - $template->assign_block_vars( - 'local', - array( - 'URL' => $url, - 'U_UPDATE' => $base_url.'local_update' - ) - ); - - // is the site already existing ? - $query = ' -SELECT COUNT(*) - FROM '.SITES_TABLE.' - WHERE galleries_url = \''.addslashes($url).'\' -;'; - list($count) = mysql_fetch_array(pwg_query($query)); - if ($count == 0) - { - $template->assign_block_vars('local.new_site', array()); - } - } -} -// +-----------------------------------------------------------------------+ -// | remote sites list | -// +-----------------------------------------------------------------------+ - -// site 1 is the local site, should not be taken into account -$query = ' -SELECT id, galleries_url - FROM '.SITES_TABLE.' - WHERE id != 1 -;'; -$result = pwg_query($query); - -if (mysql_num_rows($result) > 0) -{ - $template->assign_block_vars('sites', array()); -} - -while ($row = mysql_fetch_array($result)) -{ - $base_url = PHPWG_ROOT_PATH.'admin.php'; - $base_url.= '?page=remote_site'; - $base_url.= '&site='.$row['id']; - $base_url.= '&action='; - - $template->assign_block_vars( - 'sites.site', - array( - 'NAME' => $row['galleries_url'], - 'U_GENERATE' => $base_url.'generate', - 'U_UPDATE' => $base_url.'update', - 'U_CLEAN' => $base_url.'clean', - 'U_DELETE' => $base_url.'delete' - ) - ); -} -// +-----------------------------------------------------------------------+ -// | sending html code | -// +-----------------------------------------------------------------------+ -$template->assign_var_from_handle('ADMIN_CONTENT', 'remote_site'); -?>
\ No newline at end of file diff --git a/admin/site_manager.php b/admin/site_manager.php index 0f8ca7d41..b6f3b8f24 100644 --- a/admin/site_manager.php +++ b/admin/site_manager.php @@ -1,260 +1,258 @@ -<?php
-// +-----------------------------------------------------------------------+
-// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
-// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
-// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $RCSfile$
-// | last update : $Date: 2006-01-31 21:46:26 -0500 (Tue, 31 Jan 2006) $
-// | last modifier : $Author: rvelices $
-// | revision : $Revision: 1020 $
-// +-----------------------------------------------------------------------+
-// | 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!");
-}
-include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
-
-/**
- * requests the given $url (a remote create_listing_file.php) and fills a
- * list of lines corresponding to request output
- *
- * @param string $url
- * @return void
- */
-function remote_output($url)
-{
- global $template, $page;
-
- if($lines = @file($url))
- {
- $template->assign_block_vars('remote_output', array());
- // cleaning lines from HTML tags
- foreach ($lines as $line)
- {
- $line = trim(strip_tags($line));
- if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches))
- {
- $template->assign_block_vars(
- 'remote_output.remote_line',
- array(
- 'CLASS' => 'remote'.ucfirst(strtolower($matches[1])),
- 'CONTENT' => $line
- )
- );
- }
- }
- }
- else
- {
- array_push($page['errors'], l10n('remote_site_file_not_found'));
- }
-}
-
-
-// +-----------------------------------------------------------------------+
-// | template init |
-// +-----------------------------------------------------------------------+
-$template->set_filenames(array('site_manager'=>'admin/site_manager.tpl'));
-
-// +-----------------------------------------------------------------------+
-// | new site creation form |
-// +-----------------------------------------------------------------------+
-if (isset($_POST['submit']))
-{
- $is_remote = url_is_remote( $_POST['galleries_url'] );
- $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']);
- $url.= '/';
- if (! $is_remote)
- {
- if ( ! (strpos($url, '.') === 0 ) )
- {
- $url = './' . $url;
- }
- }
-
- // site must not exists
- $query = '
-SELECT COUNT(id) AS count
- FROM '.SITES_TABLE.'
- WHERE galleries_url = \''.$url.'\'
-;';
- $row = mysql_fetch_array(pwg_query($query));
- if ($row['count'] > 0)
- {
- array_push($page['errors'],
- l10n('remote_site_already_exists').' ['.$url.']');
- }
- if (count($page['errors']) == 0)
- {
- if ($is_remote)
- {
- $clf_url = $url.'create_listing_file.php';
- $clf_url.= '?action=test';
- $clf_url.= '&version='.PHPWG_VERSION;
- if ($lines = @file($clf_url))
- {
- $first_line = strip_tags($lines[0]);
- if (!preg_match('/^PWG-INFO-2:/', $first_line))
- {
- array_push($page['errors'],
- l10n('remote_site_error').' : '.$first_line);
- }
- }
- else
- {
- array_push($page['errors'], l10n('remote_site_file_not_found') );
- }
- }
- else
- { // local directory
- if ( ! file_exists($url) )
- {
- array_push($page['errors'],
- l10n('Directory does not exist').' ['.$url.']');
- }
- }
- }
-
- if (count($page['errors']) == 0)
- {
- $query = '
-INSERT INTO '.SITES_TABLE.'
- (galleries_url)
- VALUES
- (\''.$url.'\')
-;';
- pwg_query($query);
- array_push($page['infos'],
- $url.' '.l10n('remote_site_created'));
- }
-}
-
-// +-----------------------------------------------------------------------+
-// | actions on site |
-// +-----------------------------------------------------------------------+
-if (isset($_GET['site']) and is_numeric($_GET['site']))
-{
- $page['site'] = $_GET['site'];
-}
-if (isset($_GET['action']) and isset($page['site']) )
-{
- $query = '
-SELECT galleries_url
- FROM '.SITES_TABLE.'
- WHERE id = '.$page['site'].'
-;';
- list($galleries_url) = mysql_fetch_array(pwg_query($query));
- switch($_GET['action'])
- {
- case 'generate' :
- {
- $title = $galleries_url.' : '.l10n('remote_site_generate');
- $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
- remote_output($galleries_url.'create_listing_file.php?action=generate');
- break;
- }
- case 'test' :
- {
- $title = $galleries_url.' : '.l10n('remote_site_test');
- $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
- remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION);
- break;
- }
- case 'clean' :
- {
- $title = $galleries_url.' : '.l10n('remote_site_clean');
- $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
- remote_output($galleries_url.'create_listing_file.php?action=clean');
- break;
- }
- case 'delete' :
- {
- delete_site($page['site']);
- array_push($page['infos'],
- $galleries_url.' '.l10n('remote_site_deleted'));
- break;
- }
- }
-}
-
-$template->assign_vars( array(
- 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php'
- .get_query_string_diff( array('action','site') )
- ) );
-
-// +-----------------------------------------------------------------------+
-// | remote sites list |
-// +-----------------------------------------------------------------------+
-
-$query = '
-SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images
-FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c
-ON s.id=c.site_id
-GROUP BY s.id'.
-';';
-$result = pwg_query($query);
-
-if (mysql_num_rows($result) > 0)
-{
- $template->assign_block_vars('sites', array());
-}
-while ($row = mysql_fetch_array($result))
-{
- $is_remote = url_is_remote($row['galleries_url']);
- $base_url = PHPWG_ROOT_PATH.'admin.php';
- $base_url.= '?page=site_manager';
- $base_url.= '&site='.$row['id'];
- $base_url.= '&action=';
-
- $update_url = PHPWG_ROOT_PATH.'admin.php';
- $update_url.= '?page=site_update';
- $update_url.= '&site='.$row['id'];
-
- $template->assign_block_vars(
- 'sites.site',
- array(
- 'NAME' => $row['galleries_url'],
- 'TYPE' => l10n( $is_remote ? 'Remote' : 'Local' ),
- 'CATEGORIES' => $row['nb_categories'],
- 'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0,
- 'U_UPDATE' => $update_url
- )
- );
-
- if ($is_remote)
- {
- $template->assign_block_vars('sites.site.remote',
- array(
- 'U_TEST' => $base_url.'test',
- 'U_GENERATE' => $base_url.'generate',
- 'U_CLEAN' => $base_url.'clean'
- )
- );
- }
-
- if ($row['id'] != 1)
- {
- $template->assign_block_vars( 'sites.site.delete',
- array('U_DELETE' => $base_url.'delete') );
- }
-}
-
-$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager');
+<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2006-01-31 21:46:26 -0500 (Tue, 31 Jan 2006) $ +// | last modifier : $Author: rvelices $ +// | revision : $Revision: 1020 $ +// +-----------------------------------------------------------------------+ +// | 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!"); +} +include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); + +/** + * requests the given $url (a remote create_listing_file.php) and fills a + * list of lines corresponding to request output + * + * @param string $url + * @return void + */ +function remote_output($url) +{ + global $template, $page; + + if($lines = @file($url)) + { + $template->assign_block_vars('remote_output', array()); + // cleaning lines from HTML tags + foreach ($lines as $line) + { + $line = trim(strip_tags($line)); + if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches)) + { + $template->assign_block_vars( + 'remote_output.remote_line', + array( + 'CLASS' => 'remote'.ucfirst(strtolower($matches[1])), + 'CONTENT' => $line + ) + ); + } + } + } + else + { + array_push($page['errors'], l10n('site_err_remote_file_not_found')); + } +} + + +// +-----------------------------------------------------------------------+ +// | template init | +// +-----------------------------------------------------------------------+ +$template->set_filenames(array('site_manager'=>'admin/site_manager.tpl')); + +// +-----------------------------------------------------------------------+ +// | new site creation form | +// +-----------------------------------------------------------------------+ +if (isset($_POST['submit'])) +{ + $is_remote = url_is_remote( $_POST['galleries_url'] ); + $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']); + $url.= '/'; + if (! $is_remote) + { + if ( ! (strpos($url, '.') === 0 ) ) + { + $url = './' . $url; + } + } + + // site must not exists + $query = ' +SELECT COUNT(id) AS count + FROM '.SITES_TABLE.' + WHERE galleries_url = \''.$url.'\' +;'; + $row = mysql_fetch_array(pwg_query($query)); + if ($row['count'] > 0) + { + array_push($page['errors'], + l10n('site_already_exists').' ['.$url.']'); + } + if (count($page['errors']) == 0) + { + if ($is_remote) + { + $clf_url = $url.'create_listing_file.php'; + $clf_url.= '?action=test'; + $clf_url.= '&version='.PHPWG_VERSION; + if ($lines = @file($clf_url)) + { + $first_line = strip_tags($lines[0]); + if (!preg_match('/^PWG-INFO-2:/', $first_line)) + { + array_push($page['errors'], + l10n('site_err').' : '.$first_line); + } + } + else + { + array_push($page['errors'], l10n('site_err_remote_file_not_found') ); + } + } + else + { // local directory + if ( ! file_exists($url) ) + { + array_push($page['errors'], + l10n('Directory does not exist').' ['.$url.']'); + } + } + } + + if (count($page['errors']) == 0) + { + $query = ' +INSERT INTO '.SITES_TABLE.' + (galleries_url) + VALUES + (\''.$url.'\') +;'; + pwg_query($query); + array_push($page['infos'], + $url.' '.l10n('site_created')); + } +} + +// +-----------------------------------------------------------------------+ +// | actions on site | +// +-----------------------------------------------------------------------+ +if (isset($_GET['site']) and is_numeric($_GET['site'])) +{ + $page['site'] = $_GET['site']; +} +if (isset($_GET['action']) and isset($page['site']) ) +{ + $query = ' +SELECT galleries_url + FROM '.SITES_TABLE.' + WHERE id = '.$page['site'].' +;'; + list($galleries_url) = mysql_fetch_array(pwg_query($query)); + switch($_GET['action']) + { + case 'generate' : + { + $title = $galleries_url.' : '.l10n('remote_site_generate'); + $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); + remote_output($galleries_url.'create_listing_file.php?action=generate'); + break; + } + case 'test' : + { + $title = $galleries_url.' : '.l10n('remote_site_test'); + $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); + remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION); + break; + } + case 'clean' : + { + $title = $galleries_url.' : '.l10n('remote_site_clean'); + $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); + remote_output($galleries_url.'create_listing_file.php?action=clean'); + break; + } + case 'delete' : + { + delete_site($page['site']); + array_push($page['infos'], + $galleries_url.' '.l10n('site_deleted')); + break; + } + } +} + +$template->assign_vars( array( + 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php' + .get_query_string_diff( array('action','site') ) + ) ); + +// +-----------------------------------------------------------------------+ +// | remote sites list | +// +-----------------------------------------------------------------------+ + +$query = ' +SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images +FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c +ON s.id=c.site_id +GROUP BY s.id'. +';'; +$result = pwg_query($query); + +if (mysql_num_rows($result) > 0) +{ + $template->assign_block_vars('sites', array()); +} +while ($row = mysql_fetch_array($result)) +{ + $is_remote = url_is_remote($row['galleries_url']); + $base_url = PHPWG_ROOT_PATH.'admin.php'; + $base_url.= '?page=site_manager'; + $base_url.= '&site='.$row['id']; + $base_url.= '&action='; + + $update_url = PHPWG_ROOT_PATH.'admin.php'; + $update_url.= '?page=site_update'; + $update_url.= '&site='.$row['id']; + $template->assign_block_vars( + 'sites.site', + array( + 'NAME' => $row['galleries_url'], + 'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ), + 'CATEGORIES' => $row['nb_categories'], + 'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0, + 'U_SYNCHRONIZE' => $update_url + ) + ); + if ($is_remote) + { + $template->assign_block_vars('sites.site.remote', + array( + 'U_TEST' => $base_url.'test', + 'U_GENERATE' => $base_url.'generate', + 'U_CLEAN' => $base_url.'clean' + ) + ); + } + + if ($row['id'] != 1) + { + $template->assign_block_vars( 'sites.site.delete', + array('U_DELETE' => $base_url.'delete') ); + } +} + +$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager'); ?>
\ No newline at end of file diff --git a/admin/site_reader_local.php b/admin/site_reader_local.php index 758906777..fc31aaec8 100644 --- a/admin/site_reader_local.php +++ b/admin/site_reader_local.php @@ -1,254 +1,254 @@ -<?php
-// +-----------------------------------------------------------------------+
-// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
-// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
-// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $RCSfile$
-// | last update : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $
-// | last modifier : $Author: plg $
-// | revision : $Revision: 967 $
-// +-----------------------------------------------------------------------+
-// | 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. |
-// +-----------------------------------------------------------------------+
-
-// provides data for site synchronization from the local file system
-class LocalSiteReader
-{
-
-var $site_url;
-
-function LocalSiteReader($url)
-{
- $this->site_url = $url;
-}
-
-/**
- * Is this local site ok ?
- *
- * @return true on success, false otherwise
- */
-function open()
-{
- global $errors;
- if (!is_dir($this->site_url))
- {
- array_push($errors, array('path' => $this->site_url, 'type' => 'PWG-ERROR-NODIR'));
- return false;
- }
- return true;
-}
-
-// retrieve file system sub-directories fulldirs
-function get_full_directories($basedir)
-{
- $fs_fulldirs = get_fs_directories($basedir);
- return $fs_fulldirs;
-}
-
-/**
- * Returns an array with all file system files according to $conf['file_ext']
- * and $conf['picture_ext']
- * @param string $path recurse in this directory
- * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... )
- */
-function get_elements($path)
-{
- global $conf;
- if (!isset($conf['flip_picture_ext']))
- {
- $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
- }
- if (!isset($conf['flip_file_ext']))
- {
- $conf['flip_file_ext'] = array_flip($conf['file_ext']);
- }
-
- $subdirs = array();
- $fs = array();
- if (is_dir($path) && $contents = opendir($path) )
- {
- while (($node = readdir($contents)) !== false)
- {
- if (is_file($path.'/'.$node))
- {
- $extension = get_extension($node);
- $filename_wo_ext = get_filename_wo_extension($node);
-
- // searching the thumbnail
- $tn_ext = $this->get_tn_ext($path, $filename_wo_ext);
-
- if (isset($conf['flip_picture_ext'][$extension]))
- {
- $fs[ $path.'/'.$node ] = array(
- 'tn_ext' => $tn_ext,
- 'has_high' => $this->get_has_high($path, $node)
- );
- }
- else if (isset($conf['flip_file_ext'][$extension]))
- { // file not a picture
- $representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
-
- $fs[ $path.'/'.$node ] = array(
- 'tn_ext' => $tn_ext,
- 'representative_ext' => $representative_ext
- );
- }
-
- }
- elseif (is_dir($path.'/'.$node)
- and $node != '.'
- and $node != '..'
- and $node != 'pwg_high'
- and $node != 'pwg_representative'
- and $node != 'thumbnail' )
- {
- array_push($subdirs, $node);
- }
- } //end while readdir
- closedir($contents);
-
- foreach ($subdirs as $subdir)
- {
- $tmp_fs = $this->get_elements($path.'/'.$subdir);
- $fs = array_merge($fs, $tmp_fs);
- }
- } //end if is_dir
- return $fs;
-}
-
-// returns the name of the attributes that are supported for
-// update/synchronization according to configuration
-function get_update_attributes()
-{
- global $conf;
- $update_fields = array( 'has_high', 'representative_ext',
- 'filesize', 'width', 'height' );
- if ($conf['use_exif'])
- {
- $update_fields =
- array_merge(
- $update_fields,
- array_keys($conf['use_exif_mapping'])
- );
- }
-
- if ($conf['use_iptc'])
- {
- $update_fields =
- array_merge(
- $update_fields,
- array_keys($conf['use_iptc_mapping'])
- );
- }
- return $update_fields;
-}
-
-// returns a hash of attributes (metadata+filesize+width,...) for file
-function get_element_update_attributes($file)
-{
- global $conf;
- if (!is_file($file))
- {
- return null;
- }
-
- $data = array();
-
- $filename = basename($file);
- $data['has_high'] = $this->get_has_high( dirname($file), $filename );
- $data['representative_ext'] = $this->get_representative_ext( dirname($file),
- get_filename_wo_extension($filename) );
-
- $data['filesize'] = floor(filesize($file)/1024);
- if ($image_size = @getimagesize($file))
- {
- $data['width'] = $image_size[0];
- $data['height'] = $image_size[1];
- }
-
- if ($conf['use_exif'])
- {
- $exif = get_sync_exif_data($file);
-
- if (count($exif) > 0)
- {
- foreach (array_keys($exif) as $key)
- {
- $data[$key] = addslashes($exif[$key]);
- }
- }
- }
-
- if ($conf['use_iptc'])
- {
- $iptc = get_sync_iptc_data($file);
- if (count($iptc) > 0)
- {
- foreach (array_keys($iptc) as $key)
- {
- $data[$key] = addslashes($iptc[$key]);
- }
- }
- }
- return $data;
-}
-
-
-//-------------------------------------------------- private functions --------
-function get_representative_ext($path, $filename_wo_ext)
-{
- global $conf;
- $base_test = $path.'/pwg_representative/';
- $base_test.= $filename_wo_ext.'.';
- foreach ($conf['picture_ext'] as $ext)
- {
- $test = $base_test.$ext;
- if (is_file($test))
- {
- return $ext;
- }
- }
- return null;
-}
-
-function get_tn_ext($path, $filename_wo_ext)
-{
- global $conf;
- $base_test = $path.'/thumbnail/';
- $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.';
- foreach ($conf['picture_ext'] as $ext)
- {
- $test = $base_test.$ext;
- if (is_file($test))
- {
- return $ext;
- }
- }
- return null;
-}
-
-function get_has_high($path, $filename)
-{
- if (is_file($path.'/pwg_high/'.$filename))
- {
- return 'true';
- }
- return null;
-}
-
-}
+<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $ +// | last modifier : $Author: plg $ +// | revision : $Revision: 967 $ +// +-----------------------------------------------------------------------+ +// | 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. | +// +-----------------------------------------------------------------------+ + +// provides data for site synchronization from the local file system +class LocalSiteReader +{ + +var $site_url; + +function LocalSiteReader($url) +{ + $this->site_url = $url; +} + +/** + * Is this local site ok ? + * + * @return true on success, false otherwise + */ +function open() +{ + global $errors; + if (!is_dir($this->site_url)) + { + array_push($errors, array('path' => $this->site_url, 'type' => 'PWG-ERROR-NO-FS')); + return false; + } + return true; +} + +// retrieve file system sub-directories fulldirs +function get_full_directories($basedir) +{ + $fs_fulldirs = get_fs_directories($basedir); + return $fs_fulldirs; +} + +/** + * Returns an array with all file system files according to $conf['file_ext'] + * and $conf['picture_ext'] + * @param string $path recurse in this directory + * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... ) + */ +function get_elements($path) +{ + global $conf; + if (!isset($conf['flip_picture_ext'])) + { + $conf['flip_picture_ext'] = array_flip($conf['picture_ext']); + } + if (!isset($conf['flip_file_ext'])) + { + $conf['flip_file_ext'] = array_flip($conf['file_ext']); + } + + $subdirs = array(); + $fs = array(); + if (is_dir($path) && $contents = opendir($path) ) + { + while (($node = readdir($contents)) !== false) + { + if (is_file($path.'/'.$node)) + { + $extension = get_extension($node); + $filename_wo_ext = get_filename_wo_extension($node); + + // searching the thumbnail + $tn_ext = $this->get_tn_ext($path, $filename_wo_ext); + + if (isset($conf['flip_picture_ext'][$extension])) + { + $fs[ $path.'/'.$node ] = array( + 'tn_ext' => $tn_ext, + 'has_high' => $this->get_has_high($path, $node) + ); + } + else if (isset($conf['flip_file_ext'][$extension])) + { // file not a picture + $representative_ext = $this->get_representative_ext($path, $filename_wo_ext); + + $fs[ $path.'/'.$node ] = array( + 'tn_ext' => $tn_ext, + 'representative_ext' => $representative_ext + ); + } + + } + elseif (is_dir($path.'/'.$node) + and $node != '.' + and $node != '..' + and $node != 'pwg_high' + and $node != 'pwg_representative' + and $node != 'thumbnail' ) + { + array_push($subdirs, $node); + } + } //end while readdir + closedir($contents); + + foreach ($subdirs as $subdir) + { + $tmp_fs = $this->get_elements($path.'/'.$subdir); + $fs = array_merge($fs, $tmp_fs); + } + } //end if is_dir + return $fs; +} + +// returns the name of the attributes that are supported for +// update/synchronization according to configuration +function get_update_attributes() +{ + global $conf; + $update_fields = array( 'has_high', 'representative_ext', + 'filesize', 'width', 'height' ); + if ($conf['use_exif']) + { + $update_fields = + array_merge( + $update_fields, + array_keys($conf['use_exif_mapping']) + ); + } + + if ($conf['use_iptc']) + { + $update_fields = + array_merge( + $update_fields, + array_keys($conf['use_iptc_mapping']) + ); + } + return $update_fields; +} + +// returns a hash of attributes (metadata+filesize+width,...) for file +function get_element_update_attributes($file) +{ + global $conf; + if (!is_file($file)) + { + return null; + } + + $data = array(); + + $filename = basename($file); + $data['has_high'] = $this->get_has_high( dirname($file), $filename ); + $data['representative_ext'] = $this->get_representative_ext( dirname($file), + get_filename_wo_extension($filename) ); + + $data['filesize'] = floor(filesize($file)/1024); + if ($image_size = @getimagesize($file)) + { + $data['width'] = $image_size[0]; + $data['height'] = $image_size[1]; + } + + if ($conf['use_exif']) + { + $exif = get_sync_exif_data($file); + + if (count($exif) > 0) + { + foreach (array_keys($exif) as $key) + { + $data[$key] = addslashes($exif[$key]); + } + } + } + + if ($conf['use_iptc']) + { + $iptc = get_sync_iptc_data($file); + if (count($iptc) > 0) + { + foreach (array_keys($iptc) as $key) + { + $data[$key] = addslashes($iptc[$key]); + } + } + } + return $data; +} + + +//-------------------------------------------------- private functions -------- +function get_representative_ext($path, $filename_wo_ext) +{ + global $conf; + $base_test = $path.'/pwg_representative/'; + $base_test.= $filename_wo_ext.'.'; + foreach ($conf['picture_ext'] as $ext) + { + $test = $base_test.$ext; + if (is_file($test)) + { + return $ext; + } + } + return null; +} + +function get_tn_ext($path, $filename_wo_ext) +{ + global $conf; + $base_test = $path.'/thumbnail/'; + $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.'; + foreach ($conf['picture_ext'] as $ext) + { + $test = $base_test.$ext; + if (is_file($test)) + { + return $ext; + } + } + return null; +} + +function get_has_high($path, $filename) +{ + if (is_file($path.'/pwg_high/'.$filename)) + { + return 'true'; + } + return null; +} + +} ?>
\ No newline at end of file diff --git a/admin/site_reader_remote.php b/admin/site_reader_remote.php index bc4cefff0..3bcd367d3 100644 --- a/admin/site_reader_remote.php +++ b/admin/site_reader_remote.php @@ -1,192 +1,192 @@ -<?php
-// +-----------------------------------------------------------------------+
-// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
-// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
-// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $RCSfile$
-// | last update : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $
-// | last modifier : $Author: plg $
-// | revision : $Revision: 967 $
-// +-----------------------------------------------------------------------+
-// | 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. |
-// +-----------------------------------------------------------------------+
-
-
-// provides data for site synchronization from a remote listing.xml
-class RemoteSiteReader
-{
-
-var $site_url;
-var $site_dirs;
-var $site_files;
-var $insert_attributes;
-var $update_attributes;
-
-function RemoteSiteReader($url)
-{
- $this->site_url = $url;
- $this->insert_attributes = array('tn_ext', 'representative_ext', 'has_high');
- $this->update_attributes = array( 'representative_ext', 'has_high', 'filesize', 'width', 'height' );
-}
-
-/**
- * Is this remote site ok ?
- *
- * @return true on success, false otherwise
- */
-function open()
-{
- global $errors;
- $listing_file = $this->site_url.'/listing.xml';
- if (@fopen($listing_file, 'r'))
- {
- $this->site_dirs = array();
- $this->site_files = array();
- $xml_content = getXmlCode($listing_file);
- $info_xml_element = getChild($xml_content, 'informations');
- if ( getAttribute($info_xml_element , 'phpwg_version') != PHPWG_VERSION )
- {
- array_push($errors, array('path' => $listing_file, 'type' => 'PWG-ERROR-VERSION'));
- return false;
- }
- $meta_attributes = explode ( ',',
- getAttribute($info_xml_element , 'metadata') );
- $this->update_attributes = array_merge( $this->update_attributes, $meta_attributes );
- $this->build_structure($xml_content, '', 0);
- return true;
- }
- else
- {
- array_push($errors, array('path' => $listing_file, 'type' => 'PWG-ERROR-NO-FS'));
- return false;
- }
-}
-
-// retrieve xml sub-directories fulldirs
-function get_full_directories($basedir)
-{
- $dirs = array();
- foreach ( array_keys($this->site_dirs) as $dir)
- {
- $full_dir = $this->site_url . $dir;
- if ( $full_dir!=$basedir
- and strpos($full_dir, $basedir)===0
- )
- {
- array_push($dirs, $full_dir);
- }
- }
- return $dirs;
-}
-
-/**
- * Returns a hash with all elements (images and files) inside the full $path
- * according to listing.xml
- * @param string $path recurse in this directory only
- * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... )
- */
-function get_elements($path)
-{
- $elements = array();
- foreach ( $this->site_dirs as $dir=>$files)
- {
- $full_dir = $this->site_url . $dir;
- if ( strpos($full_dir, $path)===0 )
- {
- foreach ( $files as $file)
- {
- $data = $this->get_element_attributes($file,
- $this->insert_attributes);
- $elements[$file] = $data;
- }
- }
- }
-
- return $elements;
-}
-
-// returns the name of the attributes that are supported for
-// update/synchronization according to listing.xml
-function get_update_attributes()
-{
- return $this->update_attributes;
-}
-
-// returns a hash of attributes (metadata+filesize+width,...) for file
-function get_element_update_attributes($file)
-{
- return $this->get_element_attributes($file,
- $this->update_attributes);
-}
-
-//-------------------------------------------------- private functions --------
-/**
- * Returns a hash of image/file attributes
- * @param string $file fully qualified file name
- * @param array $attributes specifies which attributes to retrieve
- * returned
-*/
-function get_element_attributes($file, $attributes)
-{
- $xml_element = $this->site_files[$file];
- if ( ! isset($xml_element) )
- {
- return null;
- }
- $data = array();
- foreach($attributes as $att)
- {
- if (getAttribute($xml_element, $att) != '')
- {
- $val = html_entity_decode( getAttribute($xml_element, $att) );
- $data[$att] = addslashes($val);
- }
- }
- return $data;
-}
-
-// recursively parse the xml_content for later usage
-function build_structure($xml_content, $basedir, $level)
-{
- $temp_dirs = getChildren($xml_content, 'dir'.$level);
- foreach ($temp_dirs as $temp_dir)
- {
- $dir_name = $basedir;
- if ($dir_name != '' )
- {
- $dir_name .= '/';
- }
- $dir_name .= getAttribute($temp_dir, 'name');
- $this->site_dirs[ $dir_name ] = array();
- $this->build_structure($temp_dir, $dir_name, $level+1);
- }
-
- if ($basedir != '')
- {
- $xml_elements = getChildren( getChild($xml_content, 'root'), 'element' );
- foreach ($xml_elements as $xml_element)
- {
- $path = getAttribute($xml_element, 'path');
- $this->site_files[$path] = $xml_element;
- array_push( $this->site_dirs[$basedir], $path);
- }
- }
-}
-
-}
-
+<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $ +// | last modifier : $Author: plg $ +// | revision : $Revision: 967 $ +// +-----------------------------------------------------------------------+ +// | 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. | +// +-----------------------------------------------------------------------+ + + +// provides data for site synchronization from a remote listing.xml +class RemoteSiteReader +{ + +var $site_url; +var $site_dirs; +var $site_files; +var $insert_attributes; +var $update_attributes; + +function RemoteSiteReader($url) +{ + $this->site_url = $url; + $this->insert_attributes = array('tn_ext', 'representative_ext', 'has_high'); + $this->update_attributes = array( 'representative_ext', 'has_high', 'filesize', 'width', 'height' ); +} + +/** + * Is this remote site ok ? + * + * @return true on success, false otherwise + */ +function open() +{ + global $errors; + $listing_file = $this->site_url.'/listing.xml'; + if (@fopen($listing_file, 'r')) + { + $this->site_dirs = array(); + $this->site_files = array(); + $xml_content = getXmlCode($listing_file); + $info_xml_element = getChild($xml_content, 'informations'); + if ( getAttribute($info_xml_element , 'phpwg_version') != PHPWG_VERSION ) + { + array_push($errors, array('path' => $listing_file, 'type' => 'PWG-ERROR-VERSION')); + return false; + } + $meta_attributes = explode ( ',', + getAttribute($info_xml_element , 'metadata') ); + $this->update_attributes = array_merge( $this->update_attributes, $meta_attributes ); + $this->build_structure($xml_content, '', 0); + return true; + } + else + { + array_push($errors, array('path' => $listing_file, 'type' => 'PWG-ERROR-NOLISTING')); + return false; + } +} + +// retrieve xml sub-directories fulldirs +function get_full_directories($basedir) +{ + $dirs = array(); + foreach ( array_keys($this->site_dirs) as $dir) + { + $full_dir = $this->site_url . $dir; + if ( $full_dir!=$basedir + and strpos($full_dir, $basedir)===0 + ) + { + array_push($dirs, $full_dir); + } + } + return $dirs; +} + +/** + * Returns a hash with all elements (images and files) inside the full $path + * according to listing.xml + * @param string $path recurse in this directory only + * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... ) + */ +function get_elements($path) +{ + $elements = array(); + foreach ( $this->site_dirs as $dir=>$files) + { + $full_dir = $this->site_url . $dir; + if ( strpos($full_dir, $path)===0 ) + { + foreach ( $files as $file) + { + $data = $this->get_element_attributes($file, + $this->insert_attributes); + $elements[$file] = $data; + } + } + } + + return $elements; +} + +// returns the name of the attributes that are supported for +// update/synchronization according to listing.xml +function get_update_attributes() +{ + return $this->update_attributes; +} + +// returns a hash of attributes (metadata+filesize+width,...) for file +function get_element_update_attributes($file) +{ + return $this->get_element_attributes($file, + $this->update_attributes); +} + +//-------------------------------------------------- private functions -------- +/** + * Returns a hash of image/file attributes + * @param string $file fully qualified file name + * @param array $attributes specifies which attributes to retrieve + * returned +*/ +function get_element_attributes($file, $attributes) +{ + $xml_element = $this->site_files[$file]; + if ( ! isset($xml_element) ) + { + return null; + } + $data = array(); + foreach($attributes as $att) + { + if (getAttribute($xml_element, $att) != '') + { + $val = getAttribute($xml_element, $att); + $data[$att] = addslashes($val); + } + } + return $data; +} + +// recursively parse the xml_content for later usage +function build_structure($xml_content, $basedir, $level) +{ + $temp_dirs = getChildren($xml_content, 'dir'.$level); + foreach ($temp_dirs as $temp_dir) + { + $dir_name = $basedir; + if ($dir_name != '' ) + { + $dir_name .= '/'; + } + $dir_name .= getAttribute($temp_dir, 'name'); + $this->site_dirs[ $dir_name ] = array(); + $this->build_structure($temp_dir, $dir_name, $level+1); + } + + if ($basedir != '') + { + $xml_elements = getChildren( getChild($xml_content, 'root'), 'element' ); + foreach ($xml_elements as $xml_element) + { + $path = getAttribute($xml_element, 'path'); + $this->site_files[$path] = $xml_element; + array_push( $this->site_dirs[$basedir], $path); + } + } +} + +} + ?>
\ No newline at end of file diff --git a/admin/site_update.php b/admin/site_update.php index 75e6ed9f7..04f395190 100644 --- a/admin/site_update.php +++ b/admin/site_update.php @@ -1,813 +1,828 @@ -<?php
-// +-----------------------------------------------------------------------+
-// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
-// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
-// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $RCSfile$
-// | last update : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $
-// | last modifier : $Author: plg $
-// | revision : $Revision: 967 $
-// +-----------------------------------------------------------------------+
-// | 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!');
-}
-include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
-
-if (! is_numeric($_GET['site']) )
-{
- die ('site param missing or invalid');
-}
-$site_id = $_GET['site'];
-$query='SELECT galleries_url FROM '.SITES_TABLE.'
-WHERE id='.$site_id.'
-;';
-list($site_url)=mysql_fetch_row(pwg_query($query));
-if (! isset($site_url) )
-{
- die ("site $site_id does not exist");
-}
-$site_is_remote = url_is_remote($site_url);
-
-list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
-define('CURRENT_DATE', $dbnow);
-
-$error_labels = array(
- 'PWG-UPDATE-1' => array( l10n('update_wrong_dirname_short'),
- l10n('update_wrong_dirname_info') ),
- 'PWG-UPDATE-2' => array( l10n('update_missing_tn_short'),
- l10n('update_missing_tn_info')
- . implode(',', $conf['picture_ext']) ),
- 'PWG-ERROR-NO-FS' => array( l10n('Does not exist'),
- l10n('update_missing_file_or_dir_info')),
- 'PWG-ERROR-VERSION' => array( l10n('Invalid PhpWebGalley version'),
- l10n('update_pwg_version_differs_info')),
- 'PWG-ERROR-NOLISTING' => array( l10n('remote_site_listing_not_found'),
- l10n('remote_site_listing_not_found_info'))
- );
-$errors = array();
-$infos = array();
-
-if ($site_is_remote)
-{
- include_once( PHPWG_ROOT_PATH.'admin/site_reader_remote.php');
- $site_reader = new RemoteSiteReader($site_url);
-}
-else
-{
- include_once( PHPWG_ROOT_PATH.'admin/site_reader_local.php');
- $site_reader = new LocalSiteReader($site_url);
-}
-
-$general_failure=true;
-if (isset($_POST['submit']))
-{
- if ($site_reader->open())
- {
- $general_failure = false;
- }
- // shall we simulate only
- if (isset($_POST['simulate']) and $_POST['simulate'] == 1)
- {
- $simulate = true;
- }
- else
- {
- $simulate = false;
- }
-}
-
-// +-----------------------------------------------------------------------+
-// | directories / categories |
-// +-----------------------------------------------------------------------+
-if (isset($_POST['submit'])
- and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
- and !$general_failure)
-{
- $counts['new_categories'] = 0;
- $counts['del_categories'] = 0;
- $counts['del_elements'] = 0;
- $counts['new_elements'] = 0;
-
- $start = get_moment();
- // which categories to update ?
- $cat_ids = array();
-
- $query = '
-SELECT id, uppercats, global_rank, status, visible
- FROM '.CATEGORIES_TABLE.'
- WHERE dir IS NOT NULL
- AND site_id = '.$site_id;
- if (isset($_POST['cat']) and is_numeric($_POST['cat']))
- {
- if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
- {
- $query.= '
- AND uppercats REGEXP \'(^|,)'.$_POST['cat'].'(,|$)\'
-';
- }
- else
- {
- $query.= '
- AND id = '.$_POST['cat'].'
-';
- }
- }
- $query.= '
-;';
- $result = pwg_query($query);
-
- $db_categories = array();
- while ($row = mysql_fetch_array($result))
- {
- $db_categories[$row['id']] = $row;
- }
-
- // get categort full directories in an array for comparison with file
- // system directory tree
- $db_fulldirs = get_fulldirs(array_keys($db_categories));
-
- // what is the base directory to search file system sub-directories ?
- if (isset($_POST['cat']) and is_numeric($_POST['cat']))
- {
- $basedir = $db_fulldirs[$_POST['cat']];
- }
- else
- {
- $basedir = preg_replace('#/*$#', '', $site_url);
- }
-
- // we need to have fulldirs as keys to make efficient comparison
- $db_fulldirs = array_flip($db_fulldirs);
-
- // finding next rank for each id_uppercat. By default, each category id
- // has 1 for next rank on its sub-categories to create
- $next_rank['NULL'] = 1;
-
- $query = '
-SELECT id
- FROM '.CATEGORIES_TABLE.'
-;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- $next_rank[$row['id']] = 1;
- }
-
- // let's see if some categories already have some sub-categories...
- $query = '
-SELECT id_uppercat, MAX(rank)+1 AS next_rank
- FROM '.CATEGORIES_TABLE.'
- GROUP BY id_uppercat
-;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- // for the id_uppercat NULL, we write 'NULL' and not the empty string
- if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
- {
- $row['id_uppercat'] = 'NULL';
- }
- $next_rank[$row['id_uppercat']] = $row['next_rank'];
- }
-
- // next category id available
- $query = '
-SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
- FROM '.CATEGORIES_TABLE.'
-;';
- list($next_id) = mysql_fetch_array(pwg_query($query));
-
- // retrieve sub-directories fulldirs from the site reader
- $fs_fulldirs = $site_reader->get_full_directories($basedir);
- //print_r( $fs_fulldirs ); echo "<br>";
-
- // get_full_directories doesn't include the base directory, so if it's a
- // category directory, we need to include it in our array
- if (isset($_POST['cat']))
- {
- array_push($fs_fulldirs, $basedir);
- }
-
- $inserts = array();
- // new categories are the directories not present yet in the database
- foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
- {
- $dir = basename($fulldir);
- if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir))
- {
- $insert = array();
-
- $insert{'id'} = $next_id++;
- $insert{'dir'} = $dir;
- $insert{'name'} = str_replace('_', ' ', $dir);
- $insert{'site_id'} = $site_id;
- $insert{'commentable'} = $conf['newcat_default_commentable'];
- if (! $site_is_remote)
- {
- $insert{'uploadable'} = $conf['newcat_default_uploadable'];
- }
- else
- {
- $insert{'uploadable'} = 'false';
- }
- $insert{'status'} = $conf{'newcat_default_status'};
- $insert{'visible'} = $conf{'newcat_default_visible'};
-
- if (isset($db_fulldirs[dirname($fulldir)]))
- {
- $parent = $db_fulldirs[dirname($fulldir)];
-
- $insert{'id_uppercat'} = $parent;
- $insert{'uppercats'} =
- $db_categories[$parent]['uppercats'].','.$insert{'id'};
- $insert{'rank'} = $next_rank[$parent]++;
- $insert{'global_rank'} =
- $db_categories[$parent]['global_rank'].'.'.$insert{'rank'};
- if ('private' == $db_categories[$parent]['status'])
- {
- $insert{'status'} = 'private';
- }
- if ('false' == $db_categories[$parent]['visible'])
- {
- $insert{'visible'} = 'false';
- }
- }
- else
- {
- $insert{'uppercats'} = $insert{'id'};
- $insert{'rank'} = $next_rank['NULL']++;
- $insert{'global_rank'} = $insert{'rank'};
- }
-
- array_push($inserts, $insert);
- array_push($infos, array('path' => $fulldir,
- 'info' => l10n('update_research_added')));
-
- // add the new category to $db_categories and $db_fulldirs array
- $db_categories[$insert{'id'}] =
- array(
- 'id' => $insert{'id'},
- 'status' => $insert{'status'},
- 'visible' => $insert{'visible'},
- 'uppercats' => $insert{'uppercats'},
- 'global_rank' => $insert{'global_rank'}
- );
- $db_fulldirs[$fulldir] = $insert{'id'};
- $next_rank[$insert{'id'}] = 1;
- }
- else
- {
- array_push($errors, array('path' => $fulldir, 'type' => 'PWG-UPDATE-1'));
- }
- }
-
- if (count($inserts) > 0)
- {
- if (!$simulate)
- {
- $dbfields = array(
- 'id','dir','name','site_id','id_uppercat','uppercats','commentable',
- 'uploadable','visible','status','rank','global_rank'
- );
- mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
- }
-
- $counts['new_categories'] = count($inserts);
- }
-
- // to delete categories
- $to_delete = array();
- foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir)
- {
- array_push($to_delete, $db_fulldirs[$fulldir]);
- unset($db_fulldirs[$fulldir]);
- array_push($infos, array('path' => $fulldir,
- 'info' => l10n('update_research_deleted')));
- }
- if (count($to_delete) > 0)
- {
- if (!$simulate)
- {
- delete_categories($to_delete);
- }
- $counts['del_categories'] = count($to_delete);
- }
-
- echo '<!-- scanning dirs : ';
- echo get_elapsed_time($start, get_moment());
- echo ' -->'."\n";
-}
-// +-----------------------------------------------------------------------+
-// | files / elements |
-// +-----------------------------------------------------------------------+
-if (isset($_POST['submit']) and $_POST['sync'] == 'files'
- and !$general_failure)
-{
- $start_files = get_moment();
- $start= $start_files;
-
- $fs = $site_reader->get_elements($basedir);
- //print_r($fs); echo "<br>";
- echo '<!-- get_elements: '.get_elapsed_time($start, get_moment())." -->\n";
-
- $cat_ids = array_diff(array_keys($db_categories), $to_delete);
-
- $db_elements = array();
- $db_unvalidated = array();
-
- if (count($cat_ids) > 0)
- {
- $query = '
-SELECT id, path
- FROM '.IMAGES_TABLE.'
- WHERE storage_category_id IN (
-'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
-;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- $db_elements[$row['id']] = $row['path'];
- }
-
- // searching the unvalidated waiting elements (they must not be taken into
- // account)
- $query = '
-SELECT file,storage_category_id
- FROM '.WAITING_TABLE.'
- WHERE storage_category_id IN (
-'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
- AND validated = \'false\'
-;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- array_push(
- $db_unvalidated,
- array_search($row['storage_category_id'],
- $db_fulldirs).'/'.$row['file']
- );
- }
- }
-
- // next element id available
- $query = '
-SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
- FROM '.IMAGES_TABLE.'
-;';
- list($next_element_id) = mysql_fetch_array(pwg_query($query));
-
- $start = get_moment();
-
- $inserts = array();
- $insert_links = array();
-
- foreach (array_diff(array_keys($fs), $db_elements, $db_unvalidated) as $path)
- {
- $insert = array();
- // storage category must exist
- $dirname = dirname($path);
- if (!isset($db_fulldirs[$dirname]))
- {
- continue;
- }
- $filename = basename($path);
- if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
- {
- array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-1'));
- continue;
- }
-
- // 2 cases : the element is a picture or not. Indeed, for a picture
- // thumbnail is mandatory and for non picture element, thumbnail and
- // representative are optionnal
- if (in_array(get_extension($filename), $conf['picture_ext']))
- {
- // if we found a thumnbnail corresponding to our picture...
- if ( isset($fs[$path]['tn_ext']) )
- {
- $insert{'id'} = $next_element_id++;
- $insert{'file'} = $filename;
- $insert{'storage_category_id'} = $db_fulldirs[$dirname];
- $insert{'date_available'} = CURRENT_DATE;
- $insert{'tn_ext'} = $fs[$path]['tn_ext'];
- $insert{'has_high'} = $fs[$path]['has_high'];
- $insert{'path'} = $path;
-
- array_push($inserts, $insert);
- array_push($insert_links,
- array('image_id' => $insert{'id'},
- 'category_id' => $insert{'storage_category_id'}));
- array_push($infos, array('path' => $insert{'path'},
- 'info' => l10n('update_research_added')));
- }
- else
- {
- array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-2'));
- }
- }
- else
- {
- $insert{'id'} = $next_element_id++;
- $insert{'file'} = $filename;
- $insert{'storage_category_id'} = $db_fulldirs[$dirname];
- $insert{'date_available'} = CURRENT_DATE;
- $insert{'has_high'} = $fs[$path]['has_high'];
- $insert{'path'} = $path;
-
- if ( isset($fs[$path]['tn_ext']) )
- {
- $insert{'tn_ext'} = $fs[$path]['tn_ext'];
- }
- if (isset($fs[$path]['representative_ext']))
- {
- $insert{'representative_ext'} = $fs[$path]['representative_ext'];
- }
-
- array_push($inserts, $insert);
- array_push($insert_links,
- array('image_id' => $insert{'id'},
- 'category_id' => $insert{'storage_category_id'}));
- array_push($infos, array('path' => $insert{'path'},
- 'info' => l10n('update_research_added')));
- }
- }
-
- if (count($inserts) > 0)
- {
- if (!$simulate)
- {
- // inserts all new elements
- $dbfields = array(
- 'id','file','storage_category_id','date_available','tn_ext'
- ,'representative_ext', 'has_high', 'path'
- );
- mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
-
- // insert all links between new elements and their storage category
- $dbfields = array('image_id','category_id');
- mass_inserts(IMAGE_CATEGORY_TABLE, $dbfields, $insert_links);
- }
- $counts['new_elements'] = count($inserts);
- }
-
- // delete elements that are in database but not in the filesystem
- $to_delete_elements = array();
- foreach (array_diff($db_elements, array_keys($fs)) as $path)
- {
- array_push($to_delete_elements, array_search($path, $db_elements));
- array_push($infos, array('path' => $path,
- 'info' => l10n('update_research_deleted')));
- }
- if (count($to_delete_elements) > 0)
- {
- if (!$simulate)
- {
- delete_elements($to_delete_elements);
- }
- $counts['del_elements'] = count($to_delete_elements);
- }
-
- echo '<!-- scanning files : ';
- echo get_elapsed_time($start_files, get_moment());
- echo ' -->'."\n";
-
- // retrieving informations given by uploaders
- if (!$simulate and count($cat_ids) > 0)
- {
- $query = '
-SELECT id,file,storage_category_id,infos
- FROM '.WAITING_TABLE.'
- WHERE storage_category_id IN (
-'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
- AND validated = \'true\'
-;';
- $result = pwg_query($query);
-
- $datas = array();
- $fields =
- array(
- 'primary' => array('id'),
- 'update' => array('date_creation', 'author', 'name', 'comment')
- );
-
- $waiting_to_delete = array();
-
- while ($row = mysql_fetch_array($result))
- {
- $data = array();
-
- $query = '
-SELECT id
- FROM '.IMAGES_TABLE.'
- WHERE storage_category_id = \''.$row['storage_category_id'].'\'
- AND file = \''.$row['file'].'\'
-;';
- list($data['id']) = mysql_fetch_array(pwg_query($query));
-
- foreach ($fields['update'] as $field)
- {
- $data[$field] = getAttribute($row['infos'], $field);
- }
-
- array_push($datas, $data);
- array_push($waiting_to_delete, $row['id']);
- }
-
- if (count($datas) > 0)
- {
- mass_updates(IMAGES_TABLE, $fields, $datas);
-
- // delete now useless waiting elements
- $query = '
-DELETE
- FROM '.WAITING_TABLE.'
- WHERE id IN ('.implode(',', $waiting_to_delete).')
-;';
- pwg_query($query);
- }
- }
-}
-
-// +-----------------------------------------------------------------------+
-// | synchronize files |
-// +-----------------------------------------------------------------------+
-if (isset($_POST['submit'])
- and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
-{
- $template->assign_block_vars(
- 'update_result',
- array(
- 'NB_NEW_CATEGORIES'=>$counts['new_categories'],
- 'NB_DEL_CATEGORIES'=>$counts['del_categories'],
- 'NB_NEW_ELEMENTS'=>$counts['new_elements'],
- 'NB_DEL_ELEMENTS'=>$counts['del_elements'],
- 'NB_ERRORS'=>count($errors),
- ));
-
- if (!$simulate)
- {
- $start = get_moment();
- update_category('all');
- echo '<!-- update_category(all) : ';
- echo get_elapsed_time($start,get_moment());
- echo ' -->'."\n";
- $start = get_moment();
- ordering();
- update_global_rank();
- echo '<!-- ordering categories : ';
- echo get_elapsed_time($start, get_moment());
- echo ' -->'."\n";
- }
-}
-
-// +-----------------------------------------------------------------------+
-// | synchronize metadata |
-// +-----------------------------------------------------------------------+
-if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
- and !$general_failure)
-{
- // sync only never synchronized files ?
- if ($_POST['sync'] == 'metadata_new')
- {
- $opts['only_new'] = true;
- }
- else
- {
- $opts['only_new'] = false;
- }
- $opts['category_id'] = '';
- $opts['recursive'] = true;
-
- if (isset($_POST['cat']))
- {
- $opts['category_id'] = $_POST['cat'];
- // recursive ?
- if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
- {
- $opts['recursive'] = false;
- }
- }
- $start = get_moment();
- $files = get_filelist($opts['category_id'], $site_id,
- $opts['recursive'],
- $opts['only_new']);
-
- echo '<!-- get_filelist : ';
- echo get_elapsed_time($start, get_moment());
- echo ' -->'."\n";
-
- $start = get_moment();
- $datas = array();
- foreach ( $files as $id=>$file )
- {
- $data = $site_reader->get_element_update_attributes($file);
- if ( is_array($data) )
- {
- $data['date_metadata_update'] = CURRENT_DATE;
- $data['id']=$id;
- array_push($datas, $data);
- }
- else
- {
- array_push($errors, array('path' => $file, 'type' => 'PWG-ERROR-NO-FS'));
- }
- }
- $update_fields = $site_reader->get_update_attributes();
- $update_fields = array_merge($update_fields, 'date_metadata_update');
- $fields =
- array(
- 'primary' => array('id'),
- 'update' => array_unique($update_fields)
- );
- //print_r($datas);
- if (!$simulate and count($datas)>0 )
- {
- mass_updates(IMAGES_TABLE, $fields, $datas);
- }
-
- echo '<!-- metadata update : ';
- echo get_elapsed_time($start, get_moment());
- echo ' -->'."\n";
-
- $template->assign_block_vars(
- 'metadata_result',
- array(
- 'NB_ELEMENTS_DONE' => count($datas),
- 'NB_ELEMENTS_CANDIDATES' => count($files),
- 'NB_ERRORS' => count($errors),
- ));
-}
-
-// +-----------------------------------------------------------------------+
-// | template initialization |
-// +-----------------------------------------------------------------------+
-$template->set_filenames(array('update'=>'admin/site_update.tpl'));
-$result_title = '';
-if (isset($simulate) and $simulate)
-{
- $result_title.= l10n('update_simulation_title').' ';
-}
-
-// used_metadata string is displayed to inform admin which metadata will be
-// used from files for synchronization
-$used_metadata = implode( ', ', $site_reader->get_update_attributes());
-if ($site_is_remote and !isset($_POST['submit']) )
-{
- $used_metadata.= ' + ' . l10n('Aditionnal remote attributes');
-}
-
-$template->assign_vars(
- array(
- 'SITE_URL'=>$site_url,
- 'U_SITE_MANAGER'=> PHPWG_ROOT_PATH.'admin.php?page=site_manager',
- 'L_RESULT_UPDATE'=>$result_title.l10n('update_part_research'),
- 'L_RESULT_METADATA'=>$result_title.l10n('update_result_metadata'),
- 'METADATA_LIST' => $used_metadata
- ));
-
-$template->assign_vars(
- array(
- 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=synchronize'
- )
- );
-// +-----------------------------------------------------------------------+
-// | introduction : choices |
-// +-----------------------------------------------------------------------+
-if (!isset($_POST['submit']) or (isset($simulate) and $simulate))
-{
- $template->assign_block_vars('introduction', array());
-
- if (isset($simulate) and $simulate)
- {
- switch ($_POST['sync'])
- {
- case 'dirs' :
- {
- $template->assign_vars(
- array('SYNC_DIRS_CHECKED'=>'checked="checked"'));
- break;
- }
- case 'files' :
- {
- $template->assign_vars(
- array('SYNC_ALL_CHECKED'=>'checked="checked"'));
- break;
- }
- case 'metadata_new' :
- {
- $template->assign_vars(
- array('SYNC_META_NEW_CHECKED'=>'checked="checked"'));
- break;
- }
- case 'metadata_all' :
- {
- $template->assign_vars(
- array('SYNC_META_ALL_CHECKED'=>'checked="checked"'));
- break;
- }
- }
-
- if (isset($_POST['display_info']) and $_POST['display_info'] == 1)
- {
- $template->assign_vars(
- array('DISPLAY_INFO_CHECKED'=>'checked="checked"'));
- }
-
- if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
- {
- $template->assign_vars(
- array('SUBCATS_INCLUDED_CHECKED'=>'checked="checked"'));
- }
-
- if (isset($_POST['cat']) and is_numeric($_POST['cat']))
- {
- $cat_selected = array($_POST['cat']);
- }
- else
- {
- $cat_selected = array();
- }
- }
- else
- {
- $template->assign_vars(
- array('SYNC_DIRS_CHECKED' => 'checked="checked"',
- 'SUBCATS_INCLUDED_CHECKED'=>'checked="checked"'));
-
- $cat_selected = array();
- }
-
- $query = '
-SELECT id,name,uppercats,global_rank
- FROM '.CATEGORIES_TABLE.'
- WHERE site_id = '.$site_id.'
-;';
- display_select_cat_wrapper($query,
- $cat_selected,
- 'introduction.category_option',
- false);
-}
-
-if (count($errors) > 0)
-{
- $template->assign_block_vars('sync_errors', array());
- foreach ($errors as $error)
- {
- $template->assign_block_vars(
- 'sync_errors.error',
- array(
- 'ELEMENT' => $error['path'],
- 'LABEL' => $error['type'].' ('.$error_labels[$error['type']][0].')'
- ));
- }
-
- foreach ($error_labels as $error_type=>$error_description)
- {
- $template->assign_block_vars(
- 'sync_errors.error_caption',
- array(
- 'TYPE' => $error_type,
- 'LABEL' => $error_description[1]
- ));
- }
-
-}
-if (count($infos) > 0
- and isset($_POST['display_info'])
- and $_POST['display_info'] == 1)
-{
- $template->assign_block_vars('sync_infos', array());
- foreach ($infos as $info)
- {
- $template->assign_block_vars(
- 'sync_infos.info',
- array(
- 'ELEMENT' => $info['path'],
- 'LABEL' => $info['info']
- ));
- }
-}
-
-// +-----------------------------------------------------------------------+
-// | sending html code |
-// +-----------------------------------------------------------------------+
-$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
+<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $ +// | last modifier : $Author: plg $ +// | revision : $Revision: 967 $ +// +-----------------------------------------------------------------------+ +// | 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!'); +} +include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); + +if (! is_numeric($_GET['site']) ) +{ + die ('site param missing or invalid'); +} +$site_id = $_GET['site']; +$query='SELECT galleries_url FROM '.SITES_TABLE.' +WHERE id='.$site_id.' +;'; +list($site_url)=mysql_fetch_row(pwg_query($query)); +if (! isset($site_url) ) +{ + die ("site $site_id does not exist"); +} +$site_is_remote = url_is_remote($site_url); + +list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); +define('CURRENT_DATE', $dbnow); + +$error_labels = array( + 'PWG-UPDATE-1' => array( l10n('update_wrong_dirname_short'), + l10n('update_wrong_dirname_info') ), + 'PWG-UPDATE-2' => array( l10n('update_missing_tn_short'), + l10n('update_missing_tn_info') + . implode(',', $conf['picture_ext']) ), + 'PWG-ERROR-NO-FS' => array( l10n('update_missing_file_or_dir'), + l10n('update_missing_file_or_dir_info')), + 'PWG-ERROR-VERSION' => array( l10n('update_err_pwg_version_differs'), + l10n('update_err_pwg_version_differs_info')), + 'PWG-ERROR-NOLISTING' => array( l10n('update_err_remote_listing_not_found'), + l10n('update_err_remote_listing_not_found_info')) + ); +$errors = array(); +$infos = array(); + +if ($site_is_remote) +{ + include_once( PHPWG_ROOT_PATH.'admin/site_reader_remote.php'); + $site_reader = new RemoteSiteReader($site_url); +} +else +{ + include_once( PHPWG_ROOT_PATH.'admin/site_reader_local.php'); + $site_reader = new LocalSiteReader($site_url); +} + +$general_failure=true; +if (isset($_POST['submit'])) +{ + if ($site_reader->open()) + { + $general_failure = false; + } + // shall we simulate only + if (isset($_POST['simulate']) and $_POST['simulate'] == 1) + { + $simulate = true; + } + else + { + $simulate = false; + } +} + +// +-----------------------------------------------------------------------+ +// | directories / categories | +// +-----------------------------------------------------------------------+ +if (isset($_POST['submit']) + and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files') + and !$general_failure) +{ + $counts['new_categories'] = 0; + $counts['del_categories'] = 0; + $counts['del_elements'] = 0; + $counts['new_elements'] = 0; + + $start = get_moment(); + // which categories to update ? + $cat_ids = array(); + + $query = ' +SELECT id, uppercats, global_rank, status, visible + FROM '.CATEGORIES_TABLE.' + WHERE dir IS NOT NULL + AND site_id = '.$site_id; + if (isset($_POST['cat']) and is_numeric($_POST['cat'])) + { + if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1) + { + $query.= ' + AND uppercats REGEXP \'(^|,)'.$_POST['cat'].'(,|$)\' +'; + } + else + { + $query.= ' + AND id = '.$_POST['cat'].' +'; + } + } + $query.= ' +;'; + $result = pwg_query($query); + + $db_categories = array(); + while ($row = mysql_fetch_array($result)) + { + $db_categories[$row['id']] = $row; + } + + // get categort full directories in an array for comparison with file + // system directory tree + $db_fulldirs = get_fulldirs(array_keys($db_categories)); + + // what is the base directory to search file system sub-directories ? + if (isset($_POST['cat']) and is_numeric($_POST['cat'])) + { + $basedir = $db_fulldirs[$_POST['cat']]; + } + else + { + $basedir = preg_replace('#/*$#', '', $site_url); + } + + // we need to have fulldirs as keys to make efficient comparison + $db_fulldirs = array_flip($db_fulldirs); + + // finding next rank for each id_uppercat. By default, each category id + // has 1 for next rank on its sub-categories to create + $next_rank['NULL'] = 1; + + $query = ' +SELECT id + FROM '.CATEGORIES_TABLE.' +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $next_rank[$row['id']] = 1; + } + + // let's see if some categories already have some sub-categories... + $query = ' +SELECT id_uppercat, MAX(rank)+1 AS next_rank + FROM '.CATEGORIES_TABLE.' + GROUP BY id_uppercat +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + // for the id_uppercat NULL, we write 'NULL' and not the empty string + if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '') + { + $row['id_uppercat'] = 'NULL'; + } + $next_rank[$row['id_uppercat']] = $row['next_rank']; + } + + // next category id available + $query = ' +SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id + FROM '.CATEGORIES_TABLE.' +;'; + list($next_id) = mysql_fetch_array(pwg_query($query)); + + // retrieve sub-directories fulldirs from the site reader + $fs_fulldirs = $site_reader->get_full_directories($basedir); + //print_r( $fs_fulldirs ); echo "<br>"; + + // get_full_directories doesn't include the base directory, so if it's a + // category directory, we need to include it in our array + if (isset($_POST['cat'])) + { + array_push($fs_fulldirs, $basedir); + } + + $inserts = array(); + // new categories are the directories not present yet in the database + foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir) + { + $dir = basename($fulldir); + if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir)) + { + $insert = array(); + + $insert{'id'} = $next_id++; + $insert{'dir'} = $dir; + $insert{'name'} = str_replace('_', ' ', $dir); + $insert{'site_id'} = $site_id; + $insert{'commentable'} = $conf['newcat_default_commentable']; + if (! $site_is_remote) + { + $insert{'uploadable'} = $conf['newcat_default_uploadable']; + } + else + { + $insert{'uploadable'} = 'false'; + } + $insert{'status'} = $conf{'newcat_default_status'}; + $insert{'visible'} = $conf{'newcat_default_visible'}; + + if (isset($db_fulldirs[dirname($fulldir)])) + { + $parent = $db_fulldirs[dirname($fulldir)]; + + $insert{'id_uppercat'} = $parent; + $insert{'uppercats'} = + $db_categories[$parent]['uppercats'].','.$insert{'id'}; + $insert{'rank'} = $next_rank[$parent]++; + $insert{'global_rank'} = + $db_categories[$parent]['global_rank'].'.'.$insert{'rank'}; + if ('private' == $db_categories[$parent]['status']) + { + $insert{'status'} = 'private'; + } + if ('false' == $db_categories[$parent]['visible']) + { + $insert{'visible'} = 'false'; + } + } + else + { + $insert{'uppercats'} = $insert{'id'}; + $insert{'rank'} = $next_rank['NULL']++; + $insert{'global_rank'} = $insert{'rank'}; + } + + array_push($inserts, $insert); + array_push($infos, array('path' => $fulldir, + 'info' => l10n('update_research_added'))); + + // add the new category to $db_categories and $db_fulldirs array + $db_categories[$insert{'id'}] = + array( + 'id' => $insert{'id'}, + 'status' => $insert{'status'}, + 'visible' => $insert{'visible'}, + 'uppercats' => $insert{'uppercats'}, + 'global_rank' => $insert{'global_rank'} + ); + $db_fulldirs[$fulldir] = $insert{'id'}; + $next_rank[$insert{'id'}] = 1; + } + else + { + array_push($errors, array('path' => $fulldir, 'type' => 'PWG-UPDATE-1')); + } + } + + if (count($inserts) > 0) + { + if (!$simulate) + { + $dbfields = array( + 'id','dir','name','site_id','id_uppercat','uppercats','commentable', + 'uploadable','visible','status','rank','global_rank' + ); + mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); + } + + $counts['new_categories'] = count($inserts); + } + + // to delete categories + $to_delete = array(); + foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir) + { + array_push($to_delete, $db_fulldirs[$fulldir]); + unset($db_fulldirs[$fulldir]); + array_push($infos, array('path' => $fulldir, + 'info' => l10n('update_research_deleted'))); + } + if (count($to_delete) > 0) + { + if (!$simulate) + { + delete_categories($to_delete); + } + $counts['del_categories'] = count($to_delete); + } + + echo '<!-- scanning dirs : '; + echo get_elapsed_time($start, get_moment()); + echo ' -->'."\n"; +} +// +-----------------------------------------------------------------------+ +// | files / elements | +// +-----------------------------------------------------------------------+ +if (isset($_POST['submit']) and $_POST['sync'] == 'files' + and !$general_failure) +{ + $start_files = get_moment(); + $start= $start_files; + + $fs = $site_reader->get_elements($basedir); + //print_r($fs); echo "<br>"; + echo '<!-- get_elements: '.get_elapsed_time($start, get_moment())." -->\n"; + + $cat_ids = array_diff(array_keys($db_categories), $to_delete); + + $db_elements = array(); + $db_unvalidated = array(); + + if (count($cat_ids) > 0) + { + $query = ' +SELECT id, path + FROM '.IMAGES_TABLE.' + WHERE storage_category_id IN ( +'.wordwrap(implode(', ', $cat_ids), 80, "\n").') +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $db_elements[$row['id']] = $row['path']; + } + + // searching the unvalidated waiting elements (they must not be taken into + // account) + $query = ' +SELECT file,storage_category_id + FROM '.WAITING_TABLE.' + WHERE storage_category_id IN ( +'.wordwrap(implode(', ', $cat_ids), 80, "\n").') + AND validated = \'false\' +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + array_push( + $db_unvalidated, + array_search($row['storage_category_id'], + $db_fulldirs).'/'.$row['file'] + ); + } + } + + // next element id available + $query = ' +SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id + FROM '.IMAGES_TABLE.' +;'; + list($next_element_id) = mysql_fetch_array(pwg_query($query)); + + $start = get_moment(); + + $inserts = array(); + $insert_links = array(); + + foreach (array_diff(array_keys($fs), $db_elements, $db_unvalidated) as $path) + { + $insert = array(); + // storage category must exist + $dirname = dirname($path); + if (!isset($db_fulldirs[$dirname])) + { + continue; + } + $filename = basename($path); + if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) + { + array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-1')); + continue; + } + + // 2 cases : the element is a picture or not. Indeed, for a picture + // thumbnail is mandatory and for non picture element, thumbnail and + // representative are optionnal + if (in_array(get_extension($filename), $conf['picture_ext'])) + { + // if we found a thumnbnail corresponding to our picture... + if ( isset($fs[$path]['tn_ext']) ) + { + $insert{'id'} = $next_element_id++; + $insert{'file'} = $filename; + $insert{'storage_category_id'} = $db_fulldirs[$dirname]; + $insert{'date_available'} = CURRENT_DATE; + $insert{'tn_ext'} = $fs[$path]['tn_ext']; + if ( isset($fs[$path]['has_high']) ) + { + $insert{'has_high'} = $fs[$path]['has_high']; + } + else + { + $insert{'has_high'} = null; + } + $insert{'path'} = $path; + + array_push($inserts, $insert); + array_push($insert_links, + array('image_id' => $insert{'id'}, + 'category_id' => $insert{'storage_category_id'})); + array_push($infos, array('path' => $insert{'path'}, + 'info' => l10n('update_research_added'))); + } + else + { + array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-2')); + } + } + else + { + $insert{'id'} = $next_element_id++; + $insert{'file'} = $filename; + $insert{'storage_category_id'} = $db_fulldirs[$dirname]; + $insert{'date_available'} = CURRENT_DATE; + $insert{'has_high'} = $fs[$path]['has_high']; + if ( isset($fs[$path]['has_high']) ) + { + $insert{'has_high'} = $fs[$path]['has_high']; + } + else + { + $insert{'has_high'} = null; + } + $insert{'path'} = $path; + + if ( isset($fs[$path]['tn_ext']) ) + { + $insert{'tn_ext'} = $fs[$path]['tn_ext']; + } + if (isset($fs[$path]['representative_ext'])) + { + $insert{'representative_ext'} = $fs[$path]['representative_ext']; + } + + array_push($inserts, $insert); + array_push($insert_links, + array('image_id' => $insert{'id'}, + 'category_id' => $insert{'storage_category_id'})); + array_push($infos, array('path' => $insert{'path'}, + 'info' => l10n('update_research_added'))); + } + } + + if (count($inserts) > 0) + { + if (!$simulate) + { + // inserts all new elements + $dbfields = array( + 'id','file','storage_category_id','date_available','tn_ext' + ,'representative_ext', 'has_high', 'path' + ); + mass_inserts(IMAGES_TABLE, $dbfields, $inserts); + + // insert all links between new elements and their storage category + $dbfields = array('image_id','category_id'); + mass_inserts(IMAGE_CATEGORY_TABLE, $dbfields, $insert_links); + } + $counts['new_elements'] = count($inserts); + } + + // delete elements that are in database but not in the filesystem + $to_delete_elements = array(); + foreach (array_diff($db_elements, array_keys($fs)) as $path) + { + array_push($to_delete_elements, array_search($path, $db_elements)); + array_push($infos, array('path' => $path, + 'info' => l10n('update_research_deleted'))); + } + if (count($to_delete_elements) > 0) + { + if (!$simulate) + { + delete_elements($to_delete_elements); + } + $counts['del_elements'] = count($to_delete_elements); + } + + echo '<!-- scanning files : '; + echo get_elapsed_time($start_files, get_moment()); + echo ' -->'."\n"; + + // retrieving informations given by uploaders + if (!$simulate and count($cat_ids) > 0) + { + $query = ' +SELECT id,file,storage_category_id,infos + FROM '.WAITING_TABLE.' + WHERE storage_category_id IN ( +'.wordwrap(implode(', ', $cat_ids), 80, "\n").') + AND validated = \'true\' +;'; + $result = pwg_query($query); + + $datas = array(); + $fields = + array( + 'primary' => array('id'), + 'update' => array('date_creation', 'author', 'name', 'comment') + ); + + $waiting_to_delete = array(); + + while ($row = mysql_fetch_array($result)) + { + $data = array(); + + $query = ' +SELECT id + FROM '.IMAGES_TABLE.' + WHERE storage_category_id = \''.$row['storage_category_id'].'\' + AND file = \''.$row['file'].'\' +;'; + list($data['id']) = mysql_fetch_array(pwg_query($query)); + + foreach ($fields['update'] as $field) + { + $data[$field] = addslashes( getAttribute($row['infos'], $field) ); + } + + array_push($datas, $data); + array_push($waiting_to_delete, $row['id']); + } + + if (count($datas) > 0) + { + mass_updates(IMAGES_TABLE, $fields, $datas); + + // delete now useless waiting elements + $query = ' +DELETE + FROM '.WAITING_TABLE.' + WHERE id IN ('.implode(',', $waiting_to_delete).') +;'; + pwg_query($query); + } + } +} + +// +-----------------------------------------------------------------------+ +// | synchronize files | +// +-----------------------------------------------------------------------+ +if (isset($_POST['submit']) + and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')) +{ + $template->assign_block_vars( + 'update_result', + array( + 'NB_NEW_CATEGORIES'=>$counts['new_categories'], + 'NB_DEL_CATEGORIES'=>$counts['del_categories'], + 'NB_NEW_ELEMENTS'=>$counts['new_elements'], + 'NB_DEL_ELEMENTS'=>$counts['del_elements'], + 'NB_ERRORS'=>count($errors), + )); + + if (!$simulate) + { + $start = get_moment(); + update_category('all'); + echo '<!-- update_category(all) : '; + echo get_elapsed_time($start,get_moment()); + echo ' -->'."\n"; + $start = get_moment(); + ordering(); + update_global_rank(); + echo '<!-- ordering categories : '; + echo get_elapsed_time($start, get_moment()); + echo ' -->'."\n"; + } +} + +// +-----------------------------------------------------------------------+ +// | synchronize metadata | +// +-----------------------------------------------------------------------+ +if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync']) + and !$general_failure) +{ + // sync only never synchronized files ? + if ($_POST['sync'] == 'metadata_new') + { + $opts['only_new'] = true; + } + else + { + $opts['only_new'] = false; + } + $opts['category_id'] = ''; + $opts['recursive'] = true; + + if (isset($_POST['cat'])) + { + $opts['category_id'] = $_POST['cat']; + // recursive ? + if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1) + { + $opts['recursive'] = false; + } + } + $start = get_moment(); + $files = get_filelist($opts['category_id'], $site_id, + $opts['recursive'], + $opts['only_new']); + + echo '<!-- get_filelist : '; + echo get_elapsed_time($start, get_moment()); + echo ' -->'."\n"; + + $start = get_moment(); + $datas = array(); + foreach ( $files as $id=>$file ) + { + $data = $site_reader->get_element_update_attributes($file); + if ( is_array($data) ) + { + $data['date_metadata_update'] = CURRENT_DATE; + $data['id']=$id; + array_push($datas, $data); + } + else + { + array_push($errors, array('path' => $file, 'type' => 'PWG-ERROR-NO-FS')); + } + } + $update_fields = $site_reader->get_update_attributes(); + $update_fields = array_merge($update_fields, 'date_metadata_update'); + $fields = + array( + 'primary' => array('id'), + 'update' => array_unique($update_fields) + ); + //print_r($datas); + if (!$simulate and count($datas)>0 ) + { + mass_updates(IMAGES_TABLE, $fields, $datas); + } + + echo '<!-- metadata update : '; + echo get_elapsed_time($start, get_moment()); + echo ' -->'."\n"; + + $template->assign_block_vars( + 'metadata_result', + array( + 'NB_ELEMENTS_DONE' => count($datas), + 'NB_ELEMENTS_CANDIDATES' => count($files), + 'NB_ERRORS' => count($errors), + )); +} + +// +-----------------------------------------------------------------------+ +// | template initialization | +// +-----------------------------------------------------------------------+ +$template->set_filenames(array('update'=>'admin/site_update.tpl')); +$result_title = ''; +if (isset($simulate) and $simulate) +{ + $result_title.= l10n('update_simulation_title').' '; +} + +// used_metadata string is displayed to inform admin which metadata will be +// used from files for synchronization +$used_metadata = implode( ', ', $site_reader->get_update_attributes()); +if ($site_is_remote and !isset($_POST['submit']) ) +{ + $used_metadata.= ' + ...'; +} + +$template->assign_vars( + array( + 'SITE_URL'=>$site_url, + 'U_SITE_MANAGER'=> PHPWG_ROOT_PATH.'admin.php?page=site_manager', + 'L_RESULT_UPDATE'=>$result_title.l10n('update_part_research'), + 'L_RESULT_METADATA'=>$result_title.l10n('update_result_metadata'), + 'METADATA_LIST' => $used_metadata + )); + +$template->assign_vars( + array( + 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=synchronize' + ) + ); +// +-----------------------------------------------------------------------+ +// | introduction : choices | +// +-----------------------------------------------------------------------+ +if (!isset($_POST['submit']) or (isset($simulate) and $simulate)) +{ + $template->assign_block_vars('introduction', array()); + + if (isset($simulate) and $simulate) + { + switch ($_POST['sync']) + { + case 'dirs' : + { + $template->assign_vars( + array('SYNC_DIRS_CHECKED'=>'checked="checked"')); + break; + } + case 'files' : + { + $template->assign_vars( + array('SYNC_ALL_CHECKED'=>'checked="checked"')); + break; + } + case 'metadata_new' : + { + $template->assign_vars( + array('SYNC_META_NEW_CHECKED'=>'checked="checked"')); + break; + } + case 'metadata_all' : + { + $template->assign_vars( + array('SYNC_META_ALL_CHECKED'=>'checked="checked"')); + break; + } + } + + if (isset($_POST['display_info']) and $_POST['display_info'] == 1) + { + $template->assign_vars( + array('DISPLAY_INFO_CHECKED'=>'checked="checked"')); + } + + if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1) + { + $template->assign_vars( + array('SUBCATS_INCLUDED_CHECKED'=>'checked="checked"')); + } + + if (isset($_POST['cat']) and is_numeric($_POST['cat'])) + { + $cat_selected = array($_POST['cat']); + } + else + { + $cat_selected = array(); + } + } + else + { + $template->assign_vars( + array('SYNC_DIRS_CHECKED' => 'checked="checked"', + 'SUBCATS_INCLUDED_CHECKED'=>'checked="checked"')); + + $cat_selected = array(); + } + + $query = ' +SELECT id,name,uppercats,global_rank + FROM '.CATEGORIES_TABLE.' + WHERE site_id = '.$site_id.' +;'; + display_select_cat_wrapper($query, + $cat_selected, + 'introduction.category_option', + false); +} + +if (count($errors) > 0) +{ + $template->assign_block_vars('sync_errors', array()); + foreach ($errors as $error) + { + $template->assign_block_vars( + 'sync_errors.error', + array( + 'ELEMENT' => $error['path'], + 'LABEL' => $error['type'].' ('.$error_labels[$error['type']][0].')' + )); + } + + foreach ($error_labels as $error_type=>$error_description) + { + $template->assign_block_vars( + 'sync_errors.error_caption', + array( + 'TYPE' => $error_type, + 'LABEL' => $error_description[1] + )); + } + +} +if (count($infos) > 0 + and isset($_POST['display_info']) + and $_POST['display_info'] == 1) +{ + $template->assign_block_vars('sync_infos', array()); + foreach ($infos as $info) + { + $template->assign_block_vars( + 'sync_infos.info', + array( + 'ELEMENT' => $info['path'], + 'LABEL' => $info['info'] + )); + } +} + +// +-----------------------------------------------------------------------+ +// | sending html code | +// +-----------------------------------------------------------------------+ +$template->assign_var_from_handle('ADMIN_CONTENT', 'update'); ?>
\ No newline at end of file diff --git a/admin/update.php b/admin/update.php deleted file mode 100644 index f19bc8a9e..000000000 --- a/admin/update.php +++ /dev/null @@ -1,770 +0,0 @@ -<?php -// +-----------------------------------------------------------------------+ -// | PhpWebGallery - a PHP based picture gallery | -// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - 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. | -// +-----------------------------------------------------------------------+ - -if (!defined('PHPWG_ROOT_PATH')) -{ - die ('Hacking attempt!'); -} -include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); - -list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); -define('CURRENT_DATE', $dbnow); - -$error_labels = array('PWG-UPDATE-1' => $lang['update_wrong_dirname_short'], - 'PWG-UPDATE-2' => $lang['update_missing_tn_short']); -$errors = array(); -$infos = array(); -// +-----------------------------------------------------------------------+ -// | directories / categories | -// +-----------------------------------------------------------------------+ -if (isset($_POST['submit']) - and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')) -{ - $counts['new_categories'] = 0; - $counts['del_categories'] = 0; - $counts['del_elements'] = 0; - $counts['new_elements'] = 0; - - // shall we simulate only - if (isset($_POST['simulate']) and $_POST['simulate'] == 1) - { - $simulate = true; - } - else - { - $simulate = false; - } - - $start = get_moment(); - // which categories to update ? - $cat_ids = array(); - - $query = ' -SELECT id, uppercats, global_rank, status, visible - FROM '.CATEGORIES_TABLE.' - WHERE dir IS NOT NULL - AND site_id = 1'; - if (isset($_POST['cat']) and is_numeric($_POST['cat'])) - { - if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1) - { - $query.= ' - AND uppercats REGEXP \'(^|,)'.$_POST['cat'].'(,|$)\' -'; - } - else - { - $query.= ' - AND id = '.$_POST['cat'].' -'; - } - } - $query.= ' -;'; - $result = pwg_query($query); - - $db_categories = array(); - while ($row = mysql_fetch_array($result)) - { - $db_categories[$row['id']] = $row; - } - - // get categort full directories in an array for comparison with file - // system directory tree - $db_fulldirs = get_fulldirs(array_keys($db_categories)); - - // what is the base directory to search file system sub-directories ? - if (isset($_POST['cat']) and is_numeric($_POST['cat'])) - { - $basedir = $db_fulldirs[$_POST['cat']]; - } - else - { - $query = ' -SELECT galleries_url - FROM '.SITES_TABLE.' - WHERE id = 1 -;'; - list($galleries_url) = mysql_fetch_array(pwg_query($query)); - $basedir = preg_replace('#/*$#', '', $galleries_url); - } - - // we need to have fulldirs as keys to make efficient comparison - $db_fulldirs = array_flip($db_fulldirs); - - // finding next rank for each id_uppercat. By default, each category id - // has 1 for next rank on its sub-categories to create - $next_rank['NULL'] = 1; - - $query = ' -SELECT id - FROM '.CATEGORIES_TABLE.' -;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - $next_rank[$row['id']] = 1; - } - - // let's see if some categories already have some sub-categories... - $query = ' -SELECT id_uppercat, MAX(rank)+1 AS next_rank - FROM '.CATEGORIES_TABLE.' - GROUP BY id_uppercat -;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - // for the id_uppercat NULL, we write 'NULL' and not the empty string - if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '') - { - $row['id_uppercat'] = 'NULL'; - } - $next_rank[$row['id_uppercat']] = $row['next_rank']; - } - - // next category id available - $query = ' -SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id - FROM '.CATEGORIES_TABLE.' -;'; - list($next_id) = mysql_fetch_array(pwg_query($query)); - - // retrieve file system sub-directories fulldirs - $fs_fulldirs = get_fs_directories($basedir); - // get_fs_directories doesn't include the base directory, so if it's a - // category directory, we need to include it in our array - if (isset($_POST['cat'])) - { - array_push($fs_fulldirs, $basedir); - } - - $inserts = array(); - // new categories are the directories not present yet in the database - foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir) - { - $dir = basename($fulldir); - if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir)) - { - $insert = array(); - - $insert{'id'} = $next_id++; - $insert{'dir'} = $dir; - $insert{'name'} = str_replace('_', ' ', $dir); - $insert{'site_id'} = 1; - $insert{'commentable'} = $conf['newcat_default_commentable']; - $insert{'uploadable'} = $conf['newcat_default_uploadable']; - $insert{'status'} = $conf{'newcat_default_status'}; - $insert{'visible'} = $conf{'newcat_default_visible'}; - - if (isset($db_fulldirs[dirname($fulldir)])) - { - $parent = $db_fulldirs[dirname($fulldir)]; - - $insert{'id_uppercat'} = $parent; - $insert{'uppercats'} = - $db_categories[$parent]['uppercats'].','.$insert{'id'}; - $insert{'rank'} = $next_rank[$parent]++; - $insert{'global_rank'} = - $db_categories[$parent]['global_rank'].'.'.$insert{'rank'}; - if ('private' == $db_categories[$parent]['status']) - { - $insert{'status'} = 'private'; - } - if ('false' == $db_categories[$parent]['visible']) - { - $insert{'visible'} = 'false'; - } - } - else - { - $insert{'uppercats'} = $insert{'id'}; - $insert{'rank'} = $next_rank['NULL']++; - $insert{'global_rank'} = $insert{'rank'}; - } - - array_push($inserts, $insert); - array_push($infos, array('path' => $fulldir, - 'info' => $lang['update_research_added'])); - - // add the new category to $db_categories and $db_fulldirs array - $db_categories[$insert{'id'}] = - array( - 'id' => $insert{'id'}, - 'status' => $insert{'status'}, - 'visible' => $insert{'visible'}, - 'uppercats' => $insert{'uppercats'}, - 'global_rank' => $insert{'global_rank'} - ); - $db_fulldirs[$fulldir] = $insert{'id'}; - $next_rank[$insert{'id'}] = 1; - } - else - { - array_push($errors, array('path' => $fulldir, 'type' => 'PWG-UPDATE-1')); - } - } - - if (count($inserts) > 0) - { - if (!$simulate) - { - $dbfields = array( - 'id','dir','name','site_id','id_uppercat','uppercats','commentable', - 'uploadable','visible','status','rank','global_rank' - ); - mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); - } - - $counts['new_categories'] = count($inserts); - } - - // to delete categories - $to_delete = array(); - foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir) - { - array_push($to_delete, $db_fulldirs[$fulldir]); - unset($db_fulldirs[$fulldir]); - array_push($infos, array('path' => $fulldir, - 'info' => $lang['update_research_deleted'])); - } - if (count($to_delete) > 0) - { - if (!$simulate) - { - delete_categories($to_delete); - } - $counts['del_categories'] = count($to_delete); - } - - echo '<!-- scanning dirs : '; - echo get_elapsed_time($start, get_moment()); - echo ' -->'."\n"; -} -// +-----------------------------------------------------------------------+ -// | files / elements | -// +-----------------------------------------------------------------------+ -if (isset($_POST['submit']) and $_POST['sync'] == 'files') -{ - $start_files = get_moment(); - $start= $start_files; - - $fs = get_fs($basedir); - - echo '<!-- get_fs : '.get_elapsed_time($start, get_moment()).' -->'."\n"; - - $cat_ids = array_diff(array_keys($db_categories), $to_delete); - - $db_elements = array(); - $db_unvalidated = array(); - - if (count($cat_ids) > 0) - { - $query = ' -SELECT id, path - FROM '.IMAGES_TABLE.' - WHERE storage_category_id IN ( -'.wordwrap(implode(', ', $cat_ids), 80, "\n").') -;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - $db_elements[$row['id']] = $row['path']; - } - - // searching the unvalidated waiting elements (they must not be taken into - // account) - $query = ' -SELECT file,storage_category_id - FROM '.WAITING_TABLE.' - WHERE storage_category_id IN ( -'.wordwrap(implode(', ', $cat_ids), 80, "\n").') - AND validated = \'false\' -;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push( - $db_unvalidated, - array_search($row['storage_category_id'], - $db_fulldirs).'/'.$row['file'] - ); - } - } - - // next element id available - $query = ' -SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id - FROM '.IMAGES_TABLE.' -;'; - list($next_element_id) = mysql_fetch_array(pwg_query($query)); - - $start = get_moment(); - - // because isset is one hundred time faster than in_array - $fs['thumbnails'] = array_flip($fs['thumbnails']); - $fs['representatives'] = array_flip($fs['representatives']); - - $inserts = array(); - $insert_links = array(); - - foreach (array_diff($fs['elements'], $db_elements, $db_unvalidated) as $path) - { - $insert = array(); - // storage category must exist - $dirname = dirname($path); - if (!isset($db_fulldirs[$dirname])) - { - continue; - } - $filename = basename($path); - if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename)) - { - array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-1')); - continue; - } - - // searching the thumbnail - $filename_wo_ext = get_filename_wo_extension($filename); - $tn_ext = ''; - $base_test = $dirname.'/thumbnail/'; - $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.'; - foreach ($conf['picture_ext'] as $ext) - { - $test = $base_test.$ext; - if (isset($fs['thumbnails'][$test])) - { - $tn_ext = $ext; - break; - } - } - - // 2 cases : the element is a picture or not. Indeed, for a picture - // thumbnail is mandatory and for non picture element, thumbnail and - // representative are optionnal - if (in_array(get_extension($filename), $conf['picture_ext'])) - { - // if we found a thumnbnail corresponding to our picture... - if ($tn_ext != '') - { - $insert{'id'} = $next_element_id++; - $insert{'file'} = $filename; - $insert{'storage_category_id'} = $db_fulldirs[$dirname]; - $insert{'date_available'} = CURRENT_DATE; - $insert{'tn_ext'} = $tn_ext; - $insert{'path'} = $path; - - array_push($inserts, $insert); - array_push($insert_links, - array('image_id' => $insert{'id'}, - 'category_id' => $insert{'storage_category_id'})); - array_push($infos, array('path' => $insert{'path'}, - 'info' => $lang['update_research_added'])); - } - else - { - array_push($errors, array('path' => $path, 'type' => 'PWG-UPDATE-2')); - } - } - else - { - // searching a representative - $representative_ext = ''; - $base_test = $dirname.'/pwg_representative/'.$filename_wo_ext.'.'; - foreach ($conf['picture_ext'] as $ext) - { - $test = $base_test.$ext; - if (isset($fs['representatives'][$test])) - { - $representative_ext = $ext; - break; - } - } - - $insert{'id'} = $next_element_id++; - $insert{'file'} = $filename; - $insert{'storage_category_id'} = $db_fulldirs[$dirname]; - $insert{'date_available'} = CURRENT_DATE; - $insert{'path'} = $path; - - if ($tn_ext != '') - { - $insert{'tn_ext'} = $tn_ext; - } - if ($representative_ext != '') - { - $insert{'representative_ext'} = $representative_ext; - } - - array_push($inserts, $insert); - array_push($insert_links, - array('image_id' => $insert{'id'}, - 'category_id' => $insert{'storage_category_id'})); - array_push($infos, array('path' => $insert{'path'}, - 'info' => $lang['update_research_added'])); - } - } - - if (count($inserts) > 0) - { - if (!$simulate) - { - // inserts all new elements - $dbfields = array( - 'id','file','storage_category_id','date_available','tn_ext' - ,'representative_ext','path' - ); - mass_inserts(IMAGES_TABLE, $dbfields, $inserts); - - // insert all links between new elements and their storage category - $dbfields = array('image_id','category_id'); - mass_inserts(IMAGE_CATEGORY_TABLE, $dbfields, $insert_links); - } - $counts['new_elements'] = count($inserts); - } - - // delete elements that are in database but not in the filesystem - $to_delete_elements = array(); - foreach (array_diff($db_elements, $fs['elements']) as $path) - { - array_push($to_delete_elements, array_search($path, $db_elements)); - array_push($infos, array('path' => $path, - 'info' => $lang['update_research_deleted'])); - } - if (count($to_delete_elements) > 0) - { - if (!$simulate) - { - delete_elements($to_delete_elements); - } - $counts['del_elements'] = count($to_delete_elements); - } - - echo '<!-- scanning files : '; - echo get_elapsed_time($start_files, get_moment()); - echo ' -->'."\n"; - - // retrieving informations given by uploaders - if (!$simulate and count($cat_ids) > 0) - { - $query = ' -SELECT id,file,storage_category_id,infos - FROM '.WAITING_TABLE.' - WHERE storage_category_id IN ( -'.wordwrap(implode(', ', $cat_ids), 80, "\n").') - AND validated = \'true\' -;'; - $result = pwg_query($query); - - $datas = array(); - $fields = - array( - 'primary' => array('id'), - 'update' => array('date_creation', 'author', 'name', 'comment') - ); - - $waiting_to_delete = array(); - - while ($row = mysql_fetch_array($result)) - { - $data = array(); - - $query = ' -SELECT id - FROM '.IMAGES_TABLE.' - WHERE storage_category_id = \''.$row['storage_category_id'].'\' - AND file = \''.$row['file'].'\' -;'; - list($data['id']) = mysql_fetch_array(pwg_query($query)); - - foreach ($fields['update'] as $field) - { - $data[$field] = getAttribute($row['infos'], $field); - } - - array_push($datas, $data); - array_push($waiting_to_delete, $row['id']); - } - - if (count($datas) > 0) - { - mass_updates(IMAGES_TABLE, $fields, $datas); - - // delete now useless waiting elements - $query = ' -DELETE - FROM '.WAITING_TABLE.' - WHERE id IN ('.implode(',', $waiting_to_delete).') -;'; - pwg_query($query); - } - } -} -// +-----------------------------------------------------------------------+ -// | template initialization | -// +-----------------------------------------------------------------------+ -$template->set_filenames(array('update'=>'admin/update.tpl')); - -$result_title = ''; -if (isset($simulate) and $simulate) -{ - $result_title.= $lang['update_simulation_title'].' '; -} -$result_title.= $lang['update_part_research']; - -// used_metadata string is displayed to inform admin which metadata will be -// used from files for synchronization -$used_metadata = $lang['metadata_basic'].' (filesize, width, height)'; - -if ($conf['use_exif']) -{ - $used_metadata.= ', '.$lang['metadata_exif'].' (date_creation)'; -} - -if ($conf['use_iptc']) -{ - $used_metadata.= ', '.$lang['metadata_iptc']; - $used_metadata.= '('; - $used_metadata.= implode(', ', array_keys($conf['use_iptc_mapping'])); - $used_metadata.= ')'; -} - -$template->assign_vars( - array( - 'L_SUBMIT'=>$lang['submit'], - 'L_RESET'=>$lang['reset'], - 'L_UPDATE_TITLE'=>$lang['update_default_title'], - 'L_UPDATE_SYNC_FILES'=>$lang['update_sync_files'], - 'L_UPDATE_SYNC_DIRS'=>$lang['update_sync_dirs'], - 'L_UPDATE_SYNC_ALL'=>$lang['update_sync_all'], - 'L_UPDATE_SYNC_METADATA'=>$lang['update_sync_metadata'], - 'L_UPDATE_SYNC_METADATA_NEW'=>$lang['update_sync_metadata_new'], - 'L_UPDATE_SYNC_METADATA_ALL'=>$lang['update_sync_metadata_all'], - 'L_UPDATE_CATS_SUBSET'=>$lang['update_cats_subset'], - 'L_RESULT_UPDATE'=>$result_title, - 'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'], - 'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'], - 'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'], - 'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'], - 'L_UPDATE_NB_ERRORS'=>$lang['update_nb_errors'], - 'L_SEARCH_SUBCATS_INCLUDED'=>$lang['search_subcats_included'], - 'L_UPDATE_WRONG_DIRNAME_INFO'=>$lang['update_wrong_dirname_info'], - 'L_UPDATE_MISSING_TN_INFO'=>$lang['update_missing_tn_info'], - 'PICTURE_EXT_LIST'=>implode(',', $conf['picture_ext']), - 'L_UPDATE_ERROR_LIST_TITLE'=>$lang['update_error_list_title'], - 'L_UPDATE_ERRORS_CAPTION'=>$lang['update_errors_caption'], - 'L_UPDATE_DISPLAY_INFO'=>$lang['update_display_info'], - 'L_UPDATE_SIMULATE'=>$lang['update_simulate'], - 'L_UPDATE_INFOS_TITLE'=>$lang['update_infos_title'], - 'L_RESULT_METADATA'=>$lang['update_result_metadata'], - 'L_ELEMENTS_METADATA_SYNC'=>$lang['update_elements_metadata_sync'], - 'L_USED_METADATA'=>$lang['update_used_metadata'], - 'METADATA_LIST' => $used_metadata - )); - -$template->assign_vars( - array( - 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=synchronize' - ) - ); -// +-----------------------------------------------------------------------+ -// | introduction : choices | -// +-----------------------------------------------------------------------+ -if (!isset($_POST['submit']) or (isset($simulate) and $simulate)) -{ - $template->assign_block_vars('introduction', array()); - - if (isset($simulate) and $simulate) - { - switch ($_POST['sync']) - { - case 'dirs' : - { - $template->assign_vars( - array('SYNC_DIRS_CHECKED'=>'checked="checked"')); - break; - } - case 'files' : - { - $template->assign_vars( - array('SYNC_ALL_CHECKED'=>'checked="checked"')); - break; - } - } - - if (isset($_POST['display_info']) and $_POST['display_info'] == 1) - { - $template->assign_vars( - array('DISPLAY_INFO_CHECKED'=>'checked="checked"')); - } - - if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1) - { - $template->assign_vars( - array('SUBCATS_INCLUDED_CHECKED'=>'checked="checked"')); - } - - if (isset($_POST['cat']) and is_numeric($_POST['cat'])) - { - $cat_selected = array($_POST['cat']); - } - else - { - $cat_selected = array(); - } - } - else - { - $template->assign_vars( - array('SYNC_DIRS_CHECKED' => 'checked="checked"', - 'SUBCATS_INCLUDED_CHECKED'=>'checked="checked"')); - - $cat_selected = array(); - } - - $query = ' -SELECT id,name,uppercats,global_rank - FROM '.CATEGORIES_TABLE.' - WHERE site_id = 1 -;'; - display_select_cat_wrapper($query, - $cat_selected, - 'introduction.category_option', - false); -} -// +-----------------------------------------------------------------------+ -// | synchronize files | -// +-----------------------------------------------------------------------+ -if (isset($_POST['submit']) - and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')) -{ - $template->assign_block_vars( - 'update', - array( - 'NB_NEW_CATEGORIES'=>$counts['new_categories'], - 'NB_DEL_CATEGORIES'=>$counts['del_categories'], - 'NB_NEW_ELEMENTS'=>$counts['new_elements'], - 'NB_DEL_ELEMENTS'=>$counts['del_elements'], - 'NB_ERRORS'=>count($errors), - )); - - if (count($errors) > 0) - { - $template->assign_block_vars('update.update_errors', array()); - foreach ($errors as $error) - { - $template->assign_block_vars( - 'update.update_errors.update_error', - array( - 'ELEMENT' => $error['path'], - 'LABEL' => $error['type'].' ('.$error_labels[$error['type']].')' - )); - } - } - if (count($infos) > 0 - and isset($_POST['display_info']) - and $_POST['display_info'] == 1) - { - $template->assign_block_vars('update.update_infos', array()); - foreach ($infos as $info) - { - $template->assign_block_vars( - 'update.update_infos.update_info', - array( - 'ELEMENT' => $info['path'], - 'LABEL' => $info['info'] - )); - } - } - - if (!$simulate) - { - $start = get_moment(); - update_category('all'); - echo '<!-- update_category(all) : '; - echo get_elapsed_time($start,get_moment()); - echo ' -->'."\n"; - $start = get_moment(); - ordering(); - update_global_rank(); - echo '<!-- ordering categories : '; - echo get_elapsed_time($start, get_moment()); - echo ' -->'."\n"; - } -} -// +-----------------------------------------------------------------------+ -// | synchronize metadata | -// +-----------------------------------------------------------------------+ -else if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])) -{ - // sync only never synchronized files ? - if ($_POST['sync'] == 'metadata_new') - { - $opts['only_new'] = true; - } - else - { - $opts['only_new'] = false; - } - $opts['category_id'] = ''; - $opts['recursive'] = true; - - if (isset($_POST['cat'])) - { - $opts['category_id'] = $_POST['cat']; - // recursive ? - if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1) - { - $opts['recursive'] = false; - } - } - $start = get_moment(); - $files = get_filelist($opts['category_id'], 1, - $opts['recursive'], - $opts['only_new']); - - echo '<!-- get_filelist : '; - echo get_elapsed_time($start, get_moment()); - echo ' -->'."\n"; - - $start = get_moment(); - update_metadata($files); - echo '<!-- metadata update : '; - echo get_elapsed_time($start, get_moment()); - echo ' -->'."\n"; - - $template->assign_block_vars( - 'metadata_result', - array( - 'NB_ELEMENTS' => count($files), - )); -} -// +-----------------------------------------------------------------------+ -// | sending html code | -// +-----------------------------------------------------------------------+ -$template->assign_var_from_handle('ADMIN_CONTENT', 'update'); -?>
\ No newline at end of file |