/** * Set fields in article * * @param array $articles_ids * @param string $field_name * @param string $value * @param integer $all_matching * @return boolean true on success or false on fail */ function set_field($article_ids, $field_name, $value, $all_matching = 0) { if (!$this->check_token()) { return false; } if (!vivvo_hooks_manager::call('article_setField', array(&$article_ids, &$field_name, &$value, &$all_matching))) { return vivvo_hooks_manager::get_status(); } $sm = vivvo_lite_site::get_instance(); if ($sm->user) { $editor_restriction = $sm->user->get_privilege_object_ids('EDITOR', 'Categories'); if (!empty($editor_restriction)) { $article_list = new Articles_list(); if (!in_array('0', $editor_restriction)) { if ($field_name == 'category_id' && !in_array($value, $editor_restriction)) { $this->set_error_code(2012); return false; } } if ($field_name == 'status' && !$sm->user->can_change_status($value, '*')) { $this->set_error_code(2012); return false; } if ($all_matching == 1) { $article_params = Articles_list::get_search_params_from_url($sm); if (!is_array($article_params['search_options']['search_cid'])) { $article_params['search_options']['search_cid'] = explode(',', $article_params['search_options']['search_cid']); } if (!in_array('0', $editor_restriction) && isset($article_params['search_options']['search_cid'])) { $article_params['search_options']['search_cid'] = array_intersect($editor_restriction, $article_params['search_options']['search_cid']); } $article_list->search($article_params['search_options'], '', 'ascending', 0, 0, false); if (!in_array($field_name, array('applyTags', 'editTags'))) { if ($article_list->sql_update_list($this->_post_master, array($field_name => $value), NULL, true)) { admin_log($sm->user->get_username(), 'Edited articles #' . trim(implode(',', $article_ids))); return true; } else { $this->set_error_code(2010); return false; } } else { $res = $sm->get_db()->query('SELECT a.id ' . $article_list->_query->get_from() . ' ' . $article_list->_query->get_join() . ' ' . $article_list->_query->get_where() . ' ' . $article_list->_query->get_group_by() . ' ' . $article_list->_query->get_having()); if (PEAR::isError($res)) { $this->set_error_code(2010); return false; } $article_ids = $res->fetchCol(); $res->free(); } } elseif (!in_array($field_name, array('applyTags', 'editTags'))) { $article_list->get_articles_by_ids($article_ids, $editor_restriction); if ($article_list->sql_update_list($this->_post_master, array($field_name => $value))) { admin_log($sm->user->get_username(), 'Edited articles #' . trim(implode(',', $article_ids))); return true; } else { $this->set_error_code(2011); return false; } } if ($field_name == 'applyTags') { require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/service/Tags.service.php'; $this->tag_service = new tag_service($sm); $tags = array_map(array($this, 'parse_tags'), explode(',', $value)); foreach ($article_ids as $article_id) { foreach ($tags as $id) { $this->tag_service->add_tag_to_group($id[1], $id[0], $article_id); } } return true; } elseif ($field_name == 'editTags') { $tags = explode(',', $value); foreach ($article_ids as $article_id) { $this->manageTags($tags, $article_id); } return true; } $this->set_error_code(2011); return false; } else { $this->set_error_code(2012); return false; } } else { $this->set_error_code(2013); return false; } }