Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ////////////////////////////////////////
- /// Plugin Manager v1.0 ///
- /// In PHP By Myles ///
- /// Fully Open Source ///
- ////////////////////////////////////////
- /*
- Notes:
- All Plugins Name Must Be the Same with their class, testPlugin.php > class testPlugin{
- Thats About it.
- */
- class PluginManager{
- public $plugins,$type;
- private $ocp,$handlers,$events;
- private $version = 0.01;
- public function __construct ($ocp,$type)
- {
- $this->type = $type;
- $this->ocp = $ocp;
- $this->handlers = array();
- echo "//////////////////////////////////\n";
- echo "/// Plugin Manager v0.01 ///\n";
- echo "/// For OpenCP In PHP ///\n";
- echo "/// Coded By Myles - myles.me ///\n";
- echo "//////////////////////////////////\n";
- echo "[Plugin Manager]: Loaded Plugin Manager \n";
- echo "[Plugin Manager]: Checking For Updates \n";
- /*
- $ver = &file_get_contents("http://opencp.myles.me/version.php?ver=".$this->version);
- if(!$ver){
- echo "[Plugin Manager]: Failed to Connect \n";
- }else
- {
- if(isnumeric($ver)){
- if($ver > $this-version){
- echo "[Plugin Manager]: New Version Avaliable, Version ".$ver." Download NOW! At http://opencp.myles.me/download.php \n";
- }else
- {
- echo "[Plugin Manager]: No Updates Avaliable";
- }
- }else
- {
- echo "[Plugin Manager]: ".$ver;
- }
- }
- */
- $events = array("Servers","Message","joinServer","UserSnowball");
- foreach($events as $event){
- $this->events[$event] = 1;
- $this->handlers[$event] = array();
- }
- echo "Scanning \n";
- $dir = "Plugins";
- foreach (glob("Plugins/*.php") as $value)
- {
- $value = str_replace("Plugins/","",$value);
- echo "Found Plugin $value \n";
- $value = str_replace(".php","",$value);
- $this->loadPlugin($value);
- echo "Found Plugin $value ";
- }
- /*
- foreach($files as $key => $value){
- if($value != "" && $value != "." && $value != ".."){
- if(strpos($value,".php") !== false){
- $value = str_replace(".php","",$value);
- $this->loadPlugin($value);
- echo "Found Plugin $value ";
- }
- }
- }
- */
- }
- public function loadPlugin($name){
- $name = preg_replace("/[^a-zA-Z0-9]/", "", $name);
- include_once "Plugins/".$name.".php";
- $ocp = $this->ocp;
- $type = $this->type;
- eval("\$this->plugins[\$name] = new ".htmlspecialchars($name)."(\$this,\$ocp,\$type);");
- echo "[PluginManager]: $name Plugin Loaded \n";
- if(method_exists($this->plugins[$name],'init')){
- $this->plugins[$name]->init();
- }
- }
- public function handle(){
- $args = func_get_args();
- $event = $args[0];
- echo "[EVENT] ".$event."\n";
- foreach($this->handlers[$event] as $e){
- $name = $e['plugin'];
- $name = preg_replace("/[^a-zA-Z0-9]/", "", $name);
- $action = $e['action'];
- $action = preg_replace("/[^a-zA-Z0-9]/", "", $action);
- eval("\$return = \$this->plugins[\$name]->".$action."(\$args);");
- }
- return $return;
- }
- public function addHandler($event,$action){
- if($this->events[$event] == 1 && $event != ""){
- // Time to Catch Da Plugin.
- $bk = debug_backtrace();
- $pluginurl = substr($bk[0]['file'], strrpos($bk[0]['file'], "/") + 1);
- $fileurl = explode('\\',$pluginurl);
- $plugin = $fileurl[count($fileurl) - 1];
- $plugin_fin = str_replace(".php","",$plugin);
- $arr = array();
- $arr['plugin'] = $plugin_fin;
- $arr['action'] = $action;
- $this->handlers[$event][] = $arr;
- }else
- {
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement