/** * 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)); }
/** * Get favorites. * * @return array */ public function actions() { // Clickable favorites if (Permission::has($this->event, Model_Event::PERMISSION_FAVORITE)) { if ($this->event->is_favorite(Visitor::$user)) { // Favorite event, click to unfavorite return array(HTML::anchor(Route::model($this->event, 'unfavorite') . '?token=' . Security::csrf(), $this->event->favorite_count . ' <i class="fa fa-heart"></i>', array('title' => __('Remove favorite'), 'class' => 'ajaxify btn btn-xs btn-lovely'))); } else { // Non-favorite event, click to favorite if ($this->event->favorite_count > 1) { return array(HTML::anchor(Route::model($this->event, 'favorite') . '?token=' . Security::csrf(), $this->event->favorite_count . ' <i class="fa fa-heart"></i>', array('title' => __('Add to favorites'), 'class' => 'ajaxify btn btn-xs btn-default'))); } else { return array(HTML::anchor(Route::model($this->event, 'favorite') . '?token=' . Security::csrf(), '<i class="fa fa-heart"></i>', array('title' => __('Add to favorites'), 'class' => 'ajaxify btn btn-xs btn-default text-muted'))); } } } return $this->event->favorite_count ? array('<span class="btn btn-xs btn-default disabled"><i class="fa fa-heart"></i> ' . $this->event->favorite_count . '</span>') : null; }
/** * Render view. * * @return string */ public function render() { ob_start(); ?> <li class="media"> <div class="pull-left"> <?php echo HTML::avatar($this->user['avatar'], $this->user['username']); ?> </div> <div class="media-body"> <?php if (Visitor::$user && !Visitor::$user->is_friend($this->user)) { ?> <?php echo HTML::anchor(URL::user($this->user, 'friend') . '?token=' . Security::csrf(), '<i class="fa fa-heart"></i> ' . __('Add to friends'), array('class' => 'ajaxify btn btn-lovely btn-sm pull-right', 'data-ajaxify-target' => 'li.media')); ?> <?php } ?> <?php echo HTML::user($this->user); ?> <br /> <?php if ($this->common) { ?> <small><?php echo __(':friends mutual friends', array(':friends' => $this->common)); ?> </small><br /> <?php } ?> </div> </li> <?php return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); $ignores = array(); foreach ($this->user->find_ignores() as $ignore_id) { $ignore = Model_User::find_user_light($ignore_id); $ignores[$ignores['username']] = $ignore; } ksort($ignores, SORT_LOCALE_STRING); ?> <ul class="media-list"> <?php foreach ($ignores as $ignore) { ?> <li class="media"> <div class="pull-left"> <?php echo HTML::avatar($ignore['avatar'], $ignore['username']); ?> </div> <div class="media-body"> <?php echo HTML::user($ignore); ?> <br /> <?php echo HTML::anchor(URL::user($ignore, 'unignore') . '?token=' . Security::csrf(), '<i class="fa fa-ban"></i> ' . __('Unignore'), array('class' => 'btn btn-default btn-sm ignore-delete')); ?> </div> </li> <?php } ?> </ul> <?php return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); $ignores = array(); foreach ($this->user->find_ignores() as $ignore_id) { $ignore = Model_User::find_user_light($ignore_id); $ignores[$ignores['username']] = $ignore; } ksort($ignores, SORT_LOCALE_STRING); ?> <ul class="unstyled"> <?php foreach ($ignores as $ignore) { ?> <li class="row-fluid"> <?php echo HTML::avatar($ignore['avatar'], $ignore['username']); ?> <?php echo HTML::user($ignore); ?> <br /> <?php echo HTML::anchor(URL::user($ignore, 'unignore') . '?token=' . Security::csrf(), '<i class="icon-ban-circle icon-white"></i> ' . __('Unignore'), array('class' => 'btn btn-inverse btn-small ignore-delete')); ?> </li> <?php } ?> </ul> <?php return ob_get_clean(); }
/** * 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); }
/** * Get comments section. * * @param Model_Blog_Entry $blog_entry * @param string $route * @return View_Generic_Comments */ public function section_comments(Model_Blog_Entry $blog_entry, $route = 'blog_comment') { $section = new View_Generic_Comments($blog_entry->comments(Visitor::$user)); $section->delete = Route::url($route, array('id' => '%d', 'commentaction' => 'delete')) . '?token=' . Security::csrf(); $section->private = Route::url($route, array('id' => '%d', 'commentaction' => 'private')) . '?token=' . Security::csrf(); return $section; }
/** * Render view. * * @return string */ public function content() { ob_start(); // Load images $images = $this->user->images(); // Legacy support if (!count($images) && $this->user->picture) { echo HTML::image($this->user->picture); } if (count($images)) { // Check for actions if (Permission::has($this->user, Model_User::PERMISSION_UPDATE, self::$_user)) { $action_uri = URL::user($this->user, 'image'); } // Check for missing default image $active_id = $this->user->default_image_id; if (!$active_id) { $image = $images->current(); $active_id = $image->id; } ?> <div class="carousel-inner"> <?php foreach ($images as $image) { ?> <div class="item<?php echo $image->id == $active_id ? ' active' : ''; ?> "> <?php echo HTML::image($image->get_url()); ?> <?php if (isset($action_uri)) { ?> <div class="btn-group"> <?php if ($image->id == $this->user->default_image_id) { echo HTML::anchor('#', '<i class="icon-home"></i> ' . __('Set as default'), array('class' => 'btn btn-mini image-change disabled')); } else { echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&default=' . $image->id, '<i class="icon-home"></i> ' . __('Set as default'), array('class' => 'btn btn-mini image-change')); } ?> <?php echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&delete=' . $image->id, '<i class="icon-trash"></i> ' . __('Delete'), array('class' => 'btn btn-mini image-delete')); ?> </div> <?php } ?> </div> <?php } ?> </div> <a class="carousel-control left" href="#<?php echo $this->id; ?> " data-slide="prev">‹</a> <a class="carousel-control right" href="#<?php echo $this->id; ?> " data-slide="next">›</a> <?php } return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); ?> <div class="pull-left"> <?php if ($this->author) { ?> <?php echo HTML::avatar($this->author->avatar, $this->author->username); ?> <p> <small><?php echo __('Posts: :posts', array(':posts' => '<var>' . Num::format($this->author->post_count, 0) . '</var>')); ?> </small> </p> <?php } else { ?> <?php echo HTML::avatar(false); ?> <?php } ?> </div> <div class="arrow"></div> <div class="media-body"> <header<?php echo $this->forum_post->id == $this->forum_topic->last_post_id ? ' id="last"' : ''; ?> > <small class="ago"> <?php echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic))) . '#post-' . $this->forum_post->id, '#' . $this->nth, array('title' => __('Permalink'))); ?> • <?php if (Permission::has($this->forum_post, Model_Forum_Post::PERMISSION_UPDATE, self::$_user)) { echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic), 'action' => 'edit')), __('Edit'), array('class' => 'post-edit')) . ' • '; } ?> <?php if (Permission::has($this->forum_post, Model_Forum_Post::PERMISSION_DELETE, self::$_user)) { echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic), 'action' => 'delete')) . '?token=' . Security::csrf(), __('Delete'), array('class' => 'post-delete')) . ' • '; } ?> <?php if (Permission::has($this->forum_topic, Model_Forum_Topic::PERMISSION_POST, self::$_user)) { echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic), 'action' => 'quote')), __('Reply'), array('class' => 'post-quote')) . ' • '; } ?> <?php echo HTML::time(Date::short_span($this->forum_post->created, true, true), $this->forum_post->created); ?> </small> <?php if ($this->author) { echo HTML::user($this->author->light_array()); if ($this->author->title) { echo ' <small>“' . HTML::chars($this->author->title) . '”</small>'; } } else { echo $this->forum_post->author_name; echo ' <small>“' . __('Guest') . '”</small>'; } ?> </header> <?php if ($this->forum_post->parent_id) { echo __('Replying to :parent', array(':parent' => HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($this->forum_topic), 'id' => $this->forum_post->parent_id)) . '#post-' . $this->forum_post->parent_id, HTML::chars($this->forum_post->parent()->topic()->name)))); } ?> <?php echo BB::factory($this->forum_post->post)->render(); ?> <footer> <?php echo $this->author && $this->author->signature ? BB::factory("\n--\n" . $this->author->signature)->render() : ''; ?> <?php if ($this->forum_post->modify_count > 0) { echo '<br /><br />' . __('Edited :ago', array(':ago' => HTML::time(Date::fuzzy_span($this->forum_post->modified), $this->forum_post->modified))); } ?> </footer> </div> <?php return ob_get_clean(); }
/** * Creates CSRF token input. * * @param string $id e.g. uid * @param string $action optional action * @return string */ public static function csrf($id = '', $action = '') { return Form::hidden('token', Security::csrf($id, $action)); }
/** * Get side image. * * @param Model_Event $event * @return View_Generic_SideImage */ protected function section_event_image(Model_Event $event) { // Display front flyer by default if ($image = $event->flyer_front()) { $flyer = Model_Flyer::factory()->find_by_image($image->id); $link = Route::model($flyer); } else { if ($image = $event->flyer_back()) { $flyer = Model_Flyer::factory()->find_by_image($image->id); $link = Route::model($flyer); } else { if (count($flyers = $event->flyers())) { $flyer = $flyers[0]; $image = $flyer->image(); $link = Route::model($flyer); } else { $image = null; $link = null; } } } if (Permission::has($event, Model_User::PERMISSION_UPDATE, self::$user)) { $uri = Route::model($event, 'image'); $actions = array(); $actions[] = HTML::anchor($uri, '<i class="icon-plus-sign icon-white"></i> ' . __('Add flyer'), array('class' => 'btn btn-small btn-primary image-add ajaxify')); if ($image) { $actions[] = HTML::anchor($uri . '?token=' . Security::csrf() . '&front=' . $image->id, __('As front'), array('class' => 'btn btn-small btn-inverse image-change' . ($event->flyer_front_image_id == $image->id ? ' disabled' : ''), 'data-change' => 'front')); $actions[] = HTML::anchor($uri . '?token=' . Security::csrf() . '&back=' . $image->id, __('As back'), array('class' => 'btn btn-small btn-inverse image-change' . ($event->flyer_back_image_id == $image->id ? ' disabled' : ''), 'data-change' => 'back')); $actions[] = HTML::anchor($uri . '?token=' . Security::csrf() . '&delete=' . $image->id, '<i class="icon-trash"></i> ' . __('Delete'), array('class' => 'btn btn-small btn-inverse image-delete')); } } else { $actions = null; } $section = new View_Generic_SideImage($image, $link); $section->actions = $actions; return $section; }
/** * Render favorites. * * @return string */ public function favorites() { // Clickable favorites if (Permission::has($this->event, Model_Event::PERMISSION_FAVORITE, self::$_user)) { if ($this->event->is_favorite(self::$_user)) { // Favorite event, click to unfavorite return HTML::anchor(Route::model($this->event, 'unfavorite') . '?token=' . Security::csrf(), '<i class="icon-heart icon-white"></i> ' . $this->event->favorite_count, array('title' => __('Remove favorite'), 'class' => 'ajaxify btn btn-small btn-lovely active')); } else { // Non-favorite event, click to favorite if ($this->event->favorite_count) { return HTML::anchor(Route::model($this->event, 'favorite') . '?token=' . Security::csrf(), '<i class="icon-heart icon-white"></i> ' . $this->event->favorite_count, array('title' => __('Add to favorites'), 'class' => 'ajaxify btn btn-small btn-inverse active')); } else { return HTML::anchor(Route::model($this->event, 'favorite') . '?token=' . Security::csrf(), '<i class="icon-heart"></i>', array('title' => __('Add to favorites'), 'class' => 'ajaxify btn btn-small btn-inverse active')); } } } return $this->event->favorite_count ? '<span class="btn btn-small btn-inverse disabled"><i class="icon-heart icon-white"></i> ' . $this->event->favorite_count . '</a>' : ''; }
/** * Get image comments section. * * @param Model_Image $image * @param string $route * @return View_Generic_Comments */ public function section_image_comments(Model_Image $image, $route = 'gallery_image_comment') { $section = new View_Generic_Comments($image->comments(self::$user)); $section->delete = Route::url($route, array('id' => '%d', 'commentaction' => 'delete')) . '?token=' . Security::csrf(); $section->private = false; return $section; }
/** * Get CSRF token as a query string. * * @param string $id Custom token id, e.g. uid * @param string $action Optional action * @param integer $time Used only internally * @return string */ public static function csrf_query($id = '', $action = '', $time = 0) { return 'token=' . Security::csrf($id, $action, $time); }
/** * Get image mod * * @param Model_User $user * @return View_Module */ protected function _get_mod_image(Model_User $user) { if ($user->default_image->id) { $image = $user->default_image; } else { if (Validate::url($user->picture)) { $image = $user->picture; } else { $image = null; } } return View_Module::factory('generic/side_image', array('mod_actions2' => Permission::has($user, Model_User::PERMISSION_UPDATE, self::$user) ? array(array('link' => URL::user($user, 'image') . '?token=' . Security::csrf() . '&delete', 'text' => __('Delete'), 'class' => 'image-delete disabled'), array('link' => URL::user($user, 'image') . '?token=' . Security::csrf() . '&default', 'text' => __('Set as default'), 'class' => 'image-default disabled'), array('link' => URL::user($user, 'image'), 'text' => __('Add image'), 'class' => 'image-add ajaxify')) : null, 'image' => $image)); }
/** * Render view. * * @return string */ public function content() { $bbcode = BB::factory(); ob_start(); if ($this->my) { $panel_class = 'panel-success'; } elseif ($this->owner) { $panel_class = 'panel-info'; } else { $panel_class = 'panel-default'; } ?> <div class="pull-left"> <?php if ($this->author) { ?> <?php echo HTML::avatar($this->author->avatar_url, $this->author->username); ?> <p> <small><?php echo __('Posts: :posts', array(':posts' => '<var>' . Num::format($this->author->post_count, 0) . '</var>')); ?> </small> </p> <?php } else { ?> <?php echo HTML::avatar(false); ?> <?php } ?> </div> <div class="media-body panel <?php echo $panel_class; ?> "> <header class="panel-heading"<?php echo $this->forum_post->id == $this->forum_topic->last_post_id ? ' id="last"' : ''; ?> > <small class="pull-right"> <?php echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic))) . '#post-' . $this->forum_post->id, '#' . $this->nth, array('title' => __('Permalink'))); ?> • <?php if (Permission::has($this->forum_post, Model_Forum_Post::PERMISSION_UPDATE)) { echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic), 'action' => 'edit')), __('Edit'), array('class' => 'post-edit')); } ?> <?php if (Permission::has($this->forum_post, Model_Forum_Post::PERMISSION_DELETE)) { echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic), 'action' => 'delete')) . '?token=' . Security::csrf(), __('Delete'), array('class' => 'post-delete')); } ?> <?php if (Permission::has($this->forum_topic, Model_Forum_Topic::PERMISSION_POST)) { echo HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('id' => Route::model_id($this->forum_post), 'topic_id' => Route::model_id($this->forum_topic), 'action' => 'quote')), __('Reply'), array('class' => 'post-quote')); } ?> • <?php echo HTML::time(Date::short_span($this->forum_post->created, true, true), $this->forum_post->created); ?> <?php if ($this->forum_post->modify_count > 0) { ?> • <span title="<?php echo __($this->forum_post->modify_count == 1 ? ':edits edit, :ago' : ':edits edits, last :ago', array(':edits' => $this->forum_post->modify_count, ':ago' => Date::fuzzy_span($this->forum_post->modified))); ?> "><?php echo __('Edited'); ?> </span> <?php } ?> </small> <?php if ($this->author) { echo HTML::user($this->author->light_array()); if ($this->author->title) { echo ' <small>' . HTML::chars($this->author->title) . '</small>'; } } else { echo $this->forum_post->author_name; echo ' <small>' . __('Guest') . '</small>'; } ?> </header> <div class="panel-body"> <?php if ($this->forum_post->parent_id) { echo '<p class="text-muted">' . __('Replying to :parent', array(':parent' => HTML::anchor(Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($this->forum_topic), 'id' => $this->forum_post->parent_id)) . '#post-' . $this->forum_post->parent_id, HTML::chars($this->forum_post->parent()->topic()->name)))) . ':</p>'; } ?> <?php echo $bbcode->render($this->forum_post->post); ?> <?php if ($this->forum_post->attachment) { $attachment = 'images/liitteet/' . $this->forum_post->attachment; if (file_exists($attachment)) { echo HTML::image($attachment); } } ?> </div> <?php if ($this->author && $this->author->signature) { ?> <footer class="panel-body"> <?php echo $this->author && $this->author->signature ? $bbcode->render("\n--\n" . $this->author->signature, true) : ''; ?> </footer> <?php } ?> </div> <?php return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); // Load images $flyers = $this->event->flyers(); if ((!count($flyers) || !$flyers->current()->image()) && $this->event->flyer_front_url) { // Legacy support $flyer_url = ($flyer = $flyers->current()) ? $flyer->image_url() : $this->event->flyer_front_url; echo HTML::image($flyer_url, ['class' => 'img-responsive']); } elseif (count($flyers)) { // Check for actions if (Permission::has($this->event, Model_Event::PERMISSION_UPDATE)) { $action_uri = Route::model($this->event, 'flyer'); } // Check for missing default image $active_id = $this->event->flyer_id; if (!$active_id) { $active_id = $flyers->current()->id; } $slide = 0; ?> <div class="carousel"> <?php if (count($flyers) > 1) { ?> <ol class="carousel-indicators"> <?php foreach ($flyers as $flyer) { ?> <li data-target="#<?php echo $this->id; ?> " data-slide-to="<?php echo $slide++; ?> "<?php echo $flyer->id == $active_id ? ' class="active"' : ''; ?> ></li> <?php } ?> </ol> <?php } ?> <div class="carousel-inner"> <?php foreach ($flyers as $flyer) { if ($flyer->image()) { ?> <div class="item<?php echo $flyer->id == $active_id ? ' active' : ''; ?> "> <?php echo HTML::anchor(Route::model($flyer), HTML::image($flyer->image()->get_url(), ['class' => 'img-responsive'])); ?> <?php if (isset($action_uri)) { ?> <div class="actions"> <?php if ($flyer->id == $this->event->flyer_id) { echo HTML::anchor('#', '<i class="fa fa-picture-o"></i> ' . __('Set as default'), array('class' => 'btn btn-default btn-xs image-change disabled')); } else { echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&default=' . $flyer->id, '<i class="fa fa-picture-o"></i> ' . __('Set as default'), array('class' => 'btn btn-default btn-xs image-change')); } ?> <?php echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&delete=' . $flyer->id, '<i class="fa fa-trash-o"></i> ' . __('Delete'), array('class' => 'btn btn-default btn-xs image-delete')); ?> </div> <?php } ?> </div> <?php } } ?> </div> <?php if (count($flyers) > 1) { ?> <a class="carousel-control left" href="#<?php echo $this->id; ?> " data-slide="prev"><i class="fa fa-chevron-left icon-prev"></i></a> <a class="carousel-control right" href="#<?php echo $this->id; ?> " data-slide="next"><i class="fa fa-chevron-right icon-next"></i></a> <?php } ?> </div> <?php } elseif (Permission::has($this->event, Model_Event::PERMISSION_UPDATE)) { // Add new flyer echo HTML::anchor(Route::model($this->event, 'flyer'), '<i class="fa fa-picture-o"></i> ' . __('Upload flyer'), array('class' => 'empty ajaxify')); } return ob_get_clean(); }
/** * 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); }
/** * Get comments section. * * @param Model_User $user * @param string $route * @return View_Generic_Comments */ public function section_comments(Model_User $user, $route = 'user_comment') { // Pagination $per_page = 25; $pagination = new View_Generic_Pagination(array('base_url' => URL::user($user), 'items_per_page' => $per_page, 'total_items' => max(1, count($user->comments(self::$user, null))))); $section = new View_Generic_Comments($user->comments(self::$user, $pagination)); $section->delete = Route::url($route, array('id' => '%d', 'commentaction' => 'delete')) . '?token=' . Security::csrf(); $section->private = Route::url($route, array('id' => '%d', 'commentaction' => 'private')) . '?token=' . Security::csrf(); $section->new_comments = self::$user && self::$user->id === $user->id ? $user->new_comment_count : null; $section->pagination = $pagination; return $section; }
</small> <nav class="actions"> <?php echo HTML::anchor(Route::get($private ? 'forum_private_post' : 'forum_post')->uri(array('id' => Route::model_id($post), 'topic_id' => Route::model_id($topic))) . '#post-' . $post->id, '#' . $number, array('title' => __('Permalink'))); ?> <?php if (Permission::has($post, Model_Forum_Post::PERMISSION_UPDATE, $user)) { echo HTML::anchor(Route::get($private ? 'forum_private_post' : 'forum_post')->uri(array('id' => Route::model_id($post), 'topic_id' => Route::model_id($topic), 'action' => 'edit')), __('Edit'), array('class' => 'action post-edit small')); } ?> <?php if (Permission::has($post, Model_Forum_Post::PERMISSION_DELETE, $user)) { echo HTML::anchor(Route::get($private ? 'forum_private_post' : 'forum_post')->uri(array('id' => Route::model_id($post), 'topic_id' => Route::model_id($topic), 'action' => 'delete')) . '?token=' . Security::csrf(), __('Delete'), array('class' => 'action post-delete small')); } ?> <?php if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, $user)) { echo HTML::anchor(Route::get($private ? 'forum_private_post' : 'forum_post')->uri(array('id' => Route::model_id($post), 'topic_id' => Route::model_id($topic), 'action' => 'quote')), __('Quote'), array('class' => 'action post-quote small')); } ?> </nav> </header> <?php if ($post->parent_id) { echo __('Replying to :parent', array(':parent' => HTML::anchor(Route::get($private ? 'forum_private_post' : 'forum_post')->uri(array('topic_id' => Route::model_id($topic), 'id' => $post->parent_id)) . '#post-' . $post->parent_id, HTML::chars($post->parent()->topic()->name)))); }
/** * Render view. * * @return string */ public function content() { ob_start(); // Load images $flyers = $this->event->flyers(); if (!count($flyers) && $this->event->flyer_front_url) { // Legacy support echo HTML::image($this->event->flyer_front_url, array('width' => 290)); } elseif (count($flyers)) { // Check for actions if (Permission::has($this->event, Model_Event::PERMISSION_UPDATE, self::$_user)) { $action_uri = Route::model($this->event, 'image'); } // Check for missing default image $active_id = $this->event->flyer_front_image_id; if (!$active_id) { $active_id = $flyers->current()->image_id; } ?> <div class="carousel-inner"> <?php foreach ($flyers as $flyer) { ?> <div class="item<?php echo $flyer->image_id == $active_id ? ' active' : ''; ?> "> <?php echo HTML::image($flyer->image()->get_url(), array('width' => 290)); ?> <?php if (isset($action_uri)) { ?> <div class="btn-group"> <?php if ($flyer->image_id == $this->event->flyer_front_image_id) { echo HTML::anchor('#', __('As front'), array('class' => 'btn btn-mini image-change disabled')); echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&back=' . $flyer->image_id, __('As back'), array('class' => 'btn btn-mini image-change')); } elseif ($flyer->image_id == $this->event->flyer_back_image_id) { echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&front=' . $flyer->image_id, __('As front'), array('class' => 'btn btn-mini image-change')); echo HTML::anchor('#', __('As back'), array('class' => 'btn btn-mini image-change disabled')); } else { echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&front=' . $flyer->image_id, __('As front'), array('class' => 'btn btn-mini image-change')); echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&back=' . $flyer->image_id, __('As back'), array('class' => 'btn btn-mini image-change')); } ?> <?php echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&delete=' . $flyer->image_id, '<i class="icon-trash"></i> ' . __('Delete'), array('class' => 'btn btn-mini image-delete')); ?> </div> <?php } ?> </div> <?php } ?> </div> <?php if (count($flyers) > 1) { ?> <a class="carousel-control left" href="#<?php echo $this->id; ?> " data-slide="prev">‹</a> <a class="carousel-control right" href="#<?php echo $this->id; ?> " data-slide="next">›</a> <?php } ?> <?php } elseif (Permission::has($this->event, Model_Event::PERMISSION_UPDATE, self::$_user)) { // Add new flyer echo HTML::anchor(Route::model($this->event, 'image'), '<i class="icon-picture icon-white"></i> ' . __('Add flyer'), array('class' => 'empty ajaxify')); } return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); // Load images $images = $this->user->images(); // Is Facebook image set $facebook = !!strpos($this->user->picture, 'facebook.com'); // Legacy support if ($this->user->picture && !count($images) && !$facebook) { echo HTML::image($this->user->picture); } if (count($images) || $facebook) { $count = count($images); if ($facebook) { $count++; } // Check for actions if (Permission::has($this->user, Model_User::PERMISSION_UPDATE)) { $action_uri = URL::user($this->user, 'image'); } // Check for missing default image $active_id = $this->user->default_image_id; if (!$active_id && !$facebook) { $image = $images->current(); $active_id = $image->id; } $slide = 0; ?> <div class="carousel"> <?php if ($count > 1) { ?> <ol class="carousel-indicators"> <?php if ($facebook) { ?> <li data-target="#facebook" data-slide-to="<?php echo $slide++; ?> " class="active"></li> <?php } ?> <?php foreach ($images as $image) { ?> <li data-target="#<?php echo $this->id; ?> " data-slide-to="<?php echo $slide++; ?> "<?php echo $image->id == $active_id ? ' class="active"' : ''; ?> ></li> <?php } ?> </ol> <?php } ?> <div class="carousel-inner"> <?php if ($facebook) { ?> <div class="item active"> <?php echo HTML::image($this->user->picture); ?> <?php if (isset($action_uri)) { ?> <div class="actions"> <?php echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&delete=facebook', '<i class="fa fa-trash-o"></i> ' . __('Delete'), array('class' => 'btn btn-xs btn-default image-delete')); ?> </div> <?php } ?> </div> <?php } ?> <?php foreach ($images as $image) { ?> <div class="item<?php echo $image->id == $active_id ? ' active' : ''; ?> "> <?php echo HTML::image($image->get_url()); ?> <?php if (isset($action_uri)) { ?> <div class="actions"> <?php if ($image->id == $this->user->default_image_id) { echo HTML::anchor('#', '<i class="fa fa-home"></i> ' . __('Set as default'), array('class' => 'btn btn-xs btn-default image-change disabled')); } else { echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&default=' . $image->id, '<i class="fa fa-user"></i> ' . __('Set as default'), array('class' => 'btn btn-xs btn-default image-change')); } ?> <?php echo HTML::anchor($action_uri . '?token=' . Security::csrf() . '&delete=' . $image->id, '<i class="fa fa-trash-o"></i> ' . __('Delete'), array('class' => 'btn btn-xs btn-default image-delete')); ?> </div> <?php } ?> </div> <?php } ?> </div> <?php if ($count > 1) { ?> <a class="carousel-control left" href="#<?php echo $this->id; ?> " data-slide="prev"><i class="fa fa-chevron-left icon-prev"></i></a> <a class="carousel-control right" href="#<?php echo $this->id; ?> " data-slide="next"><i class="fa fa-chevron-right icon-next"></i></a> <?php } ?> </div> <br> <?php } // Image search echo HTML::anchor(Route::url('galleries', array('action' => 'search')) . '?user='******'<i class="fa fa-search"></i> ' . __('Search from galleries'), array('class' => 'btn btn-default btn-block')); return ob_get_clean(); }