From 627aa4da67f8d70bc00b753a20bcd4e01a532880 Mon Sep 17 00:00:00 2001 From: trendschau Date: Fri, 17 Dec 2021 15:41:30 +0100 Subject: [PATCH] Set meta tags with assets with assets.renderMeta --- plugins/demouser/demouser.php | 85 ------------------- plugins/demouser/demouser.yaml | 18 ---- plugins/demouser/templates/demouser.twig | 10 --- system/Assets.php | 46 ++++++---- .../Controllers/ControllerFrontendWebsite.php | 26 +++++- themes/cyanine/layout.twig | 30 +------ 6 files changed, 58 insertions(+), 157 deletions(-) delete mode 100644 plugins/demouser/demouser.php delete mode 100644 plugins/demouser/demouser.yaml delete mode 100644 plugins/demouser/templates/demouser.twig diff --git a/plugins/demouser/demouser.php b/plugins/demouser/demouser.php deleted file mode 100644 index f22ce21..0000000 --- a/plugins/demouser/demouser.php +++ /dev/null @@ -1,85 +0,0 @@ - 'onSystemnaviLoaded', - 'onRolesPermissionsLoaded' => 'onRolesPermissionsLoaded', - 'onPageReady' => 'onPageReady', - ); - } - - # add routes - public static function addNewRoutes() - { - return [ - ['httpMethod' => 'get', 'route' => '/tm/demoaccess', 'name' => 'demoaccess.show', 'class' => 'Typemill\Controllers\ControllerSettings:showBlank', 'resource' => 'user', 'privilege' => 'view'], - ]; - } - - # add new navi-items into the admin settings - public function onSystemnaviLoaded($navidata) - { - $this->addSvgSymbol(''); - $navi = $navidata->getData(); - - $navi['Demoaccess'] = ['routename' => 'demoaccess.show', 'icon' => 'icon-key', 'aclresource' => 'user', 'aclprivilege' => 'view']; - - # set the navigation item active - if(trim($this->getPath(),"/") == 'tm/demoaccess') - { - $navi['Demoaccess']['active'] = true; - } - - $navidata->setData($navi); - } - - - public function onRolesPermissionsLoaded($rolesAndPermissions) - { - $rolesPermissions = $rolesAndPermissions->getData(); - - $demoauthor = [ - 'name' => 'demoauthor', - 'inherits' => 'author', - 'permissions' => [ - 'mycontent' => ['delete'], - 'content' => ['create', 'update'], - ] - ]; - $rolesPermissions['demoauthor'] = $demoauthor; - $rolesAndPermissions->setData($rolesPermissions); - } - - # show subscriberlist in admin area - public function onPageReady($data) - { - # admin stuff - if($this->adminpath && $this->path == 'tm/demoaccess') - { - $settings = $this->getSettings(); - $username = isset($settings['plugins']['demouser']['demouser']) ? $settings['plugins']['demouser']['demouser'] : 'not set'; - $password = isset($settings['plugins']['demouser']['demopassword']) ? $settings['plugins']['demouser']['demopassword'] : 'not set'; - - $pagedata = $data->getData(); - - $twig = $this->getTwig(); - $loader = $twig->getLoader(); - $loader->addPath(__DIR__ . '/templates'); - - # fetch the template and render it with twig - $content = $twig->fetch('/demouser.twig', ['username' => $username, 'password' => $password]); - - $pagedata['content'] = $content; - - $data->setData($pagedata); - } - } - -} \ No newline at end of file diff --git a/plugins/demouser/demouser.yaml b/plugins/demouser/demouser.yaml deleted file mode 100644 index 1ef1fd0..0000000 --- a/plugins/demouser/demouser.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: Demouser -version: 1.0.0 -description: Add a new userrole for the demo-instance -author: Sebastian Schürmanns -homepage: https://typemill.net -licence: MIT -list: false - -forms: - fields: - - demouser: - type: text - label: Username for demo - - demopassword: - type: text - label: Password for demo \ No newline at end of file diff --git a/plugins/demouser/templates/demouser.twig b/plugins/demouser/templates/demouser.twig deleted file mode 100644 index 1f11773..0000000 --- a/plugins/demouser/templates/demouser.twig +++ /dev/null @@ -1,10 +0,0 @@ -
- -

Ihr Demo-Zugang

-

Mit den folgenden Angaben haben Sie Zugang zur Typemill-Demo. Die Zugangsdaten werden regelmäßig erneuert.

- -

Mit den Zugangsaten erhalten Sie vollen Zugriff als Administrator, sodass Sie das System ausgiebig testen können. Das System wird regelmäßig in den Ursprungszustand zurückgesetzt.

