/
Default.php
218 lines (166 loc) · 6.54 KB
/
Default.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
class Core_View_Default extends Siberian_View
{
protected static $_application;
protected static $_acl;
protected static $_session = array();
protected static $_device;
protected static $_blocks;
public function __construct($config = array()) {
// $this->_session = new Core_Model_Session('front');
parent::__construct($config);
}
public function isProduction() {
return APPLICATION_ENV == 'production';
}
public function isSae() {
return Siberian_Version::TYPE == "SAE";
}
public function isMae() {
return Siberian_Version::TYPE == "MAE";
}
public function isPe() {
return Siberian_Version::TYPE == "PE";
}
public function getSession($type = null) {
if(is_null($type)) $type = SESSION_TYPE;
if(isset(self::$_session[$type])) {
return self::$_session[$type];
} else {
$session = new Core_Model_Session($type);
self::setSession($session, $type);
return $session;
}
}
public static function setSession($session, $type = 'front') {
self::$_session[$type] = $session;
}
public function getApplication() {
return Application_Model_Application::getInstance();
}
protected function _getAcl() {
return self::$_acl;
}
public static function setAcl($acl) {
self::$_acl = $acl;
}
protected function _canAccess($resource, $value_id = null) {
return self::_getAcl() ? self::_getAcl()->isAllowed($resource, $value_id) : true;
}
public function getDevice() {
return self::$_device;
}
public static function setDevice($device) {
self::$_device = $device;
}
public static function setBlocks($blocks) {
self::$_blocks = $blocks;
}
public function getBlocks() {
return self::$_blocks;
}
public function getBlock($code) {
foreach($this->getBlocks() as $block) {
if($block->getCode() == $code) return $block;
}
return new Template_Model_Block();
}
public function _($text) {
$args = func_get_args();
return Core_Model_Translator::translate($text, $args);
}
public function isHomePage() {
return $this->getRequest()->getParam('module') == 'Front' &&
$this->getRequest()->getParam('controller') == 'index' &&
$this->getRequest()->getParam('action') == 'index'
;
}
public function isMobileDevice() {
return DEVICE_TYPE == 'mobile';
}
public function getJs($name) {
return $this->getRequest()->getMediaUrl().'/app/design/' . APPLICATION_TYPE . '/' . DESIGN_CODE . '/js/' . $name;
}
public function getImagePath() {
return Core_Model_Directory::getDesignPath(false) . '/images';
}
public function getBaseImagePath() {
return Core_Model_Directory::getDesignPath(true) . '/images';
}
public function getImage($name, $base = false) {
if(file_exists($this->getBaseImagePath() . "/" . $name)) {
$path = $base ? $this->getBaseImagePath() : $this->getImagePath();
return $path."/".$name;
}
else if(file_exists(Media_Model_Library_Image::getBaseImagePathTo($name))) {
return $base ? Media_Model_Library_Image::getBaseImagePathTo($name) : Media_Model_Library_Image::getImagePathTo($name);
}
return "";
}
public function getColorizedImage($image_id, $color) {
$color = str_replace('#', '', $color);
$id = md5(implode('+', array($image_id, $color)));
$url = '';
$image = new Media_Model_Library_Image();
if(is_numeric($image_id)) {
$image->find($image_id);
if(!$image->getId()) return $url;
if(!$image->getCanBeColorized()) $color = null;
$path = $image->getLink();
$path = Media_Model_Library_Image::getBaseImagePathTo($path, $image->getAppId());
} else if(!Zend_Uri::check($image_id) AND stripos($image_id, Core_Model_Directory::getBasePathTo()) === false) {
$path = Core_Model_Directory::getBasePathTo($image_id);
} else {
$path = $image_id;
}
try {
$image = new Core_Model_Lib_Image();
$image->setId($id)
->setPath($path)
->setColor($color)
->colorize()
;
$url = $image->getUrl();
} catch(Exception $e) {
$url = '';
}
return $url;
}
public function getExternalUrl($path) {
if(!empty($path) AND substr($path, 0, 1) != "/") $path = "/".$path;
return Core_Model_Url::create()."external".$path;
}
public function getUrl($url = '', array $params = array(), $locale = null) {
return Core_Model_Url::create($url, $params, $locale);
}
public function getPath($uri = '', array $params = array(), $locale = null) {
return Core_Model_Url::createPath($uri, $params);
}
public function getBasePath($remove_app = false) {
$path_info = array_filter(explode("/", $this->getRequest()->getPathInfo()));
$request_uri = array_filter(explode("/", $this->getRequest()->getRequestUri()));
if($remove_app AND $this->getRequest()->isApplication() AND $this->getRequest()->useApplicationKey()) {
$path_info = array_diff($path_info, array(Application_Model_Application::OVERVIEW_PATH));
$request_uri = array_diff($request_uri, array(Application_Model_Application::OVERVIEW_PATH));
}
$base_path = array_diff($request_uri, $path_info);
$base_path = join("/", $base_path);
if(!empty($base_path) AND stripos($base_path, "/") !== 0) $base_path = "/$base_path";
return $base_path;
}
public function getCurrentUrl($withParams = true, $locale = null) {
return Core_Model_Url::current($withParams, $locale);
}
protected function _renderZendMenu($xml) {
$config = new Zend_Config_Xml($xml);
$this->navigation(new Zend_Navigation($config));
if(!$this->getPluginLoader('helper')->getPaths(Zend_View_Helper_Navigation::NS)) {
$this->addHelperPath('Zend/View/Helper/Navigation', 'Zend_View_Helper_Navigation');
}
if(!$this->getPluginLoader('helper')->getPaths('Siberian_View_Helper_Navigation')) {
$this->addHelperPath('Siberian/View/Helper/Navigation', 'Siberian_View_Helper_Navigation');
}
$nav = $this->navigation();
return $nav->menu();
}
}