/** * Action: edit */ public function action_edit() { $this->history = false; // Load role $role_id = (int) $this->request->param('id', 0); if ($role_id) { $role = Model_Role::factory($role_id); if (!$role->loaded()) { throw new Model_Exception($role, $role_id); } Permission::required($role, Model_Role::PERMISSION_UPDATE, self::$user); } else { $role = Model_Role::factory(); Permission::required($role, Model_Role::PERMISSION_CREATE, self::$user); } // Handle post $errors = array(); if ($_POST) { $role->name = Arr::get($_POST, 'name'); $role->description = Arr::get($_POST, 'description'); try { $role->save(); $this->request->redirect(Route::url('roles')); } catch (Validation_Exception $e) { $errors = $e->array->errors('validate'); } } // Set title $this->view = View_Page::factory(__('Role') . ($role->name ? ': ' . $role->name : '')); // Set actions if ($role->loaded() && Permission::has($role, Model_Role::PERMISSION_DELETE, self::$user)) { $this->page_actions[] = array('link' => Route::model($role, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete role'), 'class' => 'btn btn-danger role-delete'); } $this->view->add(View_Page::COLUMN_MAIN, $this->section_role($role, $errors)); }
/** * Action: browse tracks */ public function action_browse() { $type = $this->request->param('music') == 'mixtapes' ? Model_Music_Track::TYPE_MIX : Model_Music_Track::TYPE_TRACK; $genre = $this->request->param('genre'); // Load requested music $limit = 25; $music = Model_Music_Track::factory(); $count = $music->count_by_type($type, $genre); // Build page $this->view = View_Page::factory($type == Model_Music_Track::TYPE_MIX ? __('Mixtapes') : __('Tracks')); // Set actions $this->_set_page_actions(); $this->view->tab = $this->request->param('music'); // Filters $this->view->add(View_Page::COLUMN_CENTER, $this->section_filters($this->request->param('music'), $genre)); // Pagination $this->view->add(View_Page::COLUMN_CENTER, $pagination = $this->section_pagination($limit, $count)); $this->view->subtitle = __($pagination->total_pages == 1 ? ':pages page' : ':pages pages', array(':pages' => Num::format($pagination->total_pages, 0))); // Browse $tracks = $music->find_by_type($type, $genre, $limit, $pagination->offset); $this->view->add(View_Page::COLUMN_CENTER, $this->section_browse($tracks)); // Pagination $this->view->add(View_Page::COLUMN_CENTER, $pagination); // New $this->view->add(View_Page::COLUMN_RIGHT, $this->section_list($music->find_new(Model_Music_Track::TYPE_MIX, 10), __('New mixtapes'))); $this->view->add(View_Page::COLUMN_RIGHT, $this->section_list($music->find_new(Model_Music_Track::TYPE_TRACK, 10), __('New tracks'))); }
/** * Action: index */ public function action_index() { // Build page $this->view = View_Page::factory(__('Shouts')); // Shouts $this->view->add(View_Page::COLUMN_CENTER, $this->section_shouts()); }
protected function parseForView() { $sidenav = new View_Sidenav(); $page = new View_Page(array('base' => $this->paths['base'], 'path' => $this->paths, 'name' => $this->page_name, 'type' => 'page')); $this->layout_name = $page->get_var('layout'); $layout = new View_Page(array('base' => $this->paths['base'], 'path' => $this->paths, 'name' => $this->layout_name, 'type' => 'layout')); if ($navList =& $layout->get_var('sidebar_items')) { $sidenav->set_items($navList); $sidenav->mark_active_item($this->page_name); } $context = array("page" => $page->get_vars(), "layout" => $layout->get_vars(), "path" => $this->paths, "site" => $this->site); $context['breadcrumbs'] = $sidenav->get_breadcrumbs(); $context['createLinkFunction'] = function ($value) { return '?page=' . $value; }; $this->template = $layout->get_template(); $this->context = $context; }
/** * Controller default action */ public function action_index() { // Build page $this->view = View_Page::factory(__('New members')); // New users $this->view->add(View_Page::COLUMN_MAIN, $this->section_new_users()); // Birthdays $this->view->add(View_Page::COLUMN_SIDE, $this->section_birthdays()); // Online $this->view->add(View_Page::COLUMN_SIDE, $this->section_online()); }
/** * Construct controller. */ public function before() { parent::before(); $this->auto_render = $this->_request_type === Controller::REQUEST_INITIAL; $this->history = $this->history && !$this->ajax; // Initialize Ads Ads::init(); // Load the template if ($this->auto_render === true) { $this->view = View_Page::factory(); } }
/** * Controller default action */ public function action_index() { // Newsfeed if (isset($_GET['newsfeed']) && $this->_request_type === Controller::REQUEST_AJAX) { echo $this->section_newsfeed(); exit; } // Build page $this->view = View_Page::factory(__('Welcome to :site', array(':site' => Kohana::$config->load('site.site_name')))); // Newsfeed $this->view->add(View_Page::COLUMN_MAIN, $this->section_newsfeed()); // Birthdays $this->view->add(View_Page::COLUMN_SIDE, $this->section_birthdays()); // Shouts $this->view->add(View_Page::COLUMN_SIDE, $this->section_shouts()); // Online $this->view->add(View_Page::COLUMN_SIDE, $this->section_online()); }
/** * Edit gallery * * @param integer $gallery_id * @param integer $event_id */ protected function _edit_gallery($gallery_id = null, $event_id = null) { $this->history = false; if ($gallery_id) { // Editing old $gallery = Model_Gallery::factory($gallery_id); if (!$gallery->loaded()) { throw new Model_Exception($gallery, $gallery_id); } Permission::required($gallery, Model_Gallery::PERMISSION_UPDATE, self::$user); $cancel = Route::model($gallery); $save = null; $upload = false; } else { // Creating new $gallery = Model_Gallery::factory(); Permission::required($gallery, Model_Gallery::PERMISSION_CREATE, self::$user); $cancel = Request::back(Route::url('galleries'), true); $save = __('Continue'); $upload = true; if ($event_id) { /** @var Model_Event $event */ $event = Model_Event::factory($event_id); } } // Handle post $errors = array(); if ($_POST || isset($_GET['from'])) { $event_id = $_POST ? (int) Arr::get($_POST, 'event') : (int) Arr::get($_GET, 'from'); $event = Model_Event::factory($event_id); if (!$gallery->loaded() && $event->loaded()) { // Redirect to existing gallery if trying to create duplicate $old = Model_Gallery::factory()->find_by_event($event_id); if ($old->loaded()) { $this->request->redirect(Route::model($old, 'upload')); } // Fill gallery info from event when creating new $gallery->name = $event->name; $gallery->date = $event->stamp_begin; $gallery->event_id = $event->id; } else { if ($gallery->loaded()) { // Editing old $gallery->set_fields(Arr::intersect($_POST, Model_Gallery::$editable_fields)); } } try { $gallery->save(); $this->request->redirect(Route::model($gallery, $upload ? 'upload' : null)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); } } // Build page $this->view = View_Page::factory(__('Upload images')); // Gallery edit form $section = $this->section_gallery_edit(isset($event) ? $event : null); $section->errors = $errors; $this->view->add(View_Page::COLUMN_MAIN, $section); // Gallery event info if (isset($event) && $event->loaded()) { $this->view->add(View_Page::COLUMN_MAIN, $this->section_event_info($event)); } $this->view->add(View_Page::COLUMN_SIDE, $this->section_upload_help()); }
/** * Action: tag * * @param integer $group_id */ public function action_tag($group_id = null) { $this->history = false; if ($group_id && $this->request->action() !== 'tag') { // Add new tag $group = Model_Tag_Group::factory($group_id); if (!$group->loaded()) { throw new Model_Exception($group, $group_id); } $tag = Model_Tag::factory(); $tag->tag_group_id = $group_id; $tag->author_id = Visitor::$user->id; $tag->created = time(); $this->view = View_Page::factory($group->name); $this->view->subtitle = HTML::chars($group->description); } else { if ($tag_id = (int) $this->request->param('id')) { // Edit old tag $tag = Model_Tag::factory($tag_id); if (!$tag->loaded()) { throw new Model_Exception($tag, $tag_id); } $this->view = View_Page::factory($tag->name); $this->view->subtitle = HTML::chars($tag->description); $this->page_actions[] = array('link' => Route::model($tag, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete tag'), 'class' => 'btn btn-danger tag-delete'); } else { Request::back(Route::url('tags')); } } $errors = array(); if ($_POST) { $tag->name = Arr::get($_POST, 'name'); $tag->description = Arr::get($_POST, 'description'); try { $tag->save(); $this->request->redirect(Route::model($tag)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validate'); } } $this->view->add(View_Page::COLUMN_CENTER, $this->section_tag($tag, $errors)); }
/** * Edit event * * @param integer $event_id */ protected function _edit_event($event_id = null) { $this->history = false; if ($event_id) { // Editing old $event = Model_Event::factory($event_id); if (!$event->loaded()) { throw new Model_Exception($event, $event_id); } Permission::required($event, Model_Event::PERMISSION_UPDATE, self::$user); $cancel = Request::back(Route::model($event), true); $this->view = View_Page::factory(HTML::chars($event->name)); // Set actions if (Permission::has($event, Model_Event::PERMISSION_DELETE, self::$user)) { $this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete'); } $edit = true; } else { // Creating new $event = new Model_Event(); Permission::required($event, Model_Event::PERMISSION_CREATE, self::$user); $cancel = Request::back(Route::get('events')->uri(), true); $this->view = View_Page::factory(__('New event')); $event->author_id = self::$user->id; $event->created = time(); $edit = false; } // Handle post if ($_POST && Security::csrf_valid()) { // Handle venue if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) { // Hidden events require only city } else { if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) { // Old venue $venue = Model_Venue::factory($venue_id); } else { if ($venue_name = Arr::get($_POST, 'venue_name')) { // Check for duplicate venue $venues = Model_Venue::factory()->find_by_name($venue_name); if ($venues->count()) { $city_name = strtolower(Arr::get($_POST, 'city_name')); foreach ($venues as $venue_old) { if (strtolower($venue_old->city_name) == $city_name) { $venue = $venue_old; break; } } } } } } $post = Arr::intersect($_POST, Model_Event::$editable_fields); if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time'])) { $post['stamp_end']['date'] = $post['stamp_begin']['date']; } $event->set_fields($post); if (Arr::get($_POST, 'free')) { $event->price = 0; } // Venue/location $event->venue_hidden = (bool) $venue_hidden; if ($venue_hidden) { // Hidden events don't have a venue $event->venue_id = null; $event->venue_name = null; } else { if (isset($venue)) { // Venue loaded $event->venue_id = $venue->id; $event->city_name = $venue->city_name; } else { if (!empty($venue_name)) { // Create new venue $venue = Model_Venue::factory(); $venue->name = Arr::get($_POST, 'venue_name'); $venue->address = Arr::get($_POST, 'address'); $venue->latitude = Arr::get($_POST, 'latitude'); $venue->longitude = Arr::get($_POST, 'longitude'); $venue->event_host = true; $venue->author_id = self::$user->id; $venue->city_name = $event->city_name; try { $venue->save(); $event->venue_id = $venue->id; } catch (Validation_Exception $venue_validation) { } } } } // Validate event try { $event->is_valid(); } catch (Validation_Exception $event_validation) { } // If no errors found, save if (!isset($venue_validation) && !isset($event_validation)) { // Make sure end time is after start time, i.e. the next day if ($event->stamp_end < $event->stamp_begin) { $event->stamp_end += Date::DAY; } $event->save(); // Set tags $event->set_tags(Arr::get($_POST, 'tag')); $edit ? NewsfeedItem_Events::event_edit(self::$user, $event) : NewsfeedItem_Events::event(self::$user, $event); $this->request->redirect(Route::model($event)); } } // Fill the required information to view $this->view->event = $event; $this->view->event_errors = isset($event_validation) ? $event_validation->array->errors('validation') : null; $this->view->venue = isset($venue) ? $venue : null; $this->view->venue_errors = isset($venue_validation) ? $venue_validation->array->errors('validation') : null; // Tags $tags = array(); $tag_group = new Model_Tag_Group('Music'); if ($tag_group->loaded() && count($tag_group->tags())) { foreach ($tag_group->tags() as $tag) { $tags[$tag->id()] = $tag->name(); } } // Form $section = $this->section_event_edit($event); $section->event_errors = isset($event_validation) ? $event_validation->array->errors('validation') : null; $section->venue = isset($venue) ? $venue : $event->venue; $section->venue_errors = isset($venue_validation) ? $venue_validation->array->errors('validation') : null; $section->cancel = $cancel; $this->view->add(View_Page::COLUMN_TOP, $section); }
/** * Action: sign up */ public function action_up() { $this->history = false; if (self::$user) { Request::back(); } $this->view = View_Page::factory(__('Sign up')); // Check invitation code $code = trim(Arr::get($_REQUEST, 'code')); if ($code) { $invitation = Model_Invitation::factory($code); return $invitation->loaded() ? $this->_join($invitation) : $this->_invite($code); } // Check if we got the code from the form if (!$code && $_POST) { $code = Arr::get($_POST, 'code'); if ($code) { $this->request->redirect(Route::url('sign', array('action' => 'up')) . '?code=' . $code); } } $this->_invite(); }
/** * Edit venue * * @param integer $venue_id */ protected function _edit_venue($venue_id = null) { $this->history = false; $edit = true; if ($venue_id) { // Editing old $venue = Model_Venue::factory($venue_id); if (!$venue->loaded()) { throw new Model_Exception($venue, $venue_id); } Permission::required($venue, Model_Venue::PERMISSION_UPDATE); $cancel = Route::model($venue); $this->view = View_Page::factory($venue->name); // Modified timestamp $venue->modified = time(); // Set actions if (Permission::has($venue, Model_Venue::PERMISSION_DELETE)) { $this->view->actions[] = array('link' => Route::model($venue, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete venue'), 'class' => 'btn btn-danger venue-delete'); } } else { // Creating new $edit = false; $venue = Model_Venue::factory(); $venue->author_id = Visitor::$user->id; $cancel = Route::url('venues'); $this->view = View_Page::factory(__('New venue')); } // Handle post $errors = array(); if ($_POST && Security::csrf_valid()) { $venue->set_fields(Arr::intersect($_POST, Model_Venue::$editable_fields)); try { $venue->save(); $edit ? NewsfeedItem_Venues::venue_edit(Visitor::$user, $venue) : NewsfeedItem_Venues::venue(Visitor::$user, $venue); $this->request->redirect(Route::model($venue)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); } } $section = $this->section_venue_edit($venue); $section->errors = $errors; $section->cancel = $cancel; $this->view->add(View_Page::COLUMN_TOP, $section); }
/** * Edit event * * @param integer $event_id */ protected function _edit_event($event_id = null) { $this->history = false; if ($event_id) { // Editing old $event = Model_Event::factory($event_id); if (!$event->loaded()) { throw new Model_Exception($event, $event_id); } Permission::required($event, Model_Event::PERMISSION_UPDATE); $cancel = Request::back(Route::model($event), true); $this->view = View_Page::factory(HTML::chars($event->name)); // Set actions if (Permission::has($event, Model_Event::PERMISSION_DELETE)) { $this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete'); } $edit = true; $event->update_count++; $event->modified = time(); } else { // Creating new $event = new Model_Event(); Permission::required($event, Model_Event::PERMISSION_CREATE); $cancel = Request::back(Route::get('events')->uri(), true); $this->view = View_Page::factory(__('New event')); $event->author_id = Visitor::$user->id; $event->created = time(); $edit = false; } // Handle post if ($_POST && Security::csrf_valid()) { $preview = isset($_POST['preview']); // Handle venue if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) { // Hidden events require only city } else { if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) { // Old venue $venue = Model_Venue::factory($venue_id); } else { if ($venue_name = Arr::get($_POST, 'venue_name')) { // Check for duplicate venue $venues = Model_Venue::factory()->find_by_name($venue_name); if ($venues->count()) { $city_name = strtolower(Arr::get($_POST, 'city_name')); foreach ($venues as $venue_old) { if (strtolower($venue_old->city_name) == $city_name) { $venue = $venue_old; break; } } } } } } $post = Arr::intersect($_POST, Model_Event::$editable_fields); if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time']) && !isset($post['stamp_end']['date'])) { $post['stamp_end']['date'] = $post['stamp_begin']['date']; } $event->set_fields($post); if (Arr::get($_POST, 'free')) { $event->price = 0; } // Venue/location $event->venue_hidden = (bool) $venue_hidden; if ($venue_hidden) { // Hidden events don't have a venue $event->venue_id = null; $event->venue_name = null; } else { if (isset($venue)) { // Venue loaded $event->venue_id = $venue->id; $event->city_name = $venue->city_name; } else { if (!empty($venue_name)) { // Create new venue $venue = Model_Venue::factory(); $venue->name = Arr::get($_POST, 'venue_name'); $venue->address = Arr::get($_POST, 'address'); $venue->latitude = Arr::get($_POST, 'latitude'); $venue->longitude = Arr::get($_POST, 'longitude'); $venue->foursquare_id = Arr::get($_POST, 'foursquare_id'); $venue->event_host = true; $venue->author_id = Visitor::$user->id; $venue->city_name = $event->city_name; if (!$preview) { try { $venue->save(); $event->venue_id = $venue->id; } catch (Validation_Exception $venue_validation) { } } } } } // Validate event try { $event->is_valid(); } catch (Validation_Exception $event_validation) { } // Handle preview request if ($preview) { if ($this->ajax) { $preview = '<p>' . self::_event_subtitle($event) . '</p>'; $preview .= '<div id="main" class="col-md-8">'; $preview .= $this->section_event_main($event); $preview .= '<hr></div>'; $this->response->body($preview); } return; } // Flyer if ($flyer_url = Arr::get($_POST, 'flyer')) { $event->flyer_url = $flyer_url; $image = new Model_Image(); $image->remote = $flyer_url; $image->created = time(); $image->author_id = Visitor::$user->id; try { $image->save(); try { $flyer = new Model_Flyer(); $flyer->set_fields(array('image_id' => $image->id, 'name' => $event->name, 'stamp_begin' => $event->stamp_begin)); $flyer->save(); } catch (Validation_Exception $flyer_validation) { $flyer_error = print_r($flyer_validation->array->errors('validation'), true); } } catch (Validation_Exception $image_validation) { $flyer_error = print_r($image_validation->array->errors('validation'), true); } catch (Kohana_Exception $e) { $flyer_error = $e->getMessage(); } } // If no errors found, save if (!isset($venue_validation) && !isset($event_validation) && !isset($flyer_error)) { // Make sure end time is after start time, i.e. the next day if ($event->stamp_end < $event->stamp_begin) { $event->stamp_end += Date::DAY; } $event->save(); // Handle flyer if (isset($image) && isset($flyer) && $flyer->loaded()) { $flyer->event_id = $event->id; $flyer->save(); $event->set_flyer($flyer); $event->save(); } // Set tags $event->set_tags(Arr::get($_POST, 'tag')); if ($edit) { // Don't flood edits right after save if (time() - $event->created > 60 * 30) { NewsfeedItem_Events::event_edit(Visitor::$user, $event); } } else { NewsfeedItem_Events::event(Visitor::$user, $event); // Add to favorites $event->add_favorite(Visitor::$user); // Create forum topic if ($event->add_forum_topic()) { Visitor::$user->post_count++; Visitor::$user->save(); } } $this->request->redirect(Route::model($event)); } } // Remove orphan flyer on all errors if (isset($flyer)) { $flyer->delete(); } else { if (isset($image)) { $image->delete(); } } // Tags $tags = array(); $tag_group = new Model_Tag_Group('Music'); if ($tag_group->loaded() && count($tag_group->tags())) { foreach ($tag_group->tags() as $tag) { $tags[$tag->id()] = $tag->name(); } } // Form $section = $this->section_event_edit($event); $section->event_errors = isset($event_validation) ? $event_validation->array->errors('validation') : null; $section->flyer_error = isset($flyer_error) ? $flyer_error : null; $section->venue = isset($venue) ? $venue : $event->venue; $section->venue_errors = isset($venue_validation) ? $venue_validation->array->errors('validation') : null; $section->cancel = $cancel; $this->view->add(View_Page::COLUMN_TOP, $section); }