-
\ No newline at end of file diff --git a/system/Assets.php b/system/Assets.php index 7699819..59bfde1 100644 --- a/system/Assets.php +++ b/system/Assets.php @@ -19,6 +19,7 @@ class Assets $this->editorCSS = array(); $this->editorInlineJS = array(); $this->svgSymbols = array(); + $this->meta = array(); $this->imageUrl = false; $this->imageFolder = 'original'; } @@ -211,21 +212,6 @@ class Assets $this->svgSymbols[] = $symbol; } - public function renderCSS() - { - return implode("\n", $this->CSS) . implode("\n", $this->inlineCSS); - } - - public function renderJS() - { - return implode("\n", $this->JS) . implode("\n", $this->inlineJS); - } - - public function renderSvg() - { - return implode('', $this->svgSymbols); - } - # add JS to enhance the blox-editor in author area public function addEditorJS($JS) { @@ -252,6 +238,11 @@ class Assets } } + public function addMeta($key,$meta) + { + $this->meta[$key] = $meta; + } + public function renderEditorJS() { return implode("\n", $this->editorJS) . implode("\n", $this->editorInlineJS); @@ -262,6 +253,31 @@ class Assets return implode("\n", $this->editorCSS); } + public function renderCSS() + { + return implode("\n", $this->CSS) . implode("\n", $this->inlineCSS); + } + + public function renderJS() + { + return implode("\n", $this->JS) . implode("\n", $this->inlineJS); + } + + public function renderSvg() + { + return implode('', $this->svgSymbols); + } + + public function renderMeta() + { + $metaLines = ''; + foreach($this->meta as $meta) + { + $metaLines .= "\n"; + $metaLines .= $meta; + } + return $metaLines; + } /** * Checks, if a string is a valid internal or external ressource like js-file or css-file * @params $path string diff --git a/system/Controllers/ControllerFrontendWebsite.php b/system/Controllers/ControllerFrontendWebsite.php index 0e967e4..ace5244 100644 --- a/system/Controllers/ControllerFrontendWebsite.php +++ b/system/Controllers/ControllerFrontendWebsite.php @@ -87,7 +87,15 @@ class ControllerFrontendWebsite extends ControllerShared if(isset($this->settings['favicon']) && $this->settings['favicon'] != '') { $favicon = true; - } + $this->c->assets->addMeta('tilecolor',''); + $this->c->assets->addMeta('tileimage',''); + $this->c->assets->addMeta('icon16',''); + $this->c->assets->addMeta('icon32',''); + $this->c->assets->addMeta('icon72',''); + $this->c->assets->addMeta('icon114',''); + $this->c->assets->addMeta('icon144',''); + $this->c->assets->addMeta('icon180',''); + } # the navigation is a copy of the structure without the hidden pages # hint: if the navigation has been deleted from the cache, then we do not recreate it here to save performace. Instead you have to recreate cache in admin or change a page (publish/unpublish/delete/move) @@ -219,6 +227,18 @@ class ControllerFrontendWebsite extends ControllerShared # makes sure that you always have the full meta with title, description and all the rest. $metatabs = $writeMeta->completePageMeta($contentMD, $this->settings, $item); + # write meta + if(isset($metatabs['meta']['noindex']) && $metatabs['meta']['noindex']) + { + $this->c->assets->addMeta('noindex',''); + } + + $this->c->assets->addMeta('og_site_name',''); + $this->c->assets->addMeta('og_title',''); + $this->c->assets->addMeta('og_description',''); + $this->c->assets->addMeta('og_type',''); + $this->c->assets->addMeta('og_url',''); + # dispatch meta $metatabs = $this->c->dispatcher->dispatch('onMetaLoaded', new OnMetaLoaded($metatabs))->getData(); @@ -320,6 +340,10 @@ class ControllerFrontendWebsite extends ControllerShared if($img_url) { $firstImage = array('img_url' => $this->base_url . '/' . $img_url, 'img_alt' => $img_alt); + + $this->c->assets->addMeta('og_image',''); + $this->c->assets->addMeta('twitter_image_alt',''); + $this->c->assets->addMeta('twitter_card',''); } $route = empty($args) && isset($this->settings['themes'][$theme]['cover']) ? '/cover.twig' : '/index.twig'; diff --git a/themes/cyanine/layout.twig b/themes/cyanine/layout.twig index cf0b842..097b3c9 100644 --- a/themes/cyanine/layout.twig +++ b/themes/cyanine/layout.twig @@ -8,35 +8,9 @@ - - - {% if metatabs.meta.noindex %} - - {% endif %} - - {% if favicon %} - - - - - - - - - {% endif %} - - - - - - - - {% if image.img_url %} - - - {% endif %} - + + {{ assets.renderMeta() }} {% block stylesheets %}