count-1] == 'ua' ) $domain_allow_count = -3; $domain_cookie = array_slice($domain_cookie, $domain_allow_count); } $domain_cookie = "." . implode (".", $domain_cookie); if( (ip2long($_SERVER['HTTP_HOST']) == -1 OR ip2long($_SERVER['HTTP_HOST']) === FALSE) AND strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' ) define( 'DOMAIN', $domain_cookie ); else define( 'DOMAIN', null ); } else define( 'DOMAIN', null ); $mcache = false; if ( $config['cache_type'] ) { if ( class_exists( 'Memcache' ) ) { $mcache = new Memcache(); } elseif( class_exists( 'Memcached' ) ) { $mcache = new Memcached(); } if($mcache !== false ) { $memcache_server = explode(":", $config['memcache_server']); if ($memcache_server[0] == 'unix') { $memcache_server = array($config['memcache_server'], 0); } if ( !$mcache->addServer($memcache_server[0], $memcache_server[1]) ) { $mcache = false; } if ( $mcache->getStats() === FALSE ) { $mcache = false; } } } function dle_session( $sid = false ) { $params = session_get_cookie_params(); if ( DOMAIN ) $params['domain'] = DOMAIN; if( version_compare(PHP_VERSION, '5.2', '<') ) { session_set_cookie_params($params['lifetime'], "/", $params['domain']."; HttpOnly", $params['secure']); } else { session_set_cookie_params($params['lifetime'], "/", $params['domain'], $params['secure'], true); } if ( $sid ) @session_id( $sid ); @session_start(); } function formatsize($file_size) { if( !$file_size OR $file_size < 1) return '0 b'; $prefix = array("b", "Kb", "Mb", "Gb", "Tb"); $exp = floor(log($file_size, 1024)) | 0; return round($file_size / (pow(1024, $exp)), 2).' '.$prefix[$exp]; } class microTimer { var $time; function __construct() { $this->time = $this->get_real_time(); } function get() { return round( ($this->get_real_time() - $this->time), 5 ); } function get_real_time() { list ( $seconds, $microSeconds ) = explode( ' ', microtime() ); return (( float ) $seconds + ( float ) $microSeconds); } } function flooder($ip, $news_time = false) { global $config, $db; if ( $news_time ) { $this_time = time() - $news_time; $db->query( "DELETE FROM " . PREFIX . "_flood where id < '$this_time' AND flag='1' " ); $row = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_flood WHERE ip = '$ip' AND flag='1'"); if( $row['count'] ) return TRUE; else return FALSE; } else { $this_time = time() - $config['flood_time']; $db->query( "DELETE FROM " . PREFIX . "_flood where id < '$this_time' AND flag='0' " ); $row = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_flood WHERE ip = '$ip' AND flag='0'"); if( $row['count'] ) return TRUE; else return FALSE; } } function totranslit($var, $lower = true, $punkt = true) { global $langtranslit; if ( is_array($var) ) return ""; $var = str_replace(chr(0), '', $var); if (!is_array ( $langtranslit ) OR !count( $langtranslit ) ) { $var = trim( strip_tags( $var ) ); if ( $punkt ) $var = preg_replace( "/[^a-z0-9\_\-.]+/mi", "", $var ); else $var = preg_replace( "/[^a-z0-9\_\-]+/mi", "", $var ); $var = preg_replace( '#[.]+#i', '.', $var ); $var = str_ireplace( ".php", ".ppp", $var ); if ( $lower ) $var = strtolower( $var ); return $var; } $var = trim( strip_tags( $var ) ); $var = preg_replace( "/\s+/ms", "-", $var ); $var = str_replace( "/", "-", $var ); $var = strtr($var, $langtranslit); if ( $punkt ) $var = preg_replace( "/[^a-z0-9\_\-.]+/mi", "", $var ); else $var = preg_replace( "/[^a-z0-9\_\-]+/mi", "", $var ); $var = preg_replace( '#[\-]+#i', '-', $var ); $var = preg_replace( '#[.]+#i', '.', $var ); if ( $lower ) $var = strtolower( $var ); $var = str_ireplace( ".php", "", $var ); $var = str_ireplace( ".php", ".ppp", $var ); if( strlen( $var ) > 200 ) { $var = substr( $var, 0, 200 ); if( ($temp_max = strrpos( $var, '-' )) ) $var = substr( $var, 0, $temp_max ); } return $var; } function langdate($format, $stamp, $servertime = false, $custom = false ) { global $langdate, $member_id, $customlangdate; $timezones = array('Pacific/Midway','US/Samoa','US/Hawaii','US/Alaska','US/Pacific','America/Tijuana','US/Arizona','US/Mountain','America/Chihuahua','America/Mazatlan','America/Mexico_City','America/Monterrey','US/Central','US/Eastern','US/East-Indiana','America/Lima','America/Caracas','Canada/Atlantic','America/La_Paz','America/Santiago','Canada/Newfoundland','America/Buenos_Aires','Greenland','Atlantic/Stanley','Atlantic/Azores','Africa/Casablanca','Europe/Dublin','Europe/Lisbon','Europe/London','Europe/Amsterdam','Europe/Belgrade','Europe/Berlin','Europe/Bratislava','Europe/Brussels','Europe/Budapest','Europe/Copenhagen','Europe/Madrid','Europe/Paris','Europe/Prague','Europe/Rome','Europe/Sarajevo','Europe/Stockholm','Europe/Vienna','Europe/Warsaw','Europe/Zagreb','Europe/Athens','Europe/Bucharest','Europe/Helsinki','Europe/Istanbul','Asia/Jerusalem','Europe/Kiev','Europe/Minsk','Europe/Riga','Europe/Sofia','Europe/Tallinn','Europe/Vilnius','Asia/Baghdad','Asia/Kuwait','Africa/Nairobi','Asia/Tehran','Europe/Kaliningrad','Europe/Moscow','Europe/Volgograd','Europe/Samara','Asia/Baku','Asia/Muscat','Asia/Tbilisi','Asia/Yerevan','Asia/Kabul','Asia/Yekaterinburg','Asia/Tashkent','Asia/Kolkata','Asia/Kathmandu','Asia/Almaty','Asia/Novosibirsk','Asia/Jakarta','Asia/Krasnoyarsk','Asia/Hong_Kong','Asia/Kuala_Lumpur','Asia/Singapore','Asia/Taipei','Asia/Ulaanbaatar','Asia/Urumqi','Asia/Irkutsk','Asia/Seoul','Asia/Tokyo','Australia/Adelaide','Australia/Darwin','Asia/Yakutsk','Australia/Brisbane','Pacific/Port_Moresby','Australia/Sydney','Asia/Vladivostok','Asia/Sakhalin','Asia/Magadan','Pacific/Auckland','Pacific/Fiji'); if( is_array($custom) ) $locallangdate = $customlangdate; else $locallangdate = $langdate; if (!$stamp) { $stamp = time(); } $local = new DateTime('@'.$stamp); if (isset($member_id['timezone']) AND $member_id['timezone'] AND !$servertime) { $localzone = $member_id['timezone']; } else { $localzone = date_default_timezone_get(); } if (!in_array($localzone, $timezones)) $localzone = 'Europe/Moscow'; $local->setTimeZone(new DateTimeZone($localzone)); return strtr( $local->format($format), $locallangdate ); } function formdate( $matches=array() ) { global $news_date, $customlangdate; return langdate($matches[1], $news_date, false, $customlangdate); } function check_newscount( $matches=array() ) { global $global_news_count; $block = $matches[3]; $counts = explode( ',', $matches[2] ); if( $matches[1] == "newscount" ) { if( !in_array($global_news_count, $counts) ) return ""; } else { if( in_array($global_news_count, $counts) ) return ""; } return $block; } function msgbox($title, $text) { global $tpl; if (!class_exists('dle_template')) { return; } $tpl_2 = new dle_template( ); $tpl_2->dir = TEMPLATE_DIR; $tpl_2->load_template( 'info.tpl' ); $tpl_2->set( '{error}', $text ); $tpl_2->set( '{title}', $title ); $tpl_2->compile( 'info' ); $tpl_2->clear(); $tpl->result['info'] .= $tpl_2->result['info']; } function ShowRating($id, $rating, $vote_num, $allow = true) { global $lang, $config; if( !$config['rating_type'] ) { if( $rating AND $vote_num ) $rating = round( ($rating / $vote_num), 0 ); else $rating = 0; if ($rating < 0 ) $rating = 0; $rating = $rating * 20; if( !$allow ) { $rated = << HTML; return $rated; } $rated = <<
HTML; return $rated; } elseif ($config['rating_type'] == "1") { if( $rating < 0 ) $rating = 0; if( $allow ) $rated = "{$rating}"; else $rated = "{$rating}"; return $rated; } elseif ($config['rating_type'] == "2") { $extraclass = "ratingzero"; if( $rating < 0 ) { $extraclass = "ratingminus"; } if( $rating > 0 ) { $extraclass = "ratingplus"; $rating = "+".$rating; } if( $allow ) $rated = "{$rating}"; else $rated = "{$rating}"; return $rated; } } function ShowCommentsRating($id, $rating, $vote_num, $allow = true) { global $lang, $config; if( !$config['comments_rating_type'] ) { if( $rating AND $vote_num ) $rating = round( ($rating / $vote_num), 0 ); else $rating = 0; if ($rating < 0 ) $rating = 0; $rating = $rating * 20; if( !$allow ) { $rated = << HTML; return $rated; } $rated = <<
HTML; return $rated; } elseif ($config['comments_rating_type'] == "1") { if( $rating < 0 ) $rating = 0; if( $allow ) $rated = "{$rating}"; else $rated = "{$rating}"; return $rated; } elseif ($config['comments_rating_type'] == "2") { $extraclass = "ratingzero"; if( $rating < 0 ) { $extraclass = "ratingminus"; } if( $rating > 0 ) { $extraclass = "ratingplus"; $rating = "+".$rating; } if( $allow ) $rated = "{$rating}"; else $rated = "{$rating}"; return $rated; } } function userrating($id) { global $db, $config; $id = intval($id); $row = $db->super_query( "SELECT SUM(rating) as rating, SUM(vote_num) as num FROM " . PREFIX . "_post_extras WHERE user_id ='{$id}'" ); if( !$config['rating_type'] ) { if( $row['num'] ) $rating = round( ($row['rating'] / $row['num']), 0 ); else $rating = 0; if ($rating < 0 ) $rating = 0; $rating = $rating * 20; $rated = << HTML; return $rated; } elseif ($config['rating_type'] == "1") { if( $row['num'] ) $rating = number_format($row['rating'], 0, ',', ' '); else $rating = 0; if( $rating < 0 ) $rating = 0; return "{$rating}"; } elseif ($config['rating_type'] == "2") { if( $row['num'] ) $rating = number_format($row['rating'], 0, ',', ' '); else $rating = 0; $extraclass = "ratingzero"; if( $rating < 0 ) { $extraclass = "ratingminus"; } if( $rating > 0 ) { $extraclass = "ratingplus"; $rating = "+".$rating; } return "{$rating}"; } } function commentsuserrating($id) { global $db, $config; $id = intval($id); $row = $db->super_query( "SELECT SUM(rating) as rating, SUM(vote_num) as num FROM " . PREFIX . "_comments WHERE user_id ='{$id}'" ); if( !$config['comments_rating_type'] ) { if( $row['num'] ) $rating = round( ($row['rating'] / $row['num']), 0 ); else $rating = 0; if ($rating < 0 ) $rating = 0; $rating = $rating * 20; $rated = << HTML; return $rated; } elseif ($config['comments_rating_type'] == "1") { if( $row['num'] ) $rating = number_format($row['rating'], 0, ',', ' '); else $rating = 0; if( $rating < 0 ) $rating = 0; return "{$rating}"; } elseif ($config['comments_rating_type'] == "2") { if( $row['num'] ) $rating = number_format($row['rating'], 0, ',', ' '); else $rating = 0; $extraclass = "ratingzero"; if( $rating < 0 ) { $extraclass = "ratingminus"; } if( $rating > 0 ) { $extraclass = "ratingplus"; $rating = "+".$rating; } return "{$rating}"; } } function CategoryNewsSelection($categoryid = 0, $parentid = 0, $nocat = TRUE, $sublevelmarker = '', $returnstring = '') { global $cat_info, $user_group, $member_id, $dle_module; if ($dle_module == 'addnews') $allow_list = explode( ',', $user_group[$member_id['user_group']]['cat_allow_addnews'] ); else $allow_list = explode( ',', $user_group[$member_id['user_group']]['allow_cats'] ); $not_allow_list = explode( ',', $user_group[$member_id['user_group']]['not_allow_cats'] ); $spec_list = explode( ',', $user_group[$member_id['user_group']]['cat_add'] ); $root_category = array (); if( $parentid == 0 ) { if( $nocat ) $returnstring .= ''; } else { $sublevelmarker .= '   '; } if( count( $cat_info ) ) { foreach ( $cat_info as $cats ) { if( $cats['parentid'] == $parentid ) $root_category[] = $cats['id']; } if( count( $root_category ) ) { foreach ( $root_category as $id ) { if( $allow_list[0] == "all" OR in_array( $id, $allow_list ) ) { if( in_array( $id, $not_allow_list ) ) continue; if( $spec_list[0] == "all" or in_array( $id, $spec_list ) ) $color = "black"; else $color = "red"; $returnstring .= "