Merge branch 'develop' of github.com:getgrav/grav into feature-multimedia

* 'develop' of github.com:getgrav/grav:
  Utilize new summary.delimiter setting rather than constant
  PSR fixes
  fix for markdown adding HTML tags into inline JS/CSS
  moved summary delimiter into site config
  fix for twig set capturing
  Moved to camels for plugins+themes as optional class naming type
  Added summary option
This commit is contained in:
Gert
2015-02-04 22:39:47 +01:00
7 changed files with 50 additions and 23 deletions

View File

@@ -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

View File

@@ -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', '===');

View File

@@ -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] = [

View File

@@ -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, '<p>'.SUMMARY_DELIMITER.'</p>');
$delimiter = self::$grav['config']->get('site.summary.delimiter', '===');
$divider_pos = strpos($this->content, "<p>{$delimiter}</p>");
if ($divider_pos !== false) {
$this->summary_size = $divider_pos;
$this->content = str_replace('<p>'.SUMMARY_DELIMITER.'</p>', '', $this->content);
$this->content = str_replace("<p>{$delimiter}</p>", '', $this->content);
}
}

View File

@@ -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;

View File

@@ -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')) {

View File

@@ -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