-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.php
1250 lines (1015 loc) · 45.7 KB
/
install.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @package JCE
* @copyright Copyright (c) 2009-2015 Ryan Demmer. All rights reserved.
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* JCE is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
defined('_JEXEC') or die('RESTRICTED');
// try to set time limit
@set_time_limit(0);
// try to increase memory limit
if ((int) ini_get('memory_limit') < 32) {
@ini_set('memory_limit', '32M');
}
abstract class WFInstall {
public static function install($installer) {
error_reporting(E_ERROR | E_WARNING);
// load languages
$language = JFactory::getLanguage();
$language->load('com_jce', JPATH_ADMINISTRATOR, null, true);
$language->load('com_jce.sys', JPATH_ADMINISTRATOR, null, true);
// get manifest
$manifest = $installer->getManifest();
$new_version = (string) $manifest->version;
// Joomla! 1.5
if (!defined('JPATH_PLATFORM') && !$new_version) {
$new_version = (string) $manifest->document->getElementByPath('version')->data();
}
// get version from xml file
if (!$manifest) {
$manifest = JApplicationHelper::parseXMLInstallFile($installer->getPath('manifest'));
if (is_array($manifest)) {
$new_version = $manifest['version'];
}
}
$state = false;
// the current version
$current_version = $new_version;
if (defined('JPATH_PLATFORM')) {
$xml_file = $installer->getPath('extension_administrator') . '/jce.xml';
// check for an xml file
if (is_file($xml_file)) {
if ($xml = JApplicationHelper::parseXMLInstallFile($xml_file)) {
$current_version = $xml['version'];
}
}
} else {
if (basename($installer->getPath('manifest')) == 'legacy.xml') {
$xml_file = JPATH_PLUGINS . '/editors/jce.xml';
// check for an xml file
if ($xml = JApplicationHelper::parseXMLInstallFile($xml_file)) {
$current_version = $xml['version'];
} else {
// check for old tables
if (self::checkTable('#__jce_groups')) {
$current_version = '1.5.0';
}
// check for old tables
if (self::checkTable('#__jce_profiles')) {
$current_version = '2.0.0beta1';
}
}
}
}
// install profiles etc.
$state = self::installProfiles();
// perform upgrade
if (version_compare($current_version, $new_version, '<')) {
$state = self::upgrade($current_version);
}
// Add device column
if (self::checkTableColumn('#__wf_profiles', 'device') === false) {
$db = JFactory::getDBO();
switch (strtolower($db->name)) {
case 'mysql':
case 'mysqli':
$query = 'ALTER TABLE #__wf_profiles CHANGE `description` `description` TEXT';
$db->setQuery($query);
$db->query();
// Change types field to TEXT
$query = 'ALTER TABLE #__wf_profiles CHANGE `types` `types` TEXT';
$db->setQuery($query);
$db->query();
// Add device field - MySQL
$query = 'ALTER TABLE #__wf_profiles ADD `device` VARCHAR(255) AFTER `area`';
break;
case 'sqlsrv':
case 'sqlazure':
case 'sqlzure':
$query = 'ALTER TABLE #__wf_profiles ADD `device` NVARCHAR(250)';
break;
case 'postgresql':
$query = 'ALTER TABLE #__wf_profiles ADD "device" character varying(255) NOT NULL';
break;
}
$db->setQuery($query);
$db->query();
}
if ($state) {
// legacy (JCE 1.5) cleanup
if (!defined('JPATH_PLATFORM')) {
self::legacyCleanup();
}
$message = '<div id="jce"><style type="text/css" scoped="scoped">' . file_get_contents(dirname(__FILE__) . '/media/css/install.css') . '</style>';
$message .= '<h2>' . JText::_('WF_ADMIN_TITLE') . ' ' . $new_version . '</h2>';
$message .= '<ul class="install">';
$message .= '<li class="success">' . JText::_('WF_ADMIN_DESC') . '<li>';
// install packages (editor plugin, quickicon etc)
$packages = $installer->getPath('source') . '/packages';
// install additional packages
if (is_dir($packages)) {
$message .= self::installPackages($packages);
}
$message .= '</ul>';
$message .= '</div>';
$installer->set('message', $message);
// post-install
self::addIndexfiles(array(dirname(__FILE__), JPATH_SITE . '/components/com_jce', JPATH_PLUGINS . '/jce'));
} else {
$installer->abort();
return false;
}
}
private static function paramsToObject($data) {
$registry = new JRegistry();
$registry->loadIni($data);
return $registry->toObject();
}
private static function loadXMLFile($file) {
$xml = null;
// Disable libxml errors and allow to fetch error information as needed
libxml_use_internal_errors(true);
if (is_file($file)) {
// Try to load the xml file
$xml = simplexml_load_file($file);
}
return $xml;
}
// Upgrade from JCE 1.5.x
private static function upgradeLegacy() {
$app = JFactory::getApplication();
$db = JFactory::getDBO();
$admin = JPATH_ADMINISTRATOR . '/components/com_jce';
$site = JPATH_SITE . '/components/com_jce';
//require_once($admin . '/helpers/parameter.php');
// check for groups table / data
if (self::checkTable('#__jce_groups') && self::checkTableContents('#__jce_groups')) {
jimport('joomla.plugin.helper');
// get plugin
$plugin = JPluginHelper::getPlugin('editors', 'jce');
// get JCE component
$table = JTable::getInstance('component');
$table->loadByOption('com_jce');
// process params to JSON string
$params = self::paramsToObject($table->params);
// set params
$table->params = json_encode(array('editor' => $params));
// store
$table->store();
// get all groups data
$query = 'SELECT * FROM #__jce_groups';
$db->setQuery($query);
$groups = $db->loadObjectList();
// get all plugin data
$query = 'SELECT id, name, icon FROM #__jce_plugins';
$db->setQuery($query);
$plugins = $db->loadAssocList('id');
$map = array(
'advlink' => 'link',
'advcode' => 'source',
'tablecontrols' => 'table',
'cut,copy,paste' => 'clipboard',
'paste' => 'clipboard',
'search,replace' => 'searchreplace',
'cite,abbr,acronym,del,ins,attribs' => 'xhtmlxtras',
'styleprops' => 'style',
'readmore,pagebreak' => 'article',
'ltr,rtl' => 'directionality',
'insertlayer,moveforward,movebackward,absolute' => 'layer'
);
if (self::createProfilesTable()) {
foreach ($groups as $group) {
$row = JTable::getInstance('profiles', 'WFTable');
$rows = array();
// transfer row ids to names
foreach (explode(';', $group->rows) as $item) {
$icons = array();
foreach (explode(',', $item) as $id) {
// spacer
if ($id == '00') {
$icon = 'spacer';
} else {
if (isset($plugins[$id])) {
$icon = $plugins[$id]['icon'];
// map old icon names to new
if (array_key_exists($icon, $map)) {
$icon = $map[$icon];
}
}
}
$icons[] = $icon;
}
$rows[] = implode(',', $icons);
}
// re-assign rows
$row->rows = implode(';', $rows);
$names = array('anchor');
// add lists
if (preg_match('#(numlist|bullist)#', $row->rows)) {
$names[] = 'lists';
}
// add charmap
if (strpos($row->rows, 'charmap') !== false) {
$names[] = 'charmap';
}
// transfer plugin ids to names
foreach (explode(',', $group->plugins) as $id) {
if (isset($plugins[$id])) {
$name = $plugins[$id]['name'];
// map old icon names to new
if (array_key_exists($name, $map)) {
$name = $map[$name];
}
$names[] = $name;
}
}
// re-assign plugins
$row->plugins = implode(',', $names);
// convert params to JSON
$params = self::paramsToObject($group->params);
$data = new StdClass();
// Add lists plugin
$buttons = array();
if (strpos($row->rows, 'numlist') !== false) {
$buttons[] = 'numlist';
// replace "numlist" with "lists"
$row->rows = str_replace('numlist', 'lists', $row->rows);
}
if (strpos($row->rows, 'bullist') !== false) {
$buttons[] = 'bullist';
// replace "bullist" with "lists"
if (strpos($row->rows, 'lists') === false) {
$row->rows = str_replace('bullist', 'lists', $row->rows);
}
}
// remove bullist and numlist
$row->rows = str_replace(array('bullist', 'numlist'), '', $row->rows);
// add lists buttons parameter
if (!empty($buttons)) {
$params->lists_buttons = $buttons;
}
// convert parameters
foreach ($params as $key => $value) {
$parts = explode('_', $key);
$node = array_shift($parts);
// special consideration for imgmanager_ext!!
if (strpos($key, 'imgmanager_ext_') !== false) {
$node = $node . '_' . array_shift($parts);
}
// convert some nodes
if (isset($map[$node])) {
$node = $map[$node];
}
$key = implode('_', $parts);
if ($value !== '') {
if (!isset($data->$node) || !is_object($data->$node)) {
$data->$node = new StdClass();
}
// convert Link parameters
if ($node == 'link' && $key != 'target') {
$sub = $key;
$key = 'links';
if (!isset($data->$node->$key)) {
$data->$node->$key = new StdClass();
}
if (preg_match('#^(content|contacts|static|weblinks|menu)$#', $sub)) {
if (!isset($data->$node->$key->joomlalinks)) {
$data->$node->$key->joomlalinks = new StdClass();
$data->$node->$key->joomlalinks->enable = 1;
}
$data->$node->$key->joomlalinks->$sub = $value;
} else {
$data->$node->$key->$sub = new StdClass();
$data->$node->$key->$sub->enable = 1;
}
} else {
$data->$node->$key = $value;
}
}
}
// re-assign params
$row->params = json_encode($data);
// re-assign other values
$row->name = $group->name;
$row->description = $group->description;
$row->users = $group->users;
$row->types = $group->types;
$row->components = $group->components;
$row->published = $group->published;
$row->ordering = $group->ordering;
// add area data
if ($row->name == 'Default') {
$row->area = 0;
}
if ($row->name == 'Front End') {
$row->area = 1;
}
if (self::checkTable('#__wf_profiles')) {
$name = $row->name;
// check for existing profile
$query = 'SELECT id FROM #__wf_profiles' . ' WHERE name = ' . $db->Quote($name);
$db->setQuery($query);
// create name copy if exists
while ($db->loadResult()) {
$name = JText::sprintf('WF_PROFILES_COPY_OF', $name);
$query = 'SELECT id FROM #__wf_profiles' . ' WHERE name = ' . $db->Quote($name);
$db->setQuery($query);
}
// set name
$row->name = $name;
}
if (!$row->store()) {
$app->enqueueMessage('Conversion of group data failed : ' . $row->name, 'error');
} else {
$app->enqueueMessage('Conversion of group data successful : ' . $row->name);
}
unset($row);
}
// If profiles table empty due to error, install profiles data
if (!self::checkTableContents('#__wf_profiles')) {
self::installProfiles();
} else {
// add Blogger profile
self::installProfile('Blogger');
// add Mobile profile
self::installProfile('Mobile');
}
} else {
return false;
}
// Install profiles
} else {
self::installProfiles();
}
// Remove Plugins menu item
$query = 'DELETE FROM #__components' . ' WHERE admin_menu_link = ' . $db->Quote('option=com_jce&type=plugins');
$db->setQuery($query);
$db->query();
// Update Component Name
$query = 'UPDATE #__components' . ' SET name = ' . $db->Quote('COM_JCE') . ' WHERE ' . $db->Quote('option') . '=' . $db->Quote('com_jce') . ' AND parent = 0';
$db->setQuery($query);
$db->query();
// Fix links for other views and edit names
$menus = array('install' => 'installer', 'group' => 'profiles', 'groups' => 'profiles', 'config' => 'config');
$row = JTable::getInstance('component');
foreach ($menus as $k => $v) {
$query = 'SELECT id FROM #__components' . ' WHERE admin_menu_link = ' . $db->Quote('option=com_jce&type=' . $k);
$db->setQuery($query);
$id = $db->loadObject();
if ($id) {
$row->load($id);
$row->name = $v;
$row->admin_menu_link = 'option=com_jce&view=' . $v;
if (!$row->store()) {
$mainframe->enqueueMessage('Unable to update Component Links for view : ' . strtoupper($v), 'error');
}
}
}
// remove old admin language files
$folders = JFolder::folders(JPATH_ADMINISTRATOR . '/language', '.', false, true, array('.svn', 'CVS', 'en-GB'));
foreach ($folders as $folder) {
$name = basename($folder);
$files = array($name . '.com_jce.ini', $name . '.com_jce.menu.ini', $name . '.com_jce.xml');
foreach ($files as $file) {
if (is_file($folder . '/' . $file)) {
@JFile::delete($folder . '/' . $file);
}
}
}
// remove old site language files
$folders = JFolder::folders(JPATH_SITE . '/language', '.', false, true, array('.svn', 'CVS', 'en-GB'));
foreach ($folders as $folder) {
$files = JFolder::files($folder, '^' . basename($folder) . '\.com_jce([_a-z0-9]+)?\.(ini|xml)$', false, true);
@JFile::delete($files);
}
// remove legacy admin folders
$folders = array('cpanel', 'config', 'css', 'groups', 'plugins', 'img', 'installer', 'js');
foreach ($folders as $folder) {
if (is_dir($admin . '/' . $folder)) {
@JFolder::delete($admin . '/' . $folder);
}
}
// remove legacy admin files
$files = array('editor.php', 'helper.php', 'updater.php');
foreach ($files as $file) {
if (is_file($admin . '/' . $file)) {
@JFile::delete($admin . '/' . $file);
}
}
// remove legacy admin folders
$folders = array('controller', 'css', 'js');
foreach ($folders as $folder) {
if (is_dir($site . '/' . $folder)) {
@JFolder::delete($site . '/' . $folder);
}
}
// remove legacy admin files
$files = array('popup.php');
foreach ($files as $file) {
if (is_file($site . '/' . $file)) {
@JFile::delete($site . '/' . $file);
}
}
if (!defined('JPATH_PLATFORM')) {
// remove old plugin folder
$path = JPATH_PLUGINS . '/editors';
if (is_dir($path . '/jce')) {
@JFolder::delete($path . '/jce');
}
}
return true;
}
private static function installProfile($name) {
$db = JFactory::getDBO();
$query = $db->getQuery(true);
if (is_object($query)) {
$query->select('COUNT(id)')->from('#__wf_profiles')->where('name = ' . $db->Quote($name));
} else {
$query = 'SELECT COUNT(id) FROM #__wf_profiles WHERE name = ' . $db->Quote($name);
}
$db->setQuery($query);
$id = $db->loadResult();
if (!$id) {
// Blogger
$file = JPATH_ADMINISTRATOR . '/components/com_jce/models/profiles.xml';
$xml = self::loadXMLFile($file);
if ($xml) {
foreach ($xml->profiles->children() as $profile) {
if ((string) $profile->attributes()->name == $name) {
$row = JTable::getInstance('profiles', 'WFTable');
require_once(JPATH_ADMINISTRATOR . '/components/com_jce/models/profiles.php');
$groups = WFModelProfiles::getUserGroups((int) $profile->children('area'));
foreach ($profile->children() as $item) {
switch ((string) $item->getName()) {
case 'types':
$row->types = implode(',', $groups);
break;
case 'area':
$row->area = (int) $item;
break;
case 'rows':
$row->rows = (string) $item;
break;
case 'plugins':
$row->plugins = (string) $item;
break;
default:
$key = $item->getName();
$row->$key = (string) $item;
break;
}
}
$row->store();
}
}
}
}
}
/**
* Upgrade database tables and remove legacy folders
* @return Boolean
*/
private static function upgrade($version) {
$app = JFactory::getApplication();
$db = JFactory::getDBO();
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
$admin = JPATH_ADMINISTRATOR . '/components/com_jce';
$site = JPATH_SITE . '/components/com_jce';
// add tables path
JTable::addIncludePath($admin . '/tables');
// upgrade from 1.5.x to 2.0.0 (only in Joomla! 1.5)
if (version_compare($version, '2.0.0', '<') && !defined('JPATH_PLATFORM')) {
return self::upgradeLegacy();
}// end JCE 1.5 upgrade
// Remove folders
$folders = array(
// Remove JQuery folders from admin
$admin . '/media/css/jquery',
$admin . '/media/js/jquery',
// remove plugin package folder
$admin . '/plugin',
// remove legend view
$admin . '/views/legend',
// remove controller from site
$site . '/controller',
// Remove plugin language files (incorporated into main language file)
$site . '/editor/tiny_mce/plugins/article/langs',
$site . '/editor/tiny_mce/plugins/imgmanager/langs',
$site . '/editor/tiny_mce/plugins/link/langs',
$site . '/editor/tiny_mce/plugins/searchreplace/langs',
$site . '/editor/tiny_mce/plugins/style/langs',
$site . '/editor/tiny_mce/plugins/table/langs',
$site . '/editor/tiny_mce/plugins/xhtmlxtras/langs',
// remove paste folder
$site . '/editor/tiny_mce/plugins/paste',
// remove jquery
$site . '/editor/libraries/js/jquery',
// remove browser extension
$site . '/editor/extensions/browser',
// remove browser langs
$site . '/editor/tiny_mce/plugins/browser/langs',
// remove packages
$admin . '/packages',
// remove tinymce langs
$site . '/editor/tiny_mce/langs',
// remove dragupload folder (ranamed to upload)
$site . '/editor/tiny_mce/plugins/dragupload',
// remove googlemaps
$site . '/editor/extensions/aggregator/googlemaps',
// remove extensions folder
$site . '/editor/libraries/js/extensions',
// remove fullpage plugin
$site . '/editor/tiny_mce/plugins/fullpage'
);
foreach ($folders as $folder) {
if (JFolder::exists($folder)) {
@JFolder::delete($folder);
}
}
// Remove files
$files = array(
// remove javascript files from admin (moved to site)
$admin . '/media/js/colorpicker.js',
$admin . '/media/js/help.js',
$admin . '/media/js/html5.js',
$admin . '/media/js/select.js',
$admin . '/media/js/tips.js',
// remove legend.js
$admin . '/media/js/legend.js',
// remove css files from admin (moved to site)
$admin . '/media/css/help.css',
$admin . '/media/css/select.css',
$admin . '/media/css/tips.css',
// remove legend model
$admin . '/models/legend.php',
// remove extension adapter
$admin . '/adapters/extension.php',
// remove error class from site (moved to admin)
$site . '/editor/libraries/classes/error.php',
// remove popup file
$site . '/popup.php',
// remove anchor from theme (moved to plugins)
$site . '/editor/tiny_mce/themes/advanced/css/anchor.css',
$site . '/editor/tiny_mce/themes/advanced/css/js/anchor.js',
$site . '/editor/tiny_mce/themes/advanced/css/tmpl/anchor.php',
// remove redundant file
$site . '/editor/tiny_mce/themes/advanced/css/skins/default/img/items.gif',
// remove search files from file browser (renamed to filter)
$site . '/editor/extensions/browser/css/search.css',
$site . '/editor/extensions/browser/js/search.js',
$site . '/editor/extensions/browser/search.php',
// remove dilg language file from theme (incorporated into main dlg file)
$site . '/editor/tiny_mce/themes/advanced/langs/en_dlg.js',
// remove old jquery UI
$site . '/editor/libraries/jquery/js/jquery-ui-1.9.0.custom.min.js',
$site . '/editor/libraries/jquery/js/jquery-ui-1.10.3.custom.min.js',
// remove old jquery
$site . '/editor/libraries/jquery/js/jquery-1.10.2.min.js',
// remove "touch-punch"
$site . '/editor/libraries/jquery/js/jquery.ui.touch-punch.min.js',
// remove "tiny_mce_utils"
$site . '/editor/libraries/js/tiny_mce_utils.js',
// remove "theme" files
$site . '/editor/libraries/classes/theme.php',
$site . '/editor/tiny_mce/themes/advanced/theme.php',
// remove system helper
$admin . '/helpers/system.php',
// remove tools helper
$admin . '/helpers/tools.php',
// old language files
$site . '/language/en-GB/en-GB.com_jce_advlink.ini',
$site . '/language/en-GB/en-GB.com_jce_browser.ini',
$site . '/language/en-GB/en-GB.com_jce_imgmanager.ini',
$site . '/language/en-GB/en-GB.com_jce_media.ini',
$site . '/language/en-GB/en-GB.com_jce_paste.ini',
$site . '/language/en-GB/en-GB.com_jce_spellchecker.ini',
// remove redundant parameter.js
$admin . '/media/js/parameter.js',
// remove build.xml files
$site . '/editor/extensions/filesystem/build.xml',
$site . '/editor/extensions/links/build.xml',
$site . '/editor/extensions/popups/build.xml',
// remove legend.css
$admin . '/media/css/legend.css',
// remove googlemaps
$site . '/editor/extensions/aggregator/googlemaps.php',
$site . '/editor/extensions/aggregator/googlemaps.xml',
// remove concat files
$admin . '/media/js/jce.js',
$admin . '/media/js/profiles.js',
$admin . '/media/js/extensions.js',
$admin . '/media/js/checklist.js',
$admin . '/media/js/styleformat.js',
$admin . '/media/js/fonts.js',
$admin . '/media/js/blockformats.js',
$admin . '/media/css/colorpicker.css',
$admin . '/media/css/bootstrap.min.css',
$admin . '/media/css/styles.css',
$admin . '/media/css/extensions.css',
$admin . '/media/css/styleformat.css',
$admin . '/media/css/fonts.css',
$admin . '/media/css/blockformats.css',
$admin . '/media/css/layout.css',
$admin . '/media/css/profile.css',
$site . '/editor/libraries/js/html5.js',
$site . '/editor/libraries/js/select.js',
$site . '/editor/libraries/js/tips.js',
$site . '/editor/libraries/js/colorpicker.js',
$site . '/editor/libraries/js/plugin.js',
$site . '/editor/libraries/js/extensions.js',
$site . '/editor/libraries/js/aggregator.js',
$site . '/editor/libraries/js/mediaplayer.js',
$site . '/editor/libraries/js/popups.js',
$site . '/editor/libraries/plupload/plupload.full.js',
$site . '/editor/libraries/js/tree.js',
$site . '/editor/libraries/js/upload.js',
$site . '/editor/libraries/js/browser.js',
$site . '/editor/libraries/js/sort.js',
$site . '/editor/libraries/js/filter.js',
$site . '/editor/libraries/js/manager.js',
$site . '/editor/libraries/js/link.js',
$site . '/editor/libraries/css/reset.css',
$site . '/editor/libraries/css/tips.css',
$site . '/editor/libraries/css/tree.css',
$site . '/editor/libraries/css/dialog.css',
$site . '/editor/libraries/css/upload.css',
$site . '/editor/libraries/css/browser.css',
$site . '/editor/libraries/css/bootstrap.min.css'
);
foreach ($files as $file) {
if (JFile::exists($file)) {
@JFile::delete($file);
}
}
// 2.1 - Add visualblocks plugin
if (version_compare($version, '2.1', '<')) {
$profiles = self::getProfiles();
$profile = JTable::getInstance('Profiles', 'WFTable');
if (!empty($profiles)) {
foreach ($profiles as $item) {
$profile->load($item->id);
if (strpos($profile->rows, 'visualblocks') === false) {
$profile->rows = str_replace('visualchars', 'visualchars,visualblocks', $profile->rows);
}
if (strpos($profile->plugins, 'visualblocks') === false) {
$profile->plugins = str_replace('visualchars', 'visualchars,visualblocks', $profile->plugins);
}
$profile->store();
}
}
}
// 2.1.1 - Add anchor plugin
if (version_compare($version, '2.1.1', '<')) {
$profiles = self::getProfiles();
$profile = JTable::getInstance('Profiles', 'WFTable');
if (!empty($profiles)) {
foreach ($profiles as $item) {
$profile->load($item->id);
// add anchor to end of plugins list
if (strpos($profile->rows, 'anchor') !== false) {
$profile->plugins .= ',anchor';
}
$profile->store();
}
}
}
// 2.2.1 - Add "Blogger" profile
if (version_compare($version, '2.2.1', '<')) {
self::installProfile('Blogger');
}
// 2.2.1 to 2.2.5 - Remove K2Links partial install
if (version_compare($version, '2.2.1', '>') && version_compare($version, '2.2.5', '<')) {
$path = $site . '/editor/extensions/links';
if (is_file($path . '/k2links.php') && is_file($path . '/k2links.xml') && !is_dir($path . '/k2links')) {
@JFile::delete($path . '/k2links.php');
@JFile::delete($path . '/k2links.xml');
}
}
// replace some profile row items
if (version_compare($version, '2.2.8', '<')) {
$profiles = self::getProfiles();
$profile = JTable::getInstance('Profiles', 'WFTable');
if (!empty($profiles)) {
foreach ($profiles as $item) {
$profile->load($item->id);
$profile->rows = str_replace('paste', 'clipboard', $profile->rows);
$profile->plugins = str_replace('paste', 'clipboard', $profile->plugins);
$data = json_decode($profile->params, true);
// swap paste data to 'clipboard'
if ($data && array_key_exists('paste', $data)) {
$params = array();
// add 'paste_' prefix
foreach ($data['paste'] as $k => $v) {
$params['paste_' . $k] = $v;
}
// remove paste parameters
unset($data['paste']);
// assign new params to clipboard
$data['clipboard'] = $params;
}
$profile->params = json_encode($data);
$profile->store();
}
}
}
if (version_compare($version, '2.3.0beta', '<')) {
// add Mobile profile
self::installProfile('Mobile');
}
if (version_compare($version, '2.2.9', '<') || version_compare($version, '2.3.0beta3', '<')) {
$profiles = self::getProfiles();
$profile = JTable::getInstance('Profiles', 'WFTable');
if (!empty($profiles)) {
foreach ($profiles as $item) {
$profile->load($item->id);
$buttons = array('buttons' => array());
if (strpos($profile->rows, 'numlist') !== false) {
$buttons['buttons'][] = 'numlist';
$profile->rows = str_replace('numlist', 'lists', $profile->rows);
}
if (strpos($profile->rows, 'bullist') !== false) {
$buttons['buttons'][] = 'bullist';
if (strpos($profile->rows, 'lists') === false) {
$profile->rows = str_replace('bullist', 'lists', $profile->rows);
}
}
// remove bullist and numlist
$profile->rows = str_replace(array('bullist', 'numlist'), '', $profile->rows);
// replace multiple commas with a single one
$profile->rows = preg_replace('#,+#', ',', $profile->rows);
// fix rows
$profile->rows = str_replace(',;', ';', $profile->rows);
if (!empty($buttons['buttons'])) {
$profile->plugins .= ',lists';
$data = json_decode($profile->params, true);
$data['lists'] = $buttons;
$profile->params = json_encode($data);
$profile->store();
}
}
}
}
// transfer charmap to a plugin
if (version_compare($version, '2.3.2', '<')) {
$profiles = self::getProfiles();
$table = JTable::getInstance('Profiles', 'WFTable');
if (!empty($profiles)) {
foreach ($profiles as $item) {
$table->load($item->id);
if (strpos($table->rows, 'charmap') !== false) {
$table->plugins .= ',charmap';
$table->store();
}
}
}
}
// transfer styleselect, fontselect, fontsize etc. to a plugin
if (version_compare($version, '2.3.5', '<')) {
$profiles = self::getProfiles();
$table = JTable::getInstance('Profiles', 'WFTable');
if (!empty($profiles)) {
foreach ($profiles as $item) {
$table->load($item->id);
$plugins = explode(',', $table->plugins);
if (strpos($table->rows, 'formatselect') !== false) {
$plugins[] = 'formatselect';
}
if (strpos($table->rows, 'styleselect') !== false) {
$plugins[] = 'styleselect';
}
if (strpos($table->rows, 'fontselect') !== false) {
$plugins[] = 'fontselect';
}
if (strpos($table->rows, 'fontsizeselect') !== false) {
$plugins[] = 'fontsizeselect';
}
if (strpos($table->rows, 'forecolor') !== false || strpos($table->rows, 'backcolor') !== false) {
$plugins[] = 'fontcolor';
}
$table->plugins = implode(',', $plugins);
$table->store();
}
}
}
return true;
}
private static function getProfiles() {
$db = JFactory::getDBO();
$query = $db->getQuery(true);
if (is_object($query)) {
$query->select('id')->from('#__wf_profiles');
} else {
$query = 'SELECT id FROM #__wf_profiles';
}
$db->setQuery($query);
return $db->loadObjectList();
}
private static function createProfilesTable() {
include_once (dirname(__FILE__) . '/includes/base.php');
include_once (dirname(__FILE__) . '/models/profiles.php');
$profiles = new WFModelProfiles();
if (method_exists($profiles, 'createProfilesTable')) {
return $profiles->createProfilesTable();
}
return false;
}
private static function installProfiles() {
include_once (dirname(__FILE__) . '/includes/base.php');