From e16ea1ae0568238fa4c2236d1f050ef4a85749c7 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 14:25:46 +0000 Subject: pdl editor for addon iitial commit --- Zotlabs/Module/Pdledit.php | 37 ++++++++++++++++++++++++++++++++++--- Zotlabs/Module/Pdledit_gui.php | 42 +++++++++++++++++++++++++++++++++++++++--- Zotlabs/Widget/Categories.php | 2 +- boot.php | 15 +++++++++++---- include/plugin.php | 19 +++++++++++++++---- 5 files changed, 100 insertions(+), 15 deletions(-) diff --git a/Zotlabs/Module/Pdledit.php b/Zotlabs/Module/Pdledit.php index 3b94c9611..e0bbc31d0 100644 --- a/Zotlabs/Module/Pdledit.php +++ b/Zotlabs/Module/Pdledit.php @@ -78,6 +78,23 @@ class Pdledit extends Controller { } } + // addons + $o .= '

Addons

'; + + $addons = plugins_installed_list(); + + foreach ($addons as $addon) { + + $path = 'addon/' . $addon . '/Mod_' . ucfirst($addon) . '.php'; + + if (!file_exists($path)) + continue; + + $o .= '' . $addon . '' . ((in_array($addon, $edited)) ? ' ' . t('(modified)') . ' ' . t('Reset') . '': '' ) . '
'; + + } + + $o .= ''; // list module pdl files @@ -85,11 +102,25 @@ class Pdledit extends Controller { } $t = get_pconfig(local_channel(),'system',$module); - $s = file_get_contents(theme_include($module)); - if(! $t) { + $s = ''; + + if(!$t) { + $sys_path = theme_include($module); + + if ($sys_path) { + $s = file_get_contents($sys_path); + } + else { + $addon_path = 'addon/' . argv(1) . '/' . $module; + if (file_exists($addon_path)) { + $s = file_get_contents($addon_path); + } + } + $t = $s; } - if(! $t) { + + if(!$t) { notice( t('Layout not found.') . EOL); return ''; } diff --git a/Zotlabs/Module/Pdledit_gui.php b/Zotlabs/Module/Pdledit_gui.php index b550b92d3..d8d362831 100644 --- a/Zotlabs/Module/Pdledit_gui.php +++ b/Zotlabs/Module/Pdledit_gui.php @@ -237,18 +237,45 @@ class Pdledit_gui extends Controller { } } + $addons = plugins_installed_list(); + if ($addons) { + foreach ($addons as $name) { + $path = 'addon/' . $name . '/Mod_' . ucfirst($name) . '.php'; + + if (!file_exists($path)) { + continue; + } + + $ret .= '
' . $name . '
'; + } + } + return $ret; } function get_widgets($module) { $ret = []; + $checkpaths = [ 'Zotlabs/Widget/*.php' ]; + $addons = plugins_installed_list(); + + if ($addons) { + foreach ($addons as $name) { + $path = 'addon/' . $name . '/Widget'; + + if (is_dir($path)) { + $checkpaths[] = $path . '/*.php'; + } + } + } + foreach ($checkpaths as $path) { $files = glob($path); + if($files) { foreach($files as $f) { $name = lcfirst(basename($f, '.php')); @@ -536,12 +563,21 @@ class Pdledit_gui extends Controller { 'modified' => true ]; - $pdl_path = 'mod_' . $module . '.pdl'; + $pdl = 'mod_' . $module . '.pdl'; + $pdl_path = ''; - $ret['pdl'] = get_pconfig(local_channel(), 'system', $pdl_path); + $ret['pdl'] = get_pconfig(local_channel(), 'system', $pdl); if(!$ret['pdl']) { - $pdl_path = theme_include($pdl_path); + $pdl_path = theme_include($pdl); + + if (!$pdl_path) { + $addon_path = 'addon/' . $module . '/' . $pdl; + if (file_exists($addon_path)) { + $pdl_path = $addon_path; + } + } + if ($pdl_path) { $ret['pdl'] = file_get_contents($pdl_path); $ret['modified'] = false; diff --git a/Zotlabs/Widget/Categories.php b/Zotlabs/Widget/Categories.php index b0eda253b..7e6a3c6f7 100644 --- a/Zotlabs/Widget/Categories.php +++ b/Zotlabs/Widget/Categories.php @@ -3,7 +3,7 @@ /** * * Name: Categories * * Description: Display a menu with links to categories - * * Requires: channel, articles, cards, cloud + * * Requires: channel, cloud */ namespace Zotlabs\Widget; diff --git a/boot.php b/boot.php index b02dad9d6..dd3861196 100644 --- a/boot.php +++ b/boot.php @@ -2268,6 +2268,7 @@ function load_pdl() { 'module' => App::$module, 'layout' => '' ]; + /** * @hooks load_pdl * Called when we load a PDL file or description. @@ -2281,20 +2282,26 @@ function load_pdl() { $u = App::$comanche->get_channel_id(); $s = ''; - if ($u) + if ($u) { $s = get_pconfig($u, 'system', $n); - if (!$s) + } + + if (!$s) { $s = $layout; + } - if ((!$s) && (($p = theme_include($n)) != '')) + if ((!$s) && (($p = theme_include($n)) != '')) { $s = @file_get_contents($p); - elseif (file_exists('addon/' . App::$module . '/' . $n)) + } + elseif ((!$s) && file_exists('addon/' . App::$module . '/' . $n)) { $s = @file_get_contents('addon/' . App::$module . '/' . $n); + } $arr = [ 'module' => App::$module, 'layout' => $s ]; + call_hooks('alter_pdl', $arr); $s = $arr['layout']; diff --git a/include/plugin.php b/include/plugin.php index ff5014c8b..ae73a847c 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -189,7 +189,7 @@ function plugin_is_installed($name) { function reload_plugins() { $plugins = get_config('system', 'addon'); if(strlen($plugins)) { - $r = q("SELECT * FROM addon WHERE installed = 1"); + $r = dbq("SELECT * FROM addon WHERE installed = 1"); if(count($r)) $installed = $r; else @@ -243,7 +243,7 @@ function reload_plugins() { function plugins_installed_list() { - $r = q("select * from addon where installed = 1 order by aname asc"); + $r = dbq("select * from addon where installed = 1 order by aname asc"); return(($r) ? ids_to_array($r,'aname') : []); } @@ -313,7 +313,7 @@ function plugins_sync() { */ function visible_plugin_list() { - $r = q("select * from addon where hidden = 0 order by aname asc"); + $r = dbq("select * from addon where hidden = 0 order by aname asc"); $x = (($r) ? ids_to_array($r,'aname') : array()); $y = []; if($x) { @@ -392,7 +392,7 @@ function load_hooks() { App::$hooks = []; - $r = q("SELECT * FROM hook WHERE true ORDER BY priority DESC"); + $r = dbq("SELECT * FROM hook WHERE true ORDER BY priority DESC"); if($r) { foreach($r as $rv) { @@ -613,6 +613,17 @@ function get_widget_info($widget){ "addon/$widget.php" ]; + $addons = plugins_installed_list(); + + if ($addons) { + foreach ($addons as $name) { + $path = 'addon/' . $name . '/Widget/' . $ucwidget . '.php'; + if (is_file($path)) { + $checkpaths[] = $path ; + } + } + } + $widget_found = false; foreach ($checkpaths as $path) { -- cgit v1.2.3