From 77fd1f51a3c5f5a52f72ef8a299fe368228e2285 Mon Sep 17 00:00:00 2001 From: vdigital Date: Fri, 23 May 2008 21:05:41 +0000 Subject: git-svn-id: http://piwigo.org/svn/trunk@2357 68402e56-0260-453c-a942-63ccdbb3a9ee --- BSF/admin/site_reader_remote.php | 250 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 BSF/admin/site_reader_remote.php (limited to 'BSF/admin/site_reader_remote.php') diff --git a/BSF/admin/site_reader_remote.php b/BSF/admin/site_reader_remote.php new file mode 100644 index 000000000..31ae3e792 --- /dev/null +++ b/BSF/admin/site_reader_remote.php @@ -0,0 +1,250 @@ +site_url = $url; + $this->insert_attributes = array( + 'tn_ext', + ); + $this->update_attributes = array( + 'tn_ext', 'representative_ext', 'has_high', + ); + $this->metadata_attributes = array( + 'filesize', 'width', 'height', 'high_filesize' + ); + + if (!isset($listing_url)) + { + $this->listing_url = $this->site_url.'/listing.xml'; + } + else + { + $this->listing_url = $listing_url; + } +} + +/** + * Is this remote site ok ? + * + * @return true on success, false otherwise + */ +function open() +{ + global $errors; + + if (@fopen($this->listing_url, 'r')) + { + $this->site_dirs = array(); + $this->site_files = array(); + $xml_content = getXmlCode($this->listing_url); + $info_xml_element = getChild($xml_content, 'informations'); + if (getAttribute($info_xml_element , 'phpwg_version') != PHPWG_VERSION) + { + array_push( + $errors, + array( + 'path' => $this->listing_url, + 'type' => 'PWG-ERROR-VERSION' + ) + ); + + return false; + } + + $additional_metadata = getAttribute($info_xml_element, 'metadata'); + + if ($additional_metadata != '') + { + $this->metadata_attributes = array_merge( + $this->metadata_attributes, + explode(',', $additional_metadata) + ); + } + + $this->build_structure($xml_content, '', 0); + + return true; + } + else + { + array_push( + $errors, + array( + 'path' => $this->listing_url, + '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 +// files update/synchronization +function get_update_attributes() +{ + return $this->update_attributes; +} + +function get_element_update_attributes($file) +{ + return $this->get_element_attributes( + $file, + $this->update_attributes + ); +} + +// returns the name of the attributes that are supported for +// metadata update/synchronization according to listing.xml +function get_metadata_attributes() +{ + return $this->metadata_attributes; +} + +// returns a hash of attributes (metadata+width,...) for file +function get_element_metadata($file, $has_high = false) +{ + return $this->get_element_attributes( + $file, + $this->metadata_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); + } + } +} + +} + +?> -- cgit v1.2.3