GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (423)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

system/helpers/text_helper.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 64 and the first side effect is on line 38.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
9
 * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
10
 *
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:
17
 *
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
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
32
 * @copyright	Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	http://codeigniter.com
35
 * @since	Version 1.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
40
/**
41
 * CodeIgniter Text Helpers
42
 *
43
 * @package		CodeIgniter
44
 * @subpackage	Helpers
45
 * @category	Helpers
46
 * @author		EllisLab Dev Team
47
 * @link		http://codeigniter.com/user_guide/helpers/text_helper.html
48
 */
49
50
// ------------------------------------------------------------------------
51
52
if ( ! function_exists('word_limiter'))
53
{
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
	 */
64
	function word_limiter($str, $limit = 100, $end_char = '&#8230;')
65
	{
66
		if (trim($str) === '')
67
		{
68
			return $str;
69
		}
70
71
		preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);
72
73
		if (strlen($str) === strlen($matches[0]))
74
		{
75
			$end_char = '';
76
		}
77
78
		return rtrim($matches[0]).$end_char;
79
	}
80
}
81
82
// ------------------------------------------------------------------------
83
84
if ( ! function_exists('character_limiter'))
85
{
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
	 */
97
	function character_limiter($str, $n = 500, $end_char = '&#8230;')
98
	{
99
		if (mb_strlen($str) < $n)
100
		{
101
			return $str;
102
		}
103
104
		// a bit complicated, but faster than preg_replace with \s+
105
		$str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str));
106
107
		if (mb_strlen($str) <= $n)
108
		{
109
			return $str;
110
		}
111
112
		$out = '';
113
		foreach (explode(' ', trim($str)) as $val)
114
		{
115
			$out .= $val.' ';
116
117
			if (mb_strlen($out) >= $n)
118
			{
119
				$out = trim($out);
120
				return (mb_strlen($out) === mb_strlen($str)) ? $out : $out.$end_char;
121
			}
122
		}
123
	}
124
}
125
126
// ------------------------------------------------------------------------
127
128
if ( ! function_exists('ascii_to_entities'))
129
{
130
	/**
131
	 * High ASCII to Entities
132
	 *
133
	 * Converts high ASCII text and MS Word special characters to character entities
134
	 *
135
	 * @param	string	$str
136
	 * @return	string
137
	 */
138
	function ascii_to_entities($str)
139
	{
140
		$out = '';
141
		for ($i = 0, $s = strlen($str) - 1, $count = 1, $temp = array(); $i <= $s; $i++)
142
		{
143
			$ordinal = ord($str[$i]);
144
145
			if ($ordinal < 128)
146
			{
147
				/*
148
					If the $temp array has a value but we have moved on, then it seems only
149
					fair that we output that entity and restart $temp before continuing. -Paul
150
				*/
151
				if (count($temp) === 1)
152
				{
153
					$out .= '&#'.array_shift($temp).';';
154
					$count = 1;
155
				}
156
157
				$out .= $str[$i];
158
			}
159
			else
160
			{
161
				if (count($temp) === 0)
162
				{
163
					$count = ($ordinal < 224) ? 2 : 3;
164
				}
165
166
				$temp[] = $ordinal;
167
168
				if (count($temp) === $count)
169
				{
170
					$number = ($count === 3)
171
						? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
172
						: (($temp[0] % 32) * 64) + ($temp[1] % 64);
173
174
					$out .= '&#'.$number.';';
175
					$count = 1;
176
					$temp = array();
177
				}
178
				// If this is the last iteration, just output whatever we have
179
				elseif ($i === $s)
180
				{
181
					$out .= '&#'.implode(';', $temp).';';
182
				}
183
			}
184
		}
185
186
		return $out;
187
	}
188
}
189
190
// ------------------------------------------------------------------------
191
192
if ( ! function_exists('entities_to_ascii'))
193
{
194
	/**
195
	 * Entities to ASCII
196
	 *
197
	 * Converts character entities back to ASCII
198
	 *
199
	 * @param	string
200
	 * @param	bool
201
	 * @return	string
202
	 */
203
	function entities_to_ascii($str, $all = TRUE)
204
	{
205
		if (preg_match_all('/\&#(\d+)\;/', $str, $matches))
206
		{
207
			for ($i = 0, $s = count($matches[0]); $i < $s; $i++)
208
			{
209
				$digits = $matches[1][$i];
210
				$out = '';
211
212
				if ($digits < 128)
213
				{
214
					$out .= chr($digits);
215
216
				}
217
				elseif ($digits < 2048)
218
				{
219
					$out .= chr(192 + (($digits - ($digits % 64)) / 64)).chr(128 + ($digits % 64));
220
				}
221
				else
222
				{
223
					$out .= chr(224 + (($digits - ($digits % 4096)) / 4096))
224
						.chr(128 + ((($digits % 4096) - ($digits % 64)) / 64))
225
						.chr(128 + ($digits % 64));
226
				}
227
228
				$str = str_replace($matches[0][$i], $out, $str);
229
			}
230
		}
231
232
		if ($all)
233
		{
234
			return str_replace(
235
				array('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'),
236
				array('&', '<', '>', '"', "'", '-'),
237
				$str
238
			);
239
		}
240
241
		return $str;
242
	}
243
}
244
245
// ------------------------------------------------------------------------
246
247
if ( ! function_exists('word_censor'))
248
{
249
	/**
250
	 * Word Censoring Function
251
	 *
252
	 * Supply a string and an array of disallowed words and any
253
	 * matched words will be converted to #### or to the replacement
254
	 * word you've submitted.
255
	 *
256
	 * @param	string	the text string
257
	 * @param	string	the array of censored words
258
	 * @param	string	the optional replacement value
259
	 * @return	string
260
	 */
261
	function word_censor($str, $censored, $replacement = '')
262
	{
263
		if ( ! is_array($censored))
264
		{
265
			return $str;
266
		}
267
268
		$str = ' '.$str.' ';
269
270
		// \w, \b and a few others do not match on a unicode character
271
		// set for performance reasons. As a result words like über
272
		// will not match on a word boundary. Instead, we'll assume that
273
		// a bad word will be bookeneded by any of these characters.
274
		$delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
275
276
		foreach ($censored as $badword)
277
		{
278
			if ($replacement !== '')
279
			{
280
				$str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str);
281
			}
282
			else
283
			{
284
				$str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'", $str);
285
			}
286
		}
287
288
		return trim($str);
289
	}
