Skip to content

Commit

Permalink
Merge pull request #37 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Optimize Code Performance
  • Loading branch information
nguyenanhung authored Aug 15, 2023
2 parents 5e0a541 + 44c24e6 commit 0658d7f
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 94 deletions.
23 changes: 0 additions & 23 deletions helpers/assets_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ function assets_url($uri = '', $protocol = null)
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
}

return trim(base_url('assets/' . $uri, $protocol) . $version);
}

return trim($uri);

}
}
if (!function_exists('static_url')) {
Expand All @@ -57,12 +54,9 @@ function static_url($uri = '')
$version = config_item('assets_version');
}
$host = config_item('static_url');

return trim($host) . trim($uri) . trim($version);
}

return trim($uri);

}
}
if (!function_exists('templates_url')) {
Expand All @@ -86,10 +80,8 @@ function templates_url($uri = '', $protocol = null)
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
}

return trim(base_url('templates/' . $uri, $protocol) . $version);
}

return trim($uri);
}
}
Expand All @@ -108,7 +100,6 @@ function templates_url($uri = '', $protocol = null)
function editor_url($uri = '', $protocol = null)
{
$uri = 'editors/' . $uri;

return assets_url($uri, $protocol);
}
}
Expand All @@ -127,7 +118,6 @@ function editor_url($uri = '', $protocol = null)
function favicon_url($uri = '', $protocol = null)
{
$uri = 'favicon/' . $uri;

return assets_url($uri, $protocol);
}
}
Expand All @@ -146,7 +136,6 @@ function favicon_url($uri = '', $protocol = null)
function fav_url($uri = '', $protocol = null)
{
$uri = 'fav/' . $uri;

return assets_url($uri, $protocol);
}
}
Expand Down Expand Up @@ -187,10 +176,8 @@ function storage_url($uri = '')
$version = config_item('assets_version');
}
$storageUrl = trim(config_item('storage_url')) . trim($uri) . $version;

return trim($storageUrl);
}

return $uri;
}
}
Expand All @@ -215,12 +202,9 @@ function public_storage_tmp_url($uri = '', $protocol = null)
if ($fileExt === 'CSS' || $fileExt === 'JS') {
$version = config_item('assets_version');
}

return trim(base_url('storage/tmp/' . $uri, $protocol) . $version);
}

return trim($uri);

}
}
if (!function_exists('go_url')) {
Expand All @@ -238,10 +222,8 @@ function go_url($uri = '')
{
if (function_exists('config_item')) {
$goUrl = trim(config_item('go_url')) . trim($uri);

return trim($goUrl);
}

return $uri;
}
}
Expand All @@ -260,7 +242,6 @@ function go_url($uri = '')
function assets_mobile($uri = '', $protocol = null)
{
$uri = 'mobile/assets/' . $uri;

return assets_url($uri, $protocol);
}
}
Expand Down Expand Up @@ -294,7 +275,6 @@ function assets_themes($themes = '', $uri = '', $folder = 'yes', $protocol = nul
} else {
$uri = 'themes/assets/' . $uri;
}

return assets_url($uri, $protocol);
}
}
Expand Down Expand Up @@ -386,7 +366,6 @@ function assets_themes_metronic($uri = '', $protocol = null)
function cdn_js_url($uri = '')
{
$cdnJs = '//cdnjs.cloudflare.com/ajax/libs/';

return $cdnJs . trim($uri);
}
}
Expand All @@ -404,7 +383,6 @@ function cdn_js_url($uri = '')
function google_fonts_url($family = '')
{
$fonts = '//fonts.googleapis.com/css?family=';

return $fonts . trim($family);
}
}
Expand All @@ -422,7 +400,6 @@ function google_fonts_url($family = '')
function bootstrapcdn_url($uri = '')
{
$cdn = '//maxcdn.bootstrapcdn.com/bootstrap/';

return $cdn . trim($uri);
}
}
9 changes: 0 additions & 9 deletions helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,14 @@ function isEmpty($input = '')
if ($input === null || $input === false || $input === '') {
return true;
}

$isset = isset($input);

if ($isset === true) {

$empty = empty($input);

if ($empty) {
return true;
}

return false;
}

return true;
}
}
Expand All @@ -101,7 +95,6 @@ function defaultCompressHtmlOutput($html = '')
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(' ', '>', '<', '\\1');

return preg_replace($search, $replace, $html);
}
}
Expand All @@ -110,7 +103,6 @@ function generateRandomUniqueId()
{
$uniqid = uniqid('-bear-', true);
$uniqid = trim(str_replace('.', '', $uniqid));

return date('Ymd') . '-' . generate_uuid_v4() . $uniqid;
}
}
Expand All @@ -119,7 +111,6 @@ function generateRandomNanoUniqueId()
{
$uniqid = uniqid('-bear-', true);
$uniqid = trim(str_replace('.', '', $uniqid));

return date('Ymd') . '-' . randomNanoId(16) . $uniqid;
}
}
Expand Down
2 changes: 0 additions & 2 deletions helpers/database_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ function generate_list_id_with_parent_id($allSubId, $parentId, $field = 'id')
$itemId = is_array($item) ? $item[$field] : $item->$field;
$listSub[] = $itemId; // Push các category con vào mảng dữ liệu
}

return $listSub;
}
}

return $parentId;
}

Expand Down
6 changes: 0 additions & 6 deletions helpers/date_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ function dayFloor($beginTime = '', $endTime = '')
if (empty($beginTime) && empty($endTime)) {
return 0;
}

$floor = abs(strtotime($beginTime) - strtotime($endTime));

