]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/htmloutputter.php
Fix logic that determines if a URL is relative or absolute in script() and cssLink()
[quix0rs-gnu-social.git] / lib / htmloutputter.php
index 71f17604ba989ac142cd0122224e14418e29f021..6045971161d5e933437d5c1be6d02e61e870f802 100644 (file)
@@ -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 <?xml it output for non-xhtml documents
+            $this->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
      *
@@ -160,7 +176,7 @@ class HTMLOutputter extends XMLOutputter
                        'type' => 'text',
                        'id' => $id);
         if ($value) {
-            $attrs['value'] = htmlspecialchars($value);
+            $attrs['value'] = $value;
         }
         $this->element('input', $attrs);
         if ($instructions) {
@@ -194,7 +210,7 @@ class HTMLOutputter extends XMLOutputter
                        'class' => 'checkbox',
                        'id' => $id);
         if ($value) {
-            $attrs['value'] = htmlspecialchars($value);
+            $attrs['value'] = $value;
         }
         if ($checked) {
             $attrs['checked'] = 'checked';
@@ -243,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);
@@ -313,13 +329,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->element('input', array('type' => 'submit',
                                       'id' => $id,
                                       'name' => ($name) ? $name : $id,
                                       'class' => $cls,
-                                      'value' => $label));
+                                      '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=' . 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)
+    {
+        $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=' . LACONICA_VERSION;
+            }else{
+               $src = common_path($src);
+            }
+        }
+        $this->element('link', array('rel' => 'stylesheet',
+                                'type' => 'text/css',
+                                'href' => $src,
+                                'media' => $media));
     }
 
     /**