* @license PHP License * @package WB * @subpackage vfs */ /** * Virtual File System * * Basics * * @version 0.3.0 * @package WB * @subpackage vfs */ class WBVFS extends WBStdClass { /** * file information table */ const TABLE_FILE = 'vfsfile'; /** * file upload chunks */ const TABLE_UPLOAD = 'vfsfileupload'; /** * user table */ const TABLE_USER = 'user'; const MIME_PLAIN = 'plain'; /** * constructor * * @param array $parameter */ public function __construct($parameter = array()) { } /** * Switch on/off translation feature * * @param bool|int $switch */ public function switchTranslation($switch = false) { $switch = intval($switch); if (0 < $switch) { $switch = true; } else { $switch = false; } $this->doSwitchTranslation($switch); } /** * Actually switch translation * * @param bool $switch */ protected function doSwitchTranslation($switch) { } /** * make name unique * * automatically change name like Windows(tm) explorer does * * @param string $name * @param array $siblings * @return string */ protected function makeUniqueName($name, $siblings) { // remove forward slashes from name $name = str_replace('/', '_', $name); $i = 1; $nameFormat = $name . ' (%d)'; // see whether name is already a numbered one if (preg_match('/(.+)\s\((\d+)\)$/', $name, $match)) { $i = intval($match[2]); $nameFormat = $match[1] . ' (%d)'; } while ($i < 1000) { $ok = true; foreach ($siblings as $s) { // check name of siblings if ($name == $s['name']) { $ok = false; break; } } if ($ok) { break; } ++$i; $name = sprintf($nameFormat, $i); } return $name; } /** * Extract Parameter 4 Table Access * * Avoid conflict of table and VFS parameter * * @param array * @return array */ protected function getTableParameter($parameter) { $tableParam = array(); if (!is_array($parameter)) { return $tableParam; } foreach ($parameter as $k => $v) { if (0 != strncmp('db', $k, 2)) { continue; } if ('dbconfig' == $k) { $tableParam[$k] = $v; continue; } $tableParam[substr($k, 2)] = $v; } return $tableParam; } }