]> 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 cba8a5f5e09b9023706c9635e27b3a80b51137cb..6045971161d5e933437d5c1be6d02e61e870f802 100644 (file)
@@ -109,8 +109,11 @@ class HTMLOutputter extends XMLOutputter
         header('Content-Type: '.$type);
 
         $this->extraHeaders();
-
-        $this->startXML('html');
+        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 = $this->getLanguage();
 
@@ -336,6 +339,52 @@ class HTMLOutputter extends XMLOutputter
                                       '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));
+    }
+
     /**
      * output an HTML textarea and associated elements
      *