[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\feed; 15 16 /** 17 * Class with some helpful functions used in feeds 18 */ 19 class helper 20 { 21 /** @var \phpbb\config\config */ 22 protected $config; 23 24 /** @var \phpbb\user */ 25 protected $user; 26 27 /** @var string */ 28 protected $phpbb_root_path; 29 30 /** @var string */ 31 protected $phpEx; 32 33 /** 34 * Constructor 35 * 36 * @param \phpbb\config\config $config Config object 37 * @param \phpbb\user $user User object 38 * @param string $phpbb_root_path Root path 39 * @param string $phpEx PHP file extension 40 */ 41 public function __construct(\phpbb\config\config $config, \phpbb\user $user, $phpbb_root_path, $phpEx) 42 { 43 $this->config = $config; 44 $this->user = $user; 45 $this->phpbb_root_path = $phpbb_root_path; 46 $this->phpEx = $phpEx; 47 } 48 49 /** 50 * Run links through append_sid(), prepend generate_board_url() and remove session id 51 */ 52 public function get_board_url() 53 { 54 static $board_url; 55 56 if (empty($board_url)) 57 { 58 $board_url = generate_board_url(); 59 } 60 61 return $board_url; 62 } 63 64 /** 65 * Run links through append_sid(), prepend generate_board_url() and remove session id 66 */ 67 public function append_sid($url, $params) 68 { 69 return append_sid($this->get_board_url() . '/' . $url, $params, true, ''); 70 } 71 72 /** 73 * Generate ISO 8601 date string (RFC 3339) 74 */ 75 public function format_date($time) 76 { 77 static $zone_offset; 78 static $offset_string; 79 80 if (empty($offset_string)) 81 { 82 $zone_offset = $this->user->create_datetime()->getOffset(); 83 $offset_string = phpbb_format_timezone_offset($zone_offset); 84 } 85 86 return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string; 87 } 88 89 /** 90 * Generate text content 91 * 92 * @param string $content is feed text content 93 * @param string $uid is bbcode_uid 94 * @param string $bitfield is bbcode bitfield 95 * @param int $options bbcode flag options 96 * @param int $forum_id is the forum id 97 * @param array $post_attachments is an array containing the attachments and their respective info 98 * @return string the html content to be printed for the feed 99 */ 100 public function generate_content($content, $uid, $bitfield, $options, $forum_id, $post_attachments) 101 { 102 if (empty($content)) 103 { 104 return ''; 105 } 106 107 // Prepare some bbcodes for better parsing 108 $content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content); 109 110 $content = generate_text_for_display($content, $uid, $bitfield, $options); 111 112 // Add newlines 113 $content = str_replace('<br />', '<br />' . "\n", $content); 114 115 // Convert smiley Relative paths to Absolute path, Windows style 116 $content = str_replace($this->phpbb_root_path . $this->config['smilies_path'], $this->get_board_url() . '/' . $this->config['smilies_path'], $content); 117 118 // Remove "Select all" link and mouse events 119 $content = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $this->user->lang['SELECT_ALL_CODE'] . '</a>', '', $content); 120 $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content); 121 122 // Firefox does not support CSS for feeds, though 123 124 // Remove font sizes 125 // $content = preg_replace('#<span style="font-size: [0-9]+%; line-height: [0-9]+%;">([^>]+)</span>#iU', '\1', $content); 126 127 // Make text strong :P 128 // $content = preg_replace('#<span style="font-weight: bold?">(.*?)</span>#iU', '<strong>\1</strong>', $content); 129 130 // Italic 131 // $content = preg_replace('#<span style="font-style: italic?">([^<]+)</span>#iU', '<em>\1</em>', $content); 132 133 // Underline 134 // $content = preg_replace('#<span style="text-decoration: underline?">([^<]+)</span>#iU', '<u>\1</u>', $content); 135 136 // Remove embed Windows Media Streams 137 $content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--<!\[endif\]-->#si', '', $content); 138 139 // Do not use < and >, because we want to retain code contained in [code][/code] 140 141 // Remove embed and objects 142 $content = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' <a href=$4 target="_blank"><strong>$1</strong></a> ',$content); 143 144 // Remove some specials html tag, because somewhere there are a mod to allow html tags ;) 145 $content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content); 146 147 // Parse inline images to display with the feed 148 if (!empty($post_attachments)) 149 { 150 $update_count = array(); 151 parse_attachments($forum_id, $content, $post_attachments, $update_count); 152 $content .= implode('<br />', $post_attachments); 153 154 // Convert attachments' relative path to absolute path 155 $content = str_replace($this->phpbb_root_path . 'download/file.' . $this->phpEx, $this->get_board_url() . '/download/file.' . $this->phpEx, $content); 156 } 157 158 // Remove Comments from inline attachments [ia] 159 $content = preg_replace('#<dd>(.*?)</dd>#','',$content); 160 161 // Replace some entities with their unicode counterpart 162 $entities = array( 163 ' ' => "\xC2\xA0", 164 '•' => "\xE2\x80\xA2", 165 '·' => "\xC2\xB7", 166 '©' => "\xC2\xA9", 167 ); 168 169 $content = str_replace(array_keys($entities), array_values($entities), $content); 170 171 // Remove CDATA blocks. ;) 172 $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content); 173 174 // Other control characters 175 $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content); 176 177 return $content; 178 } 179 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |