forked from master3-blank-template/Master3-Lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.php
137 lines (112 loc) · 4.85 KB
/
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
<?php defined('_JEXEC') or die;
/*
* @package Joomla.Site
* @subpackage Templates.master3lite
* @copyright Copyright (C) Aleksey A. Morozov. All rights reserved.
* @license GNU General Public License version 3 or later; see http://www.gnu.org/licenses/gpl-3.0.txt
*/
use Joomla\CMS\Factory;
use Joomla\CMS\Version;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Installer\InstallerHelper;
use Joomla\Archive\Archive;
class master3liteInstallerScript
{
function preflight($type, $parent)
{
if (strtolower($type) === 'uninstall') {
return true;
}
$minJoomlaVersion = $parent->get('manifest')->attributes()->version[0];
if (!class_exists('Joomla\CMS\Version')) {
JFactory::getApplication()->enqueueMessage(JText::sprintf('J_JOOMLA_COMPATIBLE', JText::_($parent->manifest->name[0]), $minJoomlaVersion), 'error');
return false;
}
if (strtolower($type) === 'install' && Version::MAJOR_VERSION < 4) {
$msg = '';
$name = Text::_($parent->manifest->name[0]);
$minPhpVersion = $parent->manifest->php_minimum[0];
$ver = new Version();
if (version_compare($ver->getShortVersion(), $minJoomlaVersion, 'lt')) {
$msg .= Text::sprintf('J_JOOMLA_COMPATIBLE', $name, $minJoomlaVersion);
}
if (version_compare(phpversion(), $minPhpVersion, 'lt')) {
$msg .= Text::sprintf('J_PHP_COMPATIBLE', $name, $minPhpVersion);
}
if ($msg) {
Factory::getApplication()->enqueueMessage($msg, 'error');
return false;
}
}
}
function postflight($type, $parent)
{
if (strtolower($type) === 'uninstall') {
return true;
}
$result = $this->installUikit3($parent);
if ($result !== true) {
Factory::getApplication()->enqueueMessage(Text::sprintf('TPL_MASTER3_UIKIT3_INSTALLATION_ERROR', $result), 'error');
return false;
}
$oldUikit = Path::clean(JPATH_ROOT . '/templates/master3lite/uikit');
if (is_dir($oldUikit)) {
\JFolder::delete($oldUikit);
InstallerHelper::cleanupInstall($oldUikit);
}
}
private function installUikit3($parent)
{
$isUikit3 = false;
$actualVersion = (string) $parent->manifest->uikit_actual[0];
$manifestFile = Path::clean(JPATH_ADMINISTRATOR . '/manifests/files/file_uikit3.xml');
if (file_exists(Path::clean($manifestFile))) {
$xml = @simplexml_load_file($manifestFile);
if ($xml) {
$xml = (array) $xml;
$uikitVersion = $xml['version'];
if (!version_compare($actualVersion, $uikitVersion, 'gt')) {
$isUikit3 = true;
}
}
unset($xml);
}
if (!$isUikit3) {
$tmp = Factory::getConfig()->get('tmp_path');
$uikitFile = 'https://master3.alekvolsk.info/files/uikit3_v' . $actualVersion . '_j3.zip';
$tmpFile = Path::clean($tmp . '/uikit3_v' . $actualVersion . '_j3.zip');
$extDir = Path::clean($tmp . '/' . uniqid('install_'));
$contents = file_get_contents($uikitFile);
if ($contents === false) {
return Text::sprintf('TPL_MASTER3_UIKIT3_IE_FAILED_DOWNLOAD', $uikitFile);
}
$resultContents = file_put_contents($tmpFile, $contents);
if ($resultContents == false) {
return Text::sprintf('TPL_MASTER3_UIKIT3_IE_FAILED_INSTALLATION', $tmpFile);
}
if (!file_exists($tmpFile)) {
return Text::sprintf('TPL_MASTER3_UIKIT3_IE_NOT_EXISTS', $tmpFile);
}
$archive = new Archive(['tmp_path' => $tmp]);
try {
$archive->extract($tmpFile, $extDir);
} catch (\Exception $e) {
return Text::sprintf('TPL_MASTER3_UIKIT3_IE_FAILER_UNZIP', $tmpFile, $extDir, $e->getMesage());
}
$installer = new Installer();
$installer->setPath('source', $extDir);
if (!$installer->findManifest()) {
InstallerHelper::cleanupInstall($tmpFile, $extDir);
return Text::_('TPL_MASTER3_UIKIT3_IE_INCORRECT_MANIFEST');
}
if (!$installer->install($extDir)) {
InstallerHelper::cleanupInstall($tmpFile, $extDir);
return Text::_('TPL_MASTER3_UIKIT3_IE_INSTALLER_ERROR');
}
InstallerHelper::cleanupInstall($tmpFile, $extDir);
}
return true;
}
}