Exemplo n.º 1
0
 /**
  * Controller default action
  */
 public function action_index()
 {
     $this->page_title = __('Welcome to :site', array(':site' => Kohana::config('site.site_name')));
     // Display news feed
     $newsfeed = new NewsFeed(self::$user);
     $newsfeed->max_items = 25;
     Widget::add('main', View_Module::factory('generic/newsfeed', array('newsfeed' => $newsfeed->as_array())));
     // Shout
     $shouts = Jelly::select('shout')->limit(10)->execute();
     Widget::add('side', View_Module::factory('generic/shout', array('mod_title' => __('Shouts'), 'shouts' => $shouts, 'can_shout' => Permission::has(new Model_Shout(), Model_Shout::PERMISSION_CREATE), 'errors' => array(), 'values' => array())));
 }
Exemplo n.º 2
0
 /**
  * Action: edit
  */
 public function action_edit()
 {
     $this->history = false;
     // Load role
     $role_id = (int) $this->request->param('id', 0);
     if ($role_id) {
         $role = Jelly::select('role', $role_id);
         if (!$role->loaded()) {
             throw new Model_Exception($role, $role_id);
         }
         Permission::required($role, Model_Role::PERMISSION_UPDATE, self::$user);
     } else {
         $role = Jelly::factory('role');
         Permission::required($role, Model_Role::PERMISSION_CREATE, self::$user);
     }
     // Handle post
     $errors = array();
     if ($_POST) {
         $role->set($_POST);
         try {
             $role->save();
             $this->request->redirect(Route::get('roles')->uri());
         } catch (Validate_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Set title
     $this->page_title = __('Role') . ($role->name ? ': ' . HTML::chars($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', false), 'text' => __('Delete role'), 'class' => 'role-delete');
     }
     // Build form
     $form = array('values' => $role, 'errors' => $errors, 'cancel' => Request::back(Route::get('roles')->uri(), true), 'groups' => array(array('fields' => array('name' => array(), 'description' => array()))));
     //Widget::add('main', View_Module::factory('roles/edit', array('role' => $role, 'errors' => $errors)));
     Widget::add('main', View_Module::factory('form/anqh', array('form' => $form)));
 }
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 4
0
Arquivo: topic.php Projeto: anqh/forum
 /**
  * Action: index
  */
 public function action_index()
 {
     // Go to post?
     $topic_id = (int) $this->request->param('topic_id');
     if ($topic_id) {
         $post_id = (int) $this->request->param('id');
     } else {
         $topic_id = (int) $this->request->param('id');
     }
     // Load 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_READ, self::$user);
     // Did we request single post with ajax?
     if (($this->ajax || $this->internal) && isset($post_id)) {
         $this->history = false;
         $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id);
         if (!$post->loaded()) {
             throw new Model_Exception($topic, $topic_id);
         }
         // Permission is already checked by the topic, no need to check for post
         $this->response->body($this->section_post($topic, $post));
         return;
     }
     // Update counts
     if ($this->private) {
         $topic->mark_as_read(self::$user);
     }
     if (!self::$user || $topic->author_id != self::$user->id) {
         $topic->read_count++;
         $topic->save();
     }
     // Build page
     $this->view = new View_Page();
     $this->view->title_html = Forum::topic($topic);
     $this->view->subtitle = __($topic->post_count == 1 ? ':posts post' : ':posts posts', array(':posts' => Num::format($topic->post_count, 0)));
     $this->view->tab = 'topic';
     $this->page_actions['topic'] = array('link' => Route::model($topic), 'text' => '<i class="icon-comment icon-white"></i> ' . __('Topic'));
     // Public topic extras
     if (!$this->private) {
         // Quotes are supported only in public forum as we get notifications anyway in private
         if (self::$user) {
             $quotes = Model_Forum_Quote::factory()->find_by_user(self::$user);
             if (count($quotes)) {
                 foreach ($quotes as $quote) {
                     if ($topic->id == $quote->forum_topic_id) {
                         $quote->delete();
                         break;
                     }
                 }
             }
         }
         // Facebook
         if (Kohana::$config->load('site.facebook')) {
             Anqh::open_graph('title', $topic->name);
             Anqh::open_graph('url', URL::site(Route::url('forum_topic', array('id' => $topic->id, 'action' => '')), true));
         }
         Anqh::share(true);
         // Model binding
         $area = $topic->area();
         if ($area->type == Model_Forum_Area::TYPE_BIND && $topic->bind_id) {
             if ($bind = Model_Forum_Area::get_binds($area->bind)) {
                 $model = AutoModeler::factory($bind['model'], $topic->bind_id);
                 if ($model->loaded()) {
                     // Set actions
                     $this->page_actions[] = array('link' => Route::model($model), 'text' => $bind['link']);
                     // Set views
                     foreach ((array) $bind['view'] as $view) {
                         $this->view->add(View_Page::COLUMN_SIDE, View_Module::factory($view, array($bind['model'] => $model)), Widget::TOP);
                     }
                 }
             }
         }
     }
     // Public topic extras
     // Set actions
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $this->view->actions[] = array('link' => Request::current_uri() . '#reply', 'text' => '<i class="icon-comment icon-white"></i> ' . __('Reply to topic'), 'class' => 'btn btn-primary topic-post');
     }
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($topic, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit topic'));
     }
     // Breadcrumbs
     $this->page_breadcrumbs[] = HTML::anchor(Route::url('forum_group'), __('Forum'));
     $this->page_breadcrumbs[] = HTML::anchor(Route::model($topic->area()), $topic->area()->name);
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $pagination = $this->section_pagination($topic));
     $this->view->subtitle .= ', ' . __($pagination->total_pages == 1 ? ':pages page' : ':pages pages', array(':pages' => Num::format($pagination->total_pages, 0)));
     $this->view->subtitle .= ', ' . __($topic->read_count == 1 ? ':views view' : ':views views', array(':views' => Num::format($topic->read_count, 0)));
     // Go to post?
     if (isset($post_id)) {
         $pagination->item($topic->get_post_number($post_id) + 1);
         // We need to set pagination urls manually if jumped to a post
         $pagination->base_url = Route::model($topic);
     }
     // Recipients
     if ($this->private) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_recipients($topic));
         $this->view->add(View_Page::COLUMN_MAIN, '<hr />');
     }
     // Posts
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_topic($topic, $pagination));
     // Reply
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $section = $this->section_post_edit(View_Forum_PostEdit::REPLY, $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory());
         $section->forum_topic = $topic;
         $this->view->add(View_Page::COLUMN_MAIN, $section);
     }
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $pagination);
     $this->_side_views();
 }
