File: /home/httpd/html/nyloncams.com/public_html/admin/functions.templating.php
<?php
$_SESSION['_message_context'] = 'default';
if(isset($_GET['controller']) && $_GET['controller'] == 'performer') {
$_GET['username'] = str_ireplace("-"," ",$_GET['username']);
}
function setMessageContext($context) {
$_SESSION['_message_context'] = $context;
}
function setMessage($message, $type = 'success', $print = false, $classes = array(), $debug_only = false, $prefix = '', $suffix = '') {
global $config;
if ($debug_only === true && !$config['development_mode']) {
return;
}
$_classes = (array) $classes;
array_unshift($_classes, $type);
$_type = preg_replace('/[^a-z]/', '_', strtolower($type));
if ($print) {
return "$prefix<div class=\"notification " . implode(' ', $_classes) . "\">$message</div>$suffix";
} else {
$_SESSION['messages'][$_SESSION['_message_context']][$_type][] = $message;
}
}
function getMessages($print = true, $type = null, $context = 'default') {
$message_group = array();
if (!empty($_SESSION['messages'][$context])) {
if ($print === true) {
if (array_key_exists('error', $_SESSION['messages'][$context])) {
addJs('$().ready(function() { setTimeout(function() { $(".notification.error").addClass("blink"); $("body,html").animate({ "scrollTop" : $(".notification.error").first().offset().top - 50}, 500, "easeOutExpo"); }, 500); });', 'inline', 'closure');
}
if ($type !== null && isset($_SESSION['messages'][$context][$type])) {
$messages_array = array();
foreach ($_SESSION['messages'][$context][$type] as $message) {
$messages_array[] = "$message<br>";
}
if (count($messages_array) > 0) {
$message_group[] = "<div class=\"notification $type\">" . substr(implode("", $messages_array), 0, -4) . "</div>";
}
$_SESSION['messages'][$context][$type] = array();
} else {
foreach ($_SESSION['messages'][$context] as $type => $messages) {
$messages_array = array();
foreach ($messages as $index => $message) {
$messages_array[] = "$message<br>";
}
if (count($messages_array) > 0) {
$message_group[] = "<div class=\"notification $type\">" . substr(implode("", $messages_array), 0, -4) . "</div>";
}
}
$_SESSION['messages'][$context] = array();
}
return implode("", $message_group) . getJs();
} else {
if ($type !== null) {
return count((array)$_SESSION['messages'][$context][$type]);
} else {
return count((array)$_SESSION['messages'][$context]);
}
}
}
}
function addJs($js, $type = 'inline', $mode = 'head') {
if (!getJs(false, $mode)) {
$_SESSION['scripts'][$mode] = array();
}
switch ($type) {
case 'inline':
$_SESSION['scripts'][$mode][] = $js;
break;
case 'file':
$_SESSION['js_scripts'][] = $js;
break;
}
}
function getJs($print = true, $mode = 'head', $files = false) {
if ($files === true && !empty($_SESSION['js_scripts'])) {
if ($print === true) {
$html = '';
foreach ($_SESSION['js_scripts'] as $js) {
$html .= '<script src="' . $basehttp . '/' . $js . '"></script>' . "\n";
}
$_SESSION['js_scripts'] = array();
return $html;
} else {
return count($_SESSION['js_scripts']);
}
} else if (!empty($_SESSION['scripts'][$mode])) {
if ($print === true) {
$_SESSION['scripts'][$mode] = array_unique($_SESSION['scripts'][$mode]);
$scripts = '';
if ($mode === 'all') {
foreach ($_SESSION['scripts'] as $_key => $_scripts) {
foreach ($_scripts as $js) {
$scripts .= "$js";
}
$_SESSION['scripts'][$_key] = array();
}
} else {
foreach ($_SESSION['scripts'][$mode] as $js) {
$scripts .= "$js";
}
$_SESSION['scripts'][$mode] = array();
}
return $scripts ? "<script>$scripts</script>" : '';
} else {
return count($_SESSION['scripts'][$mode]);
}
}
}
function addCss($css, $type = 'inline') {
if (!getCss(false)) {
$_SESSION['stylesheets'] = array();
}
if ($css == "") {
return;
}
switch ($type) {
case 'inline':
$_SESSION['stylesheets'][] = $css;
break;
case 'file':
break;
}
}
function getCss($print = true) {
if (!empty($_SESSION['stylesheets'])) {
if ($print) {
$stylesheets = '';
foreach ($_SESSION['stylesheets'] as $css) {
$stylesheets .= "$css\r\n";
}
$_SESSION['stylesheets'] = array();
return $stylesheets ? "<style media=\"all\" type=\"text/css\">\r\n$stylesheets\r\n</style>" : '';
} else {
return count($_SESSION['stylesheets']);
}
}
}
//get difference between two dates
function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
if (!$using_timestamps) {
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
}
$difference = $dateto - $datefrom; // Difference in seconds
if ($difference < 86400 && $difference >= 3600) {
$datediff = floor($difference / 3600);
if ($datediff > 1) {
$date_string = _t('%count hrs', array('%count' => $datediff));
} else {
$date_string = _t('1 hr');
}
} elseif ($difference < 3600) {
$datediff = floor($difference / 60);
if ($datediff > 1) {
$date_string = _t('%count mins', array('%count' => $datediff));
} else {
$date_string = _t('1 min');
}
} else {
$datediff = floor($difference / 86400);
if ($datediff > 1) {
$date_string = _t('%count days', array('%count' => $datediff));
} else {
$date_string = _t('1 day');
}
}
return $date_string;
}
function buildTags($var, $split = ',') {
global $basehttp;
$var = str_replace(', ', ',', $var);
$tags = explode(',', $var);
foreach ($tags as $i) {
$i2 = strtolower(str_replace(' ', '-', $i));
if (!empty($i)) {
$string .= "<a href=\"$basehttp/search/$i2/\">$i</a>$split ";
}
}
return substr($string, 0, -2);
}
//resizes embedded video html code to a specified width and height
function resizeEmbedded($subject, $width, $height) {
if (stripos($subject, '<') !== false) {
$subject = html_entity_decode($subject);
}
$subject = str_replace("'", '"', $subject);
$pattern = "/height=\"[0-9]*\"/";
$subject = preg_replace($pattern, "height='" . $height . "'", $subject);
$pattern = "/width=\"[0-9]*\"/";
$subject = preg_replace($pattern, "width='" . $width . "'", $subject);
return $subject;
}
function checkNav($item) {
global $thisController;
global $_GET;
switch ($item) {
case 'index':
return (($thisController == 'index' || $thisController == 'custom_url') && !$_GET['mode'] && !$_GET['page']) ? true : false;
break;
case 'favorites':
return ($thisController == 'favorites') ? true : false;
break;
case 'sites':
return ($thisController == 'sites') ? true : false;
break;
case 'tags':
return ($thisController == 'tags') ? true : false;
break;
case 'languages':
return ($thisController == 'languages') ? true : false;
break;
default:
return false;
}
}
function showVotesNo($id) {
return (int) dbValue("SELECT `total_votes` FROM `ratings` WHERE `content` = '$id'", 'total_votes', true);
}
// VIDEO RATIO
function videoRatio($r) {
global $stretchPortrait;
$width = $r['movie_width'];
$height = $r['movie_height'];
if (($height / $width) * 100 != 0 && $stretchPortrait) {
return "style='padding-top: " . ($height / $width) * 100 . "%'";
} else {
if($r['vr'] == 1) {
return "style='padding-top: 62.25%'";
} else {
return "style='padding-top: " . (9 / 16) * 100 . "%'";
}
}
}
// BODY CLASSES
function bodyClasses() {
$page_name_suffix = "";
$page_name = "home";
if (isset($_GET['controller'])) {
$page_name = htmlentities($_GET['controller']);
}
if (isset($_GET['mode'])) {
$page_name_suffix = "-" . htmlentities($_GET['mode']);
}
return $page_name . $page_name_suffix;
}
// NUMBER OF FAVORITES
function getTotalFavs($vid) {
return dbValue("SELECT COUNT(*) AS `count` FROM `favorites` WHERE `content` = '" . (int) $vid . "'", 'count', false);
}
// TOTAL VIDEOS NUMBER
function showVideosCounter() {
return dbValue("SELECT COUNT(*) AS `count` FROM `content` WHERE `enabled` = 1 AND `photos` = 0", 'count', true);
}
// SHOWS USER'S AVATAR
function getUserAvatar($id) {
global $basehttp;
global $basepath;
$av = dbRow("SELECT avatar, username, gender FROM users WHERE record_num = '$id'", true, 3600, "getUserAvatar.$id");
if ($av['avatar'] != '' && file_exists("$basepath/media/misc/{$av['avatar']}")) {
return "<img src='" . $basehttp . "/media/misc/" . $av['avatar'] . "' alt= '" . ucwords($av['username']) . "'>";
} else {
if (strtolower($av['gender']) == 'male') {
return "<img src='" . $basehttp . "/core/images/avatar_male.png' alt= '" . ucwords($av['username']) . "'>";
} elseif (strtolower($av['gender']) == 'female') {
return "<img src='" . $basehttp . "/core/images/avatar_female.png' alt= '" . ucwords($av['username']) . "'>";
} else {
return "<img src='" . $basehttp . "/core/images/avatar_default.png' alt= '" . ucwords($av['username']) . "'>";
}
}
}
//get difference between two dates
function datediff2($datefrom, $dateto = null, $using_timestamps = false) {
$mprefix = "<span class='counter'>";
$msufix = "</span>";
$prefix = "<span class='sub-label'>";
$sufix = "</span>";
if ($dateto === null) {
if ($using_timestamps) {
$dateto = time();
} else {
$dateto = date('Y-m-d H:i:s');
}
}
if (!$using_timestamps) {
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
}
$difference = $dateto - $datefrom; // Difference in seconds
if ($difference < 86400 && $difference >= 3600) {
$datediff = floor($difference / 3600);
if ($datediff > 1) {
$datediff = $mprefix . $datediff . $msufix . $prefix . ' hrs ago' . $sufix;
} else {
$datediff = $mprefix . $datediff . $msufix . $prefix . ' hr ago' . $sufix;
}
} elseif ($difference < 3600) {
$datediff = floor($difference / 60);
if ($datediff > 1) {
$datediff = $mprefix . $datediff . $msufix . $prefix . ' mins ago' . $sufix;
} else {
$datediff = $mprefix . $datediff . $msufix . $prefix . ' min ago' . $sufix;
}
} else {
$datediff = floor($difference / 86400);
// if ($datediff > 30) {
// $datediff = $mprefix . date('j', $datefrom) . $msufix . $prefix . date('F', $datefrom) . $sufix;
// } else if ($datediff > 1) {
if ($datediff > 1) {
$datediff = $mprefix . $datediff . $msufix . $prefix . ' days ago' . $sufix;
} else {
$datediff = $mprefix . $datediff . $msufix . $prefix . ' day ago' . $sufix;
}
}
return $datediff;
}
// STRAIGHT - S, GAY - G, SHEMALE - T
function filterUrl($f) {
global $basehttp;
$currentUrl = $_SERVER['REQUEST_URI'];
$prefix = "";
// check url to remove FILTER if exists
if (strpos($currentUrl, "?")) {
//$currentUrl = preg_replace('/filter=+[a-zA-Z]/', "", $currentUrl);
$paramsArray = explode("?", $currentUrl);
$subparamsArray = array();
$prefixURL = $paramsArray[0];
$suffixURL = $paramsArray[1];
$subparamsArray = explode("&", $suffixURL);
$newparamsArray = array();
$newSuffixURL = "?";
$addflag = false;
foreach ($subparamsArray as $a) {
if (is_numeric(strpos($a, "filter="))) {
$a = preg_replace('/filter=+[a-zA-Z]/', "filter=" . $f, $a);
$addflag = true;
} else {
$addflag = false;
}
array_push($newparamsArray, $a);
}
if (!$addflag && !in_array("filter=" . $f, $newparamsArray)) {
array_push($newparamsArray, "filter=" . $f);
}
$i;
foreach ($newparamsArray as $p) {
$i++;
if ($i == 1) {
$newSuffixURL .= $p;
} else {
$newSuffixURL .= "&" . $p;
}
}
// new url
$newUrl = $basehttp . $prefixURL . $newSuffixURL;
return $newUrl;
} else {
$newUrl = $basehttp . $currentUrl . "?filter=" . $f;
return $newUrl;
}
}
//partition array into several chunked ones
function partition( $list, $p ) {
$listlen = count( $list );
$partlen = floor( $listlen / $p );
$partrem = $listlen % $p;
$partition = array();
$mark = 0;
for ($px = 0; $px < $p; $px++) {
$incr = ($px < $partrem) ? $partlen + 1 : $partlen;
$partition[$px] = array_slice( $list, $mark, $incr );
$mark += $incr;
}
return $partition;
}
function showUpVotesNo($id) {
return (int) (dbValue("SELECT `total_value` FROM `ratings` WHERE `content` = '$id'", 'total_value', true)) / 100;
}
function filesize_formatted($size) {
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
//($size * .0009765625) * .0009765625
return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
}
//truncates a string to a certain length - example: "truncate($string,50)" would return the first 50 characters and then "..."
function truncate($tekst, $ile) {
$znaki = strlen($tekst);
if ($znaki >= $ile) {
$tnij = substr($tekst, 0, $ile);
$skrocone = $tnij . "...";
} else {
$skrocone = $tekst;
}
return $skrocone;
}
function addToUrl($q) {
$thisUrl = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if (parse_url($thisUrl, PHP_URL_QUERY)) {
return $thisUrl . "&" . $q;
} else {
return $thisUrl . "?" . $q;
}
}
function generateSEURL($array) {
global $basehttp;
if(isset($array) && is_array($array)) {
array_reorder_keys($array, 'tags,site,status,gender,age,hair,ethnicity,languages,sites');
foreach($array as $k=>$v) {
if(isset($v) && is_array($v)) {
$out[] = $k.'/'.implode(",",$v);
}
}
if(is_array($out)) {
return $basehttp.'/'.implode('/',$out);
} else {
return $basehttp.'/'.$out;
}
}
}
function array_reorder_keys(&$array, $keynames){
if(empty($array) || !is_array($array) || empty($keynames)) return;
if(!is_array($keynames)) $keynames = explode(',',$keynames);
if(!empty($keynames)) $keynames = array_reverse($keynames);
foreach($keynames as $n){
if(array_key_exists($n, $array)){
$newarray = array($n=>$array[$n]); //copy the node before unsetting
unset($array[$n]); //remove the node
$array = $newarray + array_filter($array); //combine copy with filtered array
}
}
}
function buildSideLink($title, $array, $key, $returnOnlyUrl = false) {
global $basehttp;
global $default_query_string;
global $seFriendly;
if(!isset($_SERVER['REQUEST_SCHEME'])) {
$_SERVER['REQUEST_SCHEME'] = 'https';
}
$thisUrl = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if(isset($_GET['controller']) && ($_GET['controller'] == 'custom_url' || $_GET['controller'] == 'router')) {
//custom url controller
$toParse = $_GET;
unset($toParse['controller']);
if(isset($toParse['url'])) { unset($toParse['url']); }
$queryString = http_build_query($toParse);
} elseif((!isset($_GET['controller']) || $_GET['controller'] == 'index') && isset($default_query_string)) {
$toParse = $_GET;
if(isset($toParse['controller'])) {
unset($toParse['controller']);
}
if(count($toParse) == 0) {
parse_str($default_query_string,$parsed);
if(is_array($parsed)) {
$finalQueryString = array_merge($toParse,$parsed);
$tmpArr = $finalQueryString; //asdf
$queryString = http_build_query($finalQueryString);
} else {
$queryString = parse_url($thisUrl, PHP_URL_QUERY);
$tmpArr = $_GET;
}
} else {
$queryString = parse_url($thisUrl, PHP_URL_QUERY);
$tmpArr = $_GET;
}
} else {
//index file
$queryString = parse_url($thisUrl, PHP_URL_QUERY);
$tmpArr = $_GET;
}
parse_str($queryString, $output);
if (is_array($output[$array]) && in_array($key, $output[$array])) {
$active = "active";
$x = "<i class=\"bi bi-x\"></i>";
} else {
$output[$array][] = $key;
}
if(isset($seFriendly) && $seFriendly == true) {
if ($active) {
if(!isset($tmpArr)) {
$tmpArr = $_GET;
}
if(isset($tmpArr) && is_array($tmpArr)) {
$thisKey = array_search($key,$tmpArr[$array]);
if(isset($tmpArr[$array][$thisKey])) {
unset($tmpArr[$array][$thisKey]);
if(isset($tmpArr[$array]) && count($tmpArr[$array]) < 1) {
unset($tmpArr[$array]);
}
}
}
$link = generateSEURL($tmpArr);
} else {
if(is_array($parsed)) {
$link = generateSEURL(array_merge_recursive($finalQueryString,array($array=>array($key))));
} else {
$link = generateSEURL(array_merge_recursive($_GET,array($array=>array($key))));
}
}
} else {
$link = str_replace("?" . $queryString, "", $thisUrl);
$newQueryString = urldecode(cr_post($output));
if ($active) {
$newQueryString = str_replace($array . "[]=" . $key, "", $newQueryString);
}
if (!empty($newQueryString)) {
$link = $basehttp . "/?" . $newQueryString;
}
}
if($returnOnlyUrl) {
return $link;
} else {
return "<a class=\"side-link " . $active . "\" href=\"" . $link . "\" title=\"\">" . $title . $x . "</a>";
}
}
function cr_post($a, $b = 0, $c = 0) {
if (!is_array($a))
return false;
foreach ((array) $a as $k => $v) {
if ($c)
$k = $b . "[]";
elseif (is_int($k))
$k = $b . $k;
if (is_array($v) || is_object($v)) {
$r[] = cr_post($v, $k, 1);
continue;
}
$r[] = urlencode($k) . "=" . urlencode($v);
}
return implode("&", $r);
}
function showPerformerIframe($rrow,$siteData) {
if($siteData['preferred'] == 'iframe_embed_revshare') {
if(isset($rrow['iframe_embed_revshare'])) {
$embed = $rrow['iframe_embed_revshare'];
} else {
$embed = $rrow['iframe_embed'];
}
} elseif($siteData['preferred'] == 'iframe_embed') {
if(isset($rrow['iframe_embed_'])) {
$embed = $rrow['iframe_embed'];
} else {
$embed = $rrow['iframe_embed_revshare'];
}
}
if(isset($embed)) {
//sub in chaturbate whitelabel if one exists
if($siteData['functionName'] == 'chaturbateData' && isset($siteData['whitelabel_domain'])) {
if($siteData['whitelabel_domain'] == "") {
$siteData['whitelabel_domain'] = "chaturbate.com";
}
if(isset($siteData['parameters'])) {
//$embed = preg_replace('~(\?|&)tour=[^&]*~', '$1tour='.$siteData['parameters'], $embed);
}
$embed = str_ireplace("chaturbate.com",$siteData['whitelabel_domain'],$embed);
}
if($siteData['functionName'] == 'chaturbateData') {
if(isset($siteData['settings_json'])) {
$settingsJson = json_decode($siteData['settings_json'],true);
if(isset($settingsJson['Tracking Campaign']) && !empty($settingsJson['Tracking Campaign'])) {
$embed = str_ireplace("track=embed","track=".$settingsJson['Tracking Campaign'],$embed);
}
if(isset($settingsJson['IFrame Style']) && !empty($settingsJson['IFrame Style'])) {
if($settingsJson['IFrame Style'] == 'camonly') {
$embed = str_ireplace("bgcolor=white","bgcolor=black"."&disable_sound=1&embed_video_only=1",$embed);
} elseif($settingsJson['IFrame Style'] == 'interactive') {
$embed = str_ireplace("bgcolor=white","bgcolor=black"."&disable_sound=1&signup_notice=1&mobileRedirect=never",$embed);
} else {
$embed = str_ireplace("bgcolor=white","bgcolor=black",$embed);
}
}
}
}
if($siteData['functionName'] == 'cambuilderData' && isset($siteData['whitelabel_domain'])) {
if($siteData['whitelabel_domain'] == "") {
$siteData['whitelabel_domain'] = "streamate.com";
}
$embed = str_ireplace("streamate.com",$siteData['whitelabel_domain'],$embed);
}
if(stripos($embed,"<iframe") === false && stripos($embed,"<script") === false) {
$embed = "<iframe src=\"".$embed."\"></iframe>";
}
echo "<div class=\"inner-stage m-2\">".$embed."</div>";
}
}
function getChatroomUrl($rrow,$siteData) {
if($siteData['functionName'] == 'chaturbateData' && isset($siteData['whitelabel_domain'])) {
if($siteData['whitelabel_domain'] == "") {
$siteData['whitelabel_domain'] = "chaturbate.com";
}
$rrow['chat_room_url'] = str_ireplace("chaturbate.com",$siteData['whitelabel_domain'],$rrow[$siteData['preferredLink']]);
if(isset($siteData['settings_json'])) {
$settingsJson = json_decode($siteData['settings_json'],true);
if(isset($settingsJson['Tracking Campaign']) && !empty($settingsJson['Tracking Campaign'])) {
$rrow['chat_room_url'] = str_ireplace("track=default","track=".$settingsJson['Tracking Campaign'],$rrow['chat_room_url']);
}
}
}
if($siteData['functionName'] == 'cambuilderData' && isset($siteData['whitelabel_domain'])) {
if($siteData['whitelabel_domain'] == "") {
$siteData['whitelabel_domain'] = "streamate.com";
}
$rrow['chat_room_url'] = str_ireplace("streamate.com",$siteData['whitelabel_domain'],$rrow[$siteData['preferredLink']]);
$rrow['chat_room_url'] = str_ireplace("?AFNO=0","",$rrow['chat_room_url']);
}
return $rrow['chat_room_url'];
}