-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyOmekaControllerPlugin.php
59 lines (52 loc) · 2.06 KB
/
MyOmekaControllerPlugin.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
<?php
/**
*
*/
class MyOmekaControllerPlugin extends Zend_Controller_Plugin_Abstract
{
protected $_loginRequiredActions = array(
array('my-omeka', 'dashboard'),
array('my-omeka', 'index'),
array('poster', 'edit'),
array('poster', 'share'),
array('poster', 'delete-confirm'),
array('poster', 'delete'),
array('poster', 'save'),
array('poster', 'new'),
array('note', 'edit'),
array('tag', 'add'),
array('tag', 'delete'));
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$this->_preventAdminAccess($request);
// If we're in the MyOmeka plugin, force us to log in for most of the actions.
$this->_forceLogin($request);
}
protected function _forceLogin($request)
{
if ('my-omeka' == $request->getModuleName()) {
$user = Omeka_Context::getInstance()->getCurrentUser();
// If the user needs to login before accessing an action, then redirect to the login page.
if (!$user and in_array(array($request->getControllerName(), $request->getActionName()), $this->_loginRequiredActions)) {
// The following code piggybacks off the current (0.10)
// implementation of UsersController::loginAction(). May need
// to change in the future.
$session = new Zend_Session_Namespace;
$session->redirect = $request->getPathInfo();
$this->_getRedirect()->goto('login', 'users', 'default');
}
}
}
protected function _preventAdminAccess($request)
{
$user = Omeka_Context::getInstance()->getCurrentUser();
// If we're logged in, then prevent access to the admin for MyOmeka users
if ($user and $user->role == MYOMEKA_USER_ROLE and is_admin_theme()) {
exit;
}
}
protected function _getRedirect()
{
return Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
}
}