-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAssetComponent.php
More file actions
108 lines (98 loc) · 2.88 KB
/
AssetComponent.php
File metadata and controls
108 lines (98 loc) · 2.88 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* AssetComponent Component
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @author Takako Miyagawa <nekoget@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
/**
* Summary for AssetComponent Component
*/
class AssetComponent extends Component {
/**
* 何度も同じデータを取得しないようにキャッシュする
*
* @var bool
*/
private static $__theme = null;
/**
* cssの存在チェック
*
* @param Controller $controller controller object
* @return bool
*/
public function isThemeBootstrapMinCss(Controller $controller) {
$filePath = App::themePath($controller->theme) . 'webroot/css/bootstrap.min.css';
if (is_file(realpath($filePath))) {
return true;
}
return false;
}
/**
* サイトテーマの取得
*
* @param Controller $controller controller object
* @return mix null or array
*/
public function getSiteTheme(Controller $controller) {
if (self::$__theme) {
return self::$__theme;
}
$theme = null;
if (Current::read('Page.theme')) {
self::$__theme = Current::read('Page.theme');
return Current::read('Page.theme');
}
//@codeCoverageIgnoreStart
if (empty($controller->Page)) {
$controller->Page = ClassRegistry::init('Pages.Page');
}
//@codeCoverageIgnoreEnd
if (Current::read('Page.id')) {
$parentIds = $controller->Page->getPath(Current::read('Page.id'), array('id'));
$page = $controller->Page->find('first', array(
'recursive' => -1,
'fields' => array('theme'),
'conditions' => array('id' => Hash::extract($parentIds, '{n}.Page.id'), 'theme !=' => null),
//'order' => array('lft' => 'desc'),
'order' => array('sort_key' => 'desc'),
));
$theme = Hash::get($page, 'Page.theme');
if ($theme) {
self::$__theme = $theme;
return $theme;
}
}
if (! Current::read('Room.id')) {
$controller->SiteSetting = ClassRegistry::init('SiteManager.SiteSetting');
$theme = $controller->SiteSetting->getSiteTheme();
self::$__theme = $theme;
return $theme;
}
if (Current::read('Room.theme')) {
$theme = Current::read('Room.theme');
self::$__theme = $theme;
return $theme;
}
//@codeCoverageIgnoreStart
if (empty($controller->Room)) {
$controller->Room = ClassRegistry::init('Rooms.Room');
}
//@codeCoverageIgnoreEnd
$parentIds = $controller->Room->getPath(Current::read('Room.id'), array('id'));
$room = $controller->Room->find('first', array(
'recursive' => -1,
'fields' => array('theme'),
'conditions' => array('id' => Hash::extract($parentIds, '{n}.Room.id'), 'theme !=' => null),
//'order' => array('lft' => 'desc'),
'order' => array('sort_key' => 'desc'),
));
$theme = Hash::get($room, 'Room.theme');
self::$__theme = $theme;
return $theme;
}
}