/** * Edit a forum. * * @param AUTO_LINK The ID of the forum we are editing. * @param SHORT_TEXT The name of the forum. * @param SHORT_TEXT The description for the forum. * @param AUTO_LINK What forum category the forum will be filed with. * @param ?AUTO_LINK The ID of the parent forum (NULL: this is the root forum). * @param integer The position of this forum relative to other forums viewable on the same screen (if parent forum hasn't specified automatic ordering). * @param BINARY Whether post counts will be incremented if members post in the forum. * @param BINARY Whether the ordering of subforums is done automatically, alphabetically). * @param LONG_TEXT The question that is shown for newbies to the forum (blank: none). * @param SHORT_TEXT The answer to the question (blank: no specific answer.. if there's a 'question', it just requires a click-through). * @param SHORT_TEXT Either blank for no redirection, the ID of another forum we are mirroring, or a URL to redirect to. * @param ID_TEXT The order the topics are shown in, by default. * @param BINARY Whether the forum is threaded. * @param boolean Whether to force forum rules to be re-agreed to, if they've just been changed. */ function ocf_edit_forum($forum_id, $name, $description, $category_id, $new_parent, $position, $post_count_increment, $order_sub_alpha, $intro_question, $intro_answer, $redirection = '', $order = 'last_post', $is_threaded = 0, $reset_intro_acceptance = false) { if ($category_id == -1) { $category_id = NULL; } if ($new_parent == -1) { $new_parent = NULL; } require_code('urls2'); suggest_new_idmoniker_for('forumview', 'misc', strval($forum_id), $name); if (!is_null($category_id) && $category_id != INTEGER_MAGIC_NULL) { ocf_ensure_category_exists($category_id); } if (!is_null($new_parent) && $new_parent != INTEGER_MAGIC_NULL) { ocf_ensure_forum_exists($new_parent); } $forum_info = $GLOBALS['FORUM_DB']->query_select('f_forums', array('*'), array('id' => $forum_id), '', 1); if (!array_key_exists(0, $forum_info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $old_parent = $forum_info[0]['f_parent_forum']; $old_name = $forum_info[0]['f_name']; $under_category_id = $new_parent; while (!is_null($under_category_id) && $under_category_id != INTEGER_MAGIC_NULL) { if ($forum_id == $under_category_id) { warn_exit(do_lang_tempcode('FORUM_CANNOT_BE_OWN_PARENT')); } $under_category_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_parent_forum', array('id' => $under_category_id)); } if ($reset_intro_acceptance && trim(get_translated_text($forum_info[0]['f_intro_question'], $GLOBALS['FORUM_DB'])) != trim($intro_question) && $intro_question != STRING_MAGIC_NULL) { $GLOBALS['FORUM_DB']->query_delete('f_forum_intro_ip', array('i_forum_id' => $forum_id)); $GLOBALS['FORUM_DB']->query_delete('f_forum_intro_member', array('i_forum_id' => $forum_id)); } $GLOBALS['FORUM_DB']->query_update('f_forums', array('f_name' => $name, 'f_description' => lang_remap($forum_info[0]['f_description'], $description, $GLOBALS['FORUM_DB']), 'f_category_id' => $category_id, 'f_parent_forum' => $new_parent, 'f_position' => $position, 'f_order_sub_alpha' => $order_sub_alpha, 'f_intro_question' => lang_remap($forum_info[0]['f_intro_question'], $intro_question, $GLOBALS['FORUM_DB']), 'f_intro_answer' => $intro_answer, 'f_post_count_increment' => $post_count_increment, 'f_redirection' => $redirection, 'f_order' => $order, 'f_is_threaded' => $is_threaded), array('id' => $forum_id), '', 1); if ($old_name != $name) { $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_name', array('f_name' => $old_name)); if (is_null($test)) { require_code('config2'); update_config_option_reference($old_name, $name, 'forum'); } } if ($old_parent != $new_parent && $new_parent != INTEGER_MAGIC_NULL) { // Recalc stats require_code('ocf_posts_action2'); $num_topics_forum = $forum_info[0]['f_cache_num_topics']; // This is valid, because we move all this forums subforums too $num_posts_forum = $forum_info[0]['f_cache_num_posts']; if (!is_null($old_parent)) { ocf_force_update_forum_cacheing($old_parent, -$num_topics_forum, -$num_posts_forum); } if (!is_null($new_parent)) { ocf_force_update_forum_cacheing($new_parent, $num_topics_forum, $num_posts_forum); } } log_it('EDIT_FORUM', strval($forum_id), $name); }
/** * Make a forum. * * @param SHORT_TEXT The name of the forum. * @param SHORT_TEXT The description for the forum. * @param ?AUTO_LINK What forum category the forum will be filed with (NULL: this is the root forum). * @param ?array Permission map (NULL: do it the standard way, outside of this function). This parameter is for import/compatibility only and works upon an emulation of 'access levels' (ala ocPortal 2.5/2.6), and it is recommended to use the normal aed_module functionality for permissions setting. * @param ?AUTO_LINK The ID of the parent forum (NULL: this is the root forum). * @param integer The position of this forum relative to other forums viewable on the same screen (if parent forum hasn't specified automatic ordering). * @param BINARY Whether post counts will be incremented if members post in the forum. * @param BINARY Whether the ordering of subforums is done automatically, alphabetically). * @param LONG_TEXT The question that is shown for newbies to the forum (blank: none). * @param SHORT_TEXT The answer to the question (blank: no specific answer.. if there's a 'question', it just requires a click-through). * @param SHORT_TEXT Either blank for no redirection, the ID of another forum we are mirroring, or a URL to redirect to. * @param ID_TEXT The order the topics are shown in, by default. * @param BINARY Whether the forum is threaded. * @return AUTO_LINK The ID of the newly created forum. */ function ocf_make_forum($name, $description, $category_id, $access_mapping, $parent_forum, $position = 1, $post_count_increment = 1, $order_sub_alpha = 0, $intro_question = '', $intro_answer = '', $redirection = '', $order = 'last_post', $is_threaded = 0) { if ($category_id == -1) { $category_id = NULL; } if ($parent_forum == -1) { $parent_forum = NULL; } if (get_page_name() != 'admin_import') { if (!is_null($category_id) && function_exists('ocf_ensure_category_exists')) { ocf_ensure_category_exists($category_id); } if (!is_null($parent_forum) && function_exists('ocf_ensure_forum_exists')) { ocf_ensure_forum_exists($parent_forum); } } $forum_id = $GLOBALS['FORUM_DB']->query_insert('f_forums', array('f_name' => $name, 'f_description' => insert_lang($description, 2, $GLOBALS['FORUM_DB']), 'f_category_id' => $category_id, 'f_parent_forum' => $parent_forum, 'f_position' => $position, 'f_order_sub_alpha' => $order_sub_alpha, 'f_post_count_increment' => $post_count_increment, 'f_intro_question' => insert_lang($intro_question, 3, $GLOBALS['FORUM_DB']), 'f_intro_answer' => $intro_answer, 'f_cache_num_topics' => 0, 'f_cache_num_posts' => 0, 'f_cache_last_topic_id' => NULL, 'f_cache_last_forum_id' => NULL, 'f_cache_last_title' => '', 'f_cache_last_time' => NULL, 'f_cache_last_username' => '', 'f_cache_last_member_id' => NULL, 'f_redirection' => $redirection, 'f_order' => $order, 'f_is_threaded' => $is_threaded), true); // Set permissions if (!is_null($access_mapping)) { $groups = $GLOBALS['OCF_DRIVER']->get_usergroup_list(false, true); foreach (array_keys($groups) as $group_id) { $level = 0; // No-access if (array_key_exists($group_id, $access_mapping)) { $level = $access_mapping[$group_id]; } if ($level >= 1) { $GLOBALS['FORUM_DB']->query_insert('group_category_access', array('module_the_name' => 'forums', 'category_name' => strval($forum_id), 'group_id' => $group_id)); if ($level == 1) { $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'submit_lowrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 0)); $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'submit_midrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 0)); } if ($level >= 3) { $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'bypass_validation_lowrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 1)); } if ($level >= 4) { $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'bypass_validation_midrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 1)); } // 2=May post, [3=May post instantly , 4=May start topics instantly , 5=Moderator -- these ones will not be treated specially, so as to avoid overriding permissions unnecessary - let the admins configure it optimally manually] } } } log_it('ADD_FORUM', strval($forum_id), $name); return $forum_id; }