Example #1
0
File: tag.php Project: anqh/core
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        echo Form::open();
        ?>

<fieldset>

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

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

</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('tags'), true), __('Cancel'), array('class' => 'cancel'));
        ?>
</fieldset>

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #2
0
File: user.php Project: anqh/core
 /**
  * Action: comment
  */
 public function action_comment()
 {
     $comment_id = (int) $this->request->param('id');
     $action = $this->request->param('commentaction');
     // Load blog_comment
     $comment = Model_User_Comment::factory($comment_id);
     if (($action == 'delete' || $action == 'private') && Security::csrf_valid() && $comment->loaded()) {
         $user = Model_User::find_user($comment->user_id);
         switch ($action) {
             // Delete comment
             case 'delete':
                 if (Permission::has($comment, Model_User_Comment::PERMISSION_DELETE, self::$user)) {
                     $comment->delete();
                     $user->comment_count--;
                     $user->save();
                 }
                 break;
                 // Set comment as private
             // Set comment as private
             case 'private':
                 if (Permission::has($comment, Model_User_Comment::PERMISSION_UPDATE, self::$user)) {
                     $comment->private = true;
                     $comment->save();
                 }
                 break;
         }
         if (!$this->ajax) {
             $this->request->redirect(Route::get('user')->uri(array('username' => urlencode($user->username))));
         }
     }
     if (!$this->ajax) {
         Request::back(Route::get('users')->uri());
     }
 }
Example #3
0
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $tags = $this->group->tags();
        if (empty($tags)) {
            ?>

<div class="empty">
	<?php 
            echo __('No tags yet.');
            ?>
</div>

<?php 
        } else {
            ?>

<ul>
	<?php 
            foreach ($tags as $tag) {
                ?>
	<li><?php 
                echo HTML::anchor(Route::model($tag), $tag->name);
                ?>
</li>
	<?php 
            }
            ?>
</ul>

<?php 
        }
        echo Form::open();
        ?>

<fieldset>

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

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

</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('tags'), true), __('Cancel'), array('class' => 'cancel'));
        ?>
</fieldset>

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #4
0
File: set.php Project: anqh/core
 /**
  * Set page width
  */
 public function action_width()
 {
     $width = $this->request->param('value');
     Session::instance()->set('page_width', $width == 'wide' ? 'liquid' : 'fixed');
     if ($this->ajax) {
         return;
     }
     Request::back();
 }
