This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/contrib/ext_manager/main.php
shish 18b97444d4 functionality
git-svn-id: file:///home/shish/svn/shimmie2/trunk@619 7f39781d-f577-437e-ae19-be835c7a54ca
2007-12-04 18:14:14 +00:00

95 lines
2.6 KiB
PHP

<?php
/**
* Name: Extension Manager
* Author: Shish <webmaster@shishnet.org>
* Link: http://trac.shishnet.org/shimmie2/
* License: GPLv2
* Description: A thing for point & click extension management
*/
class ExtManager extends Extension {
var $theme;
public function receive_event($event) {
if(is_null($this->theme)) $this->theme = get_theme_object("ext_manager", "ExtManagerTheme");
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "ext_manager")) {
if($event->user->is_admin()) {
if($event->get_arg(0) == "set") {
$this->set_things($_POST);
$event->page->set_mode("redirect");
$event->page->set_redirect("ext_manager");
}
else {
$this->theme->display_table($event->page, $this->get_extensions());
}
}
}
if(is_a($event, 'UserBlockBuildingEvent')) {
if($event->user->is_admin()) {
$event->add_link("Extension Manager", make_link("ext_manager"));
}
}
}
private function get_extensions() {
$extensions = array();
foreach(glob("contrib/*/main.php") as $main) {
$extension = array();
$matches = array();
$data = file_get_contents($main);
preg_match("#contrib/(.*)/main.php#", $main, $matches);
$extension["ext_name"] = $matches[1];
if(preg_match("/Name: (.*)/", $data, $matches)) {
$extension["name"] = $matches[1];
}
if(preg_match("/Link: (.*)/", $data, $matches)) {
$extension["link"] = $matches[1];
}
if(preg_match("/Author: (.*) [<\(](.*@.*)[>\)]/", $data, $matches)) {
$extension["author"] = $matches[1];
$extension["email"] = $matches[2];
}
else if(preg_match("/Author: (.*)/", $data, $matches)) {
$extension["author"] = $matches[1];
}
if(preg_match("/Description: (.*)/", $data, $matches)) {
$extension["description"] = $matches[1];
}
$extension["enabled"] = $this->is_enabled($extension["ext_name"]);
$extensions[] = $extension;
}
return $extensions;
}
private function is_enabled($fname) {
return file_exists("ext/$fname");
}
private function set_things($settings) {
foreach(glob("contrib/*/main.php") as $main) {
$matches = array();
preg_match("#contrib/(.*)/main.php#", $main, $matches);
$fname = $matches[1];
$this->set_enabled($fname, $settings["ext_$fname"]);
}
}
private function set_enabled($fname, $enabled) {
if($enabled) {
// enable if currently disabled
if(!file_exists("ext/$fname")) {
shell_exec("ln -s ../contrib/$fname ext/$fname");
}
}
else {
// disable if currently enabled
if(file_exists("ext/$fname")) {
shell_exec("rm ext/$fname");
}
}
}
}
add_event_listener(new ExtManager());
?>