]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/htmloutputter.php
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / lib / htmloutputter.php
index f9245414f29348a90628363a21e7aeee879e6d38..ce83295fb33783f1ddeac61da5ce19a3a2fe69e1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Low-level generator for HTML
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Output
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @author    Sarven Capadisli <csarven@controlyourself.ca>
- * @copyright 2008 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @author    Sarven Capadisli <csarven@status.net>
+ * @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://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
@@ -47,11 +47,11 @@ define('PAGE_TYPE_PREFS',
  * HTML-creation class.
  *
  * @category Output
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
- * @author   Sarven Capadisli <csarven@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Sarven Capadisli <csarven@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  *
  * @see      Action
  * @see      XMLOutputter
@@ -101,29 +101,35 @@ 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->extraHeaders();
-
-        $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 (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 = 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
     *
@@ -134,7 +140,7 @@ class HTMLOutputter extends XMLOutputter
         $this->elementEnd('html');
         $this->endXML();
     }
-    
+
     /**
     *  To specify additional HTTP headers for the action
     *
@@ -172,7 +178,7 @@ class HTMLOutputter extends XMLOutputter
                        'type' => 'text',
                        'id' => $id);
         if ($value) {
-            $attrs['value'] = htmlspecialchars($value);
+            $attrs['value'] = $value;
         }
         $this->element('input', $attrs);
         if ($instructions) {
@@ -206,7 +212,7 @@ class HTMLOutputter extends XMLOutputter
                        'class' => 'checkbox',
                        'id' => $id);
         if ($value) {
-            $attrs['value'] = htmlspecialchars($value);
+            $attrs['value'] = $value;
         }
         if ($checked) {
             $attrs['checked'] = 'checked';
@@ -255,7 +261,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);
@@ -335,6 +341,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=' . STATUSNET_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=' . STATUSNET_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
      *
@@ -362,4 +414,25 @@ class HTMLOutputter extends XMLOutputter
             $this->element('p', 'form_guide', $instructions);
         }
     }
+
+
+    /**
+    * Internal script to autofocus the given element on page onload.
+    *
+    * @param string $id element ID, must refer to an existing element
+    *
+    * @return void
+    *
+    */
+    function autofocus($id)
+    {
+        $this->elementStart('script', array('type' => 'text/javascript'));
+        $this->raw('/*<![CDATA[*/'.
+                   ' $(document).ready(function() {'.
+                   ' var el = $("#' . $id . '");'.
+                   ' if (el.length) { el.focus(); }'.
+                   ' });'.
+                   ' /*]]>*/');
+        $this->elementEnd('script');
+    }
 }