mirror of
https://github.com/typemill/typemill.git
synced 2025-10-17 15:46:28 +02:00
Version 1.1.1 Theme and Plugin Optimizations
This commit is contained in:
44
plugins/analytics/analytics.php
Normal file
44
plugins/analytics/analytics.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\Analytics;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
|
||||
class Analytics extends Plugin
|
||||
{
|
||||
protected $settings;
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'onSettingsLoaded' => 'onSettingsLoaded',
|
||||
'onTwigLoaded' => 'onTwigLoaded'
|
||||
);
|
||||
}
|
||||
|
||||
public function onSettingsLoaded($settings)
|
||||
{
|
||||
$this->settings = $settings->getData();
|
||||
}
|
||||
|
||||
public function onTwigLoaded()
|
||||
{
|
||||
/* get Twig Instance and add the cookieconsent template-folder to the path */
|
||||
$twig = $this->getTwig();
|
||||
$loader = $twig->getLoader();
|
||||
$loader->addPath(__DIR__ . '/templates');
|
||||
|
||||
$analyticSettings = $this->settings['settings']['plugins']['analytics'];
|
||||
|
||||
/* fetch the template, render it with twig and add javascript with settings */
|
||||
if($analyticSettings['tool'] == 'piwik')
|
||||
{
|
||||
$this->addInlineJS($twig->fetch('/piwikanalytics.twig', $this->settings));
|
||||
}
|
||||
elseif($analyticSettings['tool'] == 'google')
|
||||
{
|
||||
$this->addJS('https://www.googletagmanager.com/gtag/js?id=' . $analyticSettings['google_id']);
|
||||
$this->addInlineJS($twig->fetch('/googleanalytics.twig', $analyticSettings));
|
||||
}
|
||||
}
|
||||
}
|
38
plugins/analytics/analytics.yaml
Normal file
38
plugins/analytics/analytics.yaml
Normal file
@@ -0,0 +1,38 @@
|
||||
name: Analytics
|
||||
version: 1.0.0
|
||||
description: Integrate Piwik or Google Analytics Script
|
||||
author: Sebastian Schürmanns
|
||||
homepage: http://typemill.net
|
||||
licence: MIT
|
||||
|
||||
settings:
|
||||
tool: none
|
||||
|
||||
forms:
|
||||
fields:
|
||||
|
||||
tool:
|
||||
type: radio
|
||||
label: Choose Your Tool
|
||||
options:
|
||||
none: None
|
||||
piwik: Piwik
|
||||
google: Google Analytics
|
||||
|
||||
piwik_url:
|
||||
type: text
|
||||
label: Piwik URL
|
||||
help: Add the URL to your piwik installation without protocol like this: my-site.com.
|
||||
placeholder: 'url like my-piwik-installation.com'
|
||||
|
||||
piwik_id:
|
||||
type: number
|
||||
label: Piwik Site-ID
|
||||
help: You can find the id in Piwik under configuration and tracking code.
|
||||
placeholder: 'simple number like 8'
|
||||
|
||||
google_id:
|
||||
type: text
|
||||
label: Google Tracking ID
|
||||
help: You can find the tracking id in google under property. It starts with UA-
|
||||
placeholder: 'UA-12345-6'
|
5
plugins/analytics/templates/googleanalytics.twig
Normal file
5
plugins/analytics/templates/googleanalytics.twig
Normal file
@@ -0,0 +1,5 @@
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '{{ google_id }}');
|
11
plugins/analytics/templates/piwikanalytics.twig
Normal file
11
plugins/analytics/templates/piwikanalytics.twig
Normal file
@@ -0,0 +1,11 @@
|
||||
var _paq = _paq || [];
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
|
||||
(function(){
|
||||
var u="//{{ settings.plugins.analytics.piwik_url }}/";
|
||||
_paq.push(['setTrackerUrl', u+'piwik.php']);
|
||||
_paq.push(['setSiteId', '{{ settings.plugins.analytics.piwik_id }}']);
|
||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
@@ -1,19 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\cookieconsent;
|
||||
namespace Plugins\CookieConsent;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
|
||||
class cookieconsent extends Plugin
|
||||
class CookieConsent extends Plugin
|
||||
{
|
||||
protected $settings;
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'onSettingsLoaded' => ['onSettingsLoaded',0],
|
||||
'onTwigLoaded' => ['onTwigLoaded', 0]
|
||||
];
|
||||
return array(
|
||||
'onSettingsLoaded' => 'onSettingsLoaded',
|
||||
'onTwigLoaded' => 'onTwigLoaded'
|
||||
);
|
||||
}
|
||||
|
||||
public function onSettingsLoaded($settings)
|
||||
@@ -22,7 +22,7 @@ class cookieconsent extends Plugin
|
||||
}
|
||||
|
||||
public function onTwigLoaded()
|
||||
{
|
||||
{
|
||||
/* add external CSS and JavaScript */
|
||||
$this->addCSS('/cookieconsent/public/cookieconsent.min.css');
|
||||
$this->addJS('/cookieconsent/public/cookieconsent.min.js');
|
||||
@@ -33,6 +33,6 @@ class cookieconsent extends Plugin
|
||||
$loader->addPath(__DIR__ . '/templates');
|
||||
|
||||
/* fetch the template, render it with twig and add it as inline-javascript */
|
||||
$this->addInlineJS($twig->fetch('/cookieconsent.twig', $this->settings));
|
||||
$this->addInlineJS($twig->fetch('/cookieconsent.twig', $this->settings));
|
||||
}
|
||||
}
|
41
plugins/disqus/disqus.php
Normal file
41
plugins/disqus/disqus.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\Disqus;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
|
||||
class Disqus extends Plugin
|
||||
{
|
||||
protected $settings;
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function onSettingsLoaded($settings)
|
||||
{
|
||||
$this->settings = $settings->getData();
|
||||
}
|
||||
|
||||
public function onTwigLoaded()
|
||||
{
|
||||
/* get Twig Instance and add the cookieconsent template-folder to the path */
|
||||
$twig = $this->getTwig();
|
||||
$loader = $twig->getLoader();
|
||||
$loader->addPath(__DIR__ . '/templates');
|
||||
|
||||
$analyticSettings = $this->settings['settings']['plugins']['analytics'];
|
||||
|
||||
/* fetch the template, render it with twig and add javascript with settings */
|
||||
if($analyticSettings['tool'] == 'piwik')
|
||||
{
|
||||
$this->addInlineJS($twig->fetch('/piwikanalytics.twig', $this->settings));
|
||||
}
|
||||
elseif($analyticSettings['tool'] == 'google')
|
||||
{
|
||||
$this->addJS('https://www.googletagmanager.com/gtag/js?id=' . $analyticSettings['google_id']);
|
||||
$this->addInlineJS($twig->fetch('/googleanalytics.twig', $analyticSettings));
|
||||
}
|
||||
}
|
||||
}
|
15
plugins/disqus/disqus.yaml
Normal file
15
plugins/disqus/disqus.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
name: Disqus
|
||||
version: 1.0.0
|
||||
description: Integrate Disqus into Typemill.
|
||||
author: Sebastian Schürmanns
|
||||
homepage: http://typemill.net
|
||||
licence: MIT
|
||||
|
||||
forms:
|
||||
fields:
|
||||
|
||||
shortname:
|
||||
type: text
|
||||
label: Disqus-Shortname
|
||||
help: You can find the shortname in your disqus-settings
|
||||
placeholder: 'YOUR SHORTNAME'
|
12
plugins/disqus/templates/disqus.twig
Normal file
12
plugins/disqus/templates/disqus.twig
Normal file
@@ -0,0 +1,12 @@
|
||||
var disqus_config = function () {
|
||||
this.page.url = {{ item.urlAbs }} ;
|
||||
};
|
||||
|
||||
(function() {
|
||||
var d = document, s = d.createElement('script');
|
||||
|
||||
s.src = 'https://{{ settings.plugins.disqus.shortname }}.disqus.com/embed.js';
|
||||
|
||||
s.setAttribute('data-timestamp', +new Date());
|
||||
(d.head || d.body).appendChild(s);
|
||||
})();
|
Reference in New Issue
Block a user