tidy ups in the extension manager

git-svn-id: file:///home/shish/svn/shimmie2/trunk@808 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-04-11 06:04:22 +00:00
parent 4e19a29dd0
commit 9a54cf6d0d
2 changed files with 48 additions and 44 deletions

View file

@ -7,6 +7,40 @@
* Description: A thing for point & click extension management
*/
class ExtensionInfo { // {{{
var $ext_name, $name, $link, $author, $email, $description;
function ExtensionInfo($main) {
$matches = array();
$data = file_get_contents($main);
preg_match("#contrib/(.*)/main.php#", $main, $matches);
$this->ext_name = $matches[1];
$this->name = $matches[1];
if(preg_match("/Name: (.*)/", $data, $matches)) {
$this->name = $matches[1];
}
if(preg_match("/Link: (.*)/", $data, $matches)) {
$this->link = $matches[1];
}
if(preg_match("/Author: (.*) [<\(](.*@.*)[>\)]/", $data, $matches)) {
$this->author = $matches[1];
$this->email = $matches[2];
}
else if(preg_match("/Author: (.*)/", $data, $matches)) {
$this->author = $matches[1];
}
if(preg_match("/Description: (.*)/", $data, $matches)) {
$this->description = $matches[1];
}
$this->enabled = $this->is_enabled($this->ext_name);
}
private function is_enabled($fname) {
return file_exists("ext/$fname");
}
} // }}}
class ExtManager extends Extension {
var $theme;
@ -42,37 +76,11 @@ class ExtManager extends Extension {
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;
$extensions[] = new ExtensionInfo($main);
}
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();
@ -88,7 +96,12 @@ class ExtManager extends Extension {
if($enabled) {
// enable if currently disabled
if(!file_exists("ext/$fname")) {
$this->enable_extension($fname);
if(function_exists("symlink")) {
symlink("../contrib/$fname", "ext/$fname");
}
else {
full_copy("contrib/$fname", "ext/$fname");
}
}
}
else {
@ -98,15 +111,6 @@ class ExtManager extends Extension {
}
}
}
private function enable_extension($fname) {
if(function_exists("symlink")) {
symlink("../contrib/$fname", "ext/$fname");
}
else {
full_copy("contrib/$fname", "ext/$fname");
}
}
}
add_event_listener(new ExtManager());
?>

View file

@ -8,13 +8,13 @@ class ExtManagerTheme extends Themelet {
<tr><th>Name</th><th>Author</th><th>Description</th><th>Enabled</th></tr>
";
foreach($extensions as $extension) {
$ext_name = $extension["ext_name"];
$h_name = empty($extension["name"]) ? $ext_name : html_escape($extension["name"]);
$h_email = html_escape($extension["email"]);
$h_link = isset($extension["link"]) ? html_escape($extension["link"]) : "";
$h_author = html_escape($extension["author"]);
$h_description = html_escape($extension["description"]);
$h_enabled = $extension["enabled"] ? " checked='checked'" : "";
$ext_name = $extension->ext_name;
$h_name = empty($extension->name) ? $ext_name : html_escape($extension->name);
$h_email = html_escape($extension->email);
$h_link = isset($extension->link) ? html_escape($extension->link) : "";
$h_author = html_escape($extension->author);
$h_description = html_escape($extension->description);
$h_enabled = $extension->enabled ? " checked='checked'" : "";
$html .= "
<tr>
" . (