X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fhtmloutputter.php;h=2ff9380cc15bc16183e738e084b8ab6628a31cb1;hb=be73757131127c687090f925ff873ff385a88604;hp=095f4d478673e306bb1664ec381de3c0311fa7d1;hpb=e1907c9cb5324f7349de814c09728a64be589f3a;p=quix0rs-gnu-social.git diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php index 095f4d4786..2ff9380cc1 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -1,6 +1,6 @@ . * * @category Output - * @package Laconica - * @author Evan Prodromou - * @author Sarven Capadisli - * @copyright 2008 Control Yourself, Inc. + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli + * @copyright 2008 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } @@ -47,11 +47,11 @@ define('PAGE_TYPE_PREFS', * HTML-creation class. * * @category Output - * @package Laconica - * @author Evan Prodromou - * @author Sarven Capadisli + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ * * @see Action * @see XMLOutputter @@ -101,27 +101,56 @@ class HTMLOutputter extends XMLOutputter $type = common_negotiate_type($cp, $sp); if (!$type) { - common_user_error(_('This page is not available in a '. - 'media type you accept'), 406); - exit(0); + throw new ClientException(_('This page is not available in a '. + 'media type you accept'), 406); } } - header('Content-Type: '.$type); + header('Content-Type: '.$type.'; charset=UTF-8'); - $this->startXML('html', - '-//W3C//DTD XHTML 1.0 Strict//EN', - 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); - - // FIXME: correct language for interface + $this->extraHeaders(); + if (preg_match("/.*\/.*xml/", $type)) { + // Required for XML documents + $this->xw->startDocument('1.0', 'UTF-8'); + } + $this->xw->writeDTD('html', + '-//W3C//DTD XHTML 1.0 Strict//EN', + 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); - $language = common_language(); + $language = $this->getLanguage(); $this->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => $language, 'lang' => $language)); } + function getLanguage() + { + // FIXME: correct language for interface + return common_language(); + } + + /** + * Ends an HTML document + * + * @return void + */ + function endHTML() + { + $this->elementEnd('html'); + $this->endXML(); + } + + /** + * To specify additional HTTP headers for the action + * + * @return void + */ + function extraHeaders() + { + // Needs to be overloaded + } + /** * Output an HTML text input element * @@ -144,20 +173,17 @@ class HTMLOutputter extends XMLOutputter function input($id, $label, $value=null, $instructions=null) { - $this->elementStart('p'); $this->element('label', array('for' => $id), $label); $attrs = array('name' => $id, 'type' => 'text', - 'class' => 'input_text', 'id' => $id); if ($value) { - $attrs['value'] = htmlspecialchars($value); + $attrs['value'] = $value; } $this->element('input', $attrs); if ($instructions) { - $this->element('span', 'input_instructions', $instructions); + $this->element('p', 'form_guide', $instructions); } - $this->elementEnd('p'); } /** @@ -181,13 +207,12 @@ class HTMLOutputter extends XMLOutputter function checkbox($id, $label, $checked=false, $instructions=null, $value='true', $disabled=false) { - $this->elementStart('p'); $attrs = array('name' => $id, 'type' => 'checkbox', 'class' => 'checkbox', 'id' => $id); if ($value) { - $attrs['value'] = htmlspecialchars($value); + $attrs['value'] = $value; } if ($checked) { $attrs['checked'] = 'checked'; @@ -197,14 +222,13 @@ class HTMLOutputter extends XMLOutputter } $this->element('input', $attrs); $this->text(' '); - $this->element('label', array('class' => 'checkbox_label', + $this->element('label', array('class' => 'checkbox', 'for' => $id), $label); $this->text(' '); if ($instructions) { - $this->element('span', 'input_instructions', $instructions); + $this->element('p', 'form_guide', $instructions); } - $this->elementEnd('p'); } /** @@ -229,7 +253,6 @@ class HTMLOutputter extends XMLOutputter function dropdown($id, $label, $content, $instructions=null, $blank_select=false, $selected=null) { - $this->elementStart('p'); $this->element('label', array('for' => $id), $label); $this->elementStart('select', array('id' => $id, 'name' => $id)); if ($blank_select) { @@ -238,7 +261,7 @@ class HTMLOutputter extends XMLOutputter foreach ($content as $value => $option) { if ($value == $selected) { $this->element('option', array('value' => $value, - 'selected' => $value), + 'selected' => 'selected'), $option); } else { $this->element('option', array('value' => $value), $option); @@ -246,9 +269,8 @@ class HTMLOutputter extends XMLOutputter } $this->elementEnd('select'); if ($instructions) { - $this->element('span', 'input_instructions', $instructions); + $this->element('p', 'form_guide', $instructions); } - $this->elementEnd('p'); } /** @@ -285,7 +307,6 @@ class HTMLOutputter extends XMLOutputter function password($id, $label, $instructions=null) { - $this->elementStart('p'); $this->element('label', array('for' => $id), $label); $attrs = array('name' => $id, 'type' => 'password', @@ -293,9 +314,8 @@ class HTMLOutputter extends XMLOutputter 'id' => $id); $this->element('input', $attrs); if ($instructions) { - $this->element('span', 'input_instructions', $instructions); + $this->element('p', 'form_guide', $instructions); } - $this->elementEnd('p'); } /** @@ -311,15 +331,60 @@ class HTMLOutputter extends XMLOutputter * @todo add a $name parameter */ - function submit($id, $label, $cls='submit', $name=null) + function submit($id, $label, $cls='submit', $name=null, $title=null) { - $this->elementStart('p'); $this->element('input', array('type' => 'submit', 'id' => $id, 'name' => ($name) ? $name : $id, 'class' => $cls, - 'value' => $label)); - $this->elementEnd('p'); + 'value' => $label, + 'title' => $title)); + } + + /** + * output a script (almost always javascript) tag + * + * @param string $src relative or absolute script path + * @param string $type 'type' attribute value of the tag + * + * @return void + */ + function script($src, $type='text/javascript') + { + $url = parse_url($src); + if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment)) + { + $src = common_path($src) . '?version=' . STATUSNET_VERSION; + } + $this->element('script', array('type' => $type, + 'src' => $src), + ' '); + } + + /** + * output a css link + * + * @param string $src relative path within the theme directory, or an absolute path + * @param string $theme 'theme' that contains the stylesheet + * @param string media 'media' attribute of the tag + * + * @return void + */ + function cssLink($src,$theme=null,$media=null) + { + $url = parse_url($src); + if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment)) + { + if(file_exists(theme_file($src,$theme))){ + $src = theme_path($src, $theme) . '?version=' . STATUSNET_VERSION; + }else{ + $src = common_path($src); + } + } + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => $src, + 'media' => $media)); } /** @@ -339,7 +404,6 @@ class HTMLOutputter extends XMLOutputter function textarea($id, $label, $content=null, $instructions=null) { - $this->elementStart('p'); $this->element('label', array('for' => $id), $label); $this->element('textarea', array('rows' => 3, 'cols' => 40, @@ -347,8 +411,28 @@ class HTMLOutputter extends XMLOutputter 'id' => $id), ($content) ? $content : ''); if ($instructions) { - $this->element('span', 'input_instructions', $instructions); + $this->element('p', 'form_guide', $instructions); } - $this->elementEnd('p'); + } + + + /** + * Internal script to autofocus the given element on page onload. + * + * @param string $id element ID, must refer to an existing element + * + * @return void + * + */ + function autofocus($id) + { + $this->elementStart('script', array('type' => 'text/javascript')); + $this->raw('/**/'); + $this->elementEnd('script'); } }