1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap |
4
|
|
|
{ |
5
|
|
|
public static $translator = null; |
6
|
|
|
|
7
|
16 |
|
protected function _initAutoload(): void |
8
|
|
|
{ |
9
|
|
|
// Add our own action helpers |
10
|
16 |
|
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/mQueue/Controller/ActionHelper', 'mQueue\\Controller\\ActionHelper\\'); |
11
|
16 |
|
} |
12
|
|
|
|
13
|
16 |
|
protected function _initDoctype(): void |
14
|
|
|
{ |
15
|
16 |
|
$this->bootstrap('view'); |
16
|
16 |
|
$view = $this->getResource('view'); |
17
|
|
|
|
18
|
|
|
// Enable our own View Helpers |
19
|
16 |
|
$view->addHelperPath(APPLICATION_PATH . '/mQueue/View/Helper', 'mQueue\\View\\Helper'); |
20
|
16 |
|
} |
21
|
|
|
|
22
|
16 |
|
protected function _initNavigation(): void |
23
|
|
|
{ |
24
|
16 |
|
$this->bootstrap('view'); |
25
|
16 |
|
$view = $this->getResource('view'); |
26
|
|
|
|
27
|
16 |
|
$navigation = new Zend_Navigation([ |
28
|
|
|
[ |
29
|
16 |
|
'label' => $view->translate('Movies'), |
30
|
16 |
|
'controller' => 'movie', |
31
|
16 |
|
'route' => 'default', |
32
|
|
|
'pages' => [ |
33
|
|
|
[ |
34
|
16 |
|
'label' => $view->translate('Add movie'), |
35
|
16 |
|
'controller' => 'movie', |
36
|
16 |
|
'action' => 'add', |
37
|
16 |
|
'route' => 'default', |
38
|
|
|
], |
39
|
|
|
[ |
40
|
16 |
|
'label' => $view->translate('Import votes from IMDb'), |
41
|
16 |
|
'controller' => 'movie', |
42
|
16 |
|
'action' => 'import', |
43
|
16 |
|
'route' => 'default', |
44
|
|
|
], |
45
|
|
|
], |
46
|
|
|
], |
47
|
|
|
[ |
48
|
16 |
|
'label' => $view->translate('Activity'), |
49
|
16 |
|
'controller' => 'activity', |
50
|
16 |
|
'route' => 'default', |
51
|
|
|
], |
52
|
|
|
[ |
53
|
16 |
|
'label' => $view->translate('Users'), |
54
|
16 |
|
'controller' => 'user', |
55
|
16 |
|
'route' => 'default', |
56
|
|
|
], |
57
|
|
|
[ |
58
|
16 |
|
'label' => $view->translate('FAQ'), |
59
|
16 |
|
'controller' => 'faq', |
60
|
16 |
|
'route' => 'default', |
61
|
|
|
], |
62
|
|
|
]); |
63
|
|
|
|
64
|
16 |
|
$view->navigation($navigation); |
65
|
16 |
|
} |
66
|
|
|
|
67
|
16 |
|
protected function _initSession(): void |
68
|
|
|
{ |
69
|
|
|
// We need to receive cookie from any third party sites, so we inject SameSite |
70
|
|
|
// into path, because PHP 7.2 does not have a way to do it properly |
71
|
16 |
|
$cookieParams = session_get_cookie_params(); |
72
|
16 |
|
session_set_cookie_params( |
73
|
16 |
|
$cookieParams['lifetime'], |
74
|
16 |
|
$cookieParams['path'] . '; SameSite=None', |
75
|
16 |
|
$cookieParams['domain'], |
76
|
16 |
|
true, |
77
|
16 |
|
true |
78
|
|
|
); |
79
|
|
|
|
80
|
16 |
|
Zend_Session::setOptions(['name' => 'mqueue']); |
81
|
|
|
|
82
|
16 |
|
if (!Zend_Session::sessionExists()) { |
83
|
|
|
Zend_Session::rememberMe(1 * 60 * 60 * 24 * 31 * 12); // Cookie for 1 year |
84
|
|
|
} |
85
|
16 |
|
} |
86
|
|
|
|
87
|
16 |
|
protected function _initLanguage(): void |
88
|
|
|
{ |
89
|
16 |
|
$session = new Zend_Session_Namespace(); |
90
|
|
|
|
91
|
|
|
// handle language switch |
92
|
16 |
|
if (isset($_GET['lang'])) { |
93
|
|
|
$session->locale = $_GET['lang']; |
94
|
|
|
} |
95
|
|
|
|
96
|
16 |
|
if (isset($session->locale)) { |
97
|
|
|
$locale = new Zend_Locale($session->locale); |
98
|
|
|
} else { |
99
|
16 |
|
$locale = new Zend_Locale(); // autodetect browser |
100
|
|
|
} |
101
|
16 |
|
Zend_Registry::set(Zend_Locale::class, $locale); |
102
|
|
|
|
103
|
16 |
|
$adapter = new Zend_Translate('gettext', APPLICATION_PATH . '/localization', $locale, ['scan' => Zend_Translate::LOCALE_FILENAME, 'disableNotices' => true]); |
104
|
16 |
|
Zend_Registry::set(Zend_Translate::class, $adapter); |
105
|
16 |
|
Zend_Form::setDefaultTranslator($adapter); |
106
|
16 |
|
self::$translator = $adapter; |
107
|
16 |
|
} |
108
|
|
|
|
109
|
16 |
|
protected function _initPagination(): void |
110
|
|
|
{ |
111
|
16 |
|
Zend_Paginator::setDefaultScrollingStyle('Elastic'); |
112
|
16 |
|
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); |
113
|
16 |
|
} |
114
|
|
|
|
115
|
16 |
|
protected function _initRoutes(): void |
116
|
|
|
{ |
117
|
16 |
|
$front = Zend_Controller_Front::getInstance(); |
118
|
16 |
|
$router = $front->getRouter(); |
119
|
|
|
|
120
|
|
|
// Required for unit tests |
121
|
16 |
|
$router->addDefaultRoutes(); |
|
|
|
|
122
|
|
|
|
123
|
|
|
// A route for single id (typically view a single movie/user) |
124
|
16 |
|
$router->addRoute('singleid', new Zend_Controller_Router_Route(':controller/:action/:id', ['action' => 'view'])); |
|
|
|
|
125
|
|
|
|
126
|
|
|
// A route for activities |
127
|
16 |
|
$router->addRoute('activity', new Zend_Controller_Router_Route('activity/*', ['controller' => 'activity', 'action' => 'index'])); |
128
|
16 |
|
$router->addRoute('activityMovie', new Zend_Controller_Router_Route('activity/movie/:movie/*', ['controller' => 'activity', 'action' => 'index'])); |
129
|
16 |
|
$router->addRoute('activityUser', new Zend_Controller_Router_Route('activity/user/:user/*', ['controller' => 'activity', 'action' => 'index'])); |
130
|
|
|
|
131
|
|
|
// For backward compatibility with RSS readers we keep the old route |
132
|
16 |
|
$router->addRoute('activityOld', new Zend_Controller_Router_Route('activity/index/*', ['controller' => 'activity', 'action' => 'index'])); |
133
|
16 |
|
$router->addRoute('activityMovieOld', new Zend_Controller_Router_Route('activity/index/movie/:movie/*', ['controller' => 'activity', 'action' => 'index'])); |
134
|
16 |
|
$router->addRoute('activityUserOld', new Zend_Controller_Router_Route('activity/index/user/:user/*', ['controller' => 'activity', 'action' => 'index'])); |
135
|
|
|
|
136
|
|
|
// Routes to define and view statuses |
137
|
16 |
|
$router->addRoute('status', new Zend_Controller_Router_Route_Regex('status/(\d+)/(\d)', ['controller' => 'status', 'action' => 'index'], [1 => 'movie', 2 => 'rating'], 'status/%s/%s')); |
138
|
16 |
|
$router->addRoute('statusView', new Zend_Controller_Router_Route_Regex('status/(\d+)', ['controller' => 'status', 'action' => 'index'], [1 => 'movie'], 'status/%s')); |
139
|
16 |
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Add the Zend_Db_Adapter to the registry if we need to call it outside of the modules. |
143
|
|
|
* |
144
|
|
|
* @return Zend_Db_Adapter_Abstract |
145
|
|
|
*/ |
146
|
16 |
|
protected function _initMyDb() |
147
|
|
|
{ |
148
|
16 |
|
$db = $this->getPluginResource('db')->getDbAdapter(); |
|
|
|
|
149
|
16 |
|
Zend_Registry::set('db', $db); |
150
|
|
|
|
151
|
16 |
|
return $db; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Global shortcut method that returns localized strings |
157
|
|
|
* |
158
|
|
|
* @param string $msgId the original string to translate |
159
|
|
|
* |
160
|
|
|
* @return string the translated string |
161
|
|
|
*/ |
162
|
|
|
function _tr($msgId) |
163
|
|
|
{ |
164
|
12 |
|
return Bootstrap::$translator->translate($msgId); |
165
|
|
|
} |
166
|
|
|
|