ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPlugin.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
7
14abstract class ilPlugin
15{
16
20 protected $slot;
24 protected $active = false;
28 protected $iliasmaxversion = "";
32 protected $iliasminversion = "";
36 protected $version = "";
40 protected $lastupdateversion = "";
44 protected $dbversion = 0;
48 protected $lang_initialised = false;
52 protected $id = '';
60 protected $message;
61
62
63 public function __construct()
64 {
65 $this->__init();
66 $this->provider_collection = new PluginProviderCollection();
67 }
68
69
77 abstract public function getComponentType();
78
79
87 abstract public function getComponentName();
88
89
97 abstract public function getSlot();
98
99
107 abstract public function getSlotId();
108
109
118 abstract public function getPluginName();
119
120
126 private function setId($a_id)
127 {
128 $this->id = $a_id;
129 }
130
131
135 public function getId() : string
136 {
137 return $this->id;
138 }
139
140
146 private function setLastUpdateVersion(string $a_lastupdateversion)
147 {
148 $this->lastupdateversion = $a_lastupdateversion;
149 }
150
151
157 public function getLastUpdateVersion() : string
158 {
160 }
161
162
166 private function setVersion(string $a_version)
167 {
168 $this->version = $a_version;
169 }
170
171
175 public function getVersion() : string
176 {
177 return $this->version;
178 }
179
180
184 private function setIliasMinVersion(string $a_iliasminversion)
185 {
186 $this->iliasminversion = $a_iliasminversion;
187 }
188
189
193 public function getIliasMinVersion() : string
194 {
196 }
197
198
202 private function setIliasMaxVersion(string $a_iliasmaxversion)
203 {
204 $this->iliasmaxversion = $a_iliasmaxversion;
205 }
206
207
213 public function getIliasMaxVersion()
214 {
216 }
217
218
222 private function setActive(bool $a_active)
223 {
224 $this->active = $a_active;
225 }
226
227
231 public function getActive() : bool
232 {
233 return $this->active;
234 }
235
236
240 protected function setSlotObject(ilPluginSlot $a_slot)
241 {
242 $this->slot = $a_slot;
243 }
244
245
249 protected function getSlotObject() : ilPluginSlot
250 {
251 return $this->slot;
252 }
253
254
258 public function setDBVersion(int $a_dbversion)
259 {
260 $this->dbversion = $a_dbversion;
261 }
262
263
267 public function getDBVersion() : int
268 {
269 return $this->dbversion;
270 }
271
272
276 public function writeDBVersion(int $a_dbversion)
277 {
278 global $DIC;
279 $ilDB = $DIC->database();
280
281 $this->setDBVersion($a_dbversion);
282
283 $q = "UPDATE il_plugin SET db_version = " . $ilDB->quote((int) $this->getDBVersion(), "integer") .
284 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
285 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
286 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
287 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
288
289 $ilDB->manipulate($q);
290 }
291
292
298 public function getDirectory() : string
299 {
300 return $this->getSlotObject()->getPluginsDirectory() . "/" . $this->getPluginName();
301 }
302
303
307 public static function _getDirectory(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : string
308 {
309 return ilPluginSlot::_getPluginsDirectory($a_ctype, $a_cname, $a_slot_id) . "/" . $a_pname;
310 }
311
312
316 protected function getClassesDirectory() : string
317 {
318 return $this->getDirectory() . "/classes";
319 }
320
321
325 public function includeClass($a_class_file_name)
326 {
327 include_once($this->getClassesDirectory() . "/" . $a_class_file_name);
328 }
329
330
334 protected function getLanguageDirectory() : string
335 {
336 return $this->getDirectory() . "/lang";
337 }
338
339
343 public static function getAvailableLangFiles(string $a_lang_directory) : array
344 {
345 $langs = array();
346
347 if (!@is_dir($a_lang_directory)) {
348 return array();
349 }
350
351 $dir = opendir($a_lang_directory);
352 while ($file = readdir($dir)) {
353 if ($file != "." and
354 $file != ".."
355 ) {
356 // directories
357 if (@is_file($a_lang_directory . "/" . $file)) {
358 if (substr($file, 0, 6) == "ilias_"
359 && substr($file, strlen($file) - 5) == ".lang"
360 ) {
361 $langs[] = array(
362 "key" => substr($file, 6, 2),
363 "file" => $file,
364 "path" => $a_lang_directory . "/" . $file,
365 );
366 }
367 }
368 }
369 }
370
371 return $langs;
372 }
373
374
384 public static function hasConfigureClass(string $a_slot_dir, array $plugin_data, array $plugin_db_data) : bool
385 {
386 // Mantis: 23282: Disable plugin config page for incompatible plugins
387 if (!(ilComponent::isVersionGreaterString($plugin_data["ilias_min_version"], ILIAS_VERSION_NUMERIC)
388 || ilComponent::isVersionGreaterString(ILIAS_VERSION_NUMERIC, $plugin_data["ilias_max_version"])
389 || ilComponent::isVersionGreaterString($plugin_db_data["last_update_version"], $plugin_data["version"]))
390 ) {
391 if (is_file($a_slot_dir . "/" . $plugin_data["name"] . "/classes/class.il" . $plugin_data["name"] . "ConfigGUI.php")) {
392 return true;
393 }
394 }
395
396 return false;
397 }
398
399
407 public static function getConfigureClassName(array $plugin_data) : string
408 {
409 return "il" . $plugin_data["name"] . "ConfigGUI";
410 }
411
412
416 public function getPrefix() : string
417 {
418 return $this->getSlotObject()->getPrefix() . "_" . $this->getId();
419 }
420
421
430 public static function getDBUpdateScriptName(string $a_ctype, string $a_cname, string $a_slot_name, string $a_pname) : string
431 {
432 return "Customizing/global/plugins/" . $a_ctype . "/" . $a_cname . "/" .
433 $a_slot_name . "/" . $a_pname . "/sql/dbupdate.php";
434 }
435
436
440 public function getTablePrefix()
441 {
442 return $this->getPrefix();
443 }
444
445
451 public function updateLanguages($a_lang_keys = null)
452 {
453 ilGlobalCache::flushAll();
454
455 // get the keys of all installed languages if keys are not provided
456 if (!isset($a_lang_keys)) {
457 $a_lang_keys = array();
458 foreach (ilObjLanguage::getInstalledLanguages() as $langObj) {
459 if ($langObj->isInstalled()) {
460 $a_lang_keys[] = $langObj->getKey();
461 }
462 }
463 }
464
465 $langs = $this->getAvailableLangFiles($this->getLanguageDirectory());
466
467 $prefix = $this->getPrefix();
468
469 foreach ($langs as $lang) {
470 // check if the language should be updated, otherwise skip it
471 if (!in_array($lang['key'], $a_lang_keys)) {
472 continue;
473 }
474
475 $txt = file($this->getLanguageDirectory() . "/" . $lang["file"]);
476 $lang_array = array();
477
478 // get locally changed variables of the module (these should be kept)
479 $local_changes = ilObjLanguage::_getLocalChangesByModule($lang['key'], $prefix);
480
481 // get language data
482 if (is_array($txt)) {
483 foreach ($txt as $row) {
484 if ($row[0] != "#" && strpos($row, "#:#") > 0) {
485 $a = explode("#:#", trim($row));
486 $identifier = $prefix . "_" . trim($a[0]);
487 $value = trim($a[1]);
488
489 if (isset($local_changes[$identifier])) {
490 $lang_array[$identifier] = $local_changes[$identifier];
491 } else {
492 $lang_array[$identifier] = $value;
493 ilObjLanguage::replaceLangEntry($prefix, $identifier, $lang["key"], $value);
494 }
495 //echo "<br>-$prefix-".$prefix."_".trim($a[0])."-".$lang["key"]."-";
496 }
497 }
498 }
499
500 ilObjLanguage::replaceLangModule($lang["key"], $prefix, $lang_array);
501 }
502 }
503
504
508 public function updateDatabase()
509 {
510 global $DIC;
511 $ilDB = $DIC->database();
512 $lng = $DIC->language();
513
514 ilGlobalCache::flushAll();
515
516 $dbupdate = new ilPluginDBUpdate(
517 $this->getComponentType(),
518 $this->getComponentName(),
519 $this->getSlotId(),
520 $this->getPluginName(),
521 $ilDB,
522 true,
523 $this->getTablePrefix()
524 );
525
526 $result = $dbupdate->applyUpdate();
527 $message = '';
528 if ($dbupdate->updateMsg == "no_changes") {
529 $message = $lng->txt("no_changes") . ". " . $lng->txt("database_is_uptodate");
530 } else {
531 foreach ($dbupdate->updateMsg as $row) {
532 $message .= $lng->txt($row["msg"]) . ": " . $row["nr"] . "<br/>";
533 }
534 }
535
536 $this->message .= $message;
537 ilGlobalCache::flushAll();
538
539 return $result;
540 }
541
542
546 public function loadLanguageModule()
547 {
548 global $DIC;
549 $lng = $DIC->language();
550
551 if (!$this->lang_initialised && is_object($lng)) {
552 $lng->loadLanguageModule($this->getPrefix());
553 $this->lang_initialised = true;
554 }
555 }
556
557
561 public function txt(string $a_var) : string
562 {
563 global $DIC;
564 $lng = $DIC->language();
565 $this->loadLanguageModule();
566
567 return $lng->txt($this->getPrefix() . "_" . $a_var, $this->getPrefix());
568 }
569
570
578 public static function lookupTxt(string $a_mod_prefix, string $a_pl_id, string $a_lang_var) : string
579 {
580 global $DIC;
581 $lng = $DIC->language();
582
583 // this enables default language fallback
584 $prefix = $a_mod_prefix . "_" . $a_pl_id;
585
586 return $lng->txt($prefix . "_" . $a_lang_var, $prefix);
587 }
588
589
598 public static function langExitsById(string $pluginId, string $langVar) : bool
599 {
600 global $DIC;
601 $lng = $DIC->language();
602
604 $pl->loadLanguageModule();
605
606 return $lng->exists($pl->getPrefix() . "_" . $langVar);
607 }
608
609
619 public function getTemplate(string $a_template, bool $a_par1 = true, bool $a_par2 = true) : ilTemplate
620 {
621 return new ilTemplate($this->getDirectory() . "/templates/" . $a_template, $a_par1, $a_par2);
622 }
623
624
634 public static function _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img) : string
635 {
636 $img = ilUtil::getImagePath($a_img);
637 if (is_int(strpos($img, "Customizing"))) {
638 return $img;
639 }
640
641 // prior to ILIAS 8 Plugin-Icons has to be in a subfolder of 'images' of a skin
642 $directory_prefix = ilComponent::lookupId($a_ctype, $a_cname)
643 . "_"
644 . $a_slot_id
645 . "_" .
646 ilPlugin::lookupIdForName($a_ctype, $a_cname, $a_slot_id, $a_pname);
647
648 $img = ilUtil::getImagePath($directory_prefix . '/' . $a_img);
649 if (is_int(strpos($img, "Customizing"))) {
650 return $img;
651 }
652
653 $plugin_directory = ilPlugin::_getDirectory($a_ctype, $a_cname, $a_slot_id, $a_pname);
654
655 return $plugin_directory . "/templates/images/" . $a_img;
656 }
657
658
662 public function getImagePath(string $a_img) : string
663 {
664 return self::_getImagePath(
665 $this->getComponentType(),
666 $this->getComponentName(),
667 $this->getSlotId(),
668 $this->getPluginName(),
669 $a_img
670 );
671 }
672
673
679 public function getStyleSheetLocation(string $a_css_file) : string
680 {
681 $d2 = ilComponent::lookupId($this->getComponentType(), $this->getComponentName()) . "_" . $this->getSlotId() . "_" .
683
684 $css = ilUtil::getStyleSheetLocation("output", $a_css_file, $d2);
685 if (is_int(strpos($css, "Customizing"))) {
686 return $css;
687 }
688
689 return $this->getDirectory() . "/templates/" . $a_css_file;
690 }
691
692
696 public function addBlockFile($a_tpl, $a_var, $a_block, $a_tplname)
697 {
698 $a_tpl->addBlockFile(
699 $a_var,
700 $a_block,
701 $this->getDirectory() . "/templates/" . $a_tplname
702 );
703 }
704
705
714 public static function createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
715 {
716 global $DIC;
717 $ilDB = $DIC->database();
718
720
721 $q = "INSERT INTO il_plugin (component_type, component_name, slot_id, name)" .
722 " VALUES (" . $ilDB->quote($a_ctype, "text") . "," .
723 $ilDB->quote($a_cname, "text") . "," .
724 $ilDB->quote($a_slot_id, "text") . "," .
725 $ilDB->quote($a_pname, "text") . ")";
726
727 $ilDB->manipulate($q);
728 }
729
730
740 public static function getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : array
741 {
742 $cached_component = ilCachedComponentData::getInstance();
743 $rec = $cached_component->lookupPluginByName($a_pname);
744
745 if ($rec['component_type'] == $a_ctype and $rec['component_name'] == $a_cname and $rec['slot_id'] == $a_slot_id) {
746 return $rec;
747 } else {
748 throw new ilPluginException("No plugin record found for '{$a_ctype}', '{$a_cname}', '{$a_slot_id}', '{$a_pname}");
749 }
750 }
751
752
756 private function __init()
757 {
758 global $DIC;
759 $ilPluginAdmin = $DIC['ilPluginAdmin'];
760
761 // read/set basic data
763 $this->getComponentType(),
764 $this->getComponentName(),
765 $this->getSlotId(),
766 $this->getPluginName()
767 );
768 $this->setLastUpdateVersion((string) $rec["last_update_version"]);
769 $this->setDBVersion((int) $rec["db_version"]);
770 $this->setActive((bool) $rec["active"]);
771
772 // get id
773 $this->setId(
774 $ilPluginAdmin->getId(
775 $this->getComponentType(),
776 $this->getComponentName(),
777 $this->getSlotId(),
778 $this->getPluginName()
779 )
780 );
781
782 // get version
783 $this->setVersion(
784 $ilPluginAdmin->getVersion(
785 $this->getComponentType(),
786 $this->getComponentName(),
787 $this->getSlotId(),
788 $this->getPluginName()
789 )
790 );
791
792 // get ilias min version
793 $this->setIliasMinVersion(
794 $ilPluginAdmin->getIliasMinVersion(
795 $this->getComponentType(),
796 $this->getComponentName(),
797 $this->getSlotId(),
798 $this->getPluginName()
799 )
800 );
801
802 // get ilias max version
803 $this->setIliasMaxVersion(
804 $ilPluginAdmin->getIliasMaxVersion(
805 $this->getComponentType(),
806 $this->getComponentName(),
807 $this->getSlotId(),
808 $this->getPluginName()
809 )
810 );
811
812 // get slot object
813 $this->setSlotObject(
814 new ilPluginSlot(
815 $this->getComponentType(),
816 $this->getComponentName(),
817 $this->getSlotId()
818 )
819 );
820
821 // load language module
822
823 // Fix for authentication plugins
824 $this->loadLanguageModule();
825
826 // call slot and plugin init methods
827 $this->slotInit();
828 $this->init();
829 }
830
831
838 abstract protected function slotInit();
839
840
845 protected function init()
846 {
847 }
848
849
853 public function isActive()
854 {
855 global $DIC;
856 $ilPluginAdmin = $DIC['ilPluginAdmin'];
857
858 return $ilPluginAdmin->isActive(
859 $this->getComponentType(),
860 $this->getComponentName(),
861 $this->getSlotId(),
862 $this->getPluginName()
863 );
864 }
865
866
870 public function needsUpdate()
871 {
872 global $DIC;
873 $ilPluginAdmin = $DIC['ilPluginAdmin'];
874
875 return $ilPluginAdmin->needsUpdate(
876 $this->getComponentType(),
877 $this->getComponentName(),
878 $this->getSlotId(),
879 $this->getPluginName()
880 );
881 }
882
883
884 public function install()
885 {
886 global $DIC;
887 $ilDB = $DIC->database();
888
890 $q = "UPDATE il_plugin SET plugin_id = " . $ilDB->quote($this->getId(), "text") .
891 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
892 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
893 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
894 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
895
896 $ilDB->manipulate($q);
897 $this->afterInstall();
898 }
899
900
904 public function activate()
905 {
906 global $DIC;
907 $ilDB = $DIC->database();
908
910
911 $result = true;
912
913 // check whether update is necessary
914 if ($this->needsUpdate()) {
915 //$result = $this->isUpdatePossible();
916
917 // do update
918 if ($result === true) {
919 $result = $this->update();
920 }
921 }
922 if ($result === true) {
923 $result = $this->beforeActivation();
924 // activate plugin
925 if ($result === true) {
926 $q = "UPDATE il_plugin SET active = " . $ilDB->quote(1, "integer") .
927 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
928 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
929 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
930 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
931
932 $ilDB->manipulate($q);
933 $this->afterActivation();
934 }
935 }
937
938 return $result;
939 }
940
941
947 protected function afterInstall()
948 {
949 }
950
951
955 protected function beforeActivation()
956 {
957 return true; // false would indicate that anything went wrong
958 // activation would not proceed
959 // throw an exception in this case
960 //throw new ilPluginException($lng->txt(""));
961 }
962
963
967 protected function afterActivation()
968 {
969 }
970
971
975 public function deactivate()
976 {
977 global $DIC;
978 $ilDB = $DIC->database();
979
981
982 $result = true;
983
984 $q = "UPDATE il_plugin SET active = " . $ilDB->quote(0, "integer") .
985 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
986 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
987 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
988 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
989
990 $ilDB->manipulate($q);
991 $this->afterDeactivation();
992
993 return $result;
994 }
995
996
1000 protected function afterDeactivation()
1001 {
1002 }
1003
1004
1005 protected function beforeUninstall()
1006 {
1007 // plugin-specific
1008 // false would indicate that anything went wrong
1009 return true;
1010 }
1011
1012
1013 final public function uninstall()
1014 {
1015 global $DIC;
1016 $ilDB = $DIC->database();
1017
1018 if ($this->beforeUninstall()) {
1019 // remove all language entries (see ilObjLanguage)
1020 // see updateLanguages
1021 $prefix = $this->getPrefix();
1022 if ($prefix) {
1023 $ilDB->manipulate(
1024 "DELETE FROM lng_data" .
1025 " WHERE module = " . $ilDB->quote($prefix, "text")
1026 );
1027 $ilDB->manipulate(
1028 "DELETE FROM lng_modules" .
1029 " WHERE module = " . $ilDB->quote($prefix, "text")
1030 );
1031 }
1032
1033 $this->clearEventListening();
1034
1035 // db version is kept in il_plugin - will be deleted, too
1036
1037 $q = "DELETE FROM il_plugin" .
1038 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
1039 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
1040 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
1041 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
1042 $ilDB->manipulate($q);
1043
1044 $ilDB->manipulateF('DELETE FROM ctrl_classfile WHERE comp_prefix=%s', [ilDBConstants::T_TEXT], [$this->getPrefix()]);
1045 $ilDB->manipulateF('DELETE FROM ctrl_calls WHERE comp_prefix=%s', [ilDBConstants::T_TEXT], [$this->getPrefix()]);
1046
1047 $this->afterUninstall();
1048
1050
1051 return true;
1052 }
1053
1054 return false;
1055 }
1056
1057
1061 protected function afterUninstall()
1062 {
1063 }
1064
1065
1069 public function update()
1070 {
1071 global $DIC;
1072 $ilDB = $DIC->database();
1073 $ilCtrl = $DIC->ctrl();
1074
1075 ilGlobalCache::flushAll();
1076
1077 $result = $this->beforeUpdate();
1078 if ($result === false) {
1079 return false;
1080 }
1081
1082 // Load language files
1083 $this->updateLanguages();
1084
1085 // DB update
1086 if ($result === true) {
1087 $result = $this->updateDatabase();
1088 }
1089
1090 // load control structure
1091 $structure_reader = new ilCtrlStructureReader();
1092 $structure_reader->readStructure(
1093 true,
1094 "./" . $this->getDirectory(),
1095 $this->getPrefix(),
1096 $this->getDirectory()
1097 );
1098
1099 // add config gui to the ctrl calls
1100 $ilCtrl->insertCtrlCalls(
1101 "ilobjcomponentsettingsgui",
1102 ilPlugin::getConfigureClassName(["name" => $this->getPluginName()]),
1103 $this->getPrefix()
1104 );
1105
1106 $this->readEventListening();
1107
1108 // set last update version to current version
1109 if ($result === true) {
1110 $q = "UPDATE il_plugin SET last_update_version = " . $ilDB->quote($this->getVersion(), "text") .
1111 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
1112 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
1113 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
1114 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
1115
1116 $ilDB->manipulate($q);
1117 $this->afterUpdate();
1118 }
1119 ilGlobalCache::flushAll();
1120
1121 return $result;
1122 }
1123
1124
1128 protected function readEventListening()
1129 {
1130 $reader = new ilPluginReader(
1131 $this->getDirectory() . '/plugin.xml',
1132 $this->getComponentType(),
1133 $this->getComponentName(),
1134 $this->getSlotId(),
1135 $this->getPluginName()
1136 );
1137 $reader->clearEvents();
1138 $reader->startParsing();
1139 }
1140
1141
1145 protected function clearEventListening()
1146 {
1147 $reader = new ilPluginReader(
1148 $this->getDirectory() . '/plugin.xml',
1149 $this->getComponentType(),
1150 $this->getComponentName(),
1151 $this->getSlotId(),
1152 $this->getPluginName()
1153 );
1154 $reader->clearEvents();
1155 }
1156
1157
1161 protected function beforeUpdate()
1162 {
1163 return true; // false would indicate that anything went wrong
1164 // update would not proceed
1165 // throw an exception in this case
1166 //throw new ilPluginException($lng->txt(""));
1167 }
1168
1169
1173 protected function afterUpdate()
1174 {
1175 }
1176
1185 public static function getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : ilPlugin
1186 {
1187 $slot_name = ilPluginSlot::lookupSlotName($a_ctype, $a_cname, $a_slot_id);
1188
1189 $cached_component = ilCachedComponentData::getInstance();
1190 $rec = $cached_component->lookCompId($a_ctype, $a_cname);
1191 if (!$rec) {
1192 return null;
1193 }
1194
1195 $file = "./Customizing/global/plugins/" . $a_ctype . "/" .
1196 $a_cname . "/" . $slot_name . "/" .
1197 $a_pname . "/classes/class.il" . $a_pname . "Plugin.php";
1198
1199 if (is_file($file)) {
1200 include_once($file);
1201 $class = "il" . $a_pname . "Plugin";
1202 $plugin = new $class();
1203
1204 return $plugin;
1205 }
1206 throw new ilPluginException("File : ".$file. " . does not Exist for plugin: ".$a_pname. " Check if your
1207 plugin is still marked as active in the DB Table 'il_plugin' but not installed anymore.");
1208 }
1209
1210
1221 public static function lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : array
1222 {
1223 global $DIC;
1224 $ilDB = $DIC->database();
1225
1226 $q = "SELECT * FROM il_plugin WHERE" .
1227 " component_type = " . $ilDB->quote($a_ctype, "text") . " AND" .
1228 " component_name = " . $ilDB->quote($a_cname, "text") . " AND" .
1229 " slot_id = " . $ilDB->quote($a_slot_id, "text") . " AND" .
1230 " name = " . $ilDB->quote($a_pname, "text");
1231
1232 $set = $ilDB->query($q);
1233
1234 if ($ilDB->numRows($set) == 0) {
1235 return array();
1236 }
1237
1238 return $ilDB->fetchAssoc($set);
1239 }
1240
1241
1249 public static function getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id) : array
1250 {
1251 global $DIC;
1252 $ilPluginAdmin = $DIC['ilPluginAdmin'];
1253
1254 $plugins = array();
1255
1256 $cached_component = ilCachedComponentData::getInstance();
1257
1258 $lookupActivePluginsBySlotId = $cached_component->lookupActivePluginsBySlotId($a_slot_id);
1259 foreach ($lookupActivePluginsBySlotId as $rec) {
1260 if ($ilPluginAdmin->isActive($a_ctype, $a_cname, $a_slot_id, $rec["name"])) {
1261 $plugins[] = $rec["name"];
1262 }
1263 }
1264
1265 return $plugins;
1266 }
1267
1268
1278 public static function getActivePluginIdsForSlot(string $a_ctype, string $a_cname, string $a_slot_id) : array
1279 {
1280 global $DIC;
1281 $ilPluginAdmin = $DIC['ilPluginAdmin'];
1282
1283 $plugins = array();
1284 $cached_component = ilCachedComponentData::getInstance();
1285 $lookupActivePluginsBySlotId = $cached_component->lookupActivePluginsBySlotId($a_slot_id);
1286 foreach ($lookupActivePluginsBySlotId as $rec) {
1287 if ($ilPluginAdmin->isActive($a_ctype, $a_cname, $a_slot_id, $rec["name"])) {
1288 $plugins[] = $rec["plugin_id"];
1289 }
1290 }
1291
1292 return $plugins;
1293 }
1294
1295
1304 public static function lookupNameForId(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_id)
1305 {
1306 global $DIC;
1307 $ilDB = $DIC->database();
1308
1309 $q = "SELECT name FROM il_plugin " .
1310 " WHERE component_type = " . $ilDB->quote($a_ctype, "text") .
1311 " AND component_name = " . $ilDB->quote($a_cname, "text") .
1312 " AND slot_id = " . $ilDB->quote($a_slot_id, "text") .
1313 " AND plugin_id = " . $ilDB->quote($a_plugin_id, "text");
1314
1315 $set = $ilDB->query($q);
1316 if ($rec = $ilDB->fetchAssoc($set)) {
1317 return $rec["name"];
1318 }
1319 }
1320
1321
1330 public static function lookupIdForName(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_name) : string
1331 {
1332 global $DIC;
1333 $ilDB = $DIC->database();
1334
1335 $q = "SELECT plugin_id FROM il_plugin " .
1336 " WHERE component_type = " . $ilDB->quote($a_ctype, "text") .
1337 " AND component_name = " . $ilDB->quote($a_cname, "text") .
1338 " AND slot_id = " . $ilDB->quote($a_slot_id, "text") .
1339 " AND name = " . $ilDB->quote($a_plugin_name, "text");
1340
1341 $set = $ilDB->query($q);
1342 if ($rec = $ilDB->fetchAssoc($set)) {
1343 return $rec["plugin_id"];
1344 }
1345 }
1346
1347
1353 public static function lookupTypeInformationsForId(string $id)
1354 {
1355 global $DIC;
1356 $ilDB = $DIC->database();
1357
1358 $q = "SELECT component_type, component_name, slot_id FROM il_plugin "
1359 . " WHERE plugin_id = " . $ilDB->quote($id, "text");
1360
1361 $set = $ilDB->query($q);
1362 if ($rec = $ilDB->fetchAssoc($set)) {
1363 return [
1364 $rec["component_type"],
1365 $rec["component_name"],
1366 $rec["slot_id"],
1367 ];
1368 }
1369 }
1370
1371
1379 {
1380 global $DIC;
1381
1382 return new ilPluginGlobalScreenNullProvider($DIC, $this);
1383 }
1384
1385
1390 {
1392 $this->provider_collection->setMainBarProvider($this->promoteGlobalScreenProvider());
1393 }
1394
1396 }
1397
1398
1414 public function exchangeUIRendererAfterInitialization(\ILIAS\DI\Container $dic) : Closure
1415 {
1416 //This returns the callable of $c['ui.renderer'] without executing it.
1417 return $dic->raw('ui.renderer');
1418 }
1419
1420
1439 public function exchangeUIFactoryAfterInitialization(string $dic_key, \ILIAS\DI\Container $dic) : Closure
1440 {
1441 //This returns the callable of $c[$key] without executing it.
1442 return $dic->raw($dic_key);
1443 }
1444
1445
1449 public function getMessage() : string
1450 {
1451 return strval($this->message);
1452 }
1453}
$result
An exception for terminatinating execution or to throw for unit testing.
setMainBarProvider(AbstractStaticMainMenuPluginProvider $static_mai_menu_provider)
static isVersionGreaterString($a_ver1, $a_ver2)
static lookupId($a_type, $a_name)
Lookup ID of a component.
Class ilCtrlStructureReader.
static _getLocalChangesByModule($a_key, $a_module)
Get the local changes of a language module.
static getInstalledLanguages()
Get the language objects of the installed languages.
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
static getPluginObjectByType($type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin.
Database Update class.
Class ilPluginReader.
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
static _getPluginsDirectory($a_ctype, $a_cname, $a_slot_id)
Get plugins directory.
Abstract Class ilPlugin.
setDBVersion(int $a_dbversion)
setActive(bool $a_active)
static lookupNameForId(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_id)
promoteGlobalScreenProvider()
exchangeUIFactoryAfterInitialization(string $dic_key, \ILIAS\DI\Container $dic)
This methods allows to replace some factory for UI Components (see src/UI) of ILIAS after initializat...
static _getDirectory(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Get plugin directory.
static _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img)
needsUpdate()
Check whether update is needed.
static getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
getTablePrefix()
Get db table plugin prefix.
afterActivation()
After activation processing.
static lookupTxt(string $a_mod_prefix, string $a_pl_id, string $a_lang_var)
readEventListening()
Read the event listening definitions from the plugin.xml (if file exists)
updateLanguages($a_lang_keys=null)
exchangeUIRendererAfterInitialization(\ILIAS\DI\Container $dic)
This methods allows to replace the UI Renderer (see src/UI) of ILIAS after initialization by returnin...
includeClass($a_class_file_name)
Include (once) a class file.
activate()
Activate.
isActive()
Check whether plugin is active.
static getAvailableLangFiles(string $a_lang_directory)
Get array of all language files in the plugin.
getSlotId()
Get Slot ID.
static getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
setId($a_id)
Set Id.
getLastUpdateVersion()
Get Version of last update.
clearEventListening()
Clear the entries of this plugin in the event handling table.
static hasConfigureClass(string $a_slot_dir, array $plugin_data, array $plugin_db_data)
Has the plugin a configure class?
txt(string $a_var)
Get Language Variable (prefix will be prepended automatically)
addBlockFile($a_tpl, $a_var, $a_block, $a_tplname)
Add template content to placeholder variable.
getLanguageDirectory()
afterUpdate()
After update processing.
getPrefix()
Get plugin prefix, used for lang vars.
update()
Update plugin.
static getDBUpdateScriptName(string $a_ctype, string $a_cname, string $a_slot_name, string $a_pname)
afterInstall()
After install processing.
setIliasMinVersion(string $a_iliasminversion)
static langExitsById(string $pluginId, string $langVar)
Is searched lang var available in plugin lang files.
static getActivePluginIdsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
Get All active plugin ids for a slot.
static lookupIdForName(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_name)
static lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Lookup information data in il_plugin.
afterUninstall()
This is Plugin-Specific and is triggered after the uninstall command of a plugin.
init()
Object initialization.
getPluginName()
Get Plugin Name.
deactivate()
Deactivate.
getSlot()
Get Slot Name.
static lookupTypeInformationsForId(string $id)
getComponentName()
Get Component Name.
getTemplate(string $a_template, bool $a_par1=true, bool $a_par2=true)
gets a ilTemplate instance of a html-file in the plugin /templates
__init()
Default initialization.
writeDBVersion(int $a_dbversion)
beforeUpdate()
Before update processing.
setSlotObject(ilPluginSlot $a_slot)
getDirectory()
Get Plugin Directory.
getIliasMaxVersion()
Get Required ILIAS max.
beforeActivation()
Before activation processing.
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
loadLanguageModule()
Load language module for plugin.
getImagePath(string $a_img)
Get image path.
setLastUpdateVersion(string $a_lastupdateversion)
Set Version of last update.
slotInit()
Object initialization done by slot.
static getConfigureClassName(array $plugin_data)
Get plugin configure class name.
setVersion(string $a_version)
afterDeactivation()
After deactivation processing.
getStyleSheetLocation(string $a_css_file)
getComponentType()
Get Component Type.
setIliasMaxVersion(string $a_iliasmaxversion)
static createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
getGlobalScreenProviderCollection()
updateDatabase()
Update database.
special template class to simplify handling of ITX/PEAR
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$txt
Definition: error.php:13
global $DIC
Definition: goto.php:24
$img
Definition: imgupload.php:57
const ILIAS_VERSION_NUMERIC
Class HTTPServicesTest.
Class ChatMainBarProvider \MainMenu\Provider.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$dic
Definition: result.php:13
$lng
global $ilDB
$lang
Definition: xapiexit.php:8