-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadTime.php
executable file
·80 lines (63 loc) · 1.94 KB
/
ReadTime.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
<?php
/**
* Read Time plugin for Craft CMS 3.x
*
* Calculate the estimated read time for content.
*
* @link https://github.com/zizther
* @copyright Copyright (c) 2018 Nathan Reed
*/
namespace zizther\readtime;
use zizther\readtime\models\Settings;
use zizther\readtime\twigextensions\ReadTimeTwigExtension;
use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use yii\base\Event;
class ReadTime extends Plugin
{
// Static Properties
// =========================================================================
public static $plugin;
// Public Properties
// =========================================================================
public $schemaVersion = '1.0.0';
// Public Methods
// =========================================================================
public function init()
{
parent::init();
self::$plugin = $this;
Craft::$app->view->registerTwigExtension(new ReadTimeTwigExtension());
Craft::info(
Craft::t(
'read-time',
'{name} plugin loaded',
['name' => $this->name]
),
__METHOD__
);
}
// Protected Methods
// =========================================================================
protected function createSettingsModel()
{
return new Settings();
}
protected function settingsHtml(): string
{
// Get and pre-validate the settings
$settings = $this->getSettings();
$settings->validate();
// Get the settings that are being defined by the config file
$overrides = Craft::$app->getConfig()->getConfigFromFile(strtolower($this->handle));
return Craft::$app->view->renderTemplate(
'read-time/settings',
[
'settings' => $settings,
'overrides' => array_keys($overrides)
]
);
}
}