diff --git a/composer.json b/composer.json index 9129efeb..c83688e8 100755 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "authors": [ { "name": "Sergey Romanenko", - "email": "hello@romanenko.digital", + "email": "support@flextype.org", "homepage": "http://digital.flextype.org" } ], @@ -38,7 +38,6 @@ "flextype-components/text" : "1.1.2", "slim/slim": "~3.12.3", - "slim/twig-view": "~2.5.0", "slim/flash": "~0.4.0", "slim/csrf": "~0.8.3", diff --git a/flextype/bootstrap.php b/flextype/bootstrap.php index e9348285..2b3a2722 100755 --- a/flextype/bootstrap.php +++ b/flextype/bootstrap.php @@ -104,12 +104,6 @@ $app = new App([ 'outputBuffering' => $registry->get('flextype.output_buffering'), 'responseChunkSize' => $registry->get('flextype.response_chunk_size'), 'httpVersion' => $registry->get('flextype.http_version'), - 'twig' => [ - 'charset' => $registry->get('flextype.twig.charset'), - 'debug' => $registry->get('flextype.twig.debug'), - 'cache' => $registry->get('flextype.twig.cache') ? PATH['cache'] . '/twig' : false, - 'auto_reload' => $registry->get('flextype.twig.auto_reload'), - ], 'images' => [ 'driver' => $registry->get('flextype.image.driver'), ], diff --git a/flextype/dependencies.php b/flextype/dependencies.php index ef674048..b48940d7 100644 --- a/flextype/dependencies.php +++ b/flextype/dependencies.php @@ -38,10 +38,7 @@ use Slim\Csrf\Guard; use Slim\Flash\Messages; use Slim\Http\Environment; use Slim\Http\Uri; -use Slim\Views\Twig; -use Slim\Views\TwigExtension; use Thunder\Shortcode\ShortcodeFacade; -use Twig\Extension\DebugExtension; use function date; use function ucfirst; use function extension_loaded; @@ -216,42 +213,6 @@ $flextype['entries'] = static function ($container) { return new Entries($container); }; -/** - * Add view service to Flextype container - */ -$flextype['view'] = static function ($container) { - // Get twig settings - $twigSettings = $container->get('settings')['twig']; - - // Create Twig View - $view = new Twig(PATH['site'], $twigSettings); - - // Instantiate - $router = $container->get('router'); - $uri = Uri::createFromEnvironment(new Environment($_SERVER)); - - // Add Twig Extension - $view->addExtension(new TwigExtension($router, $uri)); - - // Add Twig Debug Extension - $view->addExtension(new DebugExtension()); - - // Load Flextype Twig extensions from directory /flextype/twig/ based on settings.twig.extensions array - $twig_extensions = $container['registry']->get('flextype.twig.extensions'); - - foreach ($twig_extensions as $twig_extension) { - $twig_extension_class_name = $twig_extension . 'TwigExtension'; - $twig_extension_class_name_with_namespace = 'Flextype\\' . $twig_extension . 'TwigExtension'; - - if (file_exists(ROOT_DIR . '/flextype/twig/' . $twig_extension_class_name . '.php')) { - $view->addExtension(new $twig_extension_class_name_with_namespace($container)); - } - } - - // Return view - return $view; -}; - /** * Add themes service to Flextype container */ diff --git a/flextype/twig/AssetsTwigExtension.php b/flextype/twig/AssetsTwigExtension.php deleted file mode 100644 index 13fb7670..00000000 --- a/flextype/twig/AssetsTwigExtension.php +++ /dev/null @@ -1,46 +0,0 @@ - new AssetsTwig(), - ]; - } -} - -class AssetsTwig -{ - /** - * Add Asset - */ - public function add(string $asset_type, string $asset, string $namespace, int $priority = 1) : void - { - Assets::add($asset_type, $asset, $namespace, $priority); - } - - /** - * Get Asset - */ - public function get(string $asset_type, string $namespace) : array - { - return Assets::get($asset_type, $namespace); - } -} diff --git a/flextype/twig/CacheTwigExtension.php b/flextype/twig/CacheTwigExtension.php deleted file mode 100644 index c9018de5..00000000 --- a/flextype/twig/CacheTwigExtension.php +++ /dev/null @@ -1,39 +0,0 @@ -flextype = $flextype; - } - - /** - * Register Global variables in an extension - */ - public function getGlobals() - { - return [ - 'cache' => $this->flextype['cache'], - ]; - } -} diff --git a/flextype/twig/CsrfTwigExtension.php b/flextype/twig/CsrfTwigExtension.php deleted file mode 100644 index efcaafe4..00000000 --- a/flextype/twig/CsrfTwigExtension.php +++ /dev/null @@ -1,79 +0,0 @@ -flextype = $flextype; - } - - /** - * Register Global variables in an extension - */ - public function getGlobals() - { - // CSRF token name and value - $csrfNameKey = $this->flextype->csrf->getTokenNameKey(); - $csrfValueKey = $this->flextype->csrf->getTokenValueKey(); - $csrfName = $this->flextype->csrf->getTokenName(); - $csrfValue = $this->flextype->csrf->getTokenValue(); - - return [ - 'csrf' => [ - 'keys' => [ - 'name' => $csrfNameKey, - 'value' => $csrfValueKey, - ], - 'name' => $csrfName, - 'value' => $csrfValue, - ], - ]; - } - - public function getName() - { - return 'slim/csrf'; - } - - /** - * Returns a list of functions to add to the existing list. - * - * @return array - */ - public function getFunctions() : array - { - return [ - new Twig_SimpleFunction('csrf', [$this, 'csrf'], ['is_safe' => ['html']]), - ]; - } - - /** - * CSRF - */ - public function csrf() : string - { - return '' . - ''; - } -} diff --git a/flextype/twig/DateTwigExtension.php b/flextype/twig/DateTwigExtension.php deleted file mode 100644 index 98bf677b..00000000 --- a/flextype/twig/DateTwigExtension.php +++ /dev/null @@ -1,108 +0,0 @@ - 'DD', - 'D' => 'ddd', - 'j' => 'D', - 'l' => 'dddd', - 'N' => 'E', - 'S' => 'Do', - 'w' => 'd', - 'z' => 'DDD', - // Week - 'W' => 'W', - // Month - 'F' => 'MMMM', - 'm' => 'MM', - 'M' => 'MMM', - 'n' => 'M', - 't' => '', - // Year - 'L' => '', - 'o' => 'GGGG', - 'Y' => 'YYYY', - 'y' => 'yy', - // Time - 'a' => 'a', - 'A' => 'A', - 'B' => 'SSS', - 'g' => 'h', - 'G' => 'H', - 'h' => 'hh', - 'H' => 'HH', - 'i' => 'mm', - 's' => 'ss', - 'u' => '', - // Timezone - 'e' => '', - 'I' => '', - 'O' => 'ZZ', - 'P' => 'Z', - 'T' => 'z', - 'Z' => '', - // Full Date/Time - 'c' => '', - 'r' => 'llll ZZ', - 'U' => 'X', - ]; - $js_format = ''; - $escaping = false; - $len = strlen($php_format); - for ($i = 0; $i < $len; $i++) { - $char = $php_format[$i]; - if ($char === '\\') { // PHP date format escaping character - $i++; - if ($escaping) { - $js_format .= $php_format[$i]; - } else { - $js_format .= '\'' . $php_format[$i]; - } - - $escaping = true; - } else { - if ($escaping) { - $js_format .= "'"; - $escaping = false; - } - - if (isset($symbols_matching[$char])) { - $js_format .= $symbols_matching[$char]; - } else { - $js_format .= $char; - } - } - } - - return $js_format; - } -} diff --git a/flextype/twig/EmitterTwigExtension.php b/flextype/twig/EmitterTwigExtension.php deleted file mode 100644 index 1a0ad1a7..00000000 --- a/flextype/twig/EmitterTwigExtension.php +++ /dev/null @@ -1,71 +0,0 @@ -flextype = $flextype; - } - - /** - * Register Global variables in an extension - */ - public function getGlobals() - { - return [ - 'emitter' => new EmitterTwig($this->flextype), - ]; - } -} - -class EmitterTwig -{ - /** - * Flextype Dependency Container - */ - private $flextype; - - /** - * Constructor - */ - public function __construct($flextype) - { - $this->flextype = $flextype; - } - - /** - * Emitting event - */ - public function emit($event) - { - return $this->flextype['emitter']->emit($event); - } - - /** - * Emitting events in batches - */ - public function emitBatch(array $events) - { - return $this->flextype['emitter']->emitBatch($events); - } -} diff --git a/flextype/twig/EntriesTwigExtension.php b/flextype/twig/EntriesTwigExtension.php deleted file mode 100644 index 384e426c..00000000 --- a/flextype/twig/EntriesTwigExtension.php +++ /dev/null @@ -1,79 +0,0 @@ -flextype = $flextype; - } - - /** - * Register Global variables in an extension - */ - public function getGlobals() - { - return [ - 'entries' => new EntriesTwig($this->flextype), - ]; - } -} - -class EntriesTwig -{ - /** - * Flextype Dependency Container - */ - private $flextype; - - /** - * Constructor - */ - public function __construct($flextype) - { - $this->flextype = $flextype; - } - - /** - * Fetch entry(entries) - */ - public function fetch(string $id, $args = null) : array - { - return $this->flextype['entries']->fetch($id, $args); - } - - /** - * Fetch single entry - */ - public function fetchSingle(string $id) : array - { - return $this->flextype['entries']->fetch($id); - } - - /** - * Fetch entries collection - */ - public function fetchCollection(string $id, array $args = []) : array - { - return $this->flextype['entries']->fetch($id, $args); - } -} diff --git a/flextype/twig/FilesystemTwigExtension.php b/flextype/twig/FilesystemTwigExtension.php deleted file mode 100644 index 8e48b6c0..00000000 --- a/flextype/twig/FilesystemTwigExtension.php +++ /dev/null @@ -1,61 +0,0 @@ -flextype = $flextype; - } - - /** - * Returns a list of functions to add to the existing list. - * - * @return array - */ - public function getFunctions() : array - { - return [ - new Twig_SimpleFunction('flash', [$this, 'getMessages']), - ]; - } - - /** - * Returns Flash messages; If key is provided then returns messages - * for that key. - * - * @return array - */ - public function getMessages(?string $key = null) : array - { - if ($key !== null) { - return $this->flextype['flash']->getMessage($key); - } - - return $this->flextype['flash']->getMessages(); - } -} diff --git a/flextype/twig/GlobalVarsTwigExtension.php b/flextype/twig/GlobalVarsTwigExtension.php deleted file mode 100644 index f59af8cc..00000000 --- a/flextype/twig/GlobalVarsTwigExtension.php +++ /dev/null @@ -1,55 +0,0 @@ -flextype = $flextype; - } - - /** - * Register Global variables in an extension - */ - public function getGlobals() - { - return [ - 'PATH_SITE' => PATH['site'], - 'PATH_PLUGINS' => PATH['plugins'], - 'PATH_ACCOUNTS' => PATH['accounts'], - 'PATH_UPLOADS' => PATH['uploads'], - 'PATH_TOKENS' => PATH['tokens'], - 'PATH_THEMES' => PATH['themes'], - 'PATH_ENTRIES' => PATH['entries'], - 'PATH_SNIPPETS' => PATH['snippets'], - 'PATH_FIELDSETS' => PATH['fieldsets'], - 'PATH_CONFIG_DEFAULT' => PATH['config']['default'], - 'PATH_CONFIG_SITE' => PATH['config']['site'], - 'PATH_CACHE' => PATH['cache'], - 'PATH_LOGS' => PATH['logs'], - 'FLEXTYPE_VERSION' => FLEXTYPE_VERSION, - 'PHP_VERSION' => PHP_VERSION, - 'registry' => $this->flextype['registry']->dump(), - ]; - } -} diff --git a/flextype/twig/I18nTwigExtension.php b/flextype/twig/I18nTwigExtension.php deleted file mode 100644 index 631fc0b3..00000000 --- a/flextype/twig/I18nTwigExtension.php +++ /dev/null @@ -1,50 +0,0 @@ -flextype = $flextype; - } - - /** - * Returns a list of functions to add to the existing list. - * - * @return array - */ - public function getFunctions() : array - { - return [ - new Twig_SimpleFunction('json_decode', [$this, 'decode']), - new Twig_SimpleFunction('json_encode', [$this, 'encode']), - ]; - } - - /** - * Returns a list of filters to add to the existing list. - * - * @return array - */ - public function getFilters() : array - { - return [ - new Twig_SimpleFilter('json_decode', [$this, 'decode']), - new Twig_SimpleFilter('json_encode', [$this, 'encode']), - ]; - } - - /** - * Encode JSON - */ - public function encode($input) : string - { - return $this->flextype['parser']->encode($input, 'json'); - } - - /** - * Decode JSON - */ - public function decode(string $input, bool $cache = true) - { - return $this->flextype['parser']->decode($input, 'json', $cache); - } -} diff --git a/flextype/twig/MarkdownTwigExtension.php b/flextype/twig/MarkdownTwigExtension.php deleted file mode 100644 index ee627b5a..00000000 --- a/flextype/twig/MarkdownTwigExtension.php +++ /dev/null @@ -1,49 +0,0 @@ -flextype = $flextype; - } - - /** - * Returns a list of filters to add to the existing list. - * - * @return array - */ - public function getFilters() : array - { - return [ - new Twig_SimpleFilter('markdown', [$this, 'markdown']), - ]; - } - - /** - * Markdown process - */ - public function markdown($input, bool $cache = true) : string - { - return $this->flextype['parser']->decode($input, 'markdown', $cache); - } -} diff --git a/flextype/twig/ParserTwigExtension.php b/flextype/twig/ParserTwigExtension.php deleted file mode 100644 index 80ad25aa..00000000 --- a/flextype/twig/ParserTwigExtension.php +++ /dev/null @@ -1,67 +0,0 @@ -flextype = $flextype; - } - - /** - * Returns a list of functions to add to the existing list. - * - * @return array - */ - public function getFunctions() : array - { - return [ - new Twig_SimpleFunction('parser_decode', [$this, 'decode']), - new Twig_SimpleFunction('parser_encode', [$this, 'encode']), - new Twig_SimpleFunction('parser_get_info', [$this, 'getParserInfo']), - ]; - } - - /** - * Get Parser Info - */ - public function getParserInfo(string $parser) : array - { - return $this->flextype['parser']->getParserInfo($parser); - } - - /** - * Encode - */ - public function encode($input, string $parser) - { - return $this->flextype['parser']->encode($input, $parser); - } - - /** - * Decode - */ - public function decode(string $input, string $parser, bool $cache = true) - { - return $this->flextype['parser']->decode($input, $parser, $cache); - } -} diff --git a/flextype/twig/ShortcodesTwigExtension.php b/flextype/twig/ShortcodesTwigExtension.php deleted file mode 100644 index 06b94794..00000000 --- a/flextype/twig/ShortcodesTwigExtension.php +++ /dev/null @@ -1,53 +0,0 @@ -flextype = $flextype; - } - - /** - * Returns a list of filters to add to the existing list. - * - * @return array - */ - public function getFilters() : array - { - return [ - new Twig_SimpleFilter('shortcode', [$this, 'shortcode']), - ]; - } - - /** - * Shorcode process - */ - public function shortcode($value) : string - { - if ($value !== null) { - return $this->flextype->shortcodes->process($value); - } - - return ''; - } -} diff --git a/flextype/twig/SnippetsTwigExtension.php b/flextype/twig/SnippetsTwigExtension.php deleted file mode 100644 index 065ede0f..00000000 --- a/flextype/twig/SnippetsTwigExtension.php +++ /dev/null @@ -1,63 +0,0 @@ -flextype = $flextype; - } - - /** - * Register Global variables in an extension - */ - public function getGlobals() - { - return [ - 'snippets' => new SnippetsTwig($this->flextype), - ]; - } -} - -class SnippetsTwig -{ - /** - * Flextype Dependency Container - */ - private $flextype; - - /** - * Constructor - */ - public function __construct($flextype) - { - $this->flextype = $flextype; - } - - /** - * Execute snippet - */ - public function exec($id) - { - return $this->flextype['snippets']->exec($id); - } -} diff --git a/flextype/twig/UrlTwigExtension.php b/flextype/twig/UrlTwigExtension.php deleted file mode 100644 index ed40ccdd..00000000 --- a/flextype/twig/UrlTwigExtension.php +++ /dev/null @@ -1,55 +0,0 @@ -flextype = $flextype; - } - - /** - * Callback for twig. - * - * @return array - */ - public function getFunctions() : array - { - return [ - new Twig_SimpleFunction('url', [$this, 'url'], ['is_safe' => ['html']]) - ]; - } - - /** - * Get App URL - */ - public function url() : string - { - if ($this->flextype['registry']->has('flextype.url') && $this->flextype['registry']->get('flextype.url') != '') { - return $this->flextype['registry']->get('flextype.url'); - } else { - return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); - } - } -} diff --git a/flextype/twig/YamlTwigExtension.php b/flextype/twig/YamlTwigExtension.php deleted file mode 100644 index 4b86c419..00000000 --- a/flextype/twig/YamlTwigExtension.php +++ /dev/null @@ -1,72 +0,0 @@ -flextype = $flextype; - } - - /** - * Returns a list of functions to add to the existing list. - * - * @return array - */ - public function getFunctions() : array - { - return [ - new Twig_SimpleFunction('yaml_decode', [$this, 'decode']), - new Twig_SimpleFunction('yaml_encode', [$this, 'encode']), - ]; - } - - /** - * Returns a list of filters to add to the existing list. - * - * @return array - */ - public function getFilters() : array - { - return [ - new Twig_SimpleFilter('yaml_decode', [$this, 'decode']), - new Twig_SimpleFilter('yaml_encode', [$this, 'encode']), - ]; - } - - /** - * Encode YAML - */ - public function encode($input) : string - { - return $this->flextype['parser']->encode($input, 'yaml'); - } - - /** - * Decode YAML - */ - public function decode(string $input, bool $cache = true) - { - return $this->flextype['parser']->decode($input, 'yaml', $cache); - } -}