public function action_index($id) { $page = Model_Page::getBySlug($id, false); if (!$page || !$page->isPublished() && !Helper_Account::is_admin(Auth::instance()->get_user())) { $this->template->content = View::factory("errors/index"); return; } $this->template->content = View::factory("page/index")->set("page", $page); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
public function action_index($id) { $gallery = Model_Gallery::getBySlug($id, false); if (!$gallery || !$gallery->isPublished() && !Helper_Account::is_admin(Auth::instance()->get_user())) { $this->template->content = View::factory("errors/index"); return; } $this->template->content = View::factory("gallery/index")->set("gallery", $gallery); $this->template->content->reel = Reel::factory($gallery->photos); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
public function action_page($slug) { $page = Model_Page::getBySlug($slug, false); if ($page) { $this->template->content = View::factory("myshot/index"); $this->template->content->page = $page; $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); } else { $this->template->content = "No page available"; //redirect instead? } }
/** * View the tag page. * * @return void * @author Merrick Christensen */ public function action_view($id = NULL) { $tag = ORM::factory('tag')->where('id', '=', $id)->find(); $this->template->title = 'View Photos Tagged ' . $tag->name . ' - National Geographic Kids My Shot'; $this->template->content = View::factory('tags/index'); if ($tag->loaded()) { $this->template->content->set(array('tag' => $tag, 'reel' => Reel::factory($tag->photos->order_by("photos.created", "desc")))); } else { Message::set(Message::NOTICE, "This tag does not exist."); Request::instance()->redirect('/'); } $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
/** * View the homepage. * * @return void * @author Merrick Christensen */ public function action_index() { $this->template->title = 'Share Your Photos - National Geographic Kids My Shot Community'; $this->template->scripts = array('public/js/vendor/jquery.jcarousel.js', 'public/js/categories/slideshow.js', 'public/js/home/home.js'); $awards = array(); $badges = array(); $events = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Model_Game_Site::HONOR_GIVEN))->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all(); foreach ($events as $event) { $eventUser = ORM::factory('user', $event->user->user_id); if ($eventUser->id) { if ($event->data->type == "game_Badge") { $obj = new stdClass(); $obj->data = $event->data; $obj->honor = ORM::factory($event->data->type, $event->data->honor_id); $obj->user = ORM::factory('user', $event->user->user_id); $badges[] = $obj; } } if (count($badges) >= $this->maxBadges) { break; } } if (count($awards) < $this->maxAwards) { $aevents = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Helper_Game::AWARD_GIVEN)->id)->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all(); foreach ($aevents as $event) { $obj = new stdClass(); $obj->data = $event->data; $obj->honor = ORM::factory($event->data->type, $event->data->honor_id); $obj->user = ORM::factory('user', $event->user->user_id); $obj->photo = ORM::factory('photo', $event->item->item_id); $awards[] = $obj; if (count($awards) >= $this->maxAwards) { break; } } } $honors = array_merge($awards, $badges); if (count($honors) == 0) { $honors = false; } $slider = Model_DLSliderGroup::getCurrentSlider(); if ($slider) { $this->template->top = View::factory("home/slider"); $this->template->top->slider = $slider; } $this->template->content = View::factory('home/index'); $this->template->content->set(array('user' => $this->user, 'recently_added' => Reel_More::factory(ORM::factory('photo')->order_by('created', 'desc')), 'top_rated' => Reel_More::factory(Helper_Photos::get_top_rated()), 'honors' => $honors, 'potd' => Model_DailyPhoto::todaysPhoto(), 'homeSpot' => Model_Homespot::getCurrent())); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
private function buildPage(Model_CaptionThisPhoto $caption_this_photo, View $view) { $photo_id = $caption_this_photo->photo_id; $photo = ORM::factory('photo')->where('id', '=', $photo_id)->find(); if ($photo->loaded()) { $photo->increment_view(); /* * load all captions associated with photo and sort them by rating */ $captions = DB::select('captions.*', array('AVG("caption_ratings.rating")', 'avg_rating'))->from('captions')->join('caption_ratings', 'LEFT')->on('captions.id', '=', 'caption_ratings.caption_id')->where('captions.photo_id', '=', $photo_id)->where('moderation_status_id', '=', 2)->group_by('captions.id')->order_by('avg_rating', 'DESC')->as_object('Model_Caption')->execute(); $past_caption_this_photos = ORM::factory('captionthisphoto')->where('from', '<=', date('Y-m-d'))->order_by("to", "DESC")->find_all(); $this->template->title = 'Back Talk - National Geographic Kids My Shot'; $this->template->content = $view; $this->template->content->set(array('user' => $photo->user, 'photo' => $photo, 'caption_this_photo' => $caption_this_photo, 'captions' => $captions, 'past_caption_this_photos' => $past_caption_this_photos, 'awaiting_captions' => ORM::factory('caption')->where('photo_id', '=', $photo_id)->where('moderation_status_id', '!=', '2')->where('user_id', '=', $this->user->id)->find_all())); $this->template->styles = array('public/js/vendor/rating/jquery.rating.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/photos/caption.js', 'public/js/vendor/word-count.js'); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); } }
public function action_award($id = null) { if ($id == null) { Request::instance()->redirect('/trophies/'); } else { $award = ORM::factory("game_Award", $id); if ($award->deleted) { Request::instance()->redirect('/trophies/'); } else { $this->template->content = View::factory("trophy/award"); $this->template->content->award = $award; $this->template->content->aItems = $aItems = $award->_items->order_by("id", "desc")->offset($this->numPerPage * (!empty($_GET['page']) ? filter_input(INPUT_GET, "page", FILTER_SANITIZE_NUMBER_INT) : 0))->limit($this->numPerPage)->find_all(); $pagination = Pagination::factory(array("items_per_page" => $this->numPerPage, "total_items" => $award->_items->count_all())); $this->template->content->pagination = $pagination; $this->totalItems = $award->_items->count_all(); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); } } }
/** * View the category page. * * @return void * @author Merrick Christensen */ public function action_index($id = NULL) { $category = ORM::factory('category')->where('id', '=', $id)->find(); $this->template->title = 'View ' . $category->name . ' Photos - National Geographic Kids My Shot'; $this->template->scripts = array('public/js/categories/slideshow.js'); $this->template->content = View::factory('categories/index'); // Take a deep breath! $featured = DB::query(Database::SELECT, 'SELECT * FROM (SELECT `photos`.`id` AS `id`, `ratings`.`id` AS `rating_id`, `photos`.`moderation_status_id`, `photos`.`category_id`, `photos`.`user_id`, `photos`.`name`, `photos`.`caption`, `photos`.`thumbnail`, `photos`.`small`, `photos`.`medium`, `photos`.`large`, `photos`.`original`, `photos`.`file_type`, `photos`.`order`, `photos`.`created`, Avg(`rating`) AS `rating` FROM `ratings` JOIN `photos` ON ( `photos`.`id` = `ratings`.`photo_id` ) WHERE `category_id` = ' . $id . ' GROUP BY `photo_id` ORDER BY `rating` DESC LIMIT 20) AS top_rated ORDER BY Rand() LIMIT 5')->as_object('Model_Photo'); // Did you make it? if ($category->loaded()) { $this->template->content->set(array('category' => $category, 'reel' => Reel::factory(ORM::factory('photo')->where('category_id', '=', $id)->order_by('created', 'desc')), 'featured_photos' => $featured->execute())); } else { Message::set(Message::NOTICE, "This category does not exist."); Request::instance()->redirect('/'); } $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
public function action_confirm($photo_id) { if (Helper_Account::is_admin()) { $photo = ORM::factory('photo')->where('id', '=', $photo_id)->find(); } else { $photo = ORM::factory('photo')->where('id', '=', $photo_id)->where('user_id', '=', $this->user->id)->find(); } if ($photo->loaded()) { $this->template->content = View::factory('photos/confirm'); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); $this->template->content->set(array('photo' => $photo)); $this->template->scripts = array("public/js/photos/confirm.js"); } else { Message::set(MESSAGE::NOTICE, 'We couldn\'t find this photo!'); Request::instance()->redirect('/'); } }
/** * Successful avatar upload. * * @return void * @author Merrick Christensen */ public function action_success() { $avatar = $this->user->avatar; if ($avatar->loaded()) { $this->template->content = View::factory('account/success'); $this->template->content->set(array('user' => $this->user, 'avatar' => $avatar)); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); } else { Message::set(Message::NOTICE, 'The avatar you requested doesn\'t exist!'); Request::instance()->redirect('/'); } }
/** * View the 404 page * * @return void * @author Merrick Christensen */ public function action_404() { $this->template->content = View::factory('errors/index'); $this->template->content->set(array('user' => $this->user)); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
public function before() { parent::before(); $this->template->content = View::factory('archive/view'); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
public function action_preview($id) { $id = filter_var($id, FILTER_SANITIZE_NUMBER_INT); $homeSpot = ORM::factory("homespot", $id); if (!$homeSpot->loaded()) { Message::set(Message::ERROR, "Sorry, that could not be found."); $this->request->redirect("admin/home/create"); return; } $this->template->title = 'Share Your Photos - National Geographic Kids My Shot Community'; $this->template->scripts = array('public/js/vendor/jquery.jcarousel.js', 'public/js/categories/slideshow.js', 'public/js/home/home.js'); $awards = array(); $badges = array(); $events = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Model_Game_Site::HONOR_GIVEN))->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all(); foreach ($events as $event) { $eventUser = ORM::factory('user', $event->user->user_id); if ($eventUser->id) { if ($event->data->type == "game_Badge") { $obj = new stdClass(); $obj->data = $event->data; $obj->honor = ORM::factory($event->data->type, $event->data->honor_id); $obj->user = ORM::factory('user', $event->user->user_id); $badges[] = $obj; } } if (count($badges) >= $this->maxBadges) { break; } } if (count($awards) < $this->maxAwards) { $aevents = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Helper_Game::AWARD_GIVEN)->id)->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all(); foreach ($aevents as $event) { $obj = new stdClass(); $obj->data = $event->data; $obj->honor = ORM::factory($event->data->type, $event->data->honor_id); $obj->user = ORM::factory('user', $event->user->user_id); $obj->photo = ORM::factory('photo', $event->item->item_id); $awards[] = $obj; if (count($awards) >= $this->maxAwards) { break; } } } $honors = array_merge($awards, $badges); if (count($honors) == 0) { $honors = false; } $slider = Model_DLSliderGroup::getCurrentSlider(); if ($slider) { $this->template->top = View::factory("home/slider"); $this->template->top->slider = $slider; } $this->template->content = View::factory('home/index'); $this->template->content->set(array('user' => $this->user, 'recently_added' => Reel_More::factory(ORM::factory('photo')->order_by('created', 'desc')), 'top_rated' => Reel_More::factory(Helper_Photos::get_top_rated()), 'honors' => $honors, 'potd' => Model_DailyPhoto::todaysPhoto(), 'homeSpot' => $homeSpot, 'homeSpotEditLink' => HTML::anchor("admin/home/edit/{$homeSpot->id}", "Edit"))); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }