Open Journal Systems  3.3.0
PLNHandler.inc.php
1 <?php
2 
14 import('classes.handler.Handler');
15 class PLNHandler extends Handler {
21  public function index($args, $request) {
22  $request->redirect(null, 'index');
23  }
24 
28  public function authorize($request, &$args, $roleAssignments) {
29  import('lib.pkp.classes.security.authorization.ContextRequiredPolicy');
30  $this->addPolicy(new ContextRequiredPolicy($request));
31 
32  return parent::authorize($request, $args, $roleAssignments);
33  }
34 
42  public function deposits($args, $request) {
43  $journal = $request->getJournal();
44  $depositDao = DAORegistry::getDAO('DepositDAO');
45  $fileManager = new FileManager();
46  $dispatcher = $request->getDispatcher();
47 
48  $depositUuid = (!isset($args[0]) || empty($args[0])) ? null : $args[0];
49 
50  // sanitize the input
51  if (!preg_match('/^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/',$depositUuid)) {
52  error_log(__('plugins.generic.pln.error.handler.uuid.invalid'));
53  $dispatcher->handle404();
54  return false;
55  }
56 
57  $deposit = $depositDao->getByUUID($journal->getId(), $depositUuid);
58 
59  if (!$deposit) {
60  error_log(__('plugins.generic.pln.error.handler.uuid.notfound'));
61  $dispatcher->handle404();
62  return false;
63  }
64 
65  $depositPackage = new DepositPackage($deposit, null);
66  $depositBag = $depositPackage->getPackageFilePath();
67 
68  if (!$fileManager->fileExists($depositBag)) {
69  error_log('plugins.generic.pln.error.handler.file.notfound');
70  $dispatcher->handle404();
71  return false;
72  }
73 
74  return $fileManager->downloadByPath($depositBag, PKPString::mime_content_type($depositBag), true);
75  }
76 
82  public function status($args, $request) {
83  $router = $request->getRouter();
84  $plnPlugin = PluginRegistry::getPlugin('generic', PLN_PLUGIN_NAME);
85  $templateMgr = TemplateManager::getManager();
86  $templateMgr->assign('pageHierarchy', array(array($router->url($request, null, 'about'), 'about.aboutTheJournal')));
87  $templateMgr->display($plnPlugin->getTemplatePath() . DIRECTORY_SEPARATOR . 'status.tpl');
88  }
89 
90  //
91  // Protected helper methods
92  //
97  protected function _getPlugin() {
98  return PluginRegistry::getPlugin('generic', PLN_PLUGIN_NAME);
99  }
100 }
PLNHandler\deposits
deposits($args, $request)
Definition: PLNHandler.inc.php:42
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PLNHandler\status
status($args, $request)
Definition: PLNHandler.inc.php:82
PLNHandler\index
index($args, $request)
Definition: PLNHandler.inc.php:21
PLNHandler
Handle PLN requests.
Definition: PLNHandler.inc.php:15
PKPString\mime_content_type
static mime_content_type($filename, $suggestedExtension='')
Definition: PKPString.inc.php:312
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
PLNHandler\_getPlugin
_getPlugin()
Definition: PLNHandler.inc.php:97
DepositPackage
Represent a PLN deposit package.
Definition: DepositPackage.inc.php:17
PluginRegistry\getPlugin
static getPlugin($category, $name)
Definition: PluginRegistry.inc.php:85
PLNHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: PLNHandler.inc.php:28
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
FileManager
Class defining basic operations for file management.
Definition: FileManager.inc.php:35
Handler
Base request handler application class.
Definition: Handler.inc.php:18
ContextRequiredPolicy
Policy to deny access if a context cannot be found in the request.
Definition: ContextRequiredPolicy.inc.php:17