Example #5
0
File: roles.php Project: anqh/core
 /**
  * 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'));
 }
Example #6
0
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        echo Form::open();
        ?>

<fieldset>
	<legend><?php 
        echo __('Almost there!');
        ?>
</legend>

	<?php 
        echo Form::control_group(Form::input('username', $this->user->userame, array('class' => 'input-small', 'placeholder' => __('JohnDoe'))), array('username' => __('Username')), Arr::get($this->errors, 'username'), __('Choose a unique username with at least <var>:length</var> characters. No special characters, thank you.', array(':length' => Kohana::$config->load('visitor.username.length_min'))));
        ?>

	<?php 
        echo Form::control_group(Form::password('password'), array('password' => __('Password')), Arr::get($this->errors, 'password'));
        ?>

	<?php 
        echo Form::control_group(Form::password('password_confirm'), array('password_confirm' => __('Confirm')), Arr::get($this->errors, 'password_confirm'), __('Try to use letters, numbers and special characters for a stronger password, with at least <var>8</var> characters.'));
        ?>

	<?php 
        echo Form::control_group(Form::input('email', $this->user->email, array('disabled' => 'disabled', 'class' => 'input-xxlarge', 'placeholder' => __('*****@*****.**'))), array('email' => __('Email')), Arr::get($this->errors, 'email'), __('Please remember: sign up is available only with a valid, invited email.'));
        ?>

</fieldset>

<fieldset>
	<?php 
        echo Form::hidden('code', $this->code);
        ?>
	<?php 
        echo Form::button('register', __('Sign up!'), array('type' => 'submit', 'class' => 'btn btn-primary btn-large'));
        ?>
	<?php 
        echo HTML::anchor(Request::back('/', true), __('Cancel'), array('class' => 'cancel'));
        ?>
</fieldset>

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #7
0
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        echo Form::open();
        ?>

	<fieldset>

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

		<?php 
        echo Form::input_wrap('description', $this->group->description, null, __('Description'), Arr::get($this->errors, 'description'));
        ?>

		<?php 
        echo Form::input_wrap('sort', $this->group->sort, null, __('Sort'), Arr::get($this->errors, 'sort'));
        ?>

	</fieldset>

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

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

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #8
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)));
 }
Example #9
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 #10
0
File: blog.php Project: anqh/anqh
 /**
  * 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);
 }
Example #11
0
File: invite.php Project: anqh/core
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        echo $this->message;
        // Send invite
        echo Form::open();
        ?>

<fieldset>
	<legend><?php 
        echo __('Not yet invited?');
        ?>
</legend>

	<?php 
        echo Form::control_group(Form::input('email', $this->invitation->email, array('class' => 'input-xxlarge', 'placeholder' => __('*****@*****.**'))), array('email' => __('Send an invitation to')), Arr::get($this->errors, 'email'), __('Please remember: sign up is available only with a valid, invited email.'));
        ?>

</fieldset>

<fieldset class="form-actions">
	<?php 
        echo Form::button('invite', '<i class="icon-envelope icon-white"></i> ' . __('Send invitation'), array('type' => 'submit', 'class' => 'btn btn-primary btn-large'));
        ?>
	<?php 
        echo HTML::anchor(Request::back('/', true), __('Cancel'), array('class' => 'cancel'));
        ?>
</fieldset>

<?php 
        echo Form::close();
        // Enter code
        echo Form::open();
        ?>

<fieldset>
	<legend><?php 
        echo __('Got my invitation!');
        ?>
</legend>

	<?php 
        echo Form::control_group(Form::input('code', null, array('class' => 'input-xxlarge', 'placeholder' => __('M0573XC3LL3N751R'))), array('code' => __('Enter your invitation code')), Arr::get($this->errors, 'code'), __('Your invitation code is included in the mail you received, 16 characters.'));
        ?>

</fieldset>

<fieldset class="form-actions">
	<?php 
        echo Form::hidden('signup', true);
        ?>
	<?php 
        echo Form::button('invited', __('Final step!') . ' <i class="icon-arrow-right icon-white"></i>', array('type' => 'submit', 'class' => 'btn btn-primary btn-large'));
        ?>
	<?php 
        echo HTML::anchor(Request::back('/', true), __('Cancel'), array('class' => 'cancel'));
        ?>
</fieldset>

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #12
0
File: sign.php Project: anqh/anqh
 /**
  * Action: sign up
  */
 public function action_up()
 {
     $this->history = false;
     if (Visitor::$user) {
         Request::back();
     }
     $this->view->title = __('Join :site', array(':site' => Kohana::$config->load('site.site_name')));
     // Check external provider
     if ($provider = Arr::get($_REQUEST, 'provider')) {
         if ($response = Session::instance()->get('oauth2.' . $provider . '.response')) {
             return $this->_join(null, $response, $provider);
         }
     }
     // Check invitation code
     $code = trim(Arr::get($_REQUEST, 'code'));
     if ($code) {
         $invitation = Model_Invitation::factory($code);
         return $invitation->loaded() ? $this->_join($invitation) : $this->_invite($code);
     }
     // Check if we got the code from the form
     if (!$code && $_POST) {
         $code = Arr::get($_POST, 'code');
         if ($code) {
             $this->request->redirect(Route::url('sign', array('action' => 'up')) . '?code=' . $code);
         }
     }
     $this->_invite();
 }
Example #13
0
File: invite.php Project: anqh/anqh
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        echo $this->message;
        ?>

<div class="row">
	<div class="col-sm-6">

		<?php 
        echo Form::open();
        ?>

		<fieldset>
			<legend><?php 
        echo __('Not yet invited?');
        ?>
