File: /home/httpd/html/naced.com/public_html/admin/functions.general.php
<?php
/* THIS FILE CONTAINS GENERAL FUNCTIONS WHERE ARE VERY INFREQUENTLY MODIFIED. PLEASE AVOID MODIFYING THIS FILE. */
function generateUrl($type, $name, $content_id) {
global $basehttp;
switch ($type) {
case 'webcams':
return $basehttp . '/' . $type . '/' . clearString($name) . '-' . $content_id . '.html';
break;
case 'channel':
return $basehttp . '/channels/' . $content_id . '/' . clearString($name) . '/';
break;
case 'paysite':
return $basehttp . '/paysites/' . $content_id . '/' . clearString($name) . '/';
break;
default:
return $basehttp . '/' . $type . '/' . clearString($name) . '-' . $content_id . '.html';
break;
}
}
function validateUser($username, $password) {
$validate = dbQuery("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = MD5(CONCAT('$password', `salt`))", false);
if (is_array($validate)) {
return $validate;
} else {
return false;
}
}
/**
* Detects and returns if current device is a mobile one (smartphone, tablet or any other)
*
* @global string $basepath Absolute base path
* @param string $type Type of mobile device to detect (mobile, tablet or all)
* @return boolean
*/
function detectMobile($type = '') {
global $basepath;
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if($_GET['mobileDevice']) {
return true;
}
switch(true) {
case (stripos($user_agent,'android'));
$isMobile = true;
break;
case (stripos($user_agent,'iphone')||stripos($user_agent,'ipod'));
$isMobile = true;
break;
case (stripos($user_agent,'opera mini'));
$isMobile = true;
break;
case (stripos($user_agent,'blackberry'));
$isMobile = true;
break;
case (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo|palm os|palm|hiptop|avantgo|fennec|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent));
$isMobile = true;
break;
}
return $isMobile;
}
function clearString($string) {
global $transliterate;
$chars = array(
chr(195) . chr(128) => 'A', chr(195) . chr(129) => 'A',
chr(195) . chr(130) => 'A', chr(195) . chr(131) => 'A',
chr(195) . chr(132) => 'A', chr(195) . chr(133) => 'A',
chr(195) . chr(134) => 'AE', chr(195) . chr(166) => 'ae',
chr(195) . chr(135) => 'C', chr(195) . chr(136) => 'E',
chr(195) . chr(137) => 'E', chr(195) . chr(138) => 'E',
chr(195) . chr(139) => 'E', chr(195) . chr(140) => 'I',
chr(195) . chr(141) => 'I', chr(195) . chr(142) => 'I',
chr(195) . chr(143) => 'I', chr(195) . chr(145) => 'N',
chr(195) . chr(146) => 'O', chr(195) . chr(147) => 'O',
chr(195) . chr(148) => 'O', chr(195) . chr(149) => 'O',
chr(195) . chr(150) => 'O', chr(195) . chr(153) => 'U',
chr(195) . chr(152) => 'O', chr(195) . chr(184) => 'o',
chr(195) . chr(154) => 'U', chr(195) . chr(155) => 'U',
chr(195) . chr(156) => 'U', chr(195) . chr(157) => 'Y',
chr(195) . chr(159) => 's', chr(195) . chr(160) => 'a',
chr(195) . chr(161) => 'a', chr(195) . chr(162) => 'a',
chr(195) . chr(163) => 'a', chr(195) . chr(164) => 'a',
chr(195) . chr(165) => 'a', chr(195) . chr(167) => 'c',
chr(195) . chr(168) => 'e', chr(195) . chr(169) => 'e',
chr(195) . chr(170) => 'e', chr(195) . chr(171) => 'e',
chr(195) . chr(172) => 'i', chr(195) . chr(173) => 'i',
chr(195) . chr(174) => 'i', chr(195) . chr(175) => 'i',
chr(195) . chr(177) => 'n', chr(195) . chr(178) => 'o',
chr(195) . chr(179) => 'o', chr(195) . chr(180) => 'o',
chr(195) . chr(181) => 'o', chr(195) . chr(182) => 'o',
chr(195) . chr(182) => 'o', chr(195) . chr(185) => 'u',
chr(195) . chr(186) => 'u', chr(195) . chr(187) => 'u',
chr(195) . chr(188) => 'u', chr(195) . chr(189) => 'y',
chr(195) . chr(191) => 'y',
chr(196) . chr(128) => 'A', chr(196) . chr(129) => 'a',
chr(196) . chr(130) => 'A', chr(196) . chr(131) => 'a',
chr(196) . chr(132) => 'A', chr(196) . chr(133) => 'a',
chr(196) . chr(134) => 'C', chr(196) . chr(135) => 'c',
chr(196) . chr(136) => 'C', chr(196) . chr(137) => 'c',
chr(196) . chr(138) => 'C', chr(196) . chr(139) => 'c',
chr(196) . chr(140) => 'C', chr(196) . chr(141) => 'c',
chr(196) . chr(142) => 'D', chr(196) . chr(143) => 'd',
chr(196) . chr(144) => 'D', chr(196) . chr(145) => 'd',
chr(196) . chr(146) => 'E', chr(196) . chr(147) => 'e',
chr(196) . chr(148) => 'E', chr(196) . chr(149) => 'e',
chr(196) . chr(150) => 'E', chr(196) . chr(151) => 'e',
chr(196) . chr(152) => 'E', chr(196) . chr(153) => 'e',
chr(196) . chr(154) => 'E', chr(196) . chr(155) => 'e',
chr(196) . chr(156) => 'G', chr(196) . chr(157) => 'g',
chr(196) . chr(158) => 'G', chr(196) . chr(159) => 'g',
chr(196) . chr(160) => 'G', chr(196) . chr(161) => 'g',
chr(196) . chr(162) => 'G', chr(196) . chr(163) => 'g',
chr(196) . chr(164) => 'H', chr(196) . chr(165) => 'h',
chr(196) . chr(166) => 'H', chr(196) . chr(167) => 'h',
chr(196) . chr(168) => 'I', chr(196) . chr(169) => 'i',
chr(196) . chr(170) => 'I', chr(196) . chr(171) => 'i',
chr(196) . chr(172) => 'I', chr(196) . chr(173) => 'i',
chr(196) . chr(174) => 'I', chr(196) . chr(175) => 'i',
chr(196) . chr(176) => 'I', chr(196) . chr(177) => 'i',
chr(196) . chr(178) => 'IJ', chr(196) . chr(179) => 'ij',
chr(196) . chr(180) => 'J', chr(196) . chr(181) => 'j',
chr(196) . chr(182) => 'K', chr(196) . chr(183) => 'k',
chr(196) . chr(184) => 'k', chr(196) . chr(185) => 'L',
chr(196) . chr(186) => 'l', chr(196) . chr(187) => 'L',
chr(196) . chr(188) => 'l', chr(196) . chr(189) => 'L',
chr(196) . chr(190) => 'l', chr(196) . chr(191) => 'L',
chr(197) . chr(128) => 'l', chr(197) . chr(129) => 'L',
chr(197) . chr(130) => 'l', chr(197) . chr(131) => 'N',
chr(197) . chr(132) => 'n', chr(197) . chr(133) => 'N',
chr(197) . chr(134) => 'n', chr(197) . chr(135) => 'N',
chr(197) . chr(136) => 'n', chr(197) . chr(137) => 'N',
chr(197) . chr(138) => 'n', chr(197) . chr(139) => 'N',
chr(197) . chr(140) => 'O', chr(197) . chr(141) => 'o',
chr(197) . chr(142) => 'O', chr(197) . chr(143) => 'o',
chr(197) . chr(144) => 'O', chr(197) . chr(145) => 'o',
chr(197) . chr(146) => 'OE', chr(197) . chr(147) => 'oe',
chr(197) . chr(148) => 'R', chr(197) . chr(149) => 'r',
chr(197) . chr(150) => 'R', chr(197) . chr(151) => 'r',
chr(197) . chr(152) => 'R', chr(197) . chr(153) => 'r',
chr(197) . chr(154) => 'S', chr(197) . chr(155) => 's',
chr(197) . chr(156) => 'S', chr(197) . chr(157) => 's',
chr(197) . chr(158) => 'S', chr(197) . chr(159) => 's',
chr(197) . chr(160) => 'S', chr(197) . chr(161) => 's',
chr(197) . chr(162) => 'T', chr(197) . chr(163) => 't',
chr(197) . chr(164) => 'T', chr(197) . chr(165) => 't',
chr(197) . chr(166) => 'T', chr(197) . chr(167) => 't',
chr(197) . chr(168) => 'U', chr(197) . chr(169) => 'u',
chr(197) . chr(170) => 'U', chr(197) . chr(171) => 'u',
chr(197) . chr(172) => 'U', chr(197) . chr(173) => 'u',
chr(197) . chr(174) => 'U', chr(197) . chr(175) => 'u',
chr(197) . chr(176) => 'U', chr(197) . chr(177) => 'u',
chr(197) . chr(178) => 'U', chr(197) . chr(179) => 'u',
chr(197) . chr(180) => 'W', chr(197) . chr(181) => 'w',
chr(197) . chr(182) => 'Y', chr(197) . chr(183) => 'y',
chr(197) . chr(184) => 'Y', chr(197) . chr(185) => 'Z',
chr(197) . chr(186) => 'z', chr(197) . chr(187) => 'Z',
chr(197) . chr(188) => 'z', chr(197) . chr(189) => 'Z',
chr(197) . chr(190) => 'z', chr(197) . chr(191) => 's',
// Euro
chr(226) . chr(130) . chr(172) => 'E',
// Funt
chr(194) . chr(163) => '');
if (is_array($transliterate)) {
$chars += $transliterate;
}
$string = strip_tags(strtolower(strtr($string, $chars)));
$trans = array(
'\s+' => '-',
//'-+' => '-'
);
foreach ($trans as $search => $replace) {
$string = preg_replace("/$search/i", $replace, $string);
//$string = preg_replace("/[^\p{L}\p{N}]/u", $replace, $string);
}
//return trim($string, '-');
return trim($string);
}
function generateSlug($contentid) {
$contentid = (int) $contentid;
$getContent = dbQuery("SELECT title FROM content WHERE record_num = $contentid", false);
if (!empty($getContent)) {
$content = $getContent[0];
$slug = clearString($content['title']);
$checkSlug = dbQuery("SELECT record_num FROM content WHERE slug = '$slug'");
if (!empty($checkSlug)) {
$slug = $slug . uniqid();
}
dbQuery("UPDATE content SET slug = '$slug' WHERE record_num = $contentid");
}
}
function generateChannelsAdmin($id) {
global $basehttp;
$cresult = dbQuery("SELECT niches.* FROM niches WHERE niches.record_num IN (SELECT content_niches.niche FROM content_niches WHERE content_niches.content = '$id') GROUP BY niches.record_num ORDER BY name ASC");
if(is_array($cresult)) {
foreach ($cresult as $crow) {
$catstring .= "<a href='$basehttp/admin/edit_niche.php?id=" . $crow['record_num'] . "' class='link12' >".$crow['name']."</a>, ";
}
}
return substr($catstring, 0, -2);
}
/**
* Callbacks array_map on multidimensional array
*
* @param string $callback Callback function
* @param array $array Input array
* @return array
*/
function array_map_array($callback, $array, $skip_fields = array()) {
foreach ($array as $key => $value) {
if (in_array($key, $skip_fields)) {
continue;
}
if (is_array($value)) {
$array[$key] = array_map_array($callback, $value);
} else {
$array[$key] = call_user_func($callback, $value);
}
}
return $array;
}
function recursive_array_search($needle, $haystack) {
foreach ($haystack as $key => $value) {
$current_key = $key;
if ($needle === $value OR ( is_array($value) && recursive_array_search($needle, $value) !== false)) {
return $current_key;
}
}
return false;
}
function pageDenied($admin = false) {
global $basepath, $template_path, $template_url, $basehttp, $thisController, $currentLang, $default_language, $config, $title;
header('HTTP/1.0 403 Forbidden');
if (!getMessages(false, 'error')) {
setMessage(_t('You have no rights to view this page'), 'error');
}
if ($admin === true) {
include "$basepath/admin/_error.php";
exit();
} else {
$thisController = '403';
//include_once "$basepath/includes/inc.metatags.php";
include "$template_path/template.overall_header.php";
include "$template_path/template.403.php";
include "$template_path/template.overall_footer.php";
exit();
}
}
function pageNotFound($admin = false) {
global $basepath, $template_path, $template_url, $basehttp, $thisController, $currentLang, $default_language, $config, $title, $dbconn, $dblink;
header("HTTP/1.0 404 Not Found");
if (!getMessages(false, 'error') && !getMessages(false, 'alert')) {
setMessage(_t('Page you are looking for does not exist'), 'error');
}
if ($admin === true) {
include "$basepath/admin/_error.php";
exit();
} else {
$thisController = '404';
include_once "$basepath/includes/inc.metatags.php";
include "$template_path/template.overall_header.php";
include "$template_path/template.404.php";
include "$template_path/template.overall_footer.php";
exit();
}
}
function pageError() {
global $basepath, $template_path, $template_url, $basehttp, $thisController, $currentLang, $default_language, $config, $title;
if (!getMessages(false, 'error') && !getMessages(false, 'info')) {
setMessage(_t('Unexpected error occured'), 'error');
}
$thisController = 'maintenance';
//include_once "$basepath/includes/inc.metatags.php";
include "$template_path/template.maintenance.php";
exit();
}
function createUserSession($user) {
$result = $user;
if (is_numeric($result)) {
$result = dbRow("SELECT * FROM `users` WHERE `record_num` = '$result'");
}
if (is_array($result)) {
$session_keys = array('record_num' => 'userid', 'username', 'password', 'email', 'user_level', 'tokens', 'premium');
foreach ($session_keys as $src_field => $dst_field) {
$_SESSION[$dst_field] = is_numeric($src_field) ? $result[$dst_field] : $result[$src_field];
}
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
return true;
}
}
function updateUserSession() {
if (!isset($_SESSION['userid']) || !is_numeric($_SESSION['userid'])) {
return false;
}
$result = dbRow("SELECT * FROM `users` WHERE `record_num` = '" . $_SESSION['userid'] . "'");
if (is_array($result)) {
$session_keys = array('record_num' => 'userid', 'username', 'password', 'email', 'user_level', 'tokens', 'premium');
foreach ($session_keys as $src_field => $dst_field) {
$_SESSION[$dst_field] = is_numeric($src_field) ? $result[$dst_field] : $result[$src_field];
}
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
}
}
/**
* Destroys selected user type session information, excluding "ip" (it's shared)
*
* @param string $type Session type to destroy "user" or "admin"
*/
function destroySession($type = 'user') {
if ($type === 'user' && isset($_SESSION['userid'])) {
$session_keys = array('username', 'password', 'userid', 'email', 'user_level', 'tokens', 'premium');
foreach ($session_keys as $key) {
unset($_SESSION[$key]);
}
} else if ($type === 'admin' && isset($_SESSION['isAdmin'])) {
$session_keys = array('isAdmin');
foreach ($session_keys as $key) {
unset($_SESSION[$key]);
}
}
if (!isset($_SESSION['isAdmin']) && !isset($_SESSION['userid'])) {
session_destroy();
}
}
function logData($type, $data) {
global $dblink;
dbQuery("INSERT INTO logs SET type = '".mysqli_real_escape_string($dblink,$type)."', `data` = '".mysqli_real_escape_string($dblink,$data)."', `date` = NOW()");
return $data;
}
if(isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'my-uploads') {
$_REQUEST['mode'] = 'my_uploads';
$_GET['mode'] = 'my_uploads';
}
if(isset($_REQUEST['sortby']) == 'longest') {
$_REQUEST['sortby'] = 'length';
$_GET['sortby'] = 'length';
}
function file_crc($file) {
$file_string = file_get_contents($file);
$crc = crc32($file_string);
return sprintf("%u", $crc);
}
if(stripos($_SERVER['REQUEST_URI'],'includes/ajax.login.php') !== false) {
header('HTTP/1.0 403 Forbidden');
exit();
}
if(stripos($_SERVER['REQUEST_URI'],'includes/ajax.signup.php') !== false) {
header('HTTP/1.0 403 Forbidden');
exit();
}
if(isset($_GET['q'])) {
$_GET['q'] = htmlspecialchars($_GET['q'], ENT_QUOTES, "UTF-8");
}
if(isset($_GET['option'])) {
$_GET['option'] = htmlentities($_GET['option']);
}
function secureEval($input = '') {
$functions = array(
'assert', 'include', 'include_once', 'curl_init', 'exec', 'fpassthru',
'fsockopen', 'require', 'require_once', 'call_user_func',
'call_user_func_array', 'file', 'fopen', 'mail', 'exec', 'system',
'sockopen', 'shell_exec', 'socket_connect',
);
$original = ini_get('disable_functions');
ini_set('disable_functions', implode(', ', $functions));
eval("?>" . $input);
ini_set('disable_functions', $original);
}
//added in the event that someone using php8 has shell_exec disabled as it removes the function entirely causing a fatal error
if(!function_exists("shell_exec")) {
function shell_exec($v) {
return false;
}
}
//added in the event that someone using php8 has exec disabled as it removes the function entirely causing a fatal error
if(!function_exists("exec")) {
function exec($v) {
return false;
}
}