]> git.mxchange.org Git - friendica.git/commitdiff
Update Theme functions and calls
authorAdam Magness <adam.magness@gmail.com>
Wed, 17 Jan 2018 18:52:25 +0000 (13:52 -0500)
committerAdam Magness <adam.magness@gmail.com>
Sat, 20 Jan 2018 12:48:22 +0000 (07:48 -0500)
Update function names and calls for Theme class.

index.php
mod/admin.php
mod/pretheme.php
src/Core/Theme.php

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