. * * @category Output * @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://status.net/ */ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/lib/xmloutputter.php'; // Can include XHTML options but these are too fragile in practice. define('PAGE_TYPE_PREFS', 'text/html'); /** * Low-level generator for HTML * * Abstracts some of the code necessary for HTML generation. Especially * has methods for generating HTML form elements. Note that these have * been created kind of haphazardly, not with an eye to making a general * HTML-creation class. * * @category Output * @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://status.net/ * * @see Action * @see XMLOutputter */ class HTMLOutputter extends XMLOutputter { /** * Constructor * * Just wraps the XMLOutputter constructor. * * @param string $output URI to output to, default = stdout * @param boolean $indent Whether to indent output, default true */ function __construct($output='php://output', $indent=true) { parent::__construct($output, $indent); } /** * Start an HTML document * * If $type isn't specified, will attempt to do content negotiation. * * Attempts to do content negotiation for language, also. * * @param string $type MIME type to use; default is to do negotation. * * @todo extract content negotiation code to an HTTP module or class. * * @return void */ function startHTML($type=null) { if (!$type) { $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; // XXX: allow content negotiation for RDF, RSS, or XRDS $cp = common_accept_to_prefs($httpaccept); $sp = common_accept_to_prefs(PAGE_TYPE_PREFS); $type = common_negotiate_type($cp, $sp); if (!$type) { throw new ClientException(_('This page is not available in a '. 'media type you accept'), 406); } } header('Content-Type: '.$type); $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 = $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 * * Despite the name, it is specifically for outputting a * text input element, not other elements. It outputs * a cluster of elements, including a