1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Typogrify plugin for Craft CMS |
4
|
|
|
* |
5
|
|
|
* Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com/ |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\typogrify; |
12
|
|
|
|
13
|
|
|
use Craft; |
14
|
|
|
use craft\base\Model; |
15
|
|
|
use craft\base\Plugin; |
16
|
|
|
use craft\web\twig\variables\CraftVariable; |
17
|
|
|
use nystudio107\typogrify\models\Settings; |
18
|
|
|
use nystudio107\typogrify\services\ServicesTrait; |
19
|
|
|
use nystudio107\typogrify\twigextensions\TypogrifyTwigExtension; |
20
|
|
|
use nystudio107\typogrify\variables\TypogrifyVariable; |
21
|
|
|
use yii\base\Event; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Typogrify |
25
|
|
|
* |
26
|
|
|
* @author nystudio107 |
|
|
|
|
27
|
|
|
* @package Typogrify |
|
|
|
|
28
|
|
|
* @since 1.0.0 |
|
|
|
|
29
|
|
|
* |
30
|
|
|
* @property Settings $settings |
|
|
|
|
31
|
|
|
*/ |
|
|
|
|
32
|
|
|
class Typogrify extends Plugin |
33
|
|
|
{ |
34
|
|
|
// Traits |
35
|
|
|
// ========================================================================= |
36
|
|
|
|
37
|
|
|
use ServicesTrait; |
38
|
|
|
|
39
|
|
|
// Static Properties |
40
|
|
|
// ========================================================================= |
41
|
|
|
|
42
|
|
|
/** |
|
|
|
|
43
|
|
|
* @var ?Typogrify |
44
|
|
|
*/ |
45
|
|
|
public static ?Typogrify $plugin = null; |
46
|
|
|
|
47
|
|
|
/** |
|
|
|
|
48
|
|
|
* @var ?TypogrifyVariable |
49
|
|
|
*/ |
50
|
|
|
public static ?TypogrifyVariable $variable = null; |
51
|
|
|
|
52
|
|
|
// Public Properties |
53
|
|
|
// ========================================================================= |
54
|
|
|
|
55
|
|
|
/** |
|
|
|
|
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
public string $schemaVersion = '1.0.0'; |
59
|
|
|
|
60
|
|
|
/** |
|
|
|
|
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
public bool $hasCpSettings = false; |
64
|
|
|
/** |
|
|
|
|
65
|
|
|
* @var bool |
66
|
|
|
*/ |
67
|
|
|
public bool $hasCpSection = false; |
68
|
|
|
|
69
|
|
|
// Public Methods |
70
|
|
|
// ========================================================================= |
71
|
|
|
|
72
|
|
|
/** |
|
|
|
|
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
|
|
|
|
75
|
|
|
public function init(): void |
76
|
|
|
{ |
77
|
|
|
parent::init(); |
78
|
|
|
self::$plugin = $this; |
79
|
|
|
self::$variable = new TypogrifyVariable(); |
80
|
|
|
|
81
|
|
|
Craft::$app->view->registerTwigExtension(new TypogrifyTwigExtension()); |
82
|
|
|
// Register our variables |
83
|
|
|
Event::on( |
84
|
|
|
CraftVariable::class, |
85
|
|
|
CraftVariable::EVENT_INIT, |
86
|
|
|
static function(Event $event) { |
|
|
|
|
87
|
|
|
/** @var CraftVariable $variable */ |
|
|
|
|
88
|
|
|
$variable = $event->sender; |
89
|
|
|
$variable->set('typogrify', self::$variable); |
90
|
|
|
} |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
Craft::info( |
94
|
|
|
Craft::t( |
95
|
|
|
'typogrify', |
96
|
|
|
'{name} plugin loaded', |
97
|
|
|
['name' => $this->name] |
98
|
|
|
), |
99
|
|
|
__METHOD__ |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
// Protected Methods |
104
|
|
|
// ========================================================================= |
105
|
|
|
|
106
|
|
|
/** |
|
|
|
|
107
|
|
|
* @inheritdoc |
108
|
|
|
*/ |
|
|
|
|
109
|
|
|
protected function createSettingsModel(): ?Model |
110
|
|
|
{ |
111
|
|
|
return new Settings(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|