@ 2014-04-07T16:46:40Z <?php
<?php
interface IPlugin {
public function set_hooks();
public function plugin_info();
public function deactivate();
}
function __autoload($class) {
include(getcwd() . "/plugins/" . ucfirst($class) . ".php");
}
/*
Static class responsible for every plugin
*/
class Plugins {
private static $plugins = array();
private static $hooks = array();
private static $plugin_count = 0;
private static $hook_count = 0;
public function __construct() {
$dir = opendir(getcwd() . '/plugins');
while (false !== ($filename = readdir($dir))) {
if (stripos($filename, '.php') === false || strcmp($filename, 'IPlugin.php') == 0)
continue;
$name = str_replace('.php', '', $filename);
array_push(self::$plugins, array(
'name' => $name,
'filename' => $filename,
'filepath' => getcwd().'/plugins/'.$filename
)
);
self::$plugin_count++;
self::add_hook($name, true);
}
}
public static function add_hook($name, $activate) {
$hooks = self::$hooks;
$length = count($hooks);
for ($i = 0; $i < $length; $i++)
if (in_array($name, $hooks[$i]) == true) {
if ($hooks[$i]['name'] !== $name)
continue;
self::$hooks[$i]['activate'] = 1;
self::$hook_count++;
return;
}
array_push(self::$hooks, array(
'name' => $name,
'activate' => $activate
)
);
self::$hook_count++;
}
public static function remove_hook($name) {
$hooks = self::$hooks;
$length = count($hooks);
$name = str_replace('.php', '', $name);
for ($i = 0; $i < $length; $i++) {
if ($hooks[$i]['name'] !== $name)
continue;
self::$hook_count--;
self::$hooks[$i]['activate'] = 0;
}
}
public static function run_hooks($hook) {
$plugins = self::$plugins;
$hooks = self::$hooks;
for ($i = 0; $i < count($hooks); $i++) {
$plugin = self::getPluginObject($hooks[$i]['name']);
if ($hooks[$i]['activate'] == 0) {
$hook_defunc = 'deactivate_' . $hook;
$func = is_callable(array($plugin, $hook_defunc));
if (!$func)
$plugin->deactivate();
else
$plugin->$hook_defunc();
continue;
}
$plugin_hooks = count($plugin->set_hooks());
for ($i2 = 0; $i2 < $plugin_hooks; $i2++)
if (strcasecmp($plugin_hooks[$i2], $hook) != 0)
continue;
$hook_func = 'activate_' . $hook;
$func = is_callable(array($plugin, $hook_func));
if (!$func)
$plugin->deactivate();
else
$plugin->$hook_func();
}
}
public static function getPluginObject($name) {
$plugins = self::$plugins;
$plugin_count = count($plugins);
for ($i = 0; $i < $plugin_count; $i++) {
if ($plugins[$i]['name'] !== $name)
continue;
return new $plugins[$i]['name']();
}
return null;
}
public static function getPluginCount() {
return self::$plugin_count;
}
public static function getHookCount() {
return self::$hook_count;
}
public static function get_plugins() {
return self::$plugins;
}
public static function get_hooks() {
return self::$hooks;
}
}
class TestPlugin implements IPlugin {
public function set_hooks() {
return array(
'index_bottom', 'index_content'
);
}
public function plugin_info() {
return array(
'name' => 'Test Plugin',
'version' => 1.1
);
}
public function activate_index_bottom() {
echo '<p>This will activate if the index_bottom hook is used</p>';
}
public function deactivate_index_bottom() {
echo 'DEACTIVATE INDEX BOTTOM';
}
public function activate_index_content() {
echo '<a href="lol.php" alt="">lolfags</a>';
}
public function deactivate_index_content() {
echo 'DEACTIVATE';
}
// invoked if other hook functions fail for any reason
public function deactivate() {
echo '<h1>Plugin system broken!!?!?!?</h1>';
}
}
echo '<html><head></head><body><p>blabla</p>';
$plugins = new Plugins();
$plugins->run_hooks('index_content');
echo '<hr />';
$plugins->run_hooks('index_bottom');
echo '<p>woot</p></body></html>';
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.27 0.010 0.063 18.77 5.4.26 0.013 0.067 18.91 5.4.25 0.023 0.043 18.92 5.4.24 0.007 0.053 18.92 5.4.23 0.007 0.060 19.04 5.4.22 0.007 0.080 19.07 5.4.21 0.023 0.067 18.94 5.4.20 0.003 0.063 18.73 5.4.19 0.013 0.067 18.90 5.4.18 0.000 0.067 18.78 5.4.17 0.007 0.057 18.75 5.4.16 0.023 0.063 18.86 5.4.15 0.013 0.077 18.70 5.4.14 0.013 0.050 16.57 5.4.13 0.003 0.053 16.34 5.4.12 0.027 0.060 16.38 5.4.11 0.007 0.070 16.48 5.4.10 0.017 0.043 16.54 5.4.9 0.007 0.053 16.38 5.4.8 0.010 0.050 16.36 5.4.7 0.030 0.050 16.38 5.4.6 0.003 0.073 16.51 5.4.5 0.007 0.077 16.46 5.4.4 0.010 0.067 16.41 5.4.3 0.010 0.053 16.43 5.4.2 0.013 0.063 16.32 5.4.1 0.013 0.050 16.50 5.4.0 0.010 0.047 15.88 5.3.28 0.003 0.070 14.59 5.3.27 0.003 0.067 14.49 5.3.26 0.010 0.053 14.45 5.3.25 0.010 0.063 14.61 5.3.24 0.017 0.047 14.63 5.3.23 0.010 0.053 14.62 5.3.22 0.017 0.057 14.58 5.3.21 0.007 0.063 14.59 5.3.20 0.010 0.063 14.46 5.3.19 0.017 0.047 14.72 5.3.18 0.010 0.053 14.44 5.3.17 0.017 0.060 14.72 5.3.16 0.007 0.050 14.33 5.3.15 0.010 0.063 14.41 5.3.14 0.010 0.053 14.71 5.3.13 0.020 0.040 14.55 5.3.12 0.013 0.053 14.32 5.3.11 0.013 0.070 14.43 5.3.10 0.010 0.053 14.03 5.3.9 0.010 0.047 13.89 5.3.8 0.017 0.053 14.03 5.3.7 0.003 0.063 14.01 5.3.6 0.017 0.060 14.15 5.3.5 0.010 0.047 14.10 5.3.4 0.000 0.053 13.96 5.3.3 0.010 0.050 14.02 5.3.2 0.010 0.043 13.60 5.3.1 0.013 0.047 13.66 5.3.0 0.010 0.057 13.79 5.2.17 0.007 0.057 11.30 5.2.16 0.013 0.040 11.06 5.2.15 0.007 0.040 11.16 5.2.14 0.010 0.040 11.14 5.2.13 0.010 0.050 11.02 5.2.12 0.010 0.053 11.02 5.2.11 0.017 0.043 10.86 5.2.10 0.007 0.043 11.21 5.2.9 0.007 0.040 11.10 5.2.8 0.010 0.053 11.01 5.2.7 0.003 0.060 11.18 5.2.6 0.010 0.037 10.97 5.2.5 0.017 0.043 11.04 5.2.4 0.003 0.040 11.11 5.2.3 0.010 0.037 10.99 5.2.2 0.007 0.037 10.96 5.2.1 0.010 0.047 10.75 5.2.0 0.003 0.040 10.88 5.1.6 0.007 0.047 9.91 5.1.5 0.000 0.037 10.19 5.1.4 0.010 0.043 9.92 5.1.3 0.003 0.037 10.41 5.1.2 0.013 0.047 10.11 5.1.1 0.010 0.030 10.26 5.1.0 0.000 0.040 10.13 5.0.5 0.000 0.030 8.32 5.0.4 0.010 0.020 8.46 5.0.3 0.010 0.040 8.16 5.0.2 0.007 0.023 8.20 5.0.1 0.007 0.040 8.00 5.0.0 0.003 0.043 8.21 4.4.9 0.000 0.023 7.01 4.4.8 0.007 0.020 7.01 4.4.7 0.007 0.017 7.01 4.4.6 0.000 0.023 7.01 4.4.5 0.003 0.023 7.01 4.4.4 0.007 0.030 7.01 4.4.3 0.000 0.033 7.01 4.4.2 0.003 0.020 7.01 4.4.1 0.007 0.023 7.01 4.4.0 0.010 0.033 7.01 4.3.11 0.000 0.023 7.01 4.3.10 0.010 0.020 7.01 4.3.9 0.003 0.027 7.01 4.3.8 0.010 0.023 7.01 4.3.7 0.013 0.010 7.01 4.3.6 0.003 0.020 7.01 4.3.5 0.007 0.027 7.01 4.3.4 0.007 0.033 7.01 4.3.3 0.007 0.023 7.01 4.3.2 0.007 0.020 7.01 4.3.1 0.003 0.017 7.01 4.3.0 0.017 0.013 13.49
preferences:dark mode live preview
142.63 ms | 1398 KiB | 7 Q