Advertisement
Guest User

asdsa

a guest
Aug 14th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <?php
  2. ////////////////////////////////////////
  3. /// Plugin Manager v1.0 ///
  4. /// In PHP By Myles ///
  5. /// Fully Open Source ///
  6. ////////////////////////////////////////
  7.  
  8. /*
  9. Notes:
  10. All Plugins Name Must Be the Same with their class, testPlugin.php > class testPlugin{
  11. Thats About it.
  12. */
  13. class PluginManager{
  14. public $plugins,$type;
  15. private $ocp,$handlers,$events;
  16. private $version = 0.01;
  17. public function __construct ($ocp,$type)
  18. {
  19. $this->type = $type;
  20. $this->ocp = $ocp;
  21. $this->handlers = array();
  22. echo "//////////////////////////////////\n";
  23. echo "/// Plugin Manager v0.01 ///\n";
  24. echo "/// For OpenCP In PHP ///\n";
  25. echo "/// Coded By Myles - myles.me ///\n";
  26. echo "//////////////////////////////////\n";
  27. echo "[Plugin Manager]: Loaded Plugin Manager \n";
  28. echo "[Plugin Manager]: Checking For Updates \n";
  29. /*
  30. $ver = &file_get_contents("http://opencp.myles.me/version.php?ver=".$this->version);
  31. if(!$ver){
  32. echo "[Plugin Manager]: Failed to Connect \n";
  33. }else
  34. {
  35. if(isnumeric($ver)){
  36. if($ver > $this-version){
  37. echo "[Plugin Manager]: New Version Avaliable, Version ".$ver." Download NOW! At http://opencp.myles.me/download.php \n";
  38.  
  39. }else
  40. {
  41. echo "[Plugin Manager]: No Updates Avaliable";
  42. }
  43. }else
  44. {
  45. echo "[Plugin Manager]: ".$ver;
  46. }
  47. }
  48. */
  49.  
  50. $events = array("Servers","Message","joinServer","UserSnowball");
  51. foreach($events as $event){
  52. $this->events[$event] = 1;
  53. $this->handlers[$event] = array();
  54. }
  55.  
  56. echo "Scanning \n";
  57. $dir = "Plugins";
  58. foreach (glob("Plugins/*.php") as $value)
  59. {
  60.  
  61. $value = str_replace("Plugins/","",$value);
  62. echo "Found Plugin $value \n";
  63. $value = str_replace(".php","",$value);
  64. $this->loadPlugin($value);
  65. echo "Found Plugin $value ";
  66. }
  67. /*
  68.  
  69. foreach($files as $key => $value){
  70. if($value != "" && $value != "." && $value != ".."){
  71. if(strpos($value,".php") !== false){
  72. $value = str_replace(".php","",$value);
  73. $this->loadPlugin($value);
  74. echo "Found Plugin $value ";
  75. }
  76. }
  77. }
  78. */
  79. }
  80.  
  81. public function loadPlugin($name){
  82. $name = preg_replace("/[^a-zA-Z0-9]/", "", $name);
  83. include_once "Plugins/".$name.".php";
  84. $ocp = $this->ocp;
  85. $type = $this->type;
  86. eval("\$this->plugins[\$name] = new ".htmlspecialchars($name)."(\$this,\$ocp,\$type);");
  87. echo "[PluginManager]: $name Plugin Loaded \n";
  88. if(method_exists($this->plugins[$name],'init')){
  89. $this->plugins[$name]->init();
  90. }
  91. }
  92. public function handle(){
  93. $args = func_get_args();
  94. $event = $args[0];
  95. echo "[EVENT] ".$event."\n";
  96. foreach($this->handlers[$event] as $e){
  97. $name = $e['plugin'];
  98. $name = preg_replace("/[^a-zA-Z0-9]/", "", $name);
  99. $action = $e['action'];
  100. $action = preg_replace("/[^a-zA-Z0-9]/", "", $action);
  101. eval("\$return = \$this->plugins[\$name]->".$action."(\$args);");
  102.  
  103. }
  104. return $return;
  105. }
  106. public function addHandler($event,$action){
  107. if($this->events[$event] == 1 && $event != ""){
  108.  
  109. // Time to Catch Da Plugin.
  110. $bk = debug_backtrace();
  111. $pluginurl = substr($bk[0]['file'], strrpos($bk[0]['file'], "/") + 1);
  112. $fileurl = explode('\\',$pluginurl);
  113. $plugin = $fileurl[count($fileurl) - 1];
  114. $plugin_fin = str_replace(".php","",$plugin);
  115. $arr = array();
  116. $arr['plugin'] = $plugin_fin;
  117. $arr['action'] = $action;
  118. $this->handlers[$event][] = $arr;
  119. }else
  120. {
  121. return false;
  122. }
  123. }
  124.  
  125. }
  126. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement