Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | e684bda | 2012-03-26 13:47:29 +0300 | [diff] [blame] | 8 | * |
Instructor, BCIT | 0e59db6 | 2019-01-01 08:34:36 -0800 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2019, British Columbia Institute of Technology |
Andrey Andreev | e684bda | 2012-03-26 13:47:29 +0300 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Instructor, BCIT | 0e59db6 | 2019-01-01 08:34:36 -0800 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) |
| 33 | * @license https://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.0.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter Text Helpers |
| 42 | * |
| 43 | * @package CodeIgniter |
| 44 | * @subpackage Helpers |
| 45 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 46 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 47 | * @link https://codeigniter.com/user_guide/helpers/text_helper.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | if ( ! function_exists('word_limiter')) |
| 53 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 54 | /** |
| 55 | * Word Limiter |
| 56 | * |
| 57 | * Limits a string to X number of words. |
| 58 | * |
| 59 | * @param string |
| 60 | * @param int |
| 61 | * @param string the end character. Usually an ellipsis |
| 62 | * @return string |
| 63 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 64 | function word_limiter($str, $limit = 100, $end_char = '…') |
| 65 | { |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 66 | if (trim($str) === '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 67 | { |
| 68 | return $str; |
| 69 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 70 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 72 | |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 73 | if (strlen($str) === strlen($matches[0])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | { |
| 75 | $end_char = ''; |
| 76 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 77 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | return rtrim($matches[0]).$end_char; |
| 79 | } |
| 80 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 81 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 82 | // ------------------------------------------------------------------------ |
| 83 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | if ( ! function_exists('character_limiter')) |
| 85 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 86 | /** |
| 87 | * Character Limiter |
| 88 | * |
| 89 | * Limits the string based on the character count. Preserves complete words |
| 90 | * so the character count may not be exactly as specified. |
| 91 | * |
| 92 | * @param string |
| 93 | * @param int |
| 94 | * @param string the end character. Usually an ellipsis |
| 95 | * @return string |
| 96 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 97 | function character_limiter($str, $n = 500, $end_char = '…') |
| 98 | { |
Mohammad Javad Naderi | c6f5ed1 | 2013-08-22 18:33:50 +0430 | [diff] [blame] | 99 | if (mb_strlen($str) < $n) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | { |
| 101 | return $str; |
| 102 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 103 | |
vlakoff | 62a5ee3 | 2012-09-04 23:12:49 +0200 | [diff] [blame] | 104 | // a bit complicated, but faster than preg_replace with \s+ |
Andrey Andreev | 2b26ccf | 2016-12-16 12:02:00 +0200 | [diff] [blame] | 105 | $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\v", "\f"), ' ', $str)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | |
Mohammad Javad Naderi | c6f5ed1 | 2013-08-22 18:33:50 +0430 | [diff] [blame] | 107 | if (mb_strlen($str) <= $n) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | { |
| 109 | return $str; |
| 110 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 112 | $out = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | foreach (explode(' ', trim($str)) as $val) |
| 114 | { |
Derek Jones | 01d6b4f | 2009-02-03 14:51:00 +0000 | [diff] [blame] | 115 | $out .= $val.' '; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 116 | |
Mohammad Javad Naderi | c6f5ed1 | 2013-08-22 18:33:50 +0430 | [diff] [blame] | 117 | if (mb_strlen($out) >= $n) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | { |
Derek Jones | 01d6b4f | 2009-02-03 14:51:00 +0000 | [diff] [blame] | 119 | $out = trim($out); |
Mohammad Javad Naderi | c6f5ed1 | 2013-08-22 18:33:50 +0430 | [diff] [blame] | 120 | return (mb_strlen($out) === mb_strlen($str)) ? $out : $out.$end_char; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 121 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 125 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | // ------------------------------------------------------------------------ |
| 127 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | if ( ! function_exists('ascii_to_entities')) |
| 129 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 130 | /** |
| 131 | * High ASCII to Entities |
| 132 | * |
Andrey Andreev | 7d75346 | 2012-10-27 03:37:40 +0300 | [diff] [blame] | 133 | * Converts high ASCII text and MS Word special characters to character entities |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 134 | * |
Andrey Andreev | 7d75346 | 2012-10-27 03:37:40 +0300 | [diff] [blame] | 135 | * @param string $str |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 136 | * @return string |
| 137 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | function ascii_to_entities($str) |
| 139 | { |
Andrey Andreev | 7d75346 | 2012-10-27 03:37:40 +0300 | [diff] [blame] | 140 | $out = ''; |
Andrey Andreev | f565212 | 2017-01-19 15:17:00 +0200 | [diff] [blame] | 141 | $length = defined('MB_OVERLOAD_STRING') |
| 142 | ? mb_strlen($str, '8bit') - 1 |
| 143 | : strlen($str) - 1; |
| 144 | for ($i = 0, $count = 1, $temp = array(); $i <= $length; $i++) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 145 | { |
| 146 | $ordinal = ord($str[$i]); |
| 147 | |
| 148 | if ($ordinal < 128) |
| 149 | { |
Derek Jones | 1978e12 | 2009-02-03 14:54:43 +0000 | [diff] [blame] | 150 | /* |
| 151 | If the $temp array has a value but we have moved on, then it seems only |
| 152 | fair that we output that entity and restart $temp before continuing. -Paul |
| 153 | */ |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 154 | if (count($temp) === 1) |
Derek Jones | 1978e12 | 2009-02-03 14:54:43 +0000 | [diff] [blame] | 155 | { |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 156 | $out .= '&#'.array_shift($temp).';'; |
Derek Jones | 1978e12 | 2009-02-03 14:54:43 +0000 | [diff] [blame] | 157 | $count = 1; |
| 158 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 159 | |
Derek Jones | 1978e12 | 2009-02-03 14:54:43 +0000 | [diff] [blame] | 160 | $out .= $str[$i]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 161 | } |
| 162 | else |
| 163 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 164 | if (count($temp) === 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 165 | { |
| 166 | $count = ($ordinal < 224) ? 2 : 3; |
| 167 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 169 | $temp[] = $ordinal; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 171 | if (count($temp) === $count) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 172 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 173 | $number = ($count === 3) |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 174 | ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64) |
| 175 | : (($temp[0] % 32) * 64) + ($temp[1] % 64); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 176 | |
| 177 | $out .= '&#'.$number.';'; |
| 178 | $count = 1; |
| 179 | $temp = array(); |
| 180 | } |
Andrey Andreev | 40235e6 | 2014-01-09 14:20:57 +0200 | [diff] [blame] | 181 | // If this is the last iteration, just output whatever we have |
Andrey Andreev | f565212 | 2017-01-19 15:17:00 +0200 | [diff] [blame] | 182 | elseif ($i === $length) |
Andrey Andreev | 40235e6 | 2014-01-09 14:20:57 +0200 | [diff] [blame] | 183 | { |
| 184 | $out .= '&#'.implode(';', $temp).';'; |
| 185 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
| 189 | return $out; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | } |
| 191 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 192 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | // ------------------------------------------------------------------------ |
| 194 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | if ( ! function_exists('entities_to_ascii')) |
| 196 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 197 | /** |
| 198 | * Entities to ASCII |
| 199 | * |
| 200 | * Converts character entities back to ASCII |
| 201 | * |
| 202 | * @param string |
| 203 | * @param bool |
| 204 | * @return string |
| 205 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 206 | function entities_to_ascii($str, $all = TRUE) |
| 207 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 208 | if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) |
| 209 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 210 | for ($i = 0, $s = count($matches[0]); $i < $s; $i++) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 211 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 212 | $digits = $matches[1][$i]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | $out = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 215 | if ($digits < 128) |
| 216 | { |
| 217 | $out .= chr($digits); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 219 | } |
| 220 | elseif ($digits < 2048) |
| 221 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 222 | $out .= chr(192 + (($digits - ($digits % 64)) / 64)).chr(128 + ($digits % 64)); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 223 | } |
| 224 | else |
| 225 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 226 | $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)) |
| 227 | .chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)) |
| 228 | .chr(128 + ($digits % 64)); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 229 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 230 | |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 231 | $str = str_replace($matches[0][$i], $out, $str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 232 | } |
| 233 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 235 | if ($all) |
| 236 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 237 | return str_replace( |
| 238 | array('&', '<', '>', '"', ''', '-'), |
| 239 | array('&', '<', '>', '"', "'", '-'), |
| 240 | $str |
| 241 | ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | return $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 247 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 248 | // ------------------------------------------------------------------------ |
| 249 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 250 | if ( ! function_exists('word_censor')) |
| 251 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 252 | /** |
| 253 | * Word Censoring Function |
| 254 | * |
| 255 | * Supply a string and an array of disallowed words and any |
| 256 | * matched words will be converted to #### or to the replacement |
| 257 | * word you've submitted. |
| 258 | * |
| 259 | * @param string the text string |
Calvin Tam | 55bc505 | 2015-07-24 02:27:24 -0700 | [diff] [blame] | 260 | * @param string the array of censored words |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 261 | * @param string the optional replacement value |
| 262 | * @return string |
| 263 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 264 | function word_censor($str, $censored, $replacement = '') |
| 265 | { |
| 266 | if ( ! is_array($censored)) |
| 267 | { |
| 268 | return $str; |
| 269 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 270 | |
| 271 | $str = ' '.$str.' '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 272 | |
Derek Jones | f1b721a | 2009-01-21 17:52:13 +0000 | [diff] [blame] | 273 | // \w, \b and a few others do not match on a unicode character |
| 274 | // set for performance reasons. As a result words like über |
| 275 | // will not match on a word boundary. Instead, we'll assume that |
Derek Jones | daf9c01 | 2010-03-05 10:29:30 -0600 | [diff] [blame] | 276 | // a bad word will be bookeneded by any of these characters. |
Derek Jones | f1b721a | 2009-01-21 17:52:13 +0000 | [diff] [blame] | 277 | $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; |
| 278 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | foreach ($censored as $badword) |
| 280 | { |
Andrey Andreev | 6af9dd6 | 2016-01-29 13:29:57 +0200 | [diff] [blame] | 281 | $badword = str_replace('\*', '\w*?', preg_quote($badword, '/')); |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 282 | if ($replacement !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | { |
Andrey Andreev | 6af9dd6 | 2016-01-29 13:29:57 +0200 | [diff] [blame] | 284 | $str = preg_replace( |
| 285 | "/({$delim})(".$badword.")({$delim})/i", |
| 286 | "\\1{$replacement}\\3", |
| 287 | $str |
| 288 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 289 | } |
Andrey Andreev | 6af9dd6 | 2016-01-29 13:29:57 +0200 | [diff] [blame] | 290 | elseif (preg_match_all("/{$delim}(".$badword."){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 291 | { |
Andrey Andreev | 6af9dd6 | 2016-01-29 13:29:57 +0200 | [diff] [blame] | 292 | $matches = $matches[1]; |
Andrey Andreev | 9aab22e | 2016-01-29 16:19:46 +0200 | [diff] [blame] | 293 | for ($i = count($matches) - 1; $i >= 0; $i--) |
Andrey Andreev | 6af9dd6 | 2016-01-29 13:29:57 +0200 | [diff] [blame] | 294 | { |
| 295 | $length = strlen($matches[$i][0]); |
| 296 | $str = substr_replace( |
| 297 | $str, |
| 298 | str_repeat('#', $length), |
| 299 | $matches[$i][1], |
| 300 | $length |
| 301 | ); |
| 302 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
Derek Jones | f1b721a | 2009-01-21 17:52:13 +0000 | [diff] [blame] | 305 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 306 | return trim($str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 309 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | // ------------------------------------------------------------------------ |
| 311 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 312 | if ( ! function_exists('highlight_code')) |
| 313 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 314 | /** |
| 315 | * Code Highlighter |
| 316 | * |
| 317 | * Colorizes code strings |
| 318 | * |
| 319 | * @param string the text string |
| 320 | * @return string |
| 321 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | function highlight_code($str) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 323 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 324 | /* The highlight string function encodes and highlights |
| 325 | * brackets so we need them to start raw. |
| 326 | * |
| 327 | * Also replace any existing PHP tags to temporary markers |
| 328 | * so they don't accidentally break the string out of PHP, |
| 329 | * and thus, thwart the highlighting. |
| 330 | */ |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 331 | $str = str_replace( |
| 332 | array('<', '>', '<?', '?>', '<%', '%>', '\\', '</script>'), |
| 333 | array('<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), |
| 334 | $str |
| 335 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 336 | |
| 337 | // The highlight_string function requires that the text be surrounded |
| 338 | // by PHP tags, which we will remove later |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 339 | $str = highlight_string('<?php '.$str.' ?>', TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 340 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | // Remove our artificially added PHP, and the syntax highlighting that came with it |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 342 | $str = preg_replace( |
| 343 | array( |
| 344 | '/<span style="color: #([A-Z0-9]+)"><\?php( | )/i', |
| 345 | '/(<span style="color: #[A-Z0-9]+">.*?)\?><\/span>\n<\/span>\n<\/code>/is', |
| 346 | '/<span style="color: #[A-Z0-9]+"\><\/span>/i' |
| 347 | ), |
| 348 | array( |
| 349 | '<span style="color: #$1">', |
| 350 | "$1</span>\n</span>\n</code>", |
| 351 | '' |
| 352 | ), |
| 353 | $str |
| 354 | ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 355 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | // Replace our markers back to PHP tags. |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 357 | return str_replace( |
| 358 | array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), |
| 359 | array('<?', '?>', '<%', '%>', '\\', '</script>'), |
| 360 | $str |
| 361 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 364 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | // ------------------------------------------------------------------------ |
| 366 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | if ( ! function_exists('highlight_phrase')) |
| 368 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 369 | /** |
| 370 | * Phrase Highlighter |
| 371 | * |
| 372 | * Highlights a phrase within a text string |
| 373 | * |
Andrey Andreev | ac023e1 | 2014-01-07 16:13:03 +0200 | [diff] [blame] | 374 | * @param string $str the text string |
| 375 | * @param string $phrase the phrase you'd like to highlight |
| 376 | * @param string $tag_open the openging tag to precede the phrase with |
| 377 | * @param string $tag_close the closing tag to end the phrase with |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 378 | * @return string |
| 379 | */ |
Andrey Andreev | ac023e1 | 2014-01-07 16:13:03 +0200 | [diff] [blame] | 380 | function highlight_phrase($str, $phrase, $tag_open = '<mark>', $tag_close = '</mark>') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 381 | { |
Andrey Andreev | ac023e1 | 2014-01-07 16:13:03 +0200 | [diff] [blame] | 382 | return ($str !== '' && $phrase !== '') |
Ivan Tcholakov | 8bc73eb | 2014-03-17 05:18:45 +0200 | [diff] [blame] | 383 | ? preg_replace('/('.preg_quote($phrase, '/').')/i'.(UTF8_ENABLED ? 'u' : ''), $tag_open.'\\1'.$tag_close, $str) |
Andrey Andreev | ac023e1 | 2014-01-07 16:13:03 +0200 | [diff] [blame] | 384 | : $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | } |
| 386 | } |
Derek Jones | daf9c01 | 2010-03-05 10:29:30 -0600 | [diff] [blame] | 387 | |
| 388 | // ------------------------------------------------------------------------ |
| 389 | |
Derek Jones | daf9c01 | 2010-03-05 10:29:30 -0600 | [diff] [blame] | 390 | if ( ! function_exists('convert_accented_characters')) |
| 391 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 392 | /** |
| 393 | * Convert Accented Foreign Characters to ASCII |
| 394 | * |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 395 | * @param string $str Input string |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 396 | * @return string |
| 397 | */ |
Eric Barnes | 5e04480 | 2011-01-11 16:10:26 -0500 | [diff] [blame] | 398 | function convert_accented_characters($str) |
Derek Jones | daf9c01 | 2010-03-05 10:29:30 -0600 | [diff] [blame] | 399 | { |
vlakoff | f5b4f6a | 2013-02-28 22:17:51 +0100 | [diff] [blame] | 400 | static $array_from, $array_to; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 401 | |
vlakoff | f5b4f6a | 2013-02-28 22:17:51 +0100 | [diff] [blame] | 402 | if ( ! is_array($array_from)) |
Derek Jones | daf9c01 | 2010-03-05 10:29:30 -0600 | [diff] [blame] | 403 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 404 | if (file_exists(APPPATH.'config/foreign_chars.php')) |
Andrey Andreev | 0f2ec5b | 2012-01-16 14:02:24 +0200 | [diff] [blame] | 405 | { |
| 406 | include(APPPATH.'config/foreign_chars.php'); |
| 407 | } |
| 408 | |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 409 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) |
Andrey Andreev | 0f2ec5b | 2012-01-16 14:02:24 +0200 | [diff] [blame] | 410 | { |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 411 | include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); |
| 412 | } |
| 413 | |
| 414 | if (empty($foreign_characters) OR ! is_array($foreign_characters)) |
| 415 | { |
vlakoff | f5b4f6a | 2013-02-28 22:17:51 +0100 | [diff] [blame] | 416 | $array_from = array(); |
| 417 | $array_to = array(); |
| 418 | |
Andrey Andreev | 0f2ec5b | 2012-01-16 14:02:24 +0200 | [diff] [blame] | 419 | return $str; |
| 420 | } |
Andrey Andreev | 0687911 | 2013-01-29 15:05:02 +0200 | [diff] [blame] | 421 | |
vlakoff | f5b4f6a | 2013-02-28 22:17:51 +0100 | [diff] [blame] | 422 | $array_from = array_keys($foreign_characters); |
| 423 | $array_to = array_values($foreign_characters); |
Derek Jones | daf9c01 | 2010-03-05 10:29:30 -0600 | [diff] [blame] | 424 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 425 | |
vlakoff | f5b4f6a | 2013-02-28 22:17:51 +0100 | [diff] [blame] | 426 | return preg_replace($array_from, $array_to, $str); |
Derek Jones | daf9c01 | 2010-03-05 10:29:30 -0600 | [diff] [blame] | 427 | } |
| 428 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 429 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | // ------------------------------------------------------------------------ |
| 431 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 432 | if ( ! function_exists('word_wrap')) |
| 433 | { |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 434 | /** |
| 435 | * Word Wrap |
| 436 | * |
| 437 | * Wraps text at the specified character. Maintains the integrity of words. |
| 438 | * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor |
| 439 | * will URLs. |
| 440 | * |
| 441 | * @param string $str the text string |
| 442 | * @param int $charlim = 76 the number of characters to wrap at |
| 443 | * @return string |
| 444 | */ |
Andrey Andreev | fc44355 | 2012-01-07 02:14:55 +0200 | [diff] [blame] | 445 | function word_wrap($str, $charlim = 76) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 446 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 447 | // Set the character limit |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 448 | is_numeric($charlim) OR $charlim = 76; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 449 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 450 | // Reduce multiple spaces |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 451 | $str = preg_replace('| +|', ' ', $str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 452 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 453 | // Standardize newlines |
| 454 | if (strpos($str, "\r") !== FALSE) |
| 455 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 456 | $str = str_replace(array("\r\n", "\r"), "\n", $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 457 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 458 | |
| 459 | // If the current word is surrounded by {unwrap} tags we'll |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | // strip the entire chunk and replace it with a marker. |
| 461 | $unwrap = array(); |
vlakoff | 0f7eba2 | 2014-05-20 10:32:44 +0200 | [diff] [blame] | 462 | if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 464 | for ($i = 0, $c = count($matches[0]); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 465 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 466 | $unwrap[] = $matches[1][$i]; |
vlakoff | 0f7eba2 | 2014-05-20 10:32:44 +0200 | [diff] [blame] | 467 | $str = str_replace($matches[0][$i], '{{unwrapped'.$i.'}}', $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | } |
| 469 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 470 | |
| 471 | // Use PHP's native function to do the initial wordwrap. |
| 472 | // We set the cut flag to FALSE so that any individual words that are |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 473 | // too long get left alone. In the next step we'll deal with them. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 474 | $str = wordwrap($str, $charlim, "\n", FALSE); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 475 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 476 | // Split the string into individual lines of text and cycle through them |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 477 | $output = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 478 | foreach (explode("\n", $str) as $line) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | { |
| 480 | // Is the line within the allowed character count? |
| 481 | // If so we'll join it to the output and continue |
Andrey Andreev | 6ce4746 | 2014-02-13 03:28:00 +0200 | [diff] [blame] | 482 | if (mb_strlen($line) <= $charlim) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 483 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 484 | $output .= $line."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 485 | continue; |
| 486 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 487 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | $temp = ''; |
Andrey Andreev | 6ce4746 | 2014-02-13 03:28:00 +0200 | [diff] [blame] | 489 | while (mb_strlen($line) > $charlim) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | { |
| 491 | // If the over-length word is a URL we won't wrap it |
vlakoff | 2a8560c | 2014-05-20 10:32:35 +0200 | [diff] [blame] | 492 | if (preg_match('!\[url.+\]|://|www\.!', $line)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 493 | { |
| 494 | break; |
| 495 | } |
| 496 | |
| 497 | // Trim the word down |
Andrey Andreev | 6ce4746 | 2014-02-13 03:28:00 +0200 | [diff] [blame] | 498 | $temp .= mb_substr($line, 0, $charlim - 1); |
| 499 | $line = mb_substr($line, $charlim - 1); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 500 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 501 | |
| 502 | // If $temp contains data it means we had to split up an over-length |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 503 | // word into smaller chunks so we'll add it back to our current line |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 504 | if ($temp !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 505 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 506 | $output .= $temp."\n".$line."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 507 | } |
| 508 | else |
| 509 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 510 | $output .= $line."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 511 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | // Put our markers back |
| 515 | if (count($unwrap) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 516 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | foreach ($unwrap as $key => $val) |
| 518 | { |
Andrey Andreev | 4921fed | 2012-01-07 01:28:07 +0200 | [diff] [blame] | 519 | $output = str_replace('{{unwrapped'.$key.'}}', $val, $output); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
vlakoff | 0f7eba2 | 2014-05-20 10:32:44 +0200 | [diff] [blame] | 523 | return $output; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 526 | |
Greg Aker | cbe3247 | 2010-08-05 14:09:20 -0500 | [diff] [blame] | 527 | // ------------------------------------------------------------------------ |
| 528 | |
| 529 | if ( ! function_exists('ellipsize')) |
| 530 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 531 | /** |
| 532 | * Ellipsize String |
| 533 | * |
| 534 | * This function will strip tags from a string, split it at its max_length and ellipsize |
| 535 | * |
| 536 | * @param string string to ellipsize |
| 537 | * @param int max length of string |
| 538 | * @param mixed int (1|0) or float, .5, .2, etc for position to split |
| 539 | * @param string ellipsis ; Default '...' |
| 540 | * @return string ellipsized string |
| 541 | */ |
Greg Aker | cbe3247 | 2010-08-05 14:09:20 -0500 | [diff] [blame] | 542 | function ellipsize($str, $max_length, $position = 1, $ellipsis = '…') |
| 543 | { |
| 544 | // Strip tags |
| 545 | $str = trim(strip_tags($str)); |
| 546 | |
| 547 | // Is the string long enough to ellipsize? |
Andrey Andreev | 6ce4746 | 2014-02-13 03:28:00 +0200 | [diff] [blame] | 548 | if (mb_strlen($str) <= $max_length) |
Greg Aker | cbe3247 | 2010-08-05 14:09:20 -0500 | [diff] [blame] | 549 | { |
| 550 | return $str; |
| 551 | } |
| 552 | |
Andrey Andreev | 6ce4746 | 2014-02-13 03:28:00 +0200 | [diff] [blame] | 553 | $beg = mb_substr($str, 0, floor($max_length * $position)); |
Greg Aker | cbe3247 | 2010-08-05 14:09:20 -0500 | [diff] [blame] | 554 | $position = ($position > 1) ? 1 : $position; |
| 555 | |
| 556 | if ($position === 1) |
| 557 | { |
Andrey Andreev | 6ce4746 | 2014-02-13 03:28:00 +0200 | [diff] [blame] | 558 | $end = mb_substr($str, 0, -($max_length - mb_strlen($beg))); |
Greg Aker | cbe3247 | 2010-08-05 14:09:20 -0500 | [diff] [blame] | 559 | } |
| 560 | else |
| 561 | { |
Andrey Andreev | 6ce4746 | 2014-02-13 03:28:00 +0200 | [diff] [blame] | 562 | $end = mb_substr($str, -($max_length - mb_strlen($beg))); |
Greg Aker | cbe3247 | 2010-08-05 14:09:20 -0500 | [diff] [blame] | 563 | } |
| 564 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 565 | return $beg.$ellipsis.$end; |
Greg Aker | cbe3247 | 2010-08-05 14:09:20 -0500 | [diff] [blame] | 566 | } |
| 567 | } |