PHP Code:
public $plugins = array();
private $keys = array(
'current_page' => URL,
's' => S,
't' => T,
'e' => E,
'p' => P,
'b' => B,
);
public function Init() {
$this->make_array();
$i = 1;
$x = $this->count_plugins()+1;
while($i<$x) {
$this->execute(file($this->filter($this->plugins[$i]['location']) . $this->plugins[$i]['execute'], FILE_IGNORE_NEW_LINES), $i, false);
$i++;
}
}
private function filter($str) {
foreach ($this->keys as $key => $value) {
$str = str_ireplace('{' . $key . '}', $value, $str);
}
return $str;
}
private function make_array() {
$file = $this->get_plugins();
$seperate = explode('<plugin=active>', $file);
$seperate = str_replace('</plugin=active>', '', $seperate);
foreach($seperate as $cnt => $name) {
$variables = explode('<->', $seperate[$cnt]);
$pluginname = get_between('<system_name>', '</system_name>', $name);
foreach($variables as $name) {
$variable = get_between('<', '>', $name);
if($variable == 'config') {
$get_config = get_between('<config>', '</config>', $seperate[$cnt]);
$config_seperate = explode('<->', $get_config);
foreach($config_seperate as $config_line) {
$variable = get_between('<', '>', $config_line);
$this->plugins[$pluginname]['config'][$variable] = $this->filter(get_between('<' . $variable . '>', '</' . $variable . '>', $config_line));
$this->plugins[$cnt]['config'][$variable] = $this->filter(get_between('<' . $variable . '>', '</' . $variable . '>', $config_line));
}
} else {
$this->plugins[$pluginname][$variable] = $this->filter(get_between('<' . $variable . '>', '</' . $variable . '>', $name));
$this->plugins[$cnt][$variable] = $this->filter(get_between('<' . $variable . '>', '</' . $variable . '>', $name));
}
}
}
}
private function get_plugins() {
$files = file_get_contents(S . P . 'plugins.xml');
return $files;
}
private function count_plugins() {
$plugin_file = $this->get_plugins();
$start = substr_count($plugin_file, '<plugin=active>');
$end = substr_count($plugin_file, '</plugin=active>');
if($start == $end) return $end; else die("Fatal error: Expecting euqal starts and ends in plugins.xml");
return false;
}
private function do_action($plugin, $what) {
include($this->filter($this->plugins[$plugin]['location']) . $what. '.php');
}
private function do_execute_action($what, $value, $plugin_id) {
switch($what) {
case "ONPAGELOAD":
include($this->filter($this->plugins[$plugin_id]['location']) . $value. '.php');
break;
default:
echo "DID NOT FIND THE ACTION $what";
break;
}
}
private function execute($line, $plugin_id, $file = false) {
if($file != false) $line = file($file, FILE_IGNORE_NEW_LINES);
foreach($line as $value) {
$what = get_between('<', '>', $value);
$value = get_between('<' . $what . '>', '</' . $what . '>', $value);
$this->do_execute_action($what, $value, $plugin_id);
}
}