3 * @file src/Core/Theme.php
\r
5 namespace Friendica\Core;
\r
8 use Friendica\Core\Config;
\r
9 use Friendica\Core\System;
\r
10 use Friendica\Database\DBM;
\r
13 * Some functions to handle themes
\r
18 * @brief Parse theme comment in search of theme infos.
\r
22 * ..* Name: My Theme
\r
23 * * Description: My Cool Theme
\r
24 * . * Version: 1.2.3
\r
25 * * Author: John <profile url>
\r
26 * * Maintainer: Jane <profile url>
\r
29 * @param string $theme the name of the theme
\r
33 function get_theme_info($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
95 * @brief Returns the theme's screenshot.
\r
97 * The screenshot is expected as view/theme/$theme/screenshot.[png|jpg].
\r
99 * @param sring $theme The name of the theme
\r
102 function get_theme_screenshot($theme) {
\r
103 $exts = ['.png','.jpg'];
\r
104 foreach ($exts as $ext) {
\r
105 if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
\r
106 return(System::baseUrl() . '/view/theme/' . $theme . '/screenshot' . $ext);
\r
109 return(System::baseUrl() . '/images/blank.png');
\r
112 // install and uninstall theme
\r
113 function uninstall_theme($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 function install_theme($theme) {
\r
124 // silently fail if theme was removed
\r
126 if (! file_exists("view/theme/$theme/theme.php")) {
\r
130 logger("Addons: installing theme $theme");
\r
132 include_once("view/theme/$theme/theme.php");
\r
134 if (function_exists("{$theme}_install")) {
\r
135 $func = "{$theme}_install";
\r
139 logger("Addons: FAILED installing theme $theme");
\r
146 * @brief Get the full path to relevant theme files by filename
\r
148 * This function search in the theme directory (and if not present in global theme directory)
\r
149 * if there is a directory with the file extension and for a file with the given
\r
152 * @param string $file Filename
\r
153 * @param string $root Full root path
\r
154 * @return string Path to the file or empty string if the file isn't found
\r
156 function theme_include($file, $root = '') {
\r
157 $file = basename($file);
\r
159 // Make sure $root ends with a slash / if it's not blank
\r
160 if ($root !== '' && $root[strlen($root)-1] !== '/') {
\r
161 $root = $root . '/';
\r
163 $theme_info = get_app()->theme_info;
\r
164 if (is_array($theme_info) && array_key_exists('extends',$theme_info)) {
\r
165 $parent = $theme_info['extends'];
\r
167 $parent = 'NOPATH';
\r
169 $theme = current_theme();
\r
171 $ext = substr($file,strrpos($file,'.')+1);
\r
173 "{$root}view/theme/$thname/$ext/$file",
\r
174 "{$root}view/theme/$parent/$ext/$file",
\r
175 "{$root}view/$ext/$file",
\r
177 foreach ($paths as $p) {
\r
178 // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)
\r
179 if (strpos($p,'NOPATH') !== false) {
\r
181 } elseif (file_exists($p)) {
\r