diff --git a/system/config/site.yaml b/system/config/site.yaml index 59ee2ba15..23c0f1f1b 100644 --- a/system/config/site.yaml +++ b/system/config/site.yaml @@ -6,9 +6,12 @@ taxonomies: [category,tag] # Arbitrary list of taxonomy types blog: route: '/blog' # Route to blog metadata: - description: 'My Grav Site' # Site description + description: 'My Grav Site' # Site description summary: + enabled: true # enable or disable summary of page + format: short # long = summary delimiter will be ignored; short = use the first occurence of delimter or size size: 300 # Maximum length of summary (characters) + delimiter: === # The summary delimiter routes: /something/else: '/blog/sample-3' # Alias for /blog/sample-3 /another/one/here: '/blog/sample-3' # Another alias for /blog/sample-3 diff --git a/system/defines.php b/system/defines.php index 0d011136f..e55db94b1 100644 --- a/system/defines.php +++ b/system/defines.php @@ -40,6 +40,3 @@ define('RAW_CONTENT', 1); define('TWIG_CONTENT', 2); define('TWIG_CONTENT_LIST', 3); define('TWIG_TEMPLATES', 4); - -// Misc Defines -define('SUMMARY_DELIMITER', '==='); diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index c24737276..b63de9c72 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -301,6 +301,9 @@ class Assets */ public function addInlineCss($asset, $priority = 10) { + if (is_a($asset, 'Twig_Markup')) { + $asset = strip_tags((string)$asset); + } $key = md5($asset); if (is_string($asset) && !array_key_exists($key, $this->inline_css)) { $this->inline_css[$key] = [ @@ -326,6 +329,9 @@ class Assets */ public function addInlineJs($asset, $priority = 10) { + if (is_a($asset, 'Twig_Markup')) { + $asset = strip_tags((string)$asset); + } $key = md5($asset); if (is_string($asset) && !array_key_exists($key, $this->inline_js)) { $this->inline_js[$key] = [ diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 3f2dcc0dc..404ce7c42 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -308,26 +308,31 @@ class Page return $content; } + // Get summary size from site config's file + if (is_null($size)) { + $size = $config->get('site.summary.size', null); + } + // Return calculated summary based on summary divider's position - if (!$size && isset($this->summary_size)) { + $format = $config->get('site.summary.format', 'short'); + // Return entire page content on wrong/ unknown format + if (!in_array($format, array('short', 'long'))) { + return $content; + } elseif (($format === 'short') && isset($this->summary_size)) { return substr($content, 0, $this->summary_size); } - // Return calculated summary based on setting in site config file - if (is_null($size) && $config->get('site.summary.size')) { - $size = $config->get('site.summary.size'); - } - + // If the size is zero, return the entire page content + if ($size === 0) { + return $content; // Return calculated summary based on defaults - if (!is_numeric($size) || ($size < 0)) { + } elseif (!is_numeric($size) || ($size < 0)) { $size = 300; } return Utils::truncateHTML($content, $size); } - - /** * Gets and Sets the content based on content portion of the .md file * @@ -407,10 +412,11 @@ class Page } // Handle summary divider - $divider_pos = strpos($this->content, '
'.SUMMARY_DELIMITER.'
'); + $delimiter = self::$grav['config']->get('site.summary.delimiter', '==='); + $divider_pos = strpos($this->content, "{$delimiter}
"); if ($divider_pos !== false) { $this->summary_size = $divider_pos; - $this->content = str_replace(''.SUMMARY_DELIMITER.'
', '', $this->content); + $this->content = str_replace("{$delimiter}
", '', $this->content); } } diff --git a/system/src/Grav/Common/Plugins.php b/system/src/Grav/Common/Plugins.php index 7397c8bb1..dd495963e 100644 --- a/system/src/Grav/Common/Plugins.php +++ b/system/src/Grav/Common/Plugins.php @@ -54,7 +54,7 @@ class Plugins extends Iterator $pluginClassFormat = [ 'Grav\\Plugin\\'.ucfirst($plugin).'Plugin', - 'Grav\\Plugin\\'.str_replace(['_','-'], '', $plugin).'Plugin' + 'Grav\\Plugin\\'.Inflector::camelize($plugin).'Plugin' ]; $pluginClassName = false; diff --git a/system/src/Grav/Common/Themes.php b/system/src/Grav/Common/Themes.php index e7620cede..e44472835 100644 --- a/system/src/Grav/Common/Themes.php +++ b/system/src/Grav/Common/Themes.php @@ -145,10 +145,19 @@ class Themes extends Iterator $class = include $file; if (!is_object($class)) { - $className = '\\Grav\\Theme\\' . ucfirst($name); - if (class_exists($className)) { - $class = new $className($grav, $config, $name); + $themeClassFormat = [ + 'Grav\\Theme\\'.ucfirst($name), + 'Grav\\Theme\\'.Inflector::camelize($name) + ]; + $themeClassName = false; + + foreach ($themeClassFormat as $themeClass) { + if (class_exists($themeClass)) { + $themeClassName = $themeClass; + $class = new $themeClassName($grav, $config, $name); + break; + } } } } elseif (!$locator('theme://') && !defined('GRAV_CLI')) { diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index ecee73676..ac4f95f0f 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -46,7 +46,8 @@ abstract class Utils * @param $dir * @return bool */ - public static function rrmdir($dir) { + public static function rrmdir($dir) + { $files = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST @@ -55,9 +56,13 @@ abstract class Utils /** @var \DirectoryIterator $fileinfo */ foreach ($files as $fileinfo) { if ($fileinfo->isDir()) { - if (false === rmdir($fileinfo->getRealPath())) return false; + if (false === rmdir($fileinfo->getRealPath())) { + return false; + } } else { - if (false === unlink($fileinfo->getRealPath())) return false; + if (false === unlink($fileinfo->getRealPath())) { + return false; + } } } @@ -74,7 +79,8 @@ abstract class Utils * @param bool $considerHtml * @return string */ - public static function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) { + public static function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) + { $open_tags = array(); if ($considerHtml) { // if the plain text is shorter than the maximum length, return the whole text