File: /home/httpd/html/baretube.com.new/admin/functions.general.php
<?php
/**
* updateContentSearch - Caches data to content_search table from content table.
*
* @param [in] $id content id
* @return void
*
*/
function updateContentSearch($id) {
global $dblink;
$record_num = (int)$id;
$array = dbQuery("SELECT * FROM content WHERE record_num = '$id'",false);
$row = $array[0];
$getLangs = mysqli_query($dblink,"SELECT title,keywords,description FROM content_languages WHERE content = $record_num");
if(mysqli_num_rows($getLangs) > 0) {
while($lang = mysqli_fetch_assoc($getLangs)) {
if(!empty($lang['title'])) {
$tmp['titles'][] = $lang['title'];
}
if(!empty($lang['keywords'])) {
$tmp['keywords'][] = $lang['keywords'];
}
if(!empty($lang['description'])) {
$tmp['descriptions'][] = $lang['description'];
}
}
if(!empty($tmp['titles'])) {
$array[$record_num]['titles'] = "$row[title],".implode(",",$tmp['titles']);
} else {
$array[$record_num]['titles'] = "$row[title]";
}
if(!empty($tmp['keywords'])) {
$array[$record_num]['keywords'] = "$row[keywords],".implode(",",$tmp['keywords']);
} else {
$array[$record_num]['keywords'] = "$row[keywords]";
}
if(!empty($tmp['descriptions'])) {
$array[$record_num]['descriptions'] = "$row[description],".implode(",",$tmp['descriptions']);
} else {
$array[$record_num]['descriptions'] = "$row[description]";
}
unset($tmp);
$titles = mysqli_real_escape_string($dblink,$array[$record_num]['titles']);
$keywords = mysqli_real_escape_string($dblink,$array[$record_num]['keywords']);
$descriptions = mysqli_real_escape_string($dblink, $array[$record_num]['descriptions']);
$photos = $array[$record_num]['photos'];
mysqli_query($dblink,"DELETE FROM content_search WHERE content = '$record_num'");
mysqli_query($dblink,"INSERT INTO content_search(titles,keywords,descriptions,content,photos) VALUES('$titles','$keywords','$descriptions','$record_num','$photos')");
} else {
mysqli_query($dblink,"DELETE FROM content_search WHERE content = '$record_num'");
mysqli_query($dblink,"INSERT INTO content_search (titles,keywords,descriptions,content,photos) VALUES('$row[title]','$row[keywords]','$row[description]','$record_num','0')");
}
}
/**
* updateRelatedVideos - Updates related videos
*
* @param [in] $id content id
* @return void
*
*/
function updateRelatedVideos($id) {
global $dblink;
$row = dbRow("SELECT * FROM `content` WHERE `record_num` = '$id'");
if (is_array($row)) {
$relatedVideos = array();
$string = mysqli_real_escape_string($dblink, "$row[title] $row[keywords]");
$results = dbQuery("SELECT `content`.*, (MATCH (`title`, `keywords`) AGAINST ('$string')) AS `score` FROM `content` WHERE `enabled` = 1 AND `record_num` != '" . (int) $row['record_num'] . "' AND MATCH (`title`, `keywords`) AGAINST ('$string' IN BOOLEAN MODE) HAVING `score` > 0 ORDER BY `score` DESC LIMIT 0, 50", false);
if (is_array($results)) {
foreach ($results as $rrow) {
$relatedVideos[] = $rrow['record_num'];
}
}
if(is_array($relatedVideos)) {
$relatedVideos = implode(",",$relatedVideos);
dbQuery("UPDATE content SET `related` = '$relatedVideos' WHERE record_num = '$id'");
}
}
}
/**
* getVideoLink - Gets video link. Not used anymore.
*
* @param [in] $row Array of content table data
* @return string
*
*/
function getVideoLink($row) {
global $basehttp;
$bad = array('%', '?', '!', ' ', '&', '*', '$', '#', '@', '\'', '√ß', '‰ß', '√©', '‰©', '√®', '‰®', '√™', '‰™', '√´', '‰´', '√?', '‰?', '√?', '‰?', '√Æ', '‰Æ', '√Ø', '‰Ø', '√¨', '√?', '‰?', '√≤', '‰≤', '√¥', '‰¥', '√∂', '‰∂', '√µ', '√≥', '√∏', '‰µ', '‰≥', '‰∏', '√?', '‰?', '√?', '‰?', '√ ', '‰ ', '√¢', '‰¢', '√§', '‰§', '√•', '‰•', '√?', '‰?', '√?', '‰?', '√π', '√ª', '√º', '‰º', '√?', '√?', '‰π', '‰ª', '‰º', '‰º', '‰?', '‰?', '√≤', '√±', 'Á', 'Á', 'È', 'È', 'Ë', 'Ë', 'Í', 'Í', 'Î', 'Î', ' ', ' ', 'À', 'À', 'Ó', 'Ó', 'Ô', 'Ô', 'Ï', 'Œ', 'Œ', 'Ú', 'Ú', 'Ù', 'Ù', 'ˆ', 'ˆ', 'ı', 'Û', '¯', 'ı', 'Û', '¯', '‘', '‘', '÷', '÷', '‡', '‡', '‚', '‚', '‰', '‰', 'Â', 'Â', '¬', '¬', 'ƒ', 'ƒ', 'u', '˚', '¸', '¸', '€', '‹', 'u', '˚', '¸', '¸', '€', '‹', 'Ò', 'Ò', '.', '…', '√?', 'a?', ',');
$good = array('', '', '', '-', '', '', '', '', '', '', 'c', 'c', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'n', 'n" ,"c', 'c', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'n', 'n', '', 'e', 'e', 'e', '');
return "$basehttp/videos/" . strtolower(str_replace($bad, $good, $row['title'])) . "-" . $row['record_num'] . ".html";
}
/**
* generateUrl - Generates URLs
*
* @param [in] $type Not yet documented.
* @param [in] $name Not yet documented.
* @param [in] $content_id content id
* @return string
*
*/
function generateUrl($type, $name, $content_id) {
global $basehttp;
switch ($type) {
case 'video':
return $basehttp . '/' . $type . '/' . clearString($name) . '-' . $content_id . '.html';
break;
case 'galleries':
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;
case 'pornstar':
return $basehttp . '/pornstars/' . clearString($name) . '-' . $content_id . '.html';
break;
case 'model':
return $basehttp . '/models/' . clearString($name) . '-' . $content_id . '.html';
break;
case 'user':
return $basehttp . '/' . $type . '/' . clearString($name) . '-' . $content_id . '/';
break;
default:
return $basehttp . '/' . $type . '/' . clearString($name) . '-' . $content_id . '.html';
break;
}
}
/**
* validateUser - Checks if a username/password combo is correct
*
* @param [in] $username Not yet documented.
* @param [in] $password Not yet documented.
* @return boolean
*
*/
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;
}
/**
* clearString - Removes special characters from a string.
*
* @param [in] $string Not yet documented.
* @return string
*
*/
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, '-');
}
/**
* makeImageThumbnail - Creates a thumbnail using convert command line
*
* @param [in] $input Not yet documented.
* @param [in] $output Not yet documented.
* @param [in] $thumbwidth Not yet documented.
* @param [in] $thumbheight Not yet documented.
* @param [in] $mode Not yet documented.
* @return void
*
*/
function makeImageThumbnail($input, $output, $thumbwidth, $thumbheight, $mode = 'convert') {
global $convert_path;
global $mogrify_path;
global $jpegoptim_path;
global $jpegoptim_command;
if ($input == $output) {
exit("Error: makeImageThumbnail() input and output cannot be the same!");
}
if ($mode == 'convert') {
$convert_mode = $convert_path;
} else {
$convert_mode = $mogrify_path;
}
shell_exec("$convert_mode -adaptive-resize " . ($thumbwidth) . "x" . ($thumbheight) . "^ -gravity Center -extent " . $thumbwidth . "x" . $thumbheight . " \"$input\" \"$output\"");
if($jpegoptim_path) { shell_exec("$jpegoptim_path $jpegoptim_command \"$input\""); }
if($jpegoptim_path) { shell_exec("$jpegoptim_path $jpegoptim_command \"$output\""); }
}
/**
* generateSlug - Generates a slug for a content id
*
* @param [in] $contentid Not yet documented.
* @return void
*
*/
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");
}
}
/**
* generateChannelsAdmin - Generates a list of channels for a piece of content for admin area.
*
* @param [in] $id Not yet documented.
* @return string
*
*/
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;
}
/**
* recursive_array_search - A summary has for this function has not yet been written.
*
* @param [in] $needle Not yet documented.
* @param [in] $haystack Not yet documented.
* @return void
*
*/
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;
}
/**
* getMediaServerData - Gets media server for a content id
*
* @param [in] $videoid Not yet documented.
* @return void
*
*/
function getMediaServerData($videoid) {
$vid = (int) $videoid;
$getServer = dbQuery("SELECT * FROM servers WHERE record_num = (SELECT server FROM content WHERE record_num = $vid AND server != 0)", false);
if (!empty($getServer)) {
return $getServer[0];
}
return false;
}
/**
* getMediaURLs - Generates media urls for videos
*
* @param [in] $rrow Data array from content table.
* @return void
*
*/
function getMediaURLs($rrow) {
global $multiple_servers;
global $video_url;
global $modsec_enabled;
global $hashFunction;
global $hashKey;
global $hashTime;
if ($multiple_servers == 1) {
$server = getMediaServerData($rrow['record_num']);
if ($server) {
$video_url = $server['url_path'];
}
}
if($hashFunction && $hashKey && $hashTime) {
$server['hash_function'] = $hashFunction;
}
$subdir = $rrow[filename][0] . '/' . $rrow[filename][1] . '/' . $rrow[filename][2] . '/' . $rrow[filename][3] . '/' . $rrow[filename][4] . '/';
if ($rrow['filename']) {
if ($server['hash_function']) {
$output['filename'] = call_user_func($server['hash_function'], array($rrow, 'filename'));
} else {
if ($modsec_enabled) {
$output['filename'] = getMediaLink($subdir . $rrow['filename']);
} else {
$output['filename'] = $video_url . '/' . $subdir . $rrow['filename'];
}
}
}
if ($rrow['mobile']) {
if ($server['hash_function']) {
$output['mobile'] = call_user_func($server['hash_function'], array($rrow, 'mobile'));
} else {
if ($modsec_enabled) {
$output['mobile'] = getMediaLink($subdir . $rrow['mobile']);
} else {
$output['mobile'] = $video_url . '/' . $subdir . $rrow['mobile'];
}
}
}
if ($rrow['trailer_filename']) {
if ($server['hash_function']) {
$output['trailer_filename'] = call_user_func($server['hash_function'], array($rrow, 'trailer_filename'));
} else {
if ($modsec_enabled) {
$output['trailer_filename'] = getMediaLink($subdir . $rrow['trailer_filename']);
} else {
$output['trailer_filename'] = $video_url . '/' . $subdir . $rrow['trailer_filename'];
}
}
}
return $output;
}
/**
* secureEval - eval() but secure.
*
* @param [in] $input Not yet documented.
* @return void
*
*/
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);
}
/**
* pageDenied - Spawns 401 access denied header and page.
*
* @param [in] $admin Not yet documented.
* @return void
*
*/
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();
}
}
/**
* pageNotFound - Spawns 404 page
*
* @param [in] $admin Not yet documented.
* @return void
*
*/
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();
}
}
/**
* pageError - Spawns error page
*
* @return void
*
*/
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();
}
/**
* createUserSession - Creates a user session
*
* @param [in] $user Not yet documented.
* @return void
*
*/
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;
}
}
/**
* updateUserSession - Updates a user session
*
* @return void
*
*/
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();
}
}
/**
* getVttImages - Generates a list of VTT images for a video.
*
* @param [in] $orig_filename Not yet documented.
* @param [in] $filename Not yet documented.
* @param [in] $number Not yet documented.
* @param [in] $big Not yet documented.
* @return string
*
*/
function getVttImages($orig_filename,$filename,$number,$big = false) {
global $thumb_url;
$dirname = str_replace('.flv','',$orig_filename);
$subdir = $filename[0].'/'.$filename[1].'/'.$filename[2].'/'.$filename[3].'/'.$filename[4].'/';
$dirname = $subdir.rawurlencode($dirname);
$number = str_pad($number,3,0,STR_PAD_LEFT);
$overlay = $thumb_url.'/'.$dirname."/vtt_$number.jpg";
//$overlay = '/media/thumbs/'.$dirname."/vtt_$number.jpg";
return $overlay;
}