Initial commit
This commit is contained in:
116
system/helpers/array_helper.php
Normal file
116
system/helpers/array_helper.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Array Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/array_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('element'))
|
||||
{
|
||||
/**
|
||||
* Element
|
||||
*
|
||||
* Lets you determine whether an array index is set and whether it has a value.
|
||||
* If the element is empty it returns NULL (or whatever you specify as the default value.)
|
||||
*
|
||||
* @param string
|
||||
* @param array
|
||||
* @param mixed
|
||||
* @return mixed depends on what the array contains
|
||||
*/
|
||||
function element($item, array $array, $default = NULL)
|
||||
{
|
||||
return array_key_exists($item, $array) ? $array[$item] : $default;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('random_element'))
|
||||
{
|
||||
/**
|
||||
* Random Element - Takes an array as input and returns a random element
|
||||
*
|
||||
* @param array
|
||||
* @return mixed depends on what the array contains
|
||||
*/
|
||||
function random_element($array)
|
||||
{
|
||||
return is_array($array) ? $array[array_rand($array)] : $array;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('elements'))
|
||||
{
|
||||
/**
|
||||
* Elements
|
||||
*
|
||||
* Returns only the array items specified. Will return a default value if
|
||||
* it is not set.
|
||||
*
|
||||
* @param array
|
||||
* @param array
|
||||
* @param mixed
|
||||
* @return mixed depends on what the array contains
|
||||
*/
|
||||
function elements($items, array $array, $default = NULL)
|
||||
{
|
||||
$return = array();
|
||||
|
||||
is_array($items) OR $items = array($items);
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$return[$item] = array_key_exists($item, $array) ? $array[$item] : $default;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
353
system/helpers/captcha_helper.php
Normal file
353
system/helpers/captcha_helper.php
Normal file
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter CAPTCHA Helper
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/captcha_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('create_captcha'))
|
||||
{
|
||||
/**
|
||||
* Create CAPTCHA
|
||||
*
|
||||
* @param array $data Data for the CAPTCHA
|
||||
* @param string $img_path Path to create the image in (deprecated)
|
||||
* @param string $img_url URL to the CAPTCHA image folder (deprecated)
|
||||
* @param string $font_path Server path to font (deprecated)
|
||||
* @return string
|
||||
*/
|
||||
function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
|
||||
{
|
||||
$defaults = array(
|
||||
'word' => '',
|
||||
'img_path' => '',
|
||||
'img_url' => '',
|
||||
'img_width' => '150',
|
||||
'img_height' => '30',
|
||||
'font_path' => '',
|
||||
'expiration' => 7200,
|
||||
'word_length' => 8,
|
||||
'font_size' => 16,
|
||||
'img_id' => '',
|
||||
'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'colors' => array(
|
||||
'background' => array(255,255,255),
|
||||
'border' => array(153,102,102),
|
||||
'text' => array(204,153,153),
|
||||
'grid' => array(255,182,182)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($defaults as $key => $val)
|
||||
{
|
||||
if ( ! is_array($data) && empty($$key))
|
||||
{
|
||||
$$key = $val;
|
||||
}
|
||||
else
|
||||
{
|
||||
$$key = isset($data[$key]) ? $data[$key] : $val;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! extension_loaded('gd'))
|
||||
{
|
||||
log_message('error', 'create_captcha(): GD extension is not loaded.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($img_path === '' OR $img_url === '')
|
||||
{
|
||||
log_message('error', 'create_captcha(): $img_path and $img_url are required.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( ! is_dir($img_path) OR ! is_really_writable($img_path))
|
||||
{
|
||||
log_message('error', "create_captcha(): '{$img_path}' is not a dir, nor is it writable.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// Remove old images
|
||||
// -----------------------------------
|
||||
|
||||
$now = microtime(TRUE);
|
||||
|
||||
$current_dir = @opendir($img_path);
|
||||
while ($filename = @readdir($current_dir))
|
||||
{
|
||||
if (in_array(substr($filename, -4), array('.jpg', '.png'))
|
||||
&& (str_replace(array('.jpg', '.png'), '', $filename) + $expiration) < $now)
|
||||
{
|
||||
@unlink($img_path.$filename);
|
||||
}
|
||||
}
|
||||
|
||||
@closedir($current_dir);
|
||||
|
||||
// -----------------------------------
|
||||
// Do we have a "word" yet?
|
||||
// -----------------------------------
|
||||
|
||||
if (empty($word))
|
||||
{
|
||||
$word = '';
|
||||
$pool_length = strlen($pool);
|
||||
$rand_max = $pool_length - 1;
|
||||
|
||||
// PHP7 or a suitable polyfill
|
||||
if (function_exists('random_int'))
|
||||
{
|
||||
try
|
||||
{
|
||||
for ($i = 0; $i < $word_length; $i++)
|
||||
{
|
||||
$word .= $pool[random_int(0, $rand_max)];
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// This means fallback to the next possible
|
||||
// alternative to random_int()
|
||||
$word = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($word))
|
||||
{
|
||||
// Nobody will have a larger character pool than
|
||||
// 256 characters, but let's handle it just in case ...
|
||||
//
|
||||
// No, I do not care that the fallback to mt_rand() can
|
||||
// handle it; if you trigger this, you're very obviously
|
||||
// trying to break it. -- Narf
|
||||
if ($pool_length > 256)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// We'll try using the operating system's PRNG first,
|
||||
// which we can access through CI_Security::get_random_bytes()
|
||||
$security = get_instance()->security;
|
||||
|
||||
// To avoid numerous get_random_bytes() calls, we'll
|
||||
// just try fetching as much bytes as we need at once.
|
||||
if (($bytes = $security->get_random_bytes($pool_length)) !== FALSE)
|
||||
{
|
||||
$byte_index = $word_index = 0;
|
||||
while ($word_index < $word_length)
|
||||
{
|
||||
// Do we have more random data to use?
|
||||
// It could be exhausted by previous iterations
|
||||
// ignoring bytes higher than $rand_max.
|
||||
if ($byte_index === $pool_length)
|
||||
{
|
||||
// No failures should be possible if the
|
||||
// first get_random_bytes() call didn't
|
||||
// return FALSE, but still ...
|
||||
for ($i = 0; $i < 5; $i++)
|
||||
{
|
||||
if (($bytes = $security->get_random_bytes($pool_length)) === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$byte_index = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($bytes === FALSE)
|
||||
{
|
||||
// Sadly, this means fallback to mt_rand()
|
||||
$word = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
list(, $rand_index) = unpack('C', $bytes[$byte_index++]);
|
||||
if ($rand_index > $rand_max)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$word .= $pool[$rand_index];
|
||||
$word_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($word))
|
||||
{
|
||||
for ($i = 0; $i < $word_length; $i++)
|
||||
{
|
||||
$word .= $pool[mt_rand(0, $rand_max)];
|
||||
}
|
||||
}
|
||||
elseif ( ! is_string($word))
|
||||
{
|
||||
$word = (string) $word;
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// Determine angle and position
|
||||
// -----------------------------------
|
||||
$length = strlen($word);
|
||||
$angle = ($length >= 6) ? mt_rand(-($length-6), ($length-6)) : 0;
|
||||
$x_axis = mt_rand(6, (360/$length)-16);
|
||||
$y_axis = ($angle >= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height);
|
||||
|
||||
// Create image
|
||||
// PHP.net recommends imagecreatetruecolor(), but it isn't always available
|
||||
$im = function_exists('imagecreatetruecolor')
|
||||
? imagecreatetruecolor($img_width, $img_height)
|
||||
: imagecreate($img_width, $img_height);
|
||||
|
||||
// -----------------------------------
|
||||
// Assign colors
|
||||
// ----------------------------------
|
||||
|
||||
is_array($colors) OR $colors = $defaults['colors'];
|
||||
|
||||
foreach (array_keys($defaults['colors']) as $key)
|
||||
{
|
||||
// Check for a possible missing value
|
||||
is_array($colors[$key]) OR $colors[$key] = $defaults['colors'][$key];
|
||||
$colors[$key] = imagecolorallocate($im, $colors[$key][0], $colors[$key][1], $colors[$key][2]);
|
||||
}
|
||||
|
||||
// Create the rectangle
|
||||
ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $colors['background']);
|
||||
|
||||
// -----------------------------------
|
||||
// Create the spiral pattern
|
||||
// -----------------------------------
|
||||
$theta = 1;
|
||||
$thetac = 7;
|
||||
$radius = 16;
|
||||
$circles = 20;
|
||||
$points = 32;
|
||||
|
||||
for ($i = 0, $cp = ($circles * $points) - 1; $i < $cp; $i++)
|
||||
{
|
||||
$theta += $thetac;
|
||||
$rad = $radius * ($i / $points);
|
||||
$x = ($rad * cos($theta)) + $x_axis;
|
||||
$y = ($rad * sin($theta)) + $y_axis;
|
||||
$theta += $thetac;
|
||||
$rad1 = $radius * (($i + 1) / $points);
|
||||
$x1 = ($rad1 * cos($theta)) + $x_axis;
|
||||
$y1 = ($rad1 * sin($theta)) + $y_axis;
|
||||
imageline($im, $x, $y, $x1, $y1, $colors['grid']);
|
||||
$theta -= $thetac;
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// Write the text
|
||||
// -----------------------------------
|
||||
|
||||
$use_font = ($font_path !== '' && file_exists($font_path) && function_exists('imagettftext'));
|
||||
if ($use_font === FALSE)
|
||||
{
|
||||
($font_size > 5) && $font_size = 5;
|
||||
$x = mt_rand(0, $img_width / ($length / 3));
|
||||
$y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
($font_size > 30) && $font_size = 30;
|
||||
$x = mt_rand(0, $img_width / ($length / 1.5));
|
||||
$y = $font_size + 2;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
if ($use_font === FALSE)
|
||||
{
|
||||
$y = mt_rand(0 , $img_height / 2);
|
||||
imagestring($im, $font_size, $x, $y, $word[$i], $colors['text']);
|
||||
$x += ($font_size * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$y = mt_rand($img_height / 2, $img_height - 3);
|
||||
imagettftext($im, $font_size, $angle, $x, $y, $colors['text'], $font_path, $word[$i]);
|
||||
$x += $font_size;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the border
|
||||
imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $colors['border']);
|
||||
|
||||
// -----------------------------------
|
||||
// Generate the image
|
||||
// -----------------------------------
|
||||
$img_url = rtrim($img_url, '/').'/';
|
||||
|
||||
if (function_exists('imagejpeg'))
|
||||
{
|
||||
$img_filename = $now.'.jpg';
|
||||
imagejpeg($im, $img_path.$img_filename);
|
||||
}
|
||||
elseif (function_exists('imagepng'))
|
||||
{
|
||||
$img_filename = $now.'.png';
|
||||
imagepng($im, $img_path.$img_filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$img = '<img '.($img_id === '' ? '' : 'id="'.$img_id.'"').' src="'.$img_url.$img_filename.'" style="width: '.$img_width.'px; height: '.$img_height .'px; border: 0;" alt=" " />';
|
||||
ImageDestroy($im);
|
||||
|
||||
return array('word' => $word, 'time' => $now, 'image' => $img, 'filename' => $img_filename);
|
||||
}
|
||||
}
|
114
system/helpers/cookie_helper.php
Normal file
114
system/helpers/cookie_helper.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Cookie Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/cookie_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('set_cookie'))
|
||||
{
|
||||
/**
|
||||
* Set cookie
|
||||
*
|
||||
* Accepts seven parameters, or you can submit an associative
|
||||
* array in the first parameter containing all the values.
|
||||
*
|
||||
* @param mixed
|
||||
* @param string the value of the cookie
|
||||
* @param string the number of seconds until expiration
|
||||
* @param string the cookie domain. Usually: .yourdomain.com
|
||||
* @param string the cookie path
|
||||
* @param string the cookie prefix
|
||||
* @param bool true makes the cookie secure
|
||||
* @param bool true makes the cookie accessible via http(s) only (no javascript)
|
||||
* @return void
|
||||
*/
|
||||
function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL)
|
||||
{
|
||||
// Set the config file options
|
||||
get_instance()->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_cookie'))
|
||||
{
|
||||
/**
|
||||
* Fetch an item from the COOKIE array
|
||||
*
|
||||
* @param string
|
||||
* @param bool
|
||||
* @return mixed
|
||||
*/
|
||||
function get_cookie($index, $xss_clean = NULL)
|
||||
{
|
||||
is_bool($xss_clean) OR $xss_clean = (config_item('global_xss_filtering') === TRUE);
|
||||
$prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix');
|
||||
return get_instance()->input->cookie($prefix.$index, $xss_clean);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('delete_cookie'))
|
||||
{
|
||||
/**
|
||||
* Delete a COOKIE
|
||||
*
|
||||
* @param mixed
|
||||
* @param string the cookie domain. Usually: .yourdomain.com
|
||||
* @param string the cookie path
|
||||
* @param string the cookie prefix
|
||||
* @return void
|
||||
*/
|
||||
function delete_cookie($name, $domain = '', $path = '/', $prefix = '')
|
||||
{
|
||||
set_cookie($name, '', '', $domain, $path, $prefix);
|
||||
}
|
||||
}
|
743
system/helpers/date_helper.php
Normal file
743
system/helpers/date_helper.php
Normal file
File diff suppressed because it is too large
Load Diff
102
system/helpers/directory_helper.php
Normal file
102
system/helpers/directory_helper.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Directory Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/directory_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('directory_map'))
|
||||
{
|
||||
/**
|
||||
* Create a Directory Map
|
||||
*
|
||||
* Reads the specified directory and builds an array
|
||||
* representation of it. Sub-folders contained with the
|
||||
* directory will be mapped as well.
|
||||
*
|
||||
* @param string $source_dir Path to source
|
||||
* @param int $directory_depth Depth of directories to traverse
|
||||
* (0 = fully recursive, 1 = current dir, etc)
|
||||
* @param bool $hidden Whether to show hidden files
|
||||
* @return array
|
||||
*/
|
||||
function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE)
|
||||
{
|
||||
if ($fp = @opendir($source_dir))
|
||||
{
|
||||
$filedata = array();
|
||||
$new_depth = $directory_depth - 1;
|
||||
$source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
||||
|
||||
while (FALSE !== ($file = readdir($fp)))
|
||||
{
|
||||
// Remove '.', '..', and hidden files [optional]
|
||||
if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
is_dir($source_dir.$file) && $file .= DIRECTORY_SEPARATOR;
|
||||
|
||||
if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir.$file))
|
||||
{
|
||||
$filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filedata[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
closedir($fp);
|
||||
return $filedata;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
159
system/helpers/download_helper.php
Normal file
159
system/helpers/download_helper.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Download Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/download_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('force_download'))
|
||||
{
|
||||
/**
|
||||
* Force Download
|
||||
*
|
||||
* Generates headers that force a download to happen
|
||||
*
|
||||
* @param string filename
|
||||
* @param mixed the data to be downloaded
|
||||
* @param bool whether to try and send the actual file MIME type
|
||||
* @return void
|
||||
*/
|
||||
function force_download($filename = '', $data = '', $set_mime = FALSE)
|
||||
{
|
||||
if ($filename === '' OR $data === '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
elseif ($data === NULL)
|
||||
{
|
||||
if ( ! @is_file($filename) OR ($filesize = @filesize($filename)) === FALSE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$filepath = $filename;
|
||||
$filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename));
|
||||
$filename = end($filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filesize = strlen($data);
|
||||
}
|
||||
|
||||
// Set the default MIME type to send
|
||||
$mime = 'application/octet-stream';
|
||||
|
||||
$x = explode('.', $filename);
|
||||
$extension = end($x);
|
||||
|
||||
if ($set_mime === TRUE)
|
||||
{
|
||||
if (count($x) === 1 OR $extension === '')
|
||||
{
|
||||
/* If we're going to detect the MIME type,
|
||||
* we'll need a file extension.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the mime types
|
||||
$mimes =& get_mimes();
|
||||
|
||||
// Only change the default MIME if we can find one
|
||||
if (isset($mimes[$extension]))
|
||||
{
|
||||
$mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
|
||||
}
|
||||
}
|
||||
|
||||
/* It was reported that browsers on Android 2.1 (and possibly older as well)
|
||||
* need to have the filename extension upper-cased in order to be able to
|
||||
* download it.
|
||||
*
|
||||
* Reference: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
|
||||
*/
|
||||
if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\s(1|2\.[01])/', $_SERVER['HTTP_USER_AGENT']))
|
||||
{
|
||||
$x[count($x) - 1] = strtoupper($extension);
|
||||
$filename = implode('.', $x);
|
||||
}
|
||||
|
||||
if ($data === NULL && ($fp = @fopen($filepath, 'rb')) === FALSE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean output buffer
|
||||
if (ob_get_level() !== 0 && @ob_end_clean() === FALSE)
|
||||
{
|
||||
@ob_clean();
|
||||
}
|
||||
|
||||
// Generate the server headers
|
||||
header('Content-Type: '.$mime);
|
||||
header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||
header('Expires: 0');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: '.$filesize);
|
||||
header('Cache-Control: private, no-transform, no-store, must-revalidate');
|
||||
|
||||
// If we have raw data - just dump it
|
||||
if ($data !== NULL)
|
||||
{
|
||||
exit($data);
|
||||
}
|
||||
|
||||
// Flush 1MB chunks of data
|
||||
while ( ! feof($fp) && ($data = fread($fp, 1048576)) !== FALSE)
|
||||
{
|
||||
echo $data;
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
exit;
|
||||
}
|
||||
}
|
85
system/helpers/email_helper.php
Normal file
85
system/helpers/email_helper.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Email Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/email_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('valid_email'))
|
||||
{
|
||||
/**
|
||||
* Validate email address
|
||||
*
|
||||
* @deprecated 3.0.0 Use PHP's filter_var() instead
|
||||
* @param string $email
|
||||
* @return bool
|
||||
*/
|
||||
function valid_email($email)
|
||||
{
|
||||
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('send_email'))
|
||||
{
|
||||
/**
|
||||
* Send an email
|
||||
*
|
||||
* @deprecated 3.0.0 Use PHP's mail() instead
|
||||
* @param string $recipient
|
||||
* @param string $subject
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
function send_email($recipient, $subject, $message)
|
||||
{
|
||||
return mail($recipient, $subject, $message);
|
||||
}
|
||||
}
|
454
system/helpers/file_helper.php
Normal file
454
system/helpers/file_helper.php
Normal file
@@ -0,0 +1,454 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter File Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/file_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('read_file'))
|
||||
{
|
||||
/**
|
||||
* Read File
|
||||
*
|
||||
* Opens the file specified in the path and returns it as a string.
|
||||
*
|
||||
* @todo Remove in version 3.1+.
|
||||
* @deprecated 3.0.0 It is now just an alias for PHP's native file_get_contents().
|
||||
* @param string $file Path to file
|
||||
* @return string File contents
|
||||
*/
|
||||
function read_file($file)
|
||||
{
|
||||
return @file_get_contents($file);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('write_file'))
|
||||
{
|
||||
/**
|
||||
* Write File
|
||||
*
|
||||
* Writes data to the file specified in the path.
|
||||
* Creates a new file if non-existent.
|
||||
*
|
||||
* @param string $path File path
|
||||
* @param string $data Data to write
|
||||
* @param string $mode fopen() mode (default: 'wb')
|
||||
* @return bool
|
||||
*/
|
||||
function write_file($path, $data, $mode = 'wb')
|
||||
{
|
||||
if ( ! $fp = @fopen($path, $mode))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
flock($fp, LOCK_EX);
|
||||
|
||||
for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result)
|
||||
{
|
||||
if (($result = fwrite($fp, substr($data, $written))) === FALSE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
return is_int($result);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('delete_files'))
|
||||
{
|
||||
/**
|
||||
* Delete Files
|
||||
*
|
||||
* Deletes all files contained in the supplied directory path.
|
||||
* Files must be writable or owned by the system in order to be deleted.
|
||||
* If the second parameter is set to TRUE, any directories contained
|
||||
* within the supplied base directory will be nuked as well.
|
||||
*
|
||||
* @param string $path File path
|
||||
* @param bool $del_dir Whether to delete any directories found in the path
|
||||
* @param bool $htdocs Whether to skip deleting .htaccess and index page files
|
||||
* @param int $_level Current directory depth level (default: 0; internal use only)
|
||||
* @return bool
|
||||
*/
|
||||
function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0)
|
||||
{
|
||||
// Trim the trailing slash
|
||||
$path = rtrim($path, '/\\');
|
||||
|
||||
if ( ! $current_dir = @opendir($path))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (FALSE !== ($filename = @readdir($current_dir)))
|
||||
{
|
||||
if ($filename !== '.' && $filename !== '..')
|
||||
{
|
||||
$filepath = $path.DIRECTORY_SEPARATOR.$filename;
|
||||
|
||||
if (is_dir($filepath) && $filename[0] !== '.' && ! is_link($filepath))
|
||||
{
|
||||
delete_files($filepath, $del_dir, $htdocs, $_level + 1);
|
||||
}
|
||||
elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
|
||||
{
|
||||
@unlink($filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir($current_dir);
|
||||
|
||||
return ($del_dir === TRUE && $_level > 0)
|
||||
? @rmdir($path)
|
||||
: TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_filenames'))
|
||||
{
|
||||
/**
|
||||
* Get Filenames
|
||||
*
|
||||
* Reads the specified directory and builds an array containing the filenames.
|
||||
* Any sub-folders contained within the specified path are read as well.
|
||||
*
|
||||
* @param string path to source
|
||||
* @param bool whether to include the path as part of the filename
|
||||
* @param bool internal variable to determine recursion status - do not use in calls
|
||||
* @return array
|
||||
*/
|
||||
function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
|
||||
{
|
||||
static $_filedata = array();
|
||||
|
||||
if ($fp = @opendir($source_dir))
|
||||
{
|
||||
// reset the array and make sure $source_dir has a trailing slash on the initial call
|
||||
if ($_recursion === FALSE)
|
||||
{
|
||||
$_filedata = array();
|
||||
$source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
while (FALSE !== ($file = readdir($fp)))
|
||||
{
|
||||
if (is_dir($source_dir.$file) && $file[0] !== '.')
|
||||
{
|
||||
get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
|
||||
}
|
||||
elseif ($file[0] !== '.')
|
||||
{
|
||||
$_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file;
|
||||
}
|
||||
}
|
||||
|
||||
closedir($fp);
|
||||
return $_filedata;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_dir_file_info'))
|
||||
{
|
||||
/**
|
||||
* Get Directory File Information
|
||||
*
|
||||
* Reads the specified directory and builds an array containing the filenames,
|
||||
* filesize, dates, and permissions
|
||||
*
|
||||
* Any sub-folders contained within the specified path are read as well.
|
||||
*
|
||||
* @param string path to source
|
||||
* @param bool Look only at the top level directory specified?
|
||||
* @param bool internal variable to determine recursion status - do not use in calls
|
||||
* @return array
|
||||
*/
|
||||
function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE)
|
||||
{
|
||||
static $_filedata = array();
|
||||
$relative_path = $source_dir;
|
||||
|
||||
if ($fp = @opendir($source_dir))
|
||||
{
|
||||
// reset the array and make sure $source_dir has a trailing slash on the initial call
|
||||
if ($_recursion === FALSE)
|
||||
{
|
||||
$_filedata = array();
|
||||
$source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
// Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast
|
||||
while (FALSE !== ($file = readdir($fp)))
|
||||
{
|
||||
if (is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
|
||||
{
|
||||
get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
|
||||
}
|
||||
elseif ($file[0] !== '.')
|
||||
{
|
||||
$_filedata[$file] = get_file_info($source_dir.$file);
|
||||
$_filedata[$file]['relative_path'] = $relative_path;
|
||||
}
|
||||
}
|
||||
|
||||
closedir($fp);
|
||||
return $_filedata;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_file_info'))
|
||||
{
|
||||
/**
|
||||
* Get File Info
|
||||
*
|
||||
* Given a file and path, returns the name, path, size, date modified
|
||||
* Second parameter allows you to explicitly declare what information you want returned
|
||||
* Options are: name, server_path, size, date, readable, writable, executable, fileperms
|
||||
* Returns FALSE if the file cannot be found.
|
||||
*
|
||||
* @param string path to file
|
||||
* @param mixed array or comma separated string of information returned
|
||||
* @return array
|
||||
*/
|
||||
function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
|
||||
{
|
||||
if ( ! file_exists($file))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (is_string($returned_values))
|
||||
{
|
||||
$returned_values = explode(',', $returned_values);
|
||||
}
|
||||
|
||||
foreach ($returned_values as $key)
|
||||
{
|
||||
switch ($key)
|
||||
{
|
||||
case 'name':
|
||||
$fileinfo['name'] = basename($file);
|
||||
break;
|
||||
case 'server_path':
|
||||
$fileinfo['server_path'] = $file;
|
||||
break;
|
||||
case 'size':
|
||||
$fileinfo['size'] = filesize($file);
|
||||
break;
|
||||
case 'date':
|
||||
$fileinfo['date'] = filemtime($file);
|
||||
break;
|
||||
case 'readable':
|
||||
$fileinfo['readable'] = is_readable($file);
|
||||
break;
|
||||
case 'writable':
|
||||
$fileinfo['writable'] = is_really_writable($file);
|
||||
break;
|
||||
case 'executable':
|
||||
$fileinfo['executable'] = is_executable($file);
|
||||
break;
|
||||
case 'fileperms':
|
||||
$fileinfo['fileperms'] = fileperms($file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $fileinfo;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_mime_by_extension'))
|
||||
{
|
||||
/**
|
||||
* Get Mime by Extension
|
||||
*
|
||||
* Translates a file extension into a mime type based on config/mimes.php.
|
||||
* Returns FALSE if it can't determine the type, or open the mime config file
|
||||
*
|
||||
* Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
|
||||
* It should NOT be trusted, and should certainly NOT be used for security
|
||||
*
|
||||
* @param string $filename File name
|
||||
* @return string
|
||||
*/
|
||||
function get_mime_by_extension($filename)
|
||||
{
|
||||
static $mimes;
|
||||
|
||||
if ( ! is_array($mimes))
|
||||
{
|
||||
$mimes = get_mimes();
|
||||
|
||||
if (empty($mimes))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$extension = strtolower(substr(strrchr($filename, '.'), 1));
|
||||
|
||||
if (isset($mimes[$extension]))
|
||||
{
|
||||
return is_array($mimes[$extension])
|
||||
? current($mimes[$extension]) // Multiple mime types, just give the first one
|
||||
: $mimes[$extension];
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('symbolic_permissions'))
|
||||
{
|
||||
/**
|
||||
* Symbolic Permissions
|
||||
*
|
||||
* Takes a numeric value representing a file's permissions and returns
|
||||
* standard symbolic notation representing that value
|
||||
*
|
||||
* @param int $perms Permissions
|
||||
* @return string
|
||||
*/
|
||||
function symbolic_permissions($perms)
|
||||
{
|
||||
if (($perms & 0xC000) === 0xC000)
|
||||
{
|
||||
$symbolic = 's'; // Socket
|
||||
}
|
||||
elseif (($perms & 0xA000) === 0xA000)
|
||||
{
|
||||
$symbolic = 'l'; // Symbolic Link
|
||||
}
|
||||
elseif (($perms & 0x8000) === 0x8000)
|
||||
{
|
||||
$symbolic = '-'; // Regular
|
||||
}
|
||||
elseif (($perms & 0x6000) === 0x6000)
|
||||
{
|
||||
$symbolic = 'b'; // Block special
|
||||
}
|
||||
elseif (($perms & 0x4000) === 0x4000)
|
||||
{
|
||||
$symbolic = 'd'; // Directory
|
||||
}
|
||||
elseif (($perms & 0x2000) === 0x2000)
|
||||
{
|
||||
$symbolic = 'c'; // Character special
|
||||
}
|
||||
elseif (($perms & 0x1000) === 0x1000)
|
||||
{
|
||||
$symbolic = 'p'; // FIFO pipe
|
||||
}
|
||||
else
|
||||
{
|
||||
$symbolic = 'u'; // Unknown
|
||||
}
|
||||
|
||||
// Owner
|
||||
$symbolic .= (($perms & 0x0100) ? 'r' : '-')
|
||||
.(($perms & 0x0080) ? 'w' : '-')
|
||||
.(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
|
||||
|
||||
// Group
|
||||
$symbolic .= (($perms & 0x0020) ? 'r' : '-')
|
||||
.(($perms & 0x0010) ? 'w' : '-')
|
||||
.(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
|
||||
|
||||
// World
|
||||
$symbolic .= (($perms & 0x0004) ? 'r' : '-')
|
||||
.(($perms & 0x0002) ? 'w' : '-')
|
||||
.(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
|
||||
|
||||
return $symbolic;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('octal_permissions'))
|
||||
{
|
||||
/**
|
||||
* Octal Permissions
|
||||
*
|
||||
* Takes a numeric value representing a file's permissions and returns
|
||||
* a three character string representing the file's octal permissions
|
||||
*
|
||||
* @param int $perms Permissions
|
||||
* @return string
|
||||
*/
|
||||
function octal_permissions($perms)
|
||||
{
|
||||
return substr(sprintf('%o', $perms), -3);
|
||||
}
|
||||
}
|
1056
system/helpers/form_helper.php
Normal file
1056
system/helpers/form_helper.php
Normal file
File diff suppressed because it is too large
Load Diff
410
system/helpers/html_helper.php
Normal file
410
system/helpers/html_helper.php
Normal file
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter HTML Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/html_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('heading'))
|
||||
{
|
||||
/**
|
||||
* Heading
|
||||
*
|
||||
* Generates an HTML heading tag.
|
||||
*
|
||||
* @param string content
|
||||
* @param int heading level
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function heading($data = '', $h = '1', $attributes = '')
|
||||
{
|
||||
return '<h'.$h._stringify_attributes($attributes).'>'.$data.'</h'.$h.'>';
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('ul'))
|
||||
{
|
||||
/**
|
||||
* Unordered List
|
||||
*
|
||||
* Generates an HTML unordered list from an single or multi-dimensional array.
|
||||
*
|
||||
* @param array
|
||||
* @param mixed
|
||||
* @return string
|
||||
*/
|
||||
function ul($list, $attributes = '')
|
||||
{
|
||||
return _list('ul', $list, $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('ol'))
|
||||
{
|
||||
/**
|
||||
* Ordered List
|
||||
*
|
||||
* Generates an HTML ordered list from an single or multi-dimensional array.
|
||||
*
|
||||
* @param array
|
||||
* @param mixed
|
||||
* @return string
|
||||
*/
|
||||
function ol($list, $attributes = '')
|
||||
{
|
||||
return _list('ol', $list, $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('_list'))
|
||||
{
|
||||
/**
|
||||
* Generates the list
|
||||
*
|
||||
* Generates an HTML ordered list from an single or multi-dimensional array.
|
||||
*
|
||||
* @param string
|
||||
* @param mixed
|
||||
* @param mixed
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
function _list($type = 'ul', $list = array(), $attributes = '', $depth = 0)
|
||||
{
|
||||
// If an array wasn't submitted there's nothing to do...
|
||||
if ( ! is_array($list))
|
||||
{
|
||||
return $list;
|
||||
}
|
||||
|
||||
// Set the indentation based on the depth
|
||||
$out = str_repeat(' ', $depth)
|
||||
// Write the opening list tag
|
||||
.'<'.$type._stringify_attributes($attributes).">\n";
|
||||
|
||||
// Cycle through the list elements. If an array is
|
||||
// encountered we will recursively call _list()
|
||||
|
||||
static $_last_list_item = '';
|
||||
foreach ($list as $key => $val)
|
||||
{
|
||||
$_last_list_item = $key;
|
||||
|
||||
$out .= str_repeat(' ', $depth + 2).'<li>';
|
||||
|
||||
if ( ! is_array($val))
|
||||
{
|
||||
$out .= $val;
|
||||
}
|
||||
else
|
||||
{
|
||||
$out .= $_last_list_item."\n"._list($type, $val, '', $depth + 4).str_repeat(' ', $depth + 2);
|
||||
}
|
||||
|
||||
$out .= "</li>\n";
|
||||
}
|
||||
|
||||
// Set the indentation for the closing tag and apply it
|
||||
return $out.str_repeat(' ', $depth).'</'.$type.">\n";
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('img'))
|
||||
{
|
||||
/**
|
||||
* Image
|
||||
*
|
||||
* Generates an <img /> element
|
||||
*
|
||||
* @param mixed
|
||||
* @param bool
|
||||
* @param mixed
|
||||
* @return string
|
||||
*/
|
||||
function img($src = '', $index_page = FALSE, $attributes = '')
|
||||
{
|
||||
if ( ! is_array($src) )
|
||||
{
|
||||
$src = array('src' => $src);
|
||||
}
|
||||
|
||||
// If there is no alt attribute defined, set it to an empty string
|
||||
if ( ! isset($src['alt']))
|
||||
{
|
||||
$src['alt'] = '';
|
||||
}
|
||||
|
||||
$img = '<img';
|
||||
|
||||
foreach ($src as $k => $v)
|
||||
{
|
||||
if ($k === 'src' && ! preg_match('#^(data:[a-z,;])|(([a-z]+:)?(?<!data:)//)#i', $v))
|
||||
{
|
||||
if ($index_page === TRUE)
|
||||
{
|
||||
$img .= ' src="'.get_instance()->config->site_url($v).'"';
|
||||
}
|
||||
else
|
||||
{
|
||||
$img .= ' src="'.get_instance()->config->base_url($v).'"';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$img .= ' '.$k.'="'.$v.'"';
|
||||
}
|
||||
}
|
||||
|
||||
return $img._stringify_attributes($attributes).' />';
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('doctype'))
|
||||
{
|
||||
/**
|
||||
* Doctype
|
||||
*
|
||||
* Generates a page document type declaration
|
||||
*
|
||||
* Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans,
|
||||
* xhtml-frame, html4-strict, html4-trans, and html4-frame.
|
||||
* All values are saved in the doctypes config file.
|
||||
*
|
||||
* @param string type The doctype to be generated
|
||||
* @return string
|
||||
*/
|
||||
function doctype($type = 'xhtml1-strict')
|
||||
{
|
||||
static $doctypes;
|
||||
|
||||
if ( ! is_array($doctypes))
|
||||
{
|
||||
if (file_exists(APPPATH.'config/doctypes.php'))
|
||||
{
|
||||
include(APPPATH.'config/doctypes.php');
|
||||
}
|
||||
|
||||
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
|
||||
{
|
||||
include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
|
||||
}
|
||||
|
||||
if (empty($_doctypes) OR ! is_array($_doctypes))
|
||||
{
|
||||
$doctypes = array();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$doctypes = $_doctypes;
|
||||
}
|
||||
|
||||
return isset($doctypes[$type]) ? $doctypes[$type] : FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('link_tag'))
|
||||
{
|
||||
/**
|
||||
* Link
|
||||
*
|
||||
* Generates link to a CSS file
|
||||
*
|
||||
* @param mixed stylesheet hrefs or an array
|
||||
* @param string rel
|
||||
* @param string type
|
||||
* @param string title
|
||||
* @param string media
|
||||
* @param bool should index_page be added to the css path
|
||||
* @return string
|
||||
*/
|
||||
function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$link = '<link ';
|
||||
|
||||
if (is_array($href))
|
||||
{
|
||||
foreach ($href as $k => $v)
|
||||
{
|
||||
if ($k === 'href' && ! preg_match('#^([a-z]+:)?//#i', $v))
|
||||
{
|
||||
if ($index_page === TRUE)
|
||||
{
|
||||
$link .= 'href="'.$CI->config->site_url($v).'" ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$link .= 'href="'.$CI->config->base_url($v).'" ';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$link .= $k.'="'.$v.'" ';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (preg_match('#^([a-z]+:)?//#i', $href))
|
||||
{
|
||||
$link .= 'href="'.$href.'" ';
|
||||
}
|
||||
elseif ($index_page === TRUE)
|
||||
{
|
||||
$link .= 'href="'.$CI->config->site_url($href).'" ';
|
||||
}
|
||||
else
|
||||
{
|
||||
$link .= 'href="'.$CI->config->base_url($href).'" ';
|
||||
}
|
||||
|
||||
$link .= 'rel="'.$rel.'" type="'.$type.'" ';
|
||||
|
||||
if ($media !== '')
|
||||
{
|
||||
$link .= 'media="'.$media.'" ';
|
||||
}
|
||||
|
||||
if ($title !== '')
|
||||
{
|
||||
$link .= 'title="'.$title.'" ';
|
||||
}
|
||||
}
|
||||
|
||||
return $link."/>\n";
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('meta'))
|
||||
{
|
||||
/**
|
||||
* Generates meta tags from an array of key/values
|
||||
*
|
||||
* @param array
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function meta($name = '', $content = '', $type = 'name', $newline = "\n")
|
||||
{
|
||||
// Since we allow the data to be passes as a string, a simple array
|
||||
// or a multidimensional one, we need to do a little prepping.
|
||||
if ( ! is_array($name))
|
||||
{
|
||||
$name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
|
||||
}
|
||||
elseif (isset($name['name']))
|
||||
{
|
||||
// Turn single array into multidimensional
|
||||
$name = array($name);
|
||||
}
|
||||
|
||||
$str = '';
|
||||
foreach ($name as $meta)
|
||||
{
|
||||
$type = (isset($meta['type']) && $meta['type'] !== 'name') ? 'http-equiv' : 'name';
|
||||
$name = isset($meta['name']) ? $meta['name'] : '';
|
||||
$content = isset($meta['content']) ? $meta['content'] : '';
|
||||
$newline = isset($meta['newline']) ? $meta['newline'] : "\n";
|
||||
|
||||
$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('br'))
|
||||
{
|
||||
/**
|
||||
* Generates HTML BR tags based on number supplied
|
||||
*
|
||||
* @deprecated 3.0.0 Use str_repeat() instead
|
||||
* @param int $count Number of times to repeat the tag
|
||||
* @return string
|
||||
*/
|
||||
function br($count = 1)
|
||||
{
|
||||
return str_repeat('<br />', $count);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('nbs'))
|
||||
{
|
||||
/**
|
||||
* Generates non-breaking space entities based on number supplied
|
||||
*
|
||||
* @deprecated 3.0.0 Use str_repeat() instead
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
function nbs($num = 1)
|
||||
{
|
||||
return str_repeat(' ', $num);
|
||||
}
|
||||
}
|
11
system/helpers/index.html
Normal file
11
system/helpers/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
288
system/helpers/inflector_helper.php
Normal file
288
system/helpers/inflector_helper.php
Normal file
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Inflector Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/inflector_helper.html
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('singular'))
|
||||
{
|
||||
/**
|
||||
* Singular
|
||||
*
|
||||
* Takes a plural word and makes it singular
|
||||
*
|
||||
* @param string $str Input string
|
||||
* @return string
|
||||
*/
|
||||
function singular($str)
|
||||
{
|
||||
$result = strval($str);
|
||||
|
||||
if ( ! word_is_countable($result))
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
$singular_rules = array(
|
||||
'/(matr)ices$/' => '\1ix',
|
||||
'/(vert|ind)ices$/' => '\1ex',
|
||||
'/^(ox)en/' => '\1',
|
||||
'/(alias)es$/' => '\1',
|
||||
'/([octop|vir])i$/' => '\1us',
|
||||
'/(cris|ax|test)es$/' => '\1is',
|
||||
'/(shoe)s$/' => '\1',
|
||||
'/(o)es$/' => '\1',
|
||||
'/(bus|campus)es$/' => '\1',
|
||||
'/([m|l])ice$/' => '\1ouse',
|
||||
'/(x|ch|ss|sh)es$/' => '\1',
|
||||
'/(m)ovies$/' => '\1\2ovie',
|
||||
'/(s)eries$/' => '\1\2eries',
|
||||
'/([^aeiouy]|qu)ies$/' => '\1y',
|
||||
'/([lr])ves$/' => '\1f',
|
||||
'/(tive)s$/' => '\1',
|
||||
'/(hive)s$/' => '\1',
|
||||
'/([^f])ves$/' => '\1fe',
|
||||
'/(^analy)ses$/' => '\1sis',
|
||||
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis',
|
||||
'/([ti])a$/' => '\1um',
|
||||
'/(p)eople$/' => '\1\2erson',
|
||||
'/(m)en$/' => '\1an',
|
||||
'/(s)tatuses$/' => '\1\2tatus',
|
||||
'/(c)hildren$/' => '\1\2hild',
|
||||
'/(n)ews$/' => '\1\2ews',
|
||||
'/(quiz)zes$/' => '\1',
|
||||
'/([^us])s$/' => '\1'
|
||||
);
|
||||
|
||||
foreach ($singular_rules as $rule => $replacement)
|
||||
{
|
||||
if (preg_match($rule, $result))
|
||||
{
|
||||
$result = preg_replace($rule, $replacement, $result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('plural'))
|
||||
{
|
||||
/**
|
||||
* Plural
|
||||
*
|
||||
* Takes a singular word and makes it plural
|
||||
*
|
||||
* @param string $str Input string
|
||||
* @return string
|
||||
*/
|
||||
function plural($str)
|
||||
{
|
||||
$result = strval($str);
|
||||
|
||||
if ( ! word_is_countable($result))
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
$plural_rules = array(
|
||||
'/(quiz)$/' => '\1zes', // quizzes
|
||||
'/^(ox)$/' => '\1\2en', // ox
|
||||
'/([m|l])ouse$/' => '\1ice', // mouse, louse
|
||||
'/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index
|
||||
'/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address
|
||||
'/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency
|
||||
'/(hive)$/' => '\1s', // archive, hive
|
||||
'/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife
|
||||
'/sis$/' => 'ses', // basis, diagnosis
|
||||
'/([ti])um$/' => '\1a', // datum, medium
|
||||
'/(p)erson$/' => '\1eople', // person, salesperson
|
||||
'/(m)an$/' => '\1en', // man, woman, spokesman
|
||||
'/(c)hild$/' => '\1hildren', // child
|
||||
'/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato
|
||||
'/(bu|campu)s$/' => '\1\2ses', // bus, campus
|
||||
'/(alias|status|virus)$/' => '\1es', // alias
|
||||
'/(octop)us$/' => '\1i', // octopus
|
||||
'/(ax|cris|test)is$/' => '\1es', // axis, crisis
|
||||
'/s$/' => 's', // no change (compatibility)
|
||||
'/$/' => 's',
|
||||
);
|
||||
|
||||
foreach ($plural_rules as $rule => $replacement)
|
||||
{
|
||||
if (preg_match($rule, $result))
|
||||
{
|
||||
$result = preg_replace($rule, $replacement, $result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('camelize'))
|
||||
{
|
||||
/**
|
||||
* Camelize
|
||||
*
|
||||
* Takes multiple words separated by spaces or underscores and camelizes them
|
||||
*
|
||||
* @param string $str Input string
|
||||
* @return string
|
||||
*/
|
||||
function camelize($str)
|
||||
{
|
||||
return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('underscore'))
|
||||
{
|
||||
/**
|
||||
* Underscore
|
||||
*
|
||||
* Takes multiple words separated by spaces and underscores them
|
||||
*
|
||||
* @param string $str Input string
|
||||
* @return string
|
||||
*/
|
||||
function underscore($str)
|
||||
{
|
||||
return preg_replace('/[\s]+/', '_', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str)));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('humanize'))
|
||||
{
|
||||
/**
|
||||
* Humanize
|
||||
*
|
||||
* Takes multiple words separated by the separator and changes them to spaces
|
||||
*
|
||||
* @param string $str Input string
|
||||
* @param string $separator Input separator
|
||||
* @return string
|
||||
*/
|
||||
function humanize($str, $separator = '_')
|
||||
{
|
||||
return ucwords(preg_replace('/['.preg_quote($separator).']+/', ' ', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str))));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('word_is_countable'))
|
||||
{
|
||||
/**
|
||||
* Checks if the given word has a plural version.
|
||||
*
|
||||
* @param string $word Word to check
|
||||
* @return bool
|
||||
*/
|
||||
function word_is_countable($word)
|
||||
{
|
||||
return ! in_array(
|
||||
strtolower($word),
|
||||
array(
|
||||
'audio',
|
||||
'bison',
|
||||
'chassis',
|
||||
'compensation',
|
||||
'coreopsis',
|
||||
'data',
|
||||
'deer',
|
||||
'education',
|
||||
'emoji',
|
||||
'equipment',
|
||||
'fish',
|
||||
'furniture',
|
||||
'gold',
|
||||
'information',
|
||||
'knowledge',
|
||||
'love',
|
||||
'rain',
|
||||
'money',
|
||||
'moose',
|
||||
'nutrition',
|
||||
'offspring',
|
||||
'plankton',
|
||||
'pokemon',
|
||||
'police',
|
||||
'rice',
|
||||
'series',
|
||||
'sheep',
|
||||
'species',
|
||||
'swine',
|
||||
'traffic',
|
||||
'wheat'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('is_countable'))
|
||||
{
|
||||
function is_countable($word)
|
||||
{
|
||||
trigger_error('is_countable() is a native PHP function since version 7.3.0; use word_is_countable() instead', E_USER_WARNING);
|
||||
return word_is_countable($word);
|
||||
}
|
||||
}
|
76
system/helpers/language_helper.php
Normal file
76
system/helpers/language_helper.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Language Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/language_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('lang'))
|
||||
{
|
||||
/**
|
||||
* Lang
|
||||
*
|
||||
* Fetches a language variable and optionally outputs a form label
|
||||
*
|
||||
* @param string $line The language line
|
||||
* @param string $for The "for" value (id of the form element)
|
||||
* @param array $attributes Any additional HTML attributes
|
||||
* @return string
|
||||
*/
|
||||
function lang($line, $for = '', $attributes = array())
|
||||
{
|
||||
$line = get_instance()->lang->line($line);
|
||||
|
||||
if ($for !== '')
|
||||
{
|
||||
$line = '<label for="'.$for.'"'._stringify_attributes($attributes).'>'.$line.'</label>';
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
}
|
95
system/helpers/number_helper.php
Normal file
95
system/helpers/number_helper.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Number Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/number_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('byte_format'))
|
||||
{
|
||||
/**
|
||||
* Formats a numbers as bytes, based on size, and adds the appropriate suffix
|
||||
*
|
||||
* @param mixed will be cast as int
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
function byte_format($num, $precision = 1)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$CI->lang->load('number');
|
||||
|
||||
if ($num >= 1000000000000)
|
||||
{
|
||||
$num = round($num / 1099511627776, $precision);
|
||||
$unit = $CI->lang->line('terabyte_abbr');
|
||||
}
|
||||
elseif ($num >= 1000000000)
|
||||
{
|
||||
$num = round($num / 1073741824, $precision);
|
||||
$unit = $CI->lang->line('gigabyte_abbr');
|
||||
}
|
||||
elseif ($num >= 1000000)
|
||||
{
|
||||
$num = round($num / 1048576, $precision);
|
||||
$unit = $CI->lang->line('megabyte_abbr');
|
||||
}
|
||||
elseif ($num >= 1000)
|
||||
{
|
||||
$num = round($num / 1024, $precision);
|
||||
$unit = $CI->lang->line('kilobyte_abbr');
|
||||
}
|
||||
else
|
||||
{
|
||||
$unit = $CI->lang->line('bytes');
|
||||
return number_format($num).' '.$unit;
|
||||
}
|
||||
|
||||
return number_format($num, $precision).' '.$unit;
|
||||
}
|
||||
}
|
83
system/helpers/path_helper.php
Normal file
83
system/helpers/path_helper.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Path Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/path_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('set_realpath'))
|
||||
{
|
||||
/**
|
||||
* Set Realpath
|
||||
*
|
||||
* @param string
|
||||
* @param bool checks to see if the path exists
|
||||
* @return string
|
||||
*/
|
||||
function set_realpath($path, $check_existance = FALSE)
|
||||
{
|
||||
// Security check to make sure the path is NOT a URL. No remote file inclusion!
|
||||
if (preg_match('#^(http:\/\/|https:\/\/|www\.|ftp|php:\/\/)#i', $path) OR filter_var($path, FILTER_VALIDATE_IP) === $path)
|
||||
{
|
||||
show_error('The path you submitted must be a local server path, not a URL');
|
||||
}
|
||||
|
||||
// Resolve the path
|
||||
if (realpath($path) !== FALSE)
|
||||
{
|
||||
$path = realpath($path);
|
||||
}
|
||||
elseif ($check_existance && ! is_dir($path) && ! is_file($path))
|
||||
{
|
||||
show_error('Not a valid path: '.$path);
|
||||
}
|
||||
|
||||
// Add a trailing slash, if this is a directory
|
||||
return is_dir($path) ? rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $path;
|
||||
}
|
||||
}
|
138
system/helpers/security_helper.php
Normal file
138
system/helpers/security_helper.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Security Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/security_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('xss_clean'))
|
||||
{
|
||||
/**
|
||||
* XSS Filtering
|
||||
*
|
||||
* @param string
|
||||
* @param bool whether or not the content is an image file
|
||||
* @return string
|
||||
*/
|
||||
function xss_clean($str, $is_image = FALSE)
|
||||
{
|
||||
return get_instance()->security->xss_clean($str, $is_image);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('sanitize_filename'))
|
||||
{
|
||||
/**
|
||||
* Sanitize Filename
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function sanitize_filename($filename)
|
||||
{
|
||||
return get_instance()->security->sanitize_filename($filename);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('do_hash'))
|
||||
{
|
||||
/**
|
||||
* Hash encode a string
|
||||
*
|
||||
* @todo Remove in version 3.1+.
|
||||
* @deprecated 3.0.0 Use PHP's native hash() instead.
|
||||
* @param string $str
|
||||
* @param string $type = 'sha1'
|
||||
* @return string
|
||||
*/
|
||||
function do_hash($str, $type = 'sha1')
|
||||
{
|
||||
if ( ! in_array(strtolower($type), hash_algos()))
|
||||
{
|
||||
$type = 'md5';
|
||||
}
|
||||
|
||||
return hash($type, $str);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('strip_image_tags'))
|
||||
{
|
||||
/**
|
||||
* Strip Image Tags
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function strip_image_tags($str)
|
||||
{
|
||||
return get_instance()->security->strip_image_tags($str);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('encode_php_tags'))
|
||||
{
|
||||
/**
|
||||
* Convert PHP tags to entities
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function encode_php_tags($str)
|
||||
{
|
||||
return str_replace(array('<?', '?>'), array('<?', '?>'), $str);
|
||||
}
|
||||
}
|
256
system/helpers/smiley_helper.php
Normal file
256
system/helpers/smiley_helper.php
Normal file
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Smiley Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/smiley_helper.html
|
||||
* @deprecated 3.0.0 This helper is too specific for CI.
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('smiley_js'))
|
||||
{
|
||||
/**
|
||||
* Smiley Javascript
|
||||
*
|
||||
* Returns the javascript required for the smiley insertion. Optionally takes
|
||||
* an array of aliases to loosely couple the smiley array to the view.
|
||||
*
|
||||
* @param mixed alias name or array of alias->field_id pairs
|
||||
* @param string field_id if alias name was passed in
|
||||
* @param bool
|
||||
* @return array
|
||||
*/
|
||||
function smiley_js($alias = '', $field_id = '', $inline = TRUE)
|
||||
{
|
||||
static $do_setup = TRUE;
|
||||
$r = '';
|
||||
|
||||
if ($alias !== '' && ! is_array($alias))
|
||||
{
|
||||
$alias = array($alias => $field_id);
|
||||
}
|
||||
|
||||
if ($do_setup === TRUE)
|
||||
{
|
||||
$do_setup = FALSE;
|
||||
$m = array();
|
||||
|
||||
if (is_array($alias))
|
||||
{
|
||||
foreach ($alias as $name => $id)
|
||||
{
|
||||
$m[] = '"'.$name.'" : "'.$id.'"';
|
||||
}
|
||||
}
|
||||
|
||||
$m = '{'.implode(',', $m).'}';
|
||||
|
||||
$r .= <<<EOF
|
||||
var smiley_map = {$m};
|
||||
|
||||
function insert_smiley(smiley, field_id) {
|
||||
var el = document.getElementById(field_id), newStart;
|
||||
|
||||
if ( ! el && smiley_map[field_id]) {
|
||||
el = document.getElementById(smiley_map[field_id]);
|
||||
|
||||
if ( ! el)
|
||||
return false;
|
||||
}
|
||||
|
||||
el.focus();
|
||||
smiley = " " + smiley;
|
||||
|
||||
if ('selectionStart' in el) {
|
||||
newStart = el.selectionStart + smiley.length;
|
||||
|
||||
el.value = el.value.substr(0, el.selectionStart) +
|
||||
smiley +
|
||||
el.value.substr(el.selectionEnd, el.value.length);
|
||||
el.setSelectionRange(newStart, newStart);
|
||||
}
|
||||
else if (document.selection) {
|
||||
document.selection.createRange().text = smiley;
|
||||
}
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
elseif (is_array($alias))
|
||||
{
|
||||
foreach ($alias as $name => $id)
|
||||
{
|
||||
$r .= 'smiley_map["'.$name.'"] = "'.$id."\";\n";
|
||||
}
|
||||
}
|
||||
|
||||
return ($inline)
|
||||
? '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'
|
||||
: $r;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_clickable_smileys'))
|
||||
{
|
||||
/**
|
||||
* Get Clickable Smileys
|
||||
*
|
||||
* Returns an array of image tag links that can be clicked to be inserted
|
||||
* into a form field.
|
||||
*
|
||||
* @param string the URL to the folder containing the smiley images
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
function get_clickable_smileys($image_url, $alias = '')
|
||||
{
|
||||
// For backward compatibility with js_insert_smiley
|
||||
if (is_array($alias))
|
||||
{
|
||||
$smileys = $alias;
|
||||
}
|
||||
elseif (FALSE === ($smileys = _get_smiley_array()))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Add a trailing slash to the file path if needed
|
||||
$image_url = rtrim($image_url, '/').'/';
|
||||
|
||||
$used = array();
|
||||
foreach ($smileys as $key => $val)
|
||||
{
|
||||
// Keep duplicates from being used, which can happen if the
|
||||
// mapping array contains multiple identical replacements. For example:
|
||||
// :-) and :) might be replaced with the same image so both smileys
|
||||
// will be in the array.
|
||||
if (isset($used[$smileys[$key][0]]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$link[] = '<a href="javascript:void(0);" onclick="insert_smiley(\''.$key.'\', \''.$alias.'\')"><img src="'.$image_url.$smileys[$key][0].'" alt="'.$smileys[$key][3].'" style="width: '.$smileys[$key][1].'; height: '.$smileys[$key][2].'; border: 0;" /></a>';
|
||||
$used[$smileys[$key][0]] = TRUE;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('parse_smileys'))
|
||||
{
|
||||
/**
|
||||
* Parse Smileys
|
||||
*
|
||||
* Takes a string as input and swaps any contained smileys for the actual image
|
||||
*
|
||||
* @param string the text to be parsed
|
||||
* @param string the URL to the folder containing the smiley images
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
function parse_smileys($str = '', $image_url = '', $smileys = NULL)
|
||||
{
|
||||
if ($image_url === '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())))
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
// Add a trailing slash to the file path if needed
|
||||
$image_url = rtrim($image_url, '/').'/';
|
||||
|
||||
foreach ($smileys as $key => $val)
|
||||
{
|
||||
$str = str_replace($key, '<img src="'.$image_url.$smileys[$key][0].'" alt="'.$smileys[$key][3].'" style="width: '.$smileys[$key][1].'; height: '.$smileys[$key][2].'; border: 0;" />', $str);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('_get_smiley_array'))
|
||||
{
|
||||
/**
|
||||
* Get Smiley Array
|
||||
*
|
||||
* Fetches the config/smiley.php file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function _get_smiley_array()
|
||||
{
|
||||
static $_smileys;
|
||||
|
||||
if ( ! is_array($_smileys))
|
||||
{
|
||||
if (file_exists(APPPATH.'config/smileys.php'))
|
||||
{
|
||||
include(APPPATH.'config/smileys.php');
|
||||
}
|
||||
|
||||
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
|
||||
{
|
||||
include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
|
||||
}
|
||||
|
||||
if (empty($smileys) OR ! is_array($smileys))
|
||||
{
|
||||
$_smileys = array();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$_smileys = $smileys;
|
||||
}
|
||||
|
||||
return $_smileys;
|
||||
}
|
||||
}
|
305
system/helpers/string_helper.php
Normal file
305
system/helpers/string_helper.php
Normal file
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter String Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/string_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('trim_slashes'))
|
||||
{
|
||||
/**
|
||||
* Trim Slashes
|
||||
*
|
||||
* Removes any leading/trailing slashes from a string:
|
||||
*
|
||||
* /this/that/theother/
|
||||
*
|
||||
* becomes:
|
||||
*
|
||||
* this/that/theother
|
||||
*
|
||||
* @todo Remove in version 3.1+.
|
||||
* @deprecated 3.0.0 This is just an alias for PHP's native trim()
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function trim_slashes($str)
|
||||
{
|
||||
return trim($str, '/');
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('strip_slashes'))
|
||||
{
|
||||
/**
|
||||
* Strip Slashes
|
||||
*
|
||||
* Removes slashes contained in a string or in an array
|
||||
*
|
||||
* @param mixed string or array
|
||||
* @return mixed string or array
|
||||
*/
|
||||
function strip_slashes($str)
|
||||
{
|
||||
if ( ! is_array($str))
|
||||
{
|
||||
return stripslashes($str);
|
||||
}
|
||||
|
||||
foreach ($str as $key => $val)
|
||||
{
|
||||
$str[$key] = strip_slashes($val);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('strip_quotes'))
|
||||
{
|
||||
/**
|
||||
* Strip Quotes
|
||||
*
|
||||
* Removes single and double quotes from a string
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function strip_quotes($str)
|
||||
{
|
||||
return str_replace(array('"', "'"), '', $str);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('quotes_to_entities'))
|
||||
{
|
||||
/**
|
||||
* Quotes to Entities
|
||||
*
|
||||
* Converts single and double quotes to entities
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function quotes_to_entities($str)
|
||||
{
|
||||
return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('reduce_double_slashes'))
|
||||
{
|
||||
/**
|
||||
* Reduce Double Slashes
|
||||
*
|
||||
* Converts double slashes in a string to a single slash,
|
||||
* except those found in http://
|
||||
*
|
||||
* http://www.some-site.com//index.php
|
||||
*
|
||||
* becomes:
|
||||
*
|
||||
* http://www.some-site.com/index.php
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function reduce_double_slashes($str)
|
||||
{
|
||||
return preg_replace('#(^|[^:])//+#', '\\1/', $str);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('reduce_multiples'))
|
||||
{
|
||||
/**
|
||||
* Reduce Multiples
|
||||
*
|
||||
* Reduces multiple instances of a particular character. Example:
|
||||
*
|
||||
* Fred, Bill,, Joe, Jimmy
|
||||
*
|
||||
* becomes:
|
||||
*
|
||||
* Fred, Bill, Joe, Jimmy
|
||||
*
|
||||
* @param string
|
||||
* @param string the character you wish to reduce
|
||||
* @param bool TRUE/FALSE - whether to trim the character from the beginning/end
|
||||
* @return string
|
||||
*/
|
||||
function reduce_multiples($str, $character = ',', $trim = FALSE)
|
||||
{
|
||||
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
|
||||
return ($trim === TRUE) ? trim($str, $character) : $str;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('random_string'))
|
||||
{
|
||||
/**
|
||||
* Create a "Random" String
|
||||
*
|
||||
* @param string type of random string. basic, alpha, alnum, numeric, nozero, unique, md5, encrypt and sha1
|
||||
* @param int number of characters
|
||||
* @return string
|
||||
*/
|
||||
function random_string($type = 'alnum', $len = 8)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'basic':
|
||||
return mt_rand();
|
||||
case 'alnum':
|
||||
case 'numeric':
|
||||
case 'nozero':
|
||||
case 'alpha':
|
||||
switch ($type)
|
||||
{
|
||||
case 'alpha':
|
||||
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
break;
|
||||
case 'alnum':
|
||||
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
break;
|
||||
case 'numeric':
|
||||
$pool = '0123456789';
|
||||
break;
|
||||
case 'nozero':
|
||||
$pool = '123456789';
|
||||
break;
|
||||
}
|
||||
return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len);
|
||||
case 'unique': // todo: remove in 3.1+
|
||||
case 'md5':
|
||||
return md5(uniqid(mt_rand()));
|
||||
case 'encrypt': // todo: remove in 3.1+
|
||||
case 'sha1':
|
||||
return sha1(uniqid(mt_rand(), TRUE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('increment_string'))
|
||||
{
|
||||
/**
|
||||
* Add's _1 to a string or increment the ending number to allow _2, _3, etc
|
||||
*
|
||||
* @param string required
|
||||
* @param string What should the duplicate number be appended with
|
||||
* @param string Which number should be used for the first dupe increment
|
||||
* @return string
|
||||
*/
|
||||
function increment_string($str, $separator = '_', $first = 1)
|
||||
{
|
||||
preg_match('/(.+)'.preg_quote($separator, '/').'([0-9]+)$/', $str, $match);
|
||||
return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('alternator'))
|
||||
{
|
||||
/**
|
||||
* Alternator
|
||||
*
|
||||
* Allows strings to be alternated. See docs...
|
||||
*
|
||||
* @param string (as many parameters as needed)
|
||||
* @return string
|
||||
*/
|
||||
function alternator()
|
||||
{
|
||||
static $i;
|
||||
|
||||
if (func_num_args() === 0)
|
||||
{
|
||||
$i = 0;
|
||||
return '';
|
||||
}
|
||||
|
||||
$args = func_get_args();
|
||||
return $args[($i++ % count($args))];
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('repeater'))
|
||||
{
|
||||
/**
|
||||
* Repeater function
|
||||
*
|
||||
* @todo Remove in version 3.1+.
|
||||
* @deprecated 3.0.0 This is just an alias for PHP's native str_repeat()
|
||||
*
|
||||
* @param string $data String to repeat
|
||||
* @param int $num Number of repeats
|
||||
* @return string
|
||||
*/
|
||||
function repeater($data, $num = 1)
|
||||
{
|
||||
return ($num > 0) ? str_repeat($data, $num) : '';
|
||||
}
|
||||
}
|
568
system/helpers/text_helper.php
Normal file
568
system/helpers/text_helper.php
Normal file
File diff suppressed because it is too large
Load Diff
105
system/helpers/typography_helper.php
Normal file
105
system/helpers/typography_helper.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter Typography Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/typography_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('nl2br_except_pre'))
|
||||
{
|
||||
/**
|
||||
* Convert newlines to HTML line breaks except within PRE tags
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function nl2br_except_pre($str)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$CI->load->library('typography');
|
||||
return $CI->typography->nl2br_except_pre($str);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('auto_typography'))
|
||||
{
|
||||
/**
|
||||
* Auto Typography Wrapper Function
|
||||
*
|
||||
* @param string $str
|
||||
* @param bool $reduce_linebreaks = FALSE whether to reduce multiple instances of double newlines to two
|
||||
* @return string
|
||||
*/
|
||||
function auto_typography($str, $reduce_linebreaks = FALSE)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$CI->load->library('typography');
|
||||
return $CI->typography->auto_typography($str, $reduce_linebreaks);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('entity_decode'))
|
||||
{
|
||||
/**
|
||||
* HTML Entities Decode
|
||||
*
|
||||
* This function is a replacement for html_entity_decode()
|
||||
*
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function entity_decode($str, $charset = NULL)
|
||||
{
|
||||
return get_instance()->security->entity_decode($str, $charset);
|
||||
}
|
||||
}
|
570
system/helpers/url_helper.php
Normal file
570
system/helpers/url_helper.php
Normal file
File diff suppressed because it is too large
Load Diff
91
system/helpers/xml_helper.php
Normal file
91
system/helpers/xml_helper.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 - 2022, CodeIgniter Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
|
||||
* @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CodeIgniter XML Helpers
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/userguide3/helpers/xml_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('xml_convert'))
|
||||
{
|
||||
/**
|
||||
* Convert Reserved XML characters to Entities
|
||||
*
|
||||
* @param string
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
function xml_convert($str, $protect_all = FALSE)
|
||||
{
|
||||
$temp = '__TEMP_AMPERSANDS__';
|
||||
|
||||
// Replace entities to temporary markers so that
|
||||
// ampersands won't get messed up
|
||||
$str = preg_replace('/&#(\d+);/', $temp.'\\1;', $str);
|
||||
|
||||
if ($protect_all === TRUE)
|
||||
{
|
||||
$str = preg_replace('/&(\w+);/', $temp.'\\1;', $str);
|
||||
}
|
||||
|
||||
$str = str_replace(
|
||||
array('&', '<', '>', '"', "'", '-'),
|
||||
array('&', '<', '>', '"', ''', '-'),
|
||||
$str
|
||||
);
|
||||
|
||||
// Decode the temp markers back to entities
|
||||
$str = preg_replace('/'.$temp.'(\d+);/', '&#\\1;', $str);
|
||||
|
||||
if ($protect_all === TRUE)
|
||||
{
|
||||
return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user