/** * Read from a file * * @deprecated Use img.io.MetaDataReader instead * @param io.File file * @param var default default void what should be returned in case no data is found * @return img.util.IptcData * @throws lang.FormatException in case malformed meta data is encountered * @throws lang.ElementNotFoundException in case no meta data is available * @throws img.ImagingException in case reading meta data fails */ public static function fromFile(File $file) { if (FALSE === getimagesize($file->getURI(), $info)) { $e = new ImagingException('Cannot read image information from ' . $file->getURI()); xp::gc(__FILE__); throw $e; } if (!isset($info['APP13'])) { if (func_num_args() > 1) { return func_get_arg(1); } throw new ElementNotFoundException('Cannot get IPTC information from ' . $file->getURI() . ' (no APP13 marker)'); } if (!($iptc = iptcparse($info['APP13']))) { throw new FormatException('Cannot parse IPTC information from ' . $file->getURI()); } // Parse creation date if (3 == sscanf(@$iptc['2#055'][0], '%4d%2d%d', $year, $month, $day)) { $created = Date::create($year, $month, $day, 0, 0, 0); } else { $created = NULL; } with($i = new self()); $i->setTitle(@$iptc['2#005'][0]); $i->setUrgency(@$iptc['2#010'][0]); $i->setCategory(@$iptc['2#015'][0]); $i->setSupplementalCategories(@$iptc['2#020']); $i->setKeywords(@$iptc['2#025']); $i->setSpecialInstructions(@$iptc['2#040'][0]); $i->setDateCreated($created); $i->setAuthor(@$iptc['2#080'][0]); $i->setAuthorPosition(@$iptc['2#085'][0]); $i->setCity(@$iptc['2#090'][0]); $i->setState(@$iptc['2#095'][0]); $i->setCountry(@$iptc['2#101'][0]); $i->setOriginalTransmissionReference(@$iptc['2#103'][0]); $i->setHeadline(@$iptc['2#105'][0]); $i->setCredit(@$iptc['2#110'][0]); $i->setSource(@$iptc['2#115'][0]); $i->setCopyrightNotice(@$iptc['2#116'][0]); $i->setCaption(@$iptc['2#120'][0]); $i->setWriter(@$iptc['2#122'][0]); return $i; }
/** * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement $xmlElement) * @return CultureFeed_Cdb_Item_Page */ public static function parseFromCdbXml(SimpleXMLElement $xmlElement) { if (empty($xmlElement->uid)) { throw new CultureFeed_Cdb_ParseException('Uid missing for page element'); } if (empty($xmlElement->name)) { throw new CultureFeed_Cdb_ParseException('Name missing for page element'); } $page = new self(); // Set ID + name. $page->setId((string) $xmlElement->uid); $page->setName((string) $xmlElement->name); $page->setOfficialPage(filter_var((string) $xmlElement->officialPage, FILTER_VALIDATE_BOOLEAN)); // Set categories $categories = array(); if (!empty($xmlElement->categoryIds->categoryId)) { foreach ($xmlElement->categoryIds->categoryId as $category) { $categories[] = (string) $category; } } $page->setCategories($categories); // Set keywords $keywords = array(); if (!empty($xmlElement->keywords->keyword)) { foreach ($xmlElement->keywords->keyword as $keyword) { $keywords[] = (string) $keyword; } } $page->setKeywords($keywords); // Set description. if (!empty($xmlElement->description)) { $page->setDescription((string) $xmlElement->description); } // Set the image. if (!empty($xmlElement->image)) { $page->setImage((string) $xmlElement->image); } // Set the cover. if (!empty($xmlElement->cover)) { $page->setCover((string) $xmlElement->cover); } // Set the visibility. if (!empty($xmlElement->visible)) { $page->setVisibility((string) $xmlElement->visible); } // Set address. $address = new CultureFeed_Cdb_Data_Address_PhysicalAddress(); $addressElement = $xmlElement->address; $has_address = FALSE; if (!empty($addressElement->city)) { $address->setCity((string) $addressElement->city); $has_address = TRUE; } if (!empty($addressElement->street)) { $address->setStreet((string) $addressElement->street); $has_address = TRUE; } if (!empty($addressElement->zip)) { $address->setZip((string) $addressElement->zip); $has_address = TRUE; } if (!empty($addressElement->country)) { $address->setCountry((string) $addressElement->country); $has_address = TRUE; } if (!empty($addressElement->lat) && !empty($addressElement->lon)) { $coordinates = $addressElement->lat . '-' . $addressElement->lon; if ($coordinates != '0.0-0.0') { $address->setGeoInformation(new CultureFeed_Cdb_Data_Address_GeoInformation((string) $addressElement->lon, (string) $addressElement->lat)); $has_address = TRUE; } } if ($has_address) { $page->setAddress($address); } // Set contact info. if (!empty($xmlElement->contactInfo->email)) { $page->setEmail((string) $xmlElement->contactInfo->email); } if (!empty($xmlElement->contactInfo->telephone)) { $page->setTelephone((string) $xmlElement->contactInfo->telephone); } // Set links. $links = array(); if (!empty($xmlElement->links)) { foreach ($xmlElement->links->children() as $link) { $url = (string) $link; if (empty($url)) { continue; } // Make sure http is in front of the url. if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { $url = 'http://' . $url; } $links[$link->getName()] = $url; } } $page->setLinks($links); // Set the permissions. $page->setPermissions(CultureFeed_Cdb_Data_PagePermissions::parseFromCdbXml($xmlElement->permissions)); // Set tagline. $page->setTagline((string) $xmlElement->tagline); return $page; }