PHP
  Home arrow PHP arrow Page 3 - Building a Site Engine with PHP, Part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building a Site Engine with PHP, Part 2
By: James Murray
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 70
    2004-06-14


    Table of Contents:
  • Building a Site Engine with PHP, Part 2
  • Best Site() Ever Made
  • OK, Plug it in Now
  • Module Madness
  • Bring it Together

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building a Site Engine with PHP, Part 2 - OK, Plug it in Now
    ( Page 3 of 5 )

    Now that the past couple of classes are all set up, we're ready to start loading up all our plug-ins. Well, we're ready to make the class that will load them. First we'll select the plug-in ID, name, directory, and file from the database. Then we'll set them all to an array in the plug-ins class, that way the information about the plug-ins can be used later without having to select it from the database again. After we've built our list of initialized plug-ins, we'll use a function that will actually load the plug-ins and include them into our engine. With that all said, let's take a look at the class file.

    <?PHP

    class plugins{

        public $pcount;    //this will hold the number of plug-ins that we actually load into the engine
        public $plugin_list;    //this will hold our array of plug-in information
        public $plugin_error;    //this will hold any errors that are produced by loading a plug-in
        public $lcount;    //this will hold the number of plugins in our plug-ins list
       
        function plugins($site_id=""){    //we name the main function the same as the class so that it initializes when the class is called
            global $sql,$site;    //this requests the $sql and $site classes as a global variables
            $this->pcount=0;    //set the default of $pcount to 0 because we don't yet have any plug-ins loaded
            $this->lcount=0;    //set the default of $lcount to 0 because we don't yet have any plug-ins in the plug-ins list
            if($site_id==""){    //check to see if the administrator overrides the $site_id to list plug-ins for other sites
                $site_id = $site->site['ID'];    //if the site_id isn't overridden set it to the current site's id
            }
            $plugins_list=$sql->_query("SELECT
                                             plugins.plugin_ID,
                                             plugins.plugin_name,
                                             plugins.plugin_dir,
                                             plugins.plugin_file
                                         FROM
                                             plugin_status,
                                             plugins
                                         WHERE
                                             plugins.plugin_ID = plugin_status.plugin_ID AND
                                             plugin_status.site_ID = '$site_id' AND
                                             plugin_status.plugin_status = 'initialized'
                                         ORDER BY
                                             plugins.plugin_priority DESC");    //select all the initialized plug-in information from the database
            while($plugin=$sql->_fetch_object($plugins_list)){    //start a loop to get the information from the select query using the _fetch_object function
                $this->lcount++;    // update lcount for each plug-in we add to the plug-ins list
                $this->plugin_list['plug_ID'][]=$plugin->plugin_ID;    //add the current plug-in's ID to the plugin list
                $this->plugin_list['plug_name'][]=$plugin->plugin_name;    //add the current plug-in's name to the plugin list
                $this->plugin_list['plug_dir'][]=$plugin->plugin_dir;    //add the current plug-in's directory to the plugin list
                $this->plugin_list['plug_file'][]=$plugin->plugin_file;    //add the current plug-in's file to the plugin list
            }
            if($this->pcount==0){    //check to see if any plug-ins have been loaded into the engine
                $this->load();    //if no plug-ins are loaded, call the load() function to load the plug-ins
            }
        }
       
        function load(){    //this function loads the plug-ins from the plug-ins list
            if(is_array($this->plugin_list)){    //make sure that the plug-ins list as an array, to prevent errors
                for($i=0;$i<$this->lcount;$i++){    //start a loop to identify each plug-in in the plug-ins list
                    if(file_exists("{$this->plugin_list['plug_dir'][$i]}/{$this->plugin_list['plug_file'][$i]}/main.plug.php")){    //make sure the plug-in's file exists, to prevent errors
                        @include("{$this->plugin_list['plug_dir'][$i]}/{$this->plugin_list['plug_file'][$i]}/main.plug.php");    //include the plug-in into the engine
                        $this->pcount++;    //update pcount for each plug-in that loads
                    }else{
                        $this->plugin_error[]="The plug-in file: <b>/{$this->plugin_list['plug_dir'][$i]}/{$this->plugin_list['plug_file'][$i]}/main.plug.php</b> Does not exist";    //if the plug-in cant load add an error to the error list
                    }
                }
            }   
        }
    }
    ?>

    Save this as "your_site_dir/inc/plugins.inc.php". Now that we have the plug-ins class set all up, let's get the modules class ready to go.



     
     
    >>> More PHP Articles          >>> More By James Murray
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT