From 00e142e4f753005a8b4003585c6a88548f006315 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Tue, 14 Jun 2011 14:21:43 +0200 Subject: [PATCH] Load plugin info from plugin file. Show README.md or README from plugin dir in plugin details page --- addon/oembed/oembed.php | 9 +++--- boot.php | 52 ++++++++++++++++++++++++++++++++++ mod/admin.php | 20 +++++++++---- view/admin_plugins.tpl | 7 ++--- view/admin_plugins_details.tpl | 16 +++++++++-- 5 files changed, 88 insertions(+), 16 deletions(-) diff --git a/addon/oembed/oembed.php b/addon/oembed/oembed.php index a0a0239aa..f5be44194 100644 --- a/addon/oembed/oembed.php +++ b/addon/oembed/oembed.php @@ -1,10 +1,9 @@ */ require_once('include/oembed.php'); diff --git a/boot.php b/boot.php index 42b0ca41e..5d45de36f 100644 --- a/boot.php +++ b/boot.php @@ -2828,3 +2828,55 @@ function is_site_admin() { return false; }} +/* + * parse plugin comment in search of plugin infos. + * like + * + * * Name: Plugin + * * Description: A plugin which plugs in + * * Version: 1.2.3 + * * Author: John + * * Author: Jane + * * + */ + +if (! function_exists('get_plugin_info')){ +function get_plugin_info($plugin){ + if (!is_file("addon/$plugin/$plugin.php")) return false; + + $f = file_get_contents("addon/$plugin/$plugin.php"); + $r = preg_match("|/\*.*\*/|msU", $f, $m); + + $info=Array( + 'name' => $plugin, + 'description' => "", + 'author' => array(), + 'version' => "" + ); + + if ($r){ + $ll = explode("\n", $m[0]); + foreach( $ll as $l ) { + $l = trim($l,"\t\n\r */"); + if ($l!=""){ + list($k,$v) = array_map("trim", explode(":",$l,2)); + $k= strtolower($k); + if ($k=="author"){ + $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); + if ($r) { + $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]); + } else { + $info['author'][] = array('name'=>$v); + } + } else { + if (array_key_exists($k,$info)){ + $info[$k]=$v; + } + } + + } + } + + } + return $info; +}} diff --git a/mod/admin.php b/mod/admin.php index e40c50396..6386e6ebc 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -340,7 +340,7 @@ function admin_page_plugins(&$a){ return; // NOTREACHED } // display plugin details - + require_once('library/markdown.php'); if (in_array($plugin, $a->plugins)){ $status="on"; $action= t("Disable"); @@ -348,6 +348,14 @@ function admin_page_plugins(&$a){ $status="off"; $action= t("Enable"); } + $readme=Null; + if (is_file("addon/$plugin/README.md")){ + $readme = file_get_contents("addon/$plugin/README.md"); + $readme = Markdown($readme); + } else if (is_file("addon/$plugin/README")){ + $readme = "
". file_get_contents("addon/$plugin/README") ."
"; + } + $t = get_markup_template("admin_plugins_details.tpl"); return replace_macros($t, array( '$title' => t('Administration'), @@ -357,7 +365,10 @@ function admin_page_plugins(&$a){ '$plugin' => $plugin, '$status' => $status, - '$action' => $action + '$action' => $action, + '$info' => get_plugin_info($plugin), + + '$readme' => $readme )); } @@ -373,9 +384,8 @@ function admin_page_plugins(&$a){ foreach($files as $file) { if (is_dir($file)){ list($tmp, $id)=array_map("trim", explode("/",$file)); - // TODO: plugins info - $name=$author=$description=$homepage=""; - $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $name, $author, $description, $homepage); + $info = get_plugin_info($id); + $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info); } } } diff --git a/view/admin_plugins.tpl b/view/admin_plugins.tpl index d29665a06..ee0fa67e6 100644 --- a/view/admin_plugins.tpl +++ b/view/admin_plugins.tpl @@ -4,10 +4,9 @@
    {{ for $plugins as $p }}
  • - - - $p.0 - + + $p.2.name - $p.2.version +
    $p.2.description
  • {{ endfor }}
diff --git a/view/admin_plugins_details.tpl b/view/admin_plugins_details.tpl index 7e2e95521..acb3d2862 100644 --- a/view/admin_plugins_details.tpl +++ b/view/admin_plugins_details.tpl @@ -1,7 +1,19 @@

$title - $page

-

$plugin

+

$info.name - $info.version : $action

+

$info.description

+

+ {{ for $info.author as $a }} + $a.name + {{ endfor }} +

-

$action

+ + {{ if $readme }} +

Readme

+
+ $readme +
+ {{ endif }}