diff --git a/CHANGELOG.md b/CHANGELOG.md index 67164b01e9..a88529ade1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +# v0.9.17 +## 02/05/2015 + +1. [](#new) + * Added **full HHVM support!** Get your speed on with Facebook's crazy fast PHP JIT compiler +2. [](#improved) + * More flexible page summary control + * Support **CamelCase** plugin and theme class names. Replaces dashes and underscores + * Moved summary delimiter into `site.yaml` so it can be configurable + * Various PSR fixes +3. [](#bugfix) + * Fix for `mergeConfig()` not falling back to defaults + * Fix for `addInlineCss()` and `addInlineJs()` Assets not working between Twig tags + * Fix for Markdown adding HTML tags into inline CSS and JS + # v0.9.16 ## 01/30/2015 diff --git a/system/config/site.yaml b/system/config/site.yaml index 59ee2ba158..23c0f1f1b4 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 0d011136ff..562e85140a 100644 --- a/system/defines.php +++ b/system/defines.php @@ -2,7 +2,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '0.9.16'); +define('GRAV_VERSION', '0.9.17'); define('DS', '/'); // Directories and Paths @@ -40,6 +40,3 @@ 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 c247372766..4e940d09ed 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -163,8 +163,8 @@ public function config(array $config) public function init() { /** @var Config $config */ - $config = self::$grav['config']; - $base_url = self::$grav['base_url']; + $config = self::getGrav()['config']; + $base_url = self::getGrav()['base_url']; $asset_config = (array)$config->get('system.assets'); $this->config($asset_config); @@ -301,6 +301,9 @@ public function addJs($asset, $priority = 10, $pipeline = true) */ 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 @@ public function addInlineCss($asset, $priority = 10) */ 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] = [ @@ -352,7 +358,7 @@ public function css($attributes = []) } // Sort array by priorities (larger priority first) - if (self::$grav) { + if (self::getGrav()) { usort($this->css, function ($a, $b) { if ($a['priority'] == $b['priority']) { return $b['order'] - $a['order']; @@ -465,7 +471,7 @@ public function js($attributes = []) protected function pipeline($css = true) { /** @var Cache $cache */ - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; $key = '?' . $cache->getKey(); if ($css) { @@ -681,7 +687,7 @@ protected function isRemoteLink($link) protected function buildLocalLink($asset) { try { - $asset = self::$grav['locator']->findResource($asset, false); + $asset = self::getGrav()['locator']->findResource($asset, false); } catch (\Exception $e) { } diff --git a/system/src/Grav/Common/GPM/Local/Plugins.php b/system/src/Grav/Common/GPM/Local/Plugins.php index b5193ad86c..b52efea93b 100644 --- a/system/src/Grav/Common/GPM/Local/Plugins.php +++ b/system/src/Grav/Common/GPM/Local/Plugins.php @@ -17,7 +17,7 @@ class Plugins extends Collection */ public function __construct() { - $grav = self::$grav; + $grav = self::getGrav(); foreach ($grav['plugins']->all() as $name => $data) { $this->items[$name] = new Package($data, $this->type); diff --git a/system/src/Grav/Common/GPM/Local/Themes.php b/system/src/Grav/Common/GPM/Local/Themes.php index 19d68c6a67..673490144c 100644 --- a/system/src/Grav/Common/GPM/Local/Themes.php +++ b/system/src/Grav/Common/GPM/Local/Themes.php @@ -6,7 +6,7 @@ class Themes extends Collection private $type = 'themes'; public function __construct() { - $grav = self::$grav; + $grav = self::getGrav(); foreach ($grav['themes']->all() as $name => $data) { $this->items[$name] = new Package($data, $this->type); diff --git a/system/src/Grav/Common/GPM/Remote/Collection.php b/system/src/Grav/Common/GPM/Remote/Collection.php index 58e2e69425..87c97ffaeb 100644 --- a/system/src/Grav/Common/GPM/Remote/Collection.php +++ b/system/src/Grav/Common/GPM/Remote/Collection.php @@ -31,7 +31,7 @@ public function __construct($repository = null) { throw new \RuntimeException("A repository is required for storing the cache"); } - $cache_dir = self::$grav['locator']->findResource('cache://gpm', true, true); + $cache_dir = self::getGrav()['locator']->findResource('cache://gpm', true, true); $this->cache = new FilesystemCache($cache_dir); $this->repository = $repository; diff --git a/system/src/Grav/Common/GravTrait.php b/system/src/Grav/Common/GravTrait.php index b182583234..215b868486 100644 --- a/system/src/Grav/Common/GravTrait.php +++ b/system/src/Grav/Common/GravTrait.php @@ -13,6 +13,9 @@ trait GravTrait */ public function getGrav() { + if (!self::$grav) { + self::$grav = Grav::instance(); + } return self::$grav; } diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 9ba39e423f..9de9efeef3 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -29,10 +29,10 @@ trait ParsedownGravTrait protected function init($page) { $this->page = $page; - $this->pages = self::$grav['pages']; + $this->pages = self::getGrav()['pages']; $this->BlockTypes['{'] [] = "TwigTag"; - $this->base_url = rtrim(self::$grav['base_url'] . self::$grav['pages']->base(), '/'); - $this->pages_dir = self::$grav['locator']->findResource('page://'); + $this->base_url = rtrim(self::getGrav()['base_url'] . self::getGrav()['pages']->base(), '/'); + $this->pages_dir = self::getGrav()['locator']->findResource('page://'); $this->special_chars = array('>' => 'gt', '<' => 'lt', '"' => 'quot'); } @@ -159,7 +159,7 @@ protected function inlineImage($excerpt) } else { // Create the custom lightbox element - + $attributes = $data['a_attributes']; $attributes['href'] = $data['a_href']; diff --git a/system/src/Grav/Common/Page/Media.php b/system/src/Grav/Common/Page/Media.php index afbdeeca4e..e6438327a7 100644 --- a/system/src/Grav/Common/Page/Media.php +++ b/system/src/Grav/Common/Page/Media.php @@ -55,7 +55,7 @@ public function __construct($path) $medium = $this->get("{$basename}.{$ext}"); if (!$alternative) { - + $medium = $medium ? $medium : $this->createMedium($info->getPathname()); if (!$medium) { @@ -70,7 +70,7 @@ public function __construct($path) } else { $altMedium = $this->createMedium($info->getPathname()); - + if (!$altMedium) { continue; } @@ -86,7 +86,7 @@ public function __construct($path) } $medium = $medium ? $medium : $this->scaleMedium($altMedium, $alternative, 1); - + $medium->addAlternative($this->parseRatio($alternative), $altMedium); } @@ -186,7 +186,7 @@ public function files() * Create a Medium object from a file * * @param string $file - * + * * @return Medium|null */ protected function createMedium($file) @@ -202,7 +202,7 @@ protected function createMedium($file) $basename = implode('.', $parts); /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; // Check if medium type has been configured. $params = $config->get("media.".strtolower($ext)); @@ -224,7 +224,7 @@ protected function createMedium($file) 'modified' => filemtime($file), ); - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; $lookup = $locator->findResources('image://'); foreach ($lookup as $lookupPath) { @@ -257,7 +257,7 @@ protected function scaleMedium($medium, $from, $to) $medium->set('debug', false); $file = $medium->resize($width, $height)->setPrettyName($basename)->url(); - $file = preg_replace('|'. preg_quote(self::$grav['base_url_relative']) .'$|', '', GRAV_ROOT) . $file; + $file = preg_replace('|'. preg_quote(self::getGrav()['base_url_relative']) .'$|', '', GRAV_ROOT) . $file; $medium->set('debug', $debug); diff --git a/system/src/Grav/Common/Page/Medium.php b/system/src/Grav/Common/Page/Medium.php index e39390234d..224317b795 100644 --- a/system/src/Grav/Common/Page/Medium.php +++ b/system/src/Grav/Common/Page/Medium.php @@ -120,16 +120,7 @@ public function __construct($items = array(), Blueprint $blueprint = null) $this->def('mime', 'application/octet-stream'); } - $debug = self::$grav['config']->get('system.images.debug'); - // try to override with page setting if possible - $page = self::$grav['page']; - if (!is_null($page)) { - if (isset($page->header()->images['debug'])) { - $debug = $page->header()->images['debug']; - } - } - - $this->set('debug', $debug); + $this->set('debug', self::getGrav()['config']->get('system.images.debug')); } /** @@ -177,7 +168,7 @@ public function url($reset = true) $output = preg_replace('|^' . GRAV_ROOT . '|', '', $this->get('path')) . '/' . $this->get('filename'); } - return self::$grav['base_url'] . $output; + return self::getGrav()['base_url'] . $output; } @@ -341,7 +332,7 @@ public function link($width = null, $height = null) } } else { // TODO: we need to find out URI in a bit better way. - $this->linkTarget = self::$grav['base_url'] . preg_replace('|^' . GRAV_ROOT . '|', '', $this->get('path')) . '/' . $this->get('filename'); + $this->linkTarget = self::getGrav()['base_url'] . preg_replace('|^' . GRAV_ROOT . '|', '', $this->get('path')) . '/' . $this->get('filename'); } return $this; @@ -431,7 +422,7 @@ public function __call($method, $args) */ public function image($variable = 'thumb') { - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; // TODO: add default file $file = $this->get($variable); @@ -462,7 +453,7 @@ protected function saveImage() $ratio = 1; } - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; $overlay = $locator->findResource("system://assets/responsive-overlays/{$ratio}x.png") ?: $locator->findResource('system://assets/responsive-overlays/unknown.png'); $this->image->merge(ImageFile::open($overlay)); } diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 3f2dcc0dc5..14281fb2ce 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -96,7 +96,7 @@ class Page public function __construct($array = array()) { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $this->routable = true; $this->taxonomy = array(); @@ -123,20 +123,20 @@ public function init($file) $this->modularTwig($this->slug[0] == '_'); // Handle publishing dates if no explict published option set - if (self::$grav['config']->get('system.pages.publish_dates') && !isset($this->header->published)) { + if (self::getGrav()['config']->get('system.pages.publish_dates') && !isset($this->header->published)) { // unpublish if required, if not clear cache right before page should be unpublished if ($this->unpublishDate()) { if ($this->unpublishDate() < time()) { $this->published(false); } else { $this->published(); - self::$grav['cache']->setLifeTime($this->unpublishDate()); + self::getGrav()['cache']->setLifeTime($this->unpublishDate()); } } // publish if required, if not clear cache right before page is published if ($this->publishDate() != $this->modified() && $this->publishDate() > time()) { $this->published(false); - self::$grav['cache']->setLifeTime($this->publishDate()); + self::getGrav()['cache']->setLifeTime($this->publishDate()); } } $this->published(); @@ -300,7 +300,7 @@ public function modifyHeader($key, $value) public function summary($size = null) { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $content = $this->content(); // Return summary based on settings in site config file @@ -308,26 +308,31 @@ public function summary($size = null) return $content; } - // Return calculated summary based on summary divider's position - if (!$size && isset($this->summary_size)) { - return substr($content, 0, $this->summary_size); + // Get summary size from site config's file + if (is_null($size)) { + $size = $config->get('site.summary.size', null); } - // 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'); + // Return calculated summary based on summary divider's position + $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); } + // 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 * @@ -357,7 +362,7 @@ public function content($var = null) // Load cached content /** @var Cache $cache */ - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; $cache_id = md5('page'.$this->id()); $this->content = $cache->fetch($cache_id); @@ -370,7 +375,7 @@ public function content($var = null) // if no cached-content run everything if ($this->content == false) { $this->content = $this->raw_content; - self::$grav->fireEvent('onPageContentRaw', new Event(['page' => $this])); + self::getGrav()->fireEvent('onPageContentRaw', new Event(['page' => $this])); if ($twig_first) { if ($process_twig) { @@ -407,10 +412,11 @@ public function content($var = null) } // Handle summary divider - $divider_pos = strpos($this->content, '

