Open Journal Systems  3.3.0
HelpHandler.inc.php
1 <?php
2 
16 import('classes.handler.Handler');
17 
18 class HelpHandler extends Handler {
22  function __construct() {
23  parent::__construct();
24  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
25  }
26 
32  function index($args, $request) {
33  $path = 'docs/manual/';
34  $urlPart = join('/', $request->getRequestedArgs());
35  $filename = $urlPart . '.md';
36 
38  $summaryFile = $path . $language . '/SUMMARY.md';
39 
40  // Default to English
41  if (!file_exists($path . $language) || !file_exists($summaryFile) || filesize($summaryFile)==0) $language = 'en';
42 
43  if (!preg_match('#^([[a-zA-Z0-9_-]+/)+[a-zA-Z0-9_-]+\.\w+$#', $filename) || !file_exists($path . $filename)) {
44  $request->redirect(null, null, null, array($language, 'SUMMARY'));
45  }
46 
47  // Use the summary document to find next/previous links.
48  // (Yes, we're grepping markdown outside the parser, but this is much faster.)
49  $previousLink = $nextLink = null;
50  if (preg_match_all('/\(([^)]+)\)/sm', file_get_contents($summaryFile), $matches)) {
51  $matches = $matches[1];
52  if (($i = array_search(substr($urlPart, strpos($urlPart, '/')+1), $matches)) !== false) {
53  if ($i>0) $previousLink = $matches[$i-1];
54  if ($i<count($matches)-1) $nextLink = $matches[$i+1];
55  }
56  }
57 
58  // Use a URL filter to prepend the current path to relative URLs.
59  $parser = new \Michelf\Markdown;
60  $parser->url_filter_func = function ($url) use ($filename) {
61  return (empty(parse_url($url)['host']) ? dirname($filename) . '/' : '') . $url;
62  };
63  return new JSONMessage(
64  true,
65  array(
66  'content' => $parser->transform(file_get_contents($path . $filename)),
67  'previous' => $previousLink,
68  'next' => $nextLink,
69  )
70  );
71  }
72 }
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
HelpHandler
Handle requests for help functions.
Definition: HelpHandler.inc.php:18
HelpHandler\__construct
__construct()
Definition: HelpHandler.inc.php:22
PKPLocale\getIso1FromLocale
static getIso1FromLocale($locale)
Definition: PKPLocale.inc.php:762
JSONMessage
Class to represent a JSON (Javascript Object Notation) message.
Definition: JSONMessage.inc.php:18
HelpHandler\index
index($args, $request)
Definition: HelpHandler.inc.php:32
Handler
Base request handler application class.
Definition: Handler.inc.php:18
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40