Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function render(Field $field, View $view)
 {
     $value = TextToolbox::process($field->value, $field->metadata->settings['text_processing']);
     $field->set('value', $value);
     return $view->element('Field.TextField/display', compact('field'));
 }
 /**
  * Extract data from request and prepares for inserting a new comment for
  * the given entity.
  *
  * @param \Cake\Datasource\EntityInterface $entity Entity used to guess table name
  * @return array
  */
 protected function _getRequestData(EntityInterface $entity)
 {
     $pk = (string) TableRegistry::get($entity->source())->primaryKey();
     $data = $this->_controller->request->data('comment');
     $return = ['parent_id' => null, 'subject' => '', 'body' => '', 'status' => 'pending', 'author_name' => null, 'author_email' => null, 'author_web' => null, 'author_ip' => $this->_controller->request->clientIp(), 'table_alias' => $this->_getTableAlias($entity), 'entity_id' => $entity->get($pk)];
     if (!empty($this->_controller->request->data['comment'])) {
         $data = $this->_controller->request->data['comment'];
     }
     if ($this->_controller->request->is('userLoggedIn')) {
         $return['user_id'] = user()->id;
         $return['author_name'] = null;
         $return['author_email'] = null;
         $return['author_web'] = null;
     } else {
         $return['author_name'] = !empty($data['author_name']) ? h($data['author_name']) : null;
         $return['author_email'] = !empty($data['author_email']) ? h($data['author_email']) : null;
         $return['author_web'] = !empty($data['author_web']) ? h($data['author_web']) : null;
     }
     if (!empty($data['subject'])) {
         $return['subject'] = h($data['subject']);
     }
     if (!empty($data['parent_id'])) {
         // this is validated at Model side
         $return['parent_id'] = $data['parent_id'];
     }
     if (!empty($data['body'])) {
         $return['body'] = TextToolbox::process($data['body'], $this->config('settings.text_processing'));
     }
     if ($this->config('settings.auto_approve') || $this->_controller->request->is('userAdmin')) {
         $return['status'] = 'approved';
     }
     return $return;
 }
 /**
  * Field UI main action.
  *
  * Shows all the comments attached to the Table being managed. Possibles values
  * for status are:
  *
  * - `all`: Comments marked as `pending` or `approved`. (by default)
  * - `pending`: Comments awaiting for moderation.
  * - `approved`: Comments approved and published.
  * - `spam`: Comments marked as SPAM by Akismet.
  * - `trash`: Comments that were sent to trash bin.
  *
  * @param string $status Filter comments by `status`, see list above
  * @return void
  */
 public function index($status = 'all')
 {
     $this->loadModel('Comment.Comments');
     $this->_setCounters();
     $search = '';
     // fills form's input
     $conditions = ['table_alias' => $this->_manageTable];
     if (in_array($status, ['pending', 'approved', 'spam', 'trash'])) {
         $conditions['Comments.status'] = $status;
     } else {
         $status = 'all';
         $conditions['Comments.status IN'] = ['pending', 'approved'];
     }
     if (!empty($this->request->query['search'])) {
         $search = $this->request->query['search'];
         $conditions['OR'] = ['Comments.subject LIKE' => "%{$this->request->query['search']}%", 'Comments.body LIKE' => "%{$this->request->query['search']}%"];
     }
     $comments = $this->Comments->find()->contain(['Users'])->where($conditions)->order(['Comments.created' => 'DESC'])->formatResults(function ($results) {
         return $results->map(function ($comment) {
             $comment->set('entity', $this->_inResponseTo($comment));
             $comment->set('body', TextToolbox::trimmer(TextToolbox::plainProcessor(TextToolbox::stripHtmlTags($comment->body)), 180));
             return $comment;
         });
     });
     $this->title(__d('comment', 'Comments List'));
     $this->set('search', $search);
     $this->set('filterBy', $status);
     $this->set('comments', $this->paginate($comments));
 }