Exemplo n.º 5
0
 /**
  * Print an error message
  *
  * @param  string  $message
  */
 public function error($message = null)
 {
     !$message && ($message = __('Error occured.'));
     Widget::add('error', View_Module::factory('generic/error', array('message' => $message)));
 }
Exemplo n.º 6
0
 /**
  * Edit tag
  *
  * @param  integer  $group_id
  * @param  integer  $tag_id
  */
 protected function _edit_tag($group_id = null, $tag_id = null)
 {
     $this->history = false;
     if ($group_id) {
         // Add new tag
         $group = Jelly::select('tag_group')->load($group_id);
         if (!$group->loaded()) {
             throw new Model_Exception($group, $group_id);
         }
         $this->page_title = HTML::chars($group->name);
         $this->page_subtitle = HTML::chars($group->description);
         $tag = Jelly::factory('tag')->set(array('group' => $group));
         $cancel = Route::model($group);
     } else {
         if ($tag_id) {
             // Edit old tag
             $tag = Jelly::select('tag')->load($tag_id);
             if (!$tag->loaded()) {
                 throw new Model_Exception($tag, $tag_id);
             }
             $this->page_title = HTML::chars($tag->name);
             $this->page_subtitle = HTML::chars($tag->description);
             $cancel = Route::model($tag);
         } else {
             Request::back(Route::get('tags')->uri());
         }
     }
     $errors = array();
     if ($_POST) {
         $tag->set($_POST);
         try {
             $tag->save();
             $this->request->redirect(Route::model($tag));
         } catch (Validate_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Build form
     $form = array('values' => $tag, 'errors' => $errors, 'cancel' => $cancel, 'groups' => array(array('fields' => array('name' => array(), 'description' => array()))));
     Widget::add('main', View_Module::factory('form/anqh', array('form' => $form)));
 }
Exemplo n.º 7
0
 /**
  * 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));
 }
Exemplo n.º 8
0
 /**
  * Edit venue data in dialog
  */
 protected function _edit_venue_dialog()
 {
     echo View_Module::factory('venues/edit_dialog', array());
 }