highlighting for htm/html files
[phorkie.git] / src / Phorkie / File.php
index 14a7bbf335fbbeb907a99941b1a29eee1ba1df33..84f7eb5301b448f72a8ce322a04d1ce5926367a9 100644 (file)
@@ -17,6 +17,11 @@ class File
      */
     public $repo;
 
      */
     public $repo;
 
+    /**
+     * Maps file extensions to MIME Types
+     *
+     * @var array
+     */
     public static $arMimeTypeMap = array(
         'css'  => 'text/css',
         'htm'  => 'text/html',
     public static $arMimeTypeMap = array(
         'css'  => 'text/css',
         'htm'  => 'text/html',
@@ -24,6 +29,17 @@ class File
         'js'   => 'application/javascript',
         'php'  => 'text/x-php',
         'txt'  => 'text/plain',
         'js'   => 'application/javascript',
         'php'  => 'text/x-php',
         'txt'  => 'text/plain',
+        'xml'  => 'text/xml',
+    );
+
+    /**
+     * Maps file extensions to geshi types
+     *
+     * @var array
+     */
+    public static $arTypeMap = array(
+        'htm'  => 'xml',
+        'html' => 'xml',
     );
 
     public function __construct($path, Repository $repo)
     );
 
     public function __construct($path, Repository $repo)
@@ -43,13 +59,18 @@ class File
     }
 
     /**
     }
 
     /**
-     * Returns the type of the file, as used internally by Phorkie
+     * Returns the type of the file, as used by Geshi
      *
      * @return string
      */
     public function getType()
     {
      *
      * @return string
      */
     public function getType()
     {
-        return substr($this->path, strrpos($this->path, '.') + 1);
+        $ext = substr($this->path, strrpos($this->path, '.') + 1);
+        if (isset(static::$arTypeMap[$ext])) {
+            $ext = static::$arTypeMap[$ext];
+        }
+
+        return $ext;
     }
 
     public function getContent()
     }
 
     public function getContent()
@@ -57,6 +78,19 @@ class File
         return file_get_contents($this->path);
     }
 
         return file_get_contents($this->path);
     }
 
+    public function getHighlightedContent()
+    {
+        /**
+         * Yes, geshi needs to be in your include path
+         * We use the mediawiki geshi extension package.
+         */
+        require 'MediaWiki/geshi/geshi/geshi.php';
+        $geshi = new \GeSHi($this->getContent(), $this->getType());
+        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
+        $geshi->set_header_type(GESHI_HEADER_DIV);
+        return $geshi->parse_code();
+    }
+
     public function getMimeType()
     {
         $type = $this->getType();
     public function getMimeType()
     {
         $type = $this->getType();