Exemple #1
0
 public static function isNative()
 {
     if (null === self::$_isNative) {
         self::$_isNative = function_exists('mb_strpos');
     }
     return self::$_isNative;
 }
Exemple #2
0
 public function viewMore($string, $moreLength = null, $maxLength = null, $lessLength = null, $nl2br = true)
 {
     if (!is_numeric($moreLength) || $moreLength <= 0) {
         $moreLength = $this->_moreLength;
     }
     if (!is_numeric($maxLength) || $maxLength <= 0) {
         $maxLength = $this->_maxLength;
     }
     if (!is_numeric($lessLength) || $lessLength <= 0) {
         $lessLength = $this->_lessLength;
     }
     // If using line breaks, ensure that there are not too many line breaks
     if ($nl2br) {
         $string = trim(preg_replace('/[\\r\\n]+/', "\n", $string));
         if (($c = substr_count($string, "\n")) > $this->_maxLineBreaks) {
             $pos = 0;
             for ($i = 0; $i < $this->_maxLineBreaks; $i++) {
                 $pos = strpos($string, "\n", $pos + 1);
             }
             if ($pos <= 0 || !is_int($pos)) {
                 $pos = null;
             }
             if ($pos) {
                 $moreLength = $pos;
             }
         }
     }
     // If length is less than max len, just return
     $strLen = Khcn_String::strlen($string);
     if ($strLen <= $moreLength + $this->_fudgesicles) {
         if ($nl2br) {
             return nl2br($string);
         } else {
             return $string;
         }
     }
     // Otherwise truncate
     if ($strLen >= $maxLength) {
         $strLen = $maxLength;
         $string = Khcn_String::substr($string, 0, $maxLength) . $this->view->translate('... &nbsp;');
     }
     $shortText = Khcn_String::substr($string, 0, $moreLength);
     $fullText = $string;
     // Do nl2br
     if ($nl2br) {
         $shortText = nl2br($shortText);
         $fullText = nl2br($fullText);
     }
     $content = '<' . $this->_tag . ' class="view_more"' . '>' . $shortText . $this->view->translate('... &nbsp;') . '<a class="view_more_link" href="javascript:void(0);" onclick="$(this).getParent().getNext().style.display=\'\';$(this).getParent().style.display=\'none\';">' . $this->view->translate('more') . '</a>' . '</' . $this->_tag . '>' . '<' . $this->_tag . ' class="view_more"' . ' style="display:none;"' . '>' . $fullText . ' &nbsp;';
     if ($strLen >= $lessLength) {
         $content .= '<a class="view_less_link" href="javascript:void(0);" onclick="$(this).getParent().getPrevious().style.display=\'\';$(this).getParent().style.display=\'none\';">' . $this->view->translate('less') . '</a>';
     }
     $content .= '</' . $this->_tag . '>';
     return $content;
 }
Exemple #3
0
 public function truncate($string, $length = 300, $chopString = null)
 {
     if (Khcn_String::strlen($string) <= $length) {
         return $string;
     }
     if (null === $chopString) {
         $chopString = '...';
     }
     $chopString = $this->view->translate($chopString);
     return Khcn_String::substr($string, 0, $length) . $chopString;
 }
Exemple #4
0
 /**
  * Gets a url slug for this item, based on it's title
  *
  * @return string The slug
  */
 public function getSlug($str = null)
 {
     if (null === $str) {
         $str = $this->getTitle();
     }
     if (strlen($str) > 32) {
         $str = Khcn_String::substr($str, 0, 32) . '...';
     }
     $search = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
     $replace = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
     $str = str_replace($search, $replace, $str);
     $str = preg_replace('/([a-z])([A-Z])/', '$1 $2', $str);
     $str = strtolower($str);
     $str = preg_replace('/[^a-z0-9-]+/i', '-', $str);
     $str = preg_replace('/-+/', '-', $str);
     $str = trim($str, '-');
     if (!$str) {
         $str = '-';
     }
     return $str;
 }