Changeset 4866 for trunk/includes/common/formatting.php
- Timestamp:
- 04/26/2013 11:00:38 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/common/formatting.php
r4733 r4866 121 121 // Setup variables 122 122 $openers = array( '<p>', '<br />' ); 123 $content 123 $content = preg_replace_callback( "!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", 'bbp_decode_callback', $content ); 124 124 125 125 // Do the do 126 $content 127 $content 128 $content 129 $content 130 $content 126 $content = str_replace( $openers, '', $content ); 127 $content = str_replace( '</p>', "\n", $content ); 128 $content = str_replace( '<coded_br />', '<br />', $content ); 129 $content = str_replace( '<coded_p>', '<p>', $content ); 130 $content = str_replace( '</coded_p>', '</p>', $content ); 131 131 132 132 return $content; … … 158 158 ); 159 159 160 // Add 'p' and 'br' tags to allowed array, so they are not encoded161 $allowed['p'] = array();162 $allowed['br'] = array();163 164 160 // Loop through allowed tags and compare for empty and normal tags 165 161 foreach ( $allowed as $tag => $args ) { 166 162 $preg = $args ? "{$tag}(?:\s.*?)?" : $tag; 167 163 168 // Which walker to use based on the tag and arg ments164 // Which walker to use based on the tag and arguments 169 165 if ( isset( $empty[$tag] ) ) { 170 166 array_walk( $content, 'bbp_encode_empty_callback', $preg ); … … 189 185 */ 190 186 function bbp_encode_callback( $matches = array() ) { 191 $content = trim( $matches[2] ); 187 188 // Trim inline code, not pre blocks (to prevent removing indentation) 189 if ( "`" == $matches[1] ) { 190 $content = trim( $matches[2] ); 191 } else { 192 $content = $matches[2]; 193 } 194 195 // Do some replacing 192 196 $content = htmlspecialchars( $content, ENT_QUOTES ); 193 197 $content = str_replace( array( "\r\n", "\r" ), "\n", $content ); … … 196 200 $content = str_replace( '&lt;', '<', $content ); 197 201 $content = str_replace( '&gt;', '>', $content ); 202 203 // Wrap in code tags 198 204 $content = '<code>' . $content . '</code>'; 199 205 200 if ( "`" != $matches[1] ) 206 // Wrap blocks in pre tags 207 if ( "`" != $matches[1] ) { 201 208 $content = '<pre>' . $content . '</pre>'; 209 } 202 210 203 211 return $content; … … 262 270 } 263 271 } 272 273 /** No Follow *****************************************************************/ 274 275 /** 276 * Catches links so rel=nofollow can be added (on output, not save) 277 * 278 * @since bbPress (r4865) 279 * @param string $text Post text 280 * @return string $text Text with rel=nofollow added to any links 281 */ 282 function bbp_rel_nofollow( $text = '' ) { 283 return preg_replace_callback( '|<a (.+?)>|i', 'bbp_rel_nofollow_callback', $text ); 284 } 285 286 /** 287 * Adds rel=nofollow to a link 288 * 289 * @since bbPress (r4865) 290 * @param array $matches 291 * @return string $text Link with rel=nofollow added 292 */ 293 function bbp_rel_nofollow_callback( $matches = array() ) { 294 $text = $matches[1]; 295 $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'" ), '', $text ); 296 return "<a $text rel=\"nofollow\">"; 297 }
Note: See TracChangeset
for help on using the changeset viewer.