1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Helper |
5
|
|
|
* @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua) |
6
|
|
|
* @author Aleksandr Torosh <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Application\Mvc; |
10
|
|
|
|
11
|
|
|
use Application\Mvc\Router\DefaultRouter; |
12
|
|
|
use Cms\Model\Language; |
13
|
|
|
|
14
|
|
|
class Helper extends \Phalcon\Mvc\User\Component |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
private $translate = null; |
18
|
|
|
private $admin_translate = null; |
19
|
|
|
|
20
|
|
|
public $menu; |
21
|
|
|
|
22
|
|
|
public function __construct() |
23
|
|
|
{ |
24
|
|
|
$this->menu = \Menu\Helper\Menu::getInstance(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Мультиязычный перевод строки по сайту/пользовательской_части |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public function translate($string, $placeholders = null) |
31
|
|
|
{ |
32
|
|
|
if (!$this->translate) { |
33
|
|
|
$this->translate = $this->getDi()->get('translate'); |
34
|
|
|
} |
35
|
|
|
return $this->translate->query($string, $placeholders); |
36
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Мультиязычный перевод строки по админке |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function at($string, $placeholders = null) |
43
|
|
|
{ |
44
|
|
|
if (!$this->admin_translate) { |
45
|
|
|
$this->admin_translate = $this->getDi()->get('admin_translate'); |
46
|
|
|
} |
47
|
|
|
return $this->admin_translate->query($string, $placeholders); |
48
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function widget($namespace = 'Index', array $params = []) |
52
|
|
|
{ |
53
|
|
|
return new \Application\Widget\Proxy($namespace, $params); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Вызов выджета из модуля StaticWidget |
58
|
|
|
* @param $id - идентификатор виджета, например "phone" |
59
|
|
|
*/ |
60
|
|
|
public function staticWidget($id) |
61
|
|
|
{ |
62
|
|
|
$widget = \Widget\Model\Widget::findFirst(["id='{$id}'", "cache" => ["lifetime" => 120, "key" => HOST_HASH . md5("Widget::findFirst({$id})")]]); |
63
|
|
|
if ($widget) { |
64
|
|
|
return $widget->getHtml(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
public function langUrl($params) |
69
|
|
|
{ |
70
|
|
|
$routeName = $params['for']; |
71
|
|
|
$routeName = DefaultRouter::ML_PREFIX . $routeName . '_' . LANG; |
72
|
|
|
$params['for'] = $routeName; |
73
|
|
|
return $this->url->get($params); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function languages() |
77
|
|
|
{ |
78
|
|
|
return Language::findCachedLanguages(); |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function langSwitcher($lang, $string) |
83
|
|
|
{ |
84
|
|
|
$helper = new \Application\Mvc\Helper\LangSwitcher(); |
85
|
|
|
return $helper->render($lang, $string); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function cacheExpire($seconds) |
89
|
|
|
{ |
90
|
|
|
$response = $this->getDi()->get('response'); |
91
|
|
|
$expireDate = new \DateTime(); |
92
|
|
|
$expireDate->modify("+$seconds seconds"); |
93
|
|
|
$response->setExpires($expireDate); |
94
|
|
|
$response->setHeader('Cache-Control', "max-age=$seconds"); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function isAdminSession() |
98
|
|
|
{ |
99
|
|
|
$session = $this->getDi()->get('session'); |
100
|
|
|
$auth = $session->get('auth'); |
101
|
|
|
if ($auth) { |
102
|
|
|
if ($auth->admin_session == true) { |
103
|
|
|
return true; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function error($code = 404) |
109
|
|
|
{ |
110
|
|
|
$helper = new \Application\Mvc\Helper\ErrorReporting(); |
111
|
|
|
return $helper->{'error' . $code}(); |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function title($title = null, $h1 = false) |
116
|
|
|
{ |
117
|
|
|
return \Application\Mvc\Helper\Title::getInstance($title, $h1); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function meta() |
121
|
|
|
{ |
122
|
|
|
return \Application\Mvc\Helper\Meta::getInstance(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function activeMenu() |
126
|
|
|
{ |
127
|
|
|
return \Application\Mvc\Helper\ActiveMenu::getInstance(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function announce($incomeString, $num) |
131
|
|
|
{ |
132
|
|
|
$object = new \Application\Mvc\Helper\Announce(); |
133
|
|
|
return $object->getString($incomeString, $num); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function dbProfiler() |
137
|
|
|
{ |
138
|
|
|
$object = new \Application\Mvc\Helper\DbProfiler(); |
139
|
|
|
return $object->DbOutput(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function constant($name) |
143
|
|
|
{ |
144
|
|
|
return get_defined_constants()[$name]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function image($args, $attributes = []) |
148
|
|
|
{ |
149
|
|
|
$imageFilter = new \Image\Storage($args, $attributes); |
150
|
|
|
return $imageFilter; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function querySymbol() |
154
|
|
|
{ |
155
|
|
|
$object = new \Application\Mvc\Helper\RequestQuery(); |
156
|
|
|
return $object->getSymbol(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function javascript($id) |
160
|
|
|
{ |
161
|
|
|
$javascript = \Cms\Model\Javascript::findCachedById($id); |
162
|
|
|
if ($javascript) { |
163
|
|
|
return $javascript->getText(); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function modulePartial($template, $data, $module = null) |
168
|
|
|
{ |
169
|
|
|
$view = clone $this->getDi()->get('view'); |
170
|
|
|
$partialsDir = ''; |
171
|
|
|
if ($module) { |
172
|
|
|
$moduleName = \Application\Utils\ModuleName::camelize($module); |
173
|
|
|
$partialsDir = '../../../modules/' . $moduleName . '/views/'; |
174
|
|
|
} |
175
|
|
|
$view->setPartialsDir($partialsDir); |
176
|
|
|
|
177
|
|
|
return $view->partial($template, $data); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
} |
181
|
|
|
|