-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.script.php
205 lines (175 loc) · 4.74 KB
/
installer.script.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
* @package Helix_Ultimate_Framework
* @author JoomShaper <support@joomshaper.com>
* @copyright Copyright (c) 2010 - 2020 JoomShaper
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
defined ('_JEXEC') or die();
/**
* Installer class of the Helix Ultimate Template
*
* @since 1.0.0
*/
class plgSystemTmp_helixultInstallerScript
{
/**
* Post Flight hook
*
* @param string $type
* @param object $parent
*
* @return void
* @since 1.0.0
*/
public function postflight($type, $parent)
{
$src = $parent->getParent()->getPath('source');
$manifest = $parent->getParent()->manifest;
$plugins = $manifest->xpath('plugins/plugin');
foreach ($plugins as $key => $plugin)
{
$name = (string) $plugin->attributes()->plugin;
$group = (string) $plugin->attributes()->group;
$installer = new JInstaller;
$path = $src.'/plugins/'.$group;
if (JFolder::exists($src.'/plugins/'.$group.'/'.$name))
{
$path = $src.'/plugins/'.$group.'/'.$name;
}
$plugin_info = $this->getPluginInfoByName($name, $group);
if($plugin_info)
{
$manifest_cache = json_decode($plugin_info->manifest_cache);
$cache_version = $manifest_cache->version;
$plg_manifest = $installer->parseXMLInstallFile($path.'/'.$name.'.xml');
$version = $plg_manifest['version'];
if($version < $cache_version)
{
continue;
}
}
$result = $installer->install($path);
if ($result)
{
$this->activeInstalledPlugin($name, $group);
}
}
$template_path = $src . '/template';
$plugin_path = $src . '/plugins/system';
if (JFolder::exists( $template_path ))
{
$installer = new JInstaller;
$result = $installer->install($template_path);
}
$templates = $manifest->xpath('template');
foreach($templates as $key => $template)
{
$tmpl_name = (string) $template->attributes()->name;
$tmpl_info = $this->getTemplateInfoByName($tmpl_name);
$params = json_decode($tmpl_info->params);
$params_array = (array) $params;
if(empty($params_array))
{
$options_default = file_get_contents($template_path .'/options.json');
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$fields = array(
$db->quoteName('params') . ' = ' . $db->quote($options_default)
);
$conditions = array(
$db->quoteName('client_id') . ' = 0',
$db->quoteName('template') . ' = ' . $db->quote($tmpl_name)
);
$query->update($db->quoteName('#__template_styles'))->set($fields)->where($conditions);
$db->setQuery($query);
$db->execute();
}
}
$conf = JFactory::getConfig();
$conf->set('debug', false);
$parent->getParent()->abort();
}
/**
* Get template information by name
*
* @param string $name Template name
*
* @return object
* @since 1.0.0
*/
private function getTemplateInfoByName($name)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__template_styles'));
$query->where($db->quoteName('client_id') . ' = 0');
$query->where($db->quoteName('template') . ' = ' . $db->quote( $name ));
$db->setQuery($query);
return $db->loadObject();
}
/**
* Activate the installed plugin
*
* @param string $name Plugin name
* @param string $group Plugin group
*
* @return void
* @since 1.0.0
*/
private function activeInstalledPlugin($name, $group)
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$fields = array(
$db->quoteName('enabled') . ' = 1'
);
$conditions = array(
$db->quoteName('type') . ' = ' . $db->quote('plugin'),
$db->quoteName('element') . ' = ' . $db->quote($name),
$db->quoteName('folder') . ' = ' . $db->quote($group)
);
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
$db->setQuery($query);
$db->execute();
}
/**
* Get plugins information by name
*
* @param string $name Plugin name
* @param string $group Plugin group
*
* @return object
* @since 1.0.0
*/
private function getPluginInfoByName($name, $group)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__extensions'));
$query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
$query->where($db->quoteName('element') . ' = ' . $db->quote( $name ));
$query->where($db->quoteName('folder') . ' = ' . $db->quote( $group ));
$db->setQuery($query);
return $db->loadObject();
}
/**
* Abort installation
*
* @param string $msg Abortion message
* @param string $type
*
* @return void
* @since 1.0.0
*/
public function abort($msg = null, $type = null){
if ($msg) {
JError::raiseWarning(100, $msg);
}
foreach ($this->packages as $package) {
$package['installer']->abort(null, $type);
}
}
}