PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   PHP Plugin System   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: PHP Plugin System
Extend functionality using plugin classes
Author: By
Last change:
Date: 9 years ago
Size: 2,663 bytes
 

Contents

Class file image Download
<?PHP
//include and instantiate the class
include('plugin.class.php');
$plug = new pluginClass;

//build a sortable array of menu items
foreach( $plug->plugin as $key=>$value ){
   
$menu[$plug->instance[$key]->menu['pri']]['title'] = $plug->instance[$key]->menu['title'];
   
$menu[$plug->instance[$key]->menu['pri']]['link'] = $plug->instance[$key]->menu['link'];
}
ksort($menu);

//array of parameters for observer addString method
$param = array(
   
'added this text',
   
' and a &lt;br&gt;<br>'
);

//check all observer classes to see if a method exists
$methodCheck = $plug->checkMethod('addString');

?>
<html>
    <head>
        <title>Plugin Example</title>
        <style>
            a {
                color: blue;
                text-decoration: none;
            }
            a:hover {
                color: red;
            }
        </style>
    </head>
    <body>
        <div><em>This example is based on the concept of an enterprise application with modules that can be plugged in, however the plugin class can be used whenever you need plug and play capabilities</em></div>
        <div style="margin-top:10px;">
            <h4>Menu</h4>
            <em>(demonstration of dynamically generated menu items from observers)</em><br><br>
<?PHP
//display menu items
foreach( $menu as $key=>$value ){
?>
<a href="<?PHP echo $menu[$key]['link'];?>"><?PHP echo $menu[$key]['title'];?></a><br>
<?PHP
}
?>
</div>
        <div style="margin-top:10px;">
            <h4>Method Processing</h4>
            <em>(methods will only be triggered in observers where they exist)</em><br><br>
<?PHP
//display results from method check
foreach( $methodCheck as $key=>$value ){
?>
addString method is <?PHP echo ( empty($value) ) ? '<span style="color: red;">not</span>': '';?> in the <?PHP echo $key;?> observer<br>
<?PHP
}
?>
<br>
            <?PHP echo $plug->doMethod('addString',$param,true); //initiate observer addString method?>
</div>
        <div style="margin-top:10px;">
            <h4>Event Processing</h4>
            <em>(events are methods, however for our purpose each observer would have the same method triggered by a specific event)</em><br><br>
            <?PHP echo $plug->doMethod('anEvent','',true); //initiate observer event processing?>
</div>
<?PHP
//check if the observer class moderator has been installed
if( !$plug->checkInstance('moderator') ){
?>
<div style="margin-top:10px;">
            <h4>The moderator plugin is not installed</h4>
            <em>(demonstration of a logical check to determine if a specific observer is installed)</em>
        <div>
        <div style="margin-top:10px; color: green;"><strong>Try placing the supplied moderator.plugin.php file into the plugins folder and then refresh this page</strong></div>
<?PHP
}
?>
</body>
</html>