示例#1
0
 /**
  * Purify HTML for field.
  * @return string HTML.
  */
 public function recordDisplay(ActiveRecord $record, $field = 'content', $options = array())
 {
     $purifier = $this->getPurifier($field);
     $htmlField = $field . 'Html';
     $content = $record->{$htmlField};
     if (isset($options['break']) and $options['break']) {
         $sections = explode('<div class="break"></div>', $content);
         $content = $sections[0];
     }
     $html = $this->applyFilters($field, 'prerender', $content);
     if (isset($options['maxLength']) and Unicode::length($html) > $options['maxLength']) {
         $html = Unicode::slice($html, 0, $options['maxLength']);
         if (isset($options['append'])) {
             $html .= $options['append'];
         }
     }
     return $purifier->purify($html);
 }
示例#2
0
文件: I18n.php 项目: jivoo/jivoo
 /**
  * Localized date function.
  *
  * Works like {@see date()} but translates month names and weekday names using
  * the current {@see getLocale()}.
  *
  * @param string $format The format of the outputted date string. See
  * {@link http://php.net/manual/en/function.date.php date()}
  * @param int $timestamp Optional Unix timestamp to use. Default is value of 
  * {@see time()}
  * @return string Formatted date string.
  */
 public static function date($format, $timestamp = null)
 {
     if (is_null($timestamp)) {
         $timestamp = time();
     }
     $month = date('n', $timestamp);
     if ($month == 1) {
         $F = tr('January');
     } else {
         if ($month == 2) {
             $F = tr('February');
         } else {
             if ($month == 3) {
                 $F = tr('March');
             } else {
                 if ($month == 4) {
                     $F = tr('April');
                 } else {
                     if ($month == 5) {
                         $F = tr('May');
                     } else {
                         if ($month == 6) {
                             $F = tr('June');
                         } else {
                             if ($month == 7) {
                                 $F = tr('July');
                             } else {
                                 if ($month == 8) {
                                     $F = tr('August');
                                 } else {
                                     if ($month == 9) {
                                         $F = tr('September');
                                     } else {
                                         if ($month == 10) {
                                             $F = tr('October');
                                         } else {
                                             if ($month == 11) {
                                                 $F = tr('November');
                                             } else {
                                                 if ($month == 12) {
                                                     $F = tr('December');
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $M = Unicode::slice($F, 0, 3);
     $weekday = date('w', $timestamp);
     if ($weekday == 0) {
         $l = tr('Sunday');
     } else {
         if ($weekday == 1) {
             $l = tr('Monday');
         } else {
             if ($weekday == 2) {
                 $l = tr('Tuesday');
             } else {
                 if ($weekday == 3) {
                     $l = tr('Wednesday');
                 } else {
                     if ($weekday == 4) {
                         $l = tr('Thursday');
                     } else {
                         if ($weekday == 5) {
                             $l = tr('Friday');
                         } else {
                             if ($weekday == 6) {
                                 $l = tr('Saturday');
                             }
                         }
                     }
                 }
             }
         }
     }
     $D = Unicode::slice($l, 0, 3);
     $date = date($format, $timestamp);
     $date = str_replace(date('F', $timestamp), $F, $date);
     $date = str_replace(date('M', $timestamp), $M, $date);
     $date = str_replace(date('l', $timestamp), $l, $date);
     $date = str_replace(date('D', $timestamp), $D, $date);
     return $date;
 }
示例#3
0
 /**
  * Get the name of a unit. The name of a unit is its class name without a
  * "Unit"-suffix. If the class is in the namespace "Jivoo\Core\Units" or
  * "(app namespace)\Units", the namespace is removed from the name.
  * @param Unit $unit Unit.
  * @return string Unit name.
  */
 public function getName(Unit $unit)
 {
     $class = get_class($unit);
     if (Unicode::endsWith($class, 'Unit')) {
         $class = substr($class, 0, -4);
         if (Unicode::startsWith($class, 'Jivoo\\Core\\Units\\')) {
             return substr($class, strlen('Jivoo\\Core\\Units\\'));
         }
         $ns = $this->app->n() . '\\';
         if (Unicode::startsWith($class, $ns)) {
             return substr($class, strlen($ns));
         }
     }
     return $class;
 }