Example #1
0
 /**
  * Generate box output
  *
  * @param array $params Parameters
  */
 function generate_output($params)
 {
     $this->set_template($params);
     $params += array('pg' => 1, 'fields' => '');
     // defaults
     require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Comments.class.php';
     $comments = new Comments_list(null, $params['fields']);
     $search_params = Comments_list::get_search_params(null, $params);
     if (isset($search_params['search_options']['search_article_id'])) {
         $this->_template->assign('article_id', $search_params['search_options']['search_article_id']);
     }
     $comments->search($search_params['search_options'], $search_params['search_sort_by'], $search_params['search_order'], $search_params['search_limit'], $search_params['offset']);
     if (!empty($comments->list)) {
         $comments->set_pagination($params['pg']);
         $this->_template->assign('comment_list', $comments->list);
     }
     $sm = vivvo_lite_site::get_instance();
     if (!$sm->user && $sm->guest_group) {
         $this->_template->assign('guest_group_wait_comment_for_approval', $sm->guest_group->group_privileges['ARTICLE_COMMENT']);
     }
     $this->_template->assign('comment_list_object', $comments);
 }
Example #2
0
 /**
  * Sets {@link $number_of_comments}
  *
  * @param	integer	$num
  */
 function set_number_of_comments($num = false)
 {
     if ($num === false || !is_numeric($num)) {
         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Comments.class.php';
         $cl = new Comments_list();
         $params = array('search_article_id' => $this->id);
         defined('VIVVO_ADMIN_MODE') or $params['search_status'] = 1;
         $cl->search($params, '', '', 0, 0, false);
         $this->number_of_comments = $cl->get_total_count();
     } elseif (is_numeric($num)) {
         $this->number_of_comments = $num;
     } else {
         $this->number_of_comments = false;
     }
     return true;
 }
