public save_content_admin ( $data, $delete_the_cache = true ) |
public function save_content_admin($data, $delete_the_cache = true)
{
if (is_string($data)) {
$data = parse_params($data);
}
$adm = $this->app->user_manager->is_admin();
$checks = mw_var('FORCE_SAVE_CONTENT');
$orig_data = $data;
$stop = false;
$data = $this->app->format->strip_unsafe($data);
if ($adm == false) {
$stop = true;
$author_id = user_id();
if (isset($data['created_at'])) {
unset($data['created_at']);
}
if (isset($data['updated_at'])) {
unset($data['updated_at']);
}
if (isset($data['id']) and $data['id'] != 0 and $author_id != 0) {
$page_data_to_check_author = $this->get_by_id($data['id']);
if (!isset($page_data_to_check_author['created_by']) or $page_data_to_check_author['created_by'] != $author_id) {
$stop = true;
return array('error' => "You don't have permission to edit this content");
} elseif (isset($page_data_to_check_author['created_by']) and $page_data_to_check_author['created_by'] == $author_id) {
$stop = false;
}
} elseif ($author_id == false) {
return array('error' => 'You must be logged to save content');
}
if (isset($data['id']) and $data['id'] != 0) {
if (!is_admin()) {
$check = get_content_by_id($data['id']);
if ($check['created_by'] != user_id()) {
return array('error' => 'Wrong content');
}
}
}
if (isset($data['is_home'])) {
if (!is_admin()) {
unset($data['is_home']);
}
}
if ($stop == true) {
if (defined('MW_API_FUNCTION_CALL') and MW_API_FUNCTION_CALL == __FUNCTION__) {
if (!isset($data['captcha'])) {
if (isset($data['error_msg'])) {
return array('error' => $data['error_msg']);
} else {
return array('error' => 'Please enter a captcha answer!');
}
} else {
$cap = $this->app->user_manager->session_get('captcha');
if ($cap == false) {
return array('error' => 'You must load a captcha first!');
}
if ($data['captcha'] != $cap) {
return array('error' => 'Invalid captcha answer!');
}
}
}
}
if (isset($data['categories'])) {
$data['category'] = $data['categories'];
}
//if (defined('MW_API_FUNCTION_CALL') and MW_API_FUNCTION_CALL == __FUNCTION__) {
if (isset($data['category'])) {
$cats_check = array();
if (is_array($data['category'])) {
foreach ($data['category'] as $cat) {
$cats_check[] = intval($cat);
}
} else {
$cats_check[] = intval($data['category']);
}
$check_if_user_can_publish = $this->app->category_manager->get('ids=' . implode(',', $cats_check));
if (!empty($check_if_user_can_publish)) {
$user_cats = array();
foreach ($check_if_user_can_publish as $item) {
if (isset($item['users_can_create_content']) and $item['users_can_create_content'] == 1) {
$user_cats[] = $item['id'];
$cont_cat = $this->get('limit=1&content_type=page&subtype_value=' . $item['id']);
}
}
if (!empty($user_cats)) {
$stop = false;
$data['categories'] = $user_cats;
}
}
}
}
// }
if ($stop == true) {
return array('error' => 'You don\'t have permissions to save content here!');
}
return $this->save_content($data, $delete_the_cache);
}