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();
    }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
 public function test_get_all_tags()
 {
     $start = 0;
     $limit = 1;
     $sort_field = 'tag';
     $asc = true;
     $tags = $this->tags_manager->get_all_tags($start, $limit, $sort_field, $asc);
     $this->assertEquals(array(array('id' => 3, 'tag' => 'anothertag3', 'tag_lowercase' => 'anothertag3', 'count' => 0)), $tags);
     $start = 0;
     $limit = 1;
     $sort_field = 'tag';
     $asc = false;
     $tags = $this->tags_manager->get_all_tags($start, $limit, $sort_field, $asc);
     $this->assertEquals(array(array('id' => 2, 'tag' => 'tag2', 'tag_lowercase' => 'tag2', 'count' => 0)), $tags);
     $start = 1;
     $limit = 1;
     $sort_field = 'tag';
     $asc = true;
     $tags = $this->tags_manager->get_all_tags($start, $limit, $sort_field, $asc);
     $this->assertEquals(array(array('id' => 1, 'tag' => 'tag1', 'tag_lowercase' => 'tag1', 'count' => 0)), $tags);
     // ensure proper counts
     $this->tags_manager->calc_count_tags();
     $start = 0;
     $limit = 2;
     $sort_field = 'count';
     $asc = true;
     $tags = $this->tags_manager->get_all_tags($start, $limit, $sort_field, $asc);
     $this->assertEquals(array(array('id' => 2, 'tag' => 'tag2', 'tag_lowercase' => 'tag2', 'count' => 0), array('id' => 1, 'tag' => 'tag1', 'tag_lowercase' => 'tag1', 'count' => 1)), $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();
 }
 /**
  * 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));
 }