1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
class ThemeSettings extends CiiSettingsModel
|
|
|
|
|
4
|
|
|
{
|
5
|
|
|
/**
|
6
|
|
|
* The active theme
|
7
|
|
|
* @var string
|
8
|
|
|
*/
|
9
|
|
|
public $theme = 'default';
|
10
|
|
|
|
11
|
|
|
/**
|
12
|
|
|
* Validation rules for the theme
|
13
|
|
|
* @return array
|
14
|
|
|
*/
|
15
|
|
|
public function rules()
|
16
|
|
|
{
|
17
|
|
|
return array(
|
18
|
|
|
array('theme', 'required'),
|
19
|
|
|
array('theme', 'length', 'max' => 255)
|
20
|
|
|
);
|
21
|
|
|
}
|
22
|
|
|
|
23
|
|
|
/**
|
24
|
|
|
* Attribute labels for themes
|
25
|
|
|
* @return array
|
26
|
|
|
*/
|
27
|
|
|
public function attributeLabels()
|
28
|
|
|
{
|
29
|
|
|
return array(
|
30
|
|
|
'theme' => Yii::t('ciims.models.theme', 'Theme'),
|
31
|
|
|
);
|
32
|
|
|
}
|
33
|
|
|
|
34
|
|
|
/**
|
35
|
|
|
* Returns the active theme name
|
36
|
|
|
* @return string
|
37
|
|
|
*/
|
38
|
|
|
public function getTheme()
|
39
|
|
|
{
|
40
|
|
|
return $this->theme;
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
/**
|
44
|
|
|
* Retrieves all of the themes from webroot.themes and returns them in an array group by type, each containing
|
45
|
|
|
* the contents of theme.json.
|
46
|
|
|
*
|
47
|
|
|
* The themes are then cached for easy retrieval later. (I really hate unecessary DiskIO if something isn't changing...)
|
48
|
|
|
*
|
49
|
|
|
* @return array
|
50
|
|
|
*/
|
51
|
|
|
public function getThemes()
|
52
|
|
|
{
|
53
|
|
|
$themes = Yii::app()->cache->get('settings_themes');
|
54
|
|
|
|
55
|
|
|
if ($themes == false)
|
56
|
|
|
{
|
57
|
|
|
$themes = array();
|
58
|
|
|
$currentTheme = Cii::getConfig('theme');
|
59
|
|
|
$themePath = Yii::getPathOfAlias('base.themes') . DS;
|
60
|
|
|
$directories = glob($themePath . "*", GLOB_ONLYDIR);
|
|
|
|
|
61
|
|
|
|
62
|
|
|
// Pushes the current theme onto the top of the list
|
63
|
|
|
foreach ($directories as $k=>$dir)
|
64
|
|
|
{
|
65
|
|
|
if ($dir == Yii::getPathOfAlias('base.themes').DS.$currentTheme)
|
66
|
|
|
{
|
67
|
|
|
unset($directories[$k]);
|
68
|
|
|
break;
|
69
|
|
|
}
|
70
|
|
|
}
|
71
|
|
|
|
72
|
|
|
array_unshift($directories, $themePath.$currentTheme);
|
73
|
|
|
|
74
|
|
|
foreach($directories as $dir)
|
75
|
|
|
{
|
76
|
|
|
$json = CJSON::decode(file_get_contents($dir . DIRECTORY_SEPARATOR . 'composer.json'));
|
77
|
|
|
$name = $json['name'];
|
78
|
|
|
$key = str_replace('ciims-themes/', '', $name);
|
79
|
|
|
|
80
|
|
|
$themes[$key] = array(
|
81
|
|
|
'path' => $dir,
|
82
|
|
|
'name' => $name,
|
83
|
|
|
'hidden' => isset($json['hidden']) ? $json['hidden'] : false
|
84
|
|
|
);
|
85
|
|
|
}
|
86
|
|
|
|
87
|
|
|
Yii::app()->cache->set('settings_themes', $themes);
|
88
|
|
|
return $themes;
|
89
|
|
|
}
|
90
|
|
|
|
91
|
|
|
return $themes;
|
92
|
|
|
}
|
93
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.