1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 jimport('joomla.filesystem.folder');
13
14 15 16 17 18
19 class JInstallerAdapterComponent extends JInstallerAdapter
20 {
21 22 23 24 25 26 27 28 29
30 protected $oldAdminFiles = null;
31
32 33 34 35 36 37 38 39 40
41 protected $oldFiles = null;
42
43 44 45 46 47 48 49
50 protected $manifest_script = null;
51
52 53 54 55 56 57 58
59 protected $install_script = null;
60
61 62 63 64 65 66 67 68
69 protected function checkExtensionInFilesystem()
70 {
71 72 73 74
75 if (file_exists($this->parent->getPath('extension_site')) || file_exists($this->parent->getPath('extension_administrator')))
76 {
77
78 $updateElement = $this->getManifest()->update;
79
80
81 if ($updateElement || $this->parent->isUpgrade()
82 || ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'update')))
83 {
84
85 $this->setRoute('update');
86 }
87 elseif (!$this->parent->isOverwrite())
88 {
89
90 if (file_exists($this->parent->getPath('extension_site')))
91 {
92
93 throw new RuntimeException(
94 JText::sprintf(
95 'JLIB_INSTALLER_ERROR_COMP_INSTALL_DIR_SITE',
96 $this->parent->getPath('extension_site')
97 )
98 );
99 }
100
101
102 throw new RuntimeException(
103 JText::sprintf(
104 'JLIB_INSTALLER_ERROR_COMP_INSTALL_DIR_ADMIN',
105 $this->parent->getPath('extension_administrator')
106 )
107 );
108 }
109 }
110
111 return false;
112 }
113
114 115 116 117 118 119 120 121
122 protected function copyBaseFiles()
123 {
124
125 if ($this->getManifest()->files)
126 {
127 if ($this->route === 'update')
128 {
129 $result = $this->parent->parseFiles($this->getManifest()->files, 0, $this->oldFiles);
130 }
131 else
132 {
133 $result = $this->parent->parseFiles($this->getManifest()->files);
134 }
135
136 if ($result === false)
137 {
138 throw new RuntimeException(
139 JText::sprintf(
140 'JLIB_INSTALLER_ABORT_COMP_FAIL_SITE_FILES',
141 JText::_('JLIB_INSTALLER_' . strtoupper($this->route))
142 )
143 );
144 }
145 }
146
147
148 if ($this->getManifest()->administration->files)
149 {
150 if ($this->route === 'update')
151 {
152 $result = $this->parent->parseFiles($this->getManifest()->administration->files, 1, $this->oldAdminFiles);
153 }
154 else
155 {
156 $result = $this->parent->parseFiles($this->getManifest()->administration->files, 1);
157 }
158
159 if ($result === false)
160 {
161 throw new RuntimeException(
162 JText::sprintf(
163 'JLIB_INSTALLER_ABORT_COMP_FAIL_ADMIN_FILES',
164 JText::_('JLIB_INSTALLER_' . strtoupper($this->route))
165 )
166 );
167 }
168 }
169
170
171 if ($this->manifest_script)
172 {
173 $path['src'] = $this->parent->getPath('source') . '/' . $this->manifest_script;
174 $path['dest'] = $this->parent->getPath('extension_administrator') . '/' . $this->manifest_script;
175
176 if ($this->parent->isOverwrite() || !file_exists($path['dest']))
177 {
178 if (!$this->parent->copyFiles(array($path)))
179 {
180 throw new RuntimeException(
181 JText::sprintf(
182 'JLIB_INSTALLER_ABORT_COMP_COPY_MANIFEST',
183 JText::_('JLIB_INSTALLER_' . strtoupper($this->route))
184 )
185 );
186 }
187 }
188 }
189 }
190
191 192 193 194 195 196 197 198
199 protected function createExtensionRoot()
200 {
201
202 $created = false;
203
204 if (!file_exists($this->parent->getPath('extension_site')))
205 {
206 if (!$created = JFolder::create($this->parent->getPath('extension_site')))
207 {
208 throw new RuntimeException(
209 JText::sprintf(
210 'JLIB_INSTALLER_ERROR_COMP_FAILED_TO_CREATE_DIRECTORY',
211 JText::_('JLIB_INSTALLER_' . strtoupper($this->route)),
212 $this->parent->getPath('extension_site')
213 )
214 );
215 }
216 }
217
218 219 220 221
222 if ($created)
223 {
224 $this->parent->pushStep(
225 array(
226 'type' => 'folder',
227 'path' => $this->parent->getPath('extension_site'),
228 )
229 );
230 }
231
232
233 $created = false;
234
235 if (!file_exists($this->parent->getPath('extension_administrator')))
236 {
237 if (!$created = JFolder::create($this->parent->getPath('extension_administrator')))
238 {
239 throw new RuntimeException(
240 JText::sprintf(
241 'JLIB_INSTALLER_ERROR_COMP_FAILED_TO_CREATE_DIRECTORY',
242 JText::_('JLIB_INSTALLER_' . strtoupper($this->route)),
243 $this->parent->getPath('extension_site')
244 )
245 );
246 }
247 }
248
249 250 251 252
253 if ($created)
254 {
255 $this->parent->pushStep(
256 array(
257 'type' => 'folder',
258 'path' => $this->parent->getPath('extension_administrator'),
259 )
260 );
261 }
262 }
263
264 265 266 267 268 269 270 271
272 protected function finaliseInstall()
273 {
274
275 $update = JTable::getInstance('update');
276
277
278 $uid = $update->find(
279 array(
280 'element' => $this->element,
281 'type' => $this->extension->type,
282 'client_id' => 1,
283 )
284 );
285
286 if ($uid)
287 {
288 $update->delete($uid);
289 }
290
291
292 if ($this->route !== 'discover_install')
293 {
294 if (!$this->parent->copyManifest())
295 {
296
297 throw new RuntimeException(
298 JText::sprintf(
299 'JLIB_INSTALLER_ABORT_COMP_COPY_SETUP',
300 JText::_('JLIB_INSTALLER_' . strtoupper($this->route))
301 )
302 );
303 }
304 }
305
306
307 if (!$this->_buildAdminMenus($this->extension->extension_id))
308 {
309 JLog::add(JText::_('JLIB_INSTALLER_ABORT_COMP_BUILDADMINMENUS_FAILED'), JLog::WARNING, 'jerror');
310 }
311
312
313
314 if (!$this->_updateMenus($this->extension->extension_id))
315 {
316 JLog::add(JText::_('JLIB_INSTALLER_ABORT_COMP_UPDATESITEMENUS_FAILED'), JLog::WARNING, 'jerror');
317 }
318
319
320 $asset = JTable::getInstance('Asset');
321
322
323 if (!$asset->loadByName($this->extension->element))
324 {
325
326 $asset->name = $this->extension->element;
327 $asset->parent_id = 1;
328 $asset->rules = '{}';
329 $asset->title = $this->extension->name;
330 $asset->setLocation(1, 'last-child');
331
332 if (!$asset->store())
333 {
334
335 throw new RuntimeException(
336 JText::sprintf(
337 'JLIB_INSTALLER_ABORT_ROLLBACK',
338 JText::_('JLIB_INSTALLER_' . strtoupper($this->route)),
339 $this->extension->getError()
340 )
341 );
342 }
343 }
344 }
345
346 347 348 349 350 351 352 353 354
355 public function getElement($element = null)
356 {
357 $element = parent::getElement($element);
358
359 if (strpos($element, 'com_') !== 0)
360 {
361 $element = 'com_' . $element;
362 }
363
364 return $element;
365 }
366
367 368 369 370 371 372 373 374 375
376 public function loadLanguage($path = null)
377 {
378 $source = $this->parent->getPath('source');
379 $client = $this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE;
380
381 if (!$source)
382 {
383 $this->parent->setPath('source', $client . '/components/' . $this->parent->extension->element);
384 }
385
386 $extension = $this->getElement();
387 $source = $path ?: $client . '/components/' . $extension;
388
389 if ($this->getManifest()->administration->files)
390 {
391 $element = $this->getManifest()->administration->files;
392 }
393 elseif ($this->getManifest()->files)
394 {
395 $element = $this->getManifest()->files;
396 }
397 else
398 {
399 $element = null;
400 }
401
402 if ($element)
403 {
404 $folder = (string) $element->attributes()->folder;
405
406 if ($folder && file_exists($path . '/' . $folder))
407 {
408 $source = $path . '/' . $folder;
409 }
410 }
411
412 $this->doLoadLanguage($extension, $source);
413 }
414
415 416 417 418 419 420 421
422 protected function parseOptionalTags()
423 {
424
425 $this->parent->parseMedia($this->getManifest()->media);
426 $this->parent->parseLanguages($this->getManifest()->languages);
427 $this->parent->parseLanguages($this->getManifest()->administration->languages, 1);
428 }
429
430 431 432 433 434 435 436 437
438 public function prepareDiscoverInstall()
439 {
440
441 $client = JApplicationHelper::getClientInfo($this->extension->client_id);
442 $short_element = str_replace('com_', '', $this->extension->element);
443 $manifestPath = $client->path . '/components/' . $this->extension->element . '/' . $short_element . '.xml';
444 $this->parent->manifest = $this->parent->isManifest($manifestPath);
445 $this->parent->setPath('manifest', $manifestPath);
446 $this->parent->setPath('source', $client->path . '/components/' . $this->extension->element);
447 $this->parent->setPath('extension_root', $this->parent->getPath('source'));
448 $this->setManifest($this->parent->getManifest());
449
450 $manifest_details = JInstaller::parseXMLInstallFile($this->parent->getPath('manifest'));
451 $this->extension->manifest_cache = json_encode($manifest_details);
452 $this->extension->state = 0;
453 $this->extension->name = $manifest_details['name'];
454 $this->extension->enabled = 1;
455 $this->extension->params = $this->parent->getParams();
456
457 $stored = false;
458
459 try
460 {
461 $this->extension->store();
462 $stored = true;
463 }
464 catch (RuntimeException $e)
465 {
466
467 $db = $this->db;
468
469 $query = $db->getQuery(true)
470 ->select($db->qn('extension_id'))
471 ->from($db->qn('#__extensions'))
472 ->where($db->qn('name') . ' = ' . $db->q($this->extension->name))
473 ->where($db->qn('type') . ' = ' . $db->q($this->extension->type))
474 ->where($db->qn('element') . ' = ' . $db->q($this->extension->element));
475
476 $db->setQuery($query);
477
478 $extension_ids = $db->loadColumn();
479
480 if (!empty($extension_ids))
481 {
482 foreach ($extension_ids as $eid)
483 {
484
485 $this->_removeAdminMenus($eid);
486
487
488
489 $extensionTable = JTable::getInstance('extension');
490 $extensionTable->delete($eid);
491 }
492 }
493 }
494
495 if (!$stored)
496 {
497 try
498 {
499 $this->extension->store();
500 }
501 catch (RuntimeException $e)
502 {
503 throw new RuntimeException(JText::_('JLIB_INSTALLER_ERROR_COMP_DISCOVER_STORE_DETAILS'), $e->getCode(), $e);
504 }
505 }
506 }
507
508 509 510 511 512 513 514 515
516 protected function setupInstallPaths()
517 {
518
519 $this->parent->setPath('extension_site', JPath::clean(JPATH_SITE . '/components/' . $this->element));
520 $this->parent->setPath('extension_administrator', JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $this->element));
521
522
523 $this->parent->setPath('extension_root', $this->parent->getPath('extension_administrator'));
524
525
526 if (!$this->getManifest()->administration)
527 {
528 throw new RuntimeException(JText::_('JLIB_INSTALLER_ERROR_COMP_INSTALL_ADMIN_ELEMENT'));
529 }
530 }
531
532 533 534 535 536 537 538
539 protected function setupUpdates()
540 {
541
542 $old_manifest = null;
543
544
545 $tmpInstaller = new JInstaller;
546 $tmpInstaller->setPath('source', $this->parent->getPath('extension_administrator'));
547
548 if (!$tmpInstaller->findManifest())
549 {
550
551 $tmpInstaller->setPath('source', $this->parent->getPath('extension_site'));
552
553 if ($tmpInstaller->findManifest())
554 {
555 $old_manifest = $tmpInstaller->getManifest();
556 }
557 }
558 else
559 {
560 $old_manifest = $tmpInstaller->getManifest();
561 }
562
563 if ($old_manifest)
564 {
565 $this->oldAdminFiles = $old_manifest->administration->files;
566 $this->oldFiles = $old_manifest->files;
567 }
568 }
569
570 571 572 573 574 575 576 577 578 579
580 protected function storeExtension($deleteExisting = false)
581 {
582
583 if ($this->route === 'discover_install')
584 {
585 return;
586 }
587
588
589 $this->extension->name = $this->name;
590 $this->extension->type = 'component';
591 $this->extension->element = $this->element;
592
593
594 if ($deleteExisting)
595 {
596 $db = $this->parent->getDbo();
597
598 $query = $db->getQuery(true)
599 ->select($db->qn('extension_id'))
600 ->from($db->qn('#__extensions'))
601 ->where($db->qn('name') . ' = ' . $db->q($this->extension->name))
602 ->where($db->qn('type') . ' = ' . $db->q($this->extension->type))
603 ->where($db->qn('element') . ' = ' . $db->q($this->extension->element));
604
605 $db->setQuery($query);
606
607 $extension_ids = $db->loadColumn();
608
609 if (!empty($extension_ids))
610 {
611 foreach ($extension_ids as $eid)
612 {
613
614 $this->_removeAdminMenus($eid);
615
616
617
618 $extensionTable = JTable::getInstance('extension');
619 $extensionTable->delete($eid);
620 }
621 }
622 }
623
624
625 if (!$this->currentExtensionId)
626 {
627 $this->extension->folder = '';
628 $this->extension->enabled = 1;
629 $this->extension->protected = 0;
630 $this->extension->access = 0;
631 $this->extension->client_id = 1;
632 $this->extension->params = $this->parent->getParams();
633 $this->extension->custom_data = '';
634 $this->extension->system_data = '';
635 }
636
637 $this->extension->manifest_cache = $this->parent->generateManifestCache();
638
639 $couldStore = $this->extension->store();
640
641 if (!$couldStore && $deleteExisting)
642 {
643
644 throw new RuntimeException(
645 JText::sprintf(
646 'JLIB_INSTALLER_ABORT_COMP_INSTALL_ROLLBACK',
647 $this->extension->getError()
648 )
649 );
650 }
651
652 if (!$couldStore && !$deleteExisting)
653 {
654
655 $this->storeExtension(true);
656 }
657 }
658
659 660 661 662 663 664 665 666 667
668 public function uninstall($id)
669 {
670 $db = $this->db;
671 $retval = true;
672
673
674
675 if (!$this->extension->load((int) $id))
676 {
677 JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_ERRORUNKOWNEXTENSION'), JLog::WARNING, 'jerror');
678
679 return false;
680 }
681
682
683
684 if ($this->extension->protected)
685 {
686 JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_WARNCORECOMPONENT'), JLog::WARNING, 'jerror');
687
688 return false;
689 }
690
691 692 693 694
695 if ($this->extension->package_id && !$this->parent->isPackageUninstall() && !$this->canUninstallPackageChild($this->extension->package_id))
696 {
697 JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_CANNOT_UNINSTALL_CHILD_OF_PACKAGE', $this->extension->name), JLog::WARNING, 'jerror');
698
699 return false;
700 }
701
702
703 $this->parent->setPath('extension_administrator', JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $this->extension->element));
704 $this->parent->setPath('extension_site', JPath::clean(JPATH_SITE . '/components/' . $this->extension->element));
705
706
707 $this->parent->setPath('extension_root', $this->parent->getPath('extension_administrator'));
708
709 710 711 712 713
714
715
716 $this->parent->setPath('source', $this->parent->getPath('extension_administrator'));
717
718
719
720 $this->parent->findManifest();
721 $this->setManifest($this->parent->getManifest());
722
723 if (!$this->getManifest())
724 {
725
726 JFolder::delete($this->parent->getPath('extension_administrator'));
727 JFolder::delete($this->parent->getPath('extension_site'));
728
729
730 $this->_removeAdminMenus($this->extension->extension_id);
731
732
733 JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_ERRORREMOVEMANUALLY'), JLog::WARNING, 'jerror');
734
735
736 return false;
737 }
738
739
740 $this->set('name', $this->getName());
741 $this->set('element', $this->getElement());
742
743
744 $this->loadLanguage(JPATH_ADMINISTRATOR . '/components/' . $this->element);
745
746 747 748 749 750
751
752 $this->setupScriptfile();
753
754 try
755 {
756 $this->triggerManifestScript('uninstall');
757 }
758 catch (RuntimeException $e)
759 {
760
761 }
762
763 764 765 766 767
768
769
770 try
771 {
772 $this->parseQueries();
773 }
774 catch (RuntimeException $e)
775 {
776 JLog::add($e->getMessage(), JLog::WARNING, 'jerror');
777
778 $retval = false;
779 }
780
781 $this->_removeAdminMenus($this->extension->extension_id);
782
783 784 785 786 787
788
789
790
791 $this->parent->removeFiles($this->getManifest()->media);
792 $this->parent->removeFiles($this->getManifest()->languages);
793 $this->parent->removeFiles($this->getManifest()->administration->languages, 1);
794
795
796 $query = $db->getQuery(true)
797 ->delete('#__schemas')
798 ->where('extension_id = ' . $id);
799 $db->setQuery($query);
800 $db->execute();
801
802
803 $asset = JTable::getInstance('Asset');
804
805 if ($asset->loadByName($this->element))
806 {
807 $asset->delete();
808 }
809
810
811 $query->clear()
812 ->delete('#__categories')
813 ->where('extension=' . $db->quote($this->element), 'OR')
814 ->where('extension LIKE ' . $db->quote($this->element . '.%'));
815 $db->setQuery($query);
816 $db->execute();
817
818
819 $category = JTable::getInstance('category');
820 $category->rebuild();
821
822
823 $update = JTable::getInstance('update');
824 $uid = $update->find(
825 array(
826 'element' => $this->extension->element,
827 'type' => 'component',
828 'client_id' => 1,
829 'folder' => '',
830 )
831 );
832
833 if ($uid)
834 {
835 $update->delete($uid);
836 }
837
838
839 if (trim($this->extension->element))
840 {
841
842 if (is_dir($this->parent->getPath('extension_site')))
843 {
844 if (!JFolder::delete($this->parent->getPath('extension_site')))
845 {
846 JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_FAILED_REMOVE_DIRECTORY_SITE'), JLog::WARNING, 'jerror');
847 $retval = false;
848 }
849 }
850
851
852 if (is_dir($this->parent->getPath('extension_administrator')))
853 {
854 if (!JFolder::delete($this->parent->getPath('extension_administrator')))
855 {
856 JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_FAILED_REMOVE_DIRECTORY_ADMIN'), JLog::WARNING, 'jerror');
857 $retval = false;
858 }
859 }
860
861
862 $this->extension->delete($this->extension->extension_id);
863
864 return $retval;
865 }
866 else
867 {
868
869 JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_NO_OPTION'), JLog::WARNING, 'jerror');
870
871 return false;
872 }
873 }
874
875 876 877 878 879 880 881 882 883
884 protected function ($component_id = null)
885 {
886 $db = $this->parent->getDbo();
887
888 $option = $this->get('element');
889
890
891 $query = $db->getQuery(true)
892 ->select('m.id, e.extension_id')
893 ->from('#__menu AS m')
894 ->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')
895 ->where('m.parent_id = 1')
896 ->where('m.client_id = 1')
897 ->where('m.menutype = ' . $db->quote('main'))
898 ->where('e.element = ' . $db->quote($option));
899
900 $db->setQuery($query);
901
902
903 $componentrows = $db->loadObjectList();
904
905
906 if (!empty($componentrows))
907 {
908
909 if (!$this->parent->isOverwrite())
910 {
911 return true;
912 }
913
914
915 foreach ($componentrows as $componentrow)
916 {
917
918 if ($option)
919 {
920
921 $this->_removeAdminMenus($componentrow->extension_id);
922 }
923 }
924 }
925
926
927 if (empty($component_id))
928 {
929
930 $query->clear()
931 ->select('e.extension_id')
932 ->from('#__extensions AS e')
933 ->where('e.type = ' . $db->quote('component'))
934 ->where('e.element = ' . $db->quote($option));
935
936 $db->setQuery($query);
937 $component_id = $db->loadResult();
938 }
939
940
941 $menuElement = $this->getManifest()->administration->menu;
942
943
944 if (!$menuElement)
945 {
946 return true;
947 }
948
949
950 if (in_array((string) $menuElement['hidden'], array('true', 'hidden')))
951 {
952 return true;
953 }
954
955
956 $data = array();
957
958 if ($menuElement)
959 {
960
961 $data['menutype'] = 'main';
962 $data['client_id'] = 1;
963 $data['title'] = (string) trim($menuElement);
964 $data['alias'] = (string) $menuElement;
965 $data['link'] = 'index.php?option=' . $option;
966 $data['type'] = 'component';
967 $data['published'] = 1;
968 $data['parent_id'] = 1;
969 $data['component_id'] = $component_id;
970 $data['img'] = ((string) $menuElement->attributes()->img) ?: 'class:component';
971 $data['home'] = 0;
972 $data['path'] = '';
973 $data['params'] = '';
974 }
975 else
976 {
977
978 $data = array();
979 $data['menutype'] = 'main';
980 $data['client_id'] = 1;
981 $data['title'] = $option;
982 $data['alias'] = $option;
983 $data['link'] = 'index.php?option=' . $option;
984 $data['type'] = 'component';
985 $data['published'] = 1;
986 $data['parent_id'] = 1;
987 $data['component_id'] = $component_id;
988 $data['img'] = 'class:component';
989 $data['home'] = 0;
990 $data['path'] = '';
991 $data['params'] = '';
992 }
993
994
995 $parent_id = $this->_createAdminMenuItem($data, 1);
996
997 if ($parent_id === false)
998 {
999 return false;
1000 }
1001
1002 1003 1004
1005
1006 if (!$this->getManifest()->administration->submenu)
1007 {
1008
1009 return true;
1010 }
1011
1012 foreach ($this->getManifest()->administration->submenu->menu as $child)
1013 {
1014 $data = array();
1015 $data['menutype'] = 'main';
1016 $data['client_id'] = 1;
1017 $data['title'] = (string) trim($child);
1018 $data['alias'] = (string) $child;
1019 $data['type'] = 'component';
1020 $data['published'] = 1;
1021 $data['parent_id'] = $parent_id;
1022 $data['component_id'] = $component_id;
1023 $data['img'] = ((string) $child->attributes()->img) ?: 'class:component';
1024 $data['home'] = 0;
1025
1026
1027 if ((string) $child->attributes()->link)
1028 {
1029 $data['link'] = 'index.php?' . $child->attributes()->link;
1030 }
1031 else
1032 {
1033 $request = array();
1034
1035 if ((string) $child->attributes()->act)
1036 {
1037 $request[] = 'act=' . $child->attributes()->act;
1038 }
1039
1040 if ((string) $child->attributes()->task)
1041 {
1042 $request[] = 'task=' . $child->attributes()->task;
1043 }
1044
1045 if ((string) $child->attributes()->controller)
1046 {
1047 $request[] = 'controller=' . $child->attributes()->controller;
1048 }
1049
1050 if ((string) $child->attributes()->view)
1051 {
1052 $request[] = 'view=' . $child->attributes()->view;
1053 }
1054
1055 if ((string) $child->attributes()->layout)
1056 {
1057 $request[] = 'layout=' . $child->attributes()->layout;
1058 }
1059
1060 if ((string) $child->attributes()->sub)
1061 {
1062 $request[] = 'sub=' . $child->attributes()->sub;
1063 }
1064
1065 $qstring = count($request) ? '&' . implode('&', $request) : '';
1066 $data['link'] = 'index.php?option=' . $option . $qstring;
1067 }
1068
1069 $submenuId = $this->_createAdminMenuItem($data, $parent_id);
1070
1071 if ($submenuId === false)
1072 {
1073 return false;
1074 }
1075
1076 1077 1078 1079
1080 $this->parent->pushStep(array('type' => 'menu', 'id' => $component_id));
1081 }
1082
1083 return true;
1084 }
1085
1086 1087 1088 1089 1090 1091 1092 1093 1094
1095 protected function ($id)
1096 {
1097 $db = $this->parent->getDbo();
1098
1099
1100 $table = JTable::getInstance('menu');
1101
1102
1103 $query = $db->getQuery(true)
1104 ->select('id')
1105 ->from('#__menu')
1106 ->where($db->quoteName('client_id') . ' = 1')
1107 ->where($db->quoteName('menutype') . ' = ' . $db->q('main'))
1108 ->where($db->quoteName('component_id') . ' = ' . (int) $id);
1109
1110 $db->setQuery($query);
1111
1112 $ids = $db->loadColumn();
1113
1114 $result = true;
1115
1116
1117 if (!empty($ids))
1118 {
1119
1120 foreach ($ids as $menuid)
1121 {
1122 if (!$table->delete((int) $menuid))
1123 {
1124 $this->setError($table->getError());
1125
1126 $result = false;
1127 }
1128 }
1129
1130
1131 $table->rebuild();
1132 }
1133
1134 return $result;
1135 }
1136
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
1147 protected function ($component_id = null)
1148 {
1149 return $this->_updateMenus($component_id, 0);
1150 }
1151
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
1162 protected function ($component_id, $clientId = null)
1163 {
1164 $db = $this->parent->getDbo();
1165 $option = $this->get('element');
1166
1167
1168
1169 $query = $db->getQuery(true)
1170 ->update('#__menu')
1171 ->set('component_id = ' . $db->quote($component_id))
1172 ->where('type = ' . $db->quote('component'))
1173 ->where('(' .
1174 'link LIKE ' . $db->quote('index.php?option=' . $option) . ' OR ' .
1175 'link LIKE ' . $db->q($db->escape('index.php?option=' . $option . '&') . '%', false) .
1176 ')');
1177
1178 if (isset($clientId))
1179 {
1180 $query->where('client_id = ' . (int) $clientId);
1181 }
1182
1183 $db->setQuery($query);
1184
1185 try
1186 {
1187 $db->execute();
1188 }
1189 catch (RuntimeException $e)
1190 {
1191 return false;
1192 }
1193
1194 return true;
1195 }
1196
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
1207 protected function ($step)
1208 {
1209 return $this->_removeAdminMenus($step['id']);
1210 }
1211
1212 1213 1214 1215 1216 1217 1218
1219 public function discover()
1220 {
1221 $results = array();
1222 $site_components = JFolder::folders(JPATH_SITE . '/components');
1223 $admin_components = JFolder::folders(JPATH_ADMINISTRATOR . '/components');
1224
1225 foreach ($site_components as $component)
1226 {
1227 if (file_exists(JPATH_SITE . '/components/' . $component . '/' . str_replace('com_', '', $component) . '.xml'))
1228 {
1229 $manifest_details = JInstaller::parseXMLInstallFile(
1230 JPATH_SITE . '/components/' . $component . '/' . str_replace('com_', '', $component) . '.xml'
1231 );
1232 $extension = JTable::getInstance('extension');
1233 $extension->set('type', 'component');
1234 $extension->set('client_id', 0);
1235 $extension->set('element', $component);
1236 $extension->set('folder', '');
1237 $extension->set('name', $component);
1238 $extension->set('state', -1);
1239 $extension->set('manifest_cache', json_encode($manifest_details));
1240 $extension->set('params', '{}');
1241 $results[] = $extension;
1242 }
1243 }
1244
1245 foreach ($admin_components as $component)
1246 {
1247 if (file_exists(JPATH_ADMINISTRATOR . '/components/' . $component . '/' . str_replace('com_', '', $component) . '.xml'))
1248 {
1249 $manifest_details = JInstaller::parseXMLInstallFile(
1250 JPATH_ADMINISTRATOR . '/components/' . $component . '/' . str_replace('com_', '', $component) . '.xml'
1251 );
1252 $extension = JTable::getInstance('extension');
1253 $extension->set('type', 'component');
1254 $extension->set('client_id', 1);
1255 $extension->set('element', $component);
1256 $extension->set('folder', '');
1257 $extension->set('name', $component);
1258 $extension->set('state', -1);
1259 $extension->set('manifest_cache', json_encode($manifest_details));
1260 $extension->set('params', '{}');
1261 $results[] = $extension;
1262 }
1263 }
1264
1265 return $results;
1266 }
1267
1268 1269 1270 1271 1272 1273 1274
1275 public function refreshManifestCache()
1276 {
1277
1278 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
1279 $short_element = str_replace('com_', '', $this->parent->extension->element);
1280 $manifestPath = $client->path . '/components/' . $this->parent->extension->element . '/' . $short_element . '.xml';
1281 $this->parent->manifest = $this->parent->isManifest($manifestPath);
1282 $this->parent->setPath('manifest', $manifestPath);
1283
1284 $manifest_details = JInstaller::parseXMLInstallFile($this->parent->getPath('manifest'));
1285 $this->parent->extension->manifest_cache = json_encode($manifest_details);
1286 $this->parent->extension->name = $manifest_details['name'];
1287
1288 try
1289 {
1290 return $this->parent->extension->store();
1291 }
1292 catch (RuntimeException $e)
1293 {
1294 JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_REFRESH_MANIFEST_CACHE'), JLog::WARNING, 'jerror');
1295
1296 return false;
1297 }
1298 }
1299
1300 1301 1302 1303 1304 1305 1306 1307
1308 protected function (array &$data, $parentId)
1309 {
1310 $db = $this->parent->getDbo();
1311
1312
1313 $table = JTable::getInstance('menu');
1314
1315 try
1316 {
1317 $table->setLocation($parentId, 'last-child');
1318 }
1319 catch (InvalidArgumentException $e)
1320 {
1321 JLog::add($e->getMessage(), JLog::WARNING, 'jerror');
1322
1323 return false;
1324 }
1325
1326 if (!$table->bind($data) || !$table->check() || !$table->store())
1327 {
1328
1329 $query = $db->getQuery(true)
1330 ->select('id')
1331 ->from('#__menu')
1332 ->where('menutype = ' . $db->q($data['menutype']))
1333 ->where('client_id = 1')
1334 ->where('link = ' . $db->q($data['link']))
1335 ->where('type = ' . $db->q($data['type']))
1336 ->where('parent_id = ' . $db->q($data['parent_id']))
1337 ->where('home = ' . $db->q($data['home']));
1338
1339 $db->setQuery($query);
1340 $menu_id = $db->loadResult();
1341
1342 if (!$menu_id)
1343 {
1344
1345 JError::raiseWarning(1, $table->getError());
1346
1347 return false;
1348 }
1349 else
1350 {
1351
1352 $temporaryTable = JTable::getInstance('menu');
1353 $temporaryTable->delete($menu_id, true);
1354 $temporaryTable->rebuild($data['parent_id']);
1355
1356
1357 $table->setLocation($parentId, 'last-child');
1358
1359 if (!$table->bind($data) || !$table->check() || !$table->store())
1360 {
1361
1362 JError::raiseWarning(1, $table->getError());
1363
1364 return false;
1365 }
1366 }
1367 }
1368
1369 return $table->id;
1370 }
1371 }
1372
1373 1374 1375 1376 1377 1378 1379
1380 class JInstallerComponent extends JInstallerAdapterComponent
1381 {
1382 }
1383