</legend>

			<?php 
        echo Form::input_wrap('email', $this->invitation->email, array('class' => 'input-lg', 'type' => 'email', 'placeholder' => '*****@*****.**', 'required'), __('Send an invitation to'), Arr::get($this->errors, 'email'), __('Please remember: Valid, invited email is required to join. You can invite yourself too!'));
        ?>

		</fieldset>

		<fieldset>
			<?php 
        echo Form::button('invite', '<i class="fa fa-envelope"></i> ' . __('Send invitation'), array('type' => 'submit', 'class' => 'btn btn-primary btn-large'));
        ?>
			<?php 
        echo HTML::anchor(Request::back('/', true), __('Cancel'), array('class' => 'cancel'));
        ?>
		</fieldset>

		<?php 
        echo Form::close();
        ?>

		<br>

		<?php 
        echo Form::open();
        ?>

		<fieldset>
			<legend><?php 
        echo __('Got my invitation!');
        ?>
</legend>

			<?php 
        echo Form::input_wrap('code', null, array('class' => 'input-lg', 'placeholder' => __('M0573XC3LL3N751R'), 'maxlength' => 16, 'required'), __('Invitation code'), Arr::get($this->errors, 'code'), __('Your invitation code is included in the mail you received, 16 characters.'));
        ?>

		</fieldset>

		<fieldset>
			<?php 
        echo Form::hidden('signup', true);
        ?>
			<?php 
        echo Form::button('invited', __('Final step!') . ' <i class="fa fa-arrow-right"></i>', array('type' => 'submit', 'class' => 'btn btn-primary btn-large'));
        ?>
			<?php 
        echo HTML::anchor(Request::back('/', true), __('Cancel'), array('class' => 'cancel'));
        ?>
		</fieldset>

		<?php 
        echo Form::close();
        ?>

	</div>


	<div class="col-md-1 hidden-xs text-center lead">

		<?php 
        echo __('or');
        ?>

	</div>


	<div class="col-sm-5">

		<?php 
        echo HTML::anchor(Route::url('oauth', array('action' => 'login', 'provider' => 'facebook')), '&nbsp;<i class="fa fa-facebook"></i> ' . __('Connect with Facebook') . '&nbsp;', array('class' => 'btn btn-lg btn-facebook', 'title' => __('Sign in with your Facebook account')));
        ?>

	</div>
</div>

<?php 
        return ob_get_clean();
    }
