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

content/classes/Pages/class.ilParagraphPlugins.php

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                 //echo "registered Plugin ".$plugin->getTitle();
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                             // if there is no plugin xml file, or we are in a skipping directory then continue loop
00088                                 if (array_key_exists($pluginDir,$this->skipDirectories) || !file_exists($pluginDir."/plugin.xml")) {
00089                                         continue;
00090                                 }
00091                     
00092                                 
00093                                 // load plugin xml, to retrieve plugin node (see dtd)
00094                                 $pluginDOM = new ilDOMXML();
00095                                 $pluginDOM->loadDocument("plugin.xml", $pluginDir, false);
00096                                 $pluginNodes = $pluginDOM->getElementsByTagname("plugin");
00097                                 
00098                                 if ( count ($pluginNodes)>0 ) 
00099                                 {
00100                                     // found plugin node
00101                                     $pluginNode = $pluginNodes[0];
00102                                     //print_r($pluginNode) ;
00103                                         //this is the subdirectory of the plugin
00104                                     $pluginSubDir = str_replace($this->pluginDirectory."/","",$pluginDir);
00105     
00106                                         // class file containing class which inherits from paragraph plugin
00107                                     $classfile = $pluginNode->get_attribute ("classfile");
00108                                     // according classname
00109                                         $classname = $pluginNode->get_attribute ("classname");
00110                                         
00111                                         // filter filetype, refers to sourcecode directory, hfile, e.g. java122 affects, that this plugin is for this paragraph type only
00112                                         $filetype  = $pluginNode->get_attribute ("filetype");
00113                                         
00114                                         // enable/disable plugin
00115                                         $active    = strcasecmp($pluginNode->get_attribute ("active"),"true") == 0;
00116         
00117                                         // title is alt text for image
00118                                         $title       = $this->getTextContent($pluginNode,"title");
00119                                         
00120                                         // link                                 
00121                                         $link        = $this->getTextContent($pluginNode,"link");
00122                                         
00123                                         // description, not shown at the momemnt
00124                                         $description = $this->getTextContent($pluginNode,"description");
00125                         
00126                                         
00127                                         // prepare class file for include, must reside in classes directory
00128                                         $classfile = $pluginDir . "/classes/".$classfile;
00129                                         
00130        /*                               echo $classfile."<br>";
00131                                         echo $classname."<br>";
00132                                         echo $filetype."<br>";
00133                                         echo $active."<br>";
00134                                         echo $title."<br>";
00135                                         echo $description."<br>";
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                                                 //print_r($plugin);
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 ?>

Generated on Fri Dec 13 2013 11:57:57 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1