Welcome Guest, Not a member yet? Register   Sign In
Need help with a plugin system
#1

[eluser]Yorick Peterse[/eluser]
Ok guys, I need your help Smile

I am currently working on an improved plugin system for CI, which works a bit like the WordPress plugin system. The idea is that you write a simple plugin and specify when to execute your plugin. For example, your plugin could look like the following:

Code:
<?php

// Hello world function
function hello_world() {
    // Echo the most famouns combination of letters
    echo "<strong>Hello world!</strong>";
}

function add_filter() {
    
    $data = array(
    'filter_event'        => 'index',
    'filter_function'     => 'hello_world'
    );
    
    // Return it
    return $data;
}


?&gt;

The plugin library looks like the following:

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* @name Ext.Plugin
* @version 0.1
*
* Ext.Plugin is an extended plugin system for CodeIgniter. It works just like the WordPress plugin system
*
* Copyright (c) 2009 Yorick Peterse
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

class Ext_Plugin extends Controller {
    
    // Get all plugins and execute them at a given time
    function get_plugins() {
    
    // Get all plugins with the ext_ prefix
    if ($handle = opendir('./system/application/plugins/')) {
        
        // Loop through each file
        while (false !== ($file = readdir($handle))) {
        
        // Exclude the dots and files that don't start with ext_ and end with .php
        if ($file != "." && $file != ".." && preg_match("/[.](php)$/",$file) == true && preg_match("/(ext)[_]/",$file) == true) {
            
            // Remove the .php extension
            $plugin = str_replace(".php","",$file);
            
            // Load the plugin
            $this->load->plugin($plugin);
            
            // Get the filter settings
            $filter = add_filter();
            
            $filter_event     = $filter['filter_event'];
            $filter_function     = $filter['filter_function'];
            
            // If statement to see if the current function equals the specified filter function
            
            
        }
        }
        closedir($handle);
    }
    }
}
?&gt;

The system will fetch the $data array and will execute the 'filter_function' when the 'filter_event' occurs, atleast, that's the idea. Currently I'm having trouble "injecting" the plugin into the specified function. At first I thought I could use URI segments, but that isn't going to work out when the user hasn't specified those (for example on the index page).

I'd like to know if there's any other way to do it without having to rely on those URI segments or on the CI hook system Smile


Messages In This Thread
Need help with a plugin system - by El Forum - 05-10-2009, 02:25 PM
Need help with a plugin system - by El Forum - 05-10-2009, 06:25 PM
Need help with a plugin system - by El Forum - 05-11-2009, 02:40 AM
Need help with a plugin system - by El Forum - 05-11-2009, 03:24 AM
Need help with a plugin system - by El Forum - 05-11-2009, 04:02 AM
Need help with a plugin system - by El Forum - 05-11-2009, 04:16 AM
Need help with a plugin system - by El Forum - 05-11-2009, 04:34 AM
Need help with a plugin system - by El Forum - 05-11-2009, 06:56 AM
Need help with a plugin system - by El Forum - 05-11-2009, 07:23 AM
Need help with a plugin system - by El Forum - 05-11-2009, 07:28 AM
Need help with a plugin system - by El Forum - 05-11-2009, 07:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB