This commit is contained in:
2023-11-28 04:39:36 +08:00
parent a9ac0e48b3
commit dc37274b6c
86 changed files with 2106 additions and 191 deletions

View File

@@ -3,3 +3,4 @@
require 'string_helper.php';
require 'geo_helper.php';
require 'proxy_helper.php';
require 'route_helper.php';

View File

@@ -0,0 +1,13 @@
<?php
if (! function_exists('get_route_search_result')) {
function get_route_search_result($query)
{
return route('front.search.results',
[
'query' => strtolower(urlencode($query)),
]);
}
}

View File

@@ -1,11 +1,42 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Str;
if (! function_exists('epoch_now_timestamp')) {
function epoch_now_timestamp()
if (! function_exists('dmy')) {
function dmy(Carbon $carbon)
{
return (int) round(microtime(true) * 1000);
return $carbon->format('d M Y');
}
}
if (! function_exists('epoch_now_timestamp')) {
function epoch_now_timestamp($multiplier = 1000)
{
return (int) round(microtime(true) * $multiplier);
}
}
if (! function_exists('add_params_to_url')) {
function add_params_to_url(string $url, array $newParams): string
{
$url = parse_url($url);
parse_str($url['query'] ?? '', $existingParams);
$newQuery = array_merge($existingParams, $newParams);
$newUrl = $url['scheme'].'://'.$url['host'].($url['path'] ?? '');
if ($newQuery) {
$newUrl .= '?'.http_build_query($newQuery);
}
if (isset($url['fragment'])) {
$newUrl .= '#'.$url['fragment'];
}
return $newUrl;
}
}
@@ -175,6 +206,34 @@ function str_first_sentence($str)
}
if (! function_exists('str_extract_sentences')) {
function str_extract_sentences($str, $count = 1)
{
// Split the string at ., !, or ?, including the punctuation in the result
$sentences = preg_split('/([.!?])\s*/', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$extractedSentences = [];
$currentSentence = '';
foreach ($sentences as $key => $sentence) {
if ($key % 2 == 0) {
// This is a sentence fragment
$currentSentence = $sentence;
} else {
// This is a punctuation mark
$currentSentence .= $sentence;
$extractedSentences[] = trim($currentSentence);
if (count($extractedSentences) >= $count) {
break;
}
}
}
return $extractedSentences;
}
}
if (! function_exists('unslug')) {
function unslug($slug, $delimiter = '-')
{