Open Journal Systems  3.3.0
ImportExportPlugin.inc.php
1 <?php
2 
16 import('lib.pkp.classes.plugins.Plugin');
17 
18 abstract class ImportExportPlugin extends Plugin {
20  var $_request;
21 
22 
28  abstract function executeCLI($scriptName, &$args);
29 
34  abstract function usage($scriptName);
35 
39  function getActions($request, $actionArgs) {
40  $dispatcher = $request->getDispatcher();
41  import('lib.pkp.classes.linkAction.request.RedirectAction');
42  return array_merge(
43  array(
44  new LinkAction(
45  'settings',
46  new RedirectAction($dispatcher->url(
47  $request, ROUTE_PAGE,
48  null, 'management', 'importexport', array('plugin', $this->getName())
49  )),
50  __('manager.importExport'),
51  null
52  ),
53  ),
54  parent::getActions($request, $actionArgs)
55  );
56  }
57 
63  function display($args, $request) {
64  $templateMgr = TemplateManager::getManager($request);
65  $templateMgr->registerPlugin('function', 'plugin_url', array($this, 'pluginUrl'));
66  $this->_request = $request; // Store this for use by the pluginUrl function
67  $templateMgr->assign([
68  'breadcrumbs' => [
69  [
70  'id' => 'tools',
71  'name' => __('navigation.tools'),
72  'url' => $request->getRouter()->url($request, null, 'management', 'tools'),
73  ],
74  [
75  'id' => $this->getPluginPath(),
76  'name' => $this->getDisplayName()
77  ],
78  ],
79  'pageTitle' => $this->getDisplayName(),
80  ]);
81  }
82 
90  function pluginUrl($params, $smarty) {
91  $dispatcher = $this->_request->getDispatcher();
92  return $dispatcher->url($this->_request, ROUTE_PAGE, null, 'management', 'importexport', array_merge(array('plugin', $this->getName(), isset($params['path'])?$params['path']:array())));
93  }
94 
100  function isRelativePath($url) {
101  // FIXME This is not very comprehensive, but will work for now.
102  if ($this->isAllowedMethod($url)) return false;
103  if ($url[0] == '/') return false;
104  return true;
105  }
106 
112  function isAllowedMethod($url) {
113  $allowedPrefixes = array(
114  'http://',
115  'ftp://',
116  'https://',
117  'ftps://'
118  );
119  foreach ($allowedPrefixes as $prefix) {
120  if (substr($url, 0, strlen($prefix)) === $prefix) return true;
121  }
122  return false;
123  }
124 
129  function getPluginSettingsPrefix() {
130  return '';
131  }
132 
137  function getExportPath() {
138  return Config::getVar('files', 'files_dir') . '/temp/';
139  }
140 
149  function getExportFileName($basePath, $objectsFileNamePart, $context, $extension = '.xml') {
150  return $basePath . $this->getPluginSettingsPrefix() . '-' . date('Ymd-His') .'-' . $objectsFileNamePart .'-' . $context->getId() . $extension;
151  }
152 
158  function displayXMLValidationErrors($errors, $xml) {
159  AppLocale::requireComponents(LOCALE_COMPONENT_APP_MANAGER, LOCALE_COMPONENT_PKP_MANAGER);
160  if (defined('SESSION_DISABLE_INIT')) {
161  echo __('plugins.importexport.common.validationErrors') . "\n";
162  foreach ($errors as $error) {
163  echo trim($error->message) . "\n";
164  }
165  libxml_clear_errors();
166  echo __('plugins.importexport.common.invalidXML') . "\n";
167  echo $xml . "\n";
168  } else {
169  $charset = Config::getVar('i18n', 'client_charset');
170  header('Content-type: text/html; charset=' . $charset);
171  echo '<html><body>';
172  echo '<h2>' . __('plugins.importexport.common.validationErrors') . '</h2>';
173  foreach ($errors as $error) {
174  echo '<p>' . trim($error->message) . '</p>';
175  }
176  libxml_clear_errors();
177  echo '<h3>' . __('plugins.importexport.common.invalidXML') . '</h3>';
178  echo '<p><pre>' . htmlspecialchars($xml) . '</pre></p>';
179  echo '</body></html>';
180  }
181  fatalError(__('plugins.importexport.common.error.validation'));
182  }
183 
184 }
185 
186 
ImportExportPlugin\getActions
getActions($request, $actionArgs)
Definition: ImportExportPlugin.inc.php:42
ImportExportPlugin\executeCLI
executeCLI($scriptName, &$args)
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
ImportExportPlugin\displayXMLValidationErrors
displayXMLValidationErrors($errors, $xml)
Definition: ImportExportPlugin.inc.php:161
ImportExportPlugin\usage
usage($scriptName)
Plugin\getName
getName()
ImportExportPlugin\isRelativePath
isRelativePath($url)
Definition: ImportExportPlugin.inc.php:103
ImportExportPlugin\display
display($args, $request)
Definition: ImportExportPlugin.inc.php:66
ImportExportPlugin
Abstract class for import/export plugins.
Definition: ImportExportPlugin.inc.php:18
ImportExportPlugin\isAllowedMethod
isAllowedMethod($url)
Definition: ImportExportPlugin.inc.php:115
ImportExportPlugin\getExportFileName
getExportFileName($basePath, $objectsFileNamePart, $context, $extension='.xml')
Definition: ImportExportPlugin.inc.php:152
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
ImportExportPlugin\pluginUrl
pluginUrl($params, $smarty)
Definition: ImportExportPlugin.inc.php:93
ImportExportPlugin\getExportPath
getExportPath()
Definition: ImportExportPlugin.inc.php:140
LinkAction
Base class defining an action that can be performed by the user in the user interface.
Definition: LinkAction.inc.php:22
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
RedirectAction
This action request redirects to another page.
Definition: RedirectAction.inc.php:18
ImportExportPlugin\getPluginSettingsPrefix
getPluginSettingsPrefix()
Definition: ImportExportPlugin.inc.php:132
ImportExportPlugin\$_request
$_request
Definition: ImportExportPlugin.inc.php:23
Plugin
Abstract class for plugins.
Definition: Plugin.inc.php:51
Plugin\$request
$request
Definition: Plugin.inc.php:68
fatalError
if(!function_exists('import')) fatalError($reason)
Definition: functions.inc.php:32