From df9b780706eec9ff67e97803f5f70b475b010281 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 6 Oct 2009 15:29:22 -0400 Subject: action/doc.php is PHPCS clean --- actions/doc.php | 61 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'actions/doc.php') diff --git a/actions/doc.php b/actions/doc.php index 836f039d3..5df18a859 100644 --- a/actions/doc.php +++ b/actions/doc.php @@ -49,7 +49,7 @@ class DocAction extends Action var $title; /** - * Class handler. + * Handle a request * * @param array $args array of arguments * @@ -71,6 +71,7 @@ class DocAction extends Action } $c = file_get_contents($this->filename); + $this->output = common_markup_to_html($c); Event::handle('EndLoadDoc', array($this->title, &$this->output)); @@ -79,30 +80,48 @@ class DocAction extends Action $this->showPage(); } - // overrrided to add entry-title class - function showPageTitle() { + /** + * Page title + * + * Gives the page title of the document. Override default for hAtom entry. + * + * @return void + */ + + function showPageTitle() + { $this->element('h1', array('class' => 'entry-title'), $this->title()); } - // overrided to add hentry, and content-inner classes + /** + * Block for content. + * + * Overrides default from Action to wrap everything in an hAtom entry. + * + * @return void. + */ + function showContentBlock() - { - $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); - $this->showPageTitle(); - $this->showPageNoticeBlock(); - $this->elementStart('div', array('id' => 'content_inner', - 'class' => 'entry-content')); - // show the actual content (forms, lists, whatever) - $this->showContent(); - $this->elementEnd('div'); - $this->elementEnd('div'); - } + { + $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); + $this->showPageTitle(); + $this->showPageNoticeBlock(); + $this->elementStart('div', array('id' => 'content_inner', + 'class' => 'entry-content')); + // show the actual content (forms, lists, whatever) + $this->showContent(); + $this->elementEnd('div'); + $this->elementEnd('div'); + } /** * Display content. * - * @return nothing + * Shows the content of the document. + * + * @return void */ + function showContent() { $this->raw($this->output); @@ -111,6 +130,8 @@ class DocAction extends Action /** * Page title. * + * Uses the title of the document. + * * @return page title */ function title() @@ -118,6 +139,14 @@ class DocAction extends Action return ucfirst($this->title); } + /** + * These pages are read-only. + * + * @param array $args unused. + * + * @return boolean read-only flag (false) + */ + function isReadOnly($args) { return true; -- cgit v1.2.3-54-g00ecf From 9f815c968f855b75e82224d85314007ec0613aad Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 7 Oct 2009 05:14:25 -0400 Subject: restructure doc.php for new use --- actions/doc.php | 75 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 21 deletions(-) (limited to 'actions/doc.php') 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 + } } -- cgit v1.2.3-54-g00ecf From 104d300799c0817bdbe893f08fd9b46d37a75a80 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 Jan 2010 14:13:28 -0500 Subject: do actual language negotiation for help docs --- actions/doc.php | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'actions/doc.php') diff --git a/actions/doc.php b/actions/doc.php index 99c2c7966..25d363472 100644 --- a/actions/doc.php +++ b/actions/doc.php @@ -51,6 +51,8 @@ class DocAction extends Action function prepare($args) { + parent::prepare($args); + $this->title = $this->trimmed('title'); $this->output = null; @@ -163,25 +165,41 @@ class DocAction extends Action function getFilename() { - $local = array_merge(glob(INSTALLDIR.'/local/doc-src/'.$this->title), - glob(INSTALLDIR.'/local/doc-src/'.$this->title.'.*')); + if (file_exists(INSTALLDIR.'/local/doc-src/'.$this->title)) { + $localDef = INSTALLDIR.'/local/doc-src/'.$this->title; + } + + $local = glob(INSTALLDIR.'/local/doc-src/'.$this->title.'.*'); + + if (count($local) || isset($localDef)) { + return $this->negotiateLanguage($local, $localDef); + } - if (count($local)) { - return $this->negotiateLanguage($local); + if (file_exists(INSTALLDIR.'/doc-src/'.$this->title)) { + $distDef = INSTALLDIR.'/doc-src/'.$this->title; } - $dist = array_merge(glob(INSTALLDIR.'/doc-src/'.$this->title), - glob(INSTALLDIR.'/doc-src/'.$this->title.'.*')); + $dist = glob(INSTALLDIR.'/doc-src/'.$this->title.'.*'); - if (count($dist)) { - return $this->negotiateLanguage($dist); + if (count($dist) || isset($distDef)) { + return $this->negotiateLanguage($dist, $distDef); } return null; } - function negotiateLanguage($files) + function negotiateLanguage($filenames, $defaultFilename=null) { - // FIXME: write this + // XXX: do this better + + $langcode = common_language(); + + foreach ($filenames as $filename) { + if (preg_match('/\.'.$langcode.'$/', $filename)) { + return $filename; + } + } + + return $defaultFilename; } } -- cgit v1.2.3-54-g00ecf