Add (article): ai gen, front views

This commit is contained in:
2023-09-24 22:53:40 +08:00
parent 18705bd5e4
commit 322d680961
115 changed files with 9710 additions and 201 deletions

View File

@@ -0,0 +1,46 @@
<?php
if (! function_exists('get_current_ip')) {
function get_current_ip()
{
$ip = null;
if (app()->environment() == 'local') {
return config('platform.general.dev_default_ip');
}
if (getenv('HTTP_CF_CONNECTING_IP')) {
$ip = getenv('HTTP_CF_CONNECTING_IP');
} elseif (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
if (! is_empty($ip)) {
return $ip;
}
$ip_add_set = null;
if (getenv('HTTP_CLIENT_IP')) {
$ip_add_set = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip_add_set = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_X_FORWARDED')) {
$ip_add_set = getenv('HTTP_X_FORWARDED');
} elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip_add_set = getenv('HTTP_FORWARDED_FOR');
} elseif (getenv('HTTP_FORWARDED')) {
$ip_add_set = getenv('HTTP_FORWARDED');
} elseif (getenv('REMOTE_ADDR')) {
$ip_add_set = getenv('REMOTE_ADDR');
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
$ip_add_set = $_SERVER['REMOTE_ADDR'];
} else {
$ip_add_set = '127.0.0.0';
}
$ip_add_set = explode(',', $ip_add_set);
return $ip_add_set[0];
}
}

View File

@@ -0,0 +1,5 @@
<?php
require 'string_helper.php';
require 'geo_helper.php';
require 'platform_helper.php';

View File

@@ -0,0 +1,13 @@
<?php
if (! function_exists('get_slack_channel_by_env')) {
function get_slack_channel_by_env($slack_channel = 'slack')
{
if (app()->environment() == 'local') {
return config("platform.notifications.{$slack_channel}.development_channel");
} else {
return config("platform.notifications.{$slack_channel}.production_channel");
}
}
}

View File

@@ -0,0 +1,120 @@
<?php
use Illuminate\Support\Str;
if (! function_exists('epoch_now_timestamp')) {
function epoch_now_timestamp()
{
return (int) round(microtime(true) * 1000);
}
}
if (! function_exists('unslug')) {
function unslug($slug, $delimiter = '-')
{
return ucwords(str_replace($delimiter, ' ', $slug));
}
}
if (! function_exists('str_slug')) {
function str_slug($string, $delimiter = '-')
{
return Str::of(trim($string))->slug($delimiter);
}
}
if (! function_exists('str_first_sentence')) {
function str_first_sentence($str)
{
// Split the string at ., !, or ?
$sentences = preg_split('/(\.|!|\?)(\s|$)/', $str, 2);
// Return the first part of the array if available
if (isset($sentences[0])) {
return trim($sentences[0]);
}
// If no sentence ending found, return the whole string
return $str;
}
}
if (! function_exists('is_empty')) {
/**
* A better function to check if a value is empty or null. Strings, arrays, and Objects are supported.
*
* @param mixed $value
*/
function is_empty($value): bool
{
if (is_null($value)) {
return true;
}
if (is_string($value)) {
if ($value === '') {
return true;
}
}
if (is_array($value)) {
if (count($value) === 0) {
return true;
}
}
if (is_object($value)) {
$value = (array) $value;
if (count($value) === 0) {
return true;
}
}
return false;
}
}
if (! function_exists('get_country_name_by_iso')) {
function get_country_name_by_iso($country_iso)
{
if (! is_empty($country_iso)) {
$country_iso = strtoupper($country_iso);
try {
return config("platform.country_codes.{$country_iso}")['name'];
} catch (\Exception $e) {
}
}
return 'International';
}
}
if (! function_exists('get_country_emoji_by_iso')) {
function get_country_emoji_by_iso($country_iso)
{
if (! is_empty($country_iso)) {
$country_iso = strtoupper($country_iso);
try {
return config("platform.country_codes.{$country_iso}")['emoji'];
} catch (\Exception $e) {
}
}
return '🌎';
}
}
if (! function_exists('str_random')) {
function str_random($length = 10)
{
return Str::random($length);
}
}