Beispiel #1
0
 /**
  * Action: delete group
  */
 public function action_deletegroup()
 {
     $this->history = false;
     $group_id = (int) $this->request->param('id');
     $group = Model_Tag_Group::factory($group_id);
     if (!$group->loaded() || !Security::csrf_valid()) {
         throw new Model_Exception($group, $group_id);
     }
     $group->delete();
     $this->request->redirect(Route::url('tags'));
 }
Beispiel #2
0
 /**
  * Action: delete
  */
 public function action_delete()
 {
     $this->history = false;
     $role_id = (int) $this->request->param('id');
     $role = Model_Role::factory($role_id);
     if (!$role->loaded() || !Security::csrf_valid()) {
         throw new Model_Exception($role, $role_id);
     }
     Permission::required($role, Model_Role::PERMISSION_DELETE, self::$user);
     $role->delete();
     Request::back(Route::url('roles'));
 }
Beispiel #3
0
 /**
  * Action: shout
  */
 public function action_shout()
 {
     $shout = Model_Shout::factory();
     if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) {
         $shout->author_id = Visitor::$user->id;
         $shout->shout = $_POST['shout'];
         $shout->created = time();
         try {
             $shout->save();
         } catch (Validation_Exception $e) {
         }
     }
     if ($this->ajax) {
         $section = $this->section_shouts();
         $section->aside = true;
         $this->response->body($section);
         return;
     }
     $this->request->redirect(Route::get('shouts')->uri());
 }
Beispiel #4
0
 /**
  * Action: shout
  */
 public function action_shout()
 {
     $shout = Model_Shout::factory();
     $errors = array();
     if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) {
         $shout->author_id = self::$user->id;
         $shout->shout = $_POST['shout'];
         $shout->created = time();
         try {
             $shout->save();
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     if ($this->ajax) {
         echo new View_Index_Shouts();
         exit;
     }
     $this->request->redirect(Route::get('shouts')->uri());
 }
Beispiel #5
0
 /**
  * Controller default action
  */
 public function action_index()
 {
     $this->view->title = __('Contact');
     $section = $this->section_contact();
     if (Visitor::$user) {
         $section->name = Visitor::$user->username;
         $section->email = Visitor::$user->email;
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         $name = trim(Arr::get($_POST, 'name'));
         $email = trim(Arr::get($_POST, 'email'));
         $subject = trim(Arr::get($_POST, 'subject'));
         $content = trim(Arr::get($_POST, 'content'));
         if (!Valid::email($email)) {
             $errors['email'] = __('Please check the email address');
         }
         if (!$content) {
             $errors['content'] = __('Please say something');
         }
         // Send feedback
         if (!$errors) {
             $topic = __('Feedback') . ': ' . $subject;
             $mail = $content . "\n\n" . Request::$client_ip . ' - ' . Request::host_name();
             if (Anqh_Email::send(Kohana::$config->load('site.email_contact'), array($email, $name), $topic, $mail, false, array($email, $name))) {
                 $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(__('Thank you! We will try to return back to you as soon as possible.'), true, View_Alert::SUCCESS));
             } else {
                 $errors['content'] = __('Could not send feedback');
             }
         }
         if ($errors) {
             $section->errors = $errors;
             $section->name = $name;
             $section->email = $email;
             $section->subject = $subject;
             $section->content = $content;
         }
     }
     $this->view->add(View_Page::COLUMN_CENTER, $section);
 }
