-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.php
133 lines (117 loc) · 2.75 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
<?php
/**
* @package jCode Syntax Highlighter
* @author Konstantin Kolos
* @copyright Copyright (C) 2019 - 2022 Jnotes.net.ua. All rights reserved
* @contact https://jnotes.net.ua, admin@jnotes.net.ua
* @license https://gnu.org/licenses/gpl-3.0.html, GNU/GPLv3
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerScript;
use Joomla\CMS\Language\Text;
/**
* Installation class to perform additional changes during Install / Uninstall / Update
*
* @since 1.2.0
*/
class PlgContentjCodeSyntaxHighlighterInstallerScript extends InstallerScript
{
const MIN_VERSION_JOOMLA = '3.9.0';
const MIN_VERSION_PHP = '7.2.0';
/**
* Name of extension that is used in the error message
*
* @var string
*
* @since 1.2.0
*/
protected $extensionName = 'jCode Syntax Highlighter';
/**
* Extension script constructor
*
* @since 1.3.0
*/
public function __construct()
{
$this->deleteFiles = array(
// From 1.2.1 to 1.3.0
'/media/plg_content_jcodesyntaxhighlighter/css/linenumbers.css',
'/media/plg_content_jcodesyntaxhighlighter/css/linenumbers-previewers.css',
'/media/plg_content_jcodesyntaxhighlighter/css/previewers.css',
'/media/plg_content_jcodesyntaxhighlighter/js/clipboard.min.js',
);
}
/**
* Checks compatibility in the preflight event
*
* @param $type
* @param $parent
*
* @return bool
* @throws Exception
*
* @since 1.2.0
*/
public function preflight($type, $parent)
{
if (!$this->checkVersionJoomla())
{
return false;
}
if (!$this->checkVersionPhp())
{
return false;
}
return true;
}
/**
* Function to perform changes during postflight
*
* @param string $type The action being performed
* @param ComponentAdapter $parent The class calling this method
*
* @return void
*
* @since 1.3.0
*/
public function postflight($type, $parent)
{
$this->removeFiles();
}
/**
* Checking the used version of Joomla
*
* @return bool
* @throws Exception
*
* @since 1.2.0
*/
private function checkVersionJoomla()
{
$version = new JVersion();
if (!$version->isCompatible(self::MIN_VERSION_JOOMLA))
{
Factory::getApplication()->enqueueMessage(Text::sprintf('JN_ERROR_JOOMLA_VERSION', $this->extensionName, self::MIN_VERSION_JOOMLA), 'error');
return false;
}
return true;
}
/**
* Checking the used version of PHP
*
* @return bool
* @throws Exception
*
* @since 1.2.0
*/
private function checkVersionPhp()
{
if (!version_compare(phpversion(), self::MIN_VERSION_PHP, 'ge'))
{
Factory::getApplication()->enqueueMessage(Text::sprintf('JN_ERROR_PHP_VERSION', $this->extensionName, self::MIN_VERSION_PHP), 'error');
return false;
}
return true;
}
}