/* * * Common utilities */ error_reporting(E_ALL); ob_start("ob_gzhandler"); function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float) $usec + (float) $sec); } $starttime = getmicrotime(); dbg_checktimepoint("start"); $load = sys_getloadavg(); if ($load[0] > 30) { header('HTTP/1.1 503 Too busy, try again later'); die('Server too busy. Please try again later.'); } $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; define('CE_CHOICE', 100000); define('GUIDE_CHOICE', 1000); define('CONTENT_EDITOR_NAME', "/cmt2/editor.php"); $member_hair_col_arr[0] = "цвет волос"; $member_hair_col_arr[1] = "блондин(ка)"; $member_hair_col_arr[2] = "брюнет(ка)"; $member_hair_col_arr[3] = "шатен(ка)"; $member_hair_col_arr[4] = "русые"; $member_hair_col_arr[5] = "рыжие"; $member_hair_col_arr[6] = "седые"; $member_hair_col_arr[7] = "зеленые"; $member_hair_col_arr[8] = "черные"; $member_hair_col_arr[9] = "мелированные"; $member_hair_col_arr[10] = "лысый(ая)"; $member_eyes_col_arr[0] = "цвет глаз"; $member_eyes_col_arr[1] = "зеленые"; $member_eyes_col_arr[2] = "синие"; $member_eyes_col_arr[3] = "голубые"; $member_eyes_col_arr[4] = "серые"; $member_eyes_col_arr[5] = "карие"; $member_eyes_col_arr[6] = "черные"; $member_eyes_col_arr[7] = "желтые"; $member_eyes_col_arr[8] = "красные"; $member_eyes_col_arr[9] = "мутные"; $member_eyes_col_arr[10] = "пустые"; $member_children_dat[0] = "дети"; $member_children_dat[1] = "нет"; $member_children_dat[2] = "есть"; $member_children_dat[3] = "1"; $member_children_dat[4] = "2"; $member_children_dat[5] = "3"; $member_children_dat[6] = "4+"; $member_Education_dat[0] = "образование"; $member_Education_dat[1] = "начальное"; $member_Education_dat[2] = "незак. среднее"; $member_Education_dat[3] = "среднее"; $member_Education_dat[4] = "незак. высшее"; $member_Education_dat[5] = "высшее"; $member_Education_dat[6] = "2+ высших"; if (is_file($_SERVER['DOCUMENT_ROOT'] . "/../gvmp.ini")) { /* * * Local settings exist so load them. */ include $_SERVER['DOCUMENT_ROOT'] . "/../gvmp.ini"; } else { die("NOCONFIG"); } /* require_once "memcached-client.php"; $mc = new memcached(array( 'servers' => array('127.0.0.1:11211'), 'debug' => false, 'compress_threshold' => 10240, 'persistant' => true)); */ function MakePassPhrase($PasswordLength = 5, $ForceLang = false) { global $SLANG; list($usec, $sec) = explode(' ', microtime()); mt_srand((float) $sec + ((float) $usec * 100000)); $passphrase = ''; if ($ForceLang) { $ttLANG = $ForceLang; } else { $ttLANG = $SLANG; } if ($ttLANG == 'Ru') { $Alphabet = '23456789цукенгхфывапрлджячсмитю'; } else { $Alphabet = '23456789qwertyupasdfghkjzxcvbnm'; } $Alphabet = '23456789qwertyupasdfghkjzxcvbnm'; for ($i = 0; $i < $PasswordLength; $i++) { $passphrase .= $Alphabet[mt_rand(0, strlen($Alphabet) - 1)]; } return $passphrase; } function MakeVeriCode() { global $DB, $SLANG; $hid = DBInsert( $DB, 'DC2_passverification', array( 'passphrase' => QuoteAndSlashes(MakePassPhrase()) ) ); DBExec($DB, 'delete from DC2_passverification where regdate < date_sub( now(), interval 1 hour )'); return md5($hid); } // MakeVeriCode() function CheckVeriCode($node, $VeriCode) { global $DB; $Data = GetObject($DB, "select * from DC2_passverification where md5(id)=" . QuoteAndSlashes($node)); if ($VeriCode == '' || !$Data || !$Data['passphrase'] || ($VeriCode) != ($Data['passphrase'])) { return false; } else { return true; } } // CheckVeriCode($node, $VeriCode) ; function ImageVeriCode($hid, $ttfPath) { global $DB; $Data = GetObject($DB, "select * from DC2_passverification where md5(id)=" . QuoteAndSlashes($hid)); $string = $Data['passphrase']; $im = @imagecreatetruecolor(100, 32) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); //D6DBDF $text_color[] = imagecolorallocate($im, 255, 0, 0); $text_color[] = imagecolorallocate($im, 0, 0xA0, 0); $text_color[] = imagecolorallocate($im, 0, 0, 255); $text_color[] = imagecolorallocate($im, 255, 0, 255); $text_color[] = imagecolorallocate($im, 0, 0xE0, 0xE0); $text_color[] = imagecolorallocate($im, 0xD0, 0xD0, 0); imagefilledrectangle($im, 0, 0, 99, 31, $background_color); // Set the enviroment variable for GD putenv('GDFONTPATH=' . realpath($ttfPath)); list($usec, $sec) = explode(' ', microtime()); mt_srand((float) $sec + ((float) $usec * 100000)); $cc = mt_rand(0, 5); for ($i = 0; $i < strlen($Data['passphrase']); $i++) { // size angle imagettftext($im, 14 + mt_rand(0, 5), 45 - mt_rand(0, 90), // X Y color 10 + 16 * $i /* +mt_rand(0,5) */, 25 /* 30-mt_rand(2,7) */, $text_color[($cc + $i) % 5], $_SERVER['DOCUMENT_ROOT'] . "/../verdana.ttf", iconv('cp1251', 'UTF-8', $Data['passphrase'][$i])); } header("Content-type: image/png"); imagepng($im); imagedestroy($im); } // ImageVeriCode function CountComments($ORIGINATOR_ID, $ORIGINATOR_TYPE = 'FORUM') { global $DB; $ORIGINATOR_ID = intval($ORIGINATOR_ID); $SQL = "select count(*) as cnt from AIV_COMMENTS where COMMENTS_ORIGINATOR_ID = '$ORIGINATOR_ID' and COMMENTS_ORIGINATOR_TYPE=" . QuoteAndSlashes($ORIGINATOR_TYPE); $result = GetObject($DB, $SQL); return $result["cnt"]; } function ErrorMessage($msg) { echo "$msg"; } function RuHyphen($text) { $RusA = "[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]"; $RusV = "[аеёиоуыэюя]"; $RusN = "[бвгджзклмнпрстфхцчшщ]"; $RusX = "[йъь]"; $text = preg_replace("/($RusX)($RusA$RusA)/", "\\1\\2", $text); $text = preg_replace("/($RusV)($RusV$RusA)/", "\\1\\2", $text); $text = preg_replace("/($RusV$RusN)($RusN$RusV)/", "\\1\\2", $text); $text = preg_replace("/($RusN$RusV)($RusN$RusV)/", "\\1\\2", $text); $text = preg_replace("/($RusV$RusN)($RusN$RusN$RusV)/", "\\1\\2", $text); $text = preg_replace("/($RusV$RusN$RusN)($RusN$RusN$RusV)/", "\\1\\2", $text); return $text; } function StripTAGS($THEARTICLE) { return strip_tags($THEARTICLE); } function __Sanitize(&$a) { if (is_array($a)) { foreach ($a as $k => $v) { __Sanitize($a[$k]); } } else { $a = str_replace('<' . '?', '<?', $a); $a = str_replace('?' . '>', '?>', $a); $a = str_replace('<' . '%', '<%', $a); $a = str_replace('%' . '>', '%>', $a); $a = trim($a); } } function Sanitize(&$a) { if (!isCE()) { /* sanitize input for non admins */ __Sanitize($a); } } function HTMLCleaner($Data, $StripOther = true, $StripHeader = true, $StripStyles = true, $StripClass = true, $StripSpan = true, $StripEmptySpace = true, $StripFontTags = false ) { $NLSeparator = "___HTMLCleaner___NEW___LINE_" . date('YmgHis') . "__"; $buff = preg_replace("/[ ]{0,}[\n\r]{1,}[ ]{0,}/", "$NLSeparator", $Data); if ($StripHeader) { $buff = preg_replace("/]*>/i", "", $buff); $buff = str_ireplace("", "", $buff); $buff = str_ireplace("
]*>/i", "", $buff); $buff = preg_replace("/]*>/i", "", $buff); $buff = preg_replace("/.*<\/head>/i", "", $buff); } if ($StripOther) { $buff = str_ireplace("