290
}
291
292
// ------------------------------------------------------------------------
293
294
if ( ! function_exists('highlight_code'))
295
{
296
	/**
297
	 * Code Highlighter
298
	 *
299
	 * Colorizes code strings
300
	 *
301
	 * @param	string	the text string
302
	 * @return	string
303
	 */
304
	function highlight_code($str)
305
	{
306
		/* The highlight string function encodes and highlights
307
		 * brackets so we need them to start raw.
308
		 *
309
		 * Also replace any existing PHP tags to temporary markers
310
		 * so they don't accidentally break the string out of PHP,
311
		 * and thus, thwart the highlighting.
312
		 */
313
		$str = str_replace(
314
			array('&lt;', '&gt;', '<?', '?>', '<%', '%>', '\\', '</script>'),
315
			array('<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
316
			$str
317
		);
318
319
		// The highlight_string function requires that the text be surrounded
320
		// by PHP tags, which we will remove later
321
		$str = highlight_string('<?php '.$str.' ?>', TRUE);
322
323
		// Remove our artificially added PHP, and the syntax highlighting that came with it
324
		$str = preg_replace(
325
			array(
326
				'/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i',
327
				'/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is',
328
				'/<span style="color: #[A-Z0-9]+"\><\/span>/i'
329
			),
330
			array(
331
				'<span style="color: #$1">',
332
				"$1</span>\n</span>\n</code>",
333
				''
334
			),
335
			$str
336
		);
337
338
		// Replace our markers back to PHP tags.
339
		return str_replace(
340
			array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
341
			array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'),
342
			$str
343
		);
344
	}
345
}
346
347
// ------------------------------------------------------------------------
348
349
if ( ! function_exists('highlight_phrase'))
350
{
351
	/**
352
	 * Phrase Highlighter
353
	 *
354
	 * Highlights a phrase within a text string
355
	 *
356
	 * @param	string	$str		the text string
357
	 * @param	string	$phrase		the phrase you'd like to highlight
358
	 * @param	string	$tag_open	the openging tag to precede the phrase with
359
	 * @param	string	$tag_close	the closing tag to end the phrase with
360
	 * @return	string
361
	 */
362
	function highlight_phrase($str, $phrase, $tag_open = '<mark>', $tag_close = '</mark>')
363
	{
364
		return ($str !== '' && $phrase !== '')
365
			? preg_replace('/('.preg_quote($phrase, '/').')/i'.(UTF8_ENABLED ? 'u' : ''), $tag_open.'\\1'.$tag_close, $str)
366
			: $str;
367
	}
368
}
369
370
// ------------------------------------------------------------------------
371
372
if ( ! function_exists('convert_accented_characters'))
373
{
374
	/**
375
	 * Convert Accented Foreign Characters to ASCII
376
	 *
377
	 * @param	string	$str	Input string
378
	 * @return	string
379
	 */
380
	function convert_accented_characters($str)
381
	{
382
		static $array_from, $array_to;
383
384
		if ( ! is_array($array_from))
385
		{
386
			if (file_exists(APPPATH.'config/foreign_chars.php'))
387
			{
388
				include(APPPATH.'config/foreign_chars.php');
389
			}
390
391
			if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
392
			{
393
				include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
394
			}
395
396
			if (empty($foreign_characters) OR ! is_array($foreign_characters))
397
			{
398
				$array_from = array();
399
				$array_to = array();
400
401
				return $str;
402
			}
403
404
			$array_from = array_keys($foreign_characters);
405
			$array_to = array_values($foreign_characters);
406
		}
407
408
		return preg_replace($array_from, $array_to, $str);
409
	}
410
}
411
412
// ------------------------------------------------------------------------
413
414
if ( ! function_exists('word_wrap'))
415
{
416
	/**
417
	 * Word Wrap
418
	 *
419
	 * Wraps text at the specified character. Maintains the integrity of words.
420
	 * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
421
	 * will URLs.
422
	 *
423
	 * @param	string	$str		the text string
424
	 * @param	int	$charlim = 76	the number of characters to wrap at
425
	 * @return	string
426
	 */
427
	function word_wrap($str, $charlim = 76)
428
	{
429
		// Set the character limit
430
		is_numeric($charlim) OR $charlim = 76;
431
432
		// Reduce multiple spaces
433
		$str = preg_replace('| +|', ' ', $str);
434
435
		// Standardize newlines
436 View Code Duplication
		if (strpos($str, "\r") !== FALSE)
437
		{
438
			$str = str_replace(array("\r\n", "\r"), "\n", $str);
439
		}
440
441
		// If the current word is surrounded by {unwrap} tags we'll
442
		// strip the entire chunk and replace it with a marker.
443
		$unwrap = array();
444 View Code Duplication
		if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches))
445
		{
446
			for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
447
			{
448
				$unwrap[] = $matches[1][$i];
449
				$str = str_replace($matches[0][$i], '{{unwrapped'.$i.'}}', $str);
450
			}
451
		}
452
453
		// Use PHP's native function to do the initial wordwrap.
454
		// We set the cut flag to FALSE so that any individual words that are
455
		// too long get left alone. In the next step we'll deal with them.
456
		$str = wordwrap($str, $charlim, "\n", FALSE);
457
458
		// Split the string into individual lines of text and cycle through them
459
		$output = '';
460
		foreach (explode("\n", $str) as $line)
461
		{
462
			// Is the line within the allowed character count?
463
			// If so we'll join it to the output and continue
464
			if (mb_strlen($line) <= $charlim)
465
			{
466
				$output .= $line."\n";
467
				continue;
468
			}
469
470
			$temp = '';
471 View Code Duplication
			while (mb_strlen($line) > $charlim)
472
			{
473
				// If the over-length word is a URL we won't wrap it
474
				if (preg_match('!\[url.+\]|://|www\.!', $line))
475
				{
476
					break;
477
				}
478
479
				// Trim the word down
480
				$temp .= mb_substr($line, 0, $charlim - 1);
481
				$line = mb_substr($line, $charlim - 1);
482
			}
483
484
			// If $temp contains data it means we had to split up an over-length
485
			// word into smaller chunks so we'll add it back to our current line
486
			if ($temp !== '')
487
			{
488
				$output .= $temp."\n".$line."\n";
489
			}
490
			else
491
			{
492
				$output .= $line."\n";
493
			}
494
		}
495
496
		// Put our markers back
497 View Code Duplication
		if (count($unwrap) > 0)
498
		{
499
			foreach ($unwrap as $key => $val)
500
			{
501
				$output = str_replace('{{unwrapped'.$key.'}}', $val, $output);
502
			}
503
		}
504
505
		return $output;
506
	}
