forked from Percha/fieldsattach_j3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
264 lines (215 loc) · 11 KB
/
install.php
File metadata and controls
264 lines (215 loc) · 11 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
defined('JPATH_PLATFORM') or die;
jimport('joomla.installer.helper');
//this is intializer.php
defined('DS')? null :define('DS',DIRECTORY_SEPARATOR);
/**
* Script file of FIELDSATTACH component
*/
class com_fieldsattachInstallerScript
{
/**
* method to install the component
*
* @return void
* <div id="system-message-container">
<div id="system-message">
<div class="alert alert-message"><a class="close" data-dismiss="alert">×</a>
<h4 class="alert-heading">Message</h4>
<div>
<p>Installing component was successful.</p>
</div>
</div>
</div>
</div>
*/
function install($parent)
{
// $parent is the class calling this method
echo '<div id="system-message-container">';
$msgtext="";
echo '<div id="system-message">
<div style=" overflow:hidden; margin:8px 0 8px 0; padding:5px;" >
<div style=" font-size:12px; margin:0px 0 0px 0; padding:5px; position:relative; float:right;"><div>Powered by Percha.com</div></div>
<div style="float:left; margin:0 20px 20px 0;"><img src="http://www.fieldsattach.com/images/logo_fieldsattach_small.png" alt="fieldsattach.com" /></div>
<div style=" margin:30px 0 8px 0; padding:5px; font-size:23px; color:#4892AB;">Thanks for install the Fieldsattach component.</div>
</div>';
//INSTALL THE PLUGINS *******************************************************************************
$installer = new JInstaller();
//$installer->_overwrite = true;
$pkg_path = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_fieldsattach'.DS.'extensions'.DS;
$pkgs = array(
'input.zip'=>'Plugin fieldsattachment <strong>Input</strong>',
'file.zip'=>'Plugin fieldsattachment <strong>File</strong>' ,
'image.zip'=>'Plugin fieldsattachment <strong>image</strong>' ,
'imagegallery.zip'=>'Plugin fieldsattachment <strong>imagegallery</strong>' ,
'select.zip'=>'Plugin fieldsattachment <strong>select</strong>' ,
'textarea.zip'=>'Plugin fieldsattachment <strong>textarea</strong>',
'content_fieldsattachment.zip'=>'Plugin Content FieldsAttachment',
'system_fieldsattachment.zip'=>'Plugin System FieldsAttachment',
'advancedsearch_fieldsattachment.zip'=>'Plugin Advanced Search FieldsAttachment',
'filterarticles.zip'=>'Plugin Advanced FILTER FieldsAttachment'
);
foreach( $pkgs as $pkg => $pkgname ):
$package = JInstallerHelper::unpack( $pkg_path.$pkg );
if( $installer->install( $package['dir'] ) )
{
$msgtext .= '<div id="system-message-container"><div class="alert alert-message">'.$pkgname.' successfully installed.</div></div>';
//ACTIVE IT
}
else
{
$msgtext .= '<div id="system-message-container"><div class="alert alert-message">ERROR: Could not install the $pkgname. Please install manually</div></div>';
}
//ACTIVE THE PLUGINS *******************************************************************************
$db = JFactory::getDBO();
$sql = "UPDATE #__extensions SET enabled = 1 WHERE element = 'fieldsattachment'";
$db->setQuery($sql);
$db->query();
$db = JFactory::getDBO();
$sql = "UPDATE #__extensions SET enabled = 1 WHERE element = 'fieldsattachmentadvanced'";
$db->setQuery($sql);
$db->query();
$db = JFactory::getDBO();
$sql = "UPDATE #__extensions SET enabled = 1 WHERE folder = 'fieldsattachment'";
$db->setQuery($sql);
$db->query();
//DESACTIVE OLD SEARCH
$db = JFactory::getDBO();
$sql = "UPDATE #__extensions SET enabled = 0 WHERE element = 'fieldsattachment' AND folder='search'";
$db->setQuery($sql);
$db->query();
JInstallerHelper::cleanupInstall( $pkg_path.$pkg, $package['dir'] );
endforeach;
//DELETE EXTENSIONS
$pkg_path = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_fieldsattach'.DS.'extensions'.DS;
destroy_dir($pkg_path);
$msgtext .= '<div id="system-message-container"><div class="alert alert-message">Clean install directory: '.$pkg_path.'</div></div>' ;
echo $msgtext;
echo '</div>';
//$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-1') . '</p>';
$msgtext ='';
$msgtext ='<div style=" font-size:14px; ">UNINSTALL FieldsAttach in content article for Joomla</div>';
$msgtext .= '<div style="border:1px dashed #cccccc; font-size:14px; margin:8px 0 8px 0; padding:5px;" >';
$msgtext .= 'Component uninstall FieldsAttach success';
$msgtext .= '</div>';
$db = JFactory::getDBO();
$sql = "UPDATE #__extensions SET enabled = 0 WHERE folder = 'fieldsattachment'";
$db->setQuery($sql);
$db->query();
$db = JFactory::getDBO();
$sql = "UPDATE #__extensions SET enabled = 0 WHERE element = 'fieldsattachment'";
$db->setQuery($sql);
$db->query();
$db = JFactory::getDBO();
$sql = "UPDATE #__extensions SET enabled = 0 WHERE element = 'fieldsattachmentadvanced'";
$db->setQuery($sql);
$db->query();
$db = JFactory::getDBO();
$db->setQuery("select extension_id , name from #__extensions where folder = 'fieldsattachment'");
$plugins = $db->loadObjectList();
if($plugins)
{
foreach($plugins as $plugin)
{
$plugin_uninstaller = new JInstaller;
$msgtext .= '<div style="border:1px dashed #cccccc; font-size:14px; margin:8px 0 8px 0; padding:5px;" >';
if($plugin_uninstaller->uninstall('plugin', $plugin->extension_id))
$msgtext .= 'Plugin '.$plugin->name.' uninstall fieldsattachment success <br />';
else
$msgtext .= 'Plugin '.$plugin->name.' uninstall fieldsattachment failed<br />';
$msgtext .= '</div>';
}
}
//******************
$db->setQuery("select extension_id , name from #__extensions where element = 'fieldsattachment'");
$plugins = $db->loadObjectList();
if($plugins)
{
foreach($plugins as $plugin)
{
$plugin_uninstaller = new JInstaller;
$msgtext .= '<div style="border:1px dashed #cccccc; font-size:14px; margin:8px 0 8px 0; padding:5px;" >';
if($plugin_uninstaller->uninstall('plugin', $plugin->extension_id))
$msgtext .= 'Plugin '.$plugin->name.' uninstall fieldsattachment success <br />';
else
$msgtext .= 'Plugin '.$plugin->name.' uninstall fieldsattachment failed<br />';
$msgtext .= '</div>';
}
}
//******************
$db->setQuery("select extension_id , name from #__extensions where element = 'fieldsattachmentadvanced'");
$plugins = $db->loadObjectList();
if($plugins)
{
foreach($plugins as $plugin)
{
$plugin_uninstaller = new JInstaller;
$msgtext .= '<div style="border:1px dashed #cccccc; font-size:14px; margin:8px 0 8px 0; padding:5px;" >';
if($plugin_uninstaller->uninstall('plugin', $plugin->extension_id))
$msgtext .= 'Plugin '.$plugin->name.' uninstall fieldsattachment success <br />';
else
$msgtext .= 'Plugin '.$plugin->name.' uninstall fieldsattachment failed<br />';
$msgtext .= '</div>';
}
}
echo $msgtext;
}
/**
* method to update the component
*
* @return void
*/
function update($parent)
{
$this->install($parent);
// $parent is the class calling this method
echo '<div id="system-message-container"><div class="alert alert-message">' . JText::sprintf('Fieldsattach Updated').'</div></div>';
}
/**
* method to run before an install/update/uninstall method
*
* @return void
*/
function preflight($type, $parent)
{
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
//echo '<p>' . JText::_('COM_FIELDSATTACH_PREFLIGHT_' . $type . '_TEXT1') . '</p>';
}
/**
* method to run after an install/update/uninstall method
*
* @return void
*/
function postflight($type, $parent)
{
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
//echo '<p>' . JText::_('COM_FIELDSATTACH_POSTFLIGHT_' . $type . '_TEXT2') . '</p>';
}
}
function destroy_dir($dir) {
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $file) {
if ($file == '.' || $file == '..') continue;
if (!destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) {
chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
if (!destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) return false;
};
}
return rmdir($dir);
}
?>