From 2a60f1cc6ed49ab559090c831788308fe3df0706 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 20 Feb 2022 20:18:24 +0000 Subject: merge branch pdledit_gui into dev - many widgets still miss their description and requirements (this is work in progress) --- include/plugin.php | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'include') diff --git a/include/plugin.php b/include/plugin.php index 95c9882d0..25fa22e10 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -793,6 +793,79 @@ function get_theme_info($theme){ return $info; } +/** + * @brief Parse template comment in search of template info. + * + * like + * \code + * * Name: MyWidget + * * Description: A widget + * * Version: 1.2.3 + * * Author: John + * * Author: Jane + * * ContentRegionID: some_id + * * ContentRegionID: some_other_id + * * + *\endcode + * @param string $widget the name of the widget + * @return array with the information + */ +function get_template_info($template){ + $m = array(); + $info = array( + 'name' => $template, + 'description' => '', + 'author' => array(), + 'maintainer' => array(), + 'version' => '', + 'content_regions' => [] + ); + + $checkpaths = [ + "view/php/$template.php", + ]; + + $template_found = false; + + foreach ($checkpaths as $path) { + if (is_file($path)) { + $template_found = true; + $f = file_get_contents($path); + break; + } + } + + if(! ($template_found && $f)) + return $info; + + $f = escape_tags($f); + $r = preg_match("|/\*.*\*/|msU", $f, $m); + + 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' || $k == 'maintainer'){ + $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); + if ($r) { + $info[$k][] = array('name' => $m[1], 'link' => $m[2]); + } else { + $info[$k][] = array('name' => $v); + } + } + else { + $info[$k] = $v; + } + } + } + } + + return $info; +} + /** * @brief Returns the theme's screenshot. * -- cgit v1.2.3