-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.php
153 lines (133 loc) · 3.83 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Typographe-Joomla plugin
* @author Yann Gomiero aka Daneel
* @copyright Copyright (C) 2018 Yann All Rights Reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* Website https://forum.joomla.fr
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
* Installation class to perform additional changes during install/uninstall/update
*
* @since 1.1
*/
class PlgContentTypographeInstallerScript
{
/**
* Minimum supported Joomla! version
*
* @var string
* @since 1.1
*/
protected $minimumJoomlaVersion = '2.5.0';
/**
* Minimum supported PHP version
*
* @var string
* @since 1.1
*/
protected $minimumPHPVersion = '5.3.0';
/**
* Function to act prior to installation process begins
*
* @param string $type The action being performed
* @param JInstallerPlugin $parent The function calling this method
*
* @return boolean
*
* @since 1.1
*/
public function preflight($type, $parent)
{
// Make sure we aren't uninstalling first
if ($type != 'uninstall')
{
// Check PHP version
if (version_compare(PHP_VERSION, $this->minimumPHPVersion, 'lt'))
{
JError::raiseNotice(
null, JText::sprintf('PLG_TYPOGRAPHE_ERROR_INSTALL_PHPVERSION', $this->minimumPHPVersion)
);
return false;
}
// Check Joomla! version
if (version_compare(JVERSION, $this->minimumJoomlaVersion, 'lt'))
{
JError::raiseNotice(
null, JText::sprintf('PLG_TYPOGRAPHE_ERROR_INSTALL_JVERSION', $this->minimumJoomlaVersion)
);
return false;
}
}
return true;
}
/**
* Function to perform changes during update
*
* @param JInstallerPlugin $parent The class calling this method
*
* @return void
*
* @since 1.1
*/
public function update($parent)
{
// Get the pre-update version
$version = $this->getVersion();
// If in error, throw a message about the language files
if ($version == 'Error')
{
JError::raiseNotice(null, JText::_('PLG_TYPOGRAPHE_ERROR_INSTALL_UPDATE'));
return;
}
// If coming from 1.0, remove old language folders
if (version_compare($version, '1.1', 'lt'))
{
$this->removeLanguageFiles();
}
}
/**
* Function to get the currently installed version from the manifest cache
* @return string The version that is installed
* @since 1.1
*/
private function getVersion()
{
// Get the record from the database
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->quoteName('manifest_cache'));
$query->from($db->quoteName('#__extensions'));
$query->where($db->quoteName('element') . ' = ' . $db->quote('typographe'), 'AND');
$query->where($db->quoteName('folder') . ' = ' . $db->quote('system'), 'AND');
$db->setQuery($query);
if (!($manifest = $db->loadObject()))
{
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
$version = 'Error';
return $version;
}
$record = json_decode($manifest->manifest_cache);
$version = $record->version;
return $version;
}
/**
* Function to remove language files from the system language folders in favor of extension folders
*
* @return void
*
* @since 1.1
*/
private function removeLanguageFiles()
{
jimport('joomla.filesystem.file');
$adminBase = JPATH_ADMINISTRATOR . '/language/en-GB/';
$FrenchBase = JPATH_ADMINISTRATOR . '/language/fr-FR/';
$adminFiles = array('en-GB.plg_system_typographe.ini', 'en-GB.plg_system_typographe.sys.ini');
$FrenchFiles = array('fr-FR.plg_system_typographe.ini', 'fr-FR.plg_system_typographe.sys.ini');
foreach ($adminFiles as $adminFile) { if (is_file($adminBase . $adminFile)) { JFile::delete($adminBase . $adminFile); } }
foreach ($FrenchFiles as $FrenchFile) { if (is_file($FrenchBase . $FrenchFile)) { JFile::delete($FrenchBase . $FrenchFile); } }
}
}