mirror of
https://github.com/typemill/typemill.git
synced 2025-07-31 19:30:40 +02:00
latest 20171218
This commit is contained in:
@@ -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 %}
|
||||
<li>
|
||||
{% if element.elementType == 'folder' %}
|
||||
|
@@ -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:
|
||||
|
@@ -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[] = '<link rel="stylesheet" href="' . $CSSfile . '" />';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function addInlineCSS($CSS)
|
||||
{
|
||||
$this->inlineCSS[] = '<style>' . $CSS . '</style>';
|
||||
@@ -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[] = '<script src="' . $JSfile . '"></script>';
|
||||
}
|
||||
}
|
||||
@@ -56,4 +54,26 @@ class Assets
|
||||
{
|
||||
return implode('<br/>', $this->JS) . implode('<br/>', $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;
|
||||
}
|
||||
}
|
@@ -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("</h1>", $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
system/Events/BaseEvent.php
Normal file
25
system/Events/BaseEvent.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Typemill\Events;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
class BaseEvent extends Event
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
14
system/Events/LoadBreadcrumbEvent.php
Normal file
14
system/Events/LoadBreadcrumbEvent.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Typemill\Events;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Event for breadcrumb.
|
||||
*/
|
||||
|
||||
class LoadBreadcrumbEvent extends BaseEvent
|
||||
{
|
||||
|
||||
}
|
14
system/Events/LoadItemEvent.php
Normal file
14
system/Events/LoadItemEvent.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Typemill\Events;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Event for item.
|
||||
*/
|
||||
|
||||
class LoadItemEvent extends BaseEvent
|
||||
{
|
||||
|
||||
}
|
@@ -5,25 +5,10 @@ namespace Typemill\Events;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Event for the pure content.
|
||||
* Event for markdown.
|
||||
*/
|
||||
|
||||
class LoadMarkdownEvent extends Event
|
||||
class LoadMarkdownEvent extends BaseEvent
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
14
system/Events/LoadPluginsEvent.php
Normal file
14
system/Events/LoadPluginsEvent.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Typemill\Events;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Event for the folder structure.
|
||||
*/
|
||||
|
||||
class LoadPluginsEvent extends BaseEvent
|
||||
{
|
||||
|
||||
}
|
14
system/Events/LoadSettingsEvent.php
Normal file
14
system/Events/LoadSettingsEvent.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Typemill\Events;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Event for settings
|
||||
*/
|
||||
|
||||
class LoadSettingsEvent extends BaseEvent
|
||||
{
|
||||
|
||||
}
|
@@ -5,25 +5,10 @@ namespace Typemill\Events;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Event for the pure content.
|
||||
* Event for html page.
|
||||
*/
|
||||
|
||||
class ParseHtmlEvent extends Event
|
||||
class ParseHtmlEvent extends BaseEvent
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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()
|
||||
|
@@ -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)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Typemill\Models\Helpers;
|
||||
$timer['before session start']=microtime(true);
|
||||
use Typemill\Events\LoadSettingsEvent;
|
||||
use Typemill\Events\LoadPluginsEvent;
|
||||
|
||||
/************************
|
||||
* START SESSION *
|
||||
@@ -9,11 +9,18 @@ $timer['before session start']=microtime(true);
|
||||
|
||||
session_start();
|
||||
|
||||
/****************************
|
||||
* CREATE EVENT DISPATCHER *
|
||||
****************************/
|
||||
|
||||
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
|
||||
|
||||
/************************
|
||||
* LOAD SETTINGS *
|
||||
************************/
|
||||
|
||||
$settings = Typemill\settings::loadSettings();
|
||||
$settings = $dispatcher->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 *
|
||||
************************/
|
||||
|
@@ -34,7 +34,6 @@
|
||||
</header>
|
||||
<article>
|
||||
{% block content %}{% endblock %}
|
||||
<small>{{content|rot13}}</small>
|
||||
</article>
|
||||
<aside id="navigation" class="close">
|
||||
<nav>
|
||||
@@ -42,7 +41,6 @@
|
||||
</nav>
|
||||
</aside>
|
||||
<footer>
|
||||
<p>hello {{ myName() }}</p>
|
||||
{% include 'partials/footer.twig' %}
|
||||
</footer>
|
||||
</div>
|
||||
|
BIN
typemill-1.0.5.zip
Normal file
BIN
typemill-1.0.5.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user