本文整理汇总了PHP中Path::fromRelative方法的典型用法代码示例。如果您正苦于以下问题:PHP Path::fromRelative方法的具体用法?PHP Path::fromRelative怎么用?PHP Path::fromRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path::fromRelative方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recent
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'));
}
示例2: image
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;
}
示例3: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$watches = array();
$in = inotify_init();
// add watches starting from root directory
$root = Path::fromRelative('');
$this->addWatches($in, $root, $watches);
printf("\nReading for events\n");
while (true) {
$events = inotify_read($in);
foreach ($events as $event) {
$path = $watches[$event['wd']];
$expanded = $this->expandMask($event['mask']);
$eventName = trim(implode(', ', $expanded), ', ');
// if the event has a name attached, then index that
if ($event['name']) {
$newPathName = $path->getPathname() . '/' . $event['name'];
$newPath = new Path($newPathName);
Indexer::index($newPath, 1);
// this may be a new directory, so add a watch to it anyway
if ($newPath->exists() && $newPath->isDir()) {
try {
$wd = inotify_add_watch($in, $newPath->getPathname(), $this->computedMask);
$watches[$wd] = $newPath;
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
} else {
// event must apply to this directory, so index it, 1 level deep
Indexer::index($path, 1);
}
}
}
}
示例4: index
public function index($requestPath = '')
{
$path = Path::fromRelative('/' . $requestPath);
if (!$path->exists()) {
App::abort(404, 'Path not found');
}
// if it's a file then download
if ($path->isFile()) {
return $this->download($path);
}
$path->loadCreateRecord($path);
$children = $this->exportChildren($path);
$orderParams = $this->doSorting($children);
$groupedStaff = null;
$genres = null;
$categories = null;
$userIsWatching = null;
$pageTitle = null;
$pageDescription = null;
$pageImage = null;
$relatedSeries = null;
if ($series = $path->record->series) {
$groupedStaff = $series->getGroupedStaff();
$genres = $series->getFacetNames('genre');
$categories = $series->getFacetNames('category');
$pageTitle = $series->name;
$pageDescription = $series->description;
if ($series->hasImage()) {
$pageImage = $series->getImageUrl();
}
$relatedSeries = $series->getRelated();
$user = Auth::user();
if ($user) {
$userIsWatching = $user->isWatchingSeries($series);
}
} else {
if (!$path->isRoot()) {
$pageTitle = $path->getRelativeTop();
}
}
$params = array('path' => $path, 'groupedStaff' => $groupedStaff, 'genres' => $genres, 'categories' => $categories, 'breadcrumbs' => $path->getBreadcrumbs(), 'children' => $children, 'userIsWatching' => $userIsWatching, 'pageTitle' => $pageTitle, 'pageDescription' => $pageDescription, 'pageImage' => $pageImage, 'relatedSeries' => $relatedSeries);
$params = array_merge($params, $orderParams);
return View::make('index', $params);
}
示例5: recent
public function recent()
{
Auth::basic('username');
if (!Auth::check()) {
// do auth
Auth::basic('username');
if (!Auth::check()) {
return Response::make(View::make('unauth', array()), 401)->header('WWW-Authenticate', 'Basic');
}
}
$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'));
}
示例6: getPath
public function getPath()
{
return Path::fromRelative($this->path);
}
示例7: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$dryRunOpt = $this->option('dry-run');
if ($dryRunOpt === true) {
$dryRun = true;
} elseif ($dryRunOpt === 'true') {
$dryRun = true;
} elseif ($dryRunOpt === 'false') {
$dryRun = false;
} else {
$this->error('Invalid value for --dry-run');
return;
}
$sourceDirectories = array('/Manga/_Autouploads/AutoUploaded from Assorted Sources');
$movedFiles = array();
// Loop through each auto uploads parent folder
foreach ($sourceDirectories as $sourceDirectory) {
$sourcePath = Path::fromRelative($sourceDirectory);
if (!$sourcePath->exists()) {
$this->error('Source path does not exist: ' . $sourceDirectory);
continue;
}
// Loop through each series dir in the auto uploads folder
$sourceChildren = $sourcePath->getChildren();
foreach ($sourceChildren as $sourceChild) {
$sourceName = $sourceChild->getFilename();
// Look for matching path records by series name
$matchedRecords = PathRecord::join('series', 'series.id', '=', 'path_records.series_id')->join('facet_series', 'facet_series.series_id', '=', 'series.id')->join('facets', 'facets.id', '=', 'facet_series.facet_id')->where('facet_series.type', '=', 'title')->where('facets.name', '=', $sourceName)->get();
// Found a match
if (count($matchedRecords) === 1) {
$matchedRecord = $matchedRecords->first();
$matchedPath = $matchedRecord->getPath();
$seriesChildren = $sourceChild->getChildren();
foreach ($seriesChildren as $seriesChild) {
if ($seriesChild->isDir()) {
$this->error('ERROR: Sub-directory in source series: ' . $seriesChild->getPathName());
continue;
}
$srcFile = $seriesChild->getPathName();
$dstFile = $matchedPath->getPathName() . '/' . $seriesChild->getFilename();
if (file_exists($dstFile)) {
if (filesize($srcFile) === filesize($dstFile) && md5_file($srcFile) === md5_file($dstFile)) {
$dstFile = Path::fromRelative('/Admin cleanup')->getPathName() . '/' . $seriesChild->getFilename();
} else {
$this->error('ERROR: Destination file already exists: ' . $dstFile);
continue;
}
}
$movedFiles[] = array('src' => $srcFile, 'dst' => $dstFile);
$this->info($srcFile . ' -> ' . $dstFile);
}
} else {
$row = DB::connection('mangaupdates')->table('namelist')->where('name', '=', $sourceName)->orWhere('fsSafeName', '=', $sourceName)->first();
$seriesId = null;
if ($row) {
$series = Series::where('mu_id', '=', $row->mu_id)->first();
if (!$series) {
$series = new Series();
$series->mu_id = $row->mu_id;
$series->save();
}
$seriesId = $series->id;
}
$bucket = '# - F';
$chr = strtoupper($sourceName[0]);
if ($chr >= 'N' && $chr <= 'Z') {
$bucket = 'N - Z';
} elseif ($chr >= 'G' && $chr <= 'M') {
$bucket = 'G - M';
}
$dstSeries = Path::fromRelative('/Manga/' . $bucket)->getPathName() . '/' . $sourceName;
if (file_exists($dstSeries)) {
$seriesChildren = $sourceChild->getChildren();
foreach ($seriesChildren as $seriesChild) {
if ($seriesChild->isDir()) {
$this->error('ERROR: Sub-directory in source series: ' . $seriesChild->getPathName());
continue;
}
$srcFile = $seriesChild->getPathName();
$dstFile = $dstSeries . '/' . $seriesChild->getFilename();
if (file_exists($dstFile)) {
if (filesize($srcFile) === filesize($dstFile) && md5_file($srcFile) === md5_file($dstFile)) {
$dstFile = Path::fromRelative('/Admin cleanup')->getPathName() . '/' . $seriesChild->getFilename();
} else {
$this->error('ERROR: Destination file already exists: ' . $dstFile);
continue;
}
}
$movedFiles[] = array('src' => $srcFile, 'dst' => $dstFile);
$this->info($srcFile . ' -> ' . $dstFile);
}
} else {
$movedFiles[] = array('src' => $sourceChild->getPathName(), 'dst' => $dstSeries);
$this->info($sourceChild->getPathName() . ' -> ' . $dstSeries);
}
//.........这里部分代码省略.........
示例8: getBreadcrumbs
public function getBreadcrumbs()
{
if ($this->isRoot()) {
// root fucks with everything...
$path = Path::fromRelative('/');
return array($path);
} else {
$path = trim($this->getRelative(), '/');
$bits = explode('/', $path);
$crumbs = array();
$crumbs[] = Path::fromRelative('/');
for ($i = 1; $i <= count($bits); $i++) {
$path = '/' . implode('/', array_slice($bits, 0, $i));
$crumbs[] = Path::fromRelative($path);
}
return $crumbs;
}
}
示例9: index
public function index($requestPath = '')
{
$path = Path::fromRelative('/' . $requestPath);
if (!$path->exists()) {
Auth::basic('username');
if (!Auth::check()) {
// do auth
Auth::basic('username');
if (!Auth::check()) {
return Response::make(View::make('unauth', array()), 401)->header('WWW-Authenticate', 'Basic');
}
}
App::abort(404, 'Path not found');
}
// if it's a file then download
if ($path->isFile()) {
return $this->download($path);
}
$path->loadCreateRecord($path);
$children = $this->exportChildren($path);
$orderParams = $this->doSorting($children);
$groupedStaff = null;
$genres = null;
$categories = null;
$userIsWatching = null;
$pageTitle = null;
$pageDescription = null;
$pageImage = null;
$relatedSeries = null;
if ($series = $path->record->series) {
$groupedStaff = $series->getGroupedStaff();
$genres = $series->getFacetNames('genre');
$categories = $series->getFacetNames('category');
$pageTitle = $series->name;
$pageDescription = $series->description;
if ($series->hasImage()) {
$pageImage = $series->getImageUrl();
}
$relatedSeries = $series->getRelated();
$user = Auth::user();
if ($user) {
$userIsWatching = $user->isWatchingSeries($series);
}
} else {
if (!$path->isRoot()) {
$pageTitle = $path->getRelativeTop();
}
}
$params = array('path' => $path, 'groupedStaff' => $groupedStaff, 'genres' => $genres, 'categories' => $categories, 'breadcrumbs' => $path->getBreadcrumbs(), 'children' => $children, 'userIsWatching' => $userIsWatching, 'pageTitle' => $pageTitle, 'pageDescription' => $pageDescription, 'pageImage' => $pageImage, 'relatedSeries' => $relatedSeries);
$params = array_merge($params, $orderParams);
$updated = 0;
foreach ($children as $child) {
if (!$child->isDir && $child->rawTime > $updated) {
$updated = $child->rawTime;
}
}
$params['updated'] = $updated;
if (Request::format() == 'atom' || Input::get('t') == 'atom') {
return Response::make(View::make('index-atom', $params))->header('Content-Type', 'application/atom+xml; charset=UTF-8');
} else {
if (Request::format() == 'rss' || Input::get('t') == 'rss') {
return Response::make(View::make('index-rss', $params))->header('Content-Type', 'application/rss+xml; charset=UTF-8');
} else {
Auth::basic('username');
if (!Auth::check()) {
// do auth
Auth::basic('username');
if (!Auth::check()) {
return Response::make(View::make('unauth', array()), 401)->header('WWW-Authenticate', 'Basic');
}
}
return View::make('index', $params);
}
}
}
示例10: getRelated
public function getRelated()
{
$result = DB::table('related_series')->join('series', 'series.mu_id', '=', 'related_series.related_mu_id')->join('path_records', 'path_records.series_id', '=', 'series.id')->select('series.name', 'path_records.path', 'related_series.type')->where('related_series.series_id', '=', $this->id)->get();
foreach ($result as $index => &$row) {
$row->path = Path::fromRelative($row->path);
if (!$row->path->exists()) {
unset($result[$index]);
}
}
return $result;
}