123movies-seo/app/Supports/Helpers.php

205 lines
5.7 KiB
PHP
Raw Normal View History

2024-08-24 23:08:42 +03:00
<?php
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Carbon;
function img_url($size, $path, $photon = true, $w = 300, $h = 450)
{
if (empty($path)) {
return asset('images/placeholder.webp');
}
if ($photon) {
// return "//i1.wp.com/image.tmdb.org/t/p/{$size}{$path}?resize=300,450";
// return "https://cdn.statically.io/img/image.tmdb.org/f=auto,q=80,w={$w},h={$h}/t/p/{$size}{$path}";
return "https://i1.wp.com/image.tmdb.org/t/p/{$size}{$path}?ssl=1&resize={$w},{$h}";
}
return "https://image.tmdb.org/t/p/{$size}{$path}";
}
function item($item)
{
if (isset($item->title)) { // is movie
$title = $item->title;
$link = route('movie', ['id' => $item->id, 'name' => Str::slug($item->title)]);
} else {
$title = $item->name;
$link = route('show', ['id' => $item->id, 'name' => Str::slug($item->name)]);
}
return (object)[
'link' => $link,
'title' => $title
];
}
function release_date($release_date)
{
return date('M d, Y', strtotime($release_date));
}
function release_date_year($release_date)
{
return date('Y', strtotime($release_date));
}
function minToHour($min, $array_in = false)
{
if ($array_in) {
if (!empty($min)) {
$min = $min[0];
} else {
return 'NA';
}
}
$d = floor($min / 1440);
$h = floor(($min - $d * 1440) / 60);
$m = $min - ($d * 1440) - ($h * 60);
if ($min < 60) {
return "{$m}m";
}
return "{$h}h {$m}m";
}
if (!function_exists('cast_to_object')) {
function cast_to_object($array)
{
$object = new stdClass();
foreach ($array as $key => $value) {
$object->$key = is_array($value) ? cast_to_object($value) : $value;
}
return $object;
}
}
function get_movie_genres_list($as_object = true)
{
$genres = [
['id' => '28', 'name' => 'Action'],
['id' => '12', 'name' => 'Adventure'],
['id' => '16', 'name' => 'Animation'],
['id' => '35', 'name' => 'Comedy'],
['id' => '80', 'name' => 'Crime'],
['id' => '99', 'name' => 'Documentary'],
['id' => '18', 'name' => 'Drama'],
['id' => '10751', 'name' => 'Family'],
['id' => '14', 'name' => 'Fantasy'],
['id' => '36', 'name' => 'History'],
['id' => '27', 'name' => 'Horror'],
['id' => '10402', 'name' => 'Music'],
['id' => '9648', 'name' => 'Mystery'],
['id' => '10749', 'name' => 'Romance'],
['id' => '878', 'name' => 'Science Fiction'],
['id' => '10770', 'name' => 'TV Movie'],
['id' => '53', 'name' => 'Thriller'],
['id' => '10752', 'name' => 'War'],
['id' => '37', 'name' => 'Western'],
];
return $as_object ? cast_to_object($genres) : $genres;
}
function get_tv_genres_list($as_object = true)
{
$genres = [
['id' => '10759', 'name' => 'Action & Adventure'],
['id' => '16', 'name' => 'Animation'],
['id' => '35', 'name' => 'Comedy'],
['id' => '80', 'name' => 'Crime'],
['id' => '99', 'name' => 'Documentary'],
['id' => '18', 'name' => 'Drama'],
['id' => '10751', 'name' => 'Family'],
['id' => '10762', 'name' => 'Kids'],
['id' => '9648', 'name' => 'Mystery'],
['id' => '10763', 'name' => 'News'],
['id' => '10764', 'name' => 'Reality'],
['id' => '10765', 'name' => 'Sci-Fi & Fantasy'],
['id' => '10766', 'name' => 'Soap'],
['id' => '10767', 'name' => 'Talk'],
['id' => '10768', 'name' => 'War & Politics'],
['id' => '37', 'name' => 'Western'],
];
return $as_object ? cast_to_object($genres) : $genres;
}
function genres($genres, $type = 'movie', $as_object = true)
{
$path = $type === 'movie' ? 'films' : 'tv-shows';
$results = array_map(function ($genre) use ($path) {
return [
'link' => url($path . '/genre/' . Str::slug($genre->name) . '/' . $genre->id),
'name' => $genre->name
];
}, $genres);
return $as_object ? cast_to_object($results) : $results;
}
function actors($actors, $limit = 5)
{
return array_map(function ($actor) {
return (object)[
'name' => $actor->name
];
}, collect($actors)->take($limit)->toArray());
// return collect($results)->take(3);
}
function detect_device()
{
// return new \Jenssegers\Agent\Agent();
}
function is_bing()
{
$agent = detect_device();
$bing_regex = '/bingbot|bing|slurp|altavista|trident|aol|dogpile|duckduckbot|ecosia|ekoru|elliot|enow|excite|gaia|givero|goodshop|info|kol|lilo|metacrawler|mojeek|oceanhero|oscobo|qwantify|searchencrypt|searchscene|serch|swiss|webcrawler|youcare|msnbot/i';
// dd($agent->getUserAgent());
// return $agent->match($bing_regex);
}
function get_country_code()
{
$country_code = 'RO';
if (isset($_SERVER['HTTP_CF_IPCOUNTRY'])) {
$country_code = $_SERVER['HTTP_CF_IPCOUNTRY'];
} elseif (isset($_SERVER['HTTP_CF_IPCOUNTRY'])) {
$country_code = $_SERVER['COUNTRY_CODE'];
}
return $country_code;
}
function is_country($country = 'US', $negate = false)
{
$res = (bool) preg_match('~'.$country.'~', get_country_code());
return $negate ? !$res : $res;
}
function is_primary_country($negate = false)
{
$res = (bool) preg_match('~'.config('ads.country_primary').'~', get_country_code());
return $negate ? !$res : $res;
}
function host_key() {
return ucfirst(str_replace('.', '', $_SERVER['HTTP_HOST']));
}
function url_starts_with($perma)
{
return (bool) preg_match('~/'.$perma.'~', ltrim(request()->getPathInfo()));
}