/** * {@inheritdoc} */ public function getRelativePath(PathInterface $reference) { if ($this->sameValueAs($reference)) { return ''; } $ref_path = array_values($reference->toArray()); $this_path = array_values($this->data); $filename = array_pop($this_path); //retrieve the final consecutive identical segment in the current path $index = 0; foreach ($ref_path as $offset => $value) { if (!isset($this_path[$offset]) || $value != $this_path[$offset]) { break; } $index++; } //deduce the number of similar segment according to the reference path $nb_common_segment = count($ref_path) - $index; $nb_segments = array(); if ($nb_common_segment) { $nb_segments = array_fill(0, $nb_common_segment, '..'); } //let's output the relative path using a new Path object $res = new Path(array_merge($nb_segments, array_slice($this_path, $index), array($filename))); return $res->__toString(); }
public function __construct(\Path $path) { $this->archive = \RarArchive::open($path->getPathName()); if (!$this->archive) { throw new Exception('Failed to open archive'); } }
protected function download(Path $path) { // check basic auth headers as well, so if specified, // client doesn't have to go through the login and cookie dance. Auth::onceBasic("username"); // check we're logged in if (!Auth::check()) { Session::flash('redirect', URL::current()); return Redirect::route('login'); } // record the download in the db $record = $path->loadCreateRecord($path); $record->downloaded_at = $record->freshTimestamp(); $record->increment('downloads'); $record->save(); $isMisc = strpos($path->getRelative(), '/Misc/') === 0; if ($isMisc || $path->isSafeExtension()) { // check if the extension is safe to download $file = new AsciiSafeDownloadFile($path->getPathname()); // see comments in AsciiSafeDownloadFile class $baseName = $path->getBasename(); $baseName = str_replace('%', '', $baseName); try { return Response::download($file, $baseName); } catch (InvalidArgumentException $e) { App::abort(500, 'This file has a malformed filename. Please contact an admin.'); } } else { App::abort(403, sprintf('File type "%s" not allowed', $path->getExtension())); } }
/** * {@inheritdoc} */ public function folder(string $url) : string { $this->validateUrl($url); $parsed = $this->parser->parseUrl($url); $path = new Path($parsed->path); return (string) new ParsedUrl($parsed->scheme, $parsed->user, $parsed->pass, $parsed->host, $parsed->port, (string) $path->folder(), '', ''); }
/** * @dataProvider lineProvider */ public function testLineTo($x, $y, $coords, $result) { $path = new Path($x, $y); foreach ($coords as $coord) { $path->lineTo($coord['x'], $coord['y'], $coord['relative']); } $this->assertEquals($result, (string) $path); }
public function __construct(\Path $path) { $this->archive = new \ZipArchive(); $result = $this->archive->open($path->getPathName()); if (!$result) { throw new Exception('Failed to open archive'); } }
public function encode(Path $path) { $parts = explode(Path::PATH_PART_SEPARATOR, $path->get()); foreach ($parts as $partIndex => $part) { $parts[$partIndex] = rawurlencode($part); } return new Path(implode(Path::PATH_PART_SEPARATOR, $parts)); }
function listACLsByPath($pathname) { $me = $_SERVER["PHP_SELF"]; if (!canEdit($pathname)) { echo "Ihnen fehlt leider die Berechtigung, das Verzeichnis {$pathname} zu bearbeiten"; return false; } // Verzeichnisobjekt holen $path = new Path(); if (!$path->selectByName($pathname)) { fehlerausgabe("Das Verzeichnis {$pathname} konnte nicht aus der DB gewählt werden"); return false; } // ACLs fuer das Verzeichnis holen $acllist = new ACLList(); if (!$acllist->selectByPath($pathname)) { fehlerausgabe("Die zum Verzeichnis {$pathname} gehörigen ACLs konnten nicht aus der DB gewählt werden"); return false; } echo "ACLs für Pfad {$pathname}:"; echo <<<EOF <form name="acleditor" method="post" action="{$me}"> <select name="cmd"> <option value="edit">Eine ACL bearbeiten</option> <option value="del">Löschen</option> </select> <input type="hidden" name="pathname" value="{$pathname}" /> <input type="submit" value="Los" /> <br /> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed"> <tr> <td>User</td> <td>Löschen</td> <td>Schreiben</td> <td>Lesen</td> <td>Umbenennen</td> </tr> EOF; $user = new User(); for ($i = 0; $i < count($acllist->list); $i++) { $acl = $acllist->list[$i]; $user->selectByID($acl->user_id); echo <<<EOF <tr> <td><input type="checkbox" name="aclid[]" value="{$acl->acl_id}" />{$user->loginname}</td> <td>{$acl->delete_path}</td> <td>{$acl->write_path}</td> <td>{$acl->read_path}</td> <td>{$acl->rename_path}</td> </tr> EOF; } echo <<<EOF </table> </form> EOF; return true; }
function sinvactu() { parent::Controller(); $this->load->library("rapyd"); $this->load->library("path"); $path = new Path(); $path->setPath($this->config->item('uploads_dir')); $path->append('/archivos'); $this->upload_path = $path->getPath() . '/'; }
function Catalogo() { parent::Controller(); $this->load->library("rapyd"); $this->load->library("path"); $path = new Path(); $path->setPath($this->config->item('uploads_dir')); $path->append('/inventario'); $this->upload_path = $path->getPath(); }
public function match(Path $path) { $values = array(); if (preg_match($this->regex, $path->value(), $values) == 1) { array_shift($values); $this->parameterValues = $values; return true; } return false; }
function modulos() { parent::Controller(); $this->load->library("rapyd"); $this->load->library("path"); $path = new Path(); $path->setPath($this->config->item('uploads_dir')); $path->append('/graficos'); $this->upload_path = $path->getPath() . '/'; }
function logo() { parent::Controller(); $this->load->library("rapyd"); $this->load->helper('download'); $this->load->library("path"); $path = new Path(); $path->setPath($this->config->item('base_url')); $path->append('images'); echo $this->upload_path = $path->getPath() . '/'; }
function Publicidad() { parent::Controller(); $this->load->library("rapyd"); $this->load->library("path"); $path = new Path(); $path->setPath($this->config->item('uploads_dir')); $path->append('publicidad'); $this->upload_path = $path->getPath() . '/'; //$this->datasis->modulo_id(907,1); }
function logo() { parent::Controller(); $this->load->library('rapyd'); $this->load->helper('download'); $this->load->library('path'); $path = new Path(); $path->setPath($this->config->item('base_url')); $path->append('images'); $this->upload_path = $path->getPath() . '/'; $this->write = is_writable('images'); }
protected function exportChildren(Path $path) { $children = array(); $pathChildren = $path->getChildren(); foreach ($pathChildren as $child) { $hash = $child->getHash(); $children[] = Cache::tags('paths')->rememberForever($hash, function () use($child) { return $child->export(); }); } return $children; }
function selectAll() { $dbq = new DB(); $dbq->db_connect(); $query = "SELECT path_id, loginname, pathname, description, insert_at, modified_at, path_id_parent\n FROM sage_path\n WHERE pathname REGEXP '[/]'"; $paths = $dbq->db_select($query); for ($i = 0; $i < count($paths); $i++) { $path = new Path(); $path->initializeFromRow($paths[$i]); $this->list[] = $path; } return true; }
function cargasinv() { parent::Controller(); $this->load->library("rapyd"); $this->load->library("path"); $this->load->library('encrypt'); $this->load->helper('string'); $path = new Path(); $path->setPath($this->config->item('uploads_dir')); $path1 = reduce_double_slashes(FCPATH . '/uploads/archivos'); $path->append('/archivos'); $this->upload_path = $path->getPath() . '/'; }
public static function open(\Path $path) { $ext = $path->getExtension(); switch ($ext) { case 'zip': case 'cbz': return new ZipArchive($path); case 'rar': case 'cbr': return new RarArchive($path); default: throw new \Exception('Invalid file type: ' . $ext); } }
private function getServerFiles($config, $destination) { $path = Path::assemble(BASE_PATH, $destination); $finder = new Finder(); // Set folder location $finder->in($path); // Limit by depth $finder->depth('<' . array_get($config, 'depth', '1')); // Limit by file extension foreach (array_get($config, array('allowed', 'types'), array()) as $ext) { $finder->name("/\.{$ext}/i"); } // Fetch matches $matches = $finder->files()->followLinks(); // Build array $files = array(); foreach ($matches as $file) { $filename = Path::trimSubdirectory(Path::toAsset($file->getPathname(), false)); $display_name = ltrim(str_replace($path, '', $file->getPathname()), '/'); $value = (Config::get('prepend_site_root_to_uploads', false)) ? '{{ _site_root }}' . ltrim($filename, '/') : $filename; $files[] = compact('value', 'display_name'); } return $files; }
/** * Create the classpath to be used when searching for component being defined * * @return Path */ public function createClasspath() { if ($this->classpath === null) { $this->classpath = new Path($this->project); } return $this->classpath->createPath(); }
private function _createFromReflection($projectName) { $this->_name = $projectName; $this->_dir = \Fstab::instance()->projectDirectory($projectName); $controllerBasePath = rtrim(\Path::instance()->evaluate(":{$this->_name}.apps.controller"), "/\\"); foreach (glob($controllerBasePath . "/*.php") as $filePath) { $fileName = pathinfo($filePath, PATHINFO_FILENAME); $controllerClassName = $fileName . 'Controller'; if (!class_exists($controllerClassName)) { require $filePath; } if (class_exists($controllerClassName)) { $reflection = new \ReflectionClass($controllerClassName); $this->_controllers[] = AppController::create($this, $reflection); } } $spiritBasePath = rtrim(\Path::instance()->evaluate(":{$this->_name}.spiritPath"), "/\\"); foreach (glob($spiritBasePath . "/*", GLOB_ONLYDIR) as $dirName) { $spiritName = pathinfo($dirName, PATHINFO_FILENAME); $spiritFileName = rtrim($dirName, "/\\") . '/abstractor.php'; $spiritAbstractorClassName = $spiritName . 'Abstractor'; if (!class_exists($spiritAbstractorClassName) && file_exists($spiritFileName)) { require $spiritFileName; } if (class_exists($spiritAbstractorClassName)) { $reflection = new \ReflectionClass($spiritAbstractorClassName); $this->_spirits[] = SpiritController::create($this, $reflection); } } }
public static function go_to($url) { if (!isset(self::$instance)) { self::$instance = new self(); } return self::$root_path . $url; }
public function recent() { $records = $this->getRecentRecords(); $paths = array(); $bucket = array(); $currentParent = null; foreach ($records as $record) { $path = Path::fromRelative($record->path); if ($path->exists()) { $path->record = $record; $parent = $path->getParent(); if ($currentParent === null) { $currentParent = $parent; } // if this path's parent is the same as the previous, add it to the bucket if ($parent->getHash() === $currentParent->getHash()) { $bucket[] = $path; } else { // if's different, add it to the paths array and start a new bucket $paths[] = array('parent' => $currentParent, 'paths' => $bucket); $bucket = array($path); $currentParent = $parent; } } } if (count($bucket) > 0) { $paths[] = array('parent' => $currentParent, 'paths' => $bucket); } return View::make('recent', array('pathBuckets' => $paths, 'pageTitle' => 'Recent uploads')); }
public static function get_file($call) { if (!empty($call['file'])) { return Path::get_path_from_root($call['file']); } return 'Internal'; }
function removeAll($removeAttachments = true) { global $database; $blogid = getBlogId(); POD::query("UPDATE {$database['prefix']}BlogStatistics SET visits = 0 WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}DailyStatistics WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}Categories WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}Attachments WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}Comments WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}RemoteResponses WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}RemoteResponseLogs WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}TagRelations WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}Entries WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}Links WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}Filters WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}RefererLogs WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}RefererStatistics WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}Plugins WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}FeedStarred WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}FeedReads WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}FeedGroupRelations WHERE blogid = {$blogid}"); POD::query("DELETE FROM {$database['prefix']}FeedGroups WHERE blogid = {$blogid}"); if (file_exists(__TEXTCUBE_CACHE_DIR__ . "/rss/{$blogid}.xml")) { unlink(__TEXTCUBE_CACHE_DIR__ . "/rss/{$blogid}.xml"); } if ($removeAttachments) { Path::removeFiles(Path::combine(ROOT, 'attach', $blogid)); } }
public function index($value, $parameters = array()) { $full_url_start = Config::getSiteURL() . Config::getSiteRoot(); return preg_replace_callback('/="(\\/[^"]+)"/ism', function ($item) use($full_url_start) { return '="' . Path::tidy($full_url_start . $item[1]) . '"'; }, $value); }
public function download__download() { $file = Request::get('file'); $filename = Path::fromAsset($file); $as = Request::get('as', $file); $logged_in = filter_var(Request::get('logged_in', true), FILTER_VALIDATE_BOOLEAN); $override = Request::get('override'); if (!$logged_in) { // first make sure there's an override in the config $override_config = $this->fetchConfig('override'); if (!$override_config) { die('No override key configured'); } // now see if there's an override param if (!$override) { die('No override param'); } if ($override_config != $override) { die("Override key & param don't match"); } } elseif (!Auth::isLoggedIn()) { // if the user has to be logged in, see if they are die('Must be logged in'); } if (!$this->download($filename, $as)) { die('File doesn\'t exist'); } }
public function image() { if (!Auth::check()) { Session::flash('redirect', URL::current()); return Redirect::route('login'); } $relativePath = Input::get('path'); $filePath = Input::get('file'); $path = Path::fromRelative($relativePath); if (!$path->exists()) { App::abort(404, 'Archive not found'); } $archive = Archive\Factory::open($path); $imageStream = $archive->getEntryStream($filePath); $imageData = stream_get_contents($imageStream); $response = Response::make($imageData); $ext = pathinfo($filePath, PATHINFO_EXTENSION); switch ($ext) { case 'jpg': case 'jpeg': $response->header('Content-Type', 'image/jpeg'); break; case 'png': $response->header('Content-Type', 'image/png'); break; } $response->header('Last-Modified', gmdate('D, d M Y H:i:s', $path->getMTime()) . ' GMT'); $response->header('Expires', gmdate('D, d M Y H:i:s', strtotime('+1 year')) . ' GMT'); $response->header('Cache-Control', 'public'); return $response; }
public function setUp() { $this->backup = new Backup('backup.zip'); $this->setup_test_data(); Path::get_instance()->set_path($this->test_data . '/tmp'); Path::get_instance()->set_root($this->test_data); }