mirror of
https://github.com/typemill/typemill.git
synced 2025-08-05 05:37:45 +02:00
Set meta tags with assets with assets.renderMeta
This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\demouser;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
|
||||
class Demouser extends Plugin
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'onSystemnaviLoaded' => '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('<symbol id="icon-key" viewBox="0 0 32 32"><path d="M22 0c-5.523 0-10 4.477-10 10 0 0.626 0.058 1.238 0.168 1.832l-12.168 12.168v6c0 1.105 0.895 2 2 2h2v-2h4v-4h4v-4h4l2.595-2.595c1.063 0.385 2.209 0.595 3.405 0.595 5.523 0 10-4.477 10-10s-4.477-10-10-10zM24.996 10.004c-1.657 0-3-1.343-3-3s1.343-3 3-3 3 1.343 3 3-1.343 3-3 3z"></path></symbol>');
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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
|
@@ -1,10 +0,0 @@
|
||||
<div class="mh3">
|
||||
|
||||
<h1>Ihr Demo-Zugang</h1>
|
||||
<p>Mit den folgenden Angaben haben Sie Zugang zur <a href="https://demo.typemill.pro" target="_blank">Typemill-Demo</a>. Die Zugangsdaten werden regelmäßig erneuert.</p>
|
||||
<ul>
|
||||
<li>Username: <strong>{{username}}</strong></li>
|
||||
<li>Passwort: <strong>{{password}}</strong></li>
|
||||
</ul>
|
||||
<p>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.</p>
|
||||
</div>
|
@@ -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
|
||||
|
@@ -87,7 +87,15 @@ class ControllerFrontendWebsite extends ControllerShared
|
||||
if(isset($this->settings['favicon']) && $this->settings['favicon'] != '')
|
||||
{
|
||||
$favicon = true;
|
||||
}
|
||||
$this->c->assets->addMeta('tilecolor','<meta name="msapplication-TileColor" content="#F9F8F6" />');
|
||||
$this->c->assets->addMeta('tileimage','<meta name="msapplication-TileImage" content="' . $this->base_url . '/media/files/favicon-144.png" />');
|
||||
$this->c->assets->addMeta('icon16','<link rel="icon" type="image/png" href="' . $this->base_url . '/media/files/favicon-16.png" sizes="16x16" />');
|
||||
$this->c->assets->addMeta('icon32','<link rel="icon" type="image/png" href="' . $this->base_url . '/media/files/favicon-32.png" sizes="32x32" />');
|
||||
$this->c->assets->addMeta('icon72','<link rel="apple-touch-icon" sizes="72x72" href="' . $this->base_url . '/media/files/favicon-72.png" />');
|
||||
$this->c->assets->addMeta('icon114','<link rel="apple-touch-icon" sizes="114x114" href="' . $this->base_url . '/media/files/favicon-114.png" />');
|
||||
$this->c->assets->addMeta('icon144','<link rel="apple-touch-icon" sizes="144x144" href="' . $this->base_url . '/media/files/favicon-144.png" />');
|
||||
$this->c->assets->addMeta('icon180','<link rel="apple-touch-icon" sizes="180x180" href="' . $this->base_url . '/media/files/favicon-180.png" />');
|
||||
}
|
||||
|
||||
# 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','<meta name="robots" content="noindex">');
|
||||
}
|
||||
|
||||
$this->c->assets->addMeta('og_site_name','<meta property="og:site_name" content="' . $this->settings['title'] . '">');
|
||||
$this->c->assets->addMeta('og_title','<meta property="og:title" content="' . $metatabs['meta']['title'] . '">');
|
||||
$this->c->assets->addMeta('og_description','<meta property="og:description" content="' . $metatabs['meta']['description'] . '">');
|
||||
$this->c->assets->addMeta('og_type','<meta property="og:type" content="article">');
|
||||
$this->c->assets->addMeta('og_url','<meta property="og:url" content="' . $item->urlAbs . '">');
|
||||
|
||||
# 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','<meta property="og:image" content="' . $img_url . '">');
|
||||
$this->c->assets->addMeta('twitter_image_alt','<meta name="twitter:image:alt" content="' . $img_alt. '">');
|
||||
$this->c->assets->addMeta('twitter_card','<meta name="twitter:card" content="summary_large_image">');
|
||||
}
|
||||
|
||||
$route = empty($args) && isset($this->settings['themes'][$theme]['cover']) ? '/cover.twig' : '/index.twig';
|
||||
|
@@ -8,35 +8,9 @@
|
||||
<meta name="description" content="{{ metatabs.meta.description }}" />
|
||||
<meta name="author" content="{{ metatabs.meta.author }}" />
|
||||
<meta name="generator" content="TYPEMILL" />
|
||||
<meta name="msapplication-TileColor" content="#F9F8F6" />
|
||||
|
||||
{% if metatabs.meta.noindex %}
|
||||
<meta name="robots" content="noindex">
|
||||
{% endif %}
|
||||
|
||||
{% if favicon %}
|
||||
<meta name="msapplication-TileColor" content="#F9F8F6" />
|
||||
<meta name="msapplication-TileImage" content="{{ base_url }}/media/files/favicon-144.png" />
|
||||
<link rel="icon" type="image/png" href="{{ base_url }}/media/files/favicon-16.png" sizes="16x16" />
|
||||
<link rel="icon" type="image/png" href="{{ base_url }}/media/files/favicon-32.png" sizes="32x32" />
|
||||
<link rel="apple-touch-icon" sizes="72x72" href="{{ base_url }}/media/files/favicon-72.png" />
|
||||
<link rel="apple-touch-icon" sizes="114x114" href="{{ base_url }}/media/files/favicon-114.png" />
|
||||
<link rel="apple-touch-icon" sizes="144x144" href="{{ base_url }}/media/files/favicon-144.png" />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="{{ base_url }}/media/files/favicon-180.png" />
|
||||
{% endif %}
|
||||
|
||||
<link rel="canonical" href="{{ item.urlAbs }}" />
|
||||
|
||||
<meta property="og:site_name" content="{{ settings.title }}">
|
||||
<meta property="og:title" content="{{ title }}">
|
||||
<meta property="og:description" content="{{ metatabs.meta.description }}">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:url" content="{{ item.urlAbs }}">
|
||||
{% if image.img_url %}
|
||||
<meta property="og:image" content="{{ image.img_url }}">
|
||||
<meta name="twitter:image:alt" content="{{ image.img_alt }}">
|
||||
{% endif %}
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
|
||||
{{ assets.renderMeta() }}
|
||||
|
||||
{% block stylesheets %}
|
||||
|
||||
|
Reference in New Issue
Block a user