-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaboutme.php
executable file
·105 lines (95 loc) · 3.19 KB
/
aboutme.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use Grav\Common\Page\Page;
use RocketTheme\Toolbox\Event\Event;
/**
* Class AboutMePlugin
* @package Grav\Plugin
*/
class AboutMePlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
];
}
/**
*
*/
public function onPluginsInitialized()
{
if (true === $this->isAdmin()) {
$this->active = false;
return;
}
if ($this->config->get('plugins.aboutme.enabled')) {
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onTwigPageVariables' => ['onTwigPageVariables', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onAssetsInitialized' => ['onAssetsInitialized', 0]
]);
}
}
/**
* We set twig variable in case the template is included in a page and not in a theme template
*
* @param Event $e
*/
public function onTwigPageVariables(Event $e)
{
$this->onTwigSiteVariables();
}
/**
* Set variables for the template
*/
public function onTwigSiteVariables()
{
$twig = $this->grav['twig'];
$twig->twig_vars['aboutme_name'] = $this->config->get('plugins.aboutme.name');
$twig->twig_vars['aboutme_title'] = $this->config->get('plugins.aboutme.title');
$twig->twig_vars['aboutme_description'] = $this->config->get('plugins.aboutme.description');
$twig->twig_vars['aboutme_picture_src'] = $this->config->get('plugins.aboutme.gravatar.enabled') ?
$this->getGravatarUrl() : $this->config->get('plugins.aboutme.picture_src');
if (is_array($twig->twig_vars['aboutme_picture_src'])) { // grav 1.1 gives an array instead of a simple string
$twig->twig_vars['aboutme_picture_src'] = key($twig->twig_vars['aboutme_picture_src']);
}
$pages = $this->config->get('plugins.aboutme.social_pages.pages');
uasort($pages, function ($a, $b) {
return $a['position'] < $b['position'] ? -1 : ($a['position'] == $b['position'] ? 0 : 1);
});
$twig->twig_vars['aboutme_pages'] = $pages;
}
/**
*
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
/**
* Get the profile picture based on the gravatar config
**/
private function getGravatarUrl()
{
$gravatar = $this->config->get('plugins.aboutme.gravatar');
$url = '//www.gravatar.com/avatar/';
$url .= md5(strtolower(trim($gravatar['email'])));
$url .= '?s=' . $gravatar['size'];
return $url;
}
public function onAssetsInitialized()
{
if ($this->config->get('plugins.aboutme.built_in_css')) {
$this->grav['assets']->add('plugin://aboutme/assets/css/aboutme.css');
}
if ($this->config->get('plugins.aboutme.social_pages.use_font_awesome')) {
$this->grav['assets']->addJs('https://kit.fontawesome.com/6c3a3c60c8.js');
}
}
}