-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.k2.php
311 lines (275 loc) · 10.2 KB
/
install.k2.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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
/**
* @version 2.8.x
* @package K2
* @author JoomlaWorks http://www.joomlaworks.net
* @copyright Copyright (c) 2006 - 2017 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined('_JEXEC') or die;
if (version_compare(JVERSION, '1.6.0', '<'))
{
jimport('joomla.installer.installer');
// Load K2 language file
$language = JFactory::getLanguage();
$language->load('com_k2');
$db = JFactory::getDBO();
$status = new stdClass;
$status->modules = array();
$status->plugins = array();
$src = $this->parent->getPath('source');
$isUpdate = JFile::exists(JPATH_SITE.'/modules/mod_k2_content/mod_k2_content.php');
$modules = $this->manifest->getElementByPath('modules');
if (is_a($modules, 'JSimpleXMLElement') && count($modules->children()))
{
foreach ($modules->children() as $module)
{
$mname = $module->attributes('module');
$client = $module->attributes('client');
if (is_null($client))
{
$client = 'site';
}
$path = $client == 'administrator' ? $src.'/administrator/modules/'.$mname : $src.'/modules/'.$mname;
$installer = new JInstaller;
$result = $installer->install($path);
$status->modules[] = array('name' => $mname, 'client' => $client, 'result' => $result);
}
if (!$isUpdate)
{
$query = "UPDATE #__modules SET position='icon', ordering=99, published=1 WHERE module='mod_k2_quickicons'";
$db->setQuery($query);
$db->query();
$query = "UPDATE #__modules SET position='cpanel', ordering=0, published=1 WHERE module='mod_k2_stats'";
$db->setQuery($query);
$db->query();
}
}
$plugins = $this->manifest->getElementByPath('plugins');
if (is_a($plugins, 'JSimpleXMLElement') && count($plugins->children()))
{
foreach ($plugins->children() as $plugin)
{
$pname = $plugin->attributes('plugin');
$pgroup = $plugin->attributes('group');
if ($pgroup == 'finder')
{
continue;
}
$path = $src.'/plugins/'.$pgroup;
$installer = new JInstaller;
$result = $installer->install($path);
$query = "UPDATE #__plugins SET published=1 WHERE element=".$db->Quote($pname)." AND folder=".$db->Quote($pgroup);
$db->setQuery($query);
$db->query();
$status->plugins[] = array('name' => $pname, 'group' => $pgroup, 'result' => $result);
}
}
if (JFolder::exists(JPATH_ADMINISTRATOR.'/components/com_joomfish/contentelements'))
{
$elements = $this->manifest->getElementByPath('joomfish');
if (is_a($elements, 'JSimpleXMLElement') && count($elements->children()))
{
foreach ($elements->children() as $element)
{
JFile::copy($src.'/administrator/components/com_joomfish/contentelements/'.$element->data(), JPATH_ADMINISTRATOR.'/components/com_joomfish/contentelements/'.$element->data());
}
}
}
else
{
$mainframe = JFactory::getApplication();
$mainframe->enqueueMessage(JText::_('K2_NOTICE_K2_CONTENT_ELEMENTS_FOR_JOOMFISH_WERE_NOT_COPIED_TO_THE_RELATED_FOLDER_BECAUSE_JOOMFISH_WAS_NOT_FOUND_ON_YOUR_SYSTEM'));
}
if (JFile::exists(JPATH_ADMINISTRATOR.'/components/com_k2/admin.k2.php'))
{
JFile::delete(JPATH_ADMINISTRATOR.'/components/com_k2/admin.k2.php');
}
if (JFile::exists(JPATH_ADMINISTRATOR.'/components/com_k2/models/cpanel.php'))
{
JFile::delete(JPATH_ADMINISTRATOR.'/components/com_k2/models/cpanel.php');
}
$db = JFactory::getDBO();
$fields = $db->getTableFields('#__k2_categories');
if (!array_key_exists('language', $fields['#__k2_categories']))
{
$query = "ALTER TABLE #__k2_categories ADD `language` CHAR(7) NOT NULL";
$db->setQuery($query);
$db->query();
$query = "ALTER TABLE #__k2_categories ADD INDEX (`language`)";
$db->setQuery($query);
$db->query();
}
$fields = $db->getTableFields('#__k2_items');
if (!array_key_exists('featured_ordering', $fields['#__k2_items']))
{
$query = "ALTER TABLE #__k2_items ADD `featured_ordering` INT(11) NOT NULL default '0' AFTER `featured`";
$db->setQuery($query);
$db->query();
}
if (!array_key_exists('language', $fields['#__k2_items']))
{
$query = "ALTER TABLE #__k2_items ADD `language` CHAR(7) NOT NULL";
$db->setQuery($query);
$db->query();
$query = "ALTER TABLE #__k2_items ADD INDEX (`language`)";
$db->setQuery($query);
$db->query();
}
$query = "SELECT COUNT(*) FROM #__k2_user_groups";
$db->setQuery($query);
$num = $db->loadResult();
if ($num == 0)
{
$query = "INSERT INTO #__k2_user_groups (`id`, `name`, `permissions`) VALUES('', 'Registered', 'frontEdit=0\nadd=0\neditOwn=0\neditAll=0\npublish=0\ncomment=1\ninheritance=0\ncategories=all\n\n')";
$db->setQuery($query);
$db->Query();
$query = "INSERT INTO #__k2_user_groups (`id`, `name`, `permissions`) VALUES('', 'Site Owner', 'frontEdit=1\nadd=1\neditOwn=1\neditAll=1\npublish=1\ncomment=1\ninheritance=1\ncategories=all\n\n')";
$db->setQuery($query);
$db->Query();
}
if ($fields['#__k2_items']['video'] != 'text')
{
$query = "ALTER TABLE #__k2_items MODIFY `video` TEXT";
$db->setQuery($query);
$db->query();
}
if ($fields['#__k2_items']['introtext'] == 'text')
{
$query = "ALTER TABLE #__k2_items MODIFY `introtext` MEDIUMTEXT";
$db->setQuery($query);
$db->query();
}
if ($fields['#__k2_items']['fulltext'] == 'text')
{
$query = "ALTER TABLE #__k2_items MODIFY `fulltext` MEDIUMTEXT";
$db->setQuery($query);
$db->query();
}
/*
$query = "SHOW INDEX FROM #__k2_items";
$db->setQuery($query);
$indexes = $db->loadObjectList();
$indexExists = false;
foreach ($indexes as $index)
{
if ($index->Key_name == 'search')
$indexExists = true;
}
if (!$indexExists)
{
$query = "ALTER TABLE #__k2_items ADD FULLTEXT `search` (`title`,`introtext`,`fulltext`,`extra_fields_search`,`image_caption`,`image_credits`,`video_caption`,`video_credits`,`metadesc`,`metakey`)";
$db->setQuery($query);
$db->query();
$query = "ALTER TABLE #__k2_items ADD FULLTEXT (`title`)";
$db->setQuery($query);
$db->query();
}
$query = "SHOW INDEX FROM #__k2_tags";
$db->setQuery($query);
$indexes = $db->loadObjectList();
$indexExists = false;
foreach ($indexes as $index)
{
if ($index->Key_name == 'name')
$indexExists = true;
}
if (!$indexExists)
{
$query = "ALTER TABLE #__k2_tags ADD FULLTEXT (`name`)";
$db->setQuery($query);
$db->query();
}
*/
// Add index for comments count
$query = "SHOW INDEX FROM #__k2_comments";
$db->setQuery($query);
$indexes = $db->loadObjectList();
$indexExists = false;
foreach ($indexes as $index)
{
if ($index->Key_name == 'countComments')
$indexExists = true;
}
if (!$indexExists)
{
$query = "ALTER TABLE #__k2_comments ADD INDEX `countComments` (`itemID`, `published`)";
$db->setQuery($query);
$db->query();
}
$fields = $db->getTableFields('#__k2_users');
if (!array_key_exists('ip', $fields['#__k2_users']))
{
$query = "ALTER TABLE `#__k2_users`
ADD `ip` VARCHAR( 15 ) NOT NULL ,
ADD `hostname` VARCHAR( 255 ) NOT NULL ,
ADD `notes` TEXT NOT NULL";
$db->setQuery($query);
$db->query();
}
$query = "CREATE TABLE IF NOT EXISTS `#__k2_log` (
`status` int(11) NOT NULL,
`response` text NOT NULL,
`timestamp` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$db->setQuery($query);
$db->query();
// Clean up empty entries in #__k2_users table caused by an issue in the K2 user plugin. Fix details: http://code.google.com/p/getk2/source/detail?r=1966
$query = "DELETE FROM #__k2_users WHERE userID = 0";
$db->setQuery($query);
$db->query();
}
?>
<?php if (version_compare(JVERSION, '1.6.0', '<')): ?>
<?php $rows = 0; ?>
<img src="<?php echo JURI::root(true); ?>/media/k2/assets/images/system/k2_logo_126x48.png" alt="K2" align="right" />
<h2><?php echo JText::_('K2_INSTALLATION_STATUS'); ?></h2>
<table class="adminlist">
<thead>
<tr>
<th class="title" colspan="2"><?php echo JText::_('K2_EXTENSION'); ?></th>
<th width="30%"><?php echo JText::_('K2_STATUS'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<tr class="row0">
<td class="key" colspan="2"><?php echo 'K2 '.JText::_('K2_COMPONENT'); ?></td>
<td><strong><?php echo JText::_('K2_INSTALLED'); ?></strong></td>
</tr>
<?php if (count($status->modules)): ?>
<tr>
<th><?php echo JText::_('K2_MODULE'); ?></th>
<th><?php echo JText::_('K2_CLIENT'); ?></th>
<th></th>
</tr>
<?php foreach ($status->modules as $module): ?>
<tr class="row<?php echo(++$rows % 2); ?>">
<td class="key"><?php echo $module['name']; ?></td>
<td class="key"><?php echo ucfirst($module['client']); ?></td>
<td><strong><?php echo ($module['result'])?JText::_('K2_INSTALLED'):JText::_('K2_NOT_INSTALLED'); ?></strong></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php if (count($status->plugins)): ?>
<tr>
<th><?php echo JText::_('K2_PLUGIN'); ?></th>
<th><?php echo JText::_('K2_GROUP'); ?></th>
<th></th>
</tr>
<?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::_('K2_INSTALLED'):JText::_('K2_NOT_INSTALLED'); ?></strong></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php endif; ?>