-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.php
120 lines (98 loc) · 3.24 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
<?php
/**
* Proofreader
*
* @package Proofreader
* @author Sergey M. Litvinov ([email protected])
* @copyright Copyright (C) 2013-2015 by Sergey M. Litvinov. All rights reserved.
* @copyright Copyright (C) 2005-2007 by Alexandr Balashov. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.path');
jimport('joomla.error.error');
class com_proofreaderInstallerScript
{
protected static $minimum_jversion = '2.5.14';
function preflight($type, $parent)
{
if (!version_compare(JVERSION, self::$minimum_jversion, 'ge'))
{
JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_PROOFREADER_ERROR_UNSUPPORTED_JOOMLA_VERSION', self::$minimum_jversion), 'error');
return false;
}
return true;
}
function postflight($type, $parent)
{
$db = JFactory::getDBO();
$src = $parent->getParent()->getPath('source');
$manifest = $parent->getParent()->manifest;
$plugins = $manifest->xpath('plugins/plugin');
foreach ($plugins as $plugin)
{
$name = (string) $plugin->attributes()->plugin;
$group = (string) $plugin->attributes()->group;
$path = $src . '/plugins/' . $group;
if (JFolder::exists($src . '/plugins/' . $group . '/' . $name))
{
$path = $src . '/plugins/' . $group . '/' . $name;
}
$installer = new JInstaller;
$installer->install($path);
$query = $db->getQuery(true);
$query->update($db->quoteName('#__extensions'));
$query->set($db->quoteName('enabled') . ' = 1');
$query->where($db->quoteName('type') . ' = ' . $db->Quote('plugin'));
$query->where($db->quoteName('element') . ' = ' . $db->Quote($name));
$query->where($db->quoteName('folder') . ' = ' . $db->Quote($group));
$db->setQuery($query);
$db->execute();
}
$deprecatedFiles = array(JPATH_SITE . '/components/com_proofreader/controllers/typo.raw.php');
foreach ($deprecatedFiles as $file)
{
if (is_file($file))
{
JFile::delete($file);
}
}
self::displayDonation();
}
function uninstall($parent)
{
$db = JFactory::getDBO();
$manifest = $parent->getParent()->manifest;
$plugins = $manifest->xpath('plugins/plugin');
foreach ($plugins as $plugin)
{
$name = (string) $plugin->attributes()->plugin;
$group = (string) $plugin->attributes()->group;
$query = $db->getQuery(true);
$query->select($db->quoteName('extension_id'));
$query->from($db->quoteName('#__extensions'));
$query->where($db->quoteName('type') . ' = ' . $db->Quote('plugin'));
$query->where($db->quoteName('element') . ' = ' . $db->Quote($name));
$query->where($db->quoteName('folder') . ' = ' . $db->Quote($group));
$db->setQuery($query);
$extensions = $db->loadColumn();
if (count($extensions))
{
foreach ($extensions as $id)
{
$installer = new JInstaller;
$installer->uninstall('plugin', $id);
}
}
}
self::displayDonation();
}
function displayDonation()
{
require_once(JPATH_SITE . '/components/com_proofreader/helpers/layout.php');
$html = ProofreaderLayoutHelper::render('donate', array(), JPATH_ADMINISTRATOR . '/components/com_proofreader/layouts');
echo $html;
}
}