Exemplo n.º 1
0
 /**
  * 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(\io\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 \lang\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;
 }
Exemplo n.º 2
0
 /**
  * Cast a given value
  *
  * @see     xp://scriptlet.xml.workflow.casters.ParamCaster
  * @param   array value
  * @return  array value
  */
 public function castValue($value)
 {
     $return = [];
     foreach ($value as $k => $v) {
         if ('' === $v) {
             return 'empty';
         }
         $pv = call_user_func(self::$parse, $v);
         if (!is_int($pv['year']) || !is_int($pv['month']) || !is_int($pv['day']) || 0 < $pv['warning_count'] || 0 < $pv['error_count']) {
             return 'invalid';
         }
         try {
             $date = Date::create($pv['year'], $pv['month'], $pv['day'], $pv['hour'], $pv['minute'], $pv['second']);
         } catch (\lang\IllegalArgumentException $e) {
             return $e->getMessage();
         }
         $return[$k] = $date;
     }
     return $return;
 }
Exemplo n.º 3
0
 /**
  * Convert days and seconds since 01.01.1900 to a date
  *
  * @param   int days
  * @param   int seconds
  * @return  string
  */
 protected function toDate($days, $seconds)
 {
     return Date::create(1900, 1, 1 + $days, 0, 0, $seconds / 300);
 }
Exemplo n.º 4
0
 public function dateCreateWithInvalidArgumentsExceptTimeZone()
 {
     Date::create('', '', '', '', '', '', new TimeZone('UTC'));
 }
 public function testSetTimezone()
 {
     $this->assertEquals(\util\Date::create(2000, 1, 1, 17, 15, 11, new TimeZone('GMT')), DateUtil::setTimeZone($this->fixture, new TimeZone('America/New_York')));
 }
