Beispiel #1
0
 /**
  * Edit album details
  *
  * @access 5
  * @json
  *
  * @param int $year
  * @param int $month
  * @param int $day
  * @param string $flatname
  * @param Context $ctx
  * @return array
  * @throws NotFoundException
  */
 public function edit($year, $month, $day, $flatname, Context $ctx)
 {
     $year = (int) $year;
     $month = (int) $month;
     $day = (int) $day;
     // get album
     $album = Album::one($year, $month, $day, $flatname);
     if (!$album) {
         throw new NotFoundException();
     }
     try {
         // get form data
         list($name, $date, $meta) = $ctx->post('name', 'date', 'meta');
         list($day, $month, $year) = explode('/', $date);
         $newauthors = $ctx->post('authors');
         // update author list
         if ($newauthors and $ctx->user->isAdmin()) {
             $authors = $album->authors();
             foreach ($newauthors as $oldname => $newname) {
                 if ($oldname != $newname and isset($authors[$oldname])) {
                     $authors[$oldname]->rename($newname);
                 }
             }
         }
         // update meta
         $album->edit($meta);
         // attempt update
         $year = (int) $year;
         $month = (int) $month;
         $day = (int) $day;
         if ($name != $album->name or $year != $album->year or $month != $album->month or $day != $album->day) {
             $oldalbum = $album->fullname;
             $album->rename($year, $month, $day, $name);
             $ctx->logger->info($ctx->user->username . ' edits album "' . $oldalbum . '" to "' . $album->fullname . '"', $_POST);
         }
         return ['state' => true, 'redirect' => (string) $ctx->url($album->url)];
     } catch (AuthorAlreadyExists $e) {
         return ['state' => false, 'message' => text('logic.author.already-exists')];
     } catch (AlbumAlreadyExists $e) {
         return ['state' => false, 'message' => text('logic.album.already-exists')];
     } catch (InvalidAlbumDate $e) {
         return ['state' => false, 'message' => text('logic.album.invalid-date')];
     } catch (InvalidAlbumName $e) {
         return ['state' => false, 'message' => text('logic.album.invalid-name')];
     } catch (\Exception $e) {
         return ['state' => false, 'message' => text('logic.album.cannot-edit')];
     }
 }
Beispiel #2
0
 /**
  * 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];
 }
Beispiel #3
0
 /**
  * Send feedback to admin
  *
  * @access 1
  *
  * @param Context $ctx
  * @return array
  */
 public function feedback(Context $ctx)
 {
     // get post data
     list($message, $album) = $ctx->post('message', 'album');
     if (!$message) {
         return ['state' => false, 'message' => text('logic.feedback.empty')];
     }
     // send mail
     $email = new Mail(APP_NAME . ' - Feedback ' . $ctx->user->username);
     $email->from($ctx->user);
     if ($album) {
         $email->content = '--- <br/>';
         $email->content .= strip_tags($album) . '<br/>';
         $email->content .= '--- <br/><br/>';
     }
     $email->content .= strip_tags($message);
     $email->content .= '<br/><br/>';
     $email->content .= $ctx->user->username;
     $email->send(ADMIN_EMAIL);
     return ['state' => true];
 }
Beispiel #4
0
 /**
  * Handle exception
  *
  * @param \Exception $error
  * @param Context $context
  * @return Context
  *
  * @throws \Exception
  */
 protected function error(\Exception $error, Context $context = null)
 {
     $exception = get_class($error);
     $this->logger->error($error);
     if ($this->catch) {
         foreach ($this->errors as $class => $callback) {
             if (is_string($class) and $error instanceof $class) {
                 $context->error = $error;
                 $this->logger->debug('kernel.error: ' . $exception . ' raised, has callback');
                 return $context->forward($callback, $error);
             }
         }
     }
     $this->logger->debug('kernel.error: ' . $exception . ' raised, no callback');
     throw $error;
 }