7 * Full path to the file
14 * Repository this file belongs to
20 public function __construct($path, Repository $repo = null)
27 * Get filename relative to the repository path
31 public function getFilename()
33 return basename($this->path);
37 * Return the full path to the file
41 public function getPath()
47 * Get file extension without dot
51 public function getExt()
53 return substr($this->path, strrpos($this->path, '.') + 1);
56 public function getContent()
58 return file_get_contents($this->path);
61 public function getRenderedContent(Tool_Result $res = null)
63 $ext = $this->getExt();
64 $class = '\\phorkie\\Renderer_Unknown';
66 if (isset($GLOBALS['phorkie']['languages'][$ext]['renderer'])) {
67 $class = $GLOBALS['phorkie']['languages'][$ext]['renderer'];
68 } else if (isset($GLOBALS['phorkie']['languages'][$ext]['mime'])) {
69 $type = $GLOBALS['phorkie']['languages'][$ext]['mime'];
70 if (substr($type, 0, 5) == 'text/') {
71 $class = '\\phorkie\\Renderer_Geshi';
72 } else if (substr($type, 0, 6) == 'image/') {
73 $class = '\\phorkie\\Renderer_Image';
78 return $rend->toHtml($this, $res);
82 * Get a link to the file
84 * @param string $type Link type. Supported are:
87 * @param string $option
91 public function getLink($type, $option = null)
94 return '/' . $this->repo->id . '/raw/' . $this->getFilename();
95 } else if ($type == 'tool') {
96 return '/' . $this->repo->id . '/tool/' . $option . '/' . $this->getFilename();
98 throw new Exception('Unknown type');
101 public function getMimeType()
103 $ext = $this->getExt();
104 if (!isset($GLOBALS['phorkie']['languages'][$ext])) {
107 return $GLOBALS['phorkie']['languages'][$ext]['mime'];
111 * @return array Array of Tool_Info objects
113 public function getToolInfos()
115 $tm = new Tool_Manager();
116 return $tm->getSuitable($this);
120 * Tells if the file contains textual content and is editable.
124 public function isText()
126 $ext = $this->getExt();
127 if (!isset($GLOBALS['phorkie']['languages'][$ext]['mime'])) {
131 $type = $GLOBALS['phorkie']['languages'][$ext]['mime'];
132 return substr($type, 0, 5) === 'text/';