Example #1
0
File: group.php Project: anqh/forum
 /**
  * Action: index
  */
 public function action_index()
 {
     // Load group(s)
     $group_id = (int) $this->request->param('id');
     $actions = array();
     if (!$group_id) {
         // All groups
         $groups = Model_Forum_Group::factory()->find_all();
         if (Permission::has(new Model_Forum_Group(), Model_Forum_Group::PERMISSION_CREATE, self::$user)) {
             $actions[] = array('link' => Route::url('forum_group_add'), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New group'));
         }
     } else {
         // One group
         $group = Model_Forum_Group::factory($group_id);
         if (!$group->loaded()) {
             throw new Model_Exception($group, $group_id);
         }
         Permission::required($group, Model_Forum_Group::PERMISSION_READ, self::$user);
         if (Permission::has($group, Model_Forum_Group::PERMISSION_UPDATE, self::$user)) {
             $actions[] = array('link' => Route::model($group, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit group'));
         }
         if (Permission::has($group, Model_Forum_Group::PERMISSION_CREATE_AREA, self::$user)) {
             $actions[] = array('link' => Route::model($group, 'add'), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New area'));
         }
         $groups = array($group);
     }
     // Build page
     $this->view = new View_Page(count($groups) > 1 ? __('Forum areas') : $groups[0]->name);
     $this->view->tab = 'areas';
     $this->view->actions = $actions;
     foreach ($groups as $group) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_group($group));
     }
     $this->_side_views();
 }
Example #2
0
File: forum.php Project: anqh/forum
 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     $this->page_title = __('Forum');
     // Generic page actions
     $this->page_actions['new-posts'] = array('link' => Route::url('forum'), 'text' => '<i class="icon-comment icon-white"></i> ' . __('New posts'));
     // Forum areas dropdown
     $groups = Model_Forum_Group::factory()->find_all();
     $areas = array();
     foreach ($groups as $group) {
         $divider = false;
         foreach ($group->areas() as $area) {
             if (Permission::has($area, Model_Forum_Area::PERMISSION_READ, self::$user)) {
                 $divider = true;
                 $areas[] = array('link' => Route::model($area), 'text' => HTML::entities($area->name));
             }
         }
         if ($divider) {
             $areas[] = array('divider' => true);
         }
     }
     array_pop($areas);
     $this->page_actions['areas'] = array('link' => Route::url('forum_group'), 'text' => '<i class="icon-folder-open icon-white"></i> ' . __('Areas'));
     $this->page_actions['area'] = array('link' => Route::url('forum_group'), 'text' => '', 'dropdown' => $areas);
     if (self::$user) {
         $this->page_actions['private-messages'] = array('link' => Forum::private_messages_url(), 'text' => '<i class="icon-envelope icon-white"></i> ' . __('Private messages'));
     }
 }
Example #3
0
File: group.php Project: anqh/anqh
 /**
  * Action: index
  */
 public function action_index()
 {
     // Load groups
     $groups = Model_Forum_Group::factory()->find_all();
     // Build page
     $this->view = new View_Page(__('Forum'));
     $this->view->tab = 'areas';
     // Set actions
     if (Permission::has(new Model_Forum_Group(), Model_Forum_Group::PERMISSION_CREATE)) {
         $this->view->actions[] = array('link' => Route::url('forum_group_add'), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New group'));
     }
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_groups($groups));
     $this->_side_views();
 }
Example #4
0
File: area.php Project: anqh/forum
 /**
  * Action: edit
  */
 public function action_edit()
 {
     $this->history = false;
     // Load area
     $area_id = (int) $this->request->param('id');
     if ($area_id) {
         $area = Model_Forum_Area::factory($area_id);
         if (!$area->loaded()) {
             throw new Model_Exception($area, $area_id);
         }
         Permission::required($area, Model_Forum_Area::PERMISSION_UPDATE, self::$user);
     } else {
         $area = new Model_Forum_Area();
         $area->author_id = self::$user->id;
         $area->created = time();
     }
     // Load group
     if ($area->loaded()) {
         $group = $area->group();
     } else {
         if ($group_id = (int) $this->request->param('group_id')) {
             $group = Model_Forum_Group::factory($group_id);
             $area->forum_group_id = $group->id;
             if (!$group->loaded()) {
                 throw new Model_Exception($group, $group_id);
             }
             Permission::required($group, Model_Forum_Group::PERMISSION_CREATE_AREA, self::$user);
         }
     }
     // Handle post
     $errors = array();
     if ($_POST) {
         $area->set_fields(Arr::extract($_POST, Model_Forum_Area::$editable_fields));
         try {
             $area->save();
             $this->request->redirect(Route::model($area));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Build page
     $this->view = new View_Page(__('Forum area') . ($area->name ? ': ' . HTML::chars($area->name) : ''));
     $this->view->tab = 'areas';
     // Set actions
     if ($area->loaded() && Permission::has($area, Model_Forum_Area::PERMISSION_DELETE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($area, 'delete'), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete area'), 'class' => 'btn btn-danger area-delete');
     }
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_edit($area, $errors));
 }
Example #5
0
File: forum.php Project: anqh/anqh
 /**
  * Action: latest posts
  */
 public function action_index()
 {
     $this->view = new View_Page(__('New posts'));
     $this->view->tab = 'areas';
     // Actions
     if (Permission::has(new Model_Forum_Group(), Model_Forum_Group::PERMISSION_CREATE)) {
         $this->view->actions[] = array('link' => Route::url('forum_group_add'), 'text' => '<i class="icon-plus-sign"></i> ' . __('New group'));
     }
     // New posts
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_topics(Model_Forum_Topic::factory()->find_active(20)));
     // Areas
     $groups = Model_Forum_Group::factory()->find_all();
     $this->view->add(View_Page::COLUMN_RIGHT, $this->section_groups($groups));
     //		$this->_side_views();
 }
Example #6
0
File: area.php Project: anqh/anqh
 /**
  * Get forum group.
  *
  * @return  Model_Forum_Group
  */
 public function group()
 {
     try {
         return $this->forum_group_id ? Model_Forum_Group::factory($this->forum_group_id) : null;
     } catch (AutoModeler_Exception $e) {
         return null;
     }
 }
Example #7
0
File: group.php Project: anqh/forum
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $areas = $this->group->areas();
        if (count($areas)) {
            ?>

<table class="table">
	<thead>
		<tr>
			<th class="span4"><h3><?php 
            echo HTML::anchor(Route::model($this->group), HTML::chars($this->group->name));
            ?>
</h3></th>
			<th class="span1"><?php 
            echo __('Topics');
            ?>
</th>
			<th class="span1"><?php 
            echo __('Posts');
            ?>
</th>
			<th class="span2"><?php 
            echo __('Latest post');
            ?>
</th>
		</tr>
	</thead>

	<tbody>

	<?php 
            foreach ($areas as $area) {
                ?>

		<?php 
                if (Permission::has($area, Model_Forum_Area::PERMISSION_READ, self::$_user)) {
                    ?>

		<tr>
			<td>
				<h4><?php 
                    echo HTML::anchor(Route::model($area), HTML::chars($area->name));
                    ?>
</h4>
				<?php 
                    echo $area->description;
                    ?>
			</td>
			<td><?php 
                    echo Num::format($area->topic_count, 0);
                    ?>
</td>
			<td><?php 
                    echo Num::format($area->post_count, 0);
                    ?>
</td>
			<td>

			<?php 
                    if ($area->topic_count > 0) {
                        $last_topic = $area->last_topic();
                        ?>

				<small class="ago"><?php 
                        echo HTML::time(Date::short_span($last_topic->last_posted, true, true), $last_topic->last_posted);
                        ?>
</small>
				<?php 
                        echo HTML::user($last_topic->last_post()->author_id, $last_topic->last_poster);
                        ?>
<br />
				<?php 
                        echo HTML::anchor(Route::model($last_topic), '<i class="muted iconic-upload"></i>', array('title' => __('First post')));
                        ?>
				<?php 
                        echo HTML::anchor(Route::model($last_topic, '?page=last#last'), HTML::chars($last_topic->name), array('title' => HTML::chars($last_topic->name)));
                        ?>

			<?php 
                    } else {
                        ?>

				<sup><?php 
                        echo __('No topics yet.');
                        ?>
</sup>

			<?php 
                    }
                    ?>

			</td>
		</tr>

		<?php 
                } elseif ($area->status != Model_Forum_Area::STATUS_HIDDEN) {
                    ?>

		<tr>
			<td colspan="4">
				<h4><?php 
                    echo HTML::chars($area->name);
                    ?>
</h4>
				<?php 
                    echo __('Members only');
                    ?>
			</td>
		</tr>

		<?php 
                }
                ?>

	<?php 
            }
            ?>

	</tbody>
</table>

<?php 
        } else {
            echo new View_Alert(__('No areas yet.'), null, View_Alert::INFO);
        }
        return ob_get_clean();
    }
Example #8
0
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        // Build available groups list
        $groups = array();
        foreach (Model_Forum_Group::factory()->find_all() as $_group) {
            $groups[$_group->id] = $_group->name;
        }
        echo Form::open();
        ?>

	<fieldset>

		<?php 
        echo Form::control_group(Form::select('forum_group_id', $groups, $this->area->id), array('forum_group_id' => __('Group')), Arr::get($this->errors, 'forum_group_id'));
        ?>

		<?php 
        echo Form::control_group(Form::input('name', $this->area->name), array('name' => __('Name')), Arr::get($this->errors, 'name'));
        ?>

		<?php 
        echo Form::control_group(Form::input('description', $this->area->description), array('description' => __('Description')), Arr::get($this->errors, 'description'));
        ?>

		<?php 
        echo Form::control_group(Form::input('sort', $this->area->sort, array('class' => 'input-mini')), array('sort' => __('Sort')), Arr::get($this->errors, 'sort'));
        ?>

	</fieldset>

	<fieldset>
		<legend><?php 
        echo __('Settings');
        ?>
</legend>

		<?php 
        echo Form::control_group(Form::select('access_read', array(Model_Forum_Area::READ_NORMAL => __('Everybody'), Model_Forum_Area::READ_MEMBERS => __('Members only')), $this->area->access_read), array('access_read' => __('Read access')), Arr::get($this->errors, 'access_read'));
        ?>

		<?php 
        echo Form::control_group(Form::select('access_write', array(Model_Forum_Area::WRITE_NORMAL => __('Members'), Model_Forum_Area::WRITE_ADMINS => __('Admins only')), $this->area->access_write), array('access_write' => __('Write access')), Arr::get($this->errors, 'access_write'));
        ?>

		<?php 
        echo Form::control_group(Form::select('type', array(Model_Forum_Area::TYPE_NORMAL => __('Normal'), Model_Forum_Area::TYPE_BIND => __('Bind, topics bound to content')), $this->area->type), array('type' => __('Type')), Arr::get($this->errors, 'type'));
        ?>

		<?php 
        echo Form::control_group(Form::select('bind', array('' => __('None')) + Model_Forum_Area::get_binds(), $this->area->bind), array('bind' => __('Bind config')), Arr::get($this->errors, 'bind'));
        ?>

		<?php 
        echo Form::control_group(Form::select('status', array(Model_Forum_Area::STATUS_NORMAL => __('Normal'), Model_Forum_Area::STATUS_HIDDEN => __('Hidden')), $this->area->status), array('status' => __('Status')), Arr::get($this->errors, 'status'));
        ?>

	</fieldset>

	<fieldset class="form-actions">
		<?php 
        echo Form::button('save', __('Save'), array('type' => 'submit', 'class' => 'btn btn-success btn-large'));
        ?>
		<?php 
        echo HTML::anchor(Request::back(Route::url('forum_group'), true), __('Cancel'), array('class' => 'cancel'));
        ?>

		<?php 
        echo Form::csrf();
        ?>
	</fieldset>

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #9
0
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        // Create form attributes
        $attributes = array('class' => 'media');
        if ($this->form_id) {
            $attributes['id'] = $this->form_id;
        }
        $button = __('Save');
        $author = Visitor::$user;
        if (!$this->form_action) {
            switch ($this->mode) {
                case self::QUOTE:
                    $this->form_action = Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => $this->forum_topic->id, 'id' => $this->forum_post->parent_id, 'action' => 'quote'));
                    $button = __('Reply');
                    break;
                case self::REPLY:
                    $this->form_action = Route::model($this->forum_topic, 'reply');
                    $button = __('Reply');
                    break;
                case self::EDIT_POST:
                    $this->form_action = Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => $this->forum_topic->id, 'id' => $this->forum_post->id, 'action' => 'edit'));
                    $author = $this->forum_post->author();
                    break;
            }
        }
        echo Form::open($this->form_action ? $this->form_action : null, $attributes);
        // Progressively add content, note that we don't break
        switch ($this->mode) {
            // Adding new topic
            case self::NEW_TOPIC:
                // Editing an old topic
            // Editing an old topic
            case self::EDIT_TOPIC:
                $is_admin = Visitor::$user->has_role(array('admin', 'moderator', 'forum moderator'));
                if ($is_admin) {
                    // Build available areas list
                    $areas = array();
                    foreach (Model_Forum_Group::factory()->find_all() as $_group) {
                        $areas[$_group->name] = array();
                        foreach ($_group->areas() as $_area) {
                            $areas[$_group->name][$_area->id] = $_area->name;
                        }
                    }
                    ?>

<div class="panel panel-danger">
	<header class="panel-heading"><?php 
                    echo __('Admin tools');
                    ?>
</header>
	<fieldset class="form-horizontal panel-body">
		<div class="col-md-6">
			<?php 
                    echo Form::radios_wrap('sticky', array(Model_Forum_Topic::STICKY_NORMAL => __('Normal'), Model_Forum_Topic::STICKY_STICKY => '<i class="fa fa-thumb-tack text-warning"></i> ' . __('Pinned')), (int) $this->forum_topic->sticky, array('class' => 'radios'), __('Pinning'), Arr::get($this->errors, 'sticky'), null, true);
                    ?>
		</div>

		<div class="col-md-6">
			<?php 
                    echo Form::radios_wrap('status', array(Model_Forum_Topic::STATUS_NORMAL => __('Normal'), Model_Forum_Topic::STATUS_SINK => '<i class="fa fa-unlock text-muted"></i> ' . __('Sink'), Model_Forum_Topic::STATUS_LOCKED => '<i class="fa fa-lock text-muted"></i> ' . __('Locked')), (int) $this->forum_topic->status, array('class' => 'radios'), __('Status'), Arr::get($this->errors, 'status'), null, true);
                    ?>
		</div>

		<div class="col-md-12">
			<?php 
                    if (!$this->private) {
                        echo Form::select_wrap('forum_area_id', $areas, $this->forum_topic->forum_area_id, null, __('Area'), Arr::get($this->errors, 'forum_area_id'));
                    }
                    ?>
		</div>

	</fieldset>
</div>

		<?php 
                }
                // admin
                ?>

	<?php 
                echo Form::input_wrap('name', $this->forum_topic->name, null, __('Topic'), Arr::get($this->errors, 'name'));
                ?>

	<?php 
                if ($this->private) {
                    echo Form::textarea_wrap('recipients', $this->recipients, array('rows' => 3, 'placeholder' => __('Required')), true, __('Recipients'), Arr::get($this->errors, 'recipients'));
                }
                ?>

	<?php 
                if ($this->mode === self::EDIT_TOPIC && !$is_admin) {
                    ?>

<fieldset>
	<?php 
                    echo Form::button('save', $button, array('type' => 'submit', 'class' => 'btn btn-success btn-large'));
                    ?>
	<?php 
                    echo Form::button('preview', __('Preview'), array('class' => 'btn btn-default btn-large'));
                    ?>
	<?php 
                    echo $this->cancel ? HTML::anchor($this->cancel, __('Cancel'), array('class' => 'cancel')) : '';
                    ?>

	<?php 
                    echo Form::csrf();
                    ?>
</fieldset>

<?php 
                    break;
                }
                // Replying to a topic
            // Replying to a topic
            case self::REPLY:
            case self::QUOTE:
                ?>

<div class="pull-left">
	<?php 
                echo HTML::avatar(Visitor::$user->avatar_url, Visitor::$user->username);
                ?>
</div>

<?php 
                // Editing old post
            // Editing old post
            case self::EDIT_POST:
                ?>

<div class="post-edit media-body panel panel-success form-vertical">
	<header class="panel-heading">
		<?php 
                echo $author ? HTML::user($author) : HTML::chars($this->forum_post->author_name);
                ?>
	</header>

	<fieldset class="panel-body">
		<?php 
                echo Form::textarea_wrap('post', $this->forum_post->post, array('id' => uniqid()), true, null, Arr::get($this->errors, 'post'), null, true);
                ?>
	</fieldset>

	<fieldset class="panel-body">
		<?php 
                echo Form::button('save', $button, array('type' => 'submit', 'class' => 'btn btn-success btn-large'));
                ?>
		<?php 
                echo Form::button('preview', __('Preview'), array('class' => 'btn btn-default btn-large'));
                ?>
		<?php 
                echo $this->cancel ? HTML::anchor($this->cancel, __('Cancel'), array('class' => 'cancel')) : '';
                ?>

		<?php 
                echo Form::csrf();
                ?>
	</fieldset>
</div>

<?php 
        }
        ?>


<?php 
        echo Form::close();
        // Auto-complete recipients
        if ($this->private) {
            ?>

<script>
head.ready('anqh', function() {
	$('textarea[name=recipients]').autocompleteUser({
		user:     <?php 
            echo Visitor::$user->id;
            ?>
,
		maxUsers: 100
	});
});
</script>

<?php 
        }
        return ob_get_clean();
    }