Update Theme functions and calls

Update function names and calls for Theme class.
This commit is contained in:
Adam Magness 2018-01-17 13:52:25 -05:00
parent 11cf36105c
commit d07536e032
4 changed files with 30 additions and 26 deletions

View file

@ -13,6 +13,7 @@ use Friendica\BaseObject;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; 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. * The page templates are located in /view/php/ or in the theme directory.
*/ */
if (isset($_GET["mode"])) { 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 there is no page template use the default page template
if (empty($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; require_once $template;
killme(); killme();

View file

@ -11,6 +11,7 @@ use Friendica\Content\Text\Markdown;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
@ -2007,10 +2008,10 @@ function admin_page_themes(App $a)
toggle_theme($themes, $theme, $result); toggle_theme($themes, $theme, $result);
$s = rebuild_theme_table($themes); $s = rebuild_theme_table($themes);
if ($result) { if ($result) {
install_theme($theme); Theme::install($theme);
info(sprintf('Theme %s enabled.', $theme)); info(sprintf('Theme %s enabled.', $theme));
} else { } else {
uninstall_theme($theme); Theme::uninstall($theme);
info(sprintf('Theme %s disabled.', $theme)); info(sprintf('Theme %s disabled.', $theme));
} }
@ -2058,7 +2059,7 @@ function admin_page_themes(App $a)
$a->page = $orig_page; $a->page = $orig_page;
} }
$screenshot = [get_theme_screenshot($theme), t('Screenshot')]; $screenshot = [Theme::getScreenshot($theme), t('Screenshot')];
if (!stristr($screenshot[0], $theme)) { if (!stristr($screenshot[0], $theme)) {
$screenshot = null; $screenshot = null;
} }
@ -2073,7 +2074,7 @@ function admin_page_themes(App $a)
'$plugin' => $theme, '$plugin' => $theme,
'$status' => $status, '$status' => $status,
'$action' => $action, '$action' => $action,
'$info' => get_theme_info($theme), '$info' => Theme::getInfo($theme),
'$function' => 'themes', '$function' => 'themes',
'$admin_form' => $admin_form, '$admin_form' => $admin_form,
'$str_author' => t('Author: '), '$str_author' => t('Author: '),
@ -2085,14 +2086,13 @@ function admin_page_themes(App $a)
]); ]);
} }
// reload active themes // reload active themes
if (x($_GET, "a") && $_GET['a'] == "r") { if (x($_GET, "a") && $_GET['a'] == "r") {
check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/themes', 'admin_themes', 't'); check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/themes', 'admin_themes', 't');
foreach ($themes as $th) { foreach ($themes as $th) {
if ($th['allowed']) { if ($th['allowed']) {
uninstall_theme($th['name']); Theme::uninstall($th['name']);
install_theme($th['name']); Theme::install($th['name']);
} }
} }
info("Themes reloaded"); info("Themes reloaded");
@ -2105,7 +2105,7 @@ function admin_page_themes(App $a)
$plugins = []; $plugins = [];
foreach ($themes as $th) { 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'); $t = get_markup_template('admin/plugins.tpl');

View file

@ -1,12 +1,13 @@
<?php <?php
use Friendica\App; use Friendica\App;
use Friendica\Core\Theme;
function pretheme_init(App $a) { function pretheme_init(App $a) {
if ($_REQUEST['theme']) { if ($_REQUEST['theme']) {
$theme = $_REQUEST['theme']; $theme = $_REQUEST['theme'];
$info = get_theme_info($theme); $info = Theme::getInfo($theme);
if ($info) { if ($info) {
// unfortunately there will be no translation for this string // unfortunately there will be no translation for this string
$desc = $info['description']; $desc = $info['description'];
@ -17,7 +18,7 @@ function pretheme_init(App $a) {
$version = ''; $version = '';
$credits = ''; $credits = '';
} }
echo json_encode(['img' => get_theme_screenshot($theme), 'desc' => $desc, 'version' => $version, 'credits' => $credits]); echo json_encode(['img' => Theme::getScreenshot($theme), 'desc' => $desc, 'version' => $version, 'credits' => $credits]);
} }
killme(); killme();

View file

@ -4,10 +4,9 @@
*/ */
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM;
require_once 'boot.php';
/** /**
* Some functions to handle themes * Some functions to handle themes
@ -30,7 +29,8 @@ class Theme
* @return array * @return array
*/ */
function get_theme_info($theme) { public static function getInfo($theme)
{
$info=[ $info=[
'name' => $theme, 'name' => $theme,
'description' => "", 'description' => "",
@ -61,7 +61,7 @@ class Theme
foreach ( $ll as $l ) { foreach ( $ll as $l ) {
$l = trim($l,"\t\n\r */"); $l = trim($l,"\t\n\r */");
if ($l != "") { if ($l != "") {
list($k,$v) = array_map("trim", explode(":",$l,2)); list($k, $v) = array_map("trim", explode(":", $l, 2));
$k= strtolower($k); $k= strtolower($k);
if ($k == "author") { if ($k == "author") {
@ -79,14 +79,12 @@ class Theme
$info['maintainer'][] = ['name'=>$v]; $info['maintainer'][] = ['name'=>$v];
} }
} else { } else {
if (array_key_exists($k,$info)) { if (array_key_exists($k, $info)) {
$info[$k]=$v; $info[$k] = $v;
} }
} }
} }
} }
} }
return $info; return $info;
} }
@ -99,7 +97,8 @@ class Theme
* @param sring $theme The name of the theme * @param sring $theme The name of the theme
* @return string * @return string
*/ */
function get_theme_screenshot($theme) { public static function getScreenshot($theme)
{
$exts = ['.png','.jpg']; $exts = ['.png','.jpg'];
foreach ($exts as $ext) { foreach ($exts as $ext) {
if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) { if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
@ -110,7 +109,8 @@ class Theme
} }
// install and uninstall theme // install and uninstall theme
function uninstall_theme($theme) { public static function uninstall($theme)
{
logger("Addons: uninstalling theme " . $theme); logger("Addons: uninstalling theme " . $theme);
include_once("view/theme/$theme/theme.php"); 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 // silently fail if theme was removed
if (! file_exists("view/theme/$theme/theme.php")) { if (! file_exists("view/theme/$theme/theme.php")) {
@ -153,7 +154,8 @@ class Theme
* @param string $root Full root path * @param string $root Full root path
* @return string Path to the file or empty string if the file isn't found * @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); $file = basename($file);
// Make sure $root ends with a slash / if it's not blank // Make sure $root ends with a slash / if it's not blank