forked from giansi/grav-plugin-social-buttons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocialbuttons.php
48 lines (41 loc) · 1.42 KB
/
socialbuttons.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
class SocialButtonsPlugin extends Plugin
{
public static function getSubscribedEvents() {
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
];
}
public function onPluginsInitialized()
{
if ($this->isAdmin()) {
$this->active = false;
return;
}
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
]);
}
/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
/**
* if enabled on this page, load the JS + CSS theme.
*/
public function onTwigSiteVariables()
{
$this->grav['assets']->addCss('plugin://socialbuttons/vendor/rrssb/css/rrssb.css', -999);
$this->grav['assets']->addJs('plugin://socialbuttons/vendor/rrssb/js/rrssb.min.js', -999);
$twig = $this->grav['twig'];
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$twig->twig_vars['socialbuttons_domain'] = $protocol . $_SERVER["HTTP_HOST"];
$twig->twig_vars['socialbuttons_buttons'] = $this->config->get('plugins.socialbuttons.buttons');
}
}