Esempio n. 1
0
 /**
  * Returns the calculated month
  *
  * @param  string                          $calc    Calculation to make
  * @param  string|integer|array|IfwPsn_Vendor_Zend_Date  $month   Month to calculate with, if null the actual month is taken
  * @param  string|IfwPsn_Vendor_Zend_Locale              $locale  Locale for parsing input
  * @return integer|IfwPsn_Vendor_Zend_Date  new time
  * @throws IfwPsn_Vendor_Zend_Date_Exception
  */
 private function _month($calc, $month, $locale)
 {
     if ($month === null) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date/Exception.php';
         throw new IfwPsn_Vendor_Zend_Date_Exception('parameter $month must be set, null is not allowed');
     }
     if ($locale === null) {
         $locale = $this->getLocale();
     }
     if ($month instanceof IfwPsn_Vendor_Zend_Date) {
         // extract month from object
         $found = $month->toString(self::MONTH_SHORT, 'iso', $locale);
     } else {
         if (is_numeric($month)) {
             $found = $month;
         } else {
             if (is_array($month)) {
                 if (isset($month['month']) === true) {
                     $month = $month['month'];
                 } else {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Date_Exception("no month given in array");
                 }
             } else {
                 $monthlist = IfwPsn_Vendor_Zend_Locale_Data::getList($locale, 'month');
                 $monthlist2 = IfwPsn_Vendor_Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'format', 'abbreviated'));
                 $monthlist = array_merge($monthlist, $monthlist2);
                 $found = 0;
                 $cnt = 0;
                 foreach ($monthlist as $key => $value) {
                     if (strtoupper($value) == strtoupper($month)) {
                         $found = $key % 12 + 1;
                         break;
                     }
                     ++$cnt;
                 }
                 if ($found == 0) {
                     foreach ($monthlist2 as $key => $value) {
                         if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($month)) {
                             $found = $key + 1;
                             break;
                         }
                         ++$cnt;
                     }
                 }
                 if ($found == 0) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Date_Exception("unknown month name ({$month})", 0, null, $month);
                 }
             }
         }
     }
     $return = $this->_calcdetail($calc, $found, self::MONTH_SHORT, $locale);
     if ($calc != 'cmp') {
         return $this;
     }
     return $return;
 }
Esempio n. 2
0
 /**
  * Check if the given date fits the given format
  *
  * @param  string $value  Date to check
  * @return boolean False when date does not fit the format
  */
 private function _checkFormat($value)
 {
     try {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Format.php';
         $parsed = IfwPsn_Vendor_Zend_Locale_Format::getDate($value, array('date_format' => $this->_format, 'format_type' => 'iso', 'fix_date' => false));
         if (isset($parsed['year']) and (strpos(strtoupper($this->_format), 'YY') !== false and strpos(strtoupper($this->_format), 'YYYY') === false)) {
             $parsed['year'] = IfwPsn_Vendor_Zend_Date::getFullYear($parsed['year']);
         }
     } catch (Exception $e) {
         // Date can not be parsed
         return false;
     }
     if ((strpos($this->_format, 'Y') !== false or strpos($this->_format, 'y') !== false) and !isset($parsed['year'])) {
         // Year expected but not found
         return false;
     }
     if (strpos($this->_format, 'M') !== false and !isset($parsed['month'])) {
         // Month expected but not found
         return false;
     }
     if (strpos($this->_format, 'd') !== false and !isset($parsed['day'])) {
         // Day expected but not found
         return false;
     }
     if ((strpos($this->_format, 'H') !== false or strpos($this->_format, 'h') !== false) and !isset($parsed['hour'])) {
         // Hour expected but not found
         return false;
     }
     if (strpos($this->_format, 'm') !== false and !isset($parsed['minute'])) {
         // Minute expected but not found
         return false;
     }
     if (strpos($this->_format, 's') !== false and !isset($parsed['second'])) {
         // Second expected  but not found
         return false;
     }
     // Date fits the format
     return true;
 }
Esempio n. 3
0
 /**
  * Generate a new Cookie object from a cookie string
  * (for example the value of the Set-Cookie HTTP header)
  *
  * @param string $cookieStr
  * @param IfwPsn_Vendor_Zend_Uri_Http|string $refUri Reference URI for default values (domain, path)
  * @param boolean $encodeValue Whether or not the cookie's value should be
  *                             passed through urlencode/urldecode
  * @return IfwPsn_Vendor_Zend_Http_Cookie A new IfwPsn_Vendor_Zend_Http_Cookie object or false on failure.
  */
 public static function fromString($cookieStr, $refUri = null, $encodeValue = true)
 {
     // Set default values
     if (is_string($refUri)) {
         $refUri = IfwPsn_Vendor_Zend_Uri_Http::factory($refUri);
     }
     $name = '';
     $value = '';
     $domain = '';
     $path = '';
     $expires = null;
     $secure = false;
     $parts = explode(';', $cookieStr);
     // If first part does not include '=', fail
     if (strpos($parts[0], '=') === false) {
         return false;
     }
     // Get the name and value of the cookie
     list($name, $value) = explode('=', trim(array_shift($parts)), 2);
     $name = trim($name);
     if ($encodeValue) {
         $value = urldecode(trim($value));
     }
     // Set default domain and path
     if ($refUri instanceof IfwPsn_Vendor_Zend_Uri_Http) {
         $domain = $refUri->getHost();
         $path = $refUri->getPath();
         $path = substr($path, 0, strrpos($path, '/'));
     }
     // Set other cookie parameters
     foreach ($parts as $part) {
         $part = trim($part);
         if (strtolower($part) == 'secure') {
             $secure = true;
             continue;
         }
         $keyValue = explode('=', $part, 2);
         if (count($keyValue) == 2) {
             list($k, $v) = $keyValue;
             switch (strtolower($k)) {
                 case 'expires':
                     if (($expires = strtotime($v)) === false) {
                         /**
                          * The expiration is past Tue, 19 Jan 2038 03:14:07 UTC
                          * the maximum for 32-bit signed integer. IfwPsn_Vendor_Zend_Date
                          * can get around that limit.
                          *
                          * @see IfwPsn_Vendor_Zend_Date
                          */
                         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date.php';
                         $expireDate = new IfwPsn_Vendor_Zend_Date($v);
                         $expires = $expireDate->getTimestamp();
                     }
                     break;
                 case 'path':
                     $path = $v;
                     break;
                 case 'domain':
                     $domain = $v;
                     break;
                 default:
                     break;
             }
         }
     }
     if ($name !== '') {
         $ret = new self($name, $value, $domain, $expires, $path, $secure);
         $ret->encodeValue = $encodeValue ? true : false;
         return $ret;
     } else {
         return false;
     }
 }
Esempio n. 4
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Filter_Interface
  *
  * Normalizes the given input
  *
  * @param  string $value Value to normalized
  * @return string|array The normalized value
  */
 public function filter($value)
 {
     if (is_array($value)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date.php';
         $date = new IfwPsn_Vendor_Zend_Date($value, $this->_options['locale']);
         return $date->toString($this->_options['date_format']);
     } else {
         if ($this->_options['precision'] === 0) {
             return IfwPsn_Vendor_Zend_Locale_Format::toInteger($value, $this->_options);
         } else {
             if ($this->_options['precision'] === null) {
                 return IfwPsn_Vendor_Zend_Locale_Format::toFloat($value, $this->_options);
             }
         }
     }
     return IfwPsn_Vendor_Zend_Locale_Format::toNumber($value, $this->_options);
 }