From: Adam Magness Date: Wed, 17 Jan 2018 18:52:25 +0000 (-0500) Subject: Update Theme functions and calls X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d07536e03298f8f9b2b62c7f18d4c835bb2b1f0b;p=friendica.git Update Theme functions and calls Update function names and calls for Theme class. --- diff --git a/index.php b/index.php index c4ccc9ef24..2c11ff8202 100644 --- a/index.php +++ b/index.php @@ -13,6 +13,7 @@ use Friendica\BaseObject; use Friendica\Content\Nav; use Friendica\Core\Addon; use Friendica\Core\System; +use Friendica\Core\Theme; use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; @@ -517,15 +518,15 @@ header('X-Frame-Options: sameorigin'); * The page templates are located in /view/php/ or in the theme directory. */ if (isset($_GET["mode"])) { - $template = theme_include($_GET["mode"] . '.php'); + $template = Theme::getPathForFile($_GET["mode"] . '.php'); } // If there is no page template use the default page template if (empty($template)) { - $template = theme_include("default.php"); + $template = Theme::getPathForFile("default.php"); } -/// @TODO Looks unsafe (remote-inclusion), is maybe not but theme_include() uses file_exists() but does not escape anything +/// @TODO Looks unsafe (remote-inclusion), is maybe not but Theme::getPathForFile() uses file_exists() but does not escape anything require_once $template; killme(); diff --git a/mod/admin.php b/mod/admin.php index fd8a61cb2b..f258d8de1c 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -11,6 +11,7 @@ use Friendica\Content\Text\Markdown; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\System; +use Friendica\Core\Theme; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Database\DBStructure; @@ -2007,10 +2008,10 @@ function admin_page_themes(App $a) toggle_theme($themes, $theme, $result); $s = rebuild_theme_table($themes); if ($result) { - install_theme($theme); + Theme::install($theme); info(sprintf('Theme %s enabled.', $theme)); } else { - uninstall_theme($theme); + Theme::uninstall($theme); info(sprintf('Theme %s disabled.', $theme)); } @@ -2058,7 +2059,7 @@ function admin_page_themes(App $a) $a->page = $orig_page; } - $screenshot = [get_theme_screenshot($theme), t('Screenshot')]; + $screenshot = [Theme::getScreenshot($theme), t('Screenshot')]; if (!stristr($screenshot[0], $theme)) { $screenshot = null; } @@ -2073,7 +2074,7 @@ function admin_page_themes(App $a) '$plugin' => $theme, '$status' => $status, '$action' => $action, - '$info' => get_theme_info($theme), + '$info' => Theme::getInfo($theme), '$function' => 'themes', '$admin_form' => $admin_form, '$str_author' => t('Author: '), @@ -2085,14 +2086,13 @@ function admin_page_themes(App $a) ]); } - // reload active themes if (x($_GET, "a") && $_GET['a'] == "r") { check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/themes', 'admin_themes', 't'); foreach ($themes as $th) { if ($th['allowed']) { - uninstall_theme($th['name']); - install_theme($th['name']); + Theme::uninstall($th['name']); + Theme::install($th['name']); } } info("Themes reloaded"); @@ -2105,7 +2105,7 @@ function admin_page_themes(App $a) $plugins = []; foreach ($themes as $th) { - $plugins[] = [$th['name'], (($th['allowed']) ? "on" : "off"), get_theme_info($th['name'])]; + $plugins[] = [$th['name'], (($th['allowed']) ? "on" : "off"), Theme::getInfo($th['name'])]; } $t = get_markup_template('admin/plugins.tpl'); diff --git a/mod/pretheme.php b/mod/pretheme.php index be92885b72..4989eb87b7 100644 --- a/mod/pretheme.php +++ b/mod/pretheme.php @@ -1,12 +1,13 @@ get_theme_screenshot($theme), 'desc' => $desc, 'version' => $version, 'credits' => $credits]); + echo json_encode(['img' => Theme::getScreenshot($theme), 'desc' => $desc, 'version' => $version, 'credits' => $credits]); } killme(); diff --git a/src/Core/Theme.php b/src/Core/Theme.php index f08d48efbc..9e7c632982 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -4,10 +4,9 @@ */ namespace Friendica\Core; -use Friendica\App; -use Friendica\Core\Config; use Friendica\Core\System; -use Friendica\Database\DBM; + +require_once 'boot.php'; /** * Some functions to handle themes @@ -30,7 +29,8 @@ class Theme * @return array */ - function get_theme_info($theme) { + public static function getInfo($theme) + { $info=[ 'name' => $theme, 'description' => "", @@ -61,7 +61,7 @@ class Theme foreach ( $ll as $l ) { $l = trim($l,"\t\n\r */"); if ($l != "") { - list($k,$v) = array_map("trim", explode(":",$l,2)); + list($k, $v) = array_map("trim", explode(":", $l, 2)); $k= strtolower($k); if ($k == "author") { @@ -79,14 +79,12 @@ class Theme $info['maintainer'][] = ['name'=>$v]; } } else { - if (array_key_exists($k,$info)) { - $info[$k]=$v; + if (array_key_exists($k, $info)) { + $info[$k] = $v; } } - } } - } return $info; } @@ -99,7 +97,8 @@ class Theme * @param sring $theme The name of the theme * @return string */ - function get_theme_screenshot($theme) { + public static function getScreenshot($theme) + { $exts = ['.png','.jpg']; foreach ($exts as $ext) { if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) { @@ -110,7 +109,8 @@ class Theme } // install and uninstall theme - function uninstall_theme($theme) { + public static function uninstall($theme) + { logger("Addons: uninstalling theme " . $theme); include_once("view/theme/$theme/theme.php"); @@ -120,7 +120,8 @@ class Theme } } - function install_theme($theme) { + public static function install($theme) + { // silently fail if theme was removed if (! file_exists("view/theme/$theme/theme.php")) { @@ -153,7 +154,8 @@ class Theme * @param string $root Full root path * @return string Path to the file or empty string if the file isn't found */ - function theme_include($file, $root = '') { + public static function getPathForFile($file, $root = '') + { $file = basename($file); // Make sure $root ends with a slash / if it's not blank