UnknownSec Bypass
403
:
/
mnt
/
lmsestudio-instance-vol002
/
lms_64c2eb948c86
/
app
/
Helpers
/ [
drwxr-xr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
Helpers.php
<?php namespace EstudioLMS\Helpers; use Carbon\Carbon; use DateInterval; use EstudioLMS\Exceptions\Handler; use GuzzleHttp\Client as GCliente; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator; use Illuminate\Support\Collection; /** * Class Helpers * @package EstudioLMS\Helpers */ class Helpers { /** * @param $data * @return string */ public static function logDataChanged($data) { $changes = []; $log = ''; foreach ($data->getDirty() as $key => $value) { $original = $data->getOriginal($key); $changes[$key] = [ 'old' => $original, 'new' => $value, ]; } if (isset($changes)) { if (count($changes) > 0) { $log = ''; foreach ($changes as $key => $change) { $log .= $key . ' Changed from: ' . $change['old'] . ' to: ' . $change['new'] . PHP_EOL; } } } return $log; } /** * @param $string * @return string|string[]|null */ public static function keepNumericOnly($string) { return preg_replace("/[^0-9,.]/", "", $string); } /** * @param $url * @return array|null */ public static function videoInfo($url) { if (strpos($url, 'youtube.com')) { $url = parse_url($url); if (!isset($url['query'])) { return []; } parse_str($url['query'], $output); $videoId = $output['v']; return self::youtubeVideoInfo($videoId); } elseif (strpos($url, 'youtu.be')) { $videoId = explode('youtu.be/', $url); $videoId = $videoId[1]; return self::youtubeVideoInfo($videoId); } elseif (strpos($url, 'vimeo.com')) { $videoId = explode('vimeo.com/', $url); $videoId = $videoId[1]; return self::vimeoVideoInfo($videoId); } else { return []; } } /** * @param $videoId * @return null */ private static function youtubeVideoInfo($videoId) { try { $api_key = 'AIzaSyDSg74gqy2oAvM3HNEogHlJFGcmqWbXGA4'; $vinfo['video_type'] = 'youtube'; $vinfo['video_id'] = $videoId; $xml = file_get_contents( "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$videoId&key=$api_key" ); $result = json_decode($xml, true); if (empty($result['items'][0]['contentDetails'])) { return null; } $vinfo = $result['items'][0]['contentDetails']; $interval = new DateInterval($vinfo['duration']); $vinfo['duration'] = $interval->h * 3600 + $interval->i * 60 + $interval->s; $thumbnail_base = 'https://i.ytimg.com/vi/'; $vinfo['thumbnail']['default'] = $thumbnail_base . $videoId . '/default.jpg'; $vinfo['thumbnail']['mqDefault'] = $thumbnail_base . $videoId . '/mqdefault.jpg'; $vinfo['thumbnail']['hqDefault'] = $thumbnail_base . $videoId . '/hqdefault.jpg'; $vinfo['thumbnail']['sdDefault'] = $thumbnail_base . $videoId . '/sddefault.jpg'; $vinfo['thumbnail']['maxresDefault'] = $thumbnail_base . $videoId . '/maxresdefault.jpg'; } catch (\Exception $e) { app(Handler::class)->report($e); $vinfo = []; } return $vinfo; } /** * @param $videoId * @return array */ private static function vimeoVideoInfo($videoId) { $vinfo = []; try { $baseUrl = \URL::to('/'); $oembed_endpoint = 'http://vimeo.com/api/oembed'; $video_url = 'https://vimeo.com/' . $videoId; $json_url = $oembed_endpoint . '.json?url=' . rawurlencode($video_url) . '&width=640'; $client = new GCliente([ 'headers' => [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Referer' => $baseUrl ] ]); $return = $client->get($json_url); $xml = json_decode($return->getBody(), true); $vinfo['video_type'] = $xml['provider_name']; $vinfo['video_id'] = $xml['video_id']; $vinfo['title'] = $xml['title'] ?? ''; $vinfo['url'] = $xml['uri'] ?? ''; $vinfo['author_name'] = $xml['author_name'] ?? ''; $vinfo['author_url'] = $xml['author_url'] ?? ''; $vinfo['duration'] = $xml['duration'] ?? 0; } catch (\Exception $e) { app(Handler::class)->report($e); $vinfo = []; } return $vinfo; } /** * @param $value * @return string */ public static function formatValue($value) { //$value = floor($value * 100) / 100; if (!empty($value)) { $value = self::numberFormatPrecision($value); return number_format($value, 2, ",", "."); } else { return $value; } } /** * @param $date * @param bool $time * @return string */ public static function formatDate($date, $time = false) { if (!empty($date)) { $date = new Carbon($date); if ($time) { return $date->format('d/m/Y H:i:s'); } return $date->format('d/m/Y'); } return ''; } /** * @param $email * @return string */ public static function obfuscateEmail($email) { $em = explode("@", $email); $name = implode(array_slice($em, 0, count($em) - 1), '@'); $len = floor(strlen($name) / 2); return substr($name, 0, $len) . str_repeat('*', $len) . "@" . end($em); } /** * @param $length * @return bool|string */ public static function randomPassword($length) { $chars = "@#_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; return substr(str_shuffle($chars), 0, $length); } /** * @return array */ public static function UFlist() { $ufArr = [ 'AC' => 'AC', 'AL' => 'AL', 'AM' => 'AM', 'AP' => 'AP', 'BA' => 'BA', 'CE' => 'CE', 'DF' => 'DF', 'ES' => 'ES', 'GO' => 'GO', 'MA' => 'MA', 'MG' => 'MG', 'MS' => 'MS', 'MT' => 'MT', 'PA' => 'PA', 'PB' => 'PB', 'PE' => 'PE', 'PI' => 'PI', 'PR' => 'PR', 'RJ' => 'RJ', 'RN' => 'RN', 'RO' => 'RO', 'RR' => 'RR', 'RS' => 'RS', 'SC' => 'SC', 'SE' => 'SE', 'SP' => 'SP', 'TO' => 'TO' ]; return $ufArr; } /** * @param $time * @param string $format * @return string|void */ public static function convertToHoursMins($time, $format = '%02d:%02d') { if ($time < 1) { return; } $hours = floor($time / 60); $minutes = ($time % 60); return sprintf($format, $hours, $minutes); } /** * @param bool $withSuper * @return array */ public static function userTypes($withSuper = false) { if ($withSuper) { $userTypes = [ 1 => 'admin', 2 => 'professor', 3 => 'aluno', 5 => 'Super Admin' ]; } else { $userTypes = [ 1 => 'admin', 2 => 'professor', 3 => 'aluno' ]; } return $userTypes; } /** * @param $type * @return mixed */ public static function translateUserTypes($type) { $types = ['superadmin' => trans('admin_user.dropAdmin'), 'admin' => trans('admin_user.dropAdmin'), 'teacher' => trans('admin_user.dropInstructor'), 'student' => trans('admin_user.dropStudent'), 'owner' => trans('admin_user.dropAdmin')]; return $types[$type]; } /** * @return string */ public static function newGuid() { $s = strtoupper(md5(uniqid(rand(), true))); $guidText = substr($s, 0, 8) . '-' . substr($s, 8, 4) . '-' . substr($s, 12, 4) . '-' . substr($s, 16, 4) . '-' . substr($s, 20); return $guidText; } /** * @param string $prepend * @return string */ public static function uniqueFileName($prepend = '') { if (empty($prepend)) { return uniqid(); } return uniqid($prepend); } /** * @param $videoFile * @return float|int */ public static function getLocalVideoDuration($videoFile) { try { $file = $videoFile; $result = shell_exec('ffmpeg -i ' . escapeshellcmd($file) . ' 2>&1'); preg_match('/(?<=Duration: )(\d{2}:\d{2}:\d{2})\.\d{2}/', $result, $match); $time = $match[0]; if (count($match) > 1) { $time = $match[1]; } $parsed = date_parse($time); $seconds = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second']; return $seconds; } catch (\Exception $e) { app(Handler::class)->report($e); return 0; } } /** * @param array $array * @return array */ public static function findLongestStringFromArray($array = []) { if (!empty($array)) { $lengths = array_map('strlen', $array); $maxLength = max($lengths); $key = array_search($maxLength, $lengths); return ['length' => $maxLength, 'key' => $key, 'string' => $array[$key]]; } } /** * @param $statusId * @return string */ public static function courseStatus($statusId) { $statusList = [ '0' => 'Indefinido', '1' => 'Aguardando pagamento', '2' => 'Em análise', '3' => 'Pago', '4' => 'Disponível', '5' => 'Em disputa', '6' => 'Devolvido', '7' => 'Cancelado', '10' => 'Expirado' ]; return $statusList[$statusId]; } /** * @param $validDate * Passar no formato 'my' eg. 0720 para 07/2020 * @return string */ public static function formatCardValidate($validDate) { $date = Carbon::createFromFormat('my', $validDate); return $date->format('m/Y'); } /** * @return string */ public static function generateUniqueToken() { return md5(rand(1, 10) . microtime()); } /** * Gera a paginação dos itens de um array ou collection. * * @param array|Collection $items * @param int $perPage * @param int $page * * @return LengthAwarePaginator */ public static function paginate($items, $perPage = 15, $page = null) { $pageName = 'page'; $page = $page ?: (Paginator::resolveCurrentPage($pageName) ?: 1); $items = $items instanceof Collection ? $items : Collection::make($items); return new LengthAwarePaginator( $items->forPage($page, $perPage)->values(), $items->count(), $perPage, $page, [ 'path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName, ] ); } /** * @param $number * @param int $precision * @param string $separator * @return mixed|string */ public static function numberFormatPrecision($number, $precision = 2, $separator = '.') { $numberParts = explode($separator, $number); $response = $numberParts[0]; if (count($numberParts) > 1) { $response .= $separator; $response .= substr($numberParts[1], 0, $precision); } return $response; } /** * @param $seconds * @return string */ public static function convertSecondsToHour($seconds) { $horas = floor($seconds / 3600); $minutos = floor(($seconds - ($horas * 3600)) / 60); $segundos = floor($seconds % 60); return str_pad($horas, 2, '0', STR_PAD_LEFT) . ":" . str_pad($minutos, 2, '0', STR_PAD_LEFT) . ":" . str_pad($segundos, 2, '0', STR_PAD_LEFT); } /** * @return string */ public static function getIp() { foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) { if (array_key_exists($key, $_SERVER) === true) { foreach (explode(',', $_SERVER[$key]) as $ip) { $ip = trim($ip); // just to be safe if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) { return $ip; } } } } /* * If fail, Get Local IP */ $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_connect($sock, "8.8.8.8", 53); socket_getsockname($sock, $name); $ip = $name; $ip = '201.17.119.58'; return $ip; } /** * @param $resourceTypeId * @param $resourceId * @return mixed */ public static function getResourceTitle($resourceTypeId, $resourceId) { $gdata = app(GetDataRecords::class); return $gdata->getResourceByResourceId($resourceTypeId, $resourceId, true)->title; } /** * @param $string * @param $start * @param $end * @return bool|string */ public static function getStringBetween($string, $start, $end) { $string = ' ' . $string; $ini = strpos($string, $start); if ($ini == 0) return ''; $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } /** * @param $input */ public static function utf8EncodeDeep(&$input) { if (is_string($input)) { $input = utf8_encode($input); } else if (is_array($input)) { foreach ($input as &$value) { self::utf8EncodeDeep($value); } unset($value); } else if (is_object($input)) { $vars = array_keys(get_object_vars($input)); foreach ($vars as $var) { self::utf8EncodeDeep($input->$var); } } } /** * @return void */ public static function checkIfSuspended() { $susp = \File::exists(storage_path() . '/framework/susp'); } /** * @param $bytes * @param $type * @param int $decimals * @return mixed|string */ public static function convertBytesToSpecified($bytes, $type, $decimals = 2) { switch ($type) { case 'K': $val = $bytes / 1024; $return = self::numberFormatPrecision($val); break; case 'M': $val = $bytes / 1048576; $return = self::numberFormatPrecision($val); break; case 'G': $val = $bytes / 1073741824; $return = self::numberFormatPrecision($val); break; } return $return; } /** * @param $path * @param array|null $extensions * @return Collection */ public function listFilesInDirectory($path, array $extensions = null) { $files = collect(); $listFiles = function($directoryPath, $baseDir = '', $extensions = null) use ($files) { if ($handle = opendir($directoryPath)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $filePath = $baseDir . $file; if(!is_null($extensions)) { if(in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), $extensions)) { $files->push(['id' => $filePath, 'name' => $filePath]); } } else { $files->push(['id' => $filePath, 'name' => $filePath]); } } } closedir($handle); } }; $listFiles($path, '', $extensions); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { $subDirPath = $path . DIRECTORY_SEPARATOR . $file; if ($file != "." && $file != ".." && is_dir($subDirPath)) { $listFiles($subDirPath, $file . '/', $extensions); } } closedir($handle); } return $files->pluck('name', 'id'); } /** * Sanitiza o softDescriptor para a API do PagarMe v5 * Remove caracteres especiais e limita o tamanho * * @param string $siteName * @return string */ public static function sanitizeSoftDescriptor($siteName) { // Remove caracteres especiais, mantém apenas alfanuméricos, espaços e hífens $sanitized = preg_replace('/[^a-zA-Z0-9\s\-]/', '', $siteName); // Remove espaços extras e hífens consecutivos $sanitized = preg_replace('/[\s\-]+/', ' ', $sanitized); // Remove espaços do início e fim $sanitized = trim($sanitized); // Limita a 13 caracteres conforme especificação da API if (strlen($sanitized) > 13) { $sanitized = substr($sanitized, 0, 13); } // Remove espaços que possam ter ficado no final após o corte $sanitized = rtrim($sanitized); // Se ficou vazio, usa um valor padrão if (empty($sanitized)) { $sanitized = 'ESTUDIOLMS'; } return $sanitized; } }
Copyright © 2026 - UnknownSec