Merge branch 'release/0.9.17'

This commit is contained in:
Andy Miller
2015-02-05 20:59:46 -07:00
19 changed files with 128 additions and 90 deletions

View File

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

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

@@ -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('RAW_CONTENT', 1);
define('TWIG_CONTENT', 2);
define('TWIG_CONTENT_LIST', 3);
define('TWIG_TEMPLATES', 4);
// Misc Defines
define('SUMMARY_DELIMITER', '===');

View File

@@ -163,8 +163,8 @@ class Assets
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 @@ 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] = [
@@ -352,7 +358,7 @@ class Assets
}
// 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 @@ class Assets
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 @@ class Assets
protected function buildLocalLink($asset)
{
try {
$asset = self::$grav['locator']->findResource($asset, false);
$asset = self::getGrav()['locator']->findResource($asset, false);
} catch (\Exception $e) {
}

View File

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

View File

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

View File

@@ -31,7 +31,7 @@ class Collection extends Iterator {
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;

View File

@@ -13,6 +13,9 @@ trait GravTrait
*/
public function getGrav()
{
if (!self::$grav) {
self::$grav = Grav::instance();
}
return self::$grav;
}

View File

@@ -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 @@ trait ParsedownGravTrait
} else {
// Create the custom lightbox element
$attributes = $data['a_attributes'];
$attributes['href'] = $data['a_href'];

View File

@@ -55,7 +55,7 @@ class Media extends Getters
$medium = $this->get("{$basename}.{$ext}");
if (!$alternative) {
$medium = $medium ? $medium : $this->createMedium($info->getPathname());
if (!$medium) {
@@ -70,7 +70,7 @@ class Media extends Getters
} else {
$altMedium = $this->createMedium($info->getPathname());
if (!$altMedium) {
continue;
}
@@ -86,7 +86,7 @@ class Media extends Getters
}
$medium = $medium ? $medium : $this->scaleMedium($altMedium, $alternative, 1);
$medium->addAlternative($this->parseRatio($alternative), $altMedium);
}
@@ -186,7 +186,7 @@ class Media extends Getters
* Create a Medium object from a file
*
* @param string $file
*
*
* @return Medium|null
*/
protected function createMedium($file)
@@ -202,7 +202,7 @@ class Media extends Getters
$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 @@ class Media extends Getters
'modified' => filemtime($file),
);
$locator = self::$grav['locator'];
$locator = self::getGrav()['locator'];
$lookup = $locator->findResources('image://');
foreach ($lookup as $lookupPath) {
@@ -257,7 +257,7 @@ class Media extends Getters
$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);

View File

@@ -120,16 +120,7 @@ class Medium extends Data
$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 @@ class Medium extends Data
$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 @@ class Medium extends Data
}
} 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 @@ class Medium extends Data
*/
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 @@ class Medium extends Data
$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));
}

View File

@@ -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 @@ class Page
$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 @@ class Page
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 @@ 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
*
@@ -357,7 +362,7 @@ class Page
// 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 @@ class Page
// 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 @@ class Page
}
// Handle summary divider
$divider_pos = strpos($this->content, '<p>'.SUMMARY_DELIMITER.'</p>');
$delimiter = self::getGrav()['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);
}
}
@@ -424,7 +430,7 @@ class Page
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 @@ class Page
*/
private function processTwig()
{
$twig = self::$grav['twig'];
$twig = self::getGrav()['twig'];
$this->content = $twig->processPage($this, $this->content);
}
@@ -466,10 +472,10 @@ class Page
*/
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 @@ class Page
public function blueprints()
{
/** @var Pages $pages */
$pages = self::$grav['pages'];
$pages = self::getGrav()['pages'];
return $pages->blueprints($this->template());
}
@@ -723,7 +729,7 @@ class Page
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 @@ class Page
// 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 @@ class Page
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 @@ class Page
}
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 @@ class Page
}
/** @var Pages $pages */
$pages = self::$grav['pages'];
$pages = self::getGrav()['pages'];
return $pages->get($this->parent);
}
@@ -1345,7 +1351,7 @@ class Page
public function children()
{
/** @var Pages $pages */
$pages = self::$grav['pages'];
$pages = self::getGrav()['pages'];
return $pages->children($this->path());
}
@@ -1412,7 +1418,7 @@ class Page
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 @@ class Page
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 @@ class Page
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 @@ class Page
// 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 @@ class Page
}
/** @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 @@ class Page
// @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 @@ class Page
// Do reordering.
if ($reorder && $this->order() != $this->_original->order()) {
/** @var Pages $pages */
$pages = self::$grav['pages'];
$pages = self::getGrav()['pages'];
$parent = $this->parent();

View File

@@ -142,6 +142,8 @@ class Plugin implements EventSubscriberInterface
// 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

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

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

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

View File

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

View File

@@ -140,7 +140,7 @@ class UninstallCommand extends Command
*/
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 @@ class UninstallCommand extends Command
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');