-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptfile.php
187 lines (158 loc) · 5.24 KB
/
scriptfile.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
<?php
// No direct access to this file
defined('_JEXEC') or die;
if (!class_exists('ScriptAry'))
{
include dirname(__FILE__) . '/scriptary.php';
}
// * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
/**
* Script file
*/
class plgContentAutoreadmoreInstallerScript extends ScriptAry {
function __construct() {
}
/**
* method to install the component
*
* @return void
*/
function install($parent) {
// $parent is the class calling this method
//$parent->getParent()->setRedirectURL('index.php?option=com_helloworld');
}
/**
* method to uninstall the component
*
* @return void
*/
function uninstall($parent) {
// $parent is the class calling this method
//echo '<p>' . JText::_('COM_HELLOWORLD_UNINSTALL_TEXT') . '</p>';
}
/**
* method to update the component
*
* @return void
*/
function update($parent) {
// $parent is the class calling this method
//echo '<p>' . JText::_('COM_HELLOWORLD_UPDATE_TEXT') . '</p>';
}
/**
* method to run before an install/update/uninstall method
*
* @return void
*/
function preflight($type, $parent) {
$manifest = $parent->getParent()->getManifest();
$this->plg_name = 'autoreadmore';
$this->plg_type = $manifest['group'];
$this->plg_full_name = 'plg_'.$this->plg_type.'_'.$this->plg_name;
$this->langShortCode = null;//is used for building joomfish links
$this->default_lang = JComponentHelper::getParams('com_languages')->get('admin');
$language = JFactory::getLanguage();
$language->load($this->plg_full_name, dirname(__FILE__), 'en-GB', true);
$language->load($this->plg_full_name, dirname(__FILE__), $this->default_lang, true);
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
//echo '<p>' . JText::_('COM_HELLOWORLD_PREFLIGHT_' . $type . '_TEXT') . '</p>';
}
/**
* method to run after an install/update/uninstall method
*
* @return void
*/
function postflight($type, $parent) {
$manifest = $parent->getParent()->getManifest();
if ($type == 'install') {
//Get the smallest order value
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('extension_id','element','ordering')))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type').'='.$db->Quote($manifest['type']))
->where($db->quoteName('folder').'='.$db->Quote($manifest['group']))
->order($db->quoteName('ordering').' ASC');
$db->setQuery($query,0,1);
$row = $db->loadAssoc();
$ordering = $row['ordering']-1;
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
$db->quoteName('ordering').'='.$db->Quote($ordering)
);
// Conditions for which records should be updated.
$conditions = array(
$db->quoteName('type').'='.$db->Quote($manifest['type']),
$db->quoteName('folder').'='.$db->Quote($manifest['group']),
$db->quoteName('element').'='.$db->Quote('autoreadmore')
);
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
$db->setQuery($query);
try {// It's a DB usage construction to contain J2.5 and J3.0 approaches
if ($result = $db->execute() ) {
if ($db->getAffectedRows()>0) {
$this->messages[] = JText::_('GJ_INSTALL_ORDERING_SET');
}
else {
throw new Exception(JText::_('GJ_INSTALL_ORDERING_SET_FAILED'));
}
}
else {
throw new Exception($db->getErrorMsg());
}
} catch (Exception $e) {
// Catch the error.
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
}
if ($type != 'uninstall') {
$this->installExtensions($parent);
}
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
//echo '<p>' . JText::_('COM_HELLOWORLD_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
if (!empty($this->messages)) {
echo '<ul><li>'.implode('</li><li>',$this->messages).'</li></ul>';
}
}
private function installExtensions ($parent) {
jimport('joomla.filesystem.folder');
jimport('joomla.installer.installer');
JLoader::register('LanguagesModelInstalled', JPATH_ADMINISTRATOR.'/components/com_languages/models/installed.php');
$lang = new LanguagesModelInstalled();
$current_languages = $lang ->getData();
$locales = array();
foreach($current_languages as $lang) {
$locales[]=$lang->language;
}
$extpath = dirname(__FILE__).'/extensions';
if (!is_dir($extpath)) {
return;
}
$folders = JFolder::folders ($extpath);
foreach ($folders as $folder) {
$folder_temp = explode('_',$folder,2);
if (isset ($folder_temp[0])) {
$check_if_language = $folder_temp[0];
if (preg_match('~[a-z]{2}-[A-Z]{2}~',$check_if_language)) {
if (!in_array($folder_temp[0],$locales)) {
continue;
}
}
}
$installer = new JInstaller();
if ($installer->install($extpath.'/'.$folder)) {
//~ $manifest = $installer->getManifest();
//~ $this->messages[] = JText::sprintf('COM_INSTALLER_INSTALL_SUCCESS','<b style="color:#0055BB;">['.$manifest->name.']<span style="color:green;">').'</span></b>';
}
else {
$this->messages[] = '<span style="color:red;">'.$folder . ' '.JText::_('JERROR_AN_ERROR_HAS_OCCURRED') . '</span>';
}
}
}
}
?>