Beispiel #1
0
 public function action_view($photo_id)
 {
     $photo = ORM::factory('photo')->where('id', '=', $photo_id)->where('moderation_status_id', '=', '2')->find();
     if ($photo->loaded()) {
         if (isset($_POST['comment'])) {
             Request::factory('comments/on/' . $photo_id)->execute();
         }
         if (isset($_POST['awards']) && Helper_Account::is_admin()) {
             $gamePhoto = Helper_Game::getUser($photo->user->id)->getItem($photo_id);
             foreach ($_POST['awards'] as $awardId) {
                 $award = ORM::factory('game_Award', $awardId);
                 if (!$gamePhoto->hasAward($award)) {
                     $gamePhoto->addAward($award);
                     Helper_Game::logEvent(Helper_Game::AWARD_GIVEN, $photo->user->id, $photo->id, array('honor_id' => $award->id, 'type' => 'game_Award'));
                 }
             }
             Message::set(Message::SUCCESS, 'Awards updated.');
         }
         //get dimensions if not present
         if (empty($photo->width)) {
             try {
                 $akm = Library_Akamai::factory();
                 $akm->pull($photo->original);
                 $location = Kohana::config('myshot.basePath') . $photo->original;
                 $img = Image::factory($location);
                 $photo->width = $img->width;
                 $photo->height = $img->height;
                 $photo->save();
                 unlink($location);
             } catch (Kohana_Exception $e) {
                 //don't do anything. It is jut too late to get the size of the photo
             }
         }
         $photo->increment_view();
         $dphoto = ORM::factory("DailyPhoto")->order_by("day", "DESC")->find();
         $galleries = ORM::factory("gallery")->find_all();
         $gall_ids = array();
         foreach ($galleries as $gallery) {
             //array_push($gall_ids, array($gallery->id => $gallery->name));
             $gall_ids[$gallery->id] = $gallery->name;
         }
         $user_photos = $photo->user->photos->where('moderation_status_id', '=', '2')->order_by('order', 'ASC')->find_all();
         $this->template->title = $photo->name . ' Photo - National Geographic Kids My Shot';
         $this->template->content = View::factory('photos/view');
         $this->template->content->set(array('user' => $photo->user, 'photo' => $photo, 'user_owns_page' => $photo->user->id == $this->user->id, 'allAwards' => Helper_Game::getSite()->awards, 'awards' => Helper_Game::getUser($photo->user->id)->getItem($photo->id)->awards, 'isaFan' => $this->user->id ? Helper_Game::getUser($this->user->id)->isFollowing($photo->user->id) : false, 'isFav' => $this->user->isFavorite($photo_id), 'loggedin' => $this->user->id !== null, 'user_photos' => $user_photos, 'order' => Helper_Photos::get_order_array($user_photos), 'comments' => $photo->readableComments(), 'lastDaily' => $dphoto, 'awaiting_comments' => ORM::factory('comment')->where('photo_id', '=', $photo_id)->where('moderation_status_id', '=', '1')->where('user_id', '=', $this->user->id)->find_all()));
         $this->template->content->galleries = $gall_ids;
         $this->template->styles = array('public/js/vendor/rating/jquery.rating.css' => 'screen', 'public/js/vendor/datepicker/jquery-ui-1.8.5.custom.css' => 'screen');
         $this->template->scripts = array('public/js/vendor/rating/jquery.MetaData.js', 'public/js/vendor/rating/jquery.rating.pack.js', 'public/js/vendor/jquery.jcarousel.js', 'public/js/vendor/swfobject.js', 'public/js/photos/view.js', 'public/js/vendor/word-count.js', 'public/js/vendor/jquery.tools.min.js', 'public/js/vendor/jquery-ui-1.8.5.custom.min.js', 'public/js/vendor/fl_runcontent.js', 'public/js/photos/caption-this.js', 'public/js/photos/award.js');
         $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar());
     } else {
         Message::set(Message::NOTICE, 'The photo you requested doesn\'t exist!');
         Request::instance()->redirect('/');
     }
 }