123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- require_once INSTALLDIR.'/lib/xmloutputter.php';
- define('PAGE_TYPE_PREFS', 'text/html');
- class HTMLOutputter extends XMLOutputter
- {
-
- function __construct($output='php://output', $indent=null)
- {
- parent::__construct($output, $indent);
- }
-
- function startHTML($type=null)
- {
- if (!$type) {
- $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
- $_SERVER['HTTP_ACCEPT'] : null;
-
- $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);
-
-
- if (common_config('javascript', 'bustframes')) {
- header('X-XSS-Protection: 1; mode=block');
- header('X-Frame-Options: SAMEORIGIN');
- }
- $this->extraHeaders();
- if (preg_match("/.*\/.*xml/", $type)) {
-
- $this->startXML();
- }
- $this->xw->writeDTD('html',
- '-//W3C//DTD XHTML 1.0 Strict//EN',
- 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
- $language = $this->getLanguage();
- $attrs = array(
- 'xmlns' => 'http://www.w3.org/1999/xhtml',
- 'xml:lang' => $language,
- 'lang' => $language
- );
- if (Event::handle('StartHtmlElement', array($this, &$attrs))) {
- $this->elementStart('html', $attrs);
- Event::handle('EndHtmlElement', array($this, &$attrs));
- }
- }
- function getLanguage()
- {
-
- return common_language();
- }
-
- function endHTML()
- {
- $this->elementEnd('html');
- $this->endXML();
- }
-
- function extraHeaders()
- {
-
- }
-
- function input($id, $label, $value=null, $instructions=null, $name=null, $required=false, array $attrs=array())
- {
- $this->element('label', array('for' => $id), $label);
- if (!array_key_exists('type', $attrs)) {
- $attrs['type'] = 'text';
- }
- $attrs['id'] = $id;
- $attrs['name'] = is_null($name) ? $id : $name;
- if (!is_null($value)) {
- $attrs['value'] = $value;
- }
- if (!empty($required)) {
- $attrs['required'] = 'required';
- }
- $this->element('input', $attrs);
- if ($instructions) {
- $this->element('p', 'form_guide', $instructions);
- }
- }
-
- function checkbox($id, $label, $checked=false, $instructions=null,
- $value='true', $disabled=false)
- {
- $attrs = array('name' => $id,
- 'type' => 'checkbox',
- 'class' => 'checkbox',
- 'id' => $id);
- if ($value) {
- $attrs['value'] = $value;
- }
- if ($checked) {
- $attrs['checked'] = 'checked';
- }
- if ($disabled) {
- $attrs['disabled'] = 'true';
- }
- $this->element('input', $attrs);
- $this->text(' ');
- $this->element('label', array('class' => 'checkbox',
- 'for' => $id),
- $label);
- $this->text(' ');
- if ($instructions) {
- $this->element('p', 'form_guide', $instructions);
- }
- }
-
- function dropdown($id, $label, $content, $instructions=null,
- $blank_select=false, $selected=null)
- {
- $this->element('label', array('for' => $id), $label);
- $this->elementStart('select', array('id' => $id, 'name' => $id));
- if ($blank_select) {
- $this->element('option', array('value' => ''));
- }
- foreach ($content as $value => $option) {
- if ($value == $selected) {
- $this->element('option', array('value' => $value,
- 'selected' => 'selected'),
- $option);
- } else {
- $this->element('option', array('value' => $value), $option);
- }
- }
- $this->elementEnd('select');
- if ($instructions) {
- $this->element('p', 'form_guide', $instructions);
- }
- }
-
- function hidden($id, $value, $name=null)
- {
- $this->element('input', array('name' => $name ?: $id,
- 'type' => 'hidden',
- 'id' => $id,
- 'value' => $value));
- }
-
- function password($id, $label, $instructions=null)
- {
- $this->element('label', array('for' => $id), $label);
- $attrs = array('name' => $id,
- 'type' => 'password',
- 'class' => 'password',
- 'id' => $id);
- $this->element('input', $attrs);
- if ($instructions) {
- $this->element('p', 'form_guide', $instructions);
- }
- }
-
- function submit($id, $label, $cls='submit', $name=null, $title=null)
- {
- $this->element('input', array('type' => 'submit',
- 'id' => $id,
- 'name' => $name ?: $id,
- 'class' => $cls,
- 'value' => $label,
- 'title' => $title));
- }
-
- function script($src, $type='text/javascript')
- {
- if (Event::handle('StartScriptElement', array($this,&$src,&$type))) {
- $url = parse_url($src);
- if (empty($url['scheme']) && empty($url['host']) && empty($url['query']) && empty($url['fragment'])) {
-
- if (strpos($src, 'plugins/') === 0 || strpos($src, 'local/') === 0) {
- $src = common_path($src, StatusNet::isHTTPS()) . '?version=' . GNUSOCIAL_VERSION;
- } else {
- if (StatusNet::isHTTPS()) {
- $sslserver = common_config('javascript', 'sslserver');
- if (empty($sslserver)) {
- if (is_string(common_config('site', 'sslserver')) &&
- mb_strlen(common_config('site', 'sslserver')) > 0) {
- $server = common_config('site', 'sslserver');
- } else if (common_config('site', 'server')) {
- $server = common_config('site', 'server');
- }
- $path = common_config('site', 'path') . '/js/';
- } else {
- $server = $sslserver;
- $path = common_config('javascript', 'sslpath');
- if (empty($path)) {
- $path = common_config('javascript', 'path');
- }
- }
- $protocol = 'https';
- } else {
- $path = common_config('javascript', 'path');
- if (empty($path)) {
- $path = common_config('site', 'path') . '/js/';
- }
- $server = common_config('javascript', 'server');
- if (empty($server)) {
- $server = common_config('site', 'server');
- }
- $protocol = 'http';
- }
- if ($path[strlen($path)-1] != '/') {
- $path .= '/';
- }
- if ($path[0] != '/') {
- $path = '/'.$path;
- }
- $src = $protocol.'://'.$server.$path.$src . '?version=' . GNUSOCIAL_VERSION;
- }
- }
- $this->element('script', array('type' => $type,
- 'src' => $src),
- ' ');
- Event::handle('EndScriptElement', array($this,$src,$type));
- }
- }
-
- function inlineScript($code, $type='text/javascript')
- {
- if(Event::handle('StartInlineScriptElement', array($this,&$code,&$type))) {
- $this->elementStart('script', array('type' => $type));
- if($type == 'text/javascript') {
- $this->raw('/*<![CDATA[*/ ');
- }
- $this->raw($code);
- if($type == 'text/javascript') {
- $this->raw(' /*]]>*/');
- }
- $this->elementEnd('script');
- Event::handle('EndInlineScriptElement', array($this,$code,$type));
- }
- }
-
- function cssLink($src,$theme=null,$media=null)
- {
- if(Event::handle('StartCssLinkElement', array($this,&$src,&$theme,&$media))) {
- $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);
- }else{
- $src = common_path($src, StatusNet::isHTTPS());
- }
- $src.= '?version=' . GNUSOCIAL_VERSION;
- }
- $this->element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => $src,
- 'media' => $media));
- Event::handle('EndCssLinkElement', array($this,$src,$theme,$media));
- }
- }
-
- function style($code, $type = 'text/css', $media = null)
- {
- if(Event::handle('StartStyleElement', array($this,&$code,&$type,&$media))) {
- $this->elementStart('style', array('type' => $type, 'media' => $media));
- $this->raw($code);
- $this->elementEnd('style');
- Event::handle('EndStyleElement', array($this,$code,$type,$media));
- }
- }
-
- function textarea(
- $id,
- $label,
- $content = null,
- $instructions = null,
- $name = null,
- $cols = null,
- $rows = null,
- $required = false
- ) {
- $this->element('label', array('for' => $id), $label);
- $attrs = array(
- 'rows' => 3,
- 'cols' => 40,
- 'id' => $id
- );
- $attrs['name'] = is_null($name) ? $id : $name;
- if ($cols != null) {
- $attrs['cols'] = $cols;
- }
- if ($rows != null) {
- $attrs['rows'] = $rows;
- }
- $this->element(
- 'textarea',
- $attrs,
- is_null($content) ? '' : $content
- );
- if ($instructions) {
- $this->element('p', 'form_guide', $instructions);
- }
- }
-
- function autofocus($id)
- {
- $this->inlineScript(
- ' $(document).ready(function() {'.
- ' var el = $("#' . $id . '");'.
- ' if (el.length) { el.focus(); }'.
- ' });');
- }
- }
|