Beispiel #6
0
 /**
  * Action: shout
  */
 public function action_shout()
 {
     $shout = Jelly::factory('shout');
     $errors = array();
     if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) {
         $shout->author = self::$user;
         $shout->shout = $_POST['shout'];
         try {
             $shout->save();
             if (!$this->ajax) {
                 $this->request->redirect(Route::get('shouts')->uri());
             }
         } catch (Validate_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     $shouts = Jelly::select('shout')->limit(10)->execute();
     $view = View_Module::factory('generic/shout', array('mod_title' => __('Shouts'), 'shouts' => $shouts, 'can_shout' => Permission::has($shout, Model_Shout::PERMISSION_CREATE), 'errors' => $errors));
     if ($this->ajax) {
         echo $view;
     } else {
         Widget::add('side', $view);
     }
 }
Beispiel #7
0
 /**
  * Action: gallery
  */
 public function action_gallery()
 {
     /** @var  Model_Gallery  $gallery */
     $gallery_id = (int) $this->request->param('id');
     $gallery = Model_Gallery::factory($gallery_id);
     if (!$gallery->loaded()) {
         throw new Model_Exception($gallery, $gallery_id);
     }
     // Are we approving pending images?
     if ($this->request->action() == 'pending') {
         // Can we see galleries with un-approved images?
         Permission::required($gallery, Model_Gallery::PERMISSION_APPROVE_WAITING, self::$user);
         // Can we see all of them and approve?
         $approve = Permission::has($gallery, Model_Gallery::PERMISSION_APPROVE, self::$user);
         // Handle images?
         if ($_POST && Security::csrf_valid()) {
             $pending = $gallery->find_images_pending($approve ? null : self::$user);
             $images = (array) Arr::get($_POST, 'image_id');
             $authors = array();
             if (count($pending) && count($images)) {
                 foreach ($pending as $image) {
                     $action = Arr::Get($images, $image->id, 'wait');
                     switch ($action) {
                         case 'approve':
                             if ($approve) {
                                 $author = $image->author();
                                 //$gallery->image_count++;
                                 $authors[$author['id']] = $author['username'];
                                 $image->state(AutoModeler::STATE_LOADED);
                                 $image->status = Model_Image::VISIBLE;
                                 $image->save();
                             }
                             break;
                         case 'deny':
                             $gallery->remove('image', $image->id);
                             $gallery->image_count--;
                             $image->delete();
                             break;
                     }
                 }
                 // Admin actions
                 if ($approve) {
                     // Set default image if none set
                     if (!$gallery->default_image_id) {
                         $gallery->default_image_id = $gallery->images()->current()->id;
                     }
                     $gallery->update_copyright();
                     $gallery->updated = time();
                 }
                 $gallery->save();
                 // Redirect to normal gallery if all images approved/denied
                 if (!count($gallery->find_images_pending($approve ? null : self::$user))) {
                     $this->request->redirect(Route::model($gallery));
                 } else {
                     $this->request->redirect(Route::model($gallery, 'pending'));
                 }
             }
         }
     } else {
         Permission::required($gallery, Model_Gallery::PERMISSION_READ, self::$user);
     }
     // Build page
     $this->view = View_Page::factory(__('Gallery'));
     $this->_set_page_actions(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_CREATE, self::$user));
     $this->_set_gallery($gallery);
     if (Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_UPDATE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($gallery, 'update'), 'text' => '<i class="icon-refresh icon-white"></i> ' . __('Update gallery'));
     }
     // Share
     if ($this->request->action() !== 'pending' && Kohana::$config->load('site.facebook')) {
         Anqh::open_graph('title', __('Gallery') . ': ' . $gallery->name);
         Anqh::open_graph('url', URL::site(Route::get('gallery')->uri(array('id' => $gallery->id, 'action' => '')), true));
         Anqh::open_graph('description', __($gallery->image_count == 1 ? ':images image' : ':images images', array(':images' => $gallery->image_count)) . ' - ' . date('l ', $gallery->date) . Date::format(Date::DMY_SHORT, $gallery->date) . ($event ? ' @ ' . $event->venue_name : ''));
         if ($event && ($image = $event->flyer_front())) {
             Anqh::open_graph('image', URL::site($image->get_url('thumbnail'), true));
         } else {
             if ($image = $gallery->default_image()) {
                 Anqh::open_graph('image', URL::site($image->get_url('thumbnail'), true));
             }
         }
     }
     Anqh::share(true);
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_share());
     // Event info
     if ($event = $gallery->event()) {
         // Event flyer
         $this->view->add(View_Page::COLUMN_SIDE, $this->section_event_image($event));
         // Event info
         $this->view->add(View_Page::COLUMN_SIDE, $this->section_event_info($event));
     }
     // Pictures
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_gallery_thumbs($gallery, $this->request->action() == 'pending', isset($approve) ? $approve : null));
 }
