From ed166608670c5b5d237c43bd0d672502d5b624f5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 20 Jun 2016 20:34:19 -0700 Subject: code optimisation --- Zotlabs/Module/Siteinfo.php | 26 +++++--------------------- include/network.php | 9 +-------- include/plugin.php | 6 ++++++ include/text.php | 2 +- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/Zotlabs/Module/Siteinfo.php b/Zotlabs/Module/Siteinfo.php index f6b34d0c8..a15e2896d 100644 --- a/Zotlabs/Module/Siteinfo.php +++ b/Zotlabs/Module/Siteinfo.php @@ -27,27 +27,11 @@ class Siteinfo extends \Zotlabs\Web\Controller { else { $version = $commit = ''; } - $visible_plugins = array(); - if(is_array(\App::$plugins) && count(\App::$plugins)) { - $r = q("select * from addon where hidden = 0"); - if(count($r)) - foreach($r as $rr) - $visible_plugins[] = $rr['aname']; - } - $plugins_list = ''; - if(count($visible_plugins)) { - $plugins_text = t('Installed plugins/addons/apps:'); - $sorted = $visible_plugins; - $s = ''; - sort($sorted); - foreach($sorted as $p) { - if(strlen($p)) { - if(strlen($s)) $s .= ', '; - $s .= $p; - } - } - $plugins_list .= $s; - } + + $plugins_list = implode(', ',visible_plugin_list()); + + if($plugins_list) + $plugins_text = t('Installed plugins/addons/apps:'); else $plugins_text = t('No installed plugins/addons/apps'); diff --git a/include/network.php b/include/network.php index 062f2c2bf..41d13a40e 100644 --- a/include/network.php +++ b/include/network.php @@ -1992,14 +1992,7 @@ function get_site_info() { else $service_class = false; - $visible_plugins = array(); - if(is_array(App::$plugins) && count(App::$plugins)) { - $r = q("select * from addon where hidden = 0"); - if(count($r)) - foreach($r as $rr) - $visible_plugins[] = $rr['aname']; - } - sort($visible_plugins); + $visible_plugins = visible_plugin_list(); if(@is_dir('.git') && function_exists('shell_exec')) $commit = trim(@shell_exec('git log -1 --format="%h"')); diff --git a/include/plugin.php b/include/plugin.php index 9b84039a6..c95f8cbf9 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -167,6 +167,12 @@ function reload_plugins() { } } +function visible_plugin_list() { + $r = q("select * from addon where hidden = 0 order by aname asc"); + return(($r) ? ids_to_array($r,'aname') : array()); +} + + /** * @brief registers a hook. diff --git a/include/text.php b/include/text.php index 22f4556a8..3754675d1 100644 --- a/include/text.php +++ b/include/text.php @@ -2050,7 +2050,7 @@ function ids_to_array($arr,$idx = 'id') { $t = array(); if($arr) { foreach($arr as $x) { - if(! in_array($x[$idx],$t)) { + if(strlen($x[$idx]) && (! in_array($x[$idx],$t))) { $t[] = $x[$idx]; } } -- cgit v1.2.3