'.SUMMARY_DELIMITER.'

'); + $delimiter = self::getGrav()['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); } } @@ -424,7 +430,7 @@ public function content($var = null) protected function processMarkdown() { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $defaults = (array) $config->get('system.pages.markdown'); if (isset($this->header()->markdown)) { @@ -457,7 +463,7 @@ protected function processMarkdown() */ private function processTwig() { - $twig = self::$grav['twig']; + $twig = self::getGrav()['twig']; $this->content = $twig->processPage($this, $this->content); } @@ -466,10 +472,10 @@ private function processTwig() */ private function cachePageContent() { - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; $cache_id = md5('page'.$this->id()); - self::$grav->fireEvent('onPageContentProcessed', new Event(['page' => $this])); + self::getGrav()->fireEvent('onPageContentProcessed', new Event(['page' => $this])); $cache->save($cache_id, $this->content); } @@ -644,7 +650,7 @@ public function copy($parent) public function blueprints() { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->blueprints($this->template()); } @@ -723,7 +729,7 @@ public function toJson() public function media($var = null) { /** @var Cache $cache */ - $cache = self::$grav['cache']; + $cache = self::getGrav()['cache']; if ($var) { $this->media = $var; @@ -952,7 +958,7 @@ public function metadata($var = null) // Safety check to ensure we have a header if ($page_header) { // Merge any site.metadata settings in with page metadata - $defaults = (array) self::$grav['config']->get('site.metadata'); + $defaults = (array) self::getGrav()['config']->get('site.metadata'); if (isset($page_header->metadata)) { $page_header->metadata = array_merge($defaults, $page_header->metadata); @@ -1055,10 +1061,10 @@ public function link($include_host = false) public function url($include_host = false) { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; /** @var Uri $uri */ - $uri = self::$grav['uri']; + $uri = self::getGrav()['uri']; $rootUrl = $uri->rootUrl($include_host) . $pages->base(); $url = $rootUrl.'/'.trim($this->route(), '/'); @@ -1257,7 +1263,7 @@ public function maxCount($var = null) } if (empty($this->max_count)) { /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; $this->max_count = (int) $config->get('system.pages.list.count'); } return $this->max_count; @@ -1332,7 +1338,7 @@ public function parent(Page $var = null) } /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->get($this->parent); } @@ -1345,7 +1351,7 @@ public function parent(Page $var = null) public function children() { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->children($this->path()); } @@ -1412,7 +1418,7 @@ public function adjacentSibling($direction = 1) public function active() { /** @var Uri $uri */ - $uri = self::$grav['uri']; + $uri = self::getGrav()['uri']; if ($this->url() == $uri->url()) { return true; } @@ -1428,8 +1434,8 @@ public function active() public function activeChild() { /** @var Uri $uri */ - $uri = self::$grav['uri']; - $config = self::$grav['config']; + $uri = self::getGrav()['uri']; + $config = self::getGrav()['config']; // Special check when item is home if ($this->home()) { @@ -1483,7 +1489,7 @@ public function root() public function find($url, $all = false) { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; return $pages->dispatch($url, $all); } @@ -1515,9 +1521,9 @@ public function collection($params = 'content', $pagination = true) // TODO: MOVE THIS INTO SOMEWHERE ELSE? /** @var Uri $uri */ - $uri = self::$grav['uri']; + $uri = self::getGrav()['uri']; /** @var Config $config */ - $config = self::$grav['config']; + $config = self::getGrav()['config']; foreach ((array) $config->get('site.taxonomies') as $taxonomy) { if ($uri->param($taxonomy)) { @@ -1553,7 +1559,7 @@ public function collection($params = 'content', $pagination = true) } /** @var Grav $grav */ - $grav = self::$grav['grav']; + $grav = self::getGrav()['grav']; // New Custom event to handle things like pagination. $grav->fireEvent('onCollectionProcessed', new Event(['collection' => $collection])); @@ -1633,7 +1639,7 @@ protected function evaluate($value) // @taxonomy: { category: [ blog, featured ], level: 1 } /** @var Taxonomy $taxonomy_map */ - $taxonomy_map = self::$grav['taxonomy']; + $taxonomy_map = self::getGrav()['taxonomy']; if (!empty($parts)) { $params = [implode('.', $parts) => $params]; @@ -1709,7 +1715,7 @@ protected function doRelocation($reorder) // Do reordering. if ($reorder && $this->order() != $this->_original->order()) { /** @var Pages $pages */ - $pages = self::$grav['pages']; + $pages = self::getGrav()['pages']; $parent = $this->parent(); diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index b264f722b7..ea000c247a 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -142,6 +142,8 @@ protected function mergeConfig(Page $page) // Get default plugin configurations and retrieve page header configuration if (isset($page->header()->$class_name)) { $header = array_merge($defaults, $page->header()->$class_name); + } else { + $header = $defaults; } // Create new config object and set it on the page object so it's cached for next time diff --git a/system/src/Grav/Common/Plugins.php b/system/src/Grav/Common/Plugins.php index 7397c8bb1f..dd495963e3 100644 --- a/system/src/Grav/Common/Plugins.php +++ b/system/src/Grav/Common/Plugins.php @@ -54,7 +54,7 @@ public function init() $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 e7620cede4..e44472835d 100644 --- a/system/src/Grav/Common/Themes.php +++ b/system/src/Grav/Common/Themes.php @@ -145,10 +145,19 @@ public function load() $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/User/User.php b/system/src/Grav/Common/User/User.php index 8da0896fe4..80c0f9a0f8 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -26,7 +26,7 @@ class User extends Data */ public static function load($username) { - $locator = self::$grav['locator']; + $locator = self::getGrav()['locator']; // FIXME: validate directory name $blueprints = new Blueprints('blueprints://user'); diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index ecee736764..ac4f95f0ff 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -46,7 +46,8 @@ public static function mergeObjects($obj1, $obj2) * @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 @@ public static function rrmdir($dir) { /** @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 @@ public static function rrmdir($dir) { * @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 diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 4ad07bc4b3..42c65d4953 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -35,8 +35,8 @@ trait ConsoleTrait */ public function setupConsole(InputInterface $input, OutputInterface $output) { - if (self::$grav) { - self::$grav['config']->set('system.cache.driver', 'default'); + if (self::getGrav()) { + self::getGrav()['config']->set('system.cache.driver', 'default'); } $this->argv = $_SERVER['argv'][0]; diff --git a/system/src/Grav/Console/Gpm/UninstallCommand.php b/system/src/Grav/Console/Gpm/UninstallCommand.php index fdd28a5203..085612c4f7 100644 --- a/system/src/Grav/Console/Gpm/UninstallCommand.php +++ b/system/src/Grav/Console/Gpm/UninstallCommand.php @@ -140,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output) */ private function uninstallPackage($package) { - $path = self::$grav['locator']->findResource($package->package_type . '://' . $package->slug); + $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $package->slug); Installer::uninstall($path); $errorCode = Installer::lastErrorCode(); @@ -167,7 +167,7 @@ private function uninstallPackage($package) private function checkDestination($package) { - $path = self::$grav['locator']->findResource($package->package_type . '://' . $package->slug); + $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $package->slug); $questionHelper = $this->getHelper('question'); $skipPrompt = $this->input->getOption('all-yes');