protected function enable_topictags_in_forum($forum_id) { $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', array('rh_topictags_enabled' => 1)) . ' WHERE forum_id = ' . (int) $forum_id; $this->db->sql_query($sql); $this->tags_manager->calc_count_tags(); }
public function calc_count_tags() { /* @var $auth \phpbb\auth\auth */ $auth = $this->container->get('auth'); $db_helper = new db_helper($this->db); $config_text = $this->container->get('config_text'); $tags_manager = new tags_manager($this->db, $this->config, $config_text, $auth, $db_helper, $this->table_prefix); $tags_manager->calc_count_tags(); }
public function acp_manage_forums_update_data_after($event) { $status = $this->request->variable('rh_topictags_enabled', 0); $prune = $this->request->variable('rh_topictags_prune', 0); if (!$status && $prune) { $data = $event->get_data(); $forum_id = (int) $data['forum_data']['forum_id']; $this->tags_manager->delete_tags_from_tagdisabled_forums(array($forum_id)); $this->tags_manager->delete_unused_tags(); } $this->tags_manager->calc_count_tags(); }
public function test_count_tags() { $count = $this->tags_manager->count_tags(); $this->assertEquals(3, $count); $this->tags_manager->delete_tag(1); $count = $this->tags_manager->count_tags(); $this->assertEquals(2, $count); }
/** * @param $is_ajax whether the edit is called by ajax or not * @param string $u_action phpbb acp-u_action */ private function handle_edit($u_action, $is_ajax = true) { if (!$is_ajax) { $new_tag_name = $this->request->variable('new_tag_name', ''); if (empty($new_tag_name)) { $tag_id = $this->request->variable('tag_id', 0); $old_tag_name = $this->tags_manager->get_tag_by_id($tag_id); $this->template->assign_vars(array('U_ACTION' => $this->get_tag_link($u_action, $tag_id) . '&action=edit_non_ajax', 'S_EDIT_TAG_NON_AJAX' => true, 'OLD_TAG_NAME' => $old_tag_name)); return; } // now new_tag_name and old_tag_name are set and the normal procedure can take place. } $old_tag_name = $this->request->variable('old_tag_name', ''); $new_tag_name = $this->request->variable('new_tag_name', ''); if (empty($old_tag_name) || empty($new_tag_name)) { $error_msg = $this->user->lang('TOPICTAGS_MISSING_TAG_NAMES'); $this->simple_response($u_action, $error_msg, false); } else { if ($is_ajax) { $old_tag_name = rawurldecode(base64_decode($old_tag_name)); $new_tag_name = rawurldecode(base64_decode($new_tag_name)); } if ($old_tag_name == $new_tag_name) { $error_msg = $this->user->lang('TOPICTAGS_NO_MODIFICATION', $old_tag_name); $this->simple_response($u_action, $error_msg, false); } $old_ids = $this->tags_manager->get_existing_tags(array($old_tag_name), true); if (empty($old_ids)) { $error_msg = $this->user->lang('TOPICTAGS_TAG_DOES_NOT_EXIST', $old_tag_name); $this->simple_response($u_action, $error_msg, false); } // if we reach here, we know that we got a single valid old tag $old_id = $old_ids[0]; $new_tag_name_clean = $this->tags_manager->clean_tag($new_tag_name); $is_valid = $this->tags_manager->is_valid_tag($new_tag_name_clean, true); if (!$is_valid) { $error_msg = $this->user->lang('TOPICTAGS_TAG_INVALID', $new_tag_name); $this->simple_response($u_action, $error_msg, false); } // old tag exist and new tag is valid $new_ids = $this->tags_manager->get_existing_tags(array($new_tag_name), true); if (!empty($new_ids)) { // new tag exist -> merge $new_id = $new_ids[0]; $new_tag_count = $this->tags_manager->merge($old_id, $new_tag_name, $new_id); $msg = $this->user->lang('TOPICTAGS_TAG_MERGED', $new_tag_name_clean); $this->simple_response($u_action, $msg, true, array('success' => true, 'merged' => true, 'new_tag_count' => $new_tag_count, 'msg' => base64_encode(rawurlencode($msg)))); } // old tag exist and new tag is valid and does not exist -> rename it $this->tags_manager->rename($old_id, $new_tag_name_clean); $msg = $this->user->lang('TOPICTAGS_TAG_CHANGED'); $this->simple_response($u_action, $msg); } }
/** * Gets suggestions for tags based on a ajax request, route: /tags/suggest * * @param php://input raw post data must contain a json-encoded object of this structure: {"query":"...", "exclude":["...", "...", ...]} */ public function suggest_tags() { if (false && $this->request->is_ajax()) { $data = json_decode(file_get_contents('php://input'), true); $query = $data['query']; $exclude = $data['exclude']; $tags = $this->tags_manager->get_tag_suggestions($query, $exclude, 5); $json_response = new json_response(); $json_response->send($tags); } // fake a 404 return $this->helper->error($this->user->lang('RH_TOPICTAGS_TAG_SUGGEST_TAG_ROUTE_ERROR', $this->helper->get_current_url()), 404); }
/** * Event: core.delete_topics_before_query * * prune tags when topic is deleted * * @param $event */ public function delete_topics_before_query($event) { $data = $event->get_data(); $topic_ids = $data['topic_ids']; $this->tags_manager->remove_all_tags_from_topics($topic_ids, true); }
/** * Default settings page */ private function handle_settings() { global $config, $request, $template, $user; // Define the name of the form for use as a form key $form_name = 'topictags'; add_form_key($form_name); $errors = array(); if ($request->is_set_post('submit')) { if (!check_form_key($form_name)) { trigger_error('FORM_INVALID'); } $commit_to_db = true; $msg = array(); $regex = utf8_normalize_nfc($request->variable(prefixes::CONFIG . '_allowed_tags_regex', $user->lang('ACP_RH_TOPICTAGS_REGEX_DEFAULT'), true)); if (empty($regex)) { $commit_to_db = false; $errors[] = $user->lang('ACP_RH_TOPICTAGS_REGEX_EMPTY'); } $exp_for_users = utf8_normalize_nfc($request->variable(prefixes::CONFIG . '_allowed_tags_exp_for_users', $user->lang('ACP_RH_TOPICTAGS_REGEX_EXP_FOR_USERS_DEFAULT'), true)); if (empty($exp_for_users)) { $commit_to_db = false; $errors[] = $user->lang('ACP_RH_TOPICTAGS_EXP_FOR_USERS_EMPTY'); } if ($commit_to_db) { $config->set(prefixes::CONFIG . '_display_tags_in_viewforum', $request->variable(prefixes::CONFIG . '_display_tags_in_viewforum', 1)); $config->set(prefixes::CONFIG . '_allowed_tags_regex', $regex); $config->set(prefixes::CONFIG . '_allowed_tags_exp_for_users', $exp_for_users); $config->set(prefixes::CONFIG . '_display_tagcloud_on_index', $request->variable(prefixes::CONFIG . '_display_tagcloud_on_index', 1)); $config->set(prefixes::CONFIG . '_display_tagcount_in_tagcloud', $request->variable(prefixes::CONFIG . '_display_tagcount_in_tagcloud', 1)); $max_tags_in_tagcloud = $request->variable(prefixes::CONFIG . '_max_tags_in_tagcloud', 20); if ($max_tags_in_tagcloud < 0) { $max_tags_in_tagcloud = 0; } $config->set(prefixes::CONFIG . '_max_tags_in_tagcloud', $max_tags_in_tagcloud); $config->set(prefixes::CONFIG . '_convert_space_to_minus', $request->variable(prefixes::CONFIG . '_convert_space_to_minus', 1)); $deleted_assignments_count = 0; $delete_unused_tags = false; if ($request->variable(prefixes::CONFIG . '_enable_in_all_forums', 0) > 0) { $count_affected = $this->tags_manager->enable_tags_in_all_forums(); $msg[] = $user->lang('TOPICTAGS_ENABLE_IN_ALL_FORUMS_DONE', $count_affected); } if ($request->variable(prefixes::CONFIG . '_disable_in_all_forums', 0) > 0) { $count_affected = $this->tags_manager->disable_tags_in_all_forums(); $msg[] = $user->lang('TOPICTAGS_DISABLE_IN_ALL_FORUMS_DONE', $count_affected); } if ($request->variable(prefixes::CONFIG . '_calc_count_tags', 0) > 0) { $this->tags_manager->calc_count_tags(); $msg[] = $user->lang('TOPICTAGS_CALC_COUNT_TAGS_DONE'); } if ($request->variable(prefixes::CONFIG . '_prune', 0) > 0) { $deleted_assignments_count += $this->tags_manager->delete_assignments_where_topic_does_not_exist(); $delete_unused_tags = true; } if ($request->variable(prefixes::CONFIG . '_prune_forums', 0) > 0) { $deleted_assignments_count += $this->tags_manager->delete_tags_from_tagdisabled_forums(); $delete_unused_tags = true; } if ($request->variable(prefixes::CONFIG . '_prune_invalid_tags', 0) > 0) { $deleted_assignments_count += $this->tags_manager->delete_assignments_of_invalid_tags(); $delete_unused_tags = true; } if ($delete_unused_tags) { $deleted_tags_count = $this->tags_manager->delete_unused_tags(); $msg[] = $user->lang('TOPICTAGS_PRUNE_TAGS_DONE', $deleted_tags_count); } if ($deleted_assignments_count > 0) { $msg[] = $user->lang('TOPICTAGS_PRUNE_ASSIGNMENTS_DONE', $deleted_assignments_count); } if (empty($msg)) { $msg[] = $user->lang('TOPICTAGS_SETTINGS_SAVED'); } trigger_error(join('<br/>', $msg) . adm_back_link($this->u_action)); } } $all_enabled = $this->tags_manager->is_enabled_in_all_forums(); $all_disabled = $all_enabled ? false : $this->tags_manager->is_disabled_in_all_forums(); $template->assign_vars(array('TOPICTAGS_VERSION' => $user->lang('TOPICTAGS_INSTALLED', $config[prefixes::CONFIG . '_version']), 'TOPICTAGS_DISPLAY_TAGS_IN_VIEWFORUM' => $config[prefixes::CONFIG . '_display_tags_in_viewforum'], 'TOPICTAGS_DISPLAY_TAGCLOUD_ON_INDEX' => $config[prefixes::CONFIG . '_display_tagcloud_on_index'], 'TOPICTAGS_DISPLAY_TAGCOUNT_IN_TAGCLOUD' => $config[prefixes::CONFIG . '_display_tagcount_in_tagcloud'], 'TOPICTAGS_MAX_TAGS_IN_TAGCLOUD' => $config[prefixes::CONFIG . '_max_tags_in_tagcloud'], 'TOPICTAGS_ALLOWED_TAGS_REGEX' => $config[prefixes::CONFIG . '_allowed_tags_regex'], 'TOPICTAGS_ALLOWED_TAGS_EXP_FOR_USERS' => $config[prefixes::CONFIG . '_allowed_tags_exp_for_users'], 'TOPICTAGS_CONVERT_SPACE_TO_MINUS' => $config[prefixes::CONFIG . '_convert_space_to_minus'], 'TOPICTAGS_IS_ENABLED_IN_ALL_FORUMS' => $all_enabled, 'TOPICTAGS_IS_DISABLED_IN_ALL_FORUMS' => $all_disabled, 'S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => implode('<br />', $errors), 'U_ACTION' => $this->u_action)); }