public function core_acp_manage_forums_initialise_data($event) { // because there's no php event in delete forums, // we do cleanup of posting templates of deleted forums whenever showing the form. $sql = 'SELECT config_name FROM ' . $this->config_text_table . ' WHERE config_name ' . $this->db->sql_like_expression('marttiphpbb_postingtemplate_forum' . $this->db->get_any_char()); $result = $this->db->sql_query($sql); $postingtemplates = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); if (sizeof($postingtemplates)) { $all_forums = array(); $sql = 'SELECT forum_id FROM ' . $this->forums_table; $result = $this->db->sql_query($sql); while ($forum_id = $this->db->sql_fetchfield('forum_id')) { $all_forums[$forum_id] = 1; } $this->db->sql_freeresult($result); $to_delete_ary = array(); foreach ($postingtemplates as $name) { $name = $name['config_name']; $forum_id = trim(substr($name, strpos($name, '[') + 1), ']'); if (!isset($all_forums[$forum_id])) { $to_delete_ary[] = $name; } } $this->config_text->delete_array($to_delete_ary); } }
public function test_delete_array_get_remaining() { $this->config_text->delete_array(array('foo', 'bar')); $this->assertNull($this->config_text->get('bar')); $this->assertNull($this->config_text->get('foo')); $this->assertSame('string-de-ding', $this->config_text->get('meh')); }
public function test_is_valid_tag() { global $table_prefix; $this->assertTrue($this->tags_manager->is_valid_tag("tag")); // clean tags must be trimed (note the trailing space) $this->assertFalse($this->tags_manager->is_valid_tag("tag ", true)); $this->assertFalse($this->tags_manager->is_valid_tag("ta"), 'tag is too short'); $this->assertFalse($this->tags_manager->is_valid_tag("abcdefghijabcdefghijabcdefghija", true), 'tag is too long'); // will be cleaned and thereby trimmed to 30 chars $this->assertTrue($this->tags_manager->is_valid_tag("abcdefghijabcdefghijabcdefghija", false)); // enable blacklist and whitelist global $table_prefix; $config = new \phpbb\config\config(array(prefixes::CONFIG . '_allowed_tags_regex' => '/^[a-z]{3,30}$/i', prefixes::CONFIG . '_whitelist_enabled' => true, prefixes::CONFIG . '_blacklist_enabled' => true)); $this->config_text->set_array(array(prefixes::CONFIG . '_blacklist' => json_encode(array("blacktag", "blackwhitetag")), prefixes::CONFIG . '_whitelist' => json_encode(array("whitetag", "blackwhitetag")))); $db_helper = new \robertheim\topictags\service\db_helper($this->db); $this->tags_manager = new tags_manager($this->db, $config, $this->config_text, $this->auth, $db_helper, $table_prefix); $this->assertFalse($this->tags_manager->is_valid_tag("blacktag", true), 'tag is on blacklist'); $this->assertFalse($this->tags_manager->is_valid_tag("notwhitetag", true), 'tag is not on whitelist'); $this->assertTrue($this->tags_manager->is_valid_tag("whitetag", true), 'tag is not blacklisted and on whitelist'); $this->assertFalse($this->tags_manager->is_valid_tag("blackwhitetag", true), 'blacklist must be given priority'); $this->config_text->delete_array(array(prefixes::CONFIG . '_blacklist', prefixes::CONFIG . '_whitelist')); }