PageRenderTime 42ms CodeModel.GetById 24ms app.highlight 3ms RepoModel.GetById 13ms app.codeStats 0ms

/halogy/application/helpers/bbcode_helper.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 84 lines | 48 code | 13 blank | 23 comment | 2 complexity | 0d99aefb74e3af67f38f26426a92b491 MD5 | raw file
 1<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
 2
 3/**
 4* CodeIgniter BBCode Helpers
 5*
 6* @package  CodeIgniter
 7* @subpackage Helpers
 8* @category Helpers
 9* @author  Philip Sturgeon
10* @changes  MpaK http://mrak7.com
11* @link  http://codeigniter.com/wiki/BBCode_Helper/
12*/
13
14// ------------------------------------------------------------------------
15
16/**
17* parse_bbcode
18*
19* Converts BBCode style tags into basic HTML
20*
21* @access public
22* @param string unparsed string
23* @param int max image width
24* @return string
25*/
26
27function bbcode($str = '', $max_images = 0)
28{
29	// convert to html entities
30	$str = htmlentities($str);
31
32	$str = auto_link($str);
33	
34	// Max image size eh? Better shrink that pic!
35	if($max_images > 0):
36		$str_max = "style=\"max-width:".$max_images."px; width: [removed]this.width > ".$max_images." ? ".$max_images.": true);\"";
37	endif;
38	
39	$find = array(
40	"'\n'i",
41	"'\[b\](.*?)\[/b\]'is",
42	"'\[i\](.*?)\[/i\]'is",
43	"'\[u\](.*?)\[/u\]'is",
44	"'\[s\](.*?)\[/s\]'is",
45	"'\[img\](.*?)\[/img\]'i",
46	"'\[url\](.*?)\[/url\]'i",
47	"'\[url=(.*?)\](.*?)\[/url\]'i",
48	"'\[link\](.*?)\[/link\]'i",
49	"'\[link=(.*?)\](.*?)\[/link\]'i",
50	"'\[size=small\](.*?)\[/size\]'is",	
51	"'\[size=normal\](.*?)\[/size\]'is",
52	"'\[size=medium\](.*?)\[/size\]'is",
53	"'\[size=big\](.*?)\[/size\]'is",
54	"'\[quote\](.*?)\[/quote\]'is",
55	"'\[code\](.*?)\[/code\]'is"	
56	);
57	
58	$replace = array(
59	'<br />',
60	'<strong>\\1</strong>',
61	'<em>\\1</em>',
62	'<u>\\1</u>',
63	'<s>\\1</s>',
64	'<img src="\\1" alt="" />',
65	'<a href="\\1">\\1</a>',
66	'<a href="\\1">\\2</a>',
67	'<a href="\\1">\\1</a>',
68	'<a href="\\1">\\2</a>',
69	'<span style="font-size:0.9em;">\\1</span>',	
70	'<span style="font-size:1em;">\\1</span>',
71	'<span style="font-size:1.2em;">\\1</span>',
72	'<span style="font-size:1.4em;">\\1</span>',
73	'</p><blockquote>\\1</blockquote><p>',	
74	'<pre><code>\\1</pre></code>'				
75	);
76	
77	
78	$str = preg_replace($find, $replace, $str);
79
80	return '<p>'.$str.'</p>';
81
82}
83
84?>