diff --git a/content/3_for-developers/03-twig.md b/content/3_for-developers/03-twig.md
index ce60ea2..36f9c91 100644
--- a/content/3_for-developers/03-twig.md
+++ b/content/3_for-developers/03-twig.md
@@ -8,6 +8,8 @@ Twig is a flexible, fast and secure template engine for PHP. If you have never u
The full Twig documentation for template designers is just one page long, so just head [over to Twig](http://twig.sensiolabs.org/doc/2.x/templates.html) and read it. You can learn the most important essentials for TYPEMILL in the following list.
+[TOC]
+
## Basic Twig Syntax
In a Twig template, you can use ordinary HTML markup. Statements and expressions are written in curly brackets.
@@ -183,9 +185,9 @@ Macros in Twig are like functions in PHP: You can use them for repeating tasks.
This is an example for a navigation:
{% macro loop_over(navigation) %}
-
+
{% import _self as macros %}
-
+
{% for element in navigation %}
{% if element.elementType == 'folder' %}
diff --git a/content/3_for-developers/05-theme-variables/10-item.md b/content/3_for-developers/05-theme-variables/10-item.md
index 214901d..75c120b 100644
--- a/content/3_for-developers/05-theme-variables/10-item.md
+++ b/content/3_for-developers/05-theme-variables/10-item.md
@@ -4,6 +4,8 @@ The item variable is an object. It provides informations about the actual page,
Some informations are only available for the type `folder` while some other informations are specific to the type `file`. But most informations are shared by both.
+[TOC]
+
## Example of the {{ item }} variable
This is an example of an item variable:
diff --git a/system/Assets.php b/system/Assets.php
index 8c34038..0860540 100644
--- a/system/Assets.php
+++ b/system/Assets.php
@@ -17,15 +17,14 @@ class Assets
public function addCSS(string $CSS)
{
- $CSSpath = __DIR__ . '/../plugins' . $CSS;
-
- if(file_exists($CSSfile))
+ $CSSfile = $this->getFileUrl($CSS);
+
+ if($CSSfile)
{
- $CSSfile = $this->baseUrl . '/plugins' . $CSS;
$this->CSS[] = '';
}
}
-
+
public function addInlineCSS($CSS)
{
$this->inlineCSS[] = '';
@@ -33,11 +32,10 @@ class Assets
public function addJS(string $JS)
{
- $JSpath = __DIR__ . '/../plugins' . $JS;
+ $JSfile = $this->getFileUrl($JS);
- if(file_exists($JSpath))
+ if($JSfile)
{
- $JSfile = $this->baseUrl . '/plugins' . $JS;
$this->JS[] = '';
}
}
@@ -56,4 +54,26 @@ class Assets
{
return implode(' ', $this->JS) . implode(' ', $this->inlineJS);
}
+
+ /**
+ * Checks, if a string is a valid internal or external ressource like js-file or css-file
+ * @params $path string
+ * @return string or false
+ */
+ public function getFileUrl(string $path)
+ {
+ $internalFile = __DIR__ . '/../plugins' . $path;
+
+ if(file_exists($internalFile))
+ {
+ return $this->baseUrl . '/plugins' . $path;
+ }
+
+ if(fopen($path, "r"))
+ {
+ return $path;
+ }
+
+ return false;
+ }
}
\ No newline at end of file
diff --git a/system/Controllers/PageController.php b/system/Controllers/PageController.php
index 77dc8c1..8999859 100644
--- a/system/Controllers/PageController.php
+++ b/system/Controllers/PageController.php
@@ -10,6 +10,8 @@ use \Symfony\Component\Yaml\Yaml;
use Typemill\Models\VersionCheck;
use Typemill\Models\Helpers;
use Typemill\Events\LoadPagetreeEvent;
+use Typemill\Events\LoadBreadcrumbEvent;
+use Typemill\Events\LoadItemEvent;
use Typemill\Events\LoadMarkdownEvent;
use Typemill\Events\ParseHtmlEvent;
use Typemill\Extensions\ParsedownExtension;
@@ -53,7 +55,7 @@ class PageController extends Controller
$this->render($response, '/index.twig', [ 'content' => $content ]);
}
elseif(!$cache->validate('cache', 'lastSitemap.txt', 86400))
- {
+ {
/* update sitemap */
$sitemap = new WriteSitemap();
$sitemap->updateSitemap('cache', 'sitemap.xml', 'lastSitemap.txt', $structure, $uri->getBaseUrl());
@@ -74,7 +76,7 @@ class PageController extends Controller
/* if the user is on startpage */
if(empty($args))
- {
+ {
/* check, if there is an index-file in the root of the content folder */
$contentMD = file_exists($pathToContent . DIRECTORY_SEPARATOR . 'index.md') ? file_get_contents($pathToContent . DIRECTORY_SEPARATOR . 'index.md') : NULL;
}
@@ -102,9 +104,11 @@ class PageController extends Controller
/* get breadcrumb for page */
$breadcrumb = Folder::getBreadcrumb($structure, $item->keyPathArray);
-
+ $breadcrumb = $this->c->dispatcher->dispatch('onBreadcrumbLoaded', new LoadBreadcrumbEvent($breadcrumb))->getData();
+
/* add the paging to the item */
$item = Folder::getPagingForItem($structure, $item);
+ $item = $this->c->dispatcher->dispatch('onItemLoaded', new LoadItemEvent($item))->getData();
/* check if url is a folder. If so, check if there is an index-file in that folder */
if($item->elementType == 'folder' && $item->index)
@@ -128,7 +132,7 @@ class PageController extends Controller
/* parse markdown-file to html-string */
$contentHTML = $Parsedown->text($contentMD);
$contentHTML = $this->c->dispatcher->dispatch('onHtmlParsed', new ParseHtmlEvent($contentHTML))->getData();
-
+
$excerpt = substr($contentHTML,0,200);
$excerpt = explode("", $excerpt);
$title = isset($excerpt[0]) ? strip_tags($excerpt[0]) : $settings['title'];
@@ -192,6 +196,6 @@ class PageController extends Controller
$yaml->updateYaml('settings', 'settings.yaml', $userSettings);
}
}
- }
- }
+ }
+ }
}
\ No newline at end of file
diff --git a/system/Events/BaseEvent.php b/system/Events/BaseEvent.php
new file mode 100644
index 0000000..c05ab6d
--- /dev/null
+++ b/system/Events/BaseEvent.php
@@ -0,0 +1,25 @@
+data = $data;
+ }
+
+ public function getData()
+ {
+ return $this->data;
+ }
+
+ public function setData($data)
+ {
+ $this->data = $data;
+ }
+}
\ No newline at end of file
diff --git a/system/Events/LoadBreadcrumbEvent.php b/system/Events/LoadBreadcrumbEvent.php
new file mode 100644
index 0000000..ca0b95d
--- /dev/null
+++ b/system/Events/LoadBreadcrumbEvent.php
@@ -0,0 +1,14 @@
+data = $data;
- }
-
- public function getData()
- {
- return $this->data;
- }
-
- public function setData($data)
- {
- $this->data = $data;
- }
}
\ No newline at end of file
diff --git a/system/Events/LoadPagetreeEvent.php b/system/Events/LoadPagetreeEvent.php
index 7db00e8..42411e4 100644
--- a/system/Events/LoadPagetreeEvent.php
+++ b/system/Events/LoadPagetreeEvent.php
@@ -5,25 +5,10 @@ namespace Typemill\Events;
use Symfony\Component\EventDispatcher\Event;
/**
- * Event for the folder structure.
+ * Event for the page tree.
*/
-class LoadPagetreeEvent extends Event
+class LoadPagetreeEvent extends BaseEvent
{
- protected $data;
- public function __construct($data)
- {
- $this->data = $data;
- }
-
- public function getData()
- {
- return $this->data;
- }
-
- public function setData($data)
- {
- $this->data = $data;
- }
}
\ No newline at end of file
diff --git a/system/Events/LoadPluginsEvent.php b/system/Events/LoadPluginsEvent.php
new file mode 100644
index 0000000..d9f81a2
--- /dev/null
+++ b/system/Events/LoadPluginsEvent.php
@@ -0,0 +1,14 @@
+data = $data;
- }
-
- public function getData()
- {
- return $this->data;
- }
-
- public function setData($data)
- {
- $this->data = $data;
- }
}
\ No newline at end of file
diff --git a/system/Events/RenderPageEvent.php b/system/Events/RenderPageEvent.php
index 538e69f..2035a11 100644
--- a/system/Events/RenderPageEvent.php
+++ b/system/Events/RenderPageEvent.php
@@ -5,25 +5,10 @@ namespace Typemill\Events;
use Symfony\Component\EventDispatcher\Event;
/**
- * Event for the pure content.
+ * Event for the page rendering data.
*/
-class RenderPageEvent extends Event
+class RenderPageEvent extends BaseEvent
{
- protected $data;
- public function __construct($data)
- {
- $this->data = $data;
- }
-
- public function getData()
- {
- return $this->data;
- }
-
- public function setData($data)
- {
- $this->data = $data;
- }
}
\ No newline at end of file
diff --git a/system/Plugin.php b/system/Plugin.php
index b526bc1..3f4e7dc 100644
--- a/system/Plugin.php
+++ b/system/Plugin.php
@@ -5,23 +5,17 @@ namespace Typemill;
use \Symfony\Component\EventDispatcher\EventSubscriberInterface;
abstract class Plugin implements EventSubscriberInterface
-{
-
- private $app;
-
+{
private $container;
/**
- * Constructor.
+ * Constructor
*
- * @param string $name
- * @param Grav $grav
- * @param Config $config
*/
- public function __construct($container, $app)
+
+ public function __construct($container)
{
$this->container = $container;
- $this->app = $app;
}
protected function getRoute()
diff --git a/system/Plugins.php b/system/Plugins.php
index 2d03506..fe3d0e4 100644
--- a/system/Plugins.php
+++ b/system/Plugins.php
@@ -12,7 +12,6 @@ class Plugins
/* iterate over plugin folders */
foreach($pluginFolder as $plugin)
{
-
$className = DIRECTORY_SEPARATOR . 'Plugins' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR . $plugin;
/* if plugin-class and subscribe-method exists, add classname to array */
@@ -26,7 +25,6 @@ class Plugins
public function getNewRoutes($className, $routes)
{
-
/* if route-method exists in plugin-class */
if(method_exists($className, 'addNewRoutes'))
{
@@ -59,13 +57,19 @@ class Plugins
return $routes;
}
- public function getNewMiddleware($className)
+ public function getNewMiddleware($className, $middleware)
{
if(method_exists($className, 'addNewMiddleware'))
{
- /* check array */
- return $className::addNewMiddleware();
+ $pluginMiddleware = $className::addNewMiddleware();
+
+ if($pluginMiddleware)
+ {
+ $middleware[] = $pluginMiddleware;
+ }
}
+
+ return $middleware;
}
private function checkRouteArray($routes,$route)
diff --git a/system/system.php b/system/system.php
index 340a90b..cb77cc5 100644
--- a/system/system.php
+++ b/system/system.php
@@ -1,7 +1,7 @@
dispatch('onSettingsLoaded', new LoadSettingsEvent($settings))->getData();
/************************
* INITIATE SLIM *
@@ -27,12 +34,6 @@ $app = new \Slim\App($settings);
$container = $app->getContainer();
-/****************************
-* CREATE EVENT DISPATCHER *
-****************************/
-
-$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
-
/************************
* LOAD PLUGINS *
************************/
@@ -45,11 +46,11 @@ foreach($pluginClassNames as $pluginClassName)
{
$routes = $plugins->getNewRoutes($pluginClassName, $routes);
$middleware = $plugins->getNewMiddleware($pluginClassName, $middleware);
-
- $dispatcher->addSubscriber(new $pluginClassName($container, $app));
+
+ $dispatcher->addSubscriber(new $pluginClassName($container));
}
-$dispatcher->dispatch('onPluginsInitialized');
+$dispatcher->dispatch('onPluginsLoaded', new LoadPluginsEvent($pluginClassNames));
/******************************
* ADD DISPATCHER TO CONTAINER *
@@ -107,15 +108,29 @@ $container['view'] = function ($container) use ($settings)
$container->dispatcher->dispatch('onTwigLoaded');
-/************************
-* ADD MIDDLEWARE *
-************************/
+/***************************
+* ADD NOT FOUND HANDLER *
+***************************/
$container['notFoundHandler'] = function($c)
{
return new \Typemill\Handlers\NotFoundHandler($c['view']);
};
+/************************
+* ADD MIDDLEWARE *
+************************/
+
+foreach($middleware as $pluginMiddleware)
+{
+ $middlewareClass = $pluginMiddleware['classname'];
+ $middlewareParams = $pluginMiddleware['params'];
+ if(class_exists($middlewareClass))
+ {
+ $app->add(new $middlewareClass($middlewareParams));
+ }
+}
+
/************************
* ADD ROUTES *
************************/
diff --git a/themes/typemill/partials/layout.twig b/themes/typemill/partials/layout.twig
index 0975499..2f19560 100644
--- a/themes/typemill/partials/layout.twig
+++ b/themes/typemill/partials/layout.twig
@@ -34,7 +34,6 @@
{% block content %}{% endblock %}
- {{content|rot13}}
diff --git a/typemill-1.0.5.zip b/typemill-1.0.5.zip
new file mode 100644
index 0000000..f3004f0
Binary files /dev/null and b/typemill-1.0.5.zip differ