Public Member Functions | Data Fields

ilParagraphPlugins Class Reference

class which contains all registered plugins More...

Public Member Functions

 ilParagraphPlugins ()
 constructor initializes skip Directories
 getRegisteredPluginsAsArray ()
 getPluginArray
 getParagraphPlugin ($pluginDir)
 get a specific plugin by its directory name (since directories are unique)
 registerPlugin ($plugin)
 register plugin
 serializeToString ()
 serializes all plugin to one string format filetype::title::link::image|filetypetitle::link::image|...
 initialize ()
 parses plugin subdirectory to determine registered plugins
 getTextContent ($a_element, $nodename)
 get Text content from a child node (unique by name), otherwise first will be taken.

Data Fields

 $plugins
 array which contains an instance of each plugin keys are equal to the serialization string of a plugin
 $pluginDirectory
 contains the plugins directory
 $skipDirectories
 array which contains all directories which should not be parsed within the plugins directory, by default the sub directories resources, CVS and classes are skipped

Detailed Description

class which contains all registered plugins

Definition at line 10 of file class.ilParagraphPlugins.php.


Member Function Documentation

ilParagraphPlugins::getParagraphPlugin ( pluginDir  ) 

get a specific plugin by its directory name (since directories are unique)

Parameters:
ilParagraphPlugin $pluginDir

Definition at line 53 of file class.ilParagraphPlugins.php.

                                                 {
            foreach ($this->plugins as $plugin) {
                if (strcasecmp($pluginDir, $plugin->getDirectory()) == 0) 
                   return $plugin;
            }
            return null;
        }

ilParagraphPlugins::getRegisteredPluginsAsArray (  ) 

getPluginArray

Definition at line 43 of file class.ilParagraphPlugins.php.

                                                {
                return $this->plugins;          
        }

ilParagraphPlugins::getTextContent ( a_element,
nodename 
)

get Text content from a child node (unique by name), otherwise first will be taken.

Parameters:
DOM_ELEMENT $a_element
String $nodename
Returns:
String

Definition at line 163 of file class.ilParagraphPlugins.php.

Referenced by initialize().

                                                        {
            $elems = $a_element -> get_elements_by_tagname ( $nodename );
            if (count ($elems) > 0)
            {
                return $elems[0]->get_content();
            }
        return "";
        }

Here is the caller graph for this function:

ilParagraphPlugins::ilParagraphPlugins (  ) 

constructor initializes skip Directories

Definition at line 31 of file class.ilParagraphPlugins.php.

                                       {
                $this->plugins = array();
                $this->pluginDirectory = ILIAS_ABSOLUTE_PATH."/content/plugins";
                $this->skipDirectories = array ();
                $this->skipDirectories [$this->pluginDirectory."/classes"] = "skip"; 
                $this->skipDirectories [$this->pluginDirectory."/resources"]= "skip";
                $this->skipDirectories [$this->pluginDirectory."/CVS"]= "skip";
        }

ilParagraphPlugins::initialize (  ) 

parses plugin subdirectory to determine registered plugins

Definition at line 80 of file class.ilParagraphPlugins.php.

References $title, getTextContent(), and registerPlugin().

                               {                
                if (file_exists($this->pluginDirectory)) 
                {
                    $pluginDirs = glob($this->pluginDirectory."/*",GLOB_ONLYDIR);
                    if (is_array($pluginDirs))
                    {
                        foreach ($pluginDirs as $pluginDir) {
                            // if there is no plugin xml file, or we are in a skipping directory then continue loop
                                if (array_key_exists($pluginDir,$this->skipDirectories) || !file_exists($pluginDir."/plugin.xml")) {
                                        continue;
                                }
                    
                                
                                // load plugin xml, to retrieve plugin node (see dtd)
                                $pluginDOM = new ilDOMXML();
                                $pluginDOM->loadDocument("plugin.xml", $pluginDir, false);
                                $pluginNodes = $pluginDOM->getElementsByTagname("plugin");
                                
                                if ( count ($pluginNodes)>0 ) 
                                {
                                    // found plugin node
                                    $pluginNode = $pluginNodes[0];
                                    //print_r($pluginNode) ;
                                        //this is the subdirectory of the plugin
                                    $pluginSubDir = str_replace($this->pluginDirectory."/","",$pluginDir);
    
                                        // class file containing class which inherits from paragraph plugin
                                    $classfile = $pluginNode->get_attribute ("classfile");
                                    // according classname
                                        $classname = $pluginNode->get_attribute ("classname");
                                        
                                        // filter filetype, refers to sourcecode directory, hfile, e.g. java122 affects, that this plugin is for this paragraph type only
                                        $filetype  = $pluginNode->get_attribute ("filetype");
                                        
                                        // enable/disable plugin
                                        $active    = strcasecmp($pluginNode->get_attribute ("active"),"true") == 0;
        
                                        // title is alt text for image
                                        $title       = $this->getTextContent($pluginNode,"title");
                                        
                                        // link                                 
                                        $link        = $this->getTextContent($pluginNode,"link");
                                        
                                        // description, not shown at the momemnt
                                        $description = $this->getTextContent($pluginNode,"description");
                        
                                        
                                        // prepare class file for include, must reside in classes directory
                                        $classfile = $pluginDir . "/classes/".$classfile;
                                        
       /*                               echo $classfile."<br>";
                                        echo $classname."<br>";
                                        echo $filetype."<br>";
                                        echo $active."<br>";
                                        echo $title."<br>";
                                        echo $description."<br>";
       */                               
                                        if (file_exists($classfile) && $active == TRUE && !class_exists($classname)) {
                                                include ($classfile);
                                                $plugin = new $classname($pluginSubDir, $title, $filetype, $link, $description, $active);
                                                
                                                //print_r($plugin);
                                                
                                                if (is_a($plugin,"ilParagraphPlugin") && $plugin->isActive()) {
                                                        $this->registerPlugin($plugin);
                                                        unset ($plugin);
                                                }
                                        }
                                    
                                }       
                        }
                        }       
                }
        }

Here is the call graph for this function:

ilParagraphPlugins::registerPlugin ( plugin  ) 

register plugin

Definition at line 64 of file class.ilParagraphPlugins.php.

Referenced by initialize().

                                          {
                //echo "registered Plugin ".$plugin->getTitle();
                $this->plugins[$plugin->serializeToString()] = $plugin;
        }

Here is the caller graph for this function:

ilParagraphPlugins::serializeToString (  ) 

serializes all plugin to one string format filetype::title::link::image|filetypetitle::link::image|...

Definition at line 73 of file class.ilParagraphPlugins.php.

                                     {
                return implode ("|", array_keys($this->plugins));               
        }


Field Documentation

ilParagraphPlugins::$pluginDirectory

contains the plugins directory

Definition at line 20 of file class.ilParagraphPlugins.php.

ilParagraphPlugins::$plugins

array which contains an instance of each plugin keys are equal to the serialization string of a plugin

Definition at line 15 of file class.ilParagraphPlugins.php.

ilParagraphPlugins::$skipDirectories

array which contains all directories which should not be parsed within the plugins directory, by default the sub directories resources, CVS and classes are skipped

Definition at line 26 of file class.ilParagraphPlugins.php.


The documentation for this class was generated from the following file: