ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 
14 abstract 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 = '';
53 
54 
55  public function __construct()
56  {
57  $this->__init();
58  }
59 
60 
68  abstract public function getComponentType();
69 
70 
78  abstract public function getComponentName();
79 
80 
88  abstract public function getSlot();
89 
90 
98  abstract public function getSlotId();
99 
100 
109  abstract public function getPluginName();
110 
111 
117  private function setId($a_id)
118  {
119  $this->id = $a_id;
120  }
121 
122 
126  public function getId() : string
127  {
128  return $this->id;
129  }
130 
131 
137  private function setLastUpdateVersion(string $a_lastupdateversion)
138  {
139  $this->lastupdateversion = $a_lastupdateversion;
140  }
141 
142 
148  public function getLastUpdateVersion() : string
149  {
151  }
152 
153 
157  private function setVersion(string $a_version)
158  {
159  $this->version = $a_version;
160  }
161 
162 
166  public function getVersion() : string
167  {
168  return $this->version;
169  }
170 
171 
175  private function setIliasMinVersion(string $a_iliasminversion)
176  {
177  $this->iliasminversion = $a_iliasminversion;
178  }
179 
180 
184  public function getIliasMinVersion() : string
185  {
186  return $this->iliasminversion;
187  }
188 
189 
193  private function setIliasMaxVersion(string $a_iliasmaxversion)
194  {
195  $this->iliasmaxversion = $a_iliasmaxversion;
196  }
197 
198 
204  public function getIliasMaxVersion()
205  {
206  return $this->iliasmaxversion;
207  }
208 
209 
213  private function setActive(bool $a_active)
214  {
215  $this->active = $a_active;
216  }
217 
218 
222  public function getActive() : bool
223  {
224  return $this->active;
225  }
226 
227 
231  protected function setSlotObject(ilPluginSlot $a_slot)
232  {
233  $this->slot = $a_slot;
234  }
235 
236 
240  protected function getSlotObject() : ilPluginSlot
241  {
242  return $this->slot;
243  }
244 
245 
249  public function setDBVersion(int $a_dbversion)
250  {
251  $this->dbversion = $a_dbversion;
252  }
253 
254 
258  public function getDBVersion() : int
259  {
260  return $this->dbversion;
261  }
262 
263 
267  public function writeDBVersion(int $a_dbversion)
268  {
269  global $DIC;
270  $ilDB = $DIC->database();
271 
272  $this->setDBVersion($a_dbversion);
273 
274  $q = "UPDATE il_plugin SET db_version = " . $ilDB->quote((int) $this->getDBVersion(), "integer") .
275  " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
276  " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
277  " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
278  " AND name = " . $ilDB->quote($this->getPluginName(), "text");
279 
280  $ilDB->manipulate($q);
281  }
282 
283 
289  public function getDirectory() : string
290  {
291  return $this->getSlotObject()->getPluginsDirectory() . "/" . $this->getPluginName();
292  }
293 
294 
298  public static function _getDirectory(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : string
299  {
300  return ilPluginSlot::_getPluginsDirectory($a_ctype, $a_cname, $a_slot_id) . "/" . $a_pname;
301  }
302 
303 
307  protected function getClassesDirectory() : string
308  {
309  return $this->getDirectory() . "/classes";
310  }
311 
312 
316  public function includeClass($a_class_file_name)
317  {
318  include_once($this->getClassesDirectory() . "/" . $a_class_file_name);
319  }
320 
321 
325  protected function getLanguageDirectory() : string
326  {
327  return $this->getDirectory() . "/lang";
328  }
329 
330 
334  public static function getAvailableLangFiles(string $a_lang_directory) : array
335  {
336  $langs = array();
337 
338  if (!@is_dir($a_lang_directory)) {
339  return array();
340  }
341 
342  $dir = opendir($a_lang_directory);
343  while ($file = readdir($dir)) {
344  if ($file != "." and
345  $file != ".."
346  ) {
347  // directories
348  if (@is_file($a_lang_directory . "/" . $file)) {
349  if (substr($file, 0, 6) == "ilias_"
350  && substr($file, strlen($file) - 5) == ".lang"
351  ) {
352  $langs[] = array("key" => substr($file, 6, 2), "file" => $file,
353  "path" => $a_lang_directory . "/" . $file);
354  }
355  }
356  }
357  }
358 
359  return $langs;
360  }
361 
362 
372  public static function hasConfigureClass(string $a_slot_dir, array $plugin_data, array $plugin_db_data) : bool
373  {
374  // Mantis: 23282: Disable plugin config page for incompatible plugins
375  if (!(ilComponent::isVersionGreaterString($plugin_data["ilias_min_version"], ILIAS_VERSION_NUMERIC)
376  || ilComponent::isVersionGreaterString(ILIAS_VERSION_NUMERIC, $plugin_data["ilias_max_version"])
377  || ilComponent::isVersionGreaterString($plugin_db_data["last_update_version"], $plugin_data["version"]))
378  ) {
379  if (is_file($a_slot_dir . "/" . $plugin_data["name"] . "/classes/class.il" . $plugin_data["name"] . "ConfigGUI.php")) {
380  return true;
381  }
382  }
383 
384  return false;
385  }
386 
387 
395  public static function getConfigureClassName(array $plugin_data) : string
396  {
397  return "il" . $plugin_data["name"] . "ConfigGUI";
398  }
399 
400 
404  public function getPrefix() : string
405  {
406  return $this->getSlotObject()->getPrefix() . "_" . $this->getId();
407  }
408 
409 
418  public static function getDBUpdateScriptName(string $a_ctype, string $a_cname, string $a_slot_name, string $a_pname) : string
419  {
420  return "Customizing/global/plugins/" . $a_ctype . "/" . $a_cname . "/" .
421  $a_slot_name . "/" . $a_pname . "/sql/dbupdate.php";
422  }
423 
424 
428  public function getTablePrefix()
429  {
430  return $this->getPrefix();
431  }
432 
433 
439  public function updateLanguages($a_lang_keys = null)
440  {
441  ilGlobalCache::flushAll();
442 
443  // get the keys of all installed languages if keys are not provided
444  if (!isset($a_lang_keys)) {
445  $a_lang_keys = array();
446  foreach (ilObjLanguage::getInstalledLanguages() as $langObj) {
447  if ($langObj->isInstalled()) {
448  $a_lang_keys[] = $langObj->getKey();
449  }
450  }
451  }
452 
453  $langs = $this->getAvailableLangFiles($this->getLanguageDirectory());
454 
455  $prefix = $this->getPrefix();
456 
457  foreach ($langs as $lang) {
458  // check if the language should be updated, otherwise skip it
459  if (!in_array($lang['key'], $a_lang_keys)) {
460  continue;
461  }
462 
463  $txt = file($this->getLanguageDirectory() . "/" . $lang["file"]);
464  $lang_array = array();
465 
466  // get locally changed variables of the module (these should be kept)
467  $local_changes = ilObjLanguage::_getLocalChangesByModule($lang['key'], $prefix);
468 
469  // get language data
470  if (is_array($txt)) {
471  foreach ($txt as $row) {
472  if ($row[0] != "#" && strpos($row, "#:#") > 0) {
473  $a = explode("#:#", trim($row));
474  $identifier = $prefix . "_" . trim($a[0]);
475  $value = trim($a[1]);
476 
477  if (isset($local_changes[$identifier])) {
478  $lang_array[$identifier] = $local_changes[$identifier];
479  } else {
480  $lang_array[$identifier] = $value;
481  ilObjLanguage::replaceLangEntry($prefix, $identifier, $lang["key"], $value);
482  }
483  //echo "<br>-$prefix-".$prefix."_".trim($a[0])."-".$lang["key"]."-";
484  }
485  }
486  }
487 
488  ilObjLanguage::replaceLangModule($lang["key"], $prefix, $lang_array);
489  }
490  }
491 
492 
496  public function updateDatabase()
497  {
498  global $DIC;
499  $ilDB = $DIC->database();
500  $lng = $DIC->language();
501 
502  ilGlobalCache::flushAll();
503 
504  $dbupdate = new ilPluginDBUpdate(
505  $this->getComponentType(),
506  $this->getComponentName(),
507  $this->getSlotId(),
508  $this->getPluginName(),
509  $ilDB,
510  true,
511  $this->getTablePrefix()
512  );
513 
514  $result = $dbupdate->applyUpdate();
515  $message = '';
516  if ($dbupdate->updateMsg == "no_changes") {
517  $message = $lng->txt("no_changes") . ". " . $lng->txt("database_is_uptodate");
518  } else {
519  foreach ($dbupdate->updateMsg as $row) {
520  $message .= $lng->txt($row["msg"]) . ": " . $row["nr"] . "<br/>";
521  }
522  }
523 
524  $this->message .= $message;
525  ilGlobalCache::flushAll();
526 
527  return $result;
528  }
529 
530 
534  public function loadLanguageModule()
535  {
536  global $DIC;
537  $lng = $DIC->language();
538 
539  if (!$this->lang_initialised && is_object($lng)) {
540  $lng->loadLanguageModule($this->getPrefix());
541  $this->lang_initialised = true;
542  }
543  }
544 
545 
549  public function txt(string $a_var) : string
550  {
551  global $DIC;
552  $lng = $DIC->language();
553  $this->loadLanguageModule();
554 
555  return $lng->txt($this->getPrefix() . "_" . $a_var, $this->getPrefix());
556  }
557 
558 
566  public static function lookupTxt(string $a_mod_prefix, string $a_pl_id, string $a_lang_var) : string
567  {
568  global $DIC;
569  $lng = $DIC->language();
570 
571  // this enables default language fallback
572  $prefix = $a_mod_prefix . "_" . $a_pl_id;
573 
574  return $lng->txt($prefix . "_" . $a_lang_var, $prefix);
575  }
576 
577 
586  public static function langExitsById(string $pluginId, string $langVar) : bool
587  {
588  global $DIC;
589  $lng = $DIC->language();
590 
591  $pl = ilObjectPlugin::getPluginObjectByType($pluginId);
592  $pl->loadLanguageModule();
593 
594  return $lng->exists($pl->getPrefix() . "_" . $langVar);
595  }
596 
597 
607  public function getTemplate(string $a_template, bool $a_par1 = true, bool $a_par2 = true) : ilTemplate
608  {
609  return new ilTemplate($this->getDirectory() . "/templates/" . $a_template, $a_par1, $a_par2);
610  }
611 
612 
622  public static function _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img) : string
623  {
624  $d2 = ilComponent::lookupId($a_ctype, $a_cname) . "_" . $a_slot_id . "_" .
625  ilPlugin::lookupIdForName($a_ctype, $a_cname, $a_slot_id, $a_pname);
626 
627  $img = ilUtil::getImagePath($d2 . "/" . $a_img);
628  if (is_int(strpos($img, "Customizing"))) {
629  return $img;
630  }
631 
632  $d = ilPlugin::_getDirectory($a_ctype, $a_cname, $a_slot_id, $a_pname);
633 
634  return $d . "/templates/images/" . $a_img;
635  }
636 
637 
641  public function getImagePath(string $a_img) : string
642  {
643  return self::_getImagePath(
644  $this->getComponentType(),
645  $this->getComponentName(),
646  $this->getSlotId(),
647  $this->getPluginName(),
648  $a_img
649  );
650  }
651 
652 
658  public function getStyleSheetLocation(string $a_css_file) : string
659  {
660  $d2 = ilComponent::lookupId($this->getComponentType(), $this->getComponentName()) . "_" . $this->getSlotId() . "_" .
662 
663  $css = ilUtil::getStyleSheetLocation("output", $a_css_file, $d2);
664  if (is_int(strpos($css, "Customizing"))) {
665  return $css;
666  }
667 
668  return $this->getDirectory() . "/templates/" . $a_css_file;
669  }
670 
671 
675  public function addBlockFile($a_tpl, $a_var, $a_block, $a_tplname)
676  {
677  $a_tpl->addBlockFile(
678  $a_var,
679  $a_block,
680  $this->getDirectory() . "/templates/" . $a_tplname
681  );
682  }
683 
684 
693  public static function createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
694  {
695  global $DIC;
696  $ilDB = $DIC->database();
697 
699 
700  $q = "INSERT INTO il_plugin (component_type, component_name, slot_id, name)" .
701  " VALUES (" . $ilDB->quote($a_ctype, "text") . "," .
702  $ilDB->quote($a_cname, "text") . "," .
703  $ilDB->quote($a_slot_id, "text") . "," .
704  $ilDB->quote($a_pname, "text") . ")";
705 
706  $ilDB->manipulate($q);
707  }
708 
709 
719  public static function getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : array
720  {
721  $cached_component = ilCachedComponentData::getInstance();
722  $rec = $cached_component->lookupPluginByName($a_pname);
723 
724  if ($rec['component_type'] == $a_ctype and $rec['component_name'] == $a_cname and $rec['slot_id'] == $a_slot_id) {
725  return $rec;
726  } else {
727  throw new ilPluginException("No plugin record found for '{$a_ctype}', '{$a_cname}', '{$a_slot_id}', '{$a_pname}");
728  }
729  }
730 
731 
735  private function __init()
736  {
737  global $DIC;
738  $ilPluginAdmin = $DIC['ilPluginAdmin'];
739 
740  // read/set basic data
742  $this->getComponentType(),
743  $this->getComponentName(),
744  $this->getSlotId(),
745  $this->getPluginName()
746  );
747  $this->setLastUpdateVersion((string) $rec["last_update_version"]);
748  $this->setDBVersion((int) $rec["db_version"]);
749  $this->setActive((bool) $rec["active"]);
750 
751  // get id
752  $this->setId(
753  $ilPluginAdmin->getId(
754  $this->getComponentType(),
755  $this->getComponentName(),
756  $this->getSlotId(),
757  $this->getPluginName()
758  )
759  );
760 
761  // get version
762  $this->setVersion(
763  $ilPluginAdmin->getVersion(
764  $this->getComponentType(),
765  $this->getComponentName(),
766  $this->getSlotId(),
767  $this->getPluginName()
768  )
769  );
770 
771  // get ilias min version
772  $this->setIliasMinVersion(
773  $ilPluginAdmin->getIliasMinVersion(
774  $this->getComponentType(),
775  $this->getComponentName(),
776  $this->getSlotId(),
777  $this->getPluginName()
778  )
779  );
780 
781  // get ilias max version
782  $this->setIliasMaxVersion(
783  $ilPluginAdmin->getIliasMaxVersion(
784  $this->getComponentType(),
785  $this->getComponentName(),
786  $this->getSlotId(),
787  $this->getPluginName()
788  )
789  );
790 
791  // get slot object
792  $this->setSlotObject(
793  new ilPluginSlot(
794  $this->getComponentType(),
795  $this->getComponentName(),
796  $this->getSlotId()
797  )
798  );
799 
800  // load language module
801 
802  // Fix for authentication plugins
803  $this->loadLanguageModule();
804 
805  // call slot and plugin init methods
806  $this->slotInit();
807  $this->init();
808  }
809 
810 
817  abstract protected function slotInit();
818 
819 
824  protected function init()
825  {
826  }
827 
828 
832  public function isActive()
833  {
834  global $DIC;
835  $ilPluginAdmin = $DIC['ilPluginAdmin'];
836 
837  return $ilPluginAdmin->isActive(
838  $this->getComponentType(),
839  $this->getComponentName(),
840  $this->getSlotId(),
841  $this->getPluginName()
842  );
843  }
844 
845 
849  public function needsUpdate()
850  {
851  global $DIC;
852  $ilPluginAdmin = $DIC['ilPluginAdmin'];
853 
854  return $ilPluginAdmin->needsUpdate(
855  $this->getComponentType(),
856  $this->getComponentName(),
857  $this->getSlotId(),
858  $this->getPluginName()
859  );
860  }
861 
862 
863  public function install()
864  {
865  global $DIC;
866  $ilDB = $DIC->database();
867 
869  $q = "UPDATE il_plugin SET plugin_id = " . $ilDB->quote($this->getId(), "text") .
870  " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
871  " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
872  " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
873  " AND name = " . $ilDB->quote($this->getPluginName(), "text");
874 
875  $ilDB->manipulate($q);
876  $this->afterInstall();
877  }
878 
879 
883  public function activate()
884  {
885  global $DIC;
886  $ilDB = $DIC->database();
887 
889 
890  $result = true;
891 
892  // check whether update is necessary
893  if ($this->needsUpdate()) {
894  //$result = $this->isUpdatePossible();
895 
896  // do update
897  if ($result === true) {
898  $result = $this->update();
899  }
900  }
901  if ($result === true) {
902  $result = $this->beforeActivation();
903  // activate plugin
904  if ($result === true) {
905  $q = "UPDATE il_plugin SET active = " . $ilDB->quote(1, "integer") .
906  " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
907  " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
908  " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
909  " AND name = " . $ilDB->quote($this->getPluginName(), "text");
910 
911  $ilDB->manipulate($q);
912  $this->afterActivation();
913  }
914  }
916 
917  return $result;
918  }
919 
920 
926  protected function afterInstall()
927  {
928  }
929 
930 
934  protected function beforeActivation()
935  {
936  return true; // false would indicate that anything went wrong
937  // activation would not proceed
938  // throw an exception in this case
939  //throw new ilPluginException($lng->txt(""));
940  }
941 
942 
946  protected function afterActivation()
947  {
948  }
949 
950 
954  public function deactivate()
955  {
956  global $DIC;
957  $ilDB = $DIC->database();
958 
960 
961  $result = true;
962 
963  $q = "UPDATE il_plugin SET active = " . $ilDB->quote(0, "integer") .
964  " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
965  " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
966  " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
967  " AND name = " . $ilDB->quote($this->getPluginName(), "text");
968 
969  $ilDB->manipulate($q);
970  $this->afterDeactivation();
971 
972  return $result;
973  }
974 
975 
979  protected function afterDeactivation()
980  {
981  }
982 
983 
984  protected function beforeUninstall()
985  {
986  // plugin-specific
987  // false would indicate that anything went wrong
988  return true;
989  }
990 
991 
992  final public function uninstall()
993  {
994  global $DIC;
995  $ilDB = $DIC->database();
996 
997  if ($this->beforeUninstall()) {
998  // remove all language entries (see ilObjLanguage)
999  // see updateLanguages
1000  $prefix = $this->getPrefix();
1001  if ($prefix) {
1002  $ilDB->manipulate(
1003  "DELETE FROM lng_data" .
1004  " WHERE module = " . $ilDB->quote($prefix, "text")
1005  );
1006  $ilDB->manipulate(
1007  "DELETE FROM lng_modules" .
1008  " WHERE module = " . $ilDB->quote($prefix, "text")
1009  );
1010  }
1011 
1012  $this->clearEventListening();
1013 
1014  // db version is kept in il_plugin - will be deleted, too
1015 
1016  $q = "DELETE FROM il_plugin" .
1017  " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
1018  " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
1019  " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
1020  " AND name = " . $ilDB->quote($this->getPluginName(), "text");
1021  $ilDB->manipulate($q);
1022 
1023  $ilDB->manipulateF('DELETE FROM ctrl_classfile WHERE comp_prefix=%s', [ ilDBConstants::T_TEXT ], [ $this->getPrefix() ]);
1024  $ilDB->manipulateF('DELETE FROM ctrl_calls WHERE comp_prefix=%s', [ ilDBConstants::T_TEXT ], [ $this->getPrefix() ]);
1025 
1026  $this->afterUninstall();
1027 
1029 
1030  return true;
1031  }
1032 
1033  return false;
1034  }
1035 
1036 
1040  protected function afterUninstall()
1041  {
1042  }
1043 
1044 
1048  public function update()
1049  {
1050  global $DIC;
1051  $ilDB = $DIC->database();
1052  $ilCtrl = $DIC->ctrl();
1053 
1054  ilGlobalCache::flushAll();
1055 
1056  $result = $this->beforeUpdate();
1057  if ($result === false) {
1058  return false;
1059  }
1060 
1061  // Load language files
1062  $this->updateLanguages();
1063 
1064  // DB update
1065  if ($result === true) {
1066  $result = $this->updateDatabase();
1067  }
1068 
1069  // load control structure
1070  include_once("./setup/classes/class.ilCtrlStructureReader.php");
1071  $structure_reader = new ilCtrlStructureReader();
1072  $structure_reader->readStructure(
1073  true,
1074  "./" . $this->getDirectory(),
1075  $this->getPrefix(),
1076  $this->getDirectory()
1077  );
1078 
1079  // add config gui to the ctrl calls
1080  $ilCtrl->insertCtrlCalls(
1081  "ilobjcomponentsettingsgui",
1082  ilPlugin::getConfigureClassName(["name" => $this->getPluginName()]),
1083  $this->getPrefix()
1084  );
1085 
1086  $this->readEventListening();
1087 
1088  // set last update version to current version
1089  if ($result === true) {
1090  $q = "UPDATE il_plugin SET last_update_version = " . $ilDB->quote($this->getVersion(), "text") .
1091  " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
1092  " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
1093  " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
1094  " AND name = " . $ilDB->quote($this->getPluginName(), "text");
1095 
1096  $ilDB->manipulate($q);
1097  $this->afterUpdate();
1098  }
1099  ilGlobalCache::flushAll();
1100 
1101  return $result;
1102  }
1103 
1104 
1108  protected function readEventListening()
1109  {
1110  $reader = new ilPluginReader(
1111  $this->getDirectory() . '/plugin.xml',
1112  $this->getComponentType(),
1113  $this->getComponentName(),
1114  $this->getSlotId(),
1115  $this->getPluginName()
1116  );
1117  $reader->clearEvents();
1118  $reader->startParsing();
1119  }
1120 
1121 
1125  protected function clearEventListening()
1126  {
1127  $reader = new ilPluginReader(
1128  $this->getDirectory() . '/plugin.xml',
1129  $this->getComponentType(),
1130  $this->getComponentName(),
1131  $this->getSlotId(),
1132  $this->getPluginName()
1133  );
1134  $reader->clearEvents();
1135  }
1136 
1137 
1141  protected function beforeUpdate()
1142  {
1143  return true; // false would indicate that anything went wrong
1144  // update would not proceed
1145  // throw an exception in this case
1146  //throw new ilPluginException($lng->txt(""));
1147  }
1148 
1149 
1153  protected function afterUpdate()
1154  {
1155  }
1156 
1157 
1166  public static function getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
1167  {
1168  $slot_name = ilPluginSlot::lookupSlotName($a_ctype, $a_cname, $a_slot_id);
1169 
1170  $cached_component = ilCachedComponentData::getInstance();
1171  $rec = $cached_component->lookCompId($a_ctype, $a_cname);
1172  if (!$rec) {
1173  return null;
1174  }
1175 
1176  $file = "./Customizing/global/plugins/" . $a_ctype . "/" .
1177  $a_cname . "/" . $slot_name . "/" .
1178  $a_pname . "/classes/class.il" . $a_pname . "Plugin.php";
1179 
1180  if (is_file($file)) {
1181  include_once($file);
1182  $class = "il" . $a_pname . "Plugin";
1183  $plugin = new $class();
1184 
1185  return $plugin;
1186  }
1187 
1188  return null;
1189  }
1190 
1191 
1202  public static function lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : array
1203  {
1204  global $DIC;
1205  $ilDB = $DIC->database();
1206 
1207  $q = "SELECT * FROM il_plugin WHERE" .
1208  " component_type = " . $ilDB->quote($a_ctype, "text") . " AND" .
1209  " component_name = " . $ilDB->quote($a_cname, "text") . " AND" .
1210  " slot_id = " . $ilDB->quote($a_slot_id, "text") . " AND" .
1211  " name = " . $ilDB->quote($a_pname, "text");
1212 
1213  $set = $ilDB->query($q);
1214 
1215  if ($ilDB->numRows($set) == 0) {
1216  return array();
1217  }
1218 
1219  return $ilDB->fetchAssoc($set);
1220  }
1221 
1222 
1230  public static function getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id) : array
1231  {
1232  global $DIC;
1233  $ilPluginAdmin = $DIC['ilPluginAdmin'];
1234 
1235  $plugins = array();
1236 
1237  $cached_component = ilCachedComponentData::getInstance();
1238 
1239  $lookupActivePluginsBySlotId = $cached_component->lookupActivePluginsBySlotId($a_slot_id);
1240  foreach ($lookupActivePluginsBySlotId as $rec) {
1241  if ($ilPluginAdmin->isActive($a_ctype, $a_cname, $a_slot_id, $rec["name"])) {
1242  $plugins[] = $rec["name"];
1243  }
1244  }
1245 
1246  return $plugins;
1247  }
1248 
1249 
1259  public static function getActivePluginIdsForSlot(string $a_ctype, string $a_cname, string $a_slot_id) : array
1260  {
1261  global $DIC;
1262  $ilPluginAdmin = $DIC['ilPluginAdmin'];
1263 
1264  $plugins = array();
1265  $cached_component = ilCachedComponentData::getInstance();
1266  $lookupActivePluginsBySlotId = $cached_component->lookupActivePluginsBySlotId($a_slot_id);
1267  foreach ($lookupActivePluginsBySlotId as $rec) {
1268  if ($ilPluginAdmin->isActive($a_ctype, $a_cname, $a_slot_id, $rec["name"])) {
1269  $plugins[] = $rec["plugin_id"];
1270  }
1271  }
1272 
1273  return $plugins;
1274  }
1275 
1276 
1285  public static function lookupNameForId(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_id)
1286  {
1287  global $DIC;
1288  $ilDB = $DIC->database();
1289 
1290  $q = "SELECT name FROM il_plugin " .
1291  " WHERE component_type = " . $ilDB->quote($a_ctype, "text") .
1292  " AND component_name = " . $ilDB->quote($a_cname, "text") .
1293  " AND slot_id = " . $ilDB->quote($a_slot_id, "text") .
1294  " AND plugin_id = " . $ilDB->quote($a_plugin_id, "text");
1295 
1296  $set = $ilDB->query($q);
1297  if ($rec = $ilDB->fetchAssoc($set)) {
1298  return $rec["name"];
1299  }
1300  }
1301 
1302 
1311  public static function lookupIdForName(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_name) : string
1312  {
1313  global $DIC;
1314  $ilDB = $DIC->database();
1315 
1316  $q = "SELECT plugin_id FROM il_plugin " .
1317  " WHERE component_type = " . $ilDB->quote($a_ctype, "text") .
1318  " AND component_name = " . $ilDB->quote($a_cname, "text") .
1319  " AND slot_id = " . $ilDB->quote($a_slot_id, "text") .
1320  " AND name = " . $ilDB->quote($a_plugin_name, "text");
1321 
1322  $set = $ilDB->query($q);
1323  if ($rec = $ilDB->fetchAssoc($set)) {
1324  return $rec["plugin_id"];
1325  }
1326  }
1327 
1332  public static function lookupTypeInformationsForId(string $id)
1333  {
1334  global $DIC;
1335  $ilDB = $DIC->database();
1336 
1337  $q = "SELECT component_type, component_name, slot_id FROM il_plugin "
1338  . " WHERE plugin_id = " . $ilDB->quote($id, "text")
1339  ;
1340 
1341  $set = $ilDB->query($q);
1342  if ($rec = $ilDB->fetchAssoc($set)) {
1343  return [
1344  $rec["component_type"],
1345  $rec["component_name"],
1346  $rec["slot_id"]
1347  ];
1348  }
1349  }
1350 
1351 
1356  {
1357  return new ilPluginGlobalScreenNullProvider();
1358  }
1359 }
getTablePrefix()
Get db table plugin prefix.
writeDBVersion(int $a_dbversion)
loadLanguageModule()
Load language module for plugin.
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
setActive(bool $a_active)
static lookupId($a_type, $a_name)
Lookup ID of a component.
setId($a_id)
Set Id.
$result
const ILIAS_VERSION_NUMERIC
includeClass($a_class_file_name)
Include (once) a class file.
static isVersionGreaterString($a_ver1, $a_ver2)
getImagePath(string $a_img)
Get image path.
global $DIC
Definition: saml.php:7
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
update()
Update plugin.
static getDBUpdateScriptName(string $a_ctype, string $a_cname, string $a_slot_name, string $a_pname)
static langExitsById(string $pluginId, string $langVar)
Is searched lang var available in plugin lang files.
needsUpdate()
Check whether update is needed.
static getInstalledLanguages()
Get the language objects of the installed languages.
Database Update class.
static getAvailableLangFiles(string $a_lang_directory)
Get array of all language files in the plugin.
getTemplate(string $a_template, bool $a_par1=true, bool $a_par2=true)
gets a ilTemplate instance of a html-file in the plugin /templates
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
afterUninstall()
This is Plugin-Specific and is triggered after the uninstall command of a plugin. ...
updateLanguages($a_lang_keys=null)
static _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img)
activate()
Activate.
readEventListening()
Read the event listening definitions from the plugin.xml (if file exists)
static getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
getComponentName()
Get Component Name.
beforeActivation()
Before activation processing.
Class ilCtrlStructureReader.
static getPluginObjectByType($type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin...
isActive()
Check whether plugin is active.
static lookupIdForName(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_name)
global $ilCtrl
Definition: ilias.php:18
Class ilPluginGlobalScreenNullProvider.
static lookupNameForId(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_id)
getComponentType()
Get Component Type.
static createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
init()
Object initialization.
afterInstall()
After install processing.
static getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
static lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Lookup information data in il_plugin.
catch(Exception $e) $message
afterActivation()
After activation processing.
static _getLocalChangesByModule($a_key, $a_module)
Get the local changes of a language module.
static lookupTypeInformationsForId(string $id)
setDBVersion(int $a_dbversion)
$lng
updateDatabase()
Update database.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Plugin Slot.
setIliasMinVersion(string $a_iliasminversion)
setIliasMaxVersion(string $a_iliasmaxversion)
static hasConfigureClass(string $a_slot_dir, array $plugin_data, array $plugin_db_data)
Has the plugin a configure class?
getDirectory()
Get Plugin Directory.
special template class to simplify handling of ITX/PEAR
deactivate()
Deactivate.
txt(string $a_var)
Get Language Variable (prefix will be prepended automatically)
$txt
Definition: error.php:11
getPrefix()
Get plugin prefix, used for lang vars.
static _getPluginsDirectory($a_ctype, $a_cname, $a_slot_id)
Get plugins directory.
static getConfigureClassName(array $plugin_data)
Get plugin configure class name.
afterUpdate()
After update processing.
getLastUpdateVersion()
Get Version of last update.
$row
setSlotObject(ilPluginSlot $a_slot)
getSlotId()
Get Slot ID.
slotInit()
Object initialization done by slot.
static _getDirectory(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Get plugin directory.
global $ilDB
getStyleSheetLocation(string $a_css_file)
__init()
Default initialization.
getPluginName()
Get Plugin Name.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
setLastUpdateVersion(string $a_lastupdateversion)
Set Version of last update.
promoteGlobalScreenProvider()
setVersion(string $a_version)
addBlockFile($a_tpl, $a_var, $a_block, $a_tplname)
Add template content to placeholder variable.
getLanguageDirectory()
getSlot()
Get Slot Name.
static getActivePluginIdsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
Get All active plugin ids for a slot.
Class ilPluginReader.
getIliasMaxVersion()
Get Required ILIAS max.
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
beforeUpdate()
Before update processing.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
afterDeactivation()
After deactivation processing.
static lookupTxt(string $a_mod_prefix, string $a_pl_id, string $a_lang_var)
clearEventListening()
Clear the entries of this plugin in the event handling table.