* @license PHP License * @package WB * @subpackage vfs */ WBClass::load('WBVFS_Mime'); /** * Virtual File System: Mime * * * * @version 0.1.1 * @package WB * @subpackage vfs */ class WBVFS_Mime_Text extends WBVFS_Mime { /** * list of mime types that are convertable to image * * Can convert * - video * - audio * - image * - application * * @var array */ protected $convertable = array( 'video', 'image', 'audio', 'application' ); /** * file name extension * @var string */ protected $extension = 'txt'; /** * get information about this file * * @return array */ public function getInfo() { return $this->info; } /** * import file * */ public function import() { } /** * get file name of requested file * * @return string */ protected function doGetRequestedFile(&$redirect) { $this->mimeMajor = 'text'; $cacheDir = $this->mkCacheDir(); if (!in_array($this->requestedMimeMinor, array('xml', 'html'))) { $this->requestedMimeMinor = 'plain'; } $this->file = $cacheDir . '/' . $this->requestedMimeMinor; // cache info file for five minutes if (file_exists($this->file)) { $age = time() - 300; if (filemtime($this->file) > $age) { $this->mimeMinor = $this->requestedMimeMinor; return $this->file; } } // this sort of locks the file an prevents multi processings touch($this->file, null); $info = array(); $info['obscureid'] = $this->vfile->getObscureId(); $info['views'] = $this->vfile->getViews(); $info['size'] = $this->vfile->getSize(); $info['md5'] = $this->vfile->getMd5(); $info['mime'] = $this->vfile->getMime(WBVFS_File::MIME_MAJOR | WBVFS_File::MIME_MINOR); $info['name'] = $this->vfile->getName(); $info['description'] = $this->vfile->getDescription(); // figure out file extension $cnt = array(); switch ($this->requestedMimeMinor) { case 'xml': $this->mimeMinor = 'xml'; $this->extension = 'xml'; $cnt = array(''); $cnt[] = ''; foreach ($info as $k => $v) { $v = htmlspecialchars($v); $cnt[] = sprintf(' <%s>%s', $k, $v, $k); } $cnt[] = ''; break; case 'html': $this->mimeMinor = 'html'; $this->extension = 'html'; $cnt = array(); $cnt[] = ''; $cnt[] = ''; $cnt[] = '' . $info['name'] . ''; $cnt[] = ''; $cnt[] = ''; $cnt[] = '

' . $info['name'] . '

'; $cnt[] = '

'; unset($info['name']); foreach ($info as $k => $v) { $v = htmlspecialchars($v); $cnt[] = sprintf(' %s: %s
', $k, $v); } $cnt[] = '

'; $cnt[] = ''; $cnt[] = ''; break; default: case 'plain': $this->mimeMinor = 'plain'; $this->extension = 'txt'; foreach ($info as $k => $v) { $v = htmlspecialchars($v); $cnt[] = sprintf('%s: %s', $k, $v); } break; } file_put_contents($this->file, implode("\n", $cnt) . "\n"); chmod($this->file, 0666); return $this->file; } }