Go to the documentation of this file.00001 <?php
00007 include_once("./classes/class.ilDOMXML.php");
00008 include_once("./content/classes/Pages/class.ilParagraphPlugin.php");
00009
00010 class ilParagraphPlugins {
00015 var $plugins;
00016
00020 var $pluginDirectory;
00026 var $skipDirectories;
00027
00031 function ilParagraphPlugins () {
00032 $this->plugins = array();
00033 $this->pluginDirectory = ILIAS_ABSOLUTE_PATH."/content/plugins";
00034 $this->skipDirectories = array ();
00035 $this->skipDirectories [$this->pluginDirectory."/classes"] = "skip";
00036 $this->skipDirectories [$this->pluginDirectory."/resources"]= "skip";
00037 $this->skipDirectories [$this->pluginDirectory."/CVS"]= "skip";
00038 }
00039
00043 function getRegisteredPluginsAsArray () {
00044 return $this->plugins;
00045 }
00046
00047
00053 function getParagraphPlugin ($pluginDir) {
00054 foreach ($this->plugins as $plugin) {
00055 if (strcasecmp($pluginDir, $plugin->getDirectory()) == 0)
00056 return $plugin;
00057 }
00058 return null;
00059 }
00060
00064 function registerPlugin ($plugin) {
00065
00066 $this->plugins[$plugin->serializeToString()] = $plugin;
00067 }
00068
00073 function serializeToString (){
00074 return implode ("|", array_keys($this->plugins));
00075 }
00076
00080 function initialize () {
00081 if (file_exists($this->pluginDirectory))
00082 {
00083 $pluginDirs = glob($this->pluginDirectory."/*",GLOB_ONLYDIR);
00084 if (is_array($pluginDirs))
00085 {
00086 foreach ($pluginDirs as $pluginDir) {
00087
00088 if (array_key_exists($pluginDir,$this->skipDirectories) || !file_exists($pluginDir."/plugin.xml")) {
00089 continue;
00090 }
00091
00092
00093
00094 $pluginDOM = new ilDOMXML();
00095 $pluginDOM->loadDocument("plugin.xml", $pluginDir, false);
00096 $pluginNodes = $pluginDOM->getElementsByTagname("plugin");
00097
00098 if ( count ($pluginNodes)>0 )
00099 {
00100
00101 $pluginNode = $pluginNodes[0];
00102
00103
00104 $pluginSubDir = str_replace($this->pluginDirectory."/","",$pluginDir);
00105
00106
00107 $classfile = $pluginNode->get_attribute ("classfile");
00108
00109 $classname = $pluginNode->get_attribute ("classname");
00110
00111
00112 $filetype = $pluginNode->get_attribute ("filetype");
00113
00114
00115 $active = strcasecmp($pluginNode->get_attribute ("active"),"true") == 0;
00116
00117
00118 $title = $this->getTextContent($pluginNode,"title");
00119
00120
00121 $link = $this->getTextContent($pluginNode,"link");
00122
00123
00124 $description = $this->getTextContent($pluginNode,"description");
00125
00126
00127
00128 $classfile = $pluginDir . "/classes/".$classfile;
00129
00130
00131
00132
00133
00134
00135
00136
00137 if (file_exists($classfile) && $active == TRUE && !class_exists($classname)) {
00138 include ($classfile);
00139 $plugin = new $classname($pluginSubDir, $title, $filetype, $link, $description, $active);
00140
00141
00142
00143 if (is_a($plugin,"ilParagraphPlugin") && $plugin->isActive()) {
00144 $this->registerPlugin($plugin);
00145 unset ($plugin);
00146 }
00147 }
00148
00149 }
00150 }
00151 }
00152 }
00153 }
00154
00155
00163 function getTextContent ($a_element, $nodename) {
00164 $elems = $a_element -> get_elements_by_tagname ( $nodename );
00165 if (count ($elems) > 0)
00166 {
00167 return $elems[0]->get_content();
00168 }
00169 return "";
00170 }
00171 }
00172 ?>