/** * Add new category * * @param array $in_category * @return boolean true on success or false on fail */ function add_category($in_category) { if (!$this->check_token()) { return false; } if (!vivvo_hooks_manager::call('category_add', array(&$in_category))) { return vivvo_hooks_manager::get_status(); } $sm = vivvo_lite_site::get_instance(); if ($sm->user) { if ($sm->user->is_admin()) { $in_category['category_name'] = trim($in_category['category_name']); if (empty($in_category['sefriendly'])) { $in_category['sefriendly'] = make_sefriendly($in_category['category_name']); } else { $in_category['sefriendly'] = make_sefriendly($in_category['sefriendly']); } $sefriendly = secure_sql($in_category['sefriendly']); $sql = 'SELECT id FROM ' . VIVVO_DB_PREFIX . "categories WHERE sefriendly = '{$sefriendly}' LIMIT 1 UNION\n\t\t\t\t\t\t\tSELECT id FROM " . VIVVO_DB_PREFIX . "tags_groups WHERE url = '{$sefriendly}' LIMIT 1"; if (($res = $sm->get_db()->query($sql)) && !$res instanceof MDB2_Error && $res->numRows() > 0) { $this->set_error_code(2101); return false; } $redirect = $in_category['redirect']; array_walk($in_category, 'array_htmlspecialchars'); $in_category['redirect'] = $redirect; if (!empty($in_category['form']) and $in_category['form'] == 'link' and empty($in_category['redirect'])) { $this->set_error_code(12, vivvo_lang::get_instance()->get_value('LNG_DB_categories_redirect')); return false; } $category = new Categories(); $category_list = $sm->get_categories(); $in_category['order_num'] = $category_list->get_number_of_category() + 1; if ($category->populate($in_category, true) === false) { $this->set_error_info($category->get_error_info()); return false; } $this->_post_master->set_data_object($category); if ($this->_post_master->sql_insert()) { $id = $this->_post_master->get_work_id(); $category->set_id($id); $sm->get_url_manager()->set_param('search_id', $id); if (!vivvo_hooks_manager::call('category_add_postinsert', array(&$category))) { return vivvo_hooks_manager::get_status(); } $fm = $sm->get_file_manager(); if ($fm->is_uploaded('CATEGORY_abstact_image')) { $abstract_image = $fm->upload('CATEGORY_abstact_image'); if ($abstract_image != false) { $category->set_image($abstract_image); $this->_post_master->set_data_object($category); $this->_post_master->sql_update(); } } admin_log($sm->user->get_username(), 'Created category #' . $this->_post_master->get_work_id()); return true; } else { $this->set_error_code(2102); return false; } } else { $this->set_error_code(2103); return false; } } else { $this->set_error_code(2104); return false; } }