예제 #1
0
 /**
  * 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
0
파일: Page.php 프로젝트: qbi/datenknoten.me
 /**
  * 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);
 }