X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fhtmloutputter.php;h=74876523a64e2a6913c50f0f80b79b0fb5b767cb;hb=c8c2d9d7c93f40e7ac81c6211f8ba4c3f6ae91d9;hp=75a995bef190dbcbc4ff99c43a1159254c62a81e;hpb=6b42b2a09c2031a0e3ac589589cbd1e2f545ac4c;p=quix0rs-gnu-social.git diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php index 75a995bef1..74876523a6 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -101,27 +101,33 @@ 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); - $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( ! substr($type,0,strlen('text/html'))=='text/html' ){ + // Browsers don't like it when xw->startDocument('1.0', 'UTF-8'); + } + $this->xw->writeDTD('html', $public, $system); - $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 * @@ -133,6 +139,16 @@ class HTMLOutputter extends XMLOutputter $this->endXML(); } + /** + * To specify additional HTTP headers for the action + * + * @return void + */ + function extraHeaders() + { + // Needs to be overloaded + } + /** * Output an HTML text input element * @@ -155,20 +171,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'); } /** @@ -192,13 +205,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'; @@ -208,14 +220,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'); } /** @@ -240,7 +251,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) { @@ -249,7 +259,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); @@ -257,9 +267,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'); } /** @@ -296,7 +305,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', @@ -304,9 +312,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'); } /** @@ -322,15 +329,59 @@ 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(! ($url->scheme || $url->host || $url->query || $url->fragment)) + { + $src = common_path($src) . '?version=' . LACONICA_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) + { + if (!$theme) { + $theme = common_config('site', 'theme'); + } + $url = parse_url($src); + if(! ($url->scheme || $url->host || $url->query || $url->fragment)) + { + $src = theme_path($src) . '?version=' . LACONICA_VERSION; + } + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => $src, + 'media' => $media)); } /** @@ -350,7 +401,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, @@ -358,8 +408,7 @@ 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'); } }