public function testBbcodeStripping() { $content = '[b:32fdkg1c]b[/b:32fdkg1c][i:32fdkg1c]i[/i:32fdkg1c][u:32fdkg1c]u[/u:32fdkg1c] [url=http://www.phpbb.com:32fdkg1c].com[/url:32fdkg1c] [size=85:32fdkg1c]sm[/size:32fdkg1c][color=#FF0000:32fdkg1c]re[/color:32fdkg1c][code:32fdkg1c]hi[/code:32fdkg1c][quote="MichaelC":32fdkg1c]hi[/quote:32fdkg1c][list:32fdkg1c][*:32fdkg1c]one[/*:m:32fdkg1c][*:32fdkg1c]another[/*:m:32fdkg1c][/list:u:32fdkg1c]'; $uid = '32fdkg1c'; $expected = ' b i u .com sm re hi hi one another '; $this->assertEquals(PhpbbHandling::bbcodeStripping($content, $uid), $expected); }
/** * @param integer $announcement_forum */ private function getForumAnnouncements($announcement_forum) { $retrieve_limit = 3; $phpbbConnection = $this->get('doctrine.dbal.phpbb_connection'); $forumAnnouncements = PhpbbHandling::getTopicsFromForum($phpbbConnection, $announcement_forum, $retrieve_limit, $this->container->getParameter('phpbb_database_prefix')); $finishedAnnouncements = array(); foreach ($forumAnnouncements as $announcement) { $preview = $announcement['post_text']; $preview = PhpbbHandling::bbcodeStripping($preview, $announcement['bbcode_uid']); $preview = preg_replace('#http(?:\\:|&\\#58;)//\\S+#', '', $preview); // Decide how large the preview text should be $preview_max_len = 200; $preview_len = strlen($preview); if ($preview_len > $preview_max_len) { // Truncate to the maximum length $preview = substr($preview, 0, $preview_max_len); // See if there is a nice place to break close to the max length $breakchars = array(' ', ',', '.'); $clean_break_pos = 0; foreach ($breakchars as $char) { $clean_break_pos_new = strrpos($preview, $char); $clean_break_pos = $clean_break_pos_new > $clean_break_pos ? $clean_break_pos_new : $clean_break_pos; } if ($clean_break_pos) { $preview = substr($preview, 0, $clean_break_pos); } } $finishedAnnouncements[$announcement['topic_time']] = array('DAY' => date('d', $announcement['topic_time']), 'MONTH' => date('M', $announcement['topic_time']), 'YEAR' => date('Y', $announcement['topic_time']), 'U_LINK' => '/community/viewtopic.php?f=' . $announcement_forum . '&t=' . $announcement['topic_id'], 'TITLE' => $announcement['topic_title'], 'FROM_BLOG' => false, 'PREVIEW' => $preview); } return $finishedAnnouncements; }