507
}
508
509
// ------------------------------------------------------------------------
510
511
if ( ! function_exists('ellipsize'))
512
{
513
	/**
514
	 * Ellipsize String
515
	 *
516
	 * This function will strip tags from a string, split it at its max_length and ellipsize
517
	 *
518
	 * @param	string	string to ellipsize
519
	 * @param	int	max length of string
520
	 * @param	mixed	int (1|0) or float, .5, .2, etc for position to split
521
	 * @param	string	ellipsis ; Default '...'
522
	 * @return	string	ellipsized string
523
	 */
524
	function ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
525
	{
526
		// Strip tags
527
		$str = trim(strip_tags($str));
528
529
		// Is the string long enough to ellipsize?
530
		if (mb_strlen($str) <= $max_length)
531
		{
532
			return $str;
533
		}
534
535
		$beg = mb_substr($str, 0, floor($max_length * $position));
536
		$position = ($position > 1) ? 1 : $position;
537
538
		if ($position === 1)
539
		{
540
			$end = mb_substr($str, 0, -($max_length - mb_strlen($beg)));
541
		}
542
		else
543
		{
544
			$end = mb_substr($str, -($max_length - mb_strlen($beg)));
545
		}
546
547
		return $beg.$ellipsis.$end;
548
	}
549
}
550