/**
  * performs the service processing
  *
  * @param	string 	Content which should be processed.
  * @param	string 	Content type
  * @param	array 	Configuration array
  * @return	boolean
  */
 function process($content = '', $type = '', $conf = array())
 {
     $this->conf = $conf;
     $this->out = array();
     $this->out['fields'] = array();
     $this->exif = array();
     if ($content) {
         $this->setInput($content, $type);
     }
     if ($inputFile = $this->getInputFile()) {
         // Parameter: filename (string),sections(string),arrays(bool),thumbnail(bool)
         $exifdata = @exif_read_data($inputFile, '', TRUE, FALSE);
         $exif = $exifdata['EXIF'];
         $exif = is_array($exif) ? $exif : array();
         if (is_array($exifdata['COMMENT'])) {
             $exif['fields']['description'] = tx_svmetaextract_lib::forceUtf8(implode("\n", $exifdata['COMMENT']));
         }
         if (is_array($exifdata['IFD0'])) {
             $exif = array_merge($exifdata['IFD0'], $exif);
         }
         foreach ($exif as $name => $value) {
             if (!is_array($value)) {
                 if (trim($value)) {
                     // ignore empty lines headers and empty entries
                     $name = str_replace('-', '', $name);
                     // add to exif table
                     $this->exif[$name] = $value;
                     // add to DAM table
                     switch ($name) {
                         case 'ImageCreated':
                         case 'DateTimeOriginal':
                             $parsedDate = tx_svmetaextract_lib::parseDate($value);
                             $this->out['fields']['date_cr'] = $parsedDate;
                             $this->out['fields']['date_mod'] = $parsedDate;
                             $this->out['fields']['file_ctime'] = $parsedDate;
                             $this->out['fields']['file_mtime'] = $parsedDate;
                             break;
                         case 'HorizontalResolution':
                             $this->out['fields']['hres'] = intval($value);
                             break;
                         case 'VerticalResolution':
                             $this->out['fields']['vres'] = intval($value);
                             break;
                             // I removed this because the built-in 'identify' will recognize 'RGB' and sRGB is a color profile
                             //						case 'ColorSpace':
                             //						case 'ColorSpaceInformation':
                             //							if (!$this->out['fields']['color_space']) {
                             //								$this->out['fields']['color_space'] = ($value==1)?'sRGB':$value;
                             //							}
                             break;
                         case 'Copyright':
                             $this->out['fields']['copyright'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'Artist':
                             $this->out['fields']['creator'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'Software':
                         case 'CameraModel':
                         case 'Model':
                             $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'Title':
                             $this->out['fields']['title'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'ImageDescription':
                             $this->out['fields']['description'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                     }
                 }
             }
         }
         $this->out['fields']['meta']['exif'] = $this->exif;
     } else {
         $this->errorPush(T3_ERR_SV_NO_INPUT, 'No or empty input.');
     }
     return $this->getLastError();
 }
 /**
  * Extracts PDF metadata using 'pdfinfo'
  * performs the service processing
  *
  * @param	string 	Content which should be processed.
  * @param	string 	Content type
  * @param	array 	Configuration array
  * @return	boolean
  */
 function process($content = '', $type = '', $conf = array())
 {
     $this->out = array();
     if ($content) {
         $this->setInput($content, $type);
     }
     if ($inputFile = $this->getInputFile()) {
         $cmd = t3lib_exec::getCommand($this->info['exec']) . '  "' . $inputFile . '"';
         $pdfmeta = '';
         $ret = '';
         exec($cmd, $pdfmeta, $ret);
         if (!$ret and is_array($pdfmeta)) {
             foreach ($pdfmeta as $line) {
                 // Only request 2 elements because pdfinfo output might contain colons in $value
                 list($name, $value) = explode(':', $line, 2);
                 $name = trim($name);
                 $value = trim($value);
                 if ($value) {
                     // ignore empty lines headers and empty entries
                     switch ($name) {
                         case 'Author':
                             $this->out['fields']['creator'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'Producer':
                             $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'Title':
                             $this->out['fields']['title'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'Subject':
                             $this->out['fields']['description'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'Keywords':
                             $this->out['fields']['keywords'] = tx_svmetaextract_lib::forceUtf8($value);
                             break;
                         case 'CreationDate':
                             $this->out['fields']['date_cr'] = tx_svmetaextract_lib::parseDate($value);
                             $this->out['fields']['file_ctime'] = tx_svmetaextract_lib::parseDate($value);
                             break;
                         case 'ModDate':
                             $this->out['fields']['date_mod'] = tx_svmetaextract_lib::parseDate($value);
                             $this->out['fields']['file_mtime'] = tx_svmetaextract_lib::parseDate($value);
                             break;
                         case 'Pages':
                         case 'PageCount':
                             $this->out['fields']['pages'] = intval($value);
                             break;
                         case 'Page Size':
                         case 'Page size':
                             // 595 x 842 pts (A4)
                             $v = explode(' ', $value);
                             $unitFrom = $v[3];
                             // TODO: create TCA to let user choose imperial/metric unit
                             $unitTo = 'cm';
                             $this->out['fields']['width'] = (double) tx_svmetaextract_lib::convertUnit($v[0], $unitFrom, $unitTo);
                             $this->out['fields']['height'] = (double) tx_svmetaextract_lib::convertUnit($v[2], $unitFrom, $unitTo);
                             $this->out['fields']['width_unit'] = $unitTo;
                             $this->out['fields']['height_unit'] = $unitTo;
                             break;
                         case 'PDF version':
                             $this->out['fields']['file_type_version'] = $value;
                             break;
                     }
                 }
             }
         }
     } else {
         $this->errorPush(T3_ERR_SV_NO_INPUT, 'No or empty input.');
     }
     return $this->getLastError();
 }
 /**
  * performs the service processing
  *
  * @param	string 	Content which should be processed.
  * @param	string 	Content type
  * @param	array 	Configuration array
  * @return	boolean
  */
 function process($content = '', $type = '', $conf = array())
 {
     $this->conf = $conf;
     $this->out = array();
     $this->out['fields'] = array();
     $this->iptc = array();
     if ($content) {
         $this->setInput($content, $type);
     }
     if ($inputFile = $this->getInputFile()) {
         $info = array();
         $size = getimagesize($inputFile, $info);
         if (isset($info['APP13'])) {
             $iptc = iptcparse($info['APP13']);
             if (is_array($iptc)) {
                 foreach ($iptc as $key => $val) {
                     foreach ($val as $k => $v) {
                         if (!trim($v)) {
                             continue;
                         }
                         // clean up
                         $v = trim($v);
                         $v = str_replace(chr(0x0), ' ', $v);
                         $v = str_replace(chr(213), "'", $v);
                         switch ($key) {
                             case '2#105':
                                 // headline
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['title'] = $v;
                                 $this->iptc['headline'] = $v;
                                 break;
                             case '2#005':
                                 // object name - Kurztitel, Objektname, Dokumententitel, Object Name, Objektname
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['ident'] = $v;
                                 $this->iptc['object_name'] = $v;
                                 break;
                             case '2#120':
                                 // caption - Beschreibung des Objektinhaltes, Beschreibung, Objektbeschreibung, Beschreibung, Caption, Objektbeschreibung
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['title'] = $v;
                                 $this->iptc['caption'] = $v;
                                 break;
                             case '2#025':
                                 // keyword - Liste von Schlüsselwörtern, Suchbegriffe, Stichwörter
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['keywords'][] = $v;
                                 break;
                                 // ---- Copyright
                             // ---- Copyright
                             case '2#040':
                                 // special instructions - Hinweise zur Benutzung, Hinweis, Besondere Hinweise, Anweisung
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['instructions'] = $v;
                                 $this->iptc['special_instructions'] = $v;
                                 break;
                             case '2#116':
                                 // copyright notice - Angaben zum Copyright, Copyright-Info, Copyright-Vermerk,Copyright-Informationen
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['copyright'] = $v;
                                 $this->iptc['copyright_notice'] = $v;
                                 break;
                             case '2#110':
                                 // credit
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['credit'] = $v;
                                 break;
                             case '2#115':
                                 // Source - Inhaber der Rechte. Kann eine Agentur, ein Agenturmitglied oder ein Individuum sein, Quelle
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['publisher'] = $v;
                                 $this->iptc['source'] = $v;
                                 break;
                             case '2#080':
                                 // byline - Liste von Namen der Autoren, Photografen oder Grafiker, Fotograf, Name des Autors
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['creator'] = $v;
                                 $this->iptc['byline'] = $v;
                                 break;
                             case '2#085':
                                 // byline title
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['byline_title'] = $v;
                                 break;
                                 // ---- Location
                             // ---- Location
                             case '2#100':
                                 // country code
                                 $this->out['fields']['loc_country'] = strtoupper($v);
                                 // ISO 3 ?!
                                 $this->iptc['country_code'] = $v;
                                 break;
                             case '2#101':
                                 // country
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['country'] = $v;
                                 break;
                             case '2#090':
                                 // city
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['loc_city'] = $v;
                                 $this->iptc['city'] = $v;
                                 break;
                             case '2#095':
                                 // state
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['state'] = $v;
                                 break;
                             case '2#092':
                                 // Sublocation - Stadt/Ort an dem das Objekt entstanden ist, Stelle/Flecken
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->out['fields']['loc_desc'] = $v;
                                 $this->iptc['sublocation'] = $v;
                                 break;
                                 // ---- div
                             // ---- div
                             case '2#055':
                                 // date created - Datum, Erstellt am, Erstellungsdatum
                                 $this->out['fields']['date_cr'] = tx_svmetaextract_lib::parseDate($v);
                                 $this->iptc['date_created'] = $v;
                                 break;
                                 // ----
                             // ----
                             case '2#000':
                                 // rubbish ??
                                 break;
                             case '2#022':
                                 // Fixture Identifier - ???
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['fixture'] = $v;
                                 break;
                             case '2#122':
                                 // caption writer
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['caption_writer'] = $v;
                                 break;
                             case '2#012':
                                 // Subject Reference  - Liste mit Definitionsstrukturen von Themen in der Form IPR:Referenznummer:Name:ThemenName:DetailName
                                 $v = tx_svmetaextract_lib::forceUtf8($v);
                                 $this->iptc['subject_reference'][] = $v;
                                 break;
                             case '2#015':
                                 // category
                                 $this->iptc['category'][] = $v;
                                 break;
                             case '2#020':
                                 // supplemental category
                                 $this->iptc['supplemental_category'][] = $v;
                                 break;
                             default:
                                 //$v = tx_svmetaextract_lib::forceUtf8($v);
                                 //$this->iptc['iptc_'.$key] = $v;
                                 break;
                         }
                     }
                 }
             }
         }
         $this->postProcess();
         $this->out['fields']['meta']['IPTC'] = $this->iptc;
     } else {
         $this->errorPush(T3_ERR_SV_NO_INPUT, 'No or empty input.');
     }
     return $this->getLastError();
 }
 /**
  * performs the service processing
  *
  * @param	string		Content which should be processed.
  * @param	string		Content type
  * @param	array		Configuration array
  * @return	boolean
  */
 function process($content = '', $type = '', $conf = array())
 {
     $this->conf = $conf;
     $this->out = array();
     if ($content) {
         $this->setInput($content, $type);
     }
     if ($inputFile = $this->getInputFile() and $jpeg_header_data = get_jpeg_header_data($inputFile)) {
         $this->xmpRaw = get_XMP_text($jpeg_header_data);
         preg_match('#<x:xmpmeta[^>]*>.*</x:xmpmeta>#is', $this->xmpRaw, $match);
         $this->xmpRaw = $match[0];
         $this->xmp = parseXMP2simpleArray(read_XMP_array_from_text($this->xmpRaw));
         foreach ($this->xmp as $key => $value) {
             // ignore empty lines headers and emtpy entries
             if ($value) {
                 switch (strtolower($key)) {
                     case 'dc:creator':
                         $this->out['fields']['creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:description':
                         $this->out['fields']['description'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:rights':
                         $this->out['fields']['copyright'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:subject':
                         $this->out['fields']['keywords'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:title':
                         $this->out['fields']['title'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'iptc4xmpcore:countrycode':
                         if (strlen($value) == 2) {
                             $select = 'cn_iso_3';
                             $table = 'static_countries';
                             $where = tx_staticinfotables_div::getIsoCodeField($table, $value) . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($value), 'static_countries');
                             $where .= t3lib_BEfunc::deleteClause($table);
                             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where);
                             if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                 $this->out['fields']['loc_country'] = $row['cn_iso_3'];
                             }
                         }
                         break;
                     case 'iptc4xmpcore:location':
                         $value = trim($value);
                         if ($value[0] == '/' or $value[0] == '\\') {
                             $this->out['fields']['file_orig_location'] = tx_svmetaextract_lib::forceUtf8($value);
                         } else {
                             $this->out['fields']['loc_desc'] = tx_svmetaextract_lib::forceUtf8($value);
                         }
                         break;
                     case 'xmp:createdate':
                         $this->out['fields']['date_cr'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xmp:creatortool':
                         $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xmp:modifydate':
                         $this->out['fields']['date_mod'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xap:createdate':
                         $this->out['fields']['date_cr'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xap:creatortool':
                         $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xap:modifydate':
                         $this->out['fields']['date_mod'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xaprights:copyright':
                         $this->out['fields']['copyright'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xaprights:usageterms':
                         $this->out['fields']['instructions'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xmptpg:npages':
                         $this->out['fields']['pages'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'pdf:keywords':
                         $this->out['fields']['keywords'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'pdf:producer':
                         $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:captionwriter':
                         $this->out['fields']['photoshop:captionwriter'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:city':
                         $this->out['fields']['loc_city'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:credit':
                         $this->out['fields']['copyright'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:headline':
                         $this->out['fields']['title'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:instructions':
                         $this->out['fields']['instructions'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                 }
             }
         }
         $this->out['fields']['meta']['xmp'] = $this->xmp;
         $this->out['fields']['meta']['xmp_xml'] = $this->xmpRaw;
     } else {
         $this->errorPush(T3_ERR_SV_NO_INPUT, 'No or empty input.');
     }
     return $this->getLastError();
 }