tz-tools.php 2.02 KB
<?php
/*
Plugin Name: Tenzing Tools
Version: 0.1
Description: Various classes to help out with stuff
Author: Tenzing
*/

    if (version_compare(PHP_VERSION, '5.2.2') !== 1) {
        die('PHP version 5.2.2 or greater is required');
    }

    TzTools::load();

class TzTools {
    public static function load() {
//        set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__));
        spl_autoload_register(Array(__CLASS__, 'autoloader'));

        require_once(dirname(__FILE__) . '/wp_functions.php');

        _register_script('addEvent', plugins_url('addEvent.js', __FILE__));
        _register_script('xmlhttpHandler', plugins_url('xmlhttpHandler.js', __FILE__));
        _register_script('fireEvent', plugins_url('fireEvent.js', __FILE__));

        add_action('widgets_init', Array('MenuWidget', 'init'));
    }

    public static function autoloader($class) {
        $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $class . '.php';
        if (is_file($file)) {
            include($file);
        }
    }
}

function add_actions($class) {
    if (!class_exists($class)) {
        throw new Exception("$class does not exist");
    }

    $ref     = new ReflectionClass($class);
    $actions = $ref->getMethods(ReflectionMethod::IS_STATIC);
    foreach ($actions as $action) {
        add_action($action->name, Array($class, $action->name));
    }
}

function add_shortcodes($class) {
    if (!class_exists($class)) {
        throw new Exception("$class does not exist");
    }

    $ref     = new ReflectionClass($class);
    $methods = $ref->getMethods(ReflectionMethod::IS_STATIC);
    foreach ($methods as $method) {
        add_shortcode($method->name, Array($class, $method->name));
    }
}

function add_filters($class) {
    if (!class_exists($class)) {
        throw new Exception("$class does not exist");
    }

    $ref     = new ReflectionClass($class);
    $methods = $ref->getMethods(ReflectionMethod::IS_STATIC);
    foreach ($methods as $method) {
        add_filter($method->name, Array($class, $method->name));
    }
}
?>