Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 79 lines (65 sloc) 1.941 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
<?php

class modules
{
    private $modules = array();
    
    public function __construct()
    {
        $this->load();
    }
    
    public function load()
    {
        $parents = scandir('modules');
        array_shift($parents);
        array_shift($parents);
        foreach ($parents as $parent)
        {
            $children = scandir('modules/' . $parent);
            array_shift($children);
            array_shift($children);
            foreach ($children as $child)
            {
                $contents = file_get_contents("modules/{$parent}/{$child}");
                $module = eval($contents);
                list($childName) = explode('.', $child);
                $this->modules[$parent][$childName] = array(
                    'module' => $module,
                    'enabled' => true
                );
            }
        }
    }
    
    public function unload()
    {
        $this->modules = array();
    }
    
    public function reload()
    {
        $this->unload();
        $this->load();
    }
    
    public function disable($command, $module)
    {
        if (!$this->modules[$command][$module]) return;
        
        $this->modules[$command][$module]['enabled'] = true;
    }
    
    public function enable($command, $module)
    {
        if (!$this->modules[$command][$module]) return;
        
        $this->modules[$command][$module]['enabled'] = true;
    }
    
    public function toggle($command, $module)
    {
        if (!$this->modules[$command][$module]) return;
        
        $val = $this->modules[$command][$module]['enabled'];
        $this->modules[$command][$module]['enabled'] = !$val;
    }
    
    public function hook($hook, $message)
    {
        if (!isset($this->modules[$hook])) return;

        foreach ($this->modules[$hook] as $module)
        {
            if (!$module['enabled']) continue;
            $module['module']($message);
        }
    }
}
Something went wrong with that request. Please try again.