From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Typography.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Typography.php') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index f061311b0..af6ca2bf2 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -21,7 +33,7 @@ * * @access private * @category Helpers - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/typography.html */ class CI_Typography { -- cgit v1.2.3-24-g4f1b From 7dc8c442be1122f4fa71f7f53efe4d837b555f2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Dec 2011 16:52:37 +0200 Subject: Improve the Typography library --- system/libraries/Typography.php | 99 +++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 58 deletions(-) (limited to 'system/libraries/Typography.php') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index af6ca2bf2..0f48f32ad 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -1,13 +1,13 @@ - tags - var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul'; + public $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul'; // Elements that should not have

and
tags within them. - var $skip_elements = 'p|pre|ol|ul|dl|object|table|h\d'; + public $skip_elements = 'p|pre|ol|ul|dl|object|table|h\d'; // Tags we want the parser to completely ignore when splitting the string. - var $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var'; + public $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var'; // array of block level elements that require inner content to be within another block level element - var $inner_block_required = array('blockquote'); + public $inner_block_required = array('blockquote'); // the last block element parsed - var $last_block_element = ''; + public $last_block_element = ''; // whether or not to protect quotes within { curly braces } - var $protect_braced_quotes = FALSE; + public $protect_braced_quotes = FALSE; /** * Auto Typography @@ -72,7 +72,7 @@ class CI_Typography { * @param bool whether to reduce more then two consecutive newlines to two * @return string */ - function auto_typography($str, $reduce_linebreaks = FALSE) + public function auto_typography($str, $reduce_linebreaks = FALSE) { if ($str == '') { @@ -127,35 +127,32 @@ class CI_Typography { // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} $str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str); - // Split the string at every tag. This expression creates an array with this prototype: - // - // [array] - // { - // [0] = - // [1] = Content... - // [2] = - // Etc... - // } + /* Split the string at every tag. This expression creates an array with this prototype: + * + * [array] + * { + * [0] = + * [1] = Content... + * [2] = + * Etc... + * } + */ $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text $str = ''; $process = TRUE; $paragraph = FALSE; - $current_chunk = 0; - $total_chunks = count($chunks); - foreach ($chunks as $chunk) + for ($i = 1, $c = count($chunks); $i <= $c; $i++) { - $current_chunk++; - // Are we dealing with a tag? If so, we'll skip the processing for this cycle. // Well also set the "process" flag which allows us to skip

 tags and a few other things.
-			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
+			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunks[$i], $match))
 			{
 				if (preg_match("#".$this->skip_elements."#", $match[2]))
 				{
-					$process =  ($match[1] == '/') ? TRUE : FALSE;
+					$process = ($match[1] === '/');
 				}
 
 				if ($match[1] == '')
@@ -163,24 +160,24 @@ class CI_Typography {
 					$this->last_block_element = $match[2];
 				}
 
-				$str .= $chunk;
+				$str .= $chunks[$i];
 				continue;
 			}
 
-			if ($process == FALSE)
+			if ($process === FALSE)
 			{
-				$str .= $chunk;
+				$str .= $chunks[$i];
 				continue;
 			}
 
 			//  Force a newline to make sure end tags get processed by _format_newlines()
-			if ($current_chunk == $total_chunks)
+			if ($i === $c)
 			{
-				$chunk .= "\n";
+				$chunks[$i] .= "\n";
 			}
 
 			//  Convert Newlines into 

and
tags - $str .= $this->_format_newlines($chunk); + $str .= $this->_format_newlines($chunks[$i]); } // No opening block level tag? Add it if needed. @@ -265,7 +262,7 @@ class CI_Typography { * @param string * @return string */ - function format_characters($str) + public function format_characters($str) { static $table; @@ -325,18 +322,13 @@ class CI_Typography { * * Converts newline characters into either

tags or
* - * @access public + * @access private * @param string * @return string */ - function _format_newlines($str) + private function _format_newlines($str) { - if ($str == '') - { - return $str; - } - - if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) + if ($str == '' OR (strpos($str, "\n") === FALSE AND ! in_array($this->last_block_element, $this->inner_block_required))) { return $str; } @@ -373,11 +365,11 @@ class CI_Typography { * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} * likewise double spaces are converted to {@NBS} to prevent entity conversion * - * @access public + * @access private * @param array * @return string */ - function _protect_characters($match) + private function _protect_characters($match) { return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); } @@ -391,25 +383,16 @@ class CI_Typography { * @param string * @return string */ - function nl2br_except_pre($str) + public function nl2br_except_pre($str) { - $ex = explode("pre>",$str); - $ct = count($ex); - - $newstr = ""; - for ($i = 0; $i < $ct; $i++) + $newstr = ''; + for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) { - if (($i % 2) == 0) + $newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i]; + if ($ct - 1 !== $i) { - $newstr .= nl2br($ex[$i]); + $newstr .= 'pre>'; } - else - { - $newstr .= $ex[$i]; - } - - if ($ct - 1 != $i) - $newstr .= "pre>"; } return $newstr; -- cgit v1.2.3-24-g4f1b From 43aa8e4f66e0a109cfb80a8ea424edb04b9feecc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Dec 2011 16:53:18 +0200 Subject: Replace private with protected, so the class can be easily extended --- system/libraries/Typography.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Typography.php') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 0f48f32ad..651ba7bff 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -31,7 +31,7 @@ * Typography Class * * - * @access private + * @access protected * @category Helpers * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/typography.html @@ -322,11 +322,11 @@ class CI_Typography { * * Converts newline characters into either

tags or
* - * @access private + * @access protected * @param string * @return string */ - private function _format_newlines($str) + protected function _format_newlines($str) { if ($str == '' OR (strpos($str, "\n") === FALSE AND ! in_array($this->last_block_element, $this->inner_block_required))) { @@ -365,11 +365,11 @@ class CI_Typography { * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} * likewise double spaces are converted to {@NBS} to prevent entity conversion * - * @access private + * @access protected * @param array * @return string */ - private function _protect_characters($match) + protected function _protect_characters($match) { return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); } -- cgit v1.2.3-24-g4f1b From 64b013611f65006197fdf465186ca36adf12847d Mon Sep 17 00:00:00 2001 From: Ronald Beilsma Date: Wed, 28 Dec 2011 12:59:45 +0100 Subject: fixed bug in typography library array index starts at 0, not 1 --- system/libraries/Typography.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Typography.php') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 651ba7bff..ac9486a6b 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -144,7 +144,7 @@ class CI_Typography { $process = TRUE; $paragraph = FALSE; - for ($i = 1, $c = count($chunks); $i <= $c; $i++) + for ($i = 0, $c = count($chunks) - 1; $i <= $c; $i++) { // Are we dealing with a tag? If so, we'll skip the processing for this cycle. // Well also set the "process" flag which allows us to skip

 tags and a few other things.
-- 
cgit v1.2.3-24-g4f1b


From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001
From: Greg Aker 
Date: Sun, 1 Jan 2012 18:46:41 -0600
Subject: Updating copyright date to 2012

---
 system/libraries/Typography.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'system/libraries/Typography.php')

diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index 651ba7bff..76f0d4fc5 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.php
@@ -18,7 +18,7 @@
  *
  * @package		CodeIgniter
  * @author		EllisLab Dev Team
- * @copyright	Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright	Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
  * @license		http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
  * @link		http://codeigniter.com
  * @since		Version 1.0
-- 
cgit v1.2.3-24-g4f1b