aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Theme_info.php
blob: 91ca484b768cc2600fabcba7529f958faeef5292 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

namespace Zotlabs\Module;


class Theme_info extends \Zotlabs\Web\Controller {

	function get() {
		$theme = argv(1);
		if(! $theme)
			killme();
		
		$schemalist = array();

		$theme_config = "";
		if(($themeconfigfile = $this->get_theme_config_file($theme)) != null){
			require_once($themeconfigfile);
			if(class_exists(ucfirst($theme) . 'Config')) {
				$clsname = ucfirst($theme) . 'Config';
				$th_config = new $clsname();
				$schemas = $th_config->get_schemas();
				if($schemas) {
					foreach($schemas as $k => $v) {
						$schemalist[] = [ 'key' => $k, 'val' => $v ];
					}
				}
				$theme_config = $th_config->get();
			}
		}
		$info = get_theme_info($theme);
		if($info) {
			// unfortunately there will be no translation for this string
			$desc    = $info['description'];
			$version = $info['version'];
			$credits = $info['credits'];
		}
		else {
			$desc = '';
			$version = '';
			$credits = '';
		}

		$ret = [ 
			'theme' => $theme, 
			'img' => get_theme_screenshot($theme), 
			'desc' => $desc, 
			'version' => $version, 
			'credits' => $credits, 
			'schemas' => $schemalist,
			'config' => $theme_config
		];
		json_return_and_die($ret);
		
	}


	function get_theme_config_file($theme){

		$base_theme = \App::$theme_info['extends'];
	
		if (file_exists("view/theme/$theme/php/config.php")){
			return "view/theme/$theme/php/config.php";
		} 
		if (file_exists("view/theme/$base_theme/php/config.php")){
			return "view/theme/$base_theme/php/config.php";
		}
		return null;
	}


}