Пример #1
0
 function getDateTime($time, $zone = null)
 {
     if (is_a($time, 'DateTime')) {
         return $time;
     }
     $zone = $this->getZone($zone);
     if (Tool::isInt($time)) {
         $Date = new DateTime(null, $zone);
         $Date->setTimestamp($time);
         return $Date;
     }
     return new DateTime($time, $zone);
 }
Пример #2
0
 /**
 @param	location	location to relocate to
 @param	type	type of relocation; head for header relocation, js for javascript relocation
 */
 static function redirect($location = null, $type = 'head', $code = null)
 {
     if ($type == 'head') {
         if (!$location) {
             $location = $_SERVER['REQUEST_URI'];
         }
         $code = $code ? $code : 302;
         header('Location: ' . $location, true, $code);
     } elseif ($type == 'js') {
         echo '<script type="text/javascript">';
         if (Tool::isInt($location)) {
             if ($location == 0) {
                 $location = $_SERVER['REQUEST_URI'];
                 echo 'window.location = ' . $_SERVER['REQUEST_URI'] . ';';
             } else {
                 echo 'javascript:history.go(' . $location . ');';
             }
         } else {
             echo 'document.location="' . $location . '";';
         }
         echo '</script>';
     }
     exit;
 }
Пример #3
0
 static function at($array, $index)
 {
     if (Tool::isInt($index) && $index < 0) {
         $array = array_slice($array, $index, 1);
         return $array[0];
     }
     return $array[$index];
 }
Пример #4
0
 /**
 	@param	dict	dictionary to update on query
 */
 protected function namedId($table, $name, &$dict = null)
 {
     if (Tool::isInt($name)) {
         return $name;
     }
     $id = $this->row($table, ['name' => $name], 'id');
     if ($dict !== null) {
         $dict[$name] = $id;
     }
     return $id;
 }
Пример #5
0
 static function age($value, $min = null, $max = null)
 {
     $time = new Time($value);
     $age = $time->diff(new Time('now'));
     if (Tool::isInt($max) && $age->y > $max) {
         Debug::toss(sprintf(self::$errorMessages['age.max'], $max), 'InputException');
     }
     if (Tool::isInt($min) && $age->y < $min) {
         Debug::toss(sprintf(self::$errorMessages['age.min'], $min), 'InputException');
     }
 }
Пример #6
0
 /**
 see callStatic for special static handling
 
 @param	to	to address "bob <*****@*****.**>, joe_man@susan.com"
 @param	subject	subject of email
 @param	from	from email address
 @options	array of options including bcc, cc.
 */
 private function send($to, $subject, $from = null, $options = null)
 {
     if ($this->html) {
         $this->html = self::applyLineLengthMax(utf8_encode($this->html));
     }
     if ($this->text) {
         $this->text = self::applyLineLengthMax(utf8_encode($this->text));
     }
     if ($this->attached) {
         $boundary = $_ENV['emailUniqueId'] . '-A-' . microtime(true);
         $this->header['Content-Type'] = 'multipart/mixed; boundary="' . $boundary . '"';
         $boundary = "\n\n--" . $boundary . "\n";
         if ($this->html && $this->text) {
             $message .= $boundary;
             $alterBoundary = $_ENV['emailUniqueId'] . '-B-' . microtime(true);
             $message .= 'Content-Type: multipart/alternative; boundary="' . $alterBoundary . '"';
             $alterBoundary = "\n\n--" . $alterBoundary . "\n";
             $message .= $alterBoundary . 'Content-type: text/plain; charset="UTF-8"' . "\n" . 'Content-Transfer-Encoding: 8bit' . "\n\n" . $this->text;
             $message .= $alterBoundary . 'Content-Type: text/html; charset="UTF-8"' . "\n" . 'Content-Transfer-Encoding: 8bit' . "\n\n" . $this->html;
         } elseif ($this->text) {
             $message .= $boundary . 'Content-type: text/plain; charset="UTF-8"' . "\n" . 'Content-Transfer-Encoding: 8bit' . "\n\n" . $this->text;
         } elseif ($this->html) {
             $message .= $boundary . 'Content-type: text/plain; charset="UTF-8"' . "\n" . 'Content-Transfer-Encoding: 8bit' . "\n\n" . $this->html;
         }
         foreach ($this->attached as $k => $v) {
             if (is_file($v)) {
                 $data = chunk_split(base64_encode(file_get_contents($v)));
                 $finfo = finfo_open(FILEINFO_MIME_TYPE);
                 $mime = finfo_file($finfo, $v);
                 finfo_close($finfo);
                 if (!Tool::isInt($k)) {
                     $name = $k;
                 } else {
                     $name = basename($v);
                 }
                 $message .= $boundary . 'Content-Type: ' . $mime . '; name="' . $name . '"' . "\n" . 'Content-Transfer-Encoding: base64' . "\n" . 'Content-Disposition: attachment' . "\n\n" . $data;
             }
         }
     } elseif ($this->html && $this->text) {
         $boundary = $_ENV['emailUniqueId'] . '-A-' . microtime(true);
         $this->header['Content-Type'] = 'multipart/alternative; boundary="' . $boundary . '"';
         $boundary = "\n\n--" . $boundary . "\n";
         $message .= $boundary . 'Content-type: text/plain; charset="UTF-8"' . "\n" . 'Content-Transfer-Encoding: 8bit' . "\n\n" . $this->text;
         $message .= $boundary . 'Content-Type: text/html; charset="UTF-8"' . "\n" . 'Content-Transfer-Encoding: 8bit' . "\n\n" . $this->html;
     } elseif ($this->html) {
         $this->header['Content-Type'] = 'text/html; charset=UTF-8';
         $message = $this->html;
     } else {
         $this->header['Content-Type'] = 'text/plain; charset=UTF-8';
         $message = $this->text;
     }
     if ($from) {
         $this->header['From'] = $this->header['Reply-To'] = $from;
         preg_match('#[a-z0-9.\\-]+@[a-z0-9.\\-]+\\.[a-z]+#i', $from, $match);
         $this->header['Return-Path'] = '<' . $match[0] . '>';
         $params .= '-f' . $match[0];
     }
     if ($options) {
         if ($options['cc']) {
             $this->header['Cc'] = $options['cc'];
         }
         if ($options['bcc']) {
             $this->header['Bcc'] = $options['bcc'];
         }
     }
     $this->header['Message-Id'] = '<' . $_ENV['emailUniqueId'] . '-' . sha1(uniqid(microtime()) . rand(1, 100)) . '@' . gethostname() . '>';
     foreach ($this->header as $k => $v) {
         #not separating with \r\n because this seems to cause DKIM hash to fail
         $headers .= $k . ': ' . $v . "\n";
     }
     if (is_array($to)) {
         $to = implode(', ', $to);
     }
     mail($to, $subject, $message, $headers, $params);
     return $this->header['Message-Id'];
 }
Пример #7
0
 protected function getNode($node)
 {
     if ($node && Tool::isInt($node)) {
         return $this->db->row($this->table, $node, Arrays::implode(',', ['id', 'order_in', 'order_out', 'order_depth', $this->fkColumn]));
     }
     return (array) $node;
 }