-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.plg_system_socialmagick.php
162 lines (154 loc) · 4.11 KB
/
script.plg_system_socialmagick.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Social Magick – Automatically generate Open Graph images on your site
*
* @package socialmagick
* @copyright Copyright 2021-2023 Lucid Fox
* @license GNU GPL v3 or later
*/
defined('_JEXEC') || die;
use Joomla\CMS\Installer\Adapter\PluginAdapter;
use Joomla\CMS\Installer\InstallerScript;
use Joomla\Database\DatabaseDriver;
class plgSystemSocialmagickInstallerScript extends InstallerScript
{
protected $minimumJoomla = '4.2.0';
protected $minimumPhp = '7.4.0';
protected $defaultSettingsJson = <<< JSON
{
"og-templates": {
"og-templates0": {
"template-name": "Overlay",
"base-image": "plugins\\/system\\/socialmagick\\/images\\/overlay.png",
"template-w": 1200,
"template-h": 640,
"base-color": "#000000",
"base-color-alpha": "100",
"text-font": "OpenSans-Bold.ttf",
"font-size": 32,
"text-color": "#ffffff",
"text-height": 270,
"text-width": 500,
"text-align": "center",
"text-y-center": "1",
"text-y-adjust": -40,
"text-y-absolute": "",
"text-x-center": "1",
"text-x-adjust": 0,
"text-x-absolute": "",
"use-article-image": "1",
"image-z": "under",
"image-cover": "1",
"image-width": 1200,
"image-height": 630,
"image-x": 0,
"image-y": 0
},
"og-templates1": {
"template-name": "Solid",
"base-image": "plugins\\/system\\/socialmagick\\/images\\/solid.png",
"template-w": 1200,
"template-h": 640,
"base-color": "#000000",
"base-color-alpha": "100",
"text-font": "OpenSans-Bold.ttf",
"font-size": 32,
"text-color": "#ffffff",
"text-height": 280,
"text-width": 600,
"text-align": "center",
"text-y-center": "1",
"text-y-adjust": 0,
"text-y-absolute": "",
"text-x-center": "1",
"text-x-adjust": 0,
"text-x-absolute": "",
"use-article-image": "0",
"image-z": "under",
"image-cover": "1",
"image-width": 1200,
"image-height": 630,
"image-x": 0,
"image-y": 0
},
"og-templates2": {
"template-name": "Cutout",
"base-image": "plugins\\/system\\/socialmagick\\/images\\/cutout.png",
"template-w": 1200,
"template-h": 640,
"base-color": "#000000",
"base-color-alpha": "100",
"text-font": "OpenSans-Bold.ttf",
"font-size": 32,
"text-color": "#ffffff",
"text-height": 415,
"text-width": 430,
"text-align": "left",
"text-y-center": "1",
"text-y-adjust": -20,
"text-y-absolute": "",
"text-x-center": "0",
"text-x-adjust": 165,
"text-x-absolute": 165,
"use-article-image": "1",
"image-z": "under",
"image-cover": "0",
"image-width": 420,
"image-height": 420,
"image-x": 660,
"image-y": 90
}
},
"output_folder": "images\\/og-generated",
"quality": "95",
"devmode": "0",
"textdebug": "0",
"library": "auto"
}
JSON;
/**
* Runs after install, update or discover_update. In other words, it executes after Joomla! has finished installing
* or updating your plugin. This is the last chance you've got to perform any additional installations, clean-up,
* database updates and similar housekeeping functions.
*
* @param string $type install, update or discover_update
* @param PluginAdapter $adapter Parent object
*
* @return void
* @throws Exception
* @since 1.0.0
*/
public function postflight($type, $adapter)
{
// Apply default plugin settings on brand-new installation
if (in_array($type, ['install', 'discover', 'discover_install', 'discover_update']))
{
$this->applyDefaultSettings($adapter->getParent()->getDbo());
}
}
/**
* Apply the default plugin settings on new installation
*
* @param DatabaseDriver $db The database driver
*
* @return void
* @since 1.0.0
*/
private function applyDefaultSettings(DatabaseDriver $db)
{
$query = $db->getQuery(true)
->update($db->qn('#__extensions'))
->set($db->qn('params') . ' = ' . $db->q($this->defaultSettingsJson))
->where($db->qn('type') . ' = ' . $db->q('plugin'))
->where($db->qn('element') . ' = ' . $db->q('socialmagick'))
->where($db->qn('folder') . ' = ' . $db->q('system'));
try
{
$db->setQuery($query)->execute();
}
catch (Exception $e)
{
// No problem if this fails
}
}
}