diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 7a0fddf0c1..bb96953bcf 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -4,6 +4,7 @@ imports: - { resource: notifications.yml } - { resource: migrator.yml } - { resource: avatars.yml } + - { resource: feed.yml } services: auth: diff --git a/phpBB/feed.php b/phpBB/feed.php index 676dd45c5a..c1940a5eb6 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -59,7 +59,8 @@ if ($forum_id || $topic_id || $mode) } // This boards URL -$board_url = generate_board_url(); +$phpbb_feed_helper = $phpbb_container->get('feed.helper'); +$board_url = $phpbb_feed_helper->get_board_url(); // Get correct feed object $feed = phpbb_feed_factory::init($mode, $forum_id, $topic_id); @@ -99,13 +100,13 @@ while ($row = $feed->get_item()) $item_row = array( 'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '', - 'published' => ($published > 0) ? feed_format_date($published) : '', - 'updated' => ($updated > 0) ? feed_format_date($updated) : '', + 'published' => ($published > 0) ? $phpbb_feed_helper->format_date($published) : '', + 'updated' => ($updated > 0) ? $phpbb_feed_helper->format_date($updated) : '', 'link' => '', 'title' => censor_text($title), 'category' => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', 'category_name' => ($config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '', - 'description' => censor_text(feed_generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)), + 'description' => censor_text($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options)), 'statistics' => '', ); @@ -127,11 +128,11 @@ if (!$feed_updated_time) // FEED_IMAGE is not used (atom) $global_vars = array_merge($global_vars, array( 'FEED_IMAGE' => '', - 'SELF_LINK' => feed_append_sid('/feed.' . $phpEx, $params), + 'SELF_LINK' => $phpbb_feed_helper->append_sid('/feed.' . $phpEx, $params), 'FEED_LINK' => $board_url . '/index.' . $phpEx, 'FEED_TITLE' => $config['sitename'], 'FEED_SUBTITLE' => $config['site_desc'], - 'FEED_UPDATED' => feed_format_date($feed_updated_time), + 'FEED_UPDATED' => $phpbb_feed_helper->format_date($feed_updated_time), 'FEED_LANG' => $user->lang['USER_LANG'], 'FEED_AUTHOR' => $config['sitename'], )); @@ -231,106 +232,3 @@ echo ''; garbage_collection(); exit_handler(); - -/** -* Run links through append_sid(), prepend generate_board_url() and remove session id -**/ -function feed_append_sid($url, $params) -{ - global $board_url; - - return append_sid($board_url . $url, $params, true, ''); -} - -/** -* Generate ISO 8601 date string (RFC 3339) -**/ -function feed_format_date($time) -{ - static $zone_offset; - static $offset_string; - - if (empty($offset_string)) - { - global $user; - - $zone_offset = $user->create_datetime()->getOffset(); - $offset_string = phpbb_format_timezone_offset($zone_offset); - } - - return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string; -} - -/** -* Generate text content -**/ -function feed_generate_content($content, $uid, $bitfield, $options) -{ - global $user, $config, $phpbb_root_path, $phpEx, $board_url; - - if (empty($content)) - { - return ''; - } - - // Prepare some bbcodes for better parsing - $content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]
$2
[/quote:$uid]", $content); - - $content = generate_text_for_display($content, $uid, $bitfield, $options); - - // Add newlines - $content = str_replace('
', '
' . "\n", $content); - - // Convert smiley Relative paths to Absolute path, Windows style - $content = str_replace($phpbb_root_path . $config['smilies_path'], $board_url . '/' . $config['smilies_path'], $content); - - // Remove "Select all" link and mouse events - $content = str_replace('' . $user->lang['SELECT_ALL_CODE'] . '', '', $content); - $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content); - - // Firefox does not support CSS for feeds, though - - // Remove font sizes -// $content = preg_replace('#([^>]+)#iU', '\1', $content); - - // Make text strong :P -// $content = preg_replace('#(.*?)#iU', '\1', $content); - - // Italic -// $content = preg_replace('#([^<]+)#iU', '\1', $content); - - // Underline -// $content = preg_replace('#([^<]+)#iU', '\1', $content); - - // Remove embed Windows Media Streams - $content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--#si', '', $content); - - // Do not use < and >, because we want to retain code contained in [code][/code] - - // Remove embed and objects - $content = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' $1 ',$content); - - // Remove some specials html tag, because somewhere there are a mod to allow html tags ;) - $content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' $1 ', $content); - - // Remove Comments from inline attachments [ia] - $content = preg_replace('#
(.*?)(.*?)(.*?)
#si','$4',$content); - - // Replace some entities with their unicode counterpart - $entities = array( - ' ' => "\xC2\xA0", - '•' => "\xE2\x80\xA2", - '·' => "\xC2\xB7", - '©' => "\xC2\xA9", - ); - - $content = str_replace(array_keys($entities), array_values($entities), $content); - - // Remove CDATA blocks. ;) - $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content); - - // Other control characters - $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content); - - return $content; -} diff --git a/phpBB/includes/feed/helper.php b/phpBB/includes/feed/helper.php new file mode 100644 index 0000000000..20a399bcd7 --- /dev/null +++ b/phpBB/includes/feed/helper.php @@ -0,0 +1,159 @@ +config = $config; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * Run links through append_sid(), prepend generate_board_url() and remove session id + */ + public function get_board_url() + { + static $board_url; + + if (empty($board_url)) + { + $board_url = generate_board_url(); + } + + return $board_url; + } + + /** + * Run links through append_sid(), prepend generate_board_url() and remove session id + */ + public function append_sid($url, $params) + { + return append_sid($this->get_board_url() . $url, $params, true, ''); + } + + /** + * Generate ISO 8601 date string (RFC 3339) + */ + public function format_date($time) + { + static $zone_offset; + static $offset_string; + + if (empty($offset_string)) + { + $zone_offset = $this->user->create_datetime()->getOffset(); + $offset_string = phpbb_format_timezone_offset($zone_offset); + } + + return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string; + } + + /** + * Generate text content + */ + public function generate_content($content, $uid, $bitfield, $options) + { + if (empty($content)) + { + return ''; + } + + // Prepare some bbcodes for better parsing + $content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]
$2
[/quote:$uid]", $content); + + $content = generate_text_for_display($content, $uid, $bitfield, $options); + + // Add newlines + $content = str_replace('
', '
' . "\n", $content); + + // Convert smiley Relative paths to Absolute path, Windows style + $content = str_replace($this->phpbb_root_path . $this->config['smilies_path'], $this->get_board_url() . '/' . $this->config['smilies_path'], $content); + + // Remove "Select all" link and mouse events + $content = str_replace('' . $this->user->lang['SELECT_ALL_CODE'] . '', '', $content); + $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content); + + // Firefox does not support CSS for feeds, though + + // Remove font sizes + // $content = preg_replace('#([^>]+)#iU', '\1', $content); + + // Make text strong :P + // $content = preg_replace('#(.*?)#iU', '\1', $content); + + // Italic + // $content = preg_replace('#([^<]+)#iU', '\1', $content); + + // Underline + // $content = preg_replace('#([^<]+)#iU', '\1', $content); + + // Remove embed Windows Media Streams + $content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--#si', '', $content); + + // Do not use < and >, because we want to retain code contained in [code][/code] + + // Remove embed and objects + $content = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' $1 ',$content); + + // Remove some specials html tag, because somewhere there are a mod to allow html tags ;) + $content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' $1 ', $content); + + // Remove Comments from inline attachments [ia] + $content = preg_replace('#
(.*?)(.*?)(.*?)
#si','$4',$content); + + // Replace some entities with their unicode counterpart + $entities = array( + ' ' => "\xC2\xA0", + '•' => "\xE2\x80\xA2", + '·' => "\xC2\xB7", + '©' => "\xC2\xA9", + ); + + $content = str_replace(array_keys($entities), array_values($entities), $content); + + // Remove CDATA blocks. ;) + $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content); + + // Other control characters + $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content); + + return $content; + } +}