/** * Get author's pictures * * @return Picture[] */ public function pics() { if (!$this->pics) { $this->pics = Picture::fetch($this); if ($blacklist = $this->album->meta('blacklist') and isset($blacklist[$this->name])) { $this->pics = array_diff_key($this->pics, array_flip($blacklist[$this->name])); } } return $this->pics; }
/** * Generate albums cache * * @json * * @param Context $ctx * @return array */ public function cacheClear(Context $ctx) { set_time_limit(300); $files = $ctx->request->value('files'); $files = explode(',', $files); $states = []; foreach ($files as $file) { $author = dirname($file); $album = dirname($author); $album = new Album($album); $author = $album->author(basename($author)); $pic = $author->pic(basename($file)); $state = $pic->cache(true); if ($state === null) { $states[] = [str_replace(ALBUMS_DIR, null, $file), 'skipped']; } elseif ($state === true) { $states[] = [str_replace(ALBUMS_DIR, null, $file), 'done']; } else { $states[] = [str_replace(ALBUMS_DIR, null, $file), 'failed']; } } return $states; }
/** * Rotate picture to right * * @param int $year * @param int $month * @param int $day * @param string $flatname * @param Context $ctx * @return array * * @throws NotFoundException */ public function rotateRight($year, $month, $day, $flatname, Context $ctx) { $year = (int) $year; $month = (int) $month; $day = (int) $day; // get post data and album $album = Album::one($year, $month, $day, $flatname); list($author, $filename) = $ctx->post('author', 'filename'); if (!$album or !($author = $album->author($author)) or !($picture = $author->pic($filename))) { throw new NotFoundException(); } // rotate if (!$picture->rotateRight()) { return ['state' => false, 'message' => 'Not implemented']; } $ctx->logger->info($ctx->user->username . ' rotates picture "' . $picture->filename . '" to right in "' . $album->fullname . '"', $_POST); return ['state' => true]; }
/** * Download album as .zip * * @param int $year * @param int $month * @param int $day * @param string $flatname * @return Response\Download * * @throws HttpException * @throws NotFoundException */ public function download($year, $month, $day, $flatname) { $year = (int) $year; $month = (int) $month; $day = (int) $day; // get album $album = Album::one($year, $month, $day, $flatname); if (!$album) { throw new NotFoundException(); } try { // create zip file $zipname = $album->zip(); $ctx->logger->info($ctx->user->username . ' downloads "' . $album->fullname . '"'); return Response::download($zipname)->header('Content-Type', 'application/zip'); } catch (\Exception $e) { throw new HttpException(); } }
/** * Display map of all albums * * @html albums/map */ public function map() { if (!MAPBOX_TOKEN or !MAPBOX_PROJECT) { throw new NotFoundException(); } $albums = Album::fetch(); // keep only album with meta place foreach ($albums as $index => $album) { if (!$album->meta('place')) { unset($albums[$index]); } } return ['albums' => $albums, 'ariane' => []]; }