public function action_confirm($category_id) { $category = ORM::factory('category')->where('id', '=', $category_id)->find(); $this->template->content = View::factory('admin/categories/confirm'); $this->template->sidebar = Widget::factory()->add(Helper_Default::admin_sidebar()); $this->template->content->category = $category; }
public function action_index() { $results = ORM::factory('caption')->where('moderation_status_id', '!=', '2')->find_all(); $this->template->content = View::factory('admin/captions/index'); $this->template->content->set(array('captions' => $results)); $this->template->scripts = array('public/js/admin/moderation.js'); $this->template->sidebar = Widget::factory()->add(Helper_Default::admin_sidebar()); }
public function action_index($photo_id = NULL) { /* * load all of the Caption This photos that haven't expired */ $caption_photos = ORM::factory('captionthisphoto')->where('to', '>=', date('Y-m-d'))->find_all(); if ($photo_id != NULL) { $photo = ORM::factory('photo')->where('id', '=', $photo_id)->find(); /* * try to load the photo provided via the url */ if ($photo->loaded()) { /* * check to see if from date is before to date */ if (strtotime($_POST['to']) < strtotime($_POST['from'])) { Message::set(Message::ERROR, "From date must be before to date."); Request::instance()->redirect(Helper_Photos::get_photo_url($photo)); return; } /* * check to see if form was posted and has both of the dates */ if (!empty($_POST['from']) && !empty($_POST['to'])) { $from_date = date('Y-m-d', strtotime($_POST['from'])); $to_date = date('Y-m-d', strtotime($_POST['to'])); $check_dates = DB::select('*')->from('caption_this_photos')->where('from', 'BETWEEN', array($from_date, $to_date))->or_where('to', 'BETWEEN', array($from_date, $to_date))->order_by('from', 'ASC')->execute(); if ($check_dates->count() > 0) { Message::set(Message::ERROR, "There is already a Caption This photo in the period you selected."); } else { $caption_this_photo = ORM::factory('captionthisphoto'); $caption_this_photo->from = date("Y-m-d", strtotime($_POST['from'])); $caption_this_photo->to = date("Y-m-d", strtotime($_POST['to'])); $caption_this_photo->photo_id = $photo_id; $caption_this_photo->save(); /* * if the photo was saved, show a success message */ if ($caption_this_photo->saved()) { Message::set(Message::SUCCESS, "Photo successfully set as Caption This photo from " . $_POST['from'] . " to " . $_POST['to'] . "."); Request::instance()->redirect('admin/backtalk'); } else { Message::set(Message::ERROR, "A problem occured while trying to set photo as Caption This photo."); } } } else { Message::set(Message::ERROR, "You must select the date range for Caption This photo."); } } else { Message::set(Message::ERROR, "This photo doesn't exist."); } } $this->template->content = View::factory('admin/photos/caption'); $this->template->content->set(array('caption_photos' => $caption_photos)); $this->template->styles = array('public/js/vendor/datepicker/jquery-ui-1.8.5.custom.css' => 'screen'); $this->template->scripts = array('public/js/vendor/jquery-ui-1.8.5.custom.min.js'); $this->template->sidebar = Widget::factory()->add(Helper_Default::admin_sidebar()); }
public function action_view($avatar_id) { $avatar = ORM::factory('avatar')->where('id', '=', $avatar_id)->find(); $avatar->lock(); $this->template->content = View::factory('admin/avatars/view'); $this->template->content->set(array('avatar' => $avatar)); $this->template->scripts = array('public/js/admin/moderation.js'); $this->template->sidebar = Widget::factory()->add(Helper_Default::admin_sidebar()); }
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()); }
/** * The before() method is called before your controller action. * In our template controller we override this method so that we can * set up default values. These variables are then available to our * controllers if they need to be modified. */ public function before() { parent::before(); #Open session $this->session = Session::instance(); //Check for logged in kids user if not logged in already if (!Auth::instance()->logged_in()) { $kidsLogin = Helper_Mmdb::getSessionUser(); if ($kidsLogin) { $tmpUser = ORM::factory("user")->where("kids_id", "=", $kidsLogin->id)->find(); if ($tmpUser->loaded()) { Auth::instance()->force_login($tmpUser); } else { if (empty($_SESSION["guest"]) && $this->request->uri != "account/merge" && $this->request->uri != "account/mergemyshot" && $this->request->uri != "account/adduser" && $this->request->uri != "account/setguest" && substr($this->request->uri, 0, 15) != substr("account/approve", 0, 15) && $this->request->uri != "account/delete") { $_SESSION['kids_id'] = $kidsLogin->id; $_SESSION['kidsData'] = $kidsLogin; $_SESSION['returnUri'] = $this->request->uri; Request::instance()->redirect('account/merge'); return; } } } } #Check user auth and role $action_name = Request::instance()->action; if ($this->auth_required !== FALSE && Auth::instance()->logged_in($this->auth_required) === FALSE || is_array($this->secure_actions) && array_key_exists($action_name, $this->secure_actions) && Auth::instance()->logged_in($this->secure_actions[$action_name]) === FALSE) { if (Auth::instance()->logged_in()) { Message::set(Message::NOTICE, 'We couldn\'t find what you are looking for!'); Request::instance()->redirect('/'); // Logged in but not approved. } else { Request::instance()->redirect('account/signin'); } } $this->user = Auth::instance()->get_user(); // No user, use a fake one. if (!$this->user) { $this->user = Helper_Default::get_fake_user(); } if ($this->auto_render) { // Initialize empty values $this->template->title = 'Share Your Photos - National Geographic Kids My Shot Community'; $this->template->top = ""; $this->template->content = ''; $this->template->sidebar = ''; $this->template->analytics = ''; $this->template->styles = array(); $this->template->scripts = array(); } }
/** * 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 before() { parent::before(); $this->template->sidebar = Widget::factory()->add(Helper_Default::admin_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('/'); } }
public function action_confirm($id) { $this->template->content = View::factory('admin/awards/confirm'); $this->template->sidebar = Widget::factory()->add(Helper_Default::admin_sidebar()); $this->template->content->award = ORM::factory("game_Award", $id); }
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()); }
public function before() { parent::before(); $this->template->content = View::factory('archive/view'); $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar()); }
/** * 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 action_flag($user_id = null) { $user = ORM::factory('user')->where('id', '=', $user_id)->find(); $content = $this->template->content = View::factory('admin/users/flag'); $this->template->sidebar = Widget::factory()->add(Helper_Default::admin_sidebar()); if ($user->loaded()) { $this->template->content->set(array('user' => $user)); } else { Message::set(Message::NOTICE, "This user does not exist."); Request::instance()->redirect('admin/users'); } if ($_POST) { /* How long do they want to suspend this user for? */ $flag_timeout = Arr::get($_POST, 'flag'); $user->flag = time() + $flag_timeout; /* Create the account. */ $user->save(); Request::instance()->redirect('admin/users'); /* Load the validation rules, filters etc.*/ //$post = $user->validate_update($_POST); /* If the post data validates using the rules setup in the user model. */ //if ($post->check()) //{ //$user->flag = time() + $flag_timeout; /* Create the account. */ //$user->save(); /* Redirect to users edit page. */ //Request::instance()->redirect('admin/users'); //} //else //{ /* Get errors for display in view. */ //Message::set(Message::ERROR, $post->errors("user")); //} } }