示例#1
0
 /**
  * Sanitize length.
  *
  * @param KConfig $config Configuration. Contains keys property,value,entity
  *
  * @return bool Return true if it's valid or false if it's not
  */
 protected function _sanitizeLength(KConfig $config)
 {
     $property = $config->property;
     $value = $config->value;
     $options = KConfig::unbox($config->options);
     //if a number is just passed then treat it as max
     if (!is_array($options)) {
         $options = array('max' => $options);
     }
     if ($property->isAttribute() && $property->isScalar() && isset($options['max'])) {
         $helper = new LibBaseTemplateHelperText(new KConfig());
         $value = $helper->truncate($value, array('length' => $options['max'], 'consider_html' => true, 'ending' => ''));
     }
     return $value;
 }
示例#2
0
文件: text.php 项目: stonyyi/anahita
 /**
  * Truncates a text.
  *
  * @param string $text    The text to truncate
  * @param array  $options Truncation options. Can be 'length'=>integer, 'read_more'=>boolean, 
  *                        'ending'=>string, 'exact'=>boolean, 'consider_html'=>false
  * 
  * @return string
  */
 public function truncate($text, $options = array())
 {
     $options['read_more'] = false;
     $options['length'] = 500;
     return parent::truncate($text, $options);
 }