blob: 2c5c588bc228db80e6ba2a61334811899995eebf [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allardd2df9bc2007-04-15 17:41:17 +00002/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter Typography Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/typography_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Convert newlines to HTML line breaks except within PRE tags
32 *
33 * @access public
34 * @param string
35 * @return string
36 */
Derek Jones0b59f272008-05-13 04:22:33 +000037if ( ! function_exists('nl2br_except_pre'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000038{
Derek Jones269b9422008-01-28 21:00:20 +000039 function nl2br_except_pre($str)
Derek Allardd2df9bc2007-04-15 17:41:17 +000040 {
Derek Jones269b9422008-01-28 21:00:20 +000041 $ex = explode("pre>",$str);
42 $ct = count($ex);
Derek Allardd2df9bc2007-04-15 17:41:17 +000043
Derek Jones269b9422008-01-28 21:00:20 +000044 $newstr = "";
45 for ($i = 0; $i < $ct; $i++)
46 {
47 if (($i % 2) == 0)
48 {
49 $newstr .= nl2br($ex[$i]);
50 }
51 else
52 {
53 $newstr .= $ex[$i];
54 }
55
56 if ($ct - 1 != $i)
57 $newstr .= "pre>";
58 }
59
60 return $newstr;
61 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000062}
63
64// ------------------------------------------------------------------------
65
66/**
67 * Auto Typography Wrapper Function
68 *
69 *
70 * @access public
71 * @param string
Rick Ellis55741102008-09-11 20:11:59 +000072 * @param bool whether to allow javascript event handlers
73 * @param bool whether to reduce multiple instances of double newlines to two
Derek Allardd2df9bc2007-04-15 17:41:17 +000074 * @return string
75 */
Derek Jones0b59f272008-05-13 04:22:33 +000076if ( ! function_exists('auto_typography'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000077{
Rick Ellis55741102008-09-11 20:11:59 +000078 function auto_typography($str, $allow_event_handlers = FALSE, $reduce_empty_lines = FALSE)
Derek Jones269b9422008-01-28 21:00:20 +000079 {
Rick Ellis037a5bc2008-09-10 22:58:21 +000080 $CI =& get_instance();
81
82 $CI->load->library('typography');
83
Rick Ellis55741102008-09-11 20:11:59 +000084 $CI->typography->allow_js_event_handlers($allow_event_handlers);
85 $CI->typography->reduce_empty_lines($reduce_empty_lines);
86
Rick Ellis36f375f2008-09-12 06:21:14 +000087 return $CI->typography->auto_typography($str);
Derek Jones269b9422008-01-28 21:00:20 +000088 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000089}
Derek Jones0b59f272008-05-13 04:22:33 +000090
91/* End of file typography_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +000092/* Location: ./system/helpers/typography_helper.php */