Daan is sweet to Kelley and delegates himself TestCMS code reflection
[ssproject1617.git] / testcms-final-anon / system / classes / themes.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 class Themes {
4
5 public static function list_all() {
6 $themes = array();
7
8 foreach(glob(PATH . 'themes/*') as $folder) {
9 $theme = basename($folder);
10
11 if($about = static::parse($theme)) {
12 $themes[$theme] = $about;
13 }
14 }
15
16 return $themes;
17 }
18
19 public static function parse($theme) {
20 $file = PATH . 'themes/' . $theme . '/about.txt';
21
22 if(file_exists($file) === false) {
23 return false;
24 }
25
26 // read file into a array
27 $contents = explode("\n", trim(file_get_contents($file)));
28 $about = array();
29
30 foreach(array('name', 'description', 'author', 'site', 'license') as $index => $key) {
31 // temp value
32 $about[$key] = '';
33
34 // find line if exists
35 if(!isset($contents[$index])) {
36 continue;
37 }
38
39 $line = $contents[$index];
40
41 // skip if not separated by a colon character
42 if(strpos($line, ":") === false) {
43 continue;
44 }
45
46 $parts = explode(":", $line);
47
48 // remove the key part
49 array_shift($parts);
50
51 // in case there was a colon in our value part glue it back together
52 $value = implode('', $parts);
53
54 $about[$key] = trim($value);
55 }
56
57 return $about;
58 }
59
60 }