3 * @file src/Core/Theme.php
\r
5 namespace Friendica\Core;
\r
7 use Friendica\Core\System;
\r
9 require_once 'boot.php';
\r
12 * Some functions to handle themes
\r
17 * @brief Parse theme comment in search of theme infos.
\r
21 * ..* Name: My Theme
\r
22 * * Description: My Cool Theme
\r
23 * . * Version: 1.2.3
\r
24 * * Author: John <profile url>
\r
25 * * Maintainer: Jane <profile url>
\r
28 * @param string $theme the name of the theme
\r
32 public static function getInfo($theme)
\r
36 'description' => "",
\r
41 'experimental' => false,
\r
42 'unsupported' => false
\r
45 if (file_exists("view/theme/$theme/experimental"))
\r
46 $info['experimental'] = true;
\r
47 if (file_exists("view/theme/$theme/unsupported"))
\r
48 $info['unsupported'] = true;
\r
50 if (!is_file("view/theme/$theme/theme.php")) return $info;
\r
53 $stamp1 = microtime(true);
\r
54 $f = file_get_contents("view/theme/$theme/theme.php");
\r
55 $a->save_timestamp($stamp1, "file");
\r
57 $r = preg_match("|/\*.*\*/|msU", $f, $m);
\r
60 $ll = explode("\n", $m[0]);
\r
61 foreach ( $ll as $l ) {
\r
62 $l = trim($l,"\t\n\r */");
\r
64 list($k, $v) = array_map("trim", explode(":", $l, 2));
\r
66 if ($k == "author") {
\r
68 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
\r
70 $info['author'][] = ['name'=>$m[1], 'link'=>$m[2]];
\r
72 $info['author'][] = ['name'=>$v];
\r
74 } elseif ($k == "maintainer") {
\r
75 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
\r
77 $info['maintainer'][] = ['name'=>$m[1], 'link'=>$m[2]];
\r
79 $info['maintainer'][] = ['name'=>$v];
\r
82 if (array_key_exists($k, $info)) {
\r
93 * @brief Returns the theme's screenshot.
\r
95 * The screenshot is expected as view/theme/$theme/screenshot.[png|jpg].
\r
97 * @param sring $theme The name of the theme
\r
100 public static function getScreenshot($theme)
\r
102 $exts = ['.png','.jpg'];
\r
103 foreach ($exts as $ext) {
\r
104 if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
\r
105 return(System::baseUrl() . '/view/theme/' . $theme . '/screenshot' . $ext);
\r
108 return(System::baseUrl() . '/images/blank.png');
\r
111 // install and uninstall theme
\r
112 public static function uninstall($theme)
\r
114 logger("Addons: uninstalling theme " . $theme);
\r
116 include_once("view/theme/$theme/theme.php");
\r
117 if (function_exists("{$theme}_uninstall")) {
\r
118 $func = "{$theme}_uninstall";
\r
123 public static function install($theme)
\r
125 // silently fail if theme was removed
\r
127 if (! file_exists("view/theme/$theme/theme.php")) {
\r
131 logger("Addons: installing theme $theme");
\r
133 include_once("view/theme/$theme/theme.php");
\r
135 if (function_exists("{$theme}_install")) {
\r
136 $func = "{$theme}_install";
\r
140 logger("Addons: FAILED installing theme $theme");
\r
147 * @brief Get the full path to relevant theme files by filename
\r
149 * This function search in the theme directory (and if not present in global theme directory)
\r
150 * if there is a directory with the file extension and for a file with the given
\r
153 * @param string $file Filename
\r
154 * @param string $root Full root path
\r
155 * @return string Path to the file or empty string if the file isn't found
\r
157 public static function getPathForFile($file, $root = '')
\r
159 $file = basename($file);
\r
161 // Make sure $root ends with a slash / if it's not blank
\r
162 if ($root !== '' && $root[strlen($root)-1] !== '/') {
\r
163 $root = $root . '/';
\r
165 $theme_info = get_app()->theme_info;
\r
166 if (is_array($theme_info) && array_key_exists('extends',$theme_info)) {
\r
167 $parent = $theme_info['extends'];
\r
169 $parent = 'NOPATH';
\r
171 $theme = current_theme();
\r
173 $ext = substr($file,strrpos($file,'.')+1);
\r
175 "{$root}view/theme/$thname/$ext/$file",
\r
176 "{$root}view/theme/$parent/$ext/$file",
\r
177 "{$root}view/$ext/$file",
\r
179 foreach ($paths as $p) {
\r
180 // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)
\r
181 if (strpos($p,'NOPATH') !== false) {
\r
183 } elseif (file_exists($p)) {
\r