コード例 #1
0
ファイル: string.php プロジェクト: glauberm/cinevi
 /**
  * Truncate text possibly setting a tip to show all of the text
  *
  * @param   string  $text  text to truncate
  * @param   array   $opts  optional options array
  *
  * @return  string
  */
 public static function truncate($text, $opts = array())
 {
     $origText = $text;
     $wordCount = FArrayHelper::getValue($opts, 'wordcount', 10);
     $showTip = FArrayHelper::getValue($opts, 'tip', true);
     $title = FArrayHelper::getValue($opts, 'title', '');
     $strippedText = htmlspecialchars(strip_tags($text), ENT_QUOTES);
     if (ArrayHelper::getValue($opts, 'html_format', false)) {
         $summary = FabrikString::truncateHtml($text, $wordCount);
     } else {
         $text = htmlspecialchars(strip_tags($text), ENT_QUOTES);
         $text = explode(' ', $text);
         $summary = array_slice($text, 0, $wordCount);
         if (count($text) > $wordCount) {
             $summary[] = " ...";
         }
         $summary = implode(' ', $summary);
     }
     if ($showTip && $origText != $summary) {
         FabrikHelperHTML::tips();
         if ($title !== '') {
             $title .= "::";
         }
         $tip = htmlspecialchars('<div class="truncate_text">' . $title . $strippedText . '</div>');
         $jOpts = new stdClass();
         $jOpts->notice = true;
         $jOpts->position = FArrayHelper::getValue($opts, 'position', 'top');
         $jOpts = json_encode($jOpts);
         $summary = '<span class="fabrikTip" opts=\'' . $jOpts . '\' title="' . $tip . '">' . $summary . '</span>';
     }
     return $summary;
 }