summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-10-07 05:14:25 -0400
committerEvan Prodromou <evan@status.net>2010-01-22 13:53:53 -0500
commit9f815c968f855b75e82224d85314007ec0613aad (patch)
treedd6434b76a24b4900a791aa6953c5ebcb90b6f41
parentdf9b780706eec9ff67e97803f5f70b475b010281 (diff)
restructure doc.php for new use
-rw-r--r--actions/doc.php75
1 files changed, 54 insertions, 21 deletions
diff --git a/actions/doc.php b/actions/doc.php
index 5df18a859..99c2c7966 100644
--- a/actions/doc.php
+++ b/actions/doc.php
@@ -45,8 +45,18 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
*/
class DocAction extends Action
{
- var $filename;
- var $title;
+ var $output = null;
+ var $filename = null;
+ var $title = null;
+
+ function prepare($args)
+ {
+ $this->title = $this->trimmed('title');
+ $this->output = null;
+
+ $this->loadDoc();
+ return true;
+ }
/**
* Handle a request
@@ -58,25 +68,6 @@ class DocAction extends Action
function handle($args)
{
parent::handle($args);
-
- $this->title = $this->trimmed('title');
- $this->output = null;
-
- if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
-
- $this->filename = INSTALLDIR.'/doc-src/'.$this->title;
- if (!file_exists($this->filename)) {
- $this->clientError(_('No such document.'));
- return;
- }
-
- $c = file_get_contents($this->filename);
-
- $this->output = common_markup_to_html($c);
-
- Event::handle('EndLoadDoc', array($this->title, &$this->output));
- }
-
$this->showPage();
}
@@ -151,4 +142,46 @@ class DocAction extends Action
{
return true;
}
+
+ function loadDoc()
+ {
+ if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
+
+ $this->filename = $this->getFilename();
+
+ if (empty($this->filename)) {
+ throw new ClientException(sprintf(_('No such document "%s"'), $this->title), 404);
+ }
+
+ $c = file_get_contents($this->filename);
+
+ $this->output = common_markup_to_html($c);
+
+ Event::handle('EndLoadDoc', array($this->title, &$this->output));
+ }
+ }
+
+ function getFilename()
+ {
+ $local = array_merge(glob(INSTALLDIR.'/local/doc-src/'.$this->title),
+ glob(INSTALLDIR.'/local/doc-src/'.$this->title.'.*'));
+
+ if (count($local)) {
+ return $this->negotiateLanguage($local);
+ }
+
+ $dist = array_merge(glob(INSTALLDIR.'/doc-src/'.$this->title),
+ glob(INSTALLDIR.'/doc-src/'.$this->title.'.*'));
+
+ if (count($dist)) {
+ return $this->negotiateLanguage($dist);
+ }
+
+ return null;
+ }
+
+ function negotiateLanguage($files)
+ {
+ // FIXME: write this
+ }
}