Beispiel #1
0
 /**
  * Action: flyer
  */
 public function action_flyer()
 {
     $flyer_id = $this->request->param('id');
     switch ($flyer_id) {
         // Random flyer
         case 'random':
             // Random undated flyer
         // Random undated flyer
         case 'undated':
             $flyer = Model_Flyer::factory()->find_random($flyer_id == 'undated');
             $this->request->redirect(Route::get('flyer')->uri(array('id' => $flyer->id)));
             break;
             // Known flyer
         // Known flyer
         default:
             /** @var  Model_Flyer  $flyer */
             $flyer = new Model_Flyer((int) $flyer_id);
             if (!$flyer->loaded()) {
                 throw new Model_Exception($flyer, $flyer_id);
             }
     }
     /** @var  Model_Image  $image */
     $image = $flyer->image();
     /** @var  Model_Event  $event */
     $event = $flyer->event();
     // Handle post
     $errors = array();
     if ((isset($_POST['event_id']) || isset($_POST['name'])) && Security::csrf_valid()) {
         Permission::required($flyer, Model_Flyer::PERMISSION_UPDATE, self::$user);
         try {
             if ($event_id = (int) Arr::get($_POST, 'event_id')) {
                 // Event given?
                 /** @var  Model_Event  $event */
                 $event = new Model_Event($event_id);
                 if ($event->loaded()) {
                     $flyer->set_fields(array('event_id' => $event->id, 'stamp_begin' => $event->stamp_begin));
                 }
             } else {
                 if (Arr::get($_POST, 'name')) {
                     // Name and stamp given
                     $flyer->set_fields(Arr::intersect($_POST, array('name', 'stamp_begin')));
                 }
             }
             // Save only if we got full date
             if ($flyer->has_full_date()) {
                 $flyer->save();
                 // Newsfeed
                 NewsfeedItem_Galleries::flyer_edit(self::$user, $flyer);
             }
             $this->request->redirect(Route::get('flyer')->uri(array('id' => $flyer->id)));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Comments section
     if (Permission::has($flyer, Model_Flyer::PERMISSION_COMMENTS, self::$user)) {
         $errors = array();
         $values = array();
         // Handle comment
         if (Permission::has($flyer, Model_Flyer::PERMISSION_COMMENT, self::$user) && $_POST) {
             try {
                 $comment = Model_Image_Comment::factory()->add(self::$user->id, $image, Arr::get($_POST, 'comment'), Arr::get($_POST, 'private'));
                 $image->comment_count++;
                 if ($image->author_id != self::$user->id) {
                     $image->new_comment_count++;
                 }
                 $image->save();
                 // Newsfeed
                 if (!$comment->private) {
                     NewsfeedItem_Galleries::comment_flyer(self::$user, $flyer, $image);
                 }
                 if (!$this->ajax) {
                     $this->request->redirect(Route::get('flyer')->uri(array('id' => $image->id, 'action' => '')));
                 }
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validation');
                 $values = $comment;
             }
         } else {
             if (self::$user && $image->author_id == self::$user->id && $image->new_comment_count > 0) {
                 // Clear new comment count?
                 $image->new_comment_count = 0;
                 $image->save();
             }
         }
         // Get view
         $section_comments = $this->section_image_comments($image, 'flyer_comment');
         $section_comments->errors = $errors;
         $section_comments->values = $values;
     } else {
         if (!self::$user) {
             // Guest user
             $section_comments = $this->section_image_comments_teaser($image->comment_count);
         }
     }
     if (isset($section_comments) && $this->_request_type === Controller::REQUEST_AJAX) {
         $this->response->body($section_comments);
         return;
     }
     // Build page
     $this->view = View_Page::factory(__('Flyer'));
     $this->_set_page_actions();
     $this->_set_flyer_actions($flyer);
     // Set title
     if ($event) {
         // Flyer is linked to an event
         $this->view->title = $event->name;
         $this->view->subtitle = HTML::time(date('l ', $event->stamp_begin) . Date::format(Date::DMY_SHORT, $event->stamp_begin), $event->stamp_begin, true);
         // Facebook
         if (Kohana::$config->load('site.facebook')) {
             Anqh::open_graph('title', __('Flyer') . ': ' . $event->name);
             Anqh::open_graph('url', URL::site(Route::get('flyer')->uri(array('id' => $flyer->id, 'action' => '')), true));
             Anqh::open_graph('description', date('l ', $event->stamp_begin) . Date::format(Date::DMY_SHORT, $event->stamp_begin) . ' @ ' . $event->venue_name);
             Anqh::open_graph('image', URL::site($image->get_url('thumbnail'), true));
         }
     } else {
         // Flyer is not linked to an event
         $this->view->title = $flyer->name;
         $this->view->subtitle = $flyer->has_full_date() ? HTML::time(date('l ', $flyer->stamp_begin) . Date::format(Date::DMY_SHORT, $flyer->stamp_begin), $flyer->stamp_begin, true) : __('Date unknown');
         // Facebook
         if (Kohana::$config->load('site.facebook')) {
             Anqh::open_graph('title', __('Flyer') . ': ' . $flyer->name);
             Anqh::open_graph('url', URL::site(Route::get('flyer')->uri(array('id' => $flyer->id, 'action' => '')), true));
             $flyer->has_full_date() and Anqh::open_graph('description', date('l ', $flyer->stamp_begin) . Date::format(Date::DMY_SHORT, $flyer->stamp_begin));
             Anqh::open_graph('image', URL::site($image->get_url('thumbnail'), true));
         }
     }
     Anqh::share(true);
     // Edit flyer
     if (Permission::has($flyer, Model_Flyer::PERMISSION_UPDATE, self::$user)) {
         $section = $this->section_flyer_edit($flyer);
         $section->error = $errors;
         $this->view->add(View_Page::COLUMN_TOP, $section);
     }
     // Flyer
     $image->view_count++;
     $image->save();
     $this->view->add(View_Page::COLUMN_TOP, $this->section_flyer($image));
     // Comments
     if (isset($section_comments)) {
         $this->view->add(View_Page::COLUMN_MAIN, $section_comments);
     }
 }
Beispiel #2
0
Datei: api.php Projekt: anqh/anqh
 /**
  * Action: event
  */
 public function action_event()
 {
     $event_id = Arr::get($_REQUEST, 'id');
     // Load event
     $event = new Model_Event($event_id);
     if ($event->loaded()) {
         $this->data['events'] = array($this->_prepare_event($event));
     } else {
         $this->data['events'] = array();
     }
 }