Beispiel #8
0
 /**
  * Edit forum topic
  *
  * @param  integer  $area_id
  * @param  integer  $topic_id
  *
  * @throws  Model_Exception           invalid area, invalid topic
  * @throws  InvalidArgumentException  missing area and topic
  */
 protected function _edit_topic($area_id = null, $topic_id = null)
 {
     $this->history = false;
     $this->view = new View_Page();
     if ($area_id && !$topic_id) {
         // Start new topic
         $mode = View_Forum_PostEdit::NEW_TOPIC;
         /** @var  Model_Forum_Private_Area|Model_Forum_Area  $area */
         $area = $this->private ? Model_Forum_Private_Area::factory($area_id) : Model_Forum_Area::factory($area_id);
         if (!$area->loaded()) {
             throw new Model_Exception($area, $area_id);
         }
         Permission::required($area, Model_Forum_Area::PERMISSION_POST, self::$user);
         $this->view->title = HTML::chars($area->name);
         if ($this->private) {
             $topic = new Model_Forum_Private_Topic();
             $post = new Model_Forum_Private_Post();
             $cancel = Route::url('forum_area', array('id' => 'private', 'action' => ''));
             $recipients = array();
         } else {
             $topic = new Model_Forum_Topic();
             $post = new Model_Forum_Post();
             $cancel = Route::model($area);
         }
     } else {
         if ($topic_id) {
             // Edit old topic
             $mode = View_Forum_PostEdit::EDIT_TOPIC;
             /** @var  Model_Forum_Private_Topic|Model_Forum_Topic  $topic */
             $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
             if (!$topic->loaded()) {
                 throw new Model_Exception($topic, $topic_id);
             }
             Permission::required($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user);
             // Build recipients list
             if ($this->private) {
                 $recipients = $topic->find_recipient_names();
             }
             $this->view->title_html = Forum::topic($topic);
             $cancel = Route::model($topic);
             // Set actions
             if (Permission::has($topic, Model_Forum_Topic::PERMISSION_DELETE, self::$user)) {
                 $this->view->actions[] = array('link' => Route::model($topic, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete topic'), 'class' => 'btn btn-danger topic-delete');
             }
         } else {
             throw new InvalidArgumentException('Topic and area missing');
         }
     }
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         // Get recipients
         if ($this->private) {
             $post_recipients = array();
             foreach (explode(',', Arr::get_once($_POST, 'recipients')) as $recipient) {
                 if ($user = Model_User::find_user_light(trim($recipient))) {
                     $post_recipients[$user['id']] = $user['username'];
                 }
             }
             // Make sure author is included
             $post_recipients[self::$user->id] = self::$user->username;
         }
         if (isset($post)) {
             // New topic
             $post->post = $_POST['post'];
             $post->forum_area_id = $area->id;
             $post->author_id = self::$user->id;
             $post->author_name = self::$user->username;
             $post->author_ip = Request::$client_ip;
             $post->author_host = Request::host_name();
             $post->created = time();
             try {
                 $post->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             $topic->author_id = self::$user->id;
             $topic->author_name = self::$user->username;
             $topic->name = $_POST['name'];
             $topic->forum_area_id = $area->id;
             $topic->created = time();
             try {
                 $topic->is_valid();
             } catch (Validation_Exception $e) {
                 $errors += $e->array->errors('validate');
             }
             // If no errors found, save models
             if (empty($errors)) {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 // Post
                 $post->forum_topic_id = $topic->id;
                 $post->save();
                 // Topic
                 $topic->first_post_id = $topic->last_post_id = $post->id;
                 $topic->last_poster = self::$user->username;
                 $topic->last_posted = time();
                 $topic->post_count = 1;
                 $topic->save();
                 // Area, only public forums
                 if (!$this->private) {
                     $area->last_topic_id = $topic->id;
                     $area->post_count++;
                     $area->topic_count++;
                     $area->save();
                 }
                 // User
                 self::$user->post_count++;
                 self::$user->save();
                 // News feed
                 if (!$this->private) {
                     NewsfeedItem_Forum::topic(self::$user, $topic);
                 }
                 $this->request->redirect(Route::model($topic));
             }
             isset($post_recipients) and $recipients = $post_recipients;
         } else {
             // Old topic
             $topic->set_fields(Arr::intersect($_POST, array('name', 'status', 'sticky')));
             try {
                 $topic->save();
                 // Recipients
                 if ($this->private) {
                     $topic->set_recipients($post_recipients);
                 }
                 $this->request->redirect(Route::model($topic));
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validate');
             }
         }
     }
     $form['errors'] = $errors;
     $section = $this->section_post_edit($mode, isset($post) ? $post : null);
     $section->forum_topic = $topic;
     $section->errors = $errors;
     $section->cancel = $cancel;
     $section->recipients = isset($recipients) ? implode(', ', $recipients) : null;
     $this->view->add(View_Page::COLUMN_MAIN, $section);
 }
Beispiel #9
0
 /**
  * Action: Remove from ignore
  */
 public function action_unignore()
 {
     $this->history = false;
     // Load user
     $user = $this->_get_user();
     Permission::required($user, Model_User::PERMISSION_IGNORE, self::$user);
     if (Security::csrf_valid()) {
         self::$user->delete_ignore($user);
     }
     $this->request->redirect(URL::user($user));
 }
Beispiel #10
0
 /**
  * Action: report
  */
 public function action_report()
 {
     $this->history = false;
     $gallery_id = (int) $this->request->param('gallery_id');
     $image_id = $this->request->param('id');
     /** @var  Model_Gallery  $gallery */
     $gallery = Model_Gallery::factory($gallery_id);
     if (!$gallery->loaded()) {
         throw new Model_Exception($gallery, $gallery_id);
     }
     /** @var  Model_Image  $image */
     $image = Model_Image::factory($image_id);
     if (!$image->loaded()) {
         throw new Model_Exception($image, $image_id);
     }
     Permission::required($image, Model_Image::PERMISSION_REPORT);
     $cancel_url = Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => ''));
     // Handle report
     if ($_POST && Security::csrf_valid()) {
         $reason = trim(Arr::get($_POST, 'reason'));
         Notification_Galleries::image_removal_request(Visitor::$user, $image, $reason ? $reason : null);
         if ($this->_request_type === Controller::REQUEST_AJAX) {
             $this->response->body(new View_Alert(__('Report filed.'), null, View_Alert::SUCCESS));
         } else {
             $this->request->redirect($cancel_url);
         }
         return;
     }
     $section = $this->section_image_report($image);
     // Show only the form is AJAX
     if ($this->_request_type === Controller::REQUEST_AJAX) {
         $this->response->body($section);
         return;
     }
     // Build page
     $this->view = View_Page::factory(__('Report image'));
     $this->view->actions[] = array('link' => $cancel_url, 'text' => __('Cancel'), 'class' => 'btn-inverse');
     // Image
     $this->view->add(View_Page::COLUMN_TOP, $this->section_image($image, $gallery, $cancel_url));
     // Form
     $this->view->add(View_Page::COLUMN_TOP, $section);
 }
