1
0
Fork 0

Load plugin info from plugin file. Show README.md or README from plugin dir in plugin details page

This commit is contained in:
Fabio Comuni 2011-06-14 14:21:43 +02:00
parent 283160901f
commit 00e142e4f7
5 changed files with 88 additions and 16 deletions

View file

@ -1,10 +1,9 @@
<?php <?php
/** /**
* oembed plugin * Name: OEmbed
* * Description: OEmbed is a format for allowing an embedded representation of a URL on third party sites http://www.oembed.com/
* oEmbed is a format for allowing an embedded representation of a URL on third party sites * Version: 1.2
* http://www.oembed.com/ * Author: Fabio Comuni <http://kirgroup.com/profile/fabrix>
*
*/ */
require_once('include/oembed.php'); require_once('include/oembed.php');

View file

@ -2828,3 +2828,55 @@ function is_site_admin() {
return false; 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 <profile url>
* * Author: Jane <email>
* *
*/
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;
}}

View file

@ -340,7 +340,7 @@ function admin_page_plugins(&$a){
return; // NOTREACHED return; // NOTREACHED
} }
// display plugin details // display plugin details
require_once('library/markdown.php');
if (in_array($plugin, $a->plugins)){ if (in_array($plugin, $a->plugins)){
$status="on"; $action= t("Disable"); $status="on"; $action= t("Disable");
@ -348,6 +348,14 @@ function admin_page_plugins(&$a){
$status="off"; $action= t("Enable"); $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 = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
}
$t = get_markup_template("admin_plugins_details.tpl"); $t = get_markup_template("admin_plugins_details.tpl");
return replace_macros($t, array( return replace_macros($t, array(
'$title' => t('Administration'), '$title' => t('Administration'),
@ -357,7 +365,10 @@ function admin_page_plugins(&$a){
'$plugin' => $plugin, '$plugin' => $plugin,
'$status' => $status, '$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) { foreach($files as $file) {
if (is_dir($file)){ if (is_dir($file)){
list($tmp, $id)=array_map("trim", explode("/",$file)); list($tmp, $id)=array_map("trim", explode("/",$file));
// TODO: plugins info $info = get_plugin_info($id);
$name=$author=$description=$homepage=""; $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
$plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $name, $author, $description, $homepage);
} }
} }
} }

View file

@ -4,10 +4,9 @@
<ul id='pluginslist'> <ul id='pluginslist'>
{{ for $plugins as $p }} {{ for $plugins as $p }}
<li class='plugin $p.1'> <li class='plugin $p.1'>
<a class='toggle' href='$baseurl/admin/plugins/$p.0?a=t'><span class='icon $p.1'></span></a> <a class='toggleplugin' href='$baseurl/admin/plugins/$p.0?a=t'><span class='icon $p.1'></span></a>
<a href='$baseurl/admin/plugins/$p.0'> <a href='$baseurl/admin/plugins/$p.0'><span class='name'>$p.2.name</span></a> - <span class="version">$p.2.version</span>
<span class='name'>$p.0</span> <div class='desc'>$p.2.description</div>
</a>
</li> </li>
{{ endfor }} {{ endfor }}
</ul> </ul>

View file

@ -1,7 +1,19 @@
<div id='adminpage'> <div id='adminpage'>
<h1>$title - $page</h1> <h1>$title - $page</h1>
<p><span class='icon $status'></span> $plugin</p> <p><span class='toggleplugin icon $status'></span> $info.name - $info.version : <a href="$baseurl/admin/plugins/$plugin/?a=t">$action</a></p>
<p>$info.description</p>
<p>
{{ for $info.author as $a }}
<a href="$a.link">$a.name</a>
{{ endfor }}
</p>
<p><a href="$baseurl/admin/plugins/$plugin/?a=t">$action</a></p>
{{ if $readme }}
<h3>Readme</h3>
<div id="plugin_readme">
$readme
</div>
{{ endif }}
</div> </div>