forked from BabDev/Tweet-Display-Back
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.php
152 lines (131 loc) · 3.41 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
<?php
/**
* Tweet Display Back Module for Joomla!
*
* @package TweetDisplayBack
*
* @copyright Copyright (C) 2010-2011 Michael Babker. All rights reserved.
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
*/
/**
* Class to handle additional work during installation routine
*
* @package TweetDisplayBack
* @since 2.2
*/
class Mod_TweetDisplayBackInstallerScript
{
/**
* Function to act prior to installation process begins
*
* @param string $type The action being performed
* @param JInstallerModule $parent The function calling this method
*
* @return boolean True on success, false on failure
*
* @since 2.2
*/
public function preflight($type, $parent)
{
// Requires Joomla! 2.5
$jversion = new JVersion;
if (version_compare($jversion->getShortVersion(), '2.5', 'lt'))
{
JError::raiseNotice(null, JText::_('MOD_TWEETDISPLAYBACK_ERROR_INSTALL_VERSION'));
return false;
}
return true;
}
/**
* Function to perform changes during update
*
* @param JInstallerModule $parent The class calling this method
*
* @return void
*
* @since 2.2
*/
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::_('MOD_TWEETDISPLAYBACK_ERROR_INSTALL_UPDATE'));
return;
}
// If coming from 2.1 or earlier, remove language files in system language folder
if (version_compare($version, '2.2', 'lt'))
{
$this->_removeLanguageFiles();
}
}
/**
* Function to get the currently installed version from the manifest cache
*
* @return string The version that is installed
*
* @since 2.2
*/
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('mod_tweetdisplayback'));
$db->setQuery($query);
if (!$db->loadObject())
{
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
$version = 'Error';
return $version;
}
else
{
$manifest = $db->loadObject();
}
// Decode the JSON
$record = json_decode($manifest->manifest_cache);
// Get the version
$version = $record->version;
return $version;
}
/**
* Function to remove language files from the system language folder due to changing to
* module language files for 2.2
*
* @return void
*
* @since 2.2
*/
private function _removeLanguageFiles()
{
jimport('joomla.filesystem.file');
$lang = JFactory::getLanguage();
$langCode = $lang->getTag();
$base = JPATH_SITE . '/language/' . $langCode . '/';
$engBase = JPATH_SITE . '/language/en-GB/';
// The language files for pre-2.2
$files = array($langCode . '.mod_tweetdisplayback.ini', $langCode . '.mod_tweetdisplayback.sys.ini');
$engFiles = array('en-GB.mod_tweetdisplayback.ini', 'en-GB.mod_tweetdisplayback.sys.ini');
// Remove the files
foreach ($files as $file)
{
if (is_file($base . $file))
{
JFile::delete($base . $file);
}
}
// Check for and remove en-GB files
foreach ($engFiles as $engFile)
{
if (is_file($engBase . $engFile))
{
JFile::delete($engBase . $engFile);
}
}
}
}