Ejemplo n.º 1
0
 /**
  * Event: core.viewtopic_assign_template_vars_before
  *
  * assign tags to topic-template and header-meta
  *
  * @param $event
  */
 public function viewtopic_assign_template_vars_before($event)
 {
     $data = $event->get_data();
     $topic_id = (int) $data['topic_id'];
     $forum_id = (int) $data['forum_id'];
     if ($this->tags_manager->is_tagging_enabled_in_forum($forum_id)) {
         $tags = $this->tags_manager->get_assigned_tags($topic_id);
         if (!empty($tags)) {
             $this->assign_tags_to_template('rh_topic_tags', $tags);
             $this->template->assign_vars(array('RH_TOPICTAGS_SHOW' => true, 'META' => '<meta name="keywords" content="' . join(', ', $tags) . '">'));
             // tags might want to use our extension's css.
             $this->template->assign_var('S_RH_TOPICTAGS_INCLUDE_CSS', true);
         }
     }
 }
Ejemplo n.º 2
0
    public function test_merge()
    {
        global $table_prefix;
        // uses auth, so we set up the mock/stub
        // to allow reading first forum
        $this->auth->expects($this->exactly(2))->method('acl_getf')->with($this->equalTo('f_read'))->willReturn(array(1 => array('f_read' => true)));
        $tag_to_delete = "tag1";
        $tag_to_delete_id = 1;
        $tag_to_keep = "tag2";
        $tag_to_keep_id = 2;
        $result = $this->db->sql_query('SELECT count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE id=' . $tag_to_keep_id);
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        // 2 assignments but only 1 is readable
        $count_of_assignments = $this->tags_manager->merge($tag_to_delete_id, $tag_to_keep, $tag_to_keep_id);
        $this->assertEquals(1, $count_of_assignments);
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TOPICTAGS . '
			WHERE tag_id=' . $tag_to_keep_id);
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(2, $count);
        // tag1 must be deleted
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE id=' . $tag_to_delete_id);
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        // tag2 must be assignet to both topics
        // but only counted once because of tagging disabled forum
        $result = $this->db->sql_query('SELECT count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE id=' . $tag_to_keep_id);
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count);
        $result = $this->db->sql_query('SELECT topic_id
			FROM ' . $table_prefix . tables::TOPICTAGS . '
			WHERE tag_id=' . $tag_to_keep_id);
        $topics = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $topics[] = $row['topic_id'];
        }
        $this->assertEquals(array(1, 2), $topics);
        // test if keep-tag is already assigned to topics that the deleted one is assigned to
        $tag_to_delete = "tag2";
        $tag_to_delete_id = 2;
        $tag_to_keep = "anothertag3";
        $tag_to_keep_id = 3;
        // ensure test setup (tag2 must be assigned because of the merge before)
        $tags = $this->tags_manager->get_assigned_tags(2);
        sort($tags);
        $this->assertEquals(array('anothertag3', 'tag2'), $tags);
        // 3 assignments, but only 2 are valid
        $count_of_assignments = $this->tags_manager->merge($tag_to_delete_id, $tag_to_keep, $tag_to_keep_id);
        $this->assertEquals(2, $count_of_assignments);
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TOPICTAGS . '
			WHERE tag_id=' . $tag_to_keep_id);
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(3, $count);
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TOPICTAGS . '
			WHERE tag_id=' . $tag_to_keep_id . ' AND topic_id=2');
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count, 'the topic must not be assigned twice');
        $tags = $this->tags_manager->get_assigned_tags(2);
        $this->assertEquals(array('anothertag3'), $tags);
    }