*/
public $repo;
+ public static $arMimeTypeMap = array(
+ 'css' => 'text/css',
+ 'htm' => 'text/html',
+ 'html' => 'text/html',
+ 'js' => 'application/javascript',
+ 'php' => 'text/x-php',
+ 'txt' => 'text/plain',
+ );
+
public function __construct($path, Repository $repo)
{
$this->path = $path;
return file_get_contents($this->path);
}
+ public function getMimeType()
+ {
+ $type = $this->getType();
+ if (!isset(static::$arMimeTypeMap[$type])) {
+ return null;
+ }
+ return static::$arMimeTypeMap[$type];
+ }
+
/**
* Get a link to the file
*
return $arFiles;
}
+ public function getFileByName($name)
+ {
+ $base = basename($name);
+ if ($base != $name) {
+ throw new Exception('No directories supported for now');
+ }
+ $path = $this->repoDir . '/' . $base;
+ if (!is_readable($path)) {
+ throw new Exception_Input('File does not exist');
+ }
+ return new File($path, $this);
+ }
+
public function getDescription()
{
return file_get_contents($this->repoDir . '/.git/description');
#RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([0-9]+)$ /display.php?id=$1
+RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
--- /dev/null
+<?php
+/**
+ * Displays a file
+ */
+namespace Phorkie;
+require_once 'www-header.php';
+$repo = new Repository();
+$repo->loadFromRequest();
+
+if (!isset($_GET['file']) || $_GET['file'] == '') {
+ throw new Exception_Input('File name missing');
+}
+
+$file = $repo->getFileByName($_GET['file']);
+$mimetype = $file->getMimeType();
+if ($mimetype === null) {
+ $mimetype = 'text/plain';
+}
+header('Content-Type: ' . $mimetype);
+readfile($file->path);
+?>