Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00031 include_once("./classes/class.ilDOMXML.php");
00032 include_once("./Services/COPage/classes/class.ilParagraphPlugin.php");
00033
00034 class ilParagraphPlugins {
00039 var $plugins;
00040
00044 var $pluginDirectory;
00050 var $skipDirectories;
00051
00055 function ilParagraphPlugins () {
00056 $this->plugins = array();
00057 $this->pluginDirectory = ILIAS_ABSOLUTE_PATH."/Services/COPage/plugins";
00058 $this->skipDirectories = array ();
00059 $this->skipDirectories [$this->pluginDirectory."/classes"] = "skip";
00060 $this->skipDirectories [$this->pluginDirectory."/resources"]= "skip";
00061 $this->skipDirectories [$this->pluginDirectory."/CVS"]= "skip";
00062 }
00063
00067 function getRegisteredPluginsAsArray () {
00068 return $this->plugins;
00069 }
00070
00071
00077 function getParagraphPlugin ($pluginDir) {
00078 foreach ($this->plugins as $plugin) {
00079 if (strcasecmp($pluginDir, $plugin->getDirectory()) == 0)
00080 return $plugin;
00081 }
00082 return null;
00083 }
00084
00088 function registerPlugin ($plugin) {
00089
00090 $this->plugins[$plugin->serializeToString()] = $plugin;
00091 }
00092
00093
00094 function isRegistered ($pluginClassname) {
00095 foreach ($this->plugins as $plugin) {
00096 if (strcasecmp(get_class($plugin), $pluginClassname) == 0)
00097 return true;
00098 }
00099 return false;
00100 }
00105 function serializeToString (){
00106 return implode ("|", array_keys($this->plugins));
00107 }
00108
00112 function initialize () {
00113 if (file_exists($this->pluginDirectory))
00114 {
00115 $pluginDirs = glob($this->pluginDirectory."/*",GLOB_ONLYDIR);
00116 if (is_array($pluginDirs))
00117 {
00118 foreach ($pluginDirs as $pluginDir) {
00119
00120 if (array_key_exists($pluginDir,$this->skipDirectories) || !file_exists($pluginDir."/plugin.xml")) {
00121 continue;
00122 }
00123
00124
00125
00126 $pluginDOM = new ilDOMXML();
00127 $pluginDOM->loadDocument("plugin.xml", $pluginDir, false);
00128 $pluginNodes = $pluginDOM->getElementsByTagname("plugin");
00129
00130 if ( count ($pluginNodes)>0 )
00131 {
00132
00133 $pluginNode = $pluginNodes[0];
00134
00135
00136 $pluginSubDir = str_replace($this->pluginDirectory."/","",$pluginDir);
00137
00138
00139 $classfile = $pluginNode->get_attribute ("classfile");
00140
00141 $classname = $pluginNode->get_attribute ("classname");
00142
00143
00144 $filetype = $pluginNode->get_attribute ("filetype");
00145
00146
00147 $active = strcasecmp($pluginNode->get_attribute ("active"),"true") == 0;
00148
00149
00150 $title = $this->getTextContent($pluginNode,"title");
00151
00152
00153 $link = $this->getTextContent($pluginNode,"link");
00154
00155
00156 $description = $this->getTextContent($pluginNode,"description");
00157
00158
00159
00160 $classfile = $pluginDir . "/classes/".$classfile;
00161
00162
00163
00164
00165
00166
00167
00168
00169 if (file_exists($classfile) && $active && !$this->isRegistered($classname))
00170 {
00171 include_once ($classfile);
00172 $plugin = new $classname($pluginSubDir, $title, $filetype, $link, $description, $active);
00173
00174
00175
00176 if (is_a($plugin,"ilParagraphPlugin") && $plugin->isActive()) {
00177 $this->registerPlugin($plugin);
00178
00179 unset ($plugin);
00180 }
00181 }
00182
00183 }
00184 }
00185 }
00186 }
00187 }
00188
00189
00197 function getTextContent ($a_element, $nodename) {
00198 $elems = $a_element -> get_elements_by_tagname ( $nodename );
00199 if (count ($elems) > 0)
00200 {
00201 return $elems[0]->get_content();
00202 }
00203 return "";
00204 }
00205 }
00206 ?>