This repository has been archived by the owner on Oct 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptary.php
201 lines (178 loc) · 5.7 KB
/
scriptary.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/*
* @author Gruz <[email protected]>
* @copyright Copyleft - All rights reversed
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* Script file
*/
class 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::_('You may wish to uninstall GJFields library used together with this extension. Other extensions may also use GJFields. If you uninstall GJFields by mistake, you can always reinstall it.') . '</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>';
}
/**
* A small helper class to get extension name from $this class name
*
* Full description (multiline)
*
* @author Gruz <[email protected]>
* @param type $name Description
* @return type Description
*/
static function _getExtensionName() {
$className = get_called_class();
preg_match('~(?:plg|mod_)(.*)InstallerScript~Ui',$className,$matches);
if (isset($matches[1])) {
return strtolower($matches[1]);
}
return false;
}
/**
* method to run before an install/update/uninstall method
*
* @return void
*/
function preflight($type, $parent) {
$manifest = $parent->getParent()->getManifest();
$this->ext_name = $this->_getExtensionName();
$this->ext_group = (string)$manifest['group'];
$this->ext_type = (string)$manifest['type'];
$className = get_called_class();
$ext = substr($className,0,3);
switch ($ext) {
case 'plg':
$this->ext_full_name = $ext.'_'.$this->ext_group.'_'.$this->ext_name;
break;
case 'mod':
case 'com':
case 'lib':
default :
$this->ext_full_name = $ext.'_'.$this->ext_name;
break;
}
$this->langShortCode = null;//is used for building joomfish links
$this->default_lang = JComponentHelper::getParams('com_languages')->get('admin');
$language = JFactory::getLanguage();
$language->load($this->ext_full_name, dirname(__FILE__), 'en-GB', true);
$language->load($this->ext_full_name, dirname(__FILE__), $this->default_lang, true);
}
/**
* method to run after an install/update/uninstall method
*
* @return void
*/
function postflight( $type, $parent ) {
$manifest = $parent->getParent()->getManifest();
if ($type != 'uninstall') {
$this->_installExtensions($parent);
}
if ($type == 'install' && $this->ext_type == 'plugin') {
$this->_publishPlugin($this->ext_name,$this->ext_group, $this->ext_full_name);
}
// $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 _publishPlugin($plg_name,$plg_type, $plg_full_name = null) {
$plugin = JPluginHelper::getPlugin($plg_type, $plg_name);
$success = true;
if (empty($plugin)) {
//get the smallest order value
$db = jfactory::getdbo();
// publish plugin
$query = $db->getquery(true);
// fields to update.
$fields = array(
$db->quotename('enabled').'='.$db->quote('1')
);
// conditions for which records should be updated.
$conditions = array(
$db->quotename('type').'='.$db->quote('plugin'),
$db->quotename('folder').'='.$db->quote($plg_type),
$db->quotename('element').'='.$db->quote($plg_name),
);
$query->update($db->quotename('#__extensions'))->set($fields)->where($conditions);
$db->setquery($query);
$result = $db->execute();
$getaffectedrows = $db->getAffectedRows();
$success = $getaffectedrows;
}
if (empty($plg_full_name)) { $plg_full_name = $plg_name; }
$msg = jtext::_('jglobal_fieldset_publishing').': <b style="color:blue;"> '.JText::_($plg_full_name).'</b> ... ';
if($success) {
$msg .= '<b style="color:green">'.jtext::_('jpublished').'</b>';
}
else {
$msg .= '<b style="color:red">'.jtext::_('error').'</b>';
}
$this->messages[] = $msg;
}
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>';
}
}
}
}
?>