Example #3
0
 /**
  * Advaced search list generator
  *
  * @param	array	$params	Search parameters
  * @param	string	$order	Order parameters
  * @param	integer	$limit	Limit
  * @param	integer	$offset	Offset
  * @return	array	Array of articles
  */
 function &search($params, $order = '', $direction = 'ascending', $limit = 0, $offset = 0, $set_list = true)
 {
     //search_query
     if (isset($params['search_id'])) {
         if (is_array($params['search_id'])) {
             if (!in_array(0, $params['search_id'])) {
                 $params['search_id'] = implode(',', $params['search_id']);
                 $this->add_filter('cm.id', $params['search_id']);
             }
         } else {
             if ($params['search_id'] != 0) {
                 $this->add_filter('cm.id', $params['search_id']);
             }
         }
     }
     if (isset($params['search_article_id'])) {
         $this->add_filter('cm.article_id', $params['search_article_id']);
     }
     if (isset($params['search_user_id'])) {
         $this->add_filter('cm.user_id', $params['search_user_id']);
     }
     if (isset($params['search_description']) && $params['search_description'] != '') {
         $this->add_filter('cm.description', $params['search_description']);
     }
     if (isset($params['search_create_dt'])) {
         $this->add_filter('cm.create_dt', $params['search_create_dt']);
     }
     if (isset($params['search_author']) && $params['search_author'] != '') {
         $this->add_filter('cm.author', $params['search_author']);
     }
     if (isset($params['search_author_name']) && $params['search_author_name'] != '') {
         $this->add_filter('cm.author_name', $params['search_author_name']);
     }
     if (isset($params['search_email'])) {
         $this->add_filter('cm.email', $params['search_email']);
     }
     if (isset($params['search_email_exact'])) {
         $this->add_filter('cm.email_exact', $params['search_email_exact']);
     }
     if (isset($params['search_ip'])) {
         $this->add_filter('cm.ip', $params['search_ip']);
     }
     if (isset($params['search_status']) && $params['search_status'] !== '') {
         $this->add_filter('cm.status', $params['search_status']);
     }
     if (intval($params['search_search_date']) !== 0) {
         $this->add_filter($params['search_before_after'] === '1' ? 'cm.created_before' : 'cm.created_after', $params['search_search_date']);
     }
     if (isset($params['search_vote']) && $params['search_vote'] !== '') {
         $this->add_filter('cm.vote', $params['search_vote']);
     }
     if (!empty($params['search_reply_to'])) {
         $this->add_filter('cm.reply_to', $params['search_reply_to']);
     }
     if (!empty($params['search_not_reply_to'])) {
         $this->add_filter('cm.not_reply_to', $params['search_reply_to']);
     }
     if (!empty($params['search_root_comment'])) {
         $this->add_filter('cm.root_comment', $params['search_root_comment']);
     }
     $threaded = VIVVO_COMMENTS_ENABLE_THREADED;
     if ($threaded and (!empty($params['threaded']) and $params['threaded'] == 1) and empty($params['search_reply_to']) and empty($params['search_not_reply_to'])) {
         $this->add_filter('cm.reply_to', 0);
     } else {
         $threaded = false;
     }
     // search order //
     $search_direction = $direction === 'descending' ? ' DESC' : ' ASC';
     switch ($order) {
         case 'id':
             $this->_query->add_order('cm.id' . $search_direction);
             break;
         case 'article_id':
             $this->_query->add_order('cm.article_id' . $search_direction);
             break;
         case 'user_id':
             $this->_query->add_order('cm.user_id' . $search_direction);
             break;
         case 'description':
             $this->_query->add_order('cm.description' . $search_direction);
             break;
         case 'create_dt':
             $this->_query->add_order('cm.create_dt' . $search_direction);
             break;
         case 'created':
             $this->_query->add_order('cm.create_dt' . $search_direction);
             break;
         case 'author':
             $this->_query->add_order('cm.author' . $search_direction);
             break;
         case 'email':
             $this->_query->add_order('cm.email' . $search_direction);
             break;
         case 'ip':
             $this->_query->add_order('ip' . $search_direction);
             break;
         case 'status':
             $this->_query->add_order('cm.status' . $search_direction);
             break;
         case 'vote':
             $this->_query->add_order('cm.vote' . $search_direction);
             break;
         default:
             $order = 'cm.id';
             $this->_query->add_order('cm.id' . ' DESC');
             break;
     }
     $limit = (int) $limit;
     $this->_query->set_limit($limit);
     $offset = (int) $offset;
     $this->_query->set_offset($offset);
     $this->_default_query(true);
     if ($set_list) {
         $this->set_list();
         if ($threaded && !empty($this->list)) {
             $tmp_list = new Comments_list();
             $list = $tmp_list->search(array('search_root_comment' => array_keys($this->list), 'search_status' => 1));
             foreach ($list as $id => $comment) {
                 if (($reply_to = $comment->get_reply_to()) > 0) {
                     if (isset($this->list[$reply_to])) {
                         $this->list[$reply_to]->add_response($comment);
                     } elseif (isset($list[$reply_to])) {
                         $list[$reply_to]->add_response($comment);
                     }
                 }
             }
         }
         return $this->list;
     }
 }
Example #4
0
 /**
  * Set field
  *
  * @param	integer		$comments_ids
  * @param	string		$field_name
  * @param	string		$value
  * @param	integer		$all_matching
  * @return	boolean		true on succes, or false on fail
  */
 function set_field($comments_ids, $field_name, $value, $all_matching = 0)
 {
     if (!$this->check_token()) {
         return false;
     }
     if (!vivvo_hooks_manager::call('comment_setField', array(&$comments_ids, &$field_name, &$value, &$all_matching))) {
         return vivvo_hooks_manager::get_status();
     }
     $sm = vivvo_lite_site::get_instance();
     if ($sm->user) {
         if ($sm->user->can('MODERATE_COMMENTS')) {
             $comment_list = new Comments_list();
             if ($all_matching == 1) {
                 $comment_params = Comments_list::get_search_params_from_url($sm);
                 $comment_list->search($comment_params['search_options'], '', 'ascending', 0, 0, false);
                 if ($comment_list->sql_update_list($this->_post_master, array($field_name => $value), NULL, true)) {
                     admin_log($sm->user->get_username(), 'Edited all selected comments');
                     return true;
                 } else {
                     $this->set_error_code(2215);
                     return false;
                 }
             } else {
                 if ($comment_list->get_comments_by_ids($comments_ids)) {
                     if ($comment_list->sql_update_list($this->_post_master, array($field_name => $value))) {
                         admin_log($sm->user->get_username(), 'Edited comments #' . trim(implode(',', $comments_ids)));
                         return true;
                     } else {
                         $this->set_error_code(2216);
                         return false;
                     }
                 } else {
                     return false;
                 }
             }
         } else {
             $this->set_error_code(2217);
             return false;
         }
     } else {
         $this->set_error_code(2218);
         return false;
     }
 }