ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilParagraphPlugins.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
31 include_once("./classes/class.ilDOMXML.php");
32 include_once("./Services/COPage/classes/class.ilParagraphPlugin.php");
33 
39  var $plugins;
40 
51 
55  function ilParagraphPlugins () {
56  $this->plugins = array();
57  $this->pluginDirectory = ILIAS_ABSOLUTE_PATH."/Services/COPage/plugins";
58  $this->skipDirectories = array ();
59  $this->skipDirectories [$this->pluginDirectory."/classes"] = "skip";
60  $this->skipDirectories [$this->pluginDirectory."/resources"]= "skip";
61  $this->skipDirectories [$this->pluginDirectory."/CVS"]= "skip";
62  }
63 
68  return $this->plugins;
69  }
70 
71 
77  function getParagraphPlugin ($pluginDir) {
78  foreach ($this->plugins as $plugin) {
79  if (strcasecmp($pluginDir, $plugin->getDirectory()) == 0)
80  return $plugin;
81  }
82  return null;
83  }
84 
88  function registerPlugin ($plugin) {
89  //echo "registered Plugin ".$plugin->getTitle();
90  $this->plugins[$plugin->serializeToString()] = $plugin;
91  }
92 
93 
94  function isRegistered ($pluginClassname) {
95  foreach ($this->plugins as $plugin) {
96  if (strcasecmp(get_class($plugin), $pluginClassname) == 0)
97  return true;
98  }
99  return false;
100  }
105  function serializeToString (){
106  return implode ("|", array_keys($this->plugins));
107  }
108 
112  function initialize () {
113  if (file_exists($this->pluginDirectory))
114  {
115  $pluginDirs = glob($this->pluginDirectory."/*",GLOB_ONLYDIR);
116  if (is_array($pluginDirs))
117  {
118  foreach ($pluginDirs as $pluginDir) {
119  // if there is no plugin xml file, or we are in a skipping directory then continue loop
120  if (array_key_exists($pluginDir,$this->skipDirectories) || !file_exists($pluginDir."/plugin.xml")) {
121  continue;
122  }
123 
124 
125  // load plugin xml, to retrieve plugin node (see dtd)
126  $pluginDOM = new ilDOMXML();
127  $pluginDOM->loadDocument("plugin.xml", $pluginDir, false);
128  $pluginNodes = $pluginDOM->getElementsByTagname("plugin");
129 
130  if ( count ($pluginNodes)>0 )
131  {
132  // found plugin node
133  $pluginNode = $pluginNodes[0];
134  //print_r($pluginNode) ;
135  //this is the subdirectory of the plugin
136  $pluginSubDir = str_replace($this->pluginDirectory."/","",$pluginDir);
137 
138  // class file containing class which inherits from paragraph plugin
139  $classfile = $pluginNode->get_attribute ("classfile");
140  // according classname
141  $classname = $pluginNode->get_attribute ("classname");
142 
143  // filter filetype, refers to sourcecode directory, hfile, e.g. java122 affects, that this plugin is for this paragraph type only
144  $filetype = $pluginNode->get_attribute ("filetype");
145 
146  // enable/disable plugin
147  $active = strcasecmp($pluginNode->get_attribute ("active"),"true") == 0;
148 
149  // title is alt text for image
150  $title = $this->getTextContent($pluginNode,"title");
151 
152  // link
153  $link = $this->getTextContent($pluginNode,"link");
154 
155  // description, not shown at the momemnt
156  $description = $this->getTextContent($pluginNode,"description");
157 
158 
159  // prepare class file for include, must reside in classes directory
160  $classfile = $pluginDir . "/classes/".$classfile;
161 
162  /* echo $classfile."<br>";
163  echo $classname."<br>";
164  echo $filetype."<br>";
165  echo $active."<br>";
166  echo $title."<br>";
167  echo $description."<br>";*/
168 
169  if (file_exists($classfile) && $active && !$this->isRegistered($classname))
170  {
171  include_once ($classfile);
172  $plugin = new $classname($pluginSubDir, $title, $filetype, $link, $description, $active);
173 
174  //print_r($plugin);
175 
176  if (is_a($plugin,"ilParagraphPlugin") && $plugin->isActive()) {
177  $this->registerPlugin($plugin);
178 
179  unset ($plugin);
180  }
181  }
182 
183  }
184  }
185  }
186  }
187  }
188 
189 
197  function getTextContent ($a_element, $nodename) {
198  $elems = $a_element -> get_elements_by_tagname ( $nodename );
199  if (count ($elems) > 0)
200  {
201  return $elems[0]->get_content();
202  }
203  return "";
204  }
205 }
206 ?>