aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin.php6
-rw-r--r--admin/cat_modify.php11
-rw-r--r--admin/remote_site.php746
-rw-r--r--admin/site_manager.php516
-rw-r--r--admin/site_reader_local.php506
-rw-r--r--admin/site_reader_remote.php382
-rw-r--r--admin/site_update.php1639
-rw-r--r--admin/update.php770
-rw-r--r--category.php4
-rw-r--r--include/functions_xml.inc.php11
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php40
-rw-r--r--language/fr_FR.iso-8859-1/admin.lang.php39
-rw-r--r--template/yoga/admin.tpl1
-rw-r--r--template/yoga/admin/remote_site.tpl83
-rw-r--r--template/yoga/admin/site_manager.tpl98
-rw-r--r--template/yoga/admin/site_update.tpl216
-rw-r--r--template/yoga/admin/update.tpl95
-rw-r--r--upload.php12
18 files changed, 1760 insertions, 3415 deletions
diff --git a/admin.php b/admin.php
index 4e73e2f0f..b1070e7ab 100644
--- a/admin.php
+++ b/admin.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$
@@ -81,7 +81,7 @@ $template->assign_vars(
'U_CAT_VISIBLE'=> $opt_link.'visible',
'U_CAT_STATUS'=> $opt_link.'status',
'U_CAT_OPTIONS'=> $link_start.'cat_options',
- 'U_CAT_UPDATE'=> $link_start.'update',
+ 'U_CAT_UPDATE'=> $link_start.'site_update&site=1',
'U_WAITING'=> $link_start.'waiting',
'U_COMMENTS'=> $link_start.'comments',
'U_RATING'=> $link_start.'rating',
@@ -105,7 +105,7 @@ if ($conf['allow_random_representative'])
)
);
}
-
+
//------------------------------------------------------------- content display
$page['errors'] = array();
$page['infos'] = array();
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&amp;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.= '&amp;site='.$row['id'];
- $base_url.= '&amp;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.= '&amp;site='.$row['id'];
- $base_url.= '&amp;action=';
-
- $update_url = PHPWG_ROOT_PATH.'admin.php';
- $update_url.= '?page=site_update';
- $update_url.= '&amp;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.= '&amp;site='.$row['id'];
+ $base_url.= '&amp;action=';
+
+ $update_url = PHPWG_ROOT_PATH.'admin.php';
+ $update_url.= '?page=site_update';
+ $update_url.= '&amp;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
diff --git a/category.php b/category.php
index 38d18e11f..bc0d8c28b 100644
--- a/category.php
+++ b/category.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$
@@ -435,7 +435,7 @@ if ( isset ( $page['cat'] ) )
{
// upload a picture in the category
if (is_numeric($page['cat'])
- and $page['cat_site_id'] == 1
+// and $page['cat_site_id'] == 1
and $page['cat_dir'] != ''
and $page['cat_uploadable'])
{
diff --git a/include/functions_xml.inc.php b/include/functions_xml.inc.php
index d37537fa1..64df545ce 100644
--- a/include/functions_xml.inc.php
+++ b/include/functions_xml.inc.php
@@ -53,9 +53,18 @@ function getAttribute( $element, $attribute )
{
// echo htmlentities($element).'<br /><br />';
$regex = '/^<\w+[^>]*'.$attribute.'\s*=\s*"('.VAL_REG.')"/i';
- if ( preg_match( $regex, $element, $out ) ) return $out[1];
+ if ( preg_match( $regex, $element, $out ) )
+ {
+ return html_entity_decode($out[1], ENT_QUOTES);
+ }
else return '';
}
+
+// The function encode Attribute returns the xml attribute $attribute="$value"
+function encodeAttribute( $attribute, $value )
+{
+ return $attribute.'="'.htmlspecialchars($value, ENT_QUOTES).'" ';
+}
// The function getChild returns the first child
// exemple : getChild( "<table><tr>XXX</tr><tr>YYY</tr></table>", "tr" )
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index c7b0db36a..e0238b1dc 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -135,6 +135,7 @@ $lang['Save order'] = 'Save order';
$lang['Select at least one category'] = 'Select at least one category';
$lang['Select at least one picture'] = 'Select at least one picture';
$lang['Select at least one user'] = 'Select at least one user';
+$lang['Site manager'] = 'Site manager';
$lang['Show info'] = 'Show info';
$lang['Show number of comments'] = 'Show number of comments';
$lang['Status'] = 'Status';
@@ -191,7 +192,6 @@ $lang['delete category'] = 'delete category';
$lang['description'] = 'description';
$lang['dissociate from category'] = 'dissociate from category';
$lang['dissociate from group'] = 'dissociate from group';
-$lang['down'] = 'Move down';
$lang['edit category permissions'] = 'edit category permissions';
$lang['edit'] = 'Edit';
$lang['editcat_confirm'] = 'Category informations updated successfully.';
@@ -244,32 +244,31 @@ $lang['purge sessions'] = 'purge sessions';
$lang['randomly represented'] = 'randomly represented';
$lang['registration_date'] = 'registration date';
$lang['remote_site'] = 'Remote site';
-$lang['remote_site_already_exists'] = 'This site already exists';
$lang['remote_site_clean'] = 'clean';
$lang['remote_site_clean_hint'] = 'remove remote listing.xml file';
-$lang['remote_site_create'] = 'Create a new site : (give its URL to create_listing_file.php)';
-$lang['remote_site_created'] = 'created';
-$lang['remote_site_delete'] = 'delete';
-$lang['remote_site_delete_hint'] = 'delete this site and all its attached elements';
-$lang['remote_site_deleted'] = 'deleted';
-$lang['remote_site_error'] = 'an error happened';
-$lang['remote_site_file_not_found'] = 'file create_listing_file.php on remote site was not found';
$lang['remote_site_generate'] = 'generate listing';
$lang['remote_site_generate_hint'] = 'generate file listing.xml on remote site';
-$lang['remote_site_listing_not_found'] = 'listing.xml file was not found';
$lang['remote_site_local_found'] = 'A local listing.xml file has been found for ';
-$lang['remote_site_local_new'] = '(new site)';
$lang['remote_site_local_update'] = 'read local listing.xml and update';
-$lang['remote_site_removed'] = 'was removed on remote site';
-$lang['remote_site_removed_title'] = 'Removed elements';
+$lang['remote_site_test'] = 'test';
+$lang['remote_site_test_hint'] = 'test this remote site';
$lang['remote_site_uncorrect_url'] = 'Remote site url must start by http or https and must only contain characters among "/", "a-zA-Z0-9", "-" or "_"';
-$lang['remote_site_update'] = 'update';
-$lang['remote_site_update_hint'] = 'read remote listing.xml and updates database';
-$lang['remote_sites'] = 'Remote sites';
$lang['remove keyword'] = 'remove keyword';
$lang['selection'] = 'selection';
$lang['set to'] = 'set to';
$lang['singly represented'] = 'singly represented';
+$lang['site_already_exists'] = 'This site already exists';
+$lang['site_create'] = 'Create a new site : (give its URL to create_listing_file.php)';
+$lang['site_created'] = 'created';
+$lang['site_delete'] = 'delete';
+$lang['site_delete_hint'] = 'delete this site and all its attached elements';
+$lang['site_deleted'] = 'deleted';
+$lang['site_err'] = 'an error happened';
+$lang['site_err_remote_file_not_found'] = 'file create_listing_file.php on remote site was not found';
+$lang['site_local'] = 'Local';
+$lang['site_remote'] = 'Remote';
+$lang['site_synchronize'] = 'synchronize';
+$lang['site_synchronize_hint'] = 'update the database from files';
$lang['stats_addr'] = 'IP Address';
$lang['stats_category'] = 'Category';
$lang['stats_daily_graph_title'] = 'Pages seen by hour';
@@ -336,7 +335,12 @@ $lang['update'] = 'Synchronize';
$lang['update_cats_subset'] = 'reduce to single existing categories';
$lang['update_default_title'] = 'Choose an option';
$lang['update_display_info'] = 'display maximum informations (added categories and elements, deleted categories and elements)';
-$lang['update_elements_metadata_sync'] = 'elements informations synchronized with files metadata';
+$lang['update_missing_file_or_dir'] = 'File/directory read error';
+$lang['update_missing_file_or_dir_info'] = 'The file or directory cannot be accessed (either it does not exist or the access is denied)';
+$lang['update_err_pwg_version_differs'] = 'PhpWebGallery version differs on the remote site';
+$lang['update_err_pwg_version_differs_info'] = 'Version of create_listing_file.php on the remote site and PhpWebGallery must be the same';
+$lang['update_err_remote_listing_not_found'] = 'listing.xml file was not found';
+$lang['update_err_remote_listing_not_found_info'] = 'listing.xml file was not found on the remote site. This file is generated by choosing the "generate listing" command in the Site manager';
$lang['update_error_list_title'] = 'Error list';
$lang['update_errors_caption'] = 'Errors caption';
$lang['update_infos_title'] = 'Detailed informations';
@@ -344,6 +348,8 @@ $lang['update_missing_tn_info'] = 'a picture filetype requires a thumbnail. The
$lang['update_missing_tn_short'] = 'missing thumbnail';
$lang['update_nb_del_categories'] = 'categories deleted in the database';
$lang['update_nb_del_elements'] = 'elements deleted in the database';
+$lang['update_nb_elements_metadata_available'] = 'images candidates for metadata synchronization';
+$lang['update_nb_elements_metadata_sync'] = 'elements informations synchronized with files metadata';
$lang['update_nb_errors'] = 'errors during synchronization';
$lang['update_nb_new_categories'] = 'categories added in the database';
$lang['update_nb_new_elements'] = 'elements added in the database';
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index 060a39219..49af95281 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -135,6 +135,7 @@ $lang['Save order'] = 'Sauvegarder l\'ordre';
$lang['Select at least one category'] = 'Sélectionner au moins une catégorie';
$lang['Select at least one picture'] = 'Sélectionner au moins une image';
$lang['Select at least one user'] = 'Séléctionner au moins un utilisateur';
+$lang['Site manager'] = 'Gestionnaire des sites';
$lang['Show info'] = 'Montrer les informations';
$lang['Show number of comments'] = 'Montrer le nombre de commentaires';
$lang['Status'] = 'Statut';
@@ -243,32 +244,31 @@ $lang['purge sessions'] = 'purger les sessions';
$lang['randomly represented'] = 'représentant au hasard';
$lang['registration_date'] = 'date d\'enregistrement';
$lang['remote_site'] = 'Site distant';
-$lang['remote_site_already_exists'] = 'Ce site existe déjà';
$lang['remote_site_clean'] = 'nettoyer';
$lang['remote_site_clean_hint'] = 'supprimer le fichier listing.xml distant';
-$lang['remote_site_create'] = 'Créer un nouveau site distant : (donner son URL vers create_listing_file.php)';
-$lang['remote_site_created'] = 'créé';
-$lang['remote_site_delete'] = 'supprimer';
-$lang['remote_site_delete_hint'] = 'supprimer ce site distant et toutes les informations associées';
-$lang['remote_site_deleted'] = 'supprimé';
-$lang['remote_site_error'] = 'une erreur est survenue';
-$lang['remote_site_file_not_found'] = 'le fichier create_listing_file.php est introuvable sur le site distant';
$lang['remote_site_generate'] = 'générer le listing';
$lang['remote_site_generate_hint'] = 'générer le fichier listing.xml sur le site distant';
-$lang['remote_site_listing_not_found'] = 'le fichier listing.xml est introuvable';
$lang['remote_site_local_found'] = 'Un fichier listing.xml local a été trouvé pour ';
-$lang['remote_site_local_new'] = '(nouveau site)';
$lang['remote_site_local_update'] = 'lire le listing.xml local et mettre à jour';
-$lang['remote_site_removed'] = 'a été supprimé du site distant';
-$lang['remote_site_removed_title'] = 'Éléments supprimés';
+$lang['remote_site_test'] = 'tester';
+$lang['remote_site_test_hint'] = 'tester ce site distant';
$lang['remote_site_uncorrect_url'] = 'L\'URL d\'un site distant doit commencer par "http" ou "https" et ne doit contenir des caractères que parmi "/", "a-zA-Z0-9", "-" ou "_"';
-$lang['remote_site_update'] = 'synchronisation';
-$lang['remote_site_update_hint'] = 'lit le fichier listing.xml distant et met à jour la base de données';
-$lang['remote_sites'] = 'Sites distants';
$lang['remove keyword'] = 'supprimer mot-clef';
$lang['selection'] = 'sélection';
$lang['set to'] = 'changer en';
$lang['singly represented'] = 'représentant fixe';
+$lang['site_already_exists'] = 'Ce site existe déjà';
+$lang['site_create'] = 'Créer un nouveau site distant : (donner son URL vers create_listing_file.php)';
+$lang['site_created'] = 'créé';
+$lang['site_delete'] = 'supprimer';
+$lang['site_delete_hint'] = 'supprimer ce site et toutes les informations associées';
+$lang['site_deleted'] = 'supprimé';
+$lang['site_err'] = 'une erreur est survenue';
+$lang['site_err_remote_file_not_found'] = 'le fichier create_listing_file.php est introuvable sur le site distant';
+$lang['site_local'] = 'Local';
+$lang['site_remote'] = 'Distant';
+$lang['site_synchronize'] = 'synchroniser';
+$lang['site_synchronize_hint'] = 'met à jour la base de données à partir des fichiers';
$lang['stats_addr'] = 'Adresse IP';
$lang['stats_category'] = 'Catégorie';
$lang['stats_daily_graph_title'] = 'Pages vues par heure';
@@ -335,7 +335,12 @@ $lang['update'] = 'Synchroniser';
$lang['update_cats_subset'] = 'traiter uniquement une catégorie';
$lang['update_default_title'] = 'Choisir une option';
$lang['update_display_info'] = 'afficher un maximum d\'informations (catégories ajoutées, éléments ajoutés, catégories et éléments supprimés)';
-$lang['update_elements_metadata_sync'] = 'informations des images synchronisées avec les méta-données';
+$lang['update_missing_file_or_dir'] = 'Erreur d\'ouverture fichier/répertoire';
+$lang['update_missing_file_or_dir_info'] = 'Le fichier ou répertoire ne peut pas être accede (soit il n\'existe pas, soit l\'accés est refusé)';
+$lang['update_err_pwg_version_differs'] = 'La version PhpWebGallery sur le site distant est differente';
+$lang['update_err_pwg_version_differs_info'] = 'La version de create_listing_file.php sur le site distant et PhpWebGallery doit être la même';
+$lang['update_err_remote_listing_not_found'] = 'le fichier listing.xml est introuvable';
+$lang['update_err_remote_listing_not_found_info'] = 'le fichier listing.xml est introuvable sur le site distant. Ce fichier est generé en choisissant la commande "générer le listing" dans le gestionnaire de sites';
$lang['update_error_list_title'] = 'Liste des erreurs';
$lang['update_errors_caption'] = 'Légende des erreurs';
$lang['update_infos_title'] = 'Informations détaillées';
@@ -343,6 +348,8 @@ $lang['update_missing_tn_info'] = 'Chaque fichier image requiert une miniature.
$lang['update_missing_tn_short'] = 'miniature manquante';
$lang['update_nb_del_categories'] = 'catégories supprimées de la base de données';
$lang['update_nb_del_elements'] = 'éléments supprimés de la base de données';
+$lang['update_nb_elements_metadata_available'] = 'images candidates à la synchronisation avec les méta-données';
+$lang['update_nb_elements_metadata_sync'] = 'informations des images synchronisées avec les méta-données';
$lang['update_nb_errors'] = 'erreurs survenues durant la synchronisation';
$lang['update_nb_new_categories'] = 'catégories ajoutées dans la base de données';
$lang['update_nb_new_elements'] = 'éléments ajoutés dans la base de données';
diff --git a/template/yoga/admin.tpl b/template/yoga/admin.tpl
index 33f1e6eba..b548d3bf4 100644
--- a/template/yoga/admin.tpl
+++ b/template/yoga/admin.tpl
@@ -15,7 +15,6 @@
<ul>
<li><a href="{U_FAQ}">{lang:instructions}</a></li>
<li><a href="{U_SITE_MANAGER}">{lang:Site manager}</a></li>
- <li><a href="{U_SITES}">{lang:remote_sites}</a></li>
<li><a href="{U_HISTORY}">{lang:history}</a></li>
<li><a href="{U_CAT_UPDATE}">{lang:update}</a></li>
<li><a href="{U_MAINTENANCE}">{lang:Maintenance}</a></li>
diff --git a/template/yoga/admin/remote_site.tpl b/template/yoga/admin/remote_site.tpl
deleted file mode 100644
index df5f50d5d..000000000
--- a/template/yoga/admin/remote_site.tpl
+++ /dev/null
@@ -1,83 +0,0 @@
-<!-- $Id$ -->
-<div class="titrePage">
- <ul class="categoryActions">
- <li><a href="{U_HELP}" onclick="popuphelp(this.href); return false;" title="{lang:Help}"><img src="{themeconf:icon_dir}/help.png" class="button" alt="(?)"></a></li>
- </ul>
- <h2>{lang:remote_sites}</h2>
-</div>
-
-<!-- BEGIN errors -->
-<div class="errors">
- <ul>
- <!-- BEGIN error -->
- <li>{errors.error.ERROR}</li>
- <!-- END error -->
- </ul>
-</div>
-<!-- END errors -->
-
-<!-- BEGIN confirmation -->
-<div class="info">{confirmation.CONTENT}</div>
-<!-- END confirmation -->
-
-<!-- BEGIN update -->
-<div class="admin">{L_RESULT_UPDATE}</div>
-<ul style="text-align:left;">
- <li class="update_summary_new">{update.NB_NEW_CATEGORIES} {L_NB_NEW_CATEGORIES}</li>
- <li class="update_summary_new">{update.NB_NEW_ELEMENTS} {L_NB_NEW_ELEMENTS}</li>
- <li class="update_summary_del">{update.NB_DEL_CATEGORIES} {L_NB_DEL_CATEGORIES}</li>
- <li class="update_summary_del">{update.NB_DEL_ELEMENTS} {L_NB_DEL_ELEMENTS}</li>
-</ul>
-<!-- BEGIN removes -->
-{L_REMOTE_SITE_REMOVED_TITLE}
-<ul style="text-align:left;">
- <!-- BEGIN remote_remove -->
- <li>{update.removes.remote_remove.NAME} {L_REMOTE_SITE_REMOVED}</li>
- <!-- END remote_remove -->
-</ul>
-<!-- END removes -->
-<!-- END update -->
-
-<!-- BEGIN remote_output -->
-<div class="remoteOutput">
- <ul>
- <!-- BEGIN remote_line -->
- <li class="{remote_output.remote_line.CLASS}">{remote_output.remote_line.CONTENT}</li>
- <!-- END remote_line -->
- </ul>
-</div>
-<!-- END remote_output -->
-
-<!-- BEGIN local -->
-<div class="remoteLocal">
- {L_REMOTE_SITE_LOCAL_FOUND} {local.URL}
- <!-- BEGIN new_site -->
- {L_REMOTE_SITE_LOCAL_NEW}
- <!-- END new_site -->
- [<a href="{local.U_UPDATE}">{L_REMOTE_SITE_LOCAL_UPDATE}</a>]
-</div>
-<!-- END local -->
-
-<form action="{F_ACTION}" method="post">
- <p>
- <label for="galleries_url" >{L_REMOTE_SITE_CREATE}</label>
- <input type="text" name="galleries_url" id="galleries_url" value="{F_GALLERIES_URL}" />
- </p>
- <p>
- <input type="submit" name="submit" value="{L_SUBMIT}" />
- </p>
-</form>
-
-<!-- BEGIN sites -->
-<table>
- <!-- BEGIN site -->
- <tr>
- <td>{sites.site.NAME}</td>
- <td>[<a href="{sites.site.U_GENERATE}" title="{L_REMOTE_SITE_GENERATE_HINT}">{L_REMOTE_SITE_GENERATE}</a>]</td>
- <td>[<a href="{sites.site.U_UPDATE}" title="{L_REMOTE_SITE_UPDATE_HINT}">{L_REMOTE_SITE_UPDATE}</a>]</td>
- <td>[<a href="{sites.site.U_CLEAN}" title="{L_REMOTE_SITE_CLEAN_HINT}">{L_REMOTE_SITE_CLEAN}</a>]</td>
- <td>[<a href="{sites.site.U_DELETE}" title="{L_REMOTE_SITE_DELETE_HINT}">{L_REMOTE_SITE_DELETE}</a>]</td>
- </tr>
- <!-- END site -->
-</table>
-<!-- END sites -->
diff --git a/template/yoga/admin/site_manager.tpl b/template/yoga/admin/site_manager.tpl
index 565264efe..91a81f268 100644
--- a/template/yoga/admin/site_manager.tpl
+++ b/template/yoga/admin/site_manager.tpl
@@ -1,49 +1,49 @@
-<!-- $Id: remote_site.tpl 980 2005-12-10 15:24:53Z chrisaga $ -->
-<div class="titrePage">
- <ul class="categoryActions">
- <li><a href="{U_HELP}" onclick="popuphelp(this.href); return false;" title="{lang:Help}"><img src="{themeconf:icon_dir}/help.png" class="button" alt="(?)"></a></li>
- </ul>
- <h2>{lang:remote_sites}</h2>
-</div>
-
-<!-- BEGIN remote_output -->
-<div class="remoteOutput">
- <ul>
- <!-- BEGIN remote_line -->
- <li class="{remote_output.remote_line.CLASS}">{remote_output.remote_line.CONTENT}</li>
- <!-- END remote_line -->
- </ul>
-</div>
-<!-- END remote_output -->
-
-<!-- BEGIN sites -->
-<table border="1" cellpadding="0" cellspacing="0">
- <!-- BEGIN site -->
- <tr align="left"><td>
- <a href="{sites.site.NAME}" target="_blank">{sites.site.NAME}</a><br>({sites.site.TYPE}, {sites.site.CATEGORIES} {lang:categories}, {sites.site.IMAGES} {lang:picture}s)
- </td><td>
- [<a href="{sites.site.U_UPDATE}" title="{lang:update this site}">{lang:remote_site_update}</a>]
- <!-- BEGIN delete -->
- [<a href="{sites.site.delete.U_DELETE}" onclick="return confirm('{lang:Are you sure?}');"
- title="{lang:remote_site_delete_hint}">{lang:remote_site_delete}</a>]
- <!-- END delete -->
- <!-- BEGIN remote -->
- <br>
- [<a href="{sites.site.remote.U_TEST}" title="{lang:@@}">{lang:Test}</a>]
- [<a href="{sites.site.remote.U_GENERATE}" title="{lang:remote_site_generate_hint}">{lang:remote_site_generate}</a>]
- [<a href="{sites.site.remote.U_CLEAN}" title="{lang:remote_site_clean_hint}">{lang:remote_site_clean}</a>]
- <!-- END remote -->
- </td></tr>
- <!-- END site -->
-</table>
-<!-- END sites -->
-
-<form action="{F_ACTION}" method="post">
- <p>
- <label for="galleries_url" >{lang:remote_site_create}</label>
- <input type="text" name="galleries_url" id="galleries_url" />
- </p>
- <p>
- <input type="submit" name="submit" value="{lang:submit}" />
- </p>
-</form>
+<!-- $Id: remote_site.tpl 980 2005-12-10 15:24:53Z chrisaga $ -->
+<div class="titrePage">
+ <ul class="categoryActions">
+ <li><a href="{U_HELP}" onclick="popuphelp(this.href); return false;" title="{lang:Help}"><img src="{themeconf:icon_dir}/help.png" class="button" alt="(?)"></a></li>
+ </ul>
+ <h2>{lang:Site manager}</h2>
+</div>
+
+<!-- BEGIN remote_output -->
+<div class="remoteOutput">
+ <ul>
+ <!-- BEGIN remote_line -->
+ <li class="{remote_output.remote_line.CLASS}">{remote_output.remote_line.CONTENT}</li>
+ <!-- END remote_line -->
+ </ul>
+</div>
+<!-- END remote_output -->
+
+<!-- BEGIN sites -->
+<table border="1" cellpadding="0" cellspacing="0">
+ <!-- BEGIN site -->
+ <tr align="left"><td>
+ <a href="{sites.site.NAME}" target="_blank">{sites.site.NAME}</a><br>({sites.site.TYPE}, {sites.site.CATEGORIES} {lang:categories}, {sites.site.IMAGES} {lang:picture}s)
+ </td><td>
+ [<a href="{sites.site.U_SYNCHRONIZE}" title="{lang:site_synchronize_hint}">{lang:site_synchronize}</a>]
+ <!-- BEGIN delete -->
+ [<a href="{sites.site.delete.U_DELETE}" onclick="return confirm('{lang:Are you sure?}');"
+ title="{lang:site_delete_hint}">{lang:site_delete}</a>]
+ <!-- END delete -->
+ <!-- BEGIN remote -->
+ <br>
+ [<a href="{sites.site.remote.U_TEST}" title="{lang:remote_site_test_hint}">{lang:remote_site_test}</a>]
+ [<a href="{sites.site.remote.U_GENERATE}" title="{lang:remote_site_generate_hint}">{lang:remote_site_generate}</a>]
+ [<a href="{sites.site.remote.U_CLEAN}" title="{lang:remote_site_clean_hint}">{lang:remote_site_clean}</a>]
+ <!-- END remote -->
+ </td></tr>
+ <!-- END site -->
+</table>
+<!-- END sites -->
+
+<form action="{F_ACTION}" method="post">
+ <p>
+ <label for="galleries_url" >{lang:site_create}</label>
+ <input type="text" name="galleries_url" id="galleries_url" />
+ </p>
+ <p>
+ <input type="submit" name="submit" value="{lang:submit}" />
+ </p>
+</form>
diff --git a/template/yoga/admin/site_update.tpl b/template/yoga/admin/site_update.tpl
index ad0d6ee7c..518975360 100644
--- a/template/yoga/admin/site_update.tpl
+++ b/template/yoga/admin/site_update.tpl
@@ -1,108 +1,108 @@
-<!-- $Id: update.tpl 980 2005-12-10 15:24:53Z chrisaga $ -->
-
-<div class="titrePage">
- <ul class="categoryActions">
- <li><a href="{U_HELP}" onclick="popuphelp(this.href); return false;" title="{lang:Help}"><img src="{themeconf:icon_dir}/help.png" class="button" alt="(?)"></a></li>
- </ul>
- <h2>{lang:title_update}: <a href="{SITE_URL}" target="_blank">{SITE_URL}</a></h2>
-</div>
-
-<!-- BEGIN update_result -->
-<h3>{L_RESULT_UPDATE}</h3>
-<ul>
- <li class="update_summary_new">{update_result.NB_NEW_CATEGORIES} {lang:update_nb_new_categories}</li>
- <li class="update_summary_new">{update_result.NB_NEW_ELEMENTS} {lang:update_nb_new_elements}</li>
- <li class="update_summary_del">{update_result.NB_DEL_CATEGORIES} {lang:update_nb_del_categories}</li>
- <li class="update_summary_del">{update_result.NB_DEL_ELEMENTS} {lang:update_nb_del_elements}</li>
- <li class="update_summary_err">{update_result.NB_ERRORS} {lang:update_nb_errors}</li>
-</ul>
-<!-- END update_result -->
-
-<!-- BEGIN metadata_result -->
-<h3>{L_RESULT_METADATA}</h3>
-<ul>
- <li>{metadata_result.NB_ELEMENTS_DONE} {lang:update_elements_metadata_sync}</li>
- <li>{metadata_result.NB_ELEMENTS_CANDIDATES} {lang:elements available for synchronization}</li>
- <li>{lang:update_used_metadata} : {METADATA_LIST}</li>
-</ul>
-<!-- END metadata_result -->
-
-
-<!-- BEGIN sync_errors -->
-<h3>{lang:update_error_list_title}</h3>
-<div class="errors">
-<ul>
- <!-- BEGIN error -->
- <li>[{sync_errors.error.ELEMENT}] {sync_errors.error.LABEL}</li>
- <!-- END error -->
-</ul>
-</div>
-<h3>{lang:update_errors_caption}</h3>
-<ul>
- <!-- BEGIN error_caption -->
- <li><strong>{sync_errors.error_caption.TYPE}</strong>: {sync_errors.error_caption.LABEL}</li>
- <!-- END error_caption -->
-</ul>
-<!-- END sync_errors -->
-
-<!-- BEGIN sync_infos -->
-<h3>{lang:update_infos_title}</h3>
-<div class="infos">
-<ul>
- <!-- BEGIN info -->
- <li>[{sync_infos.info.ELEMENT}] {sync_infos.info.LABEL}</li>
- <!-- END sync_infos -->
-</ul>
-</div>
-<!-- END infos -->
-
-<!-- BEGIN introduction -->
-<h3>{lang:update_default_title}</h3>
-<form action="{F_ACTION}" method="post" id="update">
-
- <fieldset>
- <legend>{lang:update_sync_files}</legend>
- <ul>
- <li><label><input type="radio" name="sync" value="dirs" {SYNC_DIRS_CHECKED} /> {lang:update_sync_dirs}</label></li>
- <li><label><input type="radio" name="sync" value="files" {SYNC_ALL_CHECKED} /> {lang:update_sync_all}</label></li>
- <li><label><input type="checkbox" name="display_info" value="1" {DISPLAY_INFO_CHECKED} /> {lang:update_display_info}</label></li>
- </ul>
- </fieldset>
-
- <fieldset>
- <legend>{lang:update_sync_metadata}</legend>
- {lang:update_used_metadata} : {METADATA_LIST}.<br/>
- <ul>
- <li><label><input type="radio" name="sync" value="metadata_new" {SYNC_META_NEW_CHECKED} /> {lang:update_sync_metadata_new}</label></li>
- <li><label><input type="radio" name="sync" value="metadata_all" {SYNC_META_ALL_CHECKED} /> {lang:update_sync_metadata_all}</label></li>
- </ul>
- </fieldset>
-
- <fieldset>
- <legend></legend>
- <ul><li><label><input type="checkbox" name="simulate" value="1" checked="checked" /> {lang:update_simulate}</label></li></ul>
- </fieldset>
-
- <fieldset>
- <legend>{lang:update_cats_subset}</legend>
- <ul>
- <li>
- <select style="width:500px" name="cat" size="10">
- <!-- BEGIN category_option -->
- <option {introduction.category_option.SELECTED} value="{introduction.category_option.VALUE}">{introduction.category_option.OPTION}</option>
- <!-- END category_option -->
- </select>
- </li>
-
- <li><label><input type="checkbox" name="subcats-included" value="1" {SUBCATS_INCLUDED_CHECKED} /> {lang:search_subcats_included}</label></li>
- </ul>
- </fieldset>
-
- <p class="bottomButtons">
- <input type="submit" value="{lang:submit}" name="submit" />
- <input type="reset" value="{lang:reset}" name="reset" />
- </p>
-</form>
-<!-- END introduction -->
-
-<a href="{U_SITE_MANAGER}">{lang:Site manager}</a>
+<!-- $Id: update.tpl 980 2005-12-10 15:24:53Z chrisaga $ -->
+
+<div class="titrePage">
+ <ul class="categoryActions">
+ <li><a href="{U_HELP}" onclick="popuphelp(this.href); return false;" title="{lang:Help}"><img src="{themeconf:icon_dir}/help.png" class="button" alt="(?)"></a></li>
+ </ul>
+ <h2>{lang:title_update}: <a href="{SITE_URL}" target="_blank">{SITE_URL}</a></h2>
+</div>
+
+<!-- BEGIN update_result -->
+<h3>{L_RESULT_UPDATE}</h3>
+<ul>
+ <li class="update_summary_new">{update_result.NB_NEW_CATEGORIES} {lang:update_nb_new_categories}</li>
+ <li class="update_summary_new">{update_result.NB_NEW_ELEMENTS} {lang:update_nb_new_elements}</li>
+ <li class="update_summary_del">{update_result.NB_DEL_CATEGORIES} {lang:update_nb_del_categories}</li>
+ <li class="update_summary_del">{update_result.NB_DEL_ELEMENTS} {lang:update_nb_del_elements}</li>
+ <li class="update_summary_err">{update_result.NB_ERRORS} {lang:update_nb_errors}</li>
+</ul>
+<!-- END update_result -->
+
+<!-- BEGIN metadata_result -->
+<h3>{L_RESULT_METADATA}</h3>
+<ul>
+ <li>{metadata_result.NB_ELEMENTS_DONE} {lang:update_nb_elements_metadata_sync}</li>
+ <li>{metadata_result.NB_ELEMENTS_CANDIDATES} {lang:update_nb_elements_metadata_available}</li>
+ <li>{lang:update_used_metadata} : {METADATA_LIST}</li>
+</ul>
+<!-- END metadata_result -->
+
+
+<!-- BEGIN sync_errors -->
+<h3>{lang:update_error_list_title}</h3>
+<div class="errors">
+<ul>
+ <!-- BEGIN error -->
+ <li>[{sync_errors.error.ELEMENT}] {sync_errors.error.LABEL}</li>
+ <!-- END error -->
+</ul>
+</div>
+<h3>{lang:update_errors_caption}</h3>
+<ul>
+ <!-- BEGIN error_caption -->
+ <li><strong>{sync_errors.error_caption.TYPE}</strong>: {sync_errors.error_caption.LABEL}</li>
+ <!-- END error_caption -->
+</ul>
+<!-- END sync_errors -->
+
+<!-- BEGIN sync_infos -->
+<h3>{lang:update_infos_title}</h3>
+<div class="infos">
+<ul>
+ <!-- BEGIN info -->
+ <li>[{sync_infos.info.ELEMENT}] {sync_infos.info.LABEL}</li>
+ <!-- END sync_infos -->
+</ul>
+</div>
+<!-- END infos -->
+
+<!-- BEGIN introduction -->
+<h3>{lang:update_default_title}</h3>
+<form action="{F_ACTION}" method="post" id="update">
+
+ <fieldset>
+ <legend>{lang:update_sync_files}</legend>
+ <ul>
+ <li><label><input type="radio" name="sync" value="dirs" {SYNC_DIRS_CHECKED} /> {lang:update_sync_dirs}</label></li>
+ <li><label><input type="radio" name="sync" value="files" {SYNC_ALL_CHECKED} /> {lang:update_sync_all}</label></li>
+ <li><label><input type="checkbox" name="display_info" value="1" {DISPLAY_INFO_CHECKED} /> {lang:update_display_info}</label></li>
+ </ul>
+ </fieldset>
+
+ <fieldset>
+ <legend>{lang:update_sync_metadata}</legend>
+ {lang:update_used_metadata} : {METADATA_LIST}.<br/>
+ <ul>
+ <li><label><input type="radio" name="sync" value="metadata_new" {SYNC_META_NEW_CHECKED} /> {lang:update_sync_metadata_new}</label></li>
+ <li><label><input type="radio" name="sync" value="metadata_all" {SYNC_META_ALL_CHECKED} /> {lang:update_sync_metadata_all}</label></li>
+ </ul>
+ </fieldset>
+
+ <fieldset>
+ <legend></legend>
+ <ul><li><label><input type="checkbox" name="simulate" value="1" checked="checked" /> {lang:update_simulate}</label></li></ul>
+ </fieldset>
+
+ <fieldset>
+ <legend>{lang:update_cats_subset}</legend>
+ <ul>
+ <li>
+ <select style="width:500px" name="cat" size="10">
+ <!-- BEGIN category_option -->
+ <option {introduction.category_option.SELECTED} value="{introduction.category_option.VALUE}">{introduction.category_option.OPTION}</option>
+ <!-- END category_option -->
+ </select>
+ </li>
+
+ <li><label><input type="checkbox" name="subcats-included" value="1" {SUBCATS_INCLUDED_CHECKED} /> {lang:search_subcats_included}</label></li>
+ </ul>
+ </fieldset>
+
+ <p class="bottomButtons">
+ <input type="submit" value="{lang:submit}" name="submit" />
+ <input type="reset" value="{lang:reset}" name="reset" />
+ </p>
+</form>
+<!-- END introduction -->
+
+<a href="{U_SITE_MANAGER}">{lang:Site manager}</a>
diff --git a/template/yoga/admin/update.tpl b/template/yoga/admin/update.tpl
deleted file mode 100644
index 9609bccad..000000000
--- a/template/yoga/admin/update.tpl
+++ /dev/null
@@ -1,95 +0,0 @@
-<!-- $Id$ -->
-
-<div class="titrePage">
- <ul class="categoryActions">
- <li><a href="{U_HELP}" onclick="popuphelp(this.href); return false;" title="{lang:Help}"><img src="{themeconf:icon_dir}/help.png" class="button" alt="(?)"></a></li>
- </ul>
- <h2>{lang:title_update}</h2>
-</div>
-
-<!-- BEGIN update -->
-<h3>{L_RESULT_UPDATE}</h3>
-<ul>
- <li class="update_summary_new">{update.NB_NEW_CATEGORIES} {L_NB_NEW_CATEGORIES}</li>
- <li class="update_summary_new">{update.NB_NEW_ELEMENTS} {L_NB_NEW_ELEMENTS}</li>
- <li class="update_summary_del">{update.NB_DEL_CATEGORIES} {L_NB_DEL_CATEGORIES}</li>
- <li class="update_summary_del">{update.NB_DEL_ELEMENTS} {L_NB_DEL_ELEMENTS}</li>
- <li class="update_summary_err">{update.NB_ERRORS} {L_UPDATE_NB_ERRORS}</li>
-</ul>
-<!-- BEGIN update_errors -->
-<h3>{L_UPDATE_ERROR_LIST_TITLE}</h3>
-<ul>
- <!-- BEGIN update_error -->
- <li>[{update.update_errors.update_error.ELEMENT}] {update.update_errors.update_error.LABEL}</li>
- <!-- END update_error -->
-</ul>
-<h3>{L_UPDATE_ERRORS_CAPTION}</h3>
-<ul>
- <li><strong>PWG-UPDATE-1</strong> : {L_UPDATE_WRONG_DIRNAME_INFO}</li>
- <li><strong>PWG-UPDATE-2</strong> : {L_UPDATE_MISSING_TN_INFO} {{PICTURE_EXT_LIST}}</li>
-</ul>
-<!-- END update_errors -->
-<!-- BEGIN update_infos -->
-<h3>{L_UPDATE_INFOS_TITLE}</h3>
-<ul>
- <!-- BEGIN update_info -->
- <li>[{update.update_infos.update_info.ELEMENT}] {update.update_infos.update_info.LABEL}</li>
- <!-- END update_info -->
-</ul>
-<!-- END update_infos -->
-<!-- END update -->
-
-<!-- BEGIN metadata_result -->
-<h3>{L_RESULT_METADATA}</h3>
-<ul>
- <li>{metadata_result.NB_ELEMENTS} {L_ELEMENTS_METADATA_SYNC}</li>
- <li>{L_USED_METADATA} : {METADATA_LIST}</li>
-</ul>
-<!-- END metadata_result -->
-
-<!-- BEGIN introduction -->
-<h3>{L_UPDATE_TITLE}</h3>
-<form action="{F_ACTION}" method="post" id="update">
-
- <fieldset>
- <legend>{L_UPDATE_SYNC_FILES}</legend>
-
- <ul>
- <li><label><input type="radio" name="sync" value="dirs" {SYNC_DIRS_CHECKED} /> {L_UPDATE_SYNC_DIRS}</label></li>
- <li><label><input type="radio" name="sync" value="files" {SYNC_ALL_CHECKED} /> {L_UPDATE_SYNC_ALL}</label></li>
- <li><label><input type="checkbox" name="display_info" value="1" {DISPLAY_INFO_CHECKED} /> {L_UPDATE_DISPLAY_INFO}</label></li>
- <li><label><input type="checkbox" name="simulate" value="1" checked="checked" /> {L_UPDATE_SIMULATE}</label></li>
- </ul>
- </fieldset>
-
- <fieldset>
- <legend>{L_UPDATE_SYNC_METADATA}</legend>
- <p> {L_USED_METADATA} : {METADATA_LIST}.</p>
- <ul>
- <li><label><input type="radio" name="sync" value="metadata_new" /> {L_UPDATE_SYNC_METADATA_NEW}</label></li>
- <li><label><input type="radio" name="sync" value="metadata_all" /> {L_UPDATE_SYNC_METADATA_ALL}</label></li>
- </ul>
- </fieldset>
-
- <fieldset>
- <legend>{L_UPDATE_CATS_SUBSET}</legend>
- <ul>
- <li>
- <select style="width:500px" name="cat" size="10">
- <!-- BEGIN category_option -->
- <option {introduction.category_option.SELECTED} value="{introduction.category_option.VALUE}">{introduction.category_option.OPTION}</option>
- <!-- END category_option -->
- </select>
- </li>
-
- <li><label><input type="checkbox" name="subcats-included" value="1" {SUBCATS_INCLUDED_CHECKED} /> {L_SEARCH_SUBCATS_INCLUDED}</label></li>
- </ul>
- </fieldset>
-
- <p class="bottomButtons">
- <input type="submit" value="{L_SUBMIT}" name="submit" />
- <input type="reset" value="{L_RESET}" name="reset" />
- </p>
-
-</form>
-<!-- END introduction -->
diff --git a/upload.php b/upload.php
index a3fb0e576..ea06794bf 100644
--- a/upload.php
+++ b/upload.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$
@@ -125,7 +125,7 @@ if (isset($page['cat']))
$page['cat_site_id'] = $result['site_id'];
$page['cat_name'] = $result['name'];
$page['cat_uploadable'] = $result['uploadable'];
- if ($page['cat_site_id'] != 1 or !$page['cat_uploadable'])
+ if ( url_is_remote($page['cat_dir']) or !$page['cat_uploadable'])
{
echo '<div style="text-align:center;">'.$lang['upload_forbidden'].'<br />';
echo '<a href="./category.php">';
@@ -182,10 +182,10 @@ if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) )
// <infos author="Pierrick LE GALL" comment="my comment"
// date_creation="2004-08-14" name="" />
$xml_infos = '<infos';
- $xml_infos.= ' author="'.htmlspecialchars($_POST['author'],ENT_QUOTES).'"';
- $xml_infos.= ' comment="'.htmlspecialchars($_POST['comment'],ENT_QUOTES).'"';
- $xml_infos.= ' date_creation="'.$date_creation.'"';
- $xml_infos.= ' name="'.htmlspecialchars( $_POST['name'], ENT_QUOTES).'"';
+ $xml_infos.= encodeAttribute('author', $_POST['author']);
+ $xml_infos.= encodeAttribute('comment', $_POST['comment']);
+ $xml_infos.= encodeAttribute('date_creation', $date_creation);
+ $xml_infos.= encodeAttribute('name', $_POST['name']);
$xml_infos.= ' />';
if ( !preg_match( '/^[a-zA-Z0-9-_.]+$/', $_FILES['picture']['name'] ) )