This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscript.slicomments.php
182 lines (158 loc) · 5.04 KB
/
script.slicomments.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
<?php
// No direct access
defined('_JEXEC') or die;
class Com_sliCommentsInstallerScript
{
public function __construct($installer)
{
$this->installer = $installer;
}
public function install($adapter)
{
$src = dirname(__FILE__);
$status = $this->installPlugins();
$db = JFactory::getDbo();
// Activated the plugins
$db->setQuery("UPDATE `#__extensions` SET enabled = 1 WHERE name = 'plg_content_slicomments'");
$result = $db->query();
?>
<table class="adminlist table-striped">
<thead>
<tr>
<th class="title"><?php echo JText::_('Extension'); ?></th>
<th width="30%"><?php echo JText::_('Status'); ?></th>
</tr>
</thead>
<tbody>
<tr class="row0">
<td class="key">sliComments</td>
<td><strong><?php echo JText::_('Installed'); ?></strong></td>
</tr>
</tbody>
</table>
<?php if (count($status->plugins)) : ?>
<table class="adminlist table-striped">
<thead>
<tr>
<th><?php echo JText::_('Plugin'); ?></th>
<th><?php echo JText::_('Group'); ?></th>
<th><?php echo JText::_('Status'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($status->plugins as $plugin) : ?>
<tr class="row<?php echo (++ $rows % 2); ?>">
<td class="key"><?php echo ucfirst($plugin['name']); ?></td>
<td class="key"><?php echo ucfirst($plugin['group']); ?></td>
<td><strong><?php echo ($plugin['result'])?JText::_('Installed'):'<span style="color:red;">'.JText::_('Not installed').'</span>'; ?></strong></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php
return true;
}
public function update($adapter)
{
// Make sure that the plugins are updated as well
$this->installPlugins();
return true;
}
protected function installPlugins()
{
$src = dirname(__FILE__);
$status = new stdClass;
// Content - sliComments
$installer = new JInstaller;
$result = $installer->install($src.'/plugins/content/slicomments');
$status->plugins[] = array('name' => 'Content - sliComments','group' => 'content', 'result' => $result);
// sliComments - Akismet
$installer = new JInstaller;
$result = $installer->install($src.'/plugins/slicomments/akismet');
$status->plugins[] = array('name' => 'sliComments - Akismet','group' => 'slicomments', 'result' => $result);
// sliComments - Jomsocial
$result = false;
if ($this->componentIsEnabled('com_community'))
{
$installer = new JInstaller;
$result = $installer->install($src.'/plugins/slicomments/jomsocial');
}
$status->plugins[] = array('name' => 'sliComments - Jomsocial','group' => 'slicomments', 'result' => $result);
return $status;
}
public function preflight($type, $adapter)
{
if ($type !== 'update') return true;
// "Fix" Joomla! bug
$row = JTable::getInstance('extension');
$eid = $row->find(array('element' => strtolower($adapter->get('element')), 'type' => 'component'));
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('version_id')
->from('#__schemas')
->where('extension_id = ' . $eid);
$db->setQuery($query);
if ($db->loadResult()) return true;
// Get the previous version
$old_manifest = null;
// Create a new installer because findManifest sets stuff
// Look in the administrator first
$tmpInstaller = new JInstaller;
$tmpInstaller->setPath('source', JPATH_ADMINISTRATOR . '/components/com_slicomments');
if (!$tmpInstaller->findManifest())
{
echo 'Could not find old manifest.';
return false;
}
$old_manifest = $tmpInstaller->getManifest();
$version = (string) $old_manifest->version;
// Store
$data = new stdClass;
$data->extension_id = $eid;
$data->version_id = $version;
$db->insertObject('#__schemas', $data);
return true;
}
public function postflight($type, $adapter)
{
if ($type !== 'install') return true;
// Store the default rules in the database
$db = JFactory::getDbo();
$defaultRules = array(
'post' => array('1' => 1, '2' => 1, '8' => 1),
'auto_publish' => array('6' => 1, '2' => 1, '8' => 1),
'vote' => array('6' => 1, '2' => 1, '8' => 1),
'flag' => array('6' => 1, '2' => 1, '8' => 1),
'edit.own' => array('6' => 1, '8' => 1),
'delete.own' => array('6' => 1, '8' => 1),
'edit' => array('4' => 1, '8' => 1),
'delete' => array('8' => 1),
'manage' => array('8' => 1)
);
jimport('joomla.access.rules');
$rules = new JAccessRules($defaultRules);
$asset = JTable::getInstance('asset');
if (!$asset->loadByName('com_slicomments')) {
$root = JTable::getInstance('asset');
$root->loadByName('root.1');
$asset->name = 'com_slicomments';
$asset->title = 'com_slicomments';
$asset->setLocation($root->id, 'last-child');
}
$asset->rules = (string) $rules;
$asset->check();
$asset->store();
}
protected function componentIsEnabled($option)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('enabled')
->from('#__extensions')
->where($query->qn('type').' = '.$db->quote('component'))
->where($query->qn('element').' = '.$db->quote($option));
$db->setQuery($query);
return (bool) $db->loadResult();
}
}