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