Beispiel #11
0
 /**
  * Edit entry
  *
  * @param   integer  $entry_id
  *
  * @throws  Model_Exception
  */
 protected function _edit_entry($entry_id = null)
 {
     $this->history = false;
     if ($entry_id) {
         // Editing old
         $entry = new Model_Blog_Entry($entry_id);
         if (!$entry->loaded()) {
             throw new Model_Exception($entry, $entry_id);
         }
         Permission::required($entry, Model_Blog_Entry::PERMISSION_UPDATE);
         $cancel = Route::model($entry);
         $this->view->title = __('Edit blog entry');
         $entry->modified = time();
         $entry->modify_count++;
     } else {
         // Creating new
         $entry = new Model_Blog_Entry();
         Permission::required($entry, Model_Blog_Entry::PERMISSION_CREATE);
         $cancel = Request::back(Route::get('blogs')->uri(), true);
         $newsfeed = true;
         $this->view->title = __('New blog entry');
         $entry->author_id = Visitor::$user->id;
         $entry->created = time();
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         try {
             $entry->name = Arr::get($_POST, 'name');
             $entry->content = Arr::get($_POST, 'content');
             $entry->save();
             // Newsfeed
             if (isset($newsfeed) && $newsfeed) {
                 NewsfeedItem_Blog::entry(Visitor::$user, $entry);
             }
             $this->request->redirect(Route::model($entry));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Form
     $section = $this->section_entry_edit($entry);
     $section->cancel = $cancel;
     $section->errors = $errors;
     $this->view->add(View_Page::COLUMN_CENTER, $section);
 }
Beispiel #12
0
 /**
  * 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);
 }
Beispiel #13
0
 /**
  * Edit track.
  *
  * @param   integer  $track_id
  *
  * @throws  Model_Exception
  */
 protected function _edit_track($track_id = null)
 {
     $this->history = false;
     if ($track_id) {
         // Editing old
         $track = new Model_Music_Track($track_id);
         if (!$track->loaded()) {
             throw new Model_Exception($track, $track_id);
         }
         Permission::required($track, Model_Music_Track::PERMISSION_UPDATE);
         $cancel = Route::model($track);
         $this->view = new View_Page(HTML::chars($track->name));
         // Set actions
         if (Permission::has($track, Model_Music_Track::PERMISSION_DELETE)) {
             $this->view->actions[] = array('link' => Route::model($track, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete'), 'class' => 'btn-danger music-delete');
         }
     } else {
         // Creating new
         $track = new Model_Music_Track();
         Permission::required($track, Model_Music_Track::PERMISSION_CREATE);
         $cancel = Request::back(Route::url('charts'), true);
         $newsfeed = true;
         $this->view = new View_Page($this->request->param('music') === 'mixtape' ? __('New mixtape') : __('New track'));
         $track->author_id = Visitor::$user->id;
         $track->type = $this->request->param('music') === 'mixtape' ? Model_Music_Track::TYPE_MIX : Model_Music_Track::TYPE_TRACK;
         $track->created = time();
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         try {
             $track->set_fields(Arr::intersect($_POST, Model_Music_Track::$editable_fields));
             $track->save();
             // Set tags
             $track->set_tags(Arr::get($_POST, 'tag'));
             // Newsfeed
             if (isset($newsfeed) && $newsfeed) {
                 NewsfeedItem_Music::track(Visitor::$user, $track);
                 // Create forum topic
                 if ($track->add_forum_topic()) {
                     Visitor::$user->post_count++;
                     Visitor::$user->save();
                 }
             }
             $this->request->redirect(Route::model($track));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Form
     $section = $this->section_track_edit($track);
     $section->cancel = $cancel;
     $section->errors = $errors;
     $this->view->add(View_Page::COLUMN_TOP, $section);
 }
Beispiel #14
0
    /**
     * Action: settings
     */
    public function action_settings()
    {
        $this->history = false;
        $user = $this->_get_user();
        Permission::required($user, Model_User::PERMISSION_UPDATE, self::$user);
        // Set generic page parameters
        $this->_set_page($user);
        // Handle post
        $errors = array();
        if ($_POST && Security::csrf_valid()) {
            $user->set(Arr::extract($_POST, Model_User::$editable_fields));
            // GeoNames
            if ($_POST['city_id'] && ($city = Geo::find_city((int) $_POST['city_id']))) {
                $user->city = $city;
            }
            $user->modified = time();
            try {
                $user->save();
                $this->request->redirect(URL::user($user));
            } catch (Validate_Exception $e) {
                $errors = $e->array->errors('validation');
            }
        }
        // Build form
        $form = array('values' => $user, 'errors' => $errors, 'cancel' => URL::user($user), 'hidden' => array('city_id' => $user->city ? $user->city->id : 0, 'latitude' => $user->latitude, 'longitude' => $user->longitude), 'groups' => array('basic' => array('header' => __('Basic information'), 'fields' => array('name' => array(), 'gender' => array('input' => 'radio'), 'dob' => array('pretty_format' => 'j.n.Y'), 'title' => array(), 'description' => array('attributes' => array('rows' => 5)))), 'contact' => array('header' => __('Contact information'), 'fields' => array('email' => array(), 'homepage' => array(), 'address_street' => array(), 'address_zip' => array(), 'address_city' => array())), 'forum' => array('header' => __('Forum settings'), 'fields' => array('signature' => array('attributes' => array('rows' => 5))))));
        Widget::add('main', View_Module::factory('form/anqh', array('form' => $form)));
        // Autocomplete
        $this->autocomplete_city('address_city', 'city_id');
        // Date picker
        $options = array('changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'd.m.yy', 'defaultDate' => date('j.n.Y', $user->dob), 'dayNames' => array(__('Sunday'), __('Monday'), __('Tuesday'), __('Wednesday'), __('Thursday'), __('Friday'), __('Saturday')), 'dayNamesMin' => array(__('Su'), __('Mo'), __('Tu'), __('We'), __('Th'), __('Fr'), __('Sa')), 'firstDay' => 1, 'monthNames' => array(__('January'), __('February'), __('March'), __('April'), __('May'), __('June'), __('July'), __('August'), __('September'), __('October'), __('November'), __('December')), 'monthNamesShort' => array(__('Jan'), __('Feb'), __('Mar'), __('Apr'), __('May'), __('Jun'), __('Jul'), __('Aug'), __('Sep'), __('Oct'), __('Nov'), __('Dec')), 'nextText' => __('&raquo;'), 'prevText' => __('&laquo;'), 'showWeek' => true, 'showOtherMonths' => true, 'weekHeader' => __('Wk'), 'yearRange' => '1900:+0');
        Widget::add('foot', HTML::script_source('$("#field-dob").datepicker(' . json_encode($options) . ');'));
        // Maps
        Widget::add('foot', HTML::script_source('
$(function() {
	$("#fields-contact ul").append("<li><div id=\\"map\\">' . __('Loading map..') . '</div></li>");

	$("#map").googleMap(' . ($user->latitude ? json_encode(array('marker' => true, 'lat' => $user->latitude, 'long' => $user->longitude)) : '') . ');

	$("input[name=address_street], input[name=address_city]").blur(function(event) {
		var address = $("input[name=address_street]").val();
		var city = $("input[name=address_city]").val();
		if (address != "" && city != "") {
			var geocode = address + ", " + city;
			geocoder.geocode({ address: geocode }, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK && results.length) {
				  map.setCenter(results[0].geometry.location);
				  $("input[name=latitude]").val(results[0].geometry.location.lat());
				  $("input[name=longitude]").val(results[0].geometry.location.lng());
				  var marker = new google.maps.Marker({
				    position: results[0].geometry.location,
				    map: map
				  });
				}
			});
		}
	});

});
'));
    }
Beispiel #15
0
 /**
  * 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);
 }
Beispiel #16
0
 /**
  * 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);
 }