Exemplo n.º 6
0
 /**
  * Get last modified date. Uses the "MDTM" command internally.
  *
  * @return  util.Date or NULL if the server does not support this
  * @throws  io.IOException in case the connection is closed
  */
 public function lastModified()
 {
     $r = $this->connection->sendCommand('MDTM %s', $this->name);
     sscanf($r[0], "%d %[^\r\n]", $code, $message);
     if (213 === $code) {
         sscanf($message, '%4d%02d%02d%02d%02d%02d', $y, $m, $d, $h, $i, $s);
         // YYYYMMDDhhmmss
         return Date::create($y, $m, $d, $h, $i, $s);
     } else {
         if (550 === $code) {
             return null;
         } else {
             throw new \peer\ProtocolException('MDTM: Unexpected response ' . $code . ': ' . $message);
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Returns an IptcData instance or NULL if this image does not contain 
  * IPTC Data
  * 
  * @return img.util.IptcData
  */
 public function iptcData()
 {
     if (!($seg = $this->segmentsOf('img.io.IptcSegment'))) {
         return null;
     }
     with($data = new IptcData(), $iptc = $seg[0]->rawData());
     // Parse creation date
     if (3 == sscanf(@$iptc['2#055'][0], '%4d%2d%d', $year, $month, $day)) {
         $created = \util\Date::create($year, $month, $day, 0, 0, 0);
     } else {
         $created = null;
     }
     $data->setTitle(@$iptc['2#005'][0]);
     $data->setUrgency(@$iptc['2#010'][0]);
     $data->setCategory(@$iptc['2#015'][0]);
     $data->setSupplementalCategories(@$iptc['2#020']);
     $data->setKeywords(@$iptc['2#025']);
     $data->setSpecialInstructions(@$iptc['2#040'][0]);
     $data->setDateCreated($created);
     $data->setAuthor(@$iptc['2#080'][0]);
     $data->setAuthorPosition(@$iptc['2#085'][0]);
     $data->setCity(@$iptc['2#090'][0]);
     $data->setState(@$iptc['2#095'][0]);
     $data->setCountry(@$iptc['2#101'][0]);
     $data->setOriginalTransmissionReference(@$iptc['2#103'][0]);
     $data->setHeadline(@$iptc['2#105'][0]);
     $data->setCredit(@$iptc['2#110'][0]);
     $data->setSource(@$iptc['2#115'][0]);
     $data->setCopyrightNotice(@$iptc['2#116'][0]);
     $data->setCaption(@$iptc['2#120'][0]);
     $data->setWriter(@$iptc['2#122'][0]);
     return $data;
 }
 /**
  * Creates a date from DOS date and time
  *
  * @see     http://www.vsft.com/hal/dostime.htm
  * @param   int date
  * @param   int time
  * @return  util.Date
  */
 protected function dateFromDosDateTime($date, $time)
 {
     return Date::create(($date >> 9 & 0x7f) + 1980, $date >> 5 & 0xf, $date & 0x1f, $time >> 11 & 0x1f, $time >> 5 & 0x3f, $time << 1 & 0x1e);
 }
Exemplo n.º 9
0
 /**
  * Parses an input string
  *
  * @param   string in
  * @return  util.Date
  */
 public function parse($in)
 {
     $o = 0;
     $m = $tz = $go = null;
     $il = strlen($in);
     $parsed = ['year' => 0, 'month' => 0, 'day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0];
     foreach ($this->format as $token) {
         switch ($token) {
             case '%Y':
                 $parsed['year'] = $this->parseNumber($in, 4, $o);
                 $o += 4;
                 break;
             case '%m':
                 $parsed['month'] = $this->parseNumber($in, 2, $o);
                 $o += 2;
                 break;
             case '%d':
                 $parsed['day'] = $this->parseNumber($in, 2, $o);
                 $o += 2;
                 break;
             case '%H':
                 $parsed['hour'] = $this->parseNumber($in, 2, $o);
                 $o += 2;
                 break;
             case '%M':
                 $parsed['minute'] = $this->parseNumber($in, 2, $o);
                 $o += 2;
                 break;
             case '%S':
                 $parsed['second'] = $this->parseNumber($in, 2, $o);
                 $o += 2;
                 break;
             case '%p':
                 $m = substr($in, $o, 2);
                 $o += 2;
                 break;
             case '%I':
                 $parsed['hour'] = $this->parseNumber($in, 2, $o);
                 $o += 2;
                 break;
             case '%z':
                 $tz = new \util\TimeZone($n = substr($in, $o, strcspn($in, ' ', $o)));
                 $o += strlen($n);
                 break;
             case '%Z':
                 sscanf(substr($in, $o, 5), '%c%02d%02d', $sign, $hours, $minutes);
                 $fa = '-' === $sign ? 1 : -1;
                 // -0800 means 8 hours ahead of time
                 $go = ['hour' => $fa * $hours, 'minute' => $fa * $minutes];
                 $tz = new \util\TimeZone('GMT');
                 $o += 5;
                 break;
             case is_array($token):
                 foreach ($token[1] as $i => $value) {
                     if ($value !== substr($in, $o, strlen($value))) {
                         continue;
                     }
                     $parsed[$token[0]] = $i + 1;
                     $o += strlen($value);
                     break 2;
                 }
                 throw new \lang\FormatException('Expected [' . implode(', ', $token[1]) . '] but have "' . substr($in, $o, 5) . '..."');
             default:
                 if ($o >= $il) {
                     throw new \lang\FormatException('Not enough input at offset ' . $o);
                 }
                 if ($token !== $in[$o]) {
                     throw new \lang\FormatException('Expected "' . $token . '" but have "' . $in[$o] . '" at offset ' . $o);
                 }
                 $o++;
         }
     }
     // AM/PM calculation
     if ('AM' === $m && 12 === $parsed['hour']) {
         $parsed['hour'] = 0;
     } else {
         if ('PM' === $m && 12 !== $parsed['hour']) {
             $parsed['hour'] += 12;
         }
     }
     // Timezone offset calculationn
     if ($go) {
         $parsed['hour'] += $go['hour'];
         $parsed['minute'] += $go['minute'];
     }
     // echo "$in => "; var_dump($parsed);
     return Date::create($parsed['year'], $parsed['month'], $parsed['day'], $parsed['hour'], $parsed['minute'], $parsed['second'], $tz);
 }