Example #14
0
File: oauth.php Project: anqh/anqh
 /**
  * Action: Redirected from 3rd party.
  */
 public function action_redirect()
 {
     $provider = $this->consumer->get_provider();
     if ($provider != 'facebook') {
         // Unsupported provider
         $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(__('We are not entirely sure what 3rd party service redirected you here'), __('Failed to load your profile :('), View_Alert::ERROR));
         Kohana::$log->add(Log::NOTICE, 'OAuth2: Unsupported provider: :provider', array(':provider' => $provider));
         return;
     }
     if ($response = Arr::get($_REQUEST, OAuth2::RESPONSE_TYPE_CODE)) {
         // Code received, change it to access token
         try {
             $token = $this->consumer->request_token(array(OAuth2::RESPONSE_TYPE_CODE => $response));
             if (Visitor::$user) {
                 // Already logged in
                 $external = Model_User_External::factory()->find_by_user_id(Visitor::$user->id, $provider);
                 if ($this->_update_token($external, $token)) {
                     // Already paired with local user
                     $this->request->redirect(URL::user(Visitor::$user, 'settings'));
                     //Request::back();
                 } else {
                     // Not paired with local user, do so
                     if ($response = $this->consumer->api_call('/me', array('fields' => 'id,email'))) {
                         // Received a response from 3rd party
                         if ($error = Arr::get($response, 'error')) {
                             // .. but it was an error
                             $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(__('They said ":error"', array(':error' => HTML::chars($error->message))), __('Failed to load your profile :('), View_Alert::ERROR));
                             Kohana::$log->add(Log::NOTICE, 'OAuth2: Failed to load Facebook profile: :error', array(':error' => $error->message));
                         } else {
                             // Received required information
                             $external = new Model_User_External();
                             $external->set_fields(array('token' => $token['access_token'], 'user_id' => Visitor::$user->id, 'external_user_id' => Arr::get($response, 'id'), 'created' => time(), 'expires' => time() + (int) $token['expires'], 'provider' => $provider));
                             $external->save();
                             $this->request->redirect(URL::user(Visitor::$user, 'settings'));
                             //Request::back();
                         }
                     } else {
                         // No data received, this should be handled by exceptions
                     }
                 }
             } else {
                 // No signed in user available
                 if ($response = $this->consumer->api_call('/me')) {
                     // Received a response from 3rd party
                     if ($error = Arr::get($response, 'error')) {
                         // .. but it was an error
                         $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(__('They said ":error"', array(':error' => HTML::chars($error->message))), __('Failed to load your profile :('), View_Alert::ERROR));
                         Kohana::$log->add(Log::NOTICE, 'OAuth2: Failed to load Facebook profile: :error', array(':error' => $error->message));
                     } else {
                         // Received required information
                         $external_user_id = Arr::get($response, 'id');
                         $external = Model_User_External::factory()->find_by_external_user_id($external_user_id, $provider);
                         if ($this->_update_token($external, $token)) {
                             // Already paired with local user, login
                             Kohana::$log->add(Log::DEBUG, 'OAuth2: Attempting to login :external_user_id => :user_id', array(':external_user_id' => $external->external_user_id, ':user_id' => $external->user_id));
                             if ($this->_login($external)) {
                                 Request::back();
                             }
                             Kohana::$log->add(Log::WARNING, 'OAuth2: Login failed');
                         } else {
                             // Not paired with a local user, check if we have unpaired user available
                             $email = Arr::get($response, 'email');
                             // Store external user id in session data, token should be stored in OAuth2
                             Session::instance()->set('oauth2.' . $provider . '.id', $external_user_id);
                             if ($user = Model_User::find_user($email)) {
                                 // User with same email found, ask to sign in
                                 Kohana::$log->add(Log::DEBUG, 'OAuth2: Existing user with same email found');
                                 $this->view->add(View_Page::COLUMN_CENTER, $this->section_signin($user, $response));
                             } else {
                                 // No user with same email found, start registering
                                 Kohana::$log->add(Log::DEBUG, 'OAuth2: Starting new user registration');
                                 Session::instance()->set('oauth2.' . $provider . '.response', $response);
                                 $this->request->redirect(Route::url('sign', array('action' => 'up')) . '?provider=' . $provider);
                             }
                         }
                     }
                 } else {
                     // No data received, this should be handled by exceptions
                 }
             }
         } catch (OAuth2_Exception_InvalidGrant $e) {
             $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(HTML::chars($e->getMessage()), __('Failed to load your profile :('), View_Alert::ERROR));
             Kohana::$log->add(Log::NOTICE, 'OAuth2: Invalid grant: :error', array(':error' => $e->getMessage()));
         } catch (Kohana_Exception $e) {
             $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(HTML::chars($e->getMessage()), __('Failed to load your profile :('), View_Alert::ERROR));
             Kohana::$log->add(Log::NOTICE, 'OAuth2: Exception: :error', array(':error' => $e->getMessage()));
         }
     } else {
         $this->view->add(View_Page::COLUMN_CENTER, new View_Alert(__('Did not receive required code from 3rd party'), __('Failed to load your profile :('), View_Alert::ERROR));
         Kohana::$log->add(Log::NOTICE, 'OAuth2: No code received');
     }
 }
Example #15
0
File: music.php Project: anqh/anqh
 /**
  * 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);
 }
Example #16
0
?>

	<fieldset>
		<legend><?php 
echo __('Almost there!');
?>
</legend>
		<ul>
			<?php 
echo Form::input_wrap('username', $user, array('placeholder' => __('JohnDoe')), __('Username'), $errors, __('Choose a unique username with at least <var>:length</var> characters. No special characters, thank you.', array(':length' => Kohana::$config->load('visitor.username.length_min'))));
?>
			<?php 
echo Form::password_wrap('password', null, null, __('Password'), $errors);
?>
			<?php 
echo Form::password_wrap('password_confirm', null, null, __('Confirm'), $errors, __('Try to use letters, numbers and special characters for a stronger password, with at least <var>8</var> characters.'));
?>
			<?php 
echo Form::input_wrap('email', $user, array('disabled' => 'disabled', 'placeholder' => __('*****@*****.**')), __('Email'), $errors, __('Please remember: sign up is available only with a valid, invited email.'));
?>
		</ul>
	</fieldset>

	<fieldset>
		<?php 
echo Form::submit_wrap('register', __('Sign up!'), null, Request::back('/', true), null, array('code' => $code));
?>
	</fieldset>

<?php 
echo Form::close();
Example #17
0
File: sign.php Project: anqh/core
 /**
  * Action: sign up
  */
 public function action_up()
 {
     $this->history = false;
     if (self::$user) {
         Request::back();
     }
     $this->view = View_Page::factory(__('Sign up'));
     // Check invitation code
     $code = trim(Arr::get($_REQUEST, 'code'));
     if ($code) {
         $invitation = Model_Invitation::factory($code);
         return $invitation->loaded() ? $this->_join($invitation) : $this->_invite($code);
     }
     // Check if we got the code from the form
     if (!$code && $_POST) {
         $code = Arr::get($_POST, 'code');
         if ($code) {
             $this->request->redirect(Route::url('sign', array('action' => 'up')) . '?code=' . $code);
         }
     }
     $this->_invite();
 }
