• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/COPage/classes/class.ilParagraphPlugins.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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                 //echo "registered Plugin ".$plugin->getTitle();
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                             // if there is no plugin xml file, or we are in a skipping directory then continue loop
00120                                 if (array_key_exists($pluginDir,$this->skipDirectories) || !file_exists($pluginDir."/plugin.xml")) {
00121                                         continue;
00122                                 }
00123 
00124 
00125                                 // load plugin xml, to retrieve plugin node (see dtd)
00126                                 $pluginDOM = new ilDOMXML();
00127                                 $pluginDOM->loadDocument("plugin.xml", $pluginDir, false);
00128                                 $pluginNodes = $pluginDOM->getElementsByTagname("plugin");
00129 
00130                                 if ( count ($pluginNodes)>0 )
00131                                 {
00132                                     // found plugin node
00133                                     $pluginNode = $pluginNodes[0];
00134                                     //print_r($pluginNode) ;
00135                                         //this is the subdirectory of the plugin
00136                                     $pluginSubDir = str_replace($this->pluginDirectory."/","",$pluginDir);
00137 
00138                                         // class file containing class which inherits from paragraph plugin
00139                                     $classfile = $pluginNode->get_attribute ("classfile");
00140                                     // according classname
00141                                         $classname = $pluginNode->get_attribute ("classname");
00142 
00143                                         // filter filetype, refers to sourcecode directory, hfile, e.g. java122 affects, that this plugin is for this paragraph type only
00144                                         $filetype  = $pluginNode->get_attribute ("filetype");
00145 
00146                                         // enable/disable plugin
00147                                         $active    = strcasecmp($pluginNode->get_attribute ("active"),"true") == 0;
00148 
00149                                         // title is alt text for image
00150                                         $title       = $this->getTextContent($pluginNode,"title");
00151 
00152                                         // link
00153                                         $link        = $this->getTextContent($pluginNode,"link");
00154 
00155                                         // description, not shown at the momemnt
00156                                         $description = $this->getTextContent($pluginNode,"description");
00157 
00158 
00159                                         // prepare class file for include, must reside in classes directory
00160                                         $classfile = $pluginDir . "/classes/".$classfile;
00161 
00162                         /*            echo $classfile."<br>";
00163                                         echo $classname."<br>";
00164                                         echo $filetype."<br>";
00165                                         echo $active."<br>";
00166                                         echo $title."<br>";
00167                                         echo $description."<br>";*/
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                                                 //print_r($plugin);
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 ?>

Generated on Fri Dec 13 2013 17:56:56 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1