923 lines
32 KiB
PHP
923 lines
32 KiB
PHP
<?php
|
|
|
|
// Copyright (C) 2002-2006 Balint Kis (balint@k-i-s.net)
|
|
// Copyright (C) 2005-2013 Solomon Peachy (pizza@shaftnet.org)
|
|
|
|
// 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; either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
include_once "include/config.php";
|
|
include_once "include/import.php";
|
|
include_once "include/exif.php";
|
|
include_once "include/common.php";
|
|
include_once "include/site.php";
|
|
|
|
$compress_pages = false; /* Explicitly disable it here */
|
|
set_time_limit(0); /* Explicitly disable timeouts here */
|
|
|
|
// Try to turn off caching
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
|
header("Pragma: no-cache");
|
|
|
|
$database = site_prolog(PO_USER_TYPE_USER);
|
|
|
|
$default_folder_id = pg_escape_string($database, $_REQUEST['folder']);
|
|
|
|
$file_name = $_FILES['file_name']['name'][0];
|
|
$file_size = $_FILES['file_name']['size'][0];
|
|
$file_name_tmp = $_FILES['file_name']['tmp_name'][0];
|
|
$original_file_type = strtolower(substr($file_name, strrpos($file_name, ".") + 1));
|
|
|
|
if ($local_bulk_upload &&
|
|
isset($_REQUEST['local_upload']) &&
|
|
$po_options['local_bulk_upload_path']) {
|
|
$original_file_type = "local";
|
|
}
|
|
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
$count = 0;
|
|
|
|
function load_default_image_data_values($default_folder) {
|
|
global $po_user;
|
|
global $po_data;
|
|
global $po_options;
|
|
|
|
$image_data = array ("num_of_files" => 0,
|
|
"po_user" => $po_user,
|
|
"po_options" => $po_options,
|
|
"photo_id" => FALSE,
|
|
"file" => array(0 => array("name" => "",
|
|
"name_tmp" => "",
|
|
"type" => "",
|
|
"remark" => "",
|
|
"master" => "f",
|
|
"orientation" => "Normal (0 deg)", /* "Normal" */
|
|
"orientation_orig" => "Normal (0 deg)", /* "Normal" */
|
|
"colorspace" => pg_escape_string($database, $_REQUEST['colorspace']),
|
|
)),
|
|
"folder" => $default_folder,
|
|
"author" => pg_escape_string($database, $_REQUEST['author']),
|
|
"title" => pg_escape_string($database, $_REQUEST['title']),
|
|
"caption" => pg_escape_string($database, $_REQUEST['caption']),
|
|
"caption_writer" => pg_escape_string($database, $_REQUEST['caption_writer']),
|
|
"web_statement" => pg_escape_string($database, $_REQUEST['web_statement']),
|
|
"copyright" => pg_escape_string($database, $_REQUEST['copyright']),
|
|
"supplemental_category" => pg_escape_string($database, $_REQUEST['supplemental_category']),
|
|
"category" => substr(pg_escape_string($database, $_REQUEST['category']), 0, 3),
|
|
"credit" => pg_escape_string($database, $_REQUEST['credit']),
|
|
"source" => pg_escape_string($database, $_REQUEST['source']),
|
|
"headline" => pg_escape_string($database, $_REQUEST['headline']),
|
|
"instructions" => pg_escape_string($database, $_REQUEST['instructions']),
|
|
"transmission_reference" => pg_escape_string($database, $_REQUEST['transmission_reference']),
|
|
"date_of_exposure" => check_date_validity($_REQUEST['exposure_timestamp']),
|
|
"location" => pg_escape_string($database, $_REQUEST['location']),
|
|
"storage_location_type" => pg_escape_string($database, $_REQUEST['storage_location_type']),
|
|
"storage_location_id" => pg_escape_string($database, $_REQUEST['storage_location_id']),
|
|
"storage_index" => pg_escape_string($database, $_REQUEST['storage_index']),
|
|
"access_rights" => pg_escape_string($database, $_REQUEST['access_rights']),
|
|
"hide_original" => pg_escape_string($database, $_REQUEST['hide_original']),
|
|
"store_url" => pg_escape_string($database, $_REQUEST['store_url']),
|
|
"remark" => pg_escape_string($database, $_REQUEST['remark']),
|
|
"camera" => pg_escape_string($database, $_REQUEST['camera']),
|
|
"film" => pg_escape_string($database, $_REQUEST['film']),
|
|
"focal_length" => pg_escape_string($database, $_REQUEST['focal_length']),
|
|
"aperture" => pg_escape_string($database, $_REQUEST['aperture']),
|
|
"shutter" => pg_escape_string($database, $_REQUEST['shutter']),
|
|
"exp_comp" => pg_escape_string($database, $_REQUEST['exp_comp']),
|
|
"exp_diff" => pg_escape_string($database, $_REQUEST['exp_diff']),
|
|
"camera_metering" => pg_escape_string($database, $_REQUEST['camera_metering']),
|
|
"camera_program" => pg_escape_string($database, $_REQUEST['camera_program']),
|
|
"flash_mode" => pg_escape_string($database, $_REQUEST['flash_mode']),
|
|
"flash_comp" => pg_escape_string($database, $_REQUEST['flash_comp']),
|
|
"scan_resolution" => pg_escape_string($database, $_REQUEST['scan_resolution']),
|
|
"scan_bitdepth" => pg_escape_string($database, $_REQUEST['scan_bitdepth']),
|
|
"scan_multiscan" => pg_escape_string($database, $_REQUEST['scan_multiscan']),
|
|
"iso_override" => pg_escape_string($database, convert_exif_iso($_REQUEST['iso_override'])),
|
|
"import_metadata_order" => $_REQUEST['import_metadata_order'],
|
|
"latitude" => pg_escape_string($database, parse_latitude($_REQUEST['latitude'])),
|
|
"longitude" => pg_escape_string($database, parse_latitude($_REQUEST['longitude'])),
|
|
"altitude" => pg_escape_string($database, $_REQUEST['altitude']),
|
|
"direction" => pg_escape_string($database, $_REQUEST['direction']),
|
|
"keywords" => array($_REQUEST['keywords']),
|
|
"IgnoreExifUserComment" => FALSE,
|
|
"exif" => "",
|
|
"camera_input_profile" => "",
|
|
"jpgfromraw" => FALSE,
|
|
"rdf" => "",
|
|
"iptc" => "",
|
|
"equipment" => isset($_REQUEST['equipment']) ? $_REQUEST['equipment'] : array()
|
|
);
|
|
|
|
return $image_data;
|
|
}
|
|
|
|
function XML_StartElement($parser, $name, $attribs) {
|
|
global $image_data;
|
|
global $current_folder;
|
|
global $temporary_directory;
|
|
global $database;
|
|
global $current_tag;
|
|
global $default_folder_id;
|
|
|
|
switch ($name) {
|
|
case "BULKUPLOAD":
|
|
break;
|
|
case "FOLDER":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$current_folder = $value;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "PHOTO":
|
|
$image_data = load_default_image_data_values($default_folder_id);
|
|
$image_data['folder'] = $current_folder;
|
|
case "TITLE":
|
|
$current_tag = "title";
|
|
$image_data['IgnoreExifUserComment'] = TRUE;
|
|
break;
|
|
case "AUTHOR":
|
|
$current_tag = "author";
|
|
break;
|
|
case "KEYWORD":
|
|
$current_tag = "keyword";
|
|
break;
|
|
case "CAPTION":
|
|
$current_tag = "caption";
|
|
break;
|
|
case "COPYRIGHT":
|
|
$current_tag = "copyright";
|
|
break;
|
|
case "CAPTION_WRITER":
|
|
$current_tag = "caption_writer";
|
|
break;
|
|
case "CATEGORY":
|
|
$current_tag = "category";
|
|
break;
|
|
case "CREDIT":
|
|
$current_tag = "credit";
|
|
break;
|
|
case "SOURCE":
|
|
$current_tag = "source";
|
|
break;
|
|
case "HEADLINE":
|
|
$current_tag = "headline";
|
|
break;
|
|
case "INSTRUCTIONS":
|
|
$current_tag = "instructions";
|
|
break;
|
|
case "TRANSMISSION_REFERENCE":
|
|
$current_tag = "transmission_reference";
|
|
break;
|
|
case "SUPPLEMENTAL_CATEGORY":
|
|
$current_tag = "supplemental_category";
|
|
break;
|
|
case "WEB_STATEMENT":
|
|
$current_tag = "web_statement";
|
|
break;
|
|
case "PURCHASE_URL":
|
|
$current_tag = "purchase_url";
|
|
break;
|
|
case "FILE":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "NAME":
|
|
$image_data['file'][$image_data['num_of_files']]['name'] = $temporary_directory . "/" . $value;
|
|
$image_data['file'][$image_data['num_of_files']]['name_tmp'] = $temporary_directory . "/" . $value;
|
|
$image_data['file'][$image_data['num_of_files']]['type'] = strtolower(substr($value, strrpos($value, ".") + 1));
|
|
break;
|
|
case "REMARK":
|
|
$image_data['file'][$image_data['num_of_files']]['remark'] = $value;
|
|
break;
|
|
case "MASTER":
|
|
$image_data['file'][$image_data['num_of_files']]['master'] = ($value == "yes") ? "t" : "f";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$image_data['num_of_files']++;
|
|
break;
|
|
case "EXPDATE":
|
|
$today = getdate(time());
|
|
$year = $today["year"];
|
|
$month = $today["month"];
|
|
$day = $today["day"];
|
|
$hour = $today["hours"];
|
|
$min = $today["minutes"];
|
|
$sec = $today["seconds"];
|
|
$sqldata = 0;
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "SQLDATA":
|
|
$image_data['date_of_exposure'] = $value;
|
|
$sqldate = 1;
|
|
break;
|
|
case "YEAR":
|
|
$year = $value;
|
|
break;
|
|
case "MONTH":
|
|
$month = $value;
|
|
break;
|
|
case "DAY":
|
|
$day = $value;
|
|
break;
|
|
case "HOURS":
|
|
$hour = $value;
|
|
break;
|
|
case "MINUTES":
|
|
$min = $value;
|
|
break;
|
|
case "SECONDS":
|
|
$min = $value;
|
|
break;
|
|
}
|
|
}
|
|
if (!$sqldate)
|
|
$image_data['date_of_exposure'] = sprintf("%04d-%02d-%02d", $year, $month, $day);
|
|
}
|
|
break;
|
|
case "LOCATION":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['location'] = $value;
|
|
}
|
|
}
|
|
}
|
|
case "GEOLOCATION":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "LATITUDE":
|
|
$image_data['latitude'] = parse_latitude($value);
|
|
break;
|
|
case "LONGITUDE":
|
|
$image_data['longitude'] = parse_latitude($value);
|
|
break;
|
|
case "ALTITUDE":
|
|
$image_data['longitude'] = $value;
|
|
break;
|
|
case "DIRECTION":
|
|
$image_data['direction'] = $value;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "STORAGE":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "TYPE":
|
|
$image_data['storage_location_type'] = $value;
|
|
break;
|
|
case "ID":
|
|
$image_data['storage_location_id'] = $value;
|
|
break;
|
|
case "IDX":
|
|
$image_data['storage_index'] = $value;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "ACCESS":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "TYPE":
|
|
$image_data['access_rights'] = $value;
|
|
break;
|
|
case "ORIGINAL":
|
|
switch ($value) {
|
|
case "t":
|
|
case "owner":
|
|
$image_data['hide_original'] = 't';
|
|
break;
|
|
case 'f':
|
|
case "all":
|
|
$image_data['hide_original'] = 'f';
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "CAMERA":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['camera'] = $value;
|
|
break;
|
|
case "METER":
|
|
switch ($value) {
|
|
case "spot":
|
|
$image_data['camera_metering'] = 1;
|
|
break;
|
|
case "center":
|
|
$image_data['camera_metering'] = 2;
|
|
break;
|
|
case "matrix":
|
|
$image_data['camera_metering'] = 3;
|
|
break;
|
|
case "colormatrix":
|
|
$image_data['camera_metering'] = 4;
|
|
break;
|
|
case "zone":
|
|
$image_data['camera_metering'] = 5;
|
|
}
|
|
break;
|
|
case "PROG":
|
|
switch ($value) {
|
|
case "auto":
|
|
$image_data['camera_program'] = 1;
|
|
break;
|
|
case "aperture":
|
|
$image_data['camera_program'] = 2;
|
|
break;
|
|
case "shutter":
|
|
$image_data['camera_program'] = 3;
|
|
break;
|
|
case "manual":
|
|
$image_data['camera_program'] = 4;
|
|
}
|
|
break;
|
|
case "SPEED":
|
|
$shutter_id = pg_fetch_row(pg_query($database, "select identifier from shutter where value='$value'"));
|
|
if ($shutter_id)
|
|
$image_data['shutter'] = $shutter_id[0];
|
|
break;
|
|
case "COMP":
|
|
$exp_comp_id = pg_fetch_row(pg_query($database, "select identifier from ev_comp where value='$value'"));
|
|
if ($exp_comp_id)
|
|
$image_data['exp_comp'] = $exp_comp_id[0];
|
|
break;
|
|
case "EVDIFF":
|
|
$ev_diff_id = pg_fetch_row(pg_query($database, "select identifier from ev_comp where value='$value'"));
|
|
if ($ev_diff_id)
|
|
$image_data['exp_diff'] = $ev_diff_id[0];
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "LENS":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['equipment'][] = "$value:".PO_EQUIPMENT_LENS;
|
|
break;
|
|
case "FOCAL_LENGTH":
|
|
$image_data['focal_length'] = $value;
|
|
break;
|
|
case "APERTURE":
|
|
$aperture_id = pg_fetch_row(pg_query($database, "select identifier from aperture where value='$value'"));
|
|
if ($aperture_id)
|
|
$image_data['aperture'] = $aperture_id[0];
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "FILTER":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['equipment'][] = "$value:".PO_EQUIPMENT_FILTER;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "FILM":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['film'] = $value;
|
|
break;
|
|
case "ISO_OVERRIDE":
|
|
$image_data['iso_override'] = $value;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "FLASH":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['equipment'][] = "$value:".PO_EQUIPMENT_FLASH;
|
|
break;
|
|
case "MODE":
|
|
switch ($value) {
|
|
case "normal":
|
|
$image_data['flash_mode'] = 1;
|
|
break;
|
|
case "slow":
|
|
$image_data['flash_mode'] = 2;
|
|
break;
|
|
case "rear":
|
|
$image_data['flash_mode'] = 3;
|
|
}
|
|
break;
|
|
case "COMP":
|
|
$flash_comp_id = pg_fetch_row(pg_query($database, "select identifier from ev_comp where value='$value'"));
|
|
if ($flash_comp_id)
|
|
$image_data['flash_comp'] = $flash_comp_id[0];
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "SCANNER":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['equipment'][] = "$value:".PO_EQUIPMENT_SCANNER;
|
|
break;
|
|
case "DPI":
|
|
$dpi_id = pg_fetch_row(pg_query($database, "select identifier from scan_resolution where value='$value'"));
|
|
if ($dpi_id)
|
|
$image_data['scan_resolution'] = $dpi_id[0];
|
|
break;
|
|
case "BITDEPTH":
|
|
$bitdepth_id = pg_fetch_row(pg_query($database, "select identifier from scan_bitdepth where value='$value'"));
|
|
if ($bitdepth_id)
|
|
$image_data['scan_bitdepth'] = $bitdepth_id[0];
|
|
break;
|
|
case "PASSES":
|
|
$multiscan_id = pg_fetch_row(pg_query($database, "select identifier from scan_multiscan where value='$value'"));
|
|
if ($multiscan_id)
|
|
$image_data['scan_multiscan'] = $multiscan_id[0];
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case "SUPPORT":
|
|
if (sizeof($attribs)) {
|
|
while (list($attribute, $value) = each($attribs)) {
|
|
switch ($attribute) {
|
|
case "ID":
|
|
$image_data['equipment'][] = "$value:".PO_EQUIPMENT_SUPPORT;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function XML_CharacterData($parser, $data) {
|
|
global $character_data;
|
|
$character_data = $data;
|
|
}
|
|
|
|
function XML_EndElement($parser, $name) {
|
|
global $image_data;
|
|
global $database;
|
|
global $default_folder_id;
|
|
global $po_user;
|
|
global $character_data;
|
|
global $current_tag;
|
|
|
|
switch ($name) {
|
|
case "PHOTO":
|
|
$count += photo_import_all($database, $image_data);
|
|
$count++;
|
|
$image_data = load_default_image_data_values($default_folder_id);
|
|
break;
|
|
case "TITLE":
|
|
$image_data['title'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "AUTHOR":
|
|
$image_data['author'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "KEYWORD":
|
|
$image_data['keywords'][] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "CAPTION":
|
|
$image_data['caption'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "COPYRIGHT":
|
|
$image_data['copyright'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "CAPTION_WRITER":
|
|
$image_data['caption_writer'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "CATEGORY":
|
|
$image_data['category'] = substr($character_data, 0, 3);
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "CREDIT":
|
|
$image_data['credit'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "SOURCE":
|
|
$image_data['source'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "HEADLINE":
|
|
$image_data['headline'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "INSTRUCTIONS":
|
|
$image_data['instructions'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "TRANSMISSION_REFERENCE":
|
|
$image_data['transmission_reference'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "SUPPLEMENTAL_CATEGORY":
|
|
$image_data['supplemental_category'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "WEB_STATEMENT":
|
|
$image_data['web_statement'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
case "PURCHASE_URL":
|
|
$image_data['purchase_url'] = $character_data;
|
|
$current_tag = "not_implemented";
|
|
$character_data = "";
|
|
break;
|
|
}
|
|
}
|
|
|
|
function XML_EndTestElement($parser, $name) {
|
|
switch ($name) {
|
|
case "PHOTO":
|
|
print ".";
|
|
break;
|
|
}
|
|
}
|
|
|
|
function parse_XML($xml_path) {
|
|
global $strings;
|
|
|
|
if (is_file($xml_path . "/data.xml")) {
|
|
$fp = fopen($xml_path . "/data.xml", "r");
|
|
print $strings['import_validating_xml']. "...";
|
|
|
|
/* first parse the xml file */
|
|
fseek ($fp, 0 ,SEEK_SET);
|
|
$xml_parser = xml_parser_create();
|
|
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, TRUE);
|
|
xml_set_element_handler($xml_parser, "XML_StartElement", "XML_EndTestElement");
|
|
|
|
$data = fread($fp, filesize($xml_path . "/data.xml"));
|
|
if (!xml_parse($xml_parser, $data)) {
|
|
print err_str(sprintf($strings['errors_xml_error'],
|
|
xml_get_error_code($xml_parser),
|
|
xml_error_string(xml_get_error_code($xml_parser)),
|
|
xml_get_current_line_number($xml_parser)));
|
|
xml_parser_free($xml_parser);
|
|
fclose($fp);
|
|
exit;
|
|
}
|
|
|
|
xml_parser_free($xml_parser);
|
|
|
|
/* now do a real upload as described in the xml file */
|
|
fseek ($fp, 0 ,SEEK_SET);
|
|
|
|
$xml_parser = xml_parser_create();
|
|
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, TRUE);
|
|
xml_set_element_handler($xml_parser, "XML_StartElement", "XML_EndElement");
|
|
xml_set_character_data_handler($xml_parser, "XML_CharacterData");
|
|
|
|
while ($data = fread($fp, 4096)) {
|
|
if (!xml_parse($xml_parser, $data, feof($fp))) {
|
|
print err_str(sprintf($strings['errors_xml_error'],
|
|
xml_get_error_code($xml_parser),
|
|
xml_error_string(xml_get_error_code($xml_parser)),
|
|
xml_get_current_line_number($xml_parser)));
|
|
xml_parser_free($xml_parser);
|
|
fclose($fp);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
xml_parser_free($xml_parser);
|
|
|
|
fclose($fp);
|
|
}
|
|
}
|
|
|
|
function upload_directory($database, $upload_path, $user_id, $target_folder, $original_file_type) {
|
|
global $po_options;
|
|
global $strings;
|
|
|
|
parse_XML($upload_path);
|
|
|
|
$num_imported = 0;
|
|
$files = array(); /* Sorted of files in directory */
|
|
$fileroots = array(); /* basename -> array(files) */
|
|
$dirs = array(); /* Directories */
|
|
$xmps = array(); /* For XMP Sidecar files */
|
|
|
|
/* upload the rest of the files which where not described in the xml file */
|
|
if ($handle = opendir($upload_path)) {
|
|
while (false !== ($file_name = readdir($handle))) {
|
|
$files[] = $file_name;
|
|
}
|
|
closedir($handle);
|
|
sort($files);
|
|
|
|
/* Loop over the file list, filter stuff into appropriate lists. */
|
|
foreach($files as $file_name) {
|
|
if ($file_name == "." || $file_name == "..") continue;
|
|
if (is_link($upload_path ."/".$file_name)) continue;
|
|
if (is_dir($upload_path . "/" . $file_name)) {
|
|
$dirs[] = $file_name;
|
|
continue;
|
|
}
|
|
|
|
$file_name_root = substr($file_name, 0, strrpos($file_name, "."));
|
|
if (!$file_name_root) $file_name_root = $file_name;
|
|
$file_name_root = strtolower($file_name_root);
|
|
$file_type = strtolower(substr($file_name, strrpos($file_name, ".") + 1));
|
|
if ($file_type == 'xmp') {
|
|
$xmps[$file_name_root] = $upload_path . '/' . $file_name;
|
|
continue;
|
|
}
|
|
if ($file_type == "xml" || $file_type == "gz" ||
|
|
$file_type == "tgz" || $file_type == "zip" ||
|
|
$file_type == "bz2" || $file_type == "tar" ||
|
|
$file_type == "bzip2" || $file_type == "7z" ||
|
|
$file_type == "xz" || $file_type == "txz" ||
|
|
preg_match("/thumbs.db/i", $file_name)) {
|
|
unlink($upload_path. "/" . $file_name);
|
|
continue;
|
|
}
|
|
|
|
$fileroots[$file_name_root][] = $file_name;
|
|
}
|
|
|
|
/* re-sort the list of image files we care about */
|
|
$files = array();
|
|
foreach($fileroots as $root => $data) {
|
|
$files[] = $root;
|
|
}
|
|
|
|
/* Deal with subdirs in the import */
|
|
foreach($dirs as $dir) {
|
|
/* Look for an existing folder which matches the directory name */
|
|
$data = pg_fetch_row(pg_query($database, "select identifier from folder where parent_folder = $target_folder and caption = '" .pg_escape_string($database, $dir) ."'"));
|
|
if ($data == null) {
|
|
print sprintf($strings['import_creating_subfolder'], $dir) . " ... ";
|
|
$result = add_folder($database, $user_id, $target_folder, $_REQUEST['access_rights'], $dir, "", "", "null", $po_options['order_by']);
|
|
if (!$result) {
|
|
$new_folder = $target_folder;
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
} else {
|
|
/* Figure out new folder ID */
|
|
$data = pg_fetch_row(pg_query($database, "select identifier from folder where parent_folder = $target_folder and caption = '" .pg_escape_string($database, $dir) ."'"));
|
|
$new_folder = $data[0];
|
|
}
|
|
print "<br/>";
|
|
} else {
|
|
$new_folder = $data[0];
|
|
}
|
|
$num_imported += upload_directory($database, $upload_path . "/" . $dir, $user_id, $new_folder, $original_file_type);
|
|
}
|
|
|
|
/* Import the the individual files */
|
|
foreach ($files as $file) {
|
|
$data = $fileroots[$file];
|
|
$index = 0;
|
|
$image_data = load_default_image_data_values($target_folder);
|
|
if (isset($xmps[$file_name_root])) {
|
|
$image_data['sidecar'] = $xmps[$file_name_root];
|
|
}
|
|
/* Build the import structure */
|
|
foreach($data as $file_name) {
|
|
$file_name_root = substr($file_name, 0, strrpos($file_name, "."));
|
|
if (!$file_name_root) $file_name_root = $file_name;
|
|
$file_name_root = strtolower($file_name_root);
|
|
$last_name_root = $file_name_root;
|
|
$file_type = strtolower(substr($file_name, strrpos($file_name, ".") + 1));
|
|
|
|
$image_data['file'][$index]['name'] = $upload_path . "/" . $file_name;
|
|
$image_data['file'][$index]['name_tmp'] = $upload_path . "/" . $file_name;
|
|
$image_data['file'][$index]['type'] = $file_type;
|
|
$image_data['file'][$index]['remark'] = "";
|
|
$image_data['num_of_files']++;
|
|
$index++;
|
|
}
|
|
|
|
/* And finally kick off the import of the master + versions */
|
|
$num_imported += photo_import_all($database, $image_data);
|
|
}
|
|
}
|
|
|
|
return $num_imported;
|
|
}
|
|
|
|
/* ================================== */
|
|
|
|
site_header($strings['import_import_photos']);
|
|
site_navigator(5);
|
|
$path_to_folder = get_path_to_folder($database, $default_folder_id);
|
|
$folder_name = pg_fetch_row(pg_query($database, "select caption from folder where identifier='$default_folder_id'"));
|
|
|
|
$user_display_string = disp_user_string($database, $po_user['id']);
|
|
|
|
site_navigator_status("$user_display_string $path_to_folder: ".$strings['import_import_photos'],
|
|
"");
|
|
|
|
print "<div class=\"content\">\n";
|
|
|
|
$temporary_directory = FALSE;
|
|
switch ($original_file_type) {
|
|
case "xmp":
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
break;
|
|
case "local":
|
|
$temporary_directory = $po_options['local_bulk_upload_path'];
|
|
print sprintf($strings['import_importing_from_folder'], $temporary_directory) ." ... <br/> ";
|
|
break;
|
|
case "gz":
|
|
case "tgz":
|
|
case "bz2":
|
|
case "bzip2":
|
|
case "xz":
|
|
case "txz":
|
|
case "tar":
|
|
case "7z":
|
|
case "zip":
|
|
/* check if bulk upload is enabled for this user */
|
|
if ($po_options['bulk_upload_enable'] != 't') {
|
|
print err_str($strings['errors_bulk_upload_disabled']);
|
|
break;
|
|
}
|
|
/* in case the file type is zip, uncompress it and process the bulk upload */
|
|
$temporary_directory = tempnam($tmp_volume_path, "po.import.");
|
|
unlink($temporary_directory);
|
|
print sprintf($strings['import_creating_temp_dir']) . " ... ";
|
|
umask(0077);
|
|
if (!mkdir($temporary_directory, 0700)) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>mkdir $temporary_directory]</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
|
|
print $strings['import_moving_file_to_tmp'] . " ... ";
|
|
if (!move_uploaded_file($file_name_tmp, $temporary_directory . "/" . $file_name)) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>mv $file_name_tmp $temporary_directory/$file_name</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
|
|
print $strings['import_uncompress'] . " $file_name ... ";
|
|
|
|
switch ($original_file_type) {
|
|
case "gz":
|
|
case "tgz":
|
|
$cmdline = "$sys_tar -x -z -C " .
|
|
escapeshellarg($temporary_directory) ." -f" .
|
|
escapeshellarg($temporary_directory ."/" . $file_name);
|
|
system($cmdline, $retval);
|
|
if ($retval) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>$cmdline</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
break;
|
|
case "bzip2":
|
|
case "bz2":
|
|
$cmdline = "$sys_tar -x -j -C " .
|
|
escapeshellarg($temporary_directory) ." -f" .
|
|
escapeshellarg($temporary_directory ."/" . $file_name);
|
|
system($cmdline, $retval);
|
|
if ($retval) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>$cmdline</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
break;
|
|
case "txz":
|
|
case "xz":
|
|
$cmdline = "$sys_tar -x -J -C " .
|
|
escapeshellarg($temporary_directory) ." -f" .
|
|
escapeshellarg($temporary_directory ."/" . $file_name);
|
|
system($cmdline, $retval);
|
|
if ($retval) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>$cmdline</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
break;
|
|
case "tar":
|
|
$cmdline = "$sys_tar -x -C " .
|
|
escapeshellarg($temporary_directory) ." -f" .
|
|
escapeshellarg($temporary_directory ."/" . $file_name);
|
|
system($cmdline, $retval);
|
|
if ($retval) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>$cmdline</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
break;
|
|
case "zip":
|
|
system("$sys_unzip -q ".
|
|
escapeshellarg($temporary_directory. "/". $file_name) ." -d".
|
|
escapeshellarg($temporary_directory), $retval);
|
|
if ($retval) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>$sys_unzip $temporary_directory/$file_name -d temporary_directory</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
break;
|
|
case "7z":
|
|
$cmdline = "$sys_7za x -bd ".
|
|
escapeshellarg("-o".$temporary_directory) . " " .
|
|
escapeshellarg($temporary_directory. "/". $file_name);
|
|
system($cmdline, $retval);
|
|
|
|
if ($retval) {
|
|
print "<font color=\"red\">".$strings['generic_failed']."</font>";
|
|
print "<pre>$cmdline</pre><br/>";
|
|
} else {
|
|
print $strings['generic_done'].".<br/>";
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
$index = 0;
|
|
$image_data = load_default_image_data_values($default_folder_id);
|
|
$tempnam = tempnam($tmp_volume_path, "po.import.");
|
|
move_uploaded_file($file_name_tmp, $tempnam);
|
|
$image_data['file'][$index]['name'] = $file_name;
|
|
$image_data['file'][$index]['name_tmp'] = $tempnam;
|
|
$image_data['file'][$index]['type'] = $original_file_type;
|
|
$image_data['file'][$index]['remark'] = "";
|
|
$image_data['num_of_files']++;
|
|
$count += photo_import_all($database, $image_data);
|
|
}
|
|
|
|
if ($temporary_directory) {
|
|
$count += upload_directory($database, $temporary_directory, $po_user['id'], $default_folder_id, $original_file_type);
|
|
}
|
|
|
|
print "<p>$count ".$strings['import_all_queued']."</p>";
|
|
|
|
if (!$external_workers) {
|
|
photo_import_worker($database, $po_user['id'], FALSE);
|
|
print "<p>".$strings['import_all_complete']."</p>";
|
|
}
|
|
|
|
print "</div>\n";
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
|
|
?>
|