/** * Render content. * * @return string */ public function content() { $shouts = array(); foreach (Model_Shout::find_latest($this->limit) as $shout) { $shouts[] = array('created' => $shout->created, 'user_id' => $shout->author_id, 'shout' => $shout->shout); } if ($shouts) { ob_start(); ?> <ul class="list-unstyled"> <?php foreach (array_reverse($shouts) as $shout) { ?> <li> <?php echo HTML::time(Date::format('HHMM', $shout['created']), array('datetime' => $shout['created'], 'class' => 'muted')); ?> <?php echo HTML::user($shout['user_id']); ?> : <?php echo Text::smileys(Text::auto_link_urls(HTML::chars($shout['shout']))); ?> </li> <?php } ?> </ul> <?php if ($this->_can_shout) { ?> <form <?php echo $this->aside ? 'class="ajaxify"' : ''; ?> action="<?php echo Route::url('shouts', array('action' => 'shout')); ?> " method="post"> <input class="form-control" type="text" name="shout" maxlength="300" placeholder="<?php echo __('Shout, and ye shall be heard..'); ?> " /> <?php echo Form::CSRF(); ?> </form> <?php } return ob_get_clean(); } return ''; }
/** * Action: shout */ public function action_shout() { $shout = Model_Shout::factory(); if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) { $shout->author_id = Visitor::$user->id; $shout->shout = $_POST['shout']; $shout->created = time(); try { $shout->save(); } catch (Validation_Exception $e) { } } if ($this->ajax) { $section = $this->section_shouts(); $section->aside = true; $this->response->body($section); return; } $this->request->redirect(Route::get('shouts')->uri()); }
/** * Action: shout */ public function action_shout() { $shout = Model_Shout::factory(); $errors = array(); if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) { $shout->author_id = self::$user->id; $shout->shout = $_POST['shout']; $shout->created = time(); try { $shout->save(); } catch (Validation_Exception $e) { $errors = $e->array->errors('validate'); } } if ($this->ajax) { echo new View_Index_Shouts(); exit; } $this->request->redirect(Route::get('shouts')->uri()); }