Move Horde-specific SyntaxHighlighter to Core
authorChuck Hagenbuch <chuck@horde.org>
Sat, 2 Oct 2010 22:35:20 +0000 (18:35 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 2 Oct 2010 22:39:07 +0000 (18:39 -0400)
framework/Core/lib/Horde/Core/Factory/MimeViewer.php
framework/Core/lib/Horde/Core/Mime/Viewer/Css.php [deleted file]
framework/Core/lib/Horde/Core/Mime/Viewer/SyntaxHighlighter.php [new file with mode: 0644]
framework/Core/package.xml
framework/Mime_Viewer/lib/Horde/Mime/Viewer/SyntaxHighlighter.php
framework/Mime_Viewer/package.xml
wicked/lib/Text_Wiki/Render/Xhtml/Code2.php

index 61e7b21..b8f08fc 100644 (file)
@@ -108,13 +108,6 @@ class Horde_Core_Factory_MimeViewer
         ));
 
         switch ($config['driver']) {
-        case 'Css':
-            if ($config['app'] == 'horde') {
-                $driver = 'Horde_Core_Mime_Viewer_Css';
-            }
-            $params['registry'] = $GLOBALS['registry'];
-            break;
-
         case 'Deb':
         case 'Rpm':
             $params['monospace'] = 'fixed';
@@ -138,6 +131,13 @@ class Horde_Core_Factory_MimeViewer
             $params['viewer_callback'] = array($this, 'getViewerCallback');
             break;
 
+        case 'Syntaxhighlighter':
+            if ($config['app'] == 'horde') {
+                $driver = 'Horde_Core_Mime_Viewer_Syntaxhighlighter';
+            }
+            $params['registry'] = $GLOBALS['registry'];
+            break;
+
         case 'Tgz':
             $params['gzip'] = Horde_Compress::factory('Gzip');
             $params['monospace'] = 'fixed';
diff --git a/framework/Core/lib/Horde/Core/Mime/Viewer/Css.php b/framework/Core/lib/Horde/Core/Mime/Viewer/Css.php
deleted file mode 100644 (file)
index 4cf8850..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-/**
- * The Horde_Core_Mime_Viewer_Css class extends the base CSS driver by adding
- * the necessary stylesheets to the full rendered version.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author   Michael Slusarz <slusarz@horde.org>
- * @category Horde
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package  Core
- */
-class Horde_Core_Mime_Viewer_Css extends Horde_Mime_Viewer_Css
-{
-    /**
-     * Constructor.
-     *
-     * @param Horde_Mime_Part $mime_part  The object with the data to be
-     *                                    rendered.
-     * @param array $conf                 Configuration:
-     * <pre>
-     * 'registry' - (Horde_Registry) Registry object.
-     * </pre>
-     *
-     * @throws InvalidArgumentException
-     */
-    public function __construct(Horde_Mime_Part $part, array $conf = array())
-    {
-        $this->_required = array_merge($this->_required, array(
-            'registry'
-        ));
-
-        parent::__construct($part, $conf);
-    }
-
-    /**
-     * Return the full rendered version of the Horde_Mime_Part object.
-     *
-     * @return array  See parent::render().
-     */
-    protected function _render()
-    {
-        $ret = $this->_renderInline();
-
-        // Need Horde headers for CSS tags.
-        if (!empty($ret)) {
-            $templates = $this->getConfigParam('registry')->get('templates', 'horde');
-
-            reset($ret);
-            Horde::startBuffer();
-            require $templates . '/common-header.inc';
-            echo $ret[key($ret)]['data'];
-            require $templates . '/common-footer.inc';
-            $ret[key($ret)]['data'] = Horde::endBuffer();
-        }
-
-        return $ret;
-    }
-
-}
diff --git a/framework/Core/lib/Horde/Core/Mime/Viewer/SyntaxHighlighter.php b/framework/Core/lib/Horde/Core/Mime/Viewer/SyntaxHighlighter.php
new file mode 100644 (file)
index 0000000..e290899
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/**
+ * The Horde_Mime_Viewer_Syntaxhighlighter class renders source code appropriate
+ * for highlighting with http://alexgorbatchev.com/SyntaxHighlighter/.
+ *
+ * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package  Mime_Viewer
+ */
+class Horde_Core_Mime_Viewer_Syntaxhighlighter extends Horde_Mime_Viewer_Syntaxhighlighter
+{
+    protected static $_shLoaded = false;
+    protected static $_shBrushes = array();
+
+    /**
+     * Return the rendered inline version of the Horde_Mime_Part object.
+     *
+     * @return array  See parent::render().
+     */
+    protected function _renderInline()
+    {
+        /* Determine the language and brush from the mime type. */
+        $mimeType = $this->_mimepart->getType();
+        $language = $this->_mimeTypeToLanguage($mimeType);
+        $brush = $this->_languageToBrush($language);
+
+        if (!self::$_shLoaded) {
+            Horde::addScriptFile('syntaxhighlighter/scripts/shCore.js', 'horde', true);
+            Horde::addInlineScript(array(
+                'SyntaxHighlighter.defaults[\'toolbar\'] = false',
+                'SyntaxHighlighter.all()',
+            ), 'dom');
+            self::$_shLoaded = true;
+
+            $sh_js_fs = $this->getConfigParam('registry')->get('jsfs', 'horde') . '/syntaxhighlighter/styles/';
+            $sh_js_uri = Horde::url($this->getConfigParam('registry')->get('jsuri', 'horde'), false, -1) . '/syntaxhighlighter/styles/';
+            Horde_Themes::includeStylesheetFiles(array('additional' => array(
+                array('f' => $sh_js_fs . 'shCoreEclipse.css', 'u' => $sh_js_uri . 'shCoreEclipse.css'),
+                array('f' => $sh_js_fs . 'shThemeEclipse.css', 'u' => $sh_js_uri . 'shThemeEclipse.css'),
+            )));
+        }
+        if (empty(self::$_shBrushes[$brush])) {
+            Horde::addScriptFile('syntaxhighlighter/scripts/shBrush' . $brush . '.js', 'horde', true);
+            self::$_shBrushes[$brush] = true;
+        }
+
+        $results = '<pre class="brush: ' . $language . '; toolbar: false;">' . htmlspecialchars($this->_mimepart->getContents(), ENT_QUOTES, $this->getConfigParam('charset')) . '</pre>';
+        return $this->_renderReturn(
+            $results,
+            'text/html; charset=' . $this->getConfigParam('charset')
+        );
+    }
+}
index 145d320..7116120 100644 (file)
@@ -190,7 +190,7 @@ Application Framework.</description>
       </dir> <!-- /lib/Horde/Core/LoginTasks -->
       <dir name="Mime">
        <dir name="Viewer">
-        <file name="Css.php" role="php" />
+        <file name="Syntaxhighlighter.php" role="php" />
         <file name="Vcard.php" role="php" />
        </dir> <!-- /lib/Horde/Core/Mime/Viewer -->
       </dir> <!-- /lib/Horde/Core/Mime -->
@@ -503,7 +503,7 @@ Application Framework.</description>
    <install as="Horde/Core/Factory/View.php" name="lib/Horde/Core/Factory/View.php" />
    <install as="Horde/Core/Log/Logger.php" name="lib/Horde/Core/Log/Logger.php" />
    <install as="Horde/Core/LoginTasks/Backend/Horde.php" name="lib/Horde/Core/LoginTasks/Backend/Horde.php" />
-   <install as="Horde/Core/Mime/Viewer/Css.php" name="lib/Horde/Core/Mime/Viewer/Css.php" />
+   <install as="Horde/Core/Mime/Viewer/Syntaxhighlighter.php" name="lib/Horde/Core/Mime/Viewer/Syntaxhighlighter.php" />
    <install as="Horde/Core/Mime/Viewer/Vcard.php" name="lib/Horde/Core/Mime/Viewer/Vcard.php" />
    <install as="Horde/Core/Notification/Hordelog.php" name="lib/Horde/Core/Notification/Hordelog.php" />
    <install as="Horde/Core/Notification/Status.php" name="lib/Horde/Core/Notification/Status.php" />
index e1eec69..6a75dc3 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
- * The Horde_Mime_Viewer_SyntaxHighlighter class renders source code appropriate
- * for highlighting with SyntaxHighlighter.
+ * The Horde_Mime_Viewer_Syntaxhighlighter class renders source code appropriate
+ * for highlighting with http://alexgorbatchev.com/SyntaxHighlighter/.
  *
  * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
  *
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @package  Mime_Viewer
  */
-class Horde_Mime_Viewer_SyntaxHighlighter extends Horde_Mime_Viewer_Base
+class Horde_Mime_Viewer_Syntaxhighlighter extends Horde_Mime_Viewer_Base
 {
-    protected static $_shLoaded = false;
-    protected static $_shBrushes = array();
-
     /**
      * This driver's display capabilities.
      *
@@ -49,32 +46,9 @@ class Horde_Mime_Viewer_SyntaxHighlighter extends Horde_Mime_Viewer_Base
     {
         /* Determine the language and brush from the mime type. */
         $mimeType = $this->_mimepart->getType();
-        if (strpos($mimeType, '/') === false) {
-            $mimeType = "application/x-$mimeType";
-        }
         $language = $this->_mimeTypeToLanguage($mimeType);
         $brush = $this->_languageToBrush($language);
 
-        if (!self::$_shLoaded) {
-            Horde::addScriptFile('syntaxhighlighter/scripts/shCore.js', 'horde', true);
-            Horde::addInlineScript(array(
-                'SyntaxHighlighter.defaults[\'toolbar\'] = false',
-                'SyntaxHighlighter.all()',
-            ), 'dom');
-            self::$_shLoaded = true;
-
-            $sh_js_fs = $GLOBALS['injector']->getInstance('Horde_Registry')->get('jsfs', 'horde') . '/syntaxhighlighter/styles/';
-            $sh_js_uri = Horde::url($GLOBALS['injector']->getInstance('Horde_Registry')->get('jsuri', 'horde'), false, -1) . '/syntaxhighlighter/styles/';
-            Horde_Themes::includeStylesheetFiles(array('additional' => array(
-                array('f' => $sh_js_fs . 'shCoreEclipse.css', 'u' => $sh_js_uri . 'shCoreEclipse.css'),
-                array('f' => $sh_js_fs . 'shThemeEclipse.css', 'u' => $sh_js_uri . 'shThemeEclipse.css'),
-            )));
-        }
-        if (empty(self::$_shBrushes[$brush])) {
-            Horde::addScriptFile('syntaxhighlighter/scripts/shBrush' . $brush . '.js', 'horde', true);
-            self::$_shBrushes[$brush] = true;
-        }
-
         $results = '<pre class="brush: ' . $language . '">' . htmlspecialchars($this->_mimepart->getContents(), ENT_QUOTES, $this->getConfigParam('charset')) . '</pre>';
         return $this->_renderReturn(
             $results,
index 2d8e922..264c022 100644 (file)
@@ -22,7 +22,7 @@
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
  <notes>
-Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlighter
+Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlighter: http://alexgorbatchev.com/SyntaxHighlighter/
  </notes>
  <contents>
   <dir baseinstalldir="/" name="/">
@@ -126,7 +126,7 @@ Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlig
        <file name="Security.php" role="php" />
        <file name="Simple.php" role="php" />
        <file name="Smil.php" role="php" />
-       <file name="SyntaxHighlighter.php" role="php" />
+       <file name="Syntaxhighlighter.php" role="php" />
        <file name="Tgz.php" role="php" />
        <file name="Tnef.php" role="php" />
        <file name="Wordperfect.php" role="php" />
@@ -264,7 +264,7 @@ Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlig
    <install as="Horde/Mime/Viewer/Security.php" name="lib/Horde/Mime/Viewer/Security.php" />
    <install as="Horde/Mime/Viewer/Simple.php" name="lib/Horde/Mime/Viewer/Simple.php" />
    <install as="Horde/Mime/Viewer/Smil.php" name="lib/Horde/Mime/Viewer/Smil.php" />
-   <install as="Horde/Mime/Viewer/SyntaxHighlighter.php" name="lib/Horde/Mime/Viewer/SyntaxHighlighter.php" />
+   <install as="Horde/Mime/Viewer/Syntaxhighlighter.php" name="lib/Horde/Mime/Viewer/Syntaxhighlighter.php" />
    <install as="Horde/Mime/Viewer/Tgz.php" name="lib/Horde/Mime/Viewer/Tgz.php" />
    <install as="Horde/Mime/Viewer/Tnef.php" name="lib/Horde/Mime/Viewer/Tnef.php" />
    <install as="Horde/Mime/Viewer/Wordperfect.php" name="lib/Horde/Mime/Viewer/Wordperfect.php" />
@@ -296,7 +296,7 @@ Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlig
    <date>2010-10-02</date>
    <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
    <notes>
-Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlighter
+Replaced external or PHP-based syntax highlighters with javascript SyntaxHighlighter: http://alexgorbatchev.com/SyntaxHighlighter/
    </notes>
   </release>
  </changelog>
index bb22216..f4aeeca 100644 (file)
@@ -1,7 +1,4 @@
 <?php
-
-require_once 'Text/Wiki/Render/Xhtml/Code.php';
-
 /**
  * @package Wicked
  */
@@ -23,7 +20,7 @@ class Text_Wiki_Render_Xhtml_Code2 extends Text_Wiki_Render_Xhtml_Code
         $part->setContents($options['text']);
         $part->setType("x-extension/$type");
 
-        $viewer = new Horde_Mime_Viewer_SyntaxHighlighter($part, array('charset' => $GLOBALS['registry']->getCharset()));
+        $viewer = new Horde_Core_Mime_Viewer_Syntaxhighlighter($part, array('registry' => $GLOBALS['registry'], 'charset' => $GLOBALS['registry']->getCharset()));
         $data = $viewer->render('inline');
         $data = reset($data);
         return $data['data'];