本文整理汇总了PHP中Grav\Common\Utils::truncateHTML方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::truncateHTML方法的具体用法?PHP Utils::truncateHTML怎么用?PHP Utils::truncateHTML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Utils
的用法示例。
在下文中一共展示了Utils::truncateHTML方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: summary
/**
* Get the summary.
*
* @param int $size Max summary size.
* @return string
*/
public function summary($size = null)
{
/** @var Config $config */
$config = self::getGrav()['config']->get('site.summary');
if (isset($this->header->summary)) {
$config = array_merge($config, $this->header->summary);
}
// Return summary based on settings in site config file
if (!$config['enabled']) {
return $this->content();
}
// Set up variables to process summary from page or from custom summary
if ($this->summary === null) {
$content = $this->content();
$summary_size = $this->summary_size;
} else {
$content = $this->summary;
$summary_size = mb_strlen($this->summary);
}
// Return calculated summary based on summary divider's position
$format = $config['format'];
// Return entire page content on wrong/ unknown format
if (!in_array($format, array('short', 'long'))) {
return $content;
} elseif ($format === 'short' && isset($summary_size)) {
return mb_substr($content, 0, $summary_size);
}
// Get summary size from site config's file
if (is_null($size)) {
$size = $config['size'];
}
// If the size is zero, return the entire page content
if ($size === 0) {
return $content;
// Return calculated summary based on defaults
} elseif (!is_numeric($size) || $size < 0) {
$size = 300;
}
return Utils::truncateHTML($content, $size);
}
示例2: summary
/**
* Get the summary.
*
* @param int $size Max summary size.
* @return string
*/
public function summary($size = null)
{
$content = $this->content();
// Return calculated summary based on summary divider's position
if (!$size && isset($this->summary_size)) {
return substr($content, 0, $this->summary_size);
}
// Return calculated summary based on setting in site config file
/** @var Config $config */
$config = self::$grav['config'];
if (!$size && $config->get('site.summary.size')) {
$size = $config->get('site.summary.size');
}
// Return calculated summary based on defaults
if (!$size) {
$size = 300;
}
return Utils::truncateHTML($content, $size);
}