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'));
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 /**
  * 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);
             }
         }
     }
 }
 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);
 }
Beispiel #5
0
 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'));
 }
Beispiel #6
0
 public function getPath()
 {
     return Path::fromRelative($this->path);
 }
 /**
  * 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);
                 }
             }
         }
     }
     if (!$dryRun) {
         foreach ($movedFiles as $move) {
             try {
                 if (is_file($move['src'])) {
                     $dir = dirname($move['src']);
                     if (!is_dir($dir)) {
                         mkdir($dir, 0777, true);
                     }
                 }
                 rename($move['src'], $move['dst']);
             } catch (ErrorException $exception) {
                 $this->error('ERROR: rename() failed: ' . $seriesChild->getPathName() . ' -> ' . $dstFile . ' ' . $exception->getMessage());
             }
         }
     }
     file_put_contents(storage_path() . '/logs/merge-auto-uploads-' . date('Y-m-d-H-i-s'), serialize($movedFiles));
     if (!$dryRun) {
         // Delete empty source folders
         foreach ($sourceDirectories as $sourceDirectory) {
             $sourcePath = Path::fromRelative($sourceDirectory);
             if (!$sourcePath->exists()) {
                 $this->error('Source path does not exist: ' . $sourceDirectory);
                 continue;
             }
             $sourceChildren = $sourcePath->getChildren();
             foreach ($sourceChildren as $sourceChild) {
                 if (count($sourceChild->getChildren()) === 0) {
                     rmdir($sourceChild->getPathName());
                 }
             }
         }
     }
 }
Beispiel #8
0
 public function getBreadcrumbs()
 {
     if ($this->isRoot()) {
         // root f***s 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;
     }
 }
Beispiel #9
0
 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);
         }
     }
 }
Beispiel #10
0
 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;
 }