From a6790cace37edd2f19a064cced3be8fc779e9493 Mon Sep 17 00:00:00 2001 From: Sommerregen Date: Sun, 1 Feb 2015 18:15:24 +0100 Subject: [PATCH 1/7] Added summary option --- system/src/Grav/Common/Page/Page.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 3f2dcc0dc..19c63eb61 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -308,26 +308,32 @@ 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 * From a3c848e4e2d14930c70713e3625d2f89b3cefcbb Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 2 Feb 2015 13:08:56 -0700 Subject: [PATCH 2/7] Moved to camels for plugins+themes as optional class naming type --- system/src/Grav/Common/Plugins.php | 2 +- system/src/Grav/Common/Themes.php | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) 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')) { From c747c4baf753129a159ec926076e1fa9e82a3975 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 2 Feb 2015 16:27:36 -0700 Subject: [PATCH 3/7] fix for twig set capturing --- system/src/Grav/Common/Assets.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index c24737276..b14ba7233 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -301,6 +301,7 @@ class Assets */ public function addInlineCss($asset, $priority = 10) { + $asset = (string) $asset; $key = md5($asset); if (is_string($asset) && !array_key_exists($key, $this->inline_css)) { $this->inline_css[$key] = [ @@ -326,6 +327,7 @@ class Assets */ public function addInlineJs($asset, $priority = 10) { + $asset = (string) $asset; $key = md5($asset); if (is_string($asset) && !array_key_exists($key, $this->inline_js)) { $this->inline_js[$key] = [ From 02508933d791b050133bfbe45ab2cd42f75c6f28 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 2 Feb 2015 17:24:41 -0700 Subject: [PATCH 4/7] moved summary delimiter into site config --- system/config/site.yaml | 5 ++++- system/defines.php | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) 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', '==='); From 3f33e97f0c9279c6479a29b663ffed2dccbbfbb7 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 2 Feb 2015 17:25:14 -0700 Subject: [PATCH 5/7] fix for markdown adding HTML tags into inline JS/CSS --- system/src/Grav/Common/Assets.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index b14ba7233..b63de9c72 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -301,7 +301,9 @@ class Assets */ public function addInlineCss($asset, $priority = 10) { - $asset = (string) $asset; + 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] = [ @@ -327,7 +329,9 @@ class Assets */ public function addInlineJs($asset, $priority = 10) { - $asset = (string) $asset; + 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] = [ From dc65475723f8fd7e542ba567d5ecb4f040b78c68 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 2 Feb 2015 17:25:24 -0700 Subject: [PATCH 6/7] PSR fixes --- system/src/Grav/Common/Utils.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 From eb4eafd91547880c145a21bf0c6d46426fd2aff9 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 2 Feb 2015 17:25:51 -0700 Subject: [PATCH 7/7] Utilize new summary.delimiter setting rather than constant --- system/src/Grav/Common/Page/Page.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 3f2dcc0dc..7a565c610 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -407,10 +407,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); } }