Example #18
0
File: tags.php Project: anqh/anqh
 /**
  * Action: tag
  *
  * @param  integer  $group_id
  */
 public function action_tag($group_id = null)
 {
     $this->history = false;
     if ($group_id && $this->request->action() !== 'tag') {
         // Add new tag
         $group = Model_Tag_Group::factory($group_id);
         if (!$group->loaded()) {
             throw new Model_Exception($group, $group_id);
         }
         $tag = Model_Tag::factory();
         $tag->tag_group_id = $group_id;
         $tag->author_id = Visitor::$user->id;
         $tag->created = time();
         $this->view = View_Page::factory($group->name);
         $this->view->subtitle = HTML::chars($group->description);
     } else {
         if ($tag_id = (int) $this->request->param('id')) {
             // Edit old tag
             $tag = Model_Tag::factory($tag_id);
             if (!$tag->loaded()) {
                 throw new Model_Exception($tag, $tag_id);
             }
             $this->view = View_Page::factory($tag->name);
             $this->view->subtitle = HTML::chars($tag->description);
             $this->page_actions[] = array('link' => Route::model($tag, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete tag'), 'class' => 'btn btn-danger tag-delete');
         } else {
             Request::back(Route::url('tags'));
         }
     }
     $errors = array();
     if ($_POST) {
         $tag->name = Arr::get($_POST, 'name');
         $tag->description = Arr::get($_POST, 'description');
         try {
             $tag->save();
             $this->request->redirect(Route::model($tag));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_tag($tag, $errors));
 }
Example #19
0
File: user.php Project: anqh/anqh
 /**
  * Action: set setting.
  */
 public function action_setting()
 {
     $success = false;
     // Support only theme
     if ($theme = Arr::get($_POST, 'theme')) {
         if (!in_array($theme, array_keys(Kohana::$config->load('site.themes')))) {
             $theme = Kohana::$config->load('site.theme');
             $this->response->status(406);
             // Not Acceptable
         } else {
             $success = true;
             $this->response->status(200);
             // OK
         }
         if (Visitor::$user) {
             Visitor::$user->setting('ui.theme', $theme);
             Visitor::$user->save();
         }
         $this->session->set('theme', $theme);
     } else {
         $this->response->status(400);
         // Bad Request
     }
     if ($this->_request_type === Controller::REQUEST_AJAX) {
         $this->response->headers('Content-Type', Controller::FORMAT_JSON);
         $this->response->body(json_encode(array('status' => $success ? 'ok' : 'error')));
         return;
     }
     Request::back();
 }
Example #20
0
File: topic.php Project: anqh/forum
 /**
  * Edit forum post
  *
  * @param  integer  $topic_id  When replying to a topic
  * @param  integer  $post_id   When editing a post
  * @param  integer  $quote_id  When quoting a post
  *
  * @throws  Model_Exception  missing topic, missing post
  */
 protected function _edit_post($topic_id, $post_id = null, $quote_id = null)
 {
     $this->history = false;
     // Topic is always loaded, avoid haxing attempts to edit posts from wrong topics
     $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_POST, self::$user);
     if ($post_id) {
         // Editing a post
         $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id);
         if (!$post->loaded() || $post->forum_topic_id != $topic->id) {
             throw new Model_Exception($post, $post_id);
         }
         Permission::required($post, Model_Forum_Post::PERMISSION_UPDATE, self::$user);
     } else {
         // New reply
         $post = $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory();
     }
     // Quoting a post
     if ($quote_id) {
         $quote = $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory($quote_id);
         if (!$quote->loaded() || $quote->forum_topic_id != $topic->id) {
             throw new Model_Exception($quote, $quote_id);
         }
         Permission::required($quote, Model_Forum_Post::PERMISSION_READ, self::$user);
         if (!$post->loaded()) {
             $post->post = '[quote author="' . $quote->author_name . '" post="' . $quote->id . '"]' . $quote->post . "[/quote]\n\n";
         }
         $post->parent_id = $quote_id;
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         $post->post = Arr::get($_POST, 'post');
         $post->author_ip = Request::$client_ip;
         $post->author_host = Request::host_name();
         if (!$post->loaded()) {
             // New post
             $post->forum_topic_id = $topic->id;
             $post->forum_area_id = $topic->forum_area_id;
             $post->author_id = self::$user->id;
             $post->author_name = self::$user->username;
             $post->created = time();
             $increase = true;
             // Notify recipients
             if ($this->private) {
                 $topic->notify_recipients(self::$user);
             }
         } else {
             // Old post
             $post->modify_count++;
             $post->modified = time();
             $increase = false;
         }
         try {
             $post->save();
             if ($increase) {
                 // Quote, only for public topics
                 if (!$this->private && $quote_id && $quote->author_id) {
                     $quoted = $quote->author_id;
                     $quote = new Model_Forum_Quote();
                     $quote->user_id = $quoted;
                     $quote->author_id = self::$user->id;
                     $quote->forum_topic_id = $topic->id;
                     $quote->forum_post_id = $post->id;
                     $quote->created = time();
                     $quote->save();
                 }
                 // Topic
                 $topic->post_count++;
                 $topic->last_post_id = $post->id;
                 $topic->last_poster = $post->author_name;
                 // If current topic is set to sink, don't update last posted date
                 if ($topic->status != Model_Forum_Topic::STATUS_SINK) {
                     $topic->last_posted = $post->created;
                 }
                 $topic->save();
                 // Area, only for public topics
                 if (!$this->private) {
                     $area = $topic->area();
                     $area->post_count++;
                     $area->last_topic_id = $topic->id;
                     $area->save();
                 }
                 // User
                 self::$user->post_count++;
                 self::$user->save();
                 // News feed
                 if (!$this->private) {
                     NewsfeedItem_Forum::reply(self::$user, $post);
                 }
             }
             if ($this->ajax) {
                 $post_route = Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($topic), 'id' => $post->id));
                 $post_response = Request::factory($post_route)->execute();
                 $this->response->body($post_response->body());
                 return;
             }
             $this->request->redirect(Route::model($topic, '?page=last#last'));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Common attributes
     if ($quote_id) {
         $mode = View_Forum_PostEdit::QUOTE;
     } else {
         if ($post_id) {
             $mode = View_Forum_PostEdit::EDIT_POST;
         } else {
             $mode = View_Forum_PostEdit::REPLY;
         }
     }
     $section = $this->section_post_edit($mode, $post);
     $section->forum_topic = $topic;
     $section->errors = $errors;
     $section->cancel = $this->ajax ? Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($topic), 'id' => $quote_id ? $quote_id : $post->id)) : Request::back(Route::model($topic), true);
     /*		$form = array(
     			'errors'  => $errors,
     			'ajax'    => $this->ajax ? true : null,
     			'topic'   => $topic,
     			'post'    => $post,
     			'user'    => self::$user,
     			'private' => $this->private,
     			'cancel'  => $this->ajax
     				? Route::get($this->private ? 'forum_private_post' : 'forum_post')
     						->uri(array(
     							'topic_id' => Route::model_id($topic),
     							'id'       => $quote_id ? $quote_id : $post->id,
     						))
     				: Request::back(Route::model($topic), true),
     		);*/
     if ($this->ajax) {
         $this->response->body($mode == View_Forum_PostEdit::EDIT_POST ? $section->content() : $section);
         return;
     }
     // Build page
     $this->view = new View_Page();
     $this->view->title_html = Forum::topic($topic);
     $this->view->add(View_Page::COLUMN_MAIN, $section);
     /*
     		Widget::add('main', View_Module::factory('forum/reply', array(
     			'mod_id'  => 'reply',
     		) + $form));*/
 }
