aboutsummaryrefslogtreecommitdiffstats
path: root/include/plugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/plugin.php')
-rw-r--r--include/plugin.php117
1 files changed, 75 insertions, 42 deletions
diff --git a/include/plugin.php b/include/plugin.php
index 95c9882d0..f9cee7ed6 100644
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -794,6 +794,79 @@ function get_theme_info($theme){
}
/**
+ * @brief Parse template comment in search of template info.
+ *
+ * like
+ * \code
+ * * Name: MyWidget
+ * * Description: A widget
+ * * Version: 1.2.3
+ * * Author: John <profile url>
+ * * Author: Jane <email>
+ * * 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.
*
* The screenshot is expected as view/theme/$theme/img/screenshot.[png|jpg].
@@ -868,9 +941,7 @@ function head_get_links() {
function format_css_if_exists($source) {
- // script_path() returns https://yoursite.tld
-
- $path_prefix = script_path();
+ $path_prefix = z_root();
$script = $source[0];
@@ -892,44 +963,6 @@ function format_css_if_exists($source) {
}
}
-/**
- * This basically calculates the baseurl. We have other functions to do that, but
- * there was an issue with script paths and mixed-content whose details are arcane
- * and perhaps lost in the message archives. The short answer is that we're ignoring
- * the URL which we are "supposed" to use, and generating script paths relative to
- * the URL which we are currently using; in order to ensure they are found and aren't
- * blocked due to mixed content issues.
- *
- * @return string
- */
-function script_path() {
- if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS'])
- $scheme = 'https';
- elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443))
- $scheme = 'https';
- elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
- $scheme = 'https';
- else
- $scheme = 'http';
-
- // Some proxy setups may require using http_host
-
- if(isset(App::$config['system']['script_path_use_http_host']) && intval(App::$config['system']['script_path_use_http_host']))
- $server_var = 'HTTP_HOST';
- else
- $server_var = 'SERVER_NAME';
-
-
- if(x($_SERVER,$server_var)) {
- $hostname = $_SERVER[$server_var];
- }
- else {
- return z_root();
- }
-
- return $scheme . '://' . $hostname;
-}
-
function head_add_js($src, $priority = 0) {
if(isset(App::$js_sources[$priority]) && !is_array(App::$js_sources[$priority]))
App::$js_sources[$priority] = [];
@@ -981,7 +1014,7 @@ function head_get_main_js() {
}
function format_js_if_exists($source) {
- $path_prefix = script_path();
+ $path_prefix = z_root();
if(strpos($source,'/') !== false) {
// The source is a known path on the system