return (int) floor($floor / (60 * 60 * 24));
}
}
Expand All @@ -47,7 +45,6 @@ function getZuluTime()
if (function_exists('log_message')) {
log_message('error', __get_error_message__($e));
}

return null;
}
}
Expand Down Expand Up @@ -82,7 +79,6 @@ function smart_bear_date_range($first, $last, $step = '+1 day', $format = 'Y-m-d
$dates[] = date($format, $current);
$current = strtotime($step, $current);
}

return $dates;
}
}
Expand All @@ -100,7 +96,6 @@ function format_datetime_vn($datetime = '', $type = 'datetime')
} else {
$timestamp = strtotime($datetime);
}

return date('d-m-Y H:i:s', $timestamp);
}
}
Expand All @@ -124,7 +119,6 @@ function get_start_and_end_date_for_week($week, $year)
$return[0] = date('d-m-Y', $time);
$time += 6 * 24 * 3600;
$return[1] = date('d-m-Y', $time);

return $return;
}
}
1 change: 0 additions & 1 deletion helpers/escape_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function bear_framework_basic_clean_str($str = '')
$str = trim($str);
$str = strip_tags($str);
$str = htmlspecialchars($str, ENT_QUOTES | ENT_HTML5 | ENT_XHTML, 'UTF-8');

return trim($str);
}
}
1 change: 0 additions & 1 deletion helpers/facebook_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function widget_facebook_script_init($appId = '', $version = 'v14.0')
$version = 'v14.0';
}
$url = 'https://connect.facebook.net/vi_VN/sdk.js#xfbml=1&version=' . trim($version) . '&appId=' . trim($appId) . '&autoLogAppEvents=1';

return '<div id="fb-root"></div><script async defer crossorigin="anonymous" src="' . trim($url) . '" nonce="EOLK7Cbn"></script>';
}
}
Expand Down
8 changes: 3 additions & 5 deletions helpers/image_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,14 @@ function bear_framework_image_url($input = '', $server = '', $base = 'live')
if (in_array($images_url, $no_thumb)) {
return assets_url($images_url);
}

$parse_input = parse_url($images_url);
if (isset($parse_input['host'])) {
$parse = parse_url($images_url);
if (isset($parse['host'])) {
return $images_url;
}
if (trim(mb_substr($images_url, 0, 12)) === 'crawler-news') {
$images_url = trim('uploads/' . $images_url);
}
$images_url = str_replace(array('upload-vcms/news/news/', 'upload-vcms/mheath/mheath/'), array('upload-vcms/news/', 'upload-vcms/mheath/'), $images_url);

return config_item('static_url') . $images_url;
}

Expand Down Expand Up @@ -151,7 +149,7 @@ function create_image_thumbnail($url = '', $width = 100, $height = 100)
return nguyenanhung\CodeIgniter\BasicHelper\ImageHelper::createThumbnail($url, $width, $height);
}
}
if (!function_exists('create_image_thumbnail')) {
if (!function_exists('bear_framework_create_image_thumbnail_with_cache')) {
/**
* Function bear_framework_create_image_thumbnail_with_cache
*
Expand Down
2 changes: 0 additions & 2 deletions helpers/nanoid_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ function randomNanoId($size = 21, $prefix = 'Bear-')
{
if (class_exists('Hidehalo\Nanoid\Client')) {
$client = new Hidehalo\Nanoid\Client();

return $client->generateId($size);
}

return uniqid($prefix, true);
}
}
6 changes: 6 additions & 0 deletions helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ function convertNumberToWords($num)
return $returnTxt;
}
}
if (!function_exists('convert_number_to_words')) {
function convert_number_to_words($num)
{
return convertNumberToWords($num);
}
}
7 changes: 0 additions & 7 deletions helpers/paging_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function view_paginations($page_type, $total_item, $item_per_page, $current_page
$page_prefix = '&page=';
$page_suffix = '';
}

$data = array(
'page_type' => $page_type,
'page_link' => $page_link,
Expand All @@ -57,7 +56,6 @@ function view_paginations($page_type, $total_item, $item_per_page, $current_page
);
$pagination = new \nguyenanhung\Libraries\Pagination\Pagination\SimplePagination();
$pagination->setData($data);

return $pagination->build();
}
}
Expand Down Expand Up @@ -100,7 +98,6 @@ function view_more($page_number, $page_total, $page_size, $url = '', $title = ''
);
$pagination = new \nguyenanhung\Libraries\Pagination\Pagination\SimplePagination();
$pagination->setData($data);

return $pagination->buildViewMore();
}
}
Expand Down Expand Up @@ -149,7 +146,6 @@ function select_page($total_rows, $per_page, $page_number, $type = '', $page_lin
);
$pagination = new \nguyenanhung\Libraries\Pagination\Pagination\SimplePagination();
$pagination->setData($data);

return $pagination->buildSelectPage();
}
}
Expand All @@ -167,7 +163,6 @@ function select_page($total_rows, $per_page, $page_number, $type = '', $page_lin
function get_paginations_title($str)
{
$pagination = new \nguyenanhung\Libraries\Pagination\Pagination\SimplePagination();

return $pagination->getPaginationsTitle($str);
}
}
Expand All @@ -185,7 +180,6 @@ function get_paginations_title($str)
function get_paginations_number($str)
{
$pagination = new \nguyenanhung\Libraries\Pagination\Pagination\SimplePagination();

return $pagination->getPageNumber($str);
}
}
Expand All @@ -204,7 +198,6 @@ function bear_framework_news_view_pagination($data = array())
{
$pagination = new \nguyenanhung\Libraries\Pagination\Pagination\SimplePagination();
$pagination->setData($data);

return $pagination->build();
}
}
Loading

0 comments on commit 0658d7f

Please sign in to comment.