Example #21
0
defined('SYSPATH') or die('No direct access allowed.');
/**
 * Tag group edit
 *
 * @package    Anqh
 * @author     Antti Qvickström
 * @copyright  (c) 2011 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
echo Form::open();
?>

	<fieldset>
		<ul>
			<?php 
echo Form::input_wrap('name', $group, array('maxlength' => 32), __('Name'), $errors);
?>
			<?php 
echo Form::input_wrap('description', $group, null, __('Description'), $errors);
?>
		</ul>
	</fieldset>

	<fieldset>
		<?php 
echo Form::submit_wrap('save', __('Save'), null, Request::back(Route::get('tags')->uri(), true));
?>
	</fieldset>

<?php 
echo Form::close();
Example #22
0
File: events.php Project: anqh/anqh
 /**
  * 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);
 }
Example #23
0
 /**
  * Edit gallery
  *
  * @param  integer  $gallery_id
  * @param  integer  $event_id
  */
 protected function _edit_gallery($gallery_id = null, $event_id = null)
 {
     $this->history = false;
     if ($gallery_id) {
         // Editing old
         $gallery = Model_Gallery::factory($gallery_id);
         if (!$gallery->loaded()) {
             throw new Model_Exception($gallery, $gallery_id);
         }
         Permission::required($gallery, Model_Gallery::PERMISSION_UPDATE, self::$user);
         $cancel = Route::model($gallery);
         $save = null;
         $upload = false;
     } else {
         // Creating new
         $gallery = Model_Gallery::factory();
         Permission::required($gallery, Model_Gallery::PERMISSION_CREATE, self::$user);
         $cancel = Request::back(Route::url('galleries'), true);
         $save = __('Continue');
         $upload = true;
         if ($event_id) {
             /** @var  Model_Event  $event */
             $event = Model_Event::factory($event_id);
         }
     }
     // Handle post
     $errors = array();
     if ($_POST || isset($_GET['from'])) {
         $event_id = $_POST ? (int) Arr::get($_POST, 'event') : (int) Arr::get($_GET, 'from');
         $event = Model_Event::factory($event_id);
         if (!$gallery->loaded() && $event->loaded()) {
             // Redirect to existing gallery if trying to create duplicate
             $old = Model_Gallery::factory()->find_by_event($event_id);
             if ($old->loaded()) {
                 $this->request->redirect(Route::model($old, 'upload'));
             }
             // Fill gallery info from event when creating new
             $gallery->name = $event->name;
             $gallery->date = $event->stamp_begin;
             $gallery->event_id = $event->id;
         } else {
             if ($gallery->loaded()) {
                 // Editing old
                 $gallery->set_fields(Arr::intersect($_POST, Model_Gallery::$editable_fields));
             }
         }
         try {
             $gallery->save();
             $this->request->redirect(Route::model($gallery, $upload ? 'upload' : null));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Build page
     $this->view = View_Page::factory(__('Upload images'));
     // Gallery edit form
     $section = $this->section_gallery_edit(isset($event) ? $event : null);
     $section->errors = $errors;
     $this->view->add(View_Page::COLUMN_MAIN, $section);
     // Gallery event info
     if (isset($event) && $event->loaded()) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_event_info($event));
     }
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_upload_help());
 }
Example #24
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);
 }
Example #25
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)));
 }
Example #26
0
/**
 * Enter invitation code
 *
 * @package    Anqh
 * @author     Antti Qvickström
 * @copyright  (c) 2011 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
echo Form::open();
?>

	<fieldset>
		<legend><?php 
echo __('Got my invitation!');
?>
</legend>
		<ul>
			<?php 
echo Form::input_wrap('code', null, array('placeholder' => __('M0573XC3LL3N751R')), __('Enter your invitation code'), $errors, __('Your invitation code is included in the mail you received, 16 characters.'));
?>
		</ul>
	</fieldset>

	<fieldset>
		<?php 
echo Form::submit_wrap('invited', __('Final step!'), null, Request::back('/', true), null, array('signup' => true));
?>
	</fieldset>

<?php 
echo Form::close();