Skip to content

Commit

Permalink
Merge pull request #35 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Update mbstring
  • Loading branch information
nguyenanhung authored Aug 7, 2023
2 parents 3ea582b + c7d7016 commit b124fe7
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 131 deletions.
12 changes: 6 additions & 6 deletions helpers/alphaid_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@ function generateAlphaId($in, $to_num = false, $pad_up = false, $passKey = null)
// with this patch by Simon Franz (http://blog.snaky.org/)
// you can optionally supply a password to make it harder
// to calculate the corresponding numeric ID
$indexLen = strlen($index);
$indexLen = mb_strlen($index);
for ($n = 0; $n < $indexLen; $n++) {
$i[] = $index[$n];
}
$passHash = hash('sha256', $passKey);
$passHash = (strlen($passHash) < strlen($index)) ? hash('sha512', $passKey) : $passHash;
$passHash = (mb_strlen($passHash) < mb_strlen($index)) ? hash('sha512', $passKey) : $passHash;

for ($n = 0; $n < $indexLen; $n++) {
$p[] = $passHash[$n];
}
array_multisort($p, SORT_DESC, $i);
$index = implode($i);
}
$base = strlen($index);
$base = mb_strlen($index);
if ($to_num) {
// Digital number <<-- alphabet letter code
$in = strrev($in);
$out = 0;
$len = strlen($in) - 1;
$len = mb_strlen($in) - 1;
for ($t = 0; $t <= $len; $t++) {
$pow = $base ** ($len - $t);
$out = $out + strpos($index, $in[$t]) * $pow;
$out = $out + mb_strpos($index, $in[$t]) * $pow;
}
if (is_numeric($pad_up)) {
$pad_up--;
Expand All @@ -104,7 +104,7 @@ function generateAlphaId($in, $to_num = false, $pad_up = false, $passKey = null)
}
}
$out = sprintf('%F', $out);
$out = substr($out, 0, strpos($out, '.'));
$out = mb_substr($out, 0, mb_strpos($out, '.'));
} else {
// Digital number -->> alphabet letter code
if (is_numeric($pad_up)) {
Expand Down
20 changes: 10 additions & 10 deletions helpers/assets_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
function assets_url($uri = '', $protocol = null)
{
if (function_exists('base_url') && function_exists('config_item')) {
$fileExt = substr(trim($uri), strrpos(trim($uri), '.') + 1);
$fileExt = strtoupper($fileExt);
$fileExt = mb_substr(trim($uri), mb_strrpos(trim($uri), '.') + 1);
$fileExt = mb_strtoupper($fileExt);
$version = '';
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
Expand All @@ -50,8 +50,8 @@ function assets_url($uri = '', $protocol = null)
function static_url($uri = '')
{
if (function_exists('base_url') && function_exists('config_item')) {
$fileExt = substr(trim($uri), strrpos(trim($uri), '.') + 1);
$fileExt = strtoupper($fileExt);
$fileExt = mb_substr(trim($uri), mb_strrpos(trim($uri), '.') + 1);
$fileExt = mb_strtoupper($fileExt);
$version = '';
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
Expand Down Expand Up @@ -80,8 +80,8 @@ function static_url($uri = '')
function templates_url($uri = '', $protocol = null)
{
if (function_exists('base_url') && function_exists('config_item')) {
$fileExt = substr(trim($uri), strrpos(trim($uri), '.') + 1);
$fileExt = strtoupper($fileExt);
$fileExt = mb_substr(trim($uri), mb_strrpos(trim($uri), '.') + 1);
$fileExt = mb_strtoupper($fileExt);
$version = '';
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
Expand Down Expand Up @@ -180,8 +180,8 @@ function favicon_html_tag($baseUrl = '')
function storage_url($uri = '')
{
if (function_exists('config_item')) {
$fileExt = substr(trim($uri), strrpos(trim($uri), '.') + 1);
$fileExt = strtoupper($fileExt);
$fileExt = mb_substr(trim($uri), mb_strrpos(trim($uri), '.') + 1);
$fileExt = mb_strtoupper($fileExt);
$version = '';
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
Expand Down Expand Up @@ -209,8 +209,8 @@ function storage_url($uri = '')
function public_storage_tmp_url($uri = '', $protocol = null)
{
if (function_exists('base_url') && function_exists('config_item')) {
$fileExt = substr(trim($uri), strrpos(trim($uri), '.') + 1);
$fileExt = strtoupper($fileExt);
$fileExt = mb_substr(trim($uri), mb_strrpos(trim($uri), '.') + 1);
$fileExt = mb_strtoupper($fileExt);
$version = '';
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
Expand Down
4 changes: 0 additions & 4 deletions helpers/database_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@
function generate_list_id_with_parent_id($allSubId, $parentId, $field = 'id')
{
if (is_array($allSubId) || is_object($allSubId)) {

// Xác định lấy toàn bộ tin tức ở các category con
$countSub = count($allSubId); // Đếm bảng ghi Category con

if ($countSub) {

// Nếu tồn tại các category con
$listSub = array();
$listSub[] = $parentId; // Push category cha

foreach ($allSubId as $item) {
$itemId = is_array($item) ? $item[$field] : $item->$field;
$listSub[] = $itemId; // Push các category con vào mảng dữ liệu
Expand Down
4 changes: 2 additions & 2 deletions helpers/download_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function download_file_chunked($path)
//$mime_type = finfo_file($finfo, $path); //For remote file, it may not work
$mime_type = mime_type($file_name);

$attachment = (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) ? "" : " attachment"; // IE 5.5 fix.
$attachment = (mb_strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) ? "" : " attachment"; // IE 5.5 fix.

// send the headers
header("Content-Type: $mime_type");
Expand Down Expand Up @@ -74,7 +74,7 @@ function download_large_file($path)
//$mime_type = finfo_file($finfo, $path); //For remote file, it may not work
$mime_type = mime_type($file_name);

$attachment = (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) ? "" : " attachment"; // IE 5.5 fix.
$attachment = (mb_strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) ? "" : " attachment"; // IE 5.5 fix.

// send the headers
header("Content-Type: $mime_type");
Expand Down
4 changes: 2 additions & 2 deletions helpers/file_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function write_file($path, $data, $mode = 'wb')

flock($fp, LOCK_EX);

for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) {
if (($result = fwrite($fp, substr($data, $written))) === false) {
for ($result = $written = 0, $length = mb_strlen($data); $written < $length; $written += $result) {
if (($result = fwrite($fp, mb_substr($data, $written))) === false) {
break;
}
}
Expand Down
20 changes: 18 additions & 2 deletions helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function meta_property($property = '', $content = '', $type = 'property', $newli
*/
function tachPage($input)
{
if (empty($input)) {
return $input;
}
preg_match('/(.*)-c(.*).html/U', $input, $output);

return $output[1];
Expand All @@ -95,6 +98,9 @@ function tachPage($input)
*/
function stripHtmlTag($str)
{
if (empty($str)) {
return $str;
}
$regEx = '/([^<]*<\s*[a-z](?:[0-9]|[a-z]{0,9}))(?:(?:\s*[a-z\-]{2,14}\s*=\s*(?:"[^"]*"|\'[^\']*\'))*)(\s*\/?>[^<]*)/i';
$chunks = preg_split($regEx, $str, -1, PREG_SPLIT_DELIM_CAPTURE);
$chunkCount = count($chunks);
Expand All @@ -121,10 +127,14 @@ function stripHtmlTag($str)
*/
function strip_only_tags($str, $tags, $stripContent = false)
{
if (empty($str)) {
return $str;
}

$content = '';

if (!is_array($tags)) {
$tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
$tags = (mb_strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
if (end($tags) === '') {
array_pop($tags);
}
Expand Down Expand Up @@ -155,6 +165,9 @@ function strip_only_tags($str, $tags, $stripContent = false)
*/
function tracking_google_analytics($analytics_id = '', $analytics_mode = 'auto')
{
if (empty($analytics_id)) {
return $analytics_id;
}
$html = "<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down Expand Up @@ -182,6 +195,9 @@ function tracking_google_analytics($analytics_id = '', $analytics_mode = 'auto')
*/
function tracking_google_gtag_analytics_default($ID = '')
{
if (empty($ID)) {
return $ID;
}
$html = "<!-- Global site tag (gtag.js) - Google Analytics -->" . PHP_EOL;
$html .= "<script async src='https://www.googletagmanager.com/gtag/js?id=" . trim($ID) . "'></script>" . PHP_EOL;
$html .= "<script>
Expand Down Expand Up @@ -223,7 +239,7 @@ function html_tag($tag, $attr = array(), $content = false)
$html .= (!empty($attr)) ? ' ' . (is_array($attr) ? arrayToAttributes($attr) : $attr) : '';

// a void element?
if (in_array(strtolower($tag), $void_elements)) {
if (in_array(mb_strtolower($tag), $void_elements)) {
// these can not have content
$html .= ' />';
} else {
Expand Down
2 changes: 0 additions & 2 deletions helpers/meta_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ function setupMetaDnsPrefetch($dns = '')
$domain = trim($domain, '/');
$html .= "<link href='//" . $domain . "/' rel='dns-prefetch' />" . PHP_EOL;
}

return $html;
}
$dns = str_replace(array('https://', 'http://'), '', $dns);
$dns = trim($dns, '/');

return "<link href='//" . $dns . "/' rel='dns-prefetch' />" . PHP_EOL;
}
}
14 changes: 7 additions & 7 deletions helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ function convertNumberToWords($num)
if ($i < 20) {
$returnTxt .= $ones[$i];
} elseif ($i < 100) {
$returnTxt .= $tens[substr($i, 0, 1)];
$returnTxt .= " " . $ones[substr($i, 1, 1)];
$returnTxt .= $tens[mb_substr($i, 0, 1)];
$returnTxt .= " " . $ones[mb_substr($i, 1, 1)];
} else {
$returnTxt .= $ones[substr($i, 0, 1)] . " " . $hundreds[0];
$returnTxt .= " " . $tens[substr($i, 1, 1)];
$returnTxt .= " " . $ones[substr($i, 2, 1)];
$returnTxt .= $ones[mb_substr($i, 0, 1)] . " " . $hundreds[0];
$returnTxt .= " " . $tens[mb_substr($i, 1, 1)];
$returnTxt .= " " . $ones[mb_substr($i, 2, 1)];
}
if ($key > 0) {
$returnTxt .= " " . $hundreds[$key] . " ";
Expand All @@ -79,8 +79,8 @@ function convertNumberToWords($num)
if ($decnum < 20) {
$returnTxt .= $ones[$decnum];
} elseif ($decnum < 100) {
$returnTxt .= $tens[substr($decnum, 0, 1)];
$returnTxt .= " " . $ones[substr($decnum, 1, 1)];
$returnTxt .= $tens[mb_substr($decnum, 0, 1)];
$returnTxt .= " " . $ones[mb_substr($decnum, 1, 1)];
}
}

Expand Down
1 change: 0 additions & 1 deletion helpers/placeholder_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function placeholder_img($size = '300x250', $bg_color = '', $text_color = '', $t
$text = '/' . $text;
}
$link = trim($domain) . trim($size) . trim($bg_color) . trim($text_color) . trim($text);

return '<img alt="Place-Holder" title="Place Holder" src="' . $link . '">';
}
}
10 changes: 5 additions & 5 deletions helpers/request_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
function sendSimpleGetRequest($url = '', $data = array(), $method = 'GET')
{
$method = strtoupper($method);
$method = mb_strtoupper($method);
if ((!empty($data) && (is_array($data) || is_object($data)))) {
$target = $url . '?' . http_build_query($data);
} else {
Expand Down Expand Up @@ -121,7 +121,7 @@ function bear_post_async_request($url, $params, $headers = array())
$out .= "User-Agent: BEAR Framework\r\n";
$out .= "Referer: " . $referer . "\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: " . strlen($post_string) . "\r\n";
$out .= "Content-Length: " . mb_strlen($post_string) . "\r\n";
if (!empty($headers)) {
foreach ($headers as $key => $value) {
$out .= $key . ": " . $value . "\r\n";
Expand All @@ -144,18 +144,18 @@ function bear_post_async_request($url, $params, $headers = array())
*
* @param $url
*
* @return false|int|string
* @return int|string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 24/02/2023 06:51
* @time : 07/08/2023 42:35
*/
function get_http_response_code($url = '')
{
$uri = $url;
if ($uri !== '') {
$headers = get_headers($uri);

return substr($headers[0], 9, 3);
return mb_substr($headers[0], 9, 3);
}

return 200;
Expand Down
4 changes: 2 additions & 2 deletions helpers/security_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function xssValidation($value)

$search = '/&#[xX]0{0,8}(21|22|23|24|25|26|27|28|29|2a|2b|2d|2f|30|31|32|33|34|35|36|37|38|39|3a|3b|3d|3f|40|41|42|43|44|45|46|47|48|49|4a|4b|4c|4d|4e|4f|50|51|52|53|54|55|56|57|58|59|5a|5b|5c|5d|5e|5f|60|61|62|63|64|65|66|67|68|69|6a|6b|6c|6d|6e|6f|70|71|72|73|74|75|76|77|78|79|7a|7b|7c|7d|7e);?/i';
$value = preg_replace_callback($search, static function ($m) {
return chr(hexdec($m[1]));
return mb_chr(hexdec($m[1]));
}, $value);

$search = '/&#0{0,8}(33|34|35|36|37|38|39|40|41|42|43|45|47|48|49|50|51|52|53|54|55|56|57|58|59|61|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126);?/i';
$value = preg_replace_callback($search, static function ($m) {
return chr($m[1]);
return mb_chr($m[1]);
}, $value);

$search = array(
Expand Down
8 changes: 5 additions & 3 deletions helpers/sentry_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ function log_to_sentry($message, $context, $name = 'hungng')
try {
$CI =& get_instance();
$CI->load->config('config_sentry');

// Init config sentry
$config = config_item('config_sentry');

// Init logger use Monolog
$logger = new Monolog\Logger($name);
$client = Sentry\ClientBuilder::create(array('dsn' => $config['dsn']))->getClient();
Expand All @@ -41,7 +39,11 @@ function log_to_sentry($message, $context, $name = 'hungng')

return true;
} catch (Exception $e) {
return __get_error_message__($e);
$errorMsg = __get_error_message__($e);
if (function_exists('log_message')) {
log_message('error', $errorMsg);
}
return $errorMsg;
}
}
}
Loading

0 comments on commit b124fe7

Please sign in to comment.