@@ -16,164 +16,208 @@ public function preDispatch()
16
16
parent ::preDispatch ();
17
17
$ this ->view ->setEncoding ('iso-8859-1 ' );
18
18
19
- $ fc= Zend_Controller_Front::getInstance ();
20
- $ module= $ fc ->getRequest ()->getModuleName ();
21
- if ($ module== 'default ' )
19
+ $ fc = Zend_Controller_Front::getInstance ();
20
+ $ module = $ fc ->getRequest ()->getModuleName ();
21
+ if ($ module == 'default ' )
22
22
{
23
- $ module= 'core ' ;
23
+ $ module = 'core ' ;
24
24
}
25
- $ this ->getLogger ()->setEventItem ('module ' ,$ module );
26
- $ this ->view ->webroot = $ fc ->getBaseUrl ();
27
- $ this ->coreWebroot = $ this ->view ->webroot .'/core ' ;
28
- $ this ->view ->coreWebroot = $ this ->coreWebroot ;
25
+ $ this ->getLogger ()->setEventItem ('module ' , $ module );
26
+ $ this ->view ->webroot = $ fc ->getBaseUrl ();
27
+ $ this ->coreWebroot = $ this ->view ->webroot .'/core ' ;
28
+ $ this ->view ->coreWebroot = $ this ->coreWebroot ;
29
29
30
- $ this ->view ->title = Zend_Registry::get ('configGlobal ' )->application ->name ;
30
+ $ this ->view ->title = Zend_Registry::get ('configGlobal ' )->application ->name ;
31
31
32
32
// Set the version
33
- $ this ->view ->version = '3.0.0 ' ;
33
+ $ this ->view ->version = '3.0.0 ' ;
34
34
if (isset (Zend_Registry::get ('configDatabase ' )->version ))
35
35
{
36
- $ this ->view ->version = Zend_Registry::get ('configDatabase ' )->version ;
36
+ $ this ->view ->version = Zend_Registry::get ('configDatabase ' )->version ;
37
37
}
38
-
38
+
39
39
require_once BASE_PATH . '/core/models/dao/UserDao.php ' ;
40
40
require_once BASE_PATH . '/core/models/dao/ItemDao.php ' ;
41
41
//Init Session
42
- if ($ fc ->getRequest ()->getActionName ()!= 'login ' || $ fc ->getRequest ()->getControllerName ()!= 'user ' )
42
+ if ($ fc ->getRequest ()->getActionName () != 'login ' || $ fc ->getRequest ()->getControllerName () != 'user ' )
43
43
{
44
-
45
-
46
- if (isset ($ _POST ['sid ' ]))
44
+ if (isset ($ _POST ['sid ' ]))
47
45
{
48
46
Zend_Session::setId ($ _POST ['sid ' ]);
49
47
}
50
48
Zend_Session::start ();
51
- $ user= new Zend_Session_Namespace ('Auth_User ' );
52
- $ user ->setExpirationSeconds (60 * Zend_Registry::get ('configGlobal ' )->session ->lifetime );
53
- $ this ->userSession = $ user ;
54
- $ this ->view ->recentItems = array ();
55
- if ($ user ->Dao != null )
49
+ $ user = new Zend_Session_Namespace ('Auth_User ' );
50
+ $ user ->setExpirationSeconds (60 * Zend_Registry::get ('configGlobal ' )->session ->lifetime );
51
+ $ this ->userSession = $ user ;
52
+ $ this ->view ->recentItems = array ();
53
+ if ($ user ->Dao != null )
56
54
{
57
- $ this ->logged =true ;
58
- $ this ->view ->logged =true ;
59
- $ user ->Dao ->lastAction =date ('c ' );
60
- $ this ->view ->userDao =$ user ->Dao ;
61
- $ cookieData = $ this ->getRequest ()->getCookie ('recentItems ' .$ this ->userSession ->Dao ->user_id );
62
- $ this ->view ->recentItems =array ();
55
+ if ($ fc ->getRequest ()->getControllerName () != 'install ' && $ fc ->getRequest ()->getControllerName () != 'error ' && $ user ->Dao ->isAdmin () && $ this ->isUpgradeNeeded ())
56
+ {
57
+ $ this ->view ->needUpgrade = true ;
58
+ }
59
+ else
60
+ {
61
+ $ this ->view ->needUpgrade = false ;
62
+ }
63
+ $ this ->logged = true ;
64
+ $ this ->view ->logged = true ;
65
+ $ user ->Dao ->lastAction = date ('c ' );
66
+ $ this ->view ->userDao = $ user ->Dao ;
67
+ $ cookieData = $ this ->getRequest ()->getCookie ('recentItems ' .$ this ->userSession ->Dao ->user_id );
68
+ $ this ->view ->recentItems = array ();
63
69
if (isset ($ cookieData ))
64
70
{
65
- $ this ->view ->recentItems = unserialize ($ cookieData );
66
- $ check= $ this ->_getParam ('checkRecentItem ' );
71
+ $ this ->view ->recentItems = unserialize ($ cookieData );
72
+ $ check = $ this ->_getParam ('checkRecentItem ' );
67
73
// check if recent items exit (every 10 minutes)
68
- if (isset ($ check )|| strtotime ($ user ->Dao ->lastAction )< strtotime ("-1 minute " ))
74
+ if (isset ($ check ) || strtotime ($ user ->Dao ->lastAction ) < strtotime ("-1 minute " ))
69
75
{
70
76
$ modelLoad = new MIDAS_ModelLoader ();
71
77
$ itemModel = $ modelLoad ->loadModel ('Item ' );
72
- foreach ($ this ->view ->recentItems as $ key => $ t )
78
+ foreach ($ this ->view ->recentItems as $ key => $ t )
73
79
{
74
80
if (!is_array ($ t ))
75
81
{
76
82
unset($ this ->view ->recentItems [$ key ]);
77
83
continue ;
78
84
}
79
- $ item= $ itemModel ->load ($ t ['item_id ' ]);
80
- if ($ item== false )
85
+ $ item = $ itemModel ->load ($ t ['item_id ' ]);
86
+ if ($ item == false )
81
87
{
82
88
unset($ this ->view ->recentItems [$ key ]);
83
89
}
84
90
}
85
- setcookie ('recentItems ' .$ this ->userSession ->Dao ->getKey (), serialize ($ this ->view ->recentItems ), time ()+ 60 * 60 * 24 * 30 ,'/ ' ); //30 days
91
+ setcookie ('recentItems ' .$ this ->userSession ->Dao ->getKey (), serialize ($ this ->view ->recentItems ), time () + 60 * 60 * 24 * 30 , '/ ' ); //30 days
86
92
}
87
93
}
88
94
}
89
95
else
90
96
{
91
- $ this ->view ->logged = false ;
92
- $ this ->logged = false ;
97
+ $ this ->view ->logged = false ;
98
+ $ this ->logged = false ;
93
99
}
94
100
}
95
101
else
96
102
{
97
- $ this ->userSession = null ;
98
- $ this ->view ->logged = false ;
99
- $ this ->logged = false ;
103
+ $ this ->userSession = null ;
104
+ $ this ->view ->logged = false ;
105
+ $ this ->logged = false ;
100
106
}
101
107
102
- $ this ->view ->lang = Zend_Registry::get ('configGlobal ' )->application ->lang ;
108
+ $ this ->view ->lang = Zend_Registry::get ('configGlobal ' )->application ->lang ;
103
109
//create a global javascript json array
104
- $ jsonGlobal =array (
105
- "webroot " =>$ this ->view ->webroot ,
106
- "coreWebroot " =>$ this ->view ->coreWebroot ,
107
- "logged " =>$ this ->logged ,
108
- "needToLog " =>false ,
109
- "currentUri " =>$ this ->getRequest ()->REQUEST_URI ,
110
- "lang " =>Zend_Registry::get ('configGlobal ' )->application ->lang ,
111
- "Yes " =>$ this ->t ('Yes ' ),
112
- "No " =>$ this ->t ('No ' )
113
- );
110
+ $ jsonGlobal = array (
111
+ "webroot " => $ this ->view ->webroot ,
112
+ "coreWebroot " => $ this ->view ->coreWebroot ,
113
+ "logged " => $ this ->logged ,
114
+ "needToLog " => false ,
115
+ "currentUri " => $ this ->getRequest ()->REQUEST_URI ,
116
+ "lang " => Zend_Registry::get ('configGlobal ' )->application ->lang ,
117
+ "Yes " => $ this ->t ('Yes ' ),
118
+ "No " => $ this ->t ('No ' ));
114
119
115
120
116
- $ login =array (
117
- "titleUploadLogin " =>$ this ->t ('Please log in ' ),
118
- "contentUploadLogin " =>$ this ->t ('You need to be logged in to be able to upload files. ' )
119
- );
121
+ $ login = array (
122
+ "titleUploadLogin " => $ this ->t ('Please log in ' ),
123
+ "contentUploadLogin " => $ this ->t ('You need to be logged in to be able to upload files. ' ));
120
124
121
- $ browse= array (
122
- 'view ' => $ this ->t ('View ' ),
123
- 'uploadIn ' => $ this ->t ('Upload here ' ),
124
- 'createFolder ' => $ this ->t ('Create a new Folder ' ),
125
- 'preview ' => $ this ->t ('Preview ' ),
126
- 'download ' => $ this ->t ('Download ' ),
127
- 'downloadLastest ' => $ this ->t ('Download lastest revision ' ),
128
- 'manage ' => $ this ->t ('Manage ' ),
129
- 'edit ' => $ this ->t ('Edit ' ),
130
- 'delete ' => $ this ->t ('Delete ' ),
131
- 'removeItem ' => $ this ->t ('Remove Item from Folder ' ),
132
- 'deleteMessage ' => $ this ->t ('Do you really want to delete the folder ' ),
133
- 'removeMessage ' => $ this ->t ('Do you really want to remove the item ' ),
134
- 'share ' => $ this ->t ('Sharing settings ' ),
135
- 'rename ' => $ this ->t ('Rename ' ),
136
- 'move ' => $ this ->t ('Move ' ),
137
- 'copy ' => $ this ->t ('Copy ' ),
138
- 'element ' => $ this ->t ('element ' ),
125
+ $ browse = array (
126
+ 'view ' => $ this ->t ('View ' ),
127
+ 'uploadIn ' => $ this ->t ('Upload here ' ),
128
+ 'createFolder ' => $ this ->t ('Create a new Folder ' ),
129
+ 'preview ' => $ this ->t ('Preview ' ),
130
+ 'download ' => $ this ->t ('Download ' ),
131
+ 'downloadLastest ' => $ this ->t ('Download lastest revision ' ),
132
+ 'manage ' => $ this ->t ('Manage ' ),
133
+ 'edit ' => $ this ->t ('Edit ' ),
134
+ 'delete ' => $ this ->t ('Delete ' ),
135
+ 'removeItem ' => $ this ->t ('Remove Item from Folder ' ),
136
+ 'deleteMessage ' => $ this ->t ('Do you really want to delete the folder ' ),
137
+ 'removeMessage ' => $ this ->t ('Do you really want to remove the item ' ),
138
+ 'share ' => $ this ->t ('Sharing settings ' ),
139
+ 'rename ' => $ this ->t ('Rename ' ),
140
+ 'move ' => $ this ->t ('Move ' ),
141
+ 'copy ' => $ this ->t ('Copy ' ),
142
+ 'element ' => $ this ->t ('element ' ),
139
143
'community ' => array (
140
- 'invit ' =>$ this ->t ('Invite collaborators ' ),
141
- 'advanced ' =>$ this ->t ('Advanced properties ' ),
142
- )
143
- );
144
+ 'invit ' => $ this ->t ('Invite collaborators ' ),
145
+ 'advanced ' => $ this ->t ('Advanced properties ' )));
144
146
145
- $ feed =array (
146
- "deleteFeed " =>$ this ->t ('Do you really want to delete the feed ' )
147
- );
147
+ $ feed = array (
148
+ "deleteFeed " => $ this ->t ('Do you really want to delete the feed ' ));
148
149
149
- $ this ->view ->json =array (
150
- "global " =>$ jsonGlobal ,"login " =>$ login ,'feed ' =>$ feed ,"browse " =>$ browse
151
- );
152
- Zend_Loader::loadClass ("JsonComponent " ,BASE_PATH .'/core/controllers/components ' );
150
+ $ this ->view ->json = array (
151
+ "global " => $ jsonGlobal , "login " => $ login , 'feed ' => $ feed , "browse " => $ browse );
152
+ Zend_Loader::loadClass ("JsonComponent " , BASE_PATH .'/core/controllers/components ' );
153
153
} // end preDispatch()
154
154
155
+ /** get server's url */
156
+ function getServerURL ()
157
+ {
158
+ $ currentPort = "" ;
159
+ $ prefix = "http:// " ;
160
+
161
+ if ($ _SERVER ['SERVER_PORT ' ] != 80 && $ _SERVER ['SERVER_PORT ' ] != 443 )
162
+ {
163
+ $ currentPort = ": " .$ _SERVER ['SERVER_PORT ' ];
164
+ }
165
+ if ($ _SERVER ['SERVER_PORT ' ] == 443 || (isset ($ _SERVER ['HTTPS ' ]) && !empty ($ _SERVER ['HTTPS ' ])))
166
+ {
167
+ $ prefix = "https:// " ;
168
+ }
169
+ return $ prefix .$ _SERVER ['SERVER_NAME ' ].$ currentPort ;
170
+ }
171
+
172
+ /** check if midas needs to be upgraded */
173
+ public function isUpgradeNeeded ()
174
+ {
175
+ require_once BASE_PATH .'/core/controllers/components/UpgradeComponent.php ' ;
176
+ $ upgradeComponent = new UpgradeComponent ();
177
+ $ db = Zend_Registry::get ('dbAdapter ' );
178
+ $ dbtype = Zend_Registry::get ('configDatabase ' )->database ->adapter ;
179
+
180
+ $ upgradeComponent ->initUpgrade ('core ' , $ db , $ dbtype );
181
+ if ($ upgradeComponent ->getNewestVersion () != $ upgradeComponent ->transformVersionToNumeric (Zend_Registry::get ('configDatabase ' )->version ))
182
+ {
183
+ return true ;
184
+ }
185
+ $ modules = array ();
186
+ $ modulesConfig = Zend_Registry::get ('configsModules ' );
187
+ foreach ($ modulesConfig as $ key => $ module )
188
+ {
189
+ $ upgradeComponent ->initUpgrade ($ key , $ db , $ dbtype );
190
+ if ($ upgradeComponent ->getNewestVersion () != 0 && $ upgradeComponent ->getNewestVersion () != $ upgradeComponent ->transformVersionToNumeric ($ module ->version ))
191
+ {
192
+ return true ;
193
+ }
194
+ }
195
+ return false ;
196
+ }
155
197
198
+ /** zend post dispatch*/
156
199
public function postDispatch ()
157
200
{
158
201
parent ::postDispatch ();
159
- $ this ->view ->json = JsonComponent::encode ($ this ->view ->json );
160
- $ this ->view ->generatedTimer = round ((microtime (true ) - START_TIME ),3 );
161
- if (Zend_Registry::get ('config ' )->mode ->test != 1 )
202
+ $ this ->view ->json = JsonComponent::encode ($ this ->view ->json );
203
+ $ this ->view ->generatedTimer = round ((microtime (true ) - START_TIME ), 3 );
204
+ if (Zend_Registry::get ('config ' )->mode ->test != 1 )
162
205
{
163
206
header ('Content-Type: text/html; charset=ISO-8859-1 ' );
164
207
}
165
208
}
166
209
210
+ /** trigger logging (javascript) */
167
211
public function haveToBeLogged ()
168
212
{
169
- $ this ->view ->header = $ this ->t ("You should be logged to access this page " );
170
- $ this ->view ->json ['global ' ]['needToLog ' ]= true ;
213
+ $ this ->view ->header = $ this ->t ("You should be logged to access this page " );
214
+ $ this ->view ->json ['global ' ]['needToLog ' ] = true ;
171
215
$ this ->_helper ->viewRenderer ->setNoRender ();
172
216
}
173
217
/** translation */
174
218
protected function t ($ text )
175
219
{
176
- Zend_Loader::loadClass ("InternationalizationComponent " ,BASE_PATH .'/core/controllers/components ' );
220
+ Zend_Loader::loadClass ("InternationalizationComponent " , BASE_PATH .'/core/controllers/components ' );
177
221
return InternationalizationComponent::translate ($ text );
178
222
} //end method t
179
223
@@ -265,7 +309,4 @@ protected function t($text)
265
309
var $ User ;
266
310
267
311
/**end completion eclipse */
268
- }
269
-
270
- //end class
271
- ?>
312
+ }//end class
0 commit comments