* @package Common * @version 1.5 28.03.2006 * @ver1.5 28.03.2006 * - * @ver1.4 22.02.2006 * - , after * @ver1.3 02.02.2006 * - db.php old.php * @ver1.2 28.12.2005 * - * @ver1.1 * - UNIX timestamp */ function t($name='test') { $_SERVER['SERVER_NAME'] = $name; } /** * . * @param string $file * @return boolean */ function check_file($file) { global $main_lang; if (!isset($_FILES[$file])) { return false; } switch ($_FILES[$file]['error']) { case UPLOAD_ERR_NO_FILE: // $result = false; break; case UPLOAD_ERR_PARTIAL: printf($main_lang['loaded_file_partially']."
", $_FILES[$file]['name']); $result = false; break; case UPLOAD_ERR_FORM_SIZE: printf($main_lang['size_loaded_file_exceeded']."
", $_FILES[$file]['name']); $result = false; break; case UPLOAD_ERR_INI_SIZE: printf($main_lang['accepted_file_admissible_size']."
", $_FILES[$file]['name']); $result = false; break; case UPLOAD_ERR_OK: $result = true; break; default: printf($main_lang['unknown_error_code_file']."
", $_FILES[$file]['error'], $_FILES[$file]['name']); $result = false; break; } return $result; }//\\check_file function canonicalize($address) { $address = explode('/', $address); $keys = array_keys($address, '..'); foreach($keys AS $keypos => $key) { array_splice($address, $key - ($keypos * 2 + 1), 2); } $address = implode('/', $address); $address = str_replace('./', '', $address); return $address; } /** * , . * @param string $dir */ function check_dir($dir) { $dir = canonicalize($dir); clearstatcache(); if (!is_dir($dir)) { mkdir($dir, 0777); } return $dir; }//\\check_dir /** * . * @param integer $errno * @param string $errmsg * @param string $filename * @param integer $linenum * @param array $vars */ function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { $dt = date("Y-m-d H:i:s (T)"); $errortype = array( E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', //E_STRICT => 'Runtime Notice', ); $err = " ".$_SERVER['SERVER_NAME']."\n"; $err .= "\t: ".$dt."\n"; $err .= "\t : ".$errno."\n"; $err .= "\t : ".$errortype[$errno]."\n"; $err .= "\t: ".$errmsg."\n"; $err .= "\t: ".$filename."\n"; $err .= "\t: ".$linenum."\n"; $err .= "\tVars: ".wddx_serialize_value($vars, "Variables")."\n"; echo nl2br($err).'
'; mail(ERROR_MAIL, ' '.$_SERVER['SERVER_NAME'], $err, "Return-Path:".SENDER_MAIL."\nFrom:".SENDER_MAIL. "\nContent-Type: text/plain; charset=Windows-1251\n"); }//\\userErrorHandler /** * . * @param integer $length . */ function generate_pass($length = 10) { $arr = array('2', '3', '4', '5', '6', '7', '8', '9', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'z', 'x', 'c', 'v', 'i', 'b', 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'); $n = count($arr) - 1; $str = ''; for ($i=0; $i<$length; $i++) { $str .= $arr[rand(0, $n)]; } if ((strtolower($str)==$str) || (strtoupper($str)==$str)) { return generate_pass(); } else { return $str; } } function delete_from_array($array, $index) { unset($array[$index]); return array_merge(array(), $array); } /** * . * @param string $str * @param boolean $head $head = false * @return string , */ function get_name($str, $head=false) { if (strpos($str, '*')===false) { $str1 = utf8_substr($str, 0, 1); $str2 = utf8_substr($str, 1); if ($head) { return ''.$str1.''.$str2; } else { return ''.$str1.''.$str2.':'; } } else { $str1 = utf8_substr($str, 0, 1); $str2 = utf8_substr(str_replace(' *', ': *', $str), 1); return ''.$str1.''.$str2.''; } }//\\get_name function text_dump(&$var, $level=0) { $result = ''; if (is_array($var)) { $result = 'Array['.count($var).']'; } elseif (is_object($var)) { $result = 'Object'; } else { $result = ''; } if ($result) { $result .= "\n"; for (reset($var), $level++; list($k,$v)=each($var);) { if (is_array($v) && $k==="GLOBALS") continue; $result .= str_repeat(' ', $level*3); $result .= ''.htmlspecialchars($k).' => '.text_dump($v, $level); } } else { $result .= '"'.htmlspecialchars($var).'"'."\n"; } return $result; } function dump(&$var) { if ((is_array($var) || is_object($var)) && count($var)) { return "
\n".text_dump($var)."
\n"; } else { return ''.text_dump($var)."\n"; } } /** * translit. * @param string $str . */ function translit($str, $space_in_use = false) { $translit = array( ''=>'a', ''=>'b', ''=>'v', ''=>'g', ''=>'d', ''=>'e', ''=>'e', ''=>'j', ''=>'z', ''=>'i', ''=>'y', ''=>'k', ''=>'l', ''=>'m', ''=>'n', ''=>'o', ''=>'p', ''=>'r', ''=>'s', ''=>'t', ''=>'u', ''=>'f', ''=>'h', ''=>'ts', ''=>'ch', ''=>'sh', ''=>'sch', ''=>"'", ''=>'i', ''=>"'", ''=>'', ''=>'yu', ''=>'ya', ''=>'A', ''=>'B', ''=>'V', ''=>'G', ''=>'D', ''=>'E', ''=>'E', ''=>'J', ''=>'Z', ''=>'I', ''=>'Y', ''=>'K', ''=>'L', ''=>'M', ''=>'N', ''=>'O', ''=>'P', ''=>'R', ''=>'S', ''=>'T', ''=>'U', ''=>'F', ''=>'H', ''=>'TS', ''=>'CH', ''=>'SH', ''=>'SCH', ''=>"'", ''=>'I', ''=>"'", ''=>'', ''=>'YU', ''=>'YA', ); // : if ($space_in_use){ $translit[' '] = '_'; } return str_replace(array_keys($translit), array_values($translit), $str); }//\\translit function translit2($var) { $Subs = array( " " => "_", "\\" => "-", "/" => "-", "!" => "-", "@" => "-", "#" => "-", "$" => "-", "%" => "-", "^" => "-", "&" => "-", "*" => "-", "(" => "-", ")" => "-", "+" => "-", "|" => "-", "`" => "-", "~" => "-", "[" => "-", "]" => "-", "{" => "-", "}" => "-", ";" => "-", ":" => "-", "'" => "-", "\"" => "-", "<" => "-", ">" => "-", "," => "-", "." => "-", "?" => "-", "" => "-", "" => "A", "" => "B", "" => "V", "" => "G", "" => "D", "" => "E", "" => "E", "" => "J", "" => "Z", "" => "I", "" => "Y", "" => "K", "" => "L", "" => "M", "" => "N", "" => "O", "" => "P", "" => "R", "" => "S", "" => "T", "" => "U", "" => "F", "" => "H", "" => "C", "" => "CH", "" => "SH", "" => "ZH", "" => "", "" => "I", "" => "", "" => "E", "" => "YU", "" => "YA", "" => "a", "" => "b", "" => "v", "" => "g", "" => "d", "" => "e", "" => "e", "" => "j", "" => "z", "" => "i", "" => "y", "" => "k", "" => "l", "" => "m", "" => "n", "" => "o", "" => "p", "" => "r", "" => "s", "" => "t", "" => "u", "" => "f", "" => "h", "" => "c", "" => "ch", "" => "sh", "" => "zh", "" => "", "" => "i", "" => "'", "" => "e", "" => "yu", "" => "ya", ); $var = strtr($var, $Subs); return htmlspecialchars($var); } function only_eng($str) { $eng = array( 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ' ', '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ); $str = str_split($str); foreach ($str as $k => $v) { if (!in_array($v, $eng)) { unset($str[$k]); } } return implode('', $str); } /** * . * @param string $text */ function error($text) { global $main_lang; global $general_lang; $modules = array(); include_once _ADMIN_INC.'templates/header.php'; include_once _ADMIN_INC.'templates/panel.php'; ?>
$col) { $str = substr($str, 0, $col-3); $str = $str.'...'; } else { $str = $str; } return $str; }//\\obrez /** * array _debug_backtrace() * Wrapper around debug_backtrace(). Correctly work with call_user_func* * (totally skip them correcting caller references). * @version 1.00 * @return array */ function debug_backtrace_smart() { if (!is_callable('debug_backtrace')) { return array(); } $trace = debug_backtrace(); $n = sizeof($trace); for ($i=1; $i<$n; $i++) { $func = strtolower(isset($trace[$i]['function'])? $trace[$i]['function'] : ''); if ($func == 'call_user_func' || $func == 'call_user_func_array' || $func == 'send_error') { $trace[$i-1] = array_merge($trace[$i], $trace[$i-1]); $trace[$i-1]['over_call_user_func'] = true; array_splice($trace, $i, 1); $i--; } } array_shift($trace); return $trace; }//\\debug_backtrace_smart if (!function_exists('redirect')) { /** * . * @param string $url * @param integer $time */ function redirect($url='', $time=0) { if ($url=='') { $url = 'index.php'; } if (strtolower(substr($url, 0, 7))!='http://') { if (strtolower(substr($url, 0, 1))=='/') { $url = 'http://'.$_SERVER['SERVER_NAME'].$url; } else { $url = 'http://'.$_SERVER['SERVER_NAME'].'/'.$url; } } header('HTTP/1.1 303 See Other'); header('Location: '.$url); }//\\redirect } /** * . * @param string $str * @return string */ function clean($str) { return mysql_real_escape_string(htmlspecialchars($str)); }//\\clean /** * MySQL. * @param string $new_date dd.mm.Y * @return string Y-mm-dd */ function convert_date_to_DB($date) { $date = explode('.', $date); return $date[2].'-'.$date[1].'-'.$date[0]; }//\\convert_date_to_DB /** * MySQL. * @param string $new_date Y-mm-dd * @return string dd.mm.Y */ function convert_date_from_DB($date) { $date = explode('-', $date); return $date[2].'.'.$date[1].'.'.$date[0]; }//\\convert_date_from_DB /** * - MySQL. * @param string $new_date - * @return string Y-mm-dd hh:mm:ss */ function convert_dt_to_DB($new_date) { $tm = before($new_date, ' '); $new_date = after($new_date, ' '); $day = before($new_date, '.'); $m_y = after($new_date, '.'); $month = before($m_y, '.'); $year = after($m_y, '.'); $date = $year.'-'.$month.'-'.$day.' '.$tm; return $date; }//\\convert_dt_to_DB /** / function convert_group_id_from_db($groupid) { switch($groupid) { case 1: $strret = ''; break; case 2: $strret = ''; break; default: $strret = 'unknown'; } return $strret; } /**/ /** * - MySQL. * @param string $new_date - * @return string hh:mm:ss dd.mm.Y */ function convert_dt_from_DB($new_date) { $tm = after($new_date, ' '); $new_date = before($new_date, ' '); $year = before($new_date, '-'); $m_d = after($new_date, '-'); $month = before($m_d, '-'); $day = after($m_d, '-'); $date = $tm.' '.$day.'.'.$month.'.'.$year; return $date; }//\\convert_dt_from_DB /** * - UNIX timestamp. * @param string $dt Y-m-d H:i:s * @return integer */ function convert_dt_to_time($dt) { $tm = after($dt, ' '); $hour = before($tm, ':'); $m_s = after($tm, ':'); $min = before($m_s, ':'); $sec = after($m_s, ':'); $dt = before($dt, ' '); $year = before($dt, '-'); $m_d = after($dt, '-'); $month = before($m_d, '-'); $day = after($m_d, '-'); return mktime($hour, $min, $sec, $month, $day, $year); }//\\convert_dt_to_time(); /** * - UNIX timestamp. * @param string $date Y-m-d * @return integer */ function convert_date_to_time($date) { $date = explode('-', $date); return mktime(0, 0, 0, $date[1], $date[2], $date[0]); }//\\convert_dt_to_time(); /** * . * @return string */ function backtrace() { $bt = debug_backtrace(); // backtrace() if (isset($bt[0])) { unset($bt[0]); } $str = "\n"; for ($i=0; $i<=count($bt); $i++) { if (isset($bt[$i])) { if (!$bt[$i]) { continue; } $str .= ': '.((isset($bt[$i]['file'])) ? $bt[$i]['file']."\n" : ' '."\n"); $str .= ': '.((isset($bt[$i]['line'])) ? $bt[$i]['line']."\n" : ' '.": \n"); $str .= (isset($bt[$i]['class'])) ? $bt[$i]['class'] : ''; $str .= (isset($bt[$i]['type'])) ? $bt[$i]['type'] : ''; $str .= (isset($bt[$i]['function'])) ? $bt[$i]['function'] : ''; $str .= ' ('; $arglist = ''; if (isset($bt[$i]['args'])) { for ($k=0; $k0) { return $url.'&'.$param; } else { return $url.'?'.$param; } }//\\add_param function lang_select($dirname = "") { if ($dirname == ""){ $dirname = _ADMIN_INC.'language'; } $dir = opendir($dirname); $lang_options = array(); while ($file = readdir($dir)) { if (($file == '.') or ($file == '..')) continue; if (preg_match('#^#i', $file) && !is_file($dirname . '/' . $file) && !is_link($dirname . '/' . $file)) { $filename = trim($file); $displayname = preg_replace('/^(.*?)_(.*)$/', '\1 [ \2 ]', $filename); $displayname = preg_replace('/\[(.*?)_(.*)\]/', '[ \1 - \2 ]', $displayname); $lang_options[$displayname] = $filename; } } closedir($dir); @asort($lang_options); @reset($lang_options); $alang_select = array(); while (list($displayname, $filename) = @each($lang_options)) { $alang_select[] = $displayname; } return $alang_select; } /*************************************************************** * * @param1: $array , * @param2: $sort_by / * @param3: $type SORT_ASC( )/SORT_DESC * @param4: $flag SORT_REGULAR( )/SORT_NUMERIC/SORT_STRING */ function ArrayMultiSort(&$array, $sort_by, $type = 4, $flag = 0) { $sort_type = ($type == 4) ? array(-1, 1) : array(1, -1); $compare_func = create_function('$a, $b', ' if ((!isset($a[\''.$sort_by.'\']))||($a[\''.$sort_by.'\'] == $b[\''.$sort_by.'\'])){ return 0; } else { $val = array($a[\''.$sort_by.'\'], $b[\''.$sort_by.'\']); sort($val, '.$flag.'); if ($a[\''.$sort_by.'\'] == $val[0]){ return '.$sort_type[0].'; } else { return '.$sort_type[1].'; } }' ); if (!function_exists($compare_func)){ return false; } return usort($array, $compare_func); } //\ end ArrayMultiSort /** * MySQL Unix TimeStamp * @param1 string $datetime MySQL * @return integer Unix TimeStamp */ function sql_datetime_to_unix($datetime) { $date = explode('-', $datetime); $year = $date[0]; $month = $date[1]; $date = explode(' ', $date[2]); $day = $date[0]; $date = explode(':', $date[1]); $hour = $date[0]; $min = $date[1]; $sec = $date[2]; return mktime($hour, $min, $sec, $month, $day, $year); } function utf8_substr($str, $offset, $length = NULL) { // generates E_NOTICE // for PHP4 objects, but not PHP5 objects $str = (string) $str; $offset = (int) $offset; if (!is_null($length)) { $length = (int) $length; } // handle trivial cases if ($length === 0 || ($offset < 0 && $length < 0 && $length < $offset)) { return ''; } // normalise negative offsets (we could use a tail // anchored pattern, but they are horribly slow!) if ($offset < 0) { // see notes $strlen = utf8_strlen($str); $offset = $strlen + $offset; if ($offset < 0) { $offset = 0; } } $op = ''; $lp = ''; // establish a pattern for offset, a // non-captured group equal in length to offset if ($offset > 0) { $ox = (int) ($offset / 65535); $oy = $offset % 65535; if ($ox) { $op = '(?:.{65535}){' . $ox . '}'; } $op = '^(?:' . $op . '.{' . $oy . '})'; } else { // offset == 0; just anchor the pattern $op = '^'; } // establish a pattern for length if (is_null($length)) { // the rest of the string $lp = '(.*)$'; } else { if (!isset($strlen)) { // see notes $strlen = utf8_strlen($str); } // another trivial case if ($offset > $strlen) { return ''; } if ($length > 0) { // reduce any length that would // go passed the end of the string $length = min($strlen - $offset, $length); $lx = (int) ($length / 65535); $ly = $length % 65535; // negative length requires a captured group // of length characters if ($lx) { $lp = '(?:.{65535}){' . $lx . '}'; } $lp = '(' . $lp . '.{'. $ly . '})'; } else if ($length < 0) { if ($length < ($offset - $strlen)) { return ''; } $lx = (int)((-$length) / 65535); $ly = (-$length) % 65535; // negative length requires ... capture everything // except a group of -length characters // anchored at the tail-end of the string if ($lx) { $lp = '(?:.{65535}){' . $lx . '}'; } $lp = '(.*)(?:' . $lp . '.{' . $ly . '})$'; } } if (!preg_match('#' . $op . $lp . '#us', $str, $match)) { return ''; } return $match[1]; } function utf8_strlen($text) { return strlen(utf8_decode($text)); } function isSerialized($str) { return ($str == serialize(false) || @unserialize($str) !== false); } function parseUserAgent($ua) { if(!strlen($ua)) return array("unknown","unknown"); $userAgent = array(); $agent = $ua; $products = array(); $pattern = "([^/[:space:]]*)" . "(/([^[:space:]]*))?" ."([[:space:]]*\[[a-zA-Z][a-zA-Z]\])?" . "[[:space:]]*" ."(\\((([^()]|(\\([^()]*\\)))*)\\))?" . "[[:space:]]*"; while( strlen($agent) > 0 ) { if ($l = ereg($pattern, $agent, $a)) { // product, version, comment array_push($products, array($a[1], // Product $a[3], // Version $a[6])); // Comment $agent = substr($agent, $l); } else { $agent = ""; } } // Directly catch these $tmp=""; foreach($products as $product) { switch($product[0]) { case 'Firefox': case 'Netscape': case 'Safari': case 'Camino': case 'Mosaic': case 'Galeon': case 'Opera': case 'Flock': case 'SeaMonkey': case 'K-Meleon': case 'Navigator': if($tmp=='Chrome') break; $userAgent[0] = $product[0]; if($product[0]!="Safari") $userAgent[1] = $product[1]; else $userAgent[1] = $tmp; break; case 'Version': $tmp=$product[1]; break; case 'Chrome': $tmp='Chrome'; $userAgent[0] = $product[0]; $userAgent[1] = $product[1]; break; } } if (count($userAgent) == 0) { // Mozilla compatible (MSIE, konqueror, etc) if(ereg("(MAXTHON) ([^;^ ]*)$",$products[0][2],$tmp)){ $userAgent[0] = $tmp[1]; $userAgent[1] = $tmp[2]; } else if ($products[0][0] == 'Mozilla' && !strncmp($products[0][2], 'compatible;', 11)) { $userAgent = array(); if ($cl = ereg("compatible; ([^ ]*)[ /]([^;]*).*", $products[0][2], $ca)) { $userAgent[0] = $ca[1]; $userAgent[1] = $ca[2]; } else { $userAgent[0] = $products[0][0]; $userAgent[1] = $products[0][1]; } } else { $userAgent = array(); $userAgent[0] = $products[0][0]; $userAgent[1] = $products[0][1]; } } return $userAgent; } function serialnum($length=0,$data=""){ $random= ""; srand((double)microtime()*1000000); $num = 0; $num2 = floor($length / 4); $num3 = 0; for($i = 0; $i < $length + $num2; $i++){ if($num == 4){ $num4 = $length + $num2; if($num3 == $num4 - 1) { } else { $num = 0; $num3++; } } else { $random .= strtoupper(substr($data, (rand()%(strlen($data))), 1)); $num++; $num3++; } } return $random; } function utf8_wordwrap($string, $width = 75, $break = "\n", $cut = false) { // We first need to explode on $break, not destroying existing (intended) breaks $lines = explode($break, $string); $new_lines = array(0 => ''); $index = 0; foreach ($lines as $line) { $words = explode(' ', $line); for ($i = 0, $size = sizeof($words); $i < $size; $i++) { $word = $words[$i]; // If cut is true we need to cut the word if it is > width chars if ($cut && utf8_strlen($word) > $width) { $words[$i] = utf8_substr($word, $width); $word = utf8_substr($word, 0, $width); $i--; } if (utf8_strlen($new_lines[$index] . $word) > $width) { $new_lines[$index] = substr($new_lines[$index], 0, -1); $index++; $new_lines[$index] = ''; } $new_lines[$index] .= $word . ' '; } $new_lines[$index] = substr($new_lines[$index], 0, -1); $index++; $new_lines[$index] = ''; } unset($new_lines[$index]); return implode($break, $new_lines); } if (extension_loaded('mbstring')) { function utf8_strtolower($str) { return mb_strtolower($str); } } else { function utf8_strtolower($string) { static $utf8_upper_to_lower = array( "\xC3\x80" => "\xC3\xA0", "\xC3\x81" => "\xC3\xA1", "\xC3\x82" => "\xC3\xA2", "\xC3\x83" => "\xC3\xA3", "\xC3\x84" => "\xC3\xA4", "\xC3\x85" => "\xC3\xA5", "\xC3\x86" => "\xC3\xA6", "\xC3\x87" => "\xC3\xA7", "\xC3\x88" => "\xC3\xA8", "\xC3\x89" => "\xC3\xA9", "\xC3\x8A" => "\xC3\xAA", "\xC3\x8B" => "\xC3\xAB", "\xC3\x8C" => "\xC3\xAC", "\xC3\x8D" => "\xC3\xAD", "\xC3\x8E" => "\xC3\xAE", "\xC3\x8F" => "\xC3\xAF", "\xC3\x90" => "\xC3\xB0", "\xC3\x91" => "\xC3\xB1", "\xC3\x92" => "\xC3\xB2", "\xC3\x93" => "\xC3\xB3", "\xC3\x94" => "\xC3\xB4", "\xC3\x95" => "\xC3\xB5", "\xC3\x96" => "\xC3\xB6", "\xC3\x98" => "\xC3\xB8", "\xC3\x99" => "\xC3\xB9", "\xC3\x9A" => "\xC3\xBA", "\xC3\x9B" => "\xC3\xBB", "\xC3\x9C" => "\xC3\xBC", "\xC3\x9D" => "\xC3\xBD", "\xC3\x9E" => "\xC3\xBE", "\xC4\x80" => "\xC4\x81", "\xC4\x82" => "\xC4\x83", "\xC4\x84" => "\xC4\x85", "\xC4\x86" => "\xC4\x87", "\xC4\x88" => "\xC4\x89", "\xC4\x8A" => "\xC4\x8B", "\xC4\x8C" => "\xC4\x8D", "\xC4\x8E" => "\xC4\x8F", "\xC4\x90" => "\xC4\x91", "\xC4\x92" => "\xC4\x93", "\xC4\x96" => "\xC4\x97", "\xC4\x98" => "\xC4\x99", "\xC4\x9A" => "\xC4\x9B", "\xC4\x9C" => "\xC4\x9D", "\xC4\x9E" => "\xC4\x9F", "\xC4\xA0" => "\xC4\xA1", "\xC4\xA2" => "\xC4\xA3", "\xC4\xA4" => "\xC4\xA5", "\xC4\xA6" => "\xC4\xA7", "\xC4\xA8" => "\xC4\xA9", "\xC4\xAA" => "\xC4\xAB", "\xC4\xAE" => "\xC4\xAF", "\xC4\xB4" => "\xC4\xB5", "\xC4\xB6" => "\xC4\xB7", "\xC4\xB9" => "\xC4\xBA", "\xC4\xBB" => "\xC4\xBC", "\xC4\xBD" => "\xC4\xBE", "\xC5\x81" => "\xC5\x82", "\xC5\x83" => "\xC5\x84", "\xC5\x85" => "\xC5\x86", "\xC5\x87" => "\xC5\x88", "\xC5\x8A" => "\xC5\x8B", "\xC5\x8C" => "\xC5\x8D", "\xC5\x90" => "\xC5\x91", "\xC5\x94" => "\xC5\x95", "\xC5\x96" => "\xC5\x97", "\xC5\x98" => "\xC5\x99", "\xC5\x9A" => "\xC5\x9B", "\xC5\x9C" => "\xC5\x9D", "\xC5\x9E" => "\xC5\x9F", "\xC5\xA0" => "\xC5\xA1", "\xC5\xA2" => "\xC5\xA3", "\xC5\xA4" => "\xC5\xA5", "\xC5\xA6" => "\xC5\xA7", "\xC5\xA8" => "\xC5\xA9", "\xC5\xAA" => "\xC5\xAB", "\xC5\xAC" => "\xC5\xAD", "\xC5\xAE" => "\xC5\xAF", "\xC5\xB0" => "\xC5\xB1", "\xC5\xB2" => "\xC5\xB3", "\xC5\xB4" => "\xC5\xB5", "\xC5\xB6" => "\xC5\xB7", "\xC5\xB8" => "\xC3\xBF", "\xC5\xB9" => "\xC5\xBA", "\xC5\xBB" => "\xC5\xBC", "\xC5\xBD" => "\xC5\xBE", "\xC6\xA0" => "\xC6\xA1", "\xC6\xAF" => "\xC6\xB0", "\xC8\x98" => "\xC8\x99", "\xC8\x9A" => "\xC8\x9B", "\xCE\x86" => "\xCE\xAC", "\xCE\x88" => "\xCE\xAD", "\xCE\x89" => "\xCE\xAE", "\xCE\x8A" => "\xCE\xAF", "\xCE\x8C" => "\xCF\x8C", "\xCE\x8E" => "\xCF\x8D", "\xCE\x8F" => "\xCF\x8E", "\xCE\x91" => "\xCE\xB1", "\xCE\x92" => "\xCE\xB2", "\xCE\x93" => "\xCE\xB3", "\xCE\x94" => "\xCE\xB4", "\xCE\x95" => "\xCE\xB5", "\xCE\x96" => "\xCE\xB6", "\xCE\x97" => "\xCE\xB7", "\xCE\x98" => "\xCE\xB8", "\xCE\x99" => "\xCE\xB9", "\xCE\x9A" => "\xCE\xBA", "\xCE\x9B" => "\xCE\xBB", "\xCE\x9C" => "\xCE\xBC", "\xCE\x9D" => "\xCE\xBD", "\xCE\x9E" => "\xCE\xBE", "\xCE\x9F" => "\xCE\xBF", "\xCE\xA0" => "\xCF\x80", "\xCE\xA1" => "\xCF\x81", "\xCE\xA3" => "\xCF\x83", "\xCE\xA4" => "\xCF\x84", "\xCE\xA5" => "\xCF\x85", "\xCE\xA6" => "\xCF\x86", "\xCE\xA7" => "\xCF\x87", "\xCE\xA8" => "\xCF\x88", "\xCE\xA9" => "\xCF\x89", "\xCE\xAA" => "\xCF\x8A", "\xCE\xAB" => "\xCF\x8B", "\xD0\x81" => "\xD1\x91", "\xD0\x82" => "\xD1\x92", "\xD0\x83" => "\xD1\x93", "\xD0\x84" => "\xD1\x94", "\xD0\x85" => "\xD1\x95", "\xD0\x86" => "\xD1\x96", "\xD0\x87" => "\xD1\x97", "\xD0\x88" => "\xD1\x98", "\xD0\x89" => "\xD1\x99", "\xD0\x8A" => "\xD1\x9A", "\xD0\x8B" => "\xD1\x9B", "\xD0\x8C" => "\xD1\x9C", "\xD0\x8E" => "\xD1\x9E", "\xD0\x8F" => "\xD1\x9F", "\xD0\x90" => "\xD0\xB0", "\xD0\x91" => "\xD0\xB1", "\xD0\x92" => "\xD0\xB2", "\xD0\x93" => "\xD0\xB3", "\xD0\x94" => "\xD0\xB4", "\xD0\x95" => "\xD0\xB5", "\xD0\x96" => "\xD0\xB6", "\xD0\x97" => "\xD0\xB7", "\xD0\x98" => "\xD0\xB8", "\xD0\x99" => "\xD0\xB9", "\xD0\x9A" => "\xD0\xBA", "\xD0\x9B" => "\xD0\xBB", "\xD0\x9C" => "\xD0\xBC", "\xD0\x9D" => "\xD0\xBD", "\xD0\x9E" => "\xD0\xBE", "\xD0\x9F" => "\xD0\xBF", "\xD0\xA0" => "\xD1\x80", "\xD0\xA1" => "\xD1\x81", "\xD0\xA2" => "\xD1\x82", "\xD0\xA3" => "\xD1\x83", "\xD0\xA4" => "\xD1\x84", "\xD0\xA5" => "\xD1\x85", "\xD0\xA6" => "\xD1\x86", "\xD0\xA7" => "\xD1\x87", "\xD0\xA8" => "\xD1\x88", "\xD0\xA9" => "\xD1\x89", "\xD0\xAA" => "\xD1\x8A", "\xD0\xAB" => "\xD1\x8B", "\xD0\xAC" => "\xD1\x8C", "\xD0\xAD" => "\xD1\x8D", "\xD0\xAE" => "\xD1\x8E", "\xD0\xAF" => "\xD1\x8F", "\xD2\x90" => "\xD2\x91", "\xE1\xB8\x82" => "\xE1\xB8\x83", "\xE1\xB8\x8A" => "\xE1\xB8\x8B", "\xE1\xB8\x9E" => "\xE1\xB8\x9F", "\xE1\xB9\x80" => "\xE1\xB9\x81", "\xE1\xB9\x96" => "\xE1\xB9\x97", "\xE1\xB9\xA0" => "\xE1\xB9\xA1", "\xE1\xB9\xAA" => "\xE1\xB9\xAB", "\xE1\xBA\x80" => "\xE1\xBA\x81", "\xE1\xBA\x82" => "\xE1\xBA\x83", "\xE1\xBA\x84" => "\xE1\xBA\x85", "\xE1\xBB\xB2" => "\xE1\xBB\xB3" ); return strtr(strtolower($string), $utf8_upper_to_lower); } } function testEmail($email) { if ($email == ''){ return false; } $idx = strpos($email, '@'); if ($idx > 0){ $point = false; $st = 0; $ed = $idx; $ch = 0; for($j = 0; $j < 2; $j++){ $next = false; $error = false; for($i = $st; $i < $ed; $i++){ $ch = ord($email[$i]); if (($ch == 46)||($ch == 45)||($ch == 95)){ if (!$next){ $error = true; break; } $next = false; if (($j == 1)&&($ch == 46)){ $point = true; } else { $point = false; } } else { if ((($ch >= 48)&&($ch <= 57))|| (($ch >= 97)&&($ch <= 122))|| (($ch >= 65)&&($ch <= 90))){ $next = true; } else { $error = true; break; } } } if ((!$error)&&(!$next)){ $error = true; } if ($error){ break; } $st = $idx + 1; $ed = strlen($email); } if (($error)||(!$point)){ return false; } else { return true; } } else { return false; } } function unescape($str) { $str = rawurldecode($str); preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U",$str,$r); $ar = $r[0]; foreach($ar as $k => $v) { if (substr($v, 0, 2) == "%u") { $ar[$k] = iconv("UCS-2", "UTF-8", pack("H4", substr($v, -4))); } elseif (substr($v, 0, 3) == "&#x") { $ar[$k] = iconv("UCS-2", "UTF-8", pack("H4", substr($v, 3, -1))); } elseif(substr($v, 0, 2) == "&#") { $ar[$k] = iconv("UCS-2", "UTF-8", pack("n", substr($v, 2, -1))); } } return join("", $ar); } ?> * @package DB * @version 1.0 02.02.2006 */ /** * . */ function update_field($table, $field, $value, $where) { $sql = sp('UPDATE '.$table.' SET '.$field.'=? '.$where, $value); exec_sql($sql); }//\\update_field /** * MySQL . * @param string $str * @return string */ function escape($str) { if (is_array($str)) { return implode(', ', array_map('escape', $str)); } else { return "'".mysql_real_escape_string($str)."'"; } }//\\escape /** * SQL-. */ function sp() { $arg = func_get_args(); $sql = explode('?', array_shift($arg)); $n = count($sql) - 1; $arg = array_map('escape', $arg); if ((!isset($arg[2])) && (isset($sql[2]))) { //echo '
',debug_print_backtrace(),'
'; } for ($i=0; $i<$n; $i++) { $sql[$i] .= $arg[$i]; } return implode('', $sql); }//\\sp /*** * . * @param resource $result . * @param string $label */ function show_table($result, $label) { $rows = mysql_num_rows($result); $record = mysql_fetch_assoc($result); ?> $value) { ?> $value) { ?> $value) { ?>
'ID ', 'page' => ' ', 'next' => 'ID ') */ function get_page($table, $where, $record_id, $limit = 1, $id_field = 'id') { $page = array('prev' => null, 'page' => '', 'next' => null); $sub_sql = 'SELECT @cnt:=@cnt + 1 AS row_num, '.$table.'.'.$id_field.' as id FROM '.$table.' '.$where; if (get_mysql_version() >= 41) { // mysql 4.1 $rows = get_count($table, $where); $record = get_sub_sql( sp('CEILING(row_num / ?) as page, row_num', $limit), $sub_sql, sp('where id=?', $record_id) ); $page['page'] = $record['page']; $cur_rec = $record['row_num']; if ($cur_rec < $rows) // => { $record = get_sub_sql('id, row_num', $sub_sql, sp('where row_num=?', $cur_rec + 1)); $page['next'] = (isset($record['id'])) ? $record['id'] : null; } if ($cur_rec > 1) // => { $record = get_sub_sql('id, row_num', $sub_sql, sp('where row_num=?', $cur_rec - 1)); $page['prev'] = (isset($record['id'])) ? $record['id'] : null; } return $page; } else { //mysql 4.0 $sql = 'SET @cnt = 0;'; $result = exec_sql($sql); $result = exec_sql($sub_sql); $rows = mysql_num_rows($result); for ($i = 0; $i < $rows; $i++) { $record = mysql_fetch_assoc($result); if ($record['id'] == $record_id) { $page['page'] = ceil($record['row_num'] / $limit); $record = mysql_fetch_assoc($result); $page['next'] = $record['id']; return $page; } $page['prev'] = $record['id']; } } } /** * . * @param string $fields * @param string $sub_sql * @param string $where WHERE * @return array */ function get_sub_sql($fields, $sub_sql, $where) { $sql = 'SET @cnt = 0;'; $result = exec_sql($sql); $sql = 'select '.$fields.' from ('.$sub_sql.') as tb '.$where; $result = exec_sql2array($sql); return ((isset($result[0])) ? $result[0] : null); }//\\get_sub_sql /** * . * @return boolean/resourse */ function db_connect() { $result = mysql_connect(HOST_NAME, DB_USER_NAME, PASSWORD); if (!$result) { return false; } if (!mysql_select_db(DB_NAME)) { if (!BUILD_DB) { return false; } exec_sql('CREATE DATABASE `'.DB_NAME.'` DEFAULT CHARACTER SET '._DB_CHARSET.' COLLATE '._DB_COLLATE.';', $result); if (!mysql_select_db(DB_NAME)) { return false; } } // $sql = 'SET NAMES cp1251'; //$sql = 'SET CHARACTER SET cp1251'; // exec_sql($sql, $result); mysql_query("set session character_set_client="._DB_CHARSET.";"); mysql_query("set session character_set_database="._DB_CHARSET.";"); mysql_query("set session character_set_connection="._DB_CHARSET.";"); mysql_query("set session character_set_results="._DB_CHARSET.";"); mysql_query("set session character_set_client="._DB_CHARSET.";"); mysql_query("set session collation_connection="._DB_CHARSET.";"); return $result; }//\\db_connect /** * sql . * @param string $sql SQL- * @param resource $db * @return resource */ function exec_sql($sql, $db='') { global $db_id; global $sql_count; global $sql_array; if (DEBUG_INFO) { //$stack = call_user_func('debug_backtrace_smart'); //$s = array_shift($stack); //while (!empty($s['over_call_user_func'])) $s = array_shift($stack); //$fl = $s['file']; //$ln = $s['line']; $sql_count++; if (DEBUG_INFO==DEBUG_SHOW_SQL_CHECK_FUNCTIONS_SHOW_BACKTRACE) { $sql_array[] = $sql.backtrace(); } else { $sql_array[] = $sql; } $start_time = array_sum(explode(' ', microtime())); } if ($db=='') { $result = mysql_query($sql, $db_id) or die (send_error($sql)); } else { $result = mysql_query($sql, $db) or die (send_error($sql)); } if (DEBUG_INFO) { $end_time = round( array_sum(explode(' ', microtime())) - $start_time, 6); if (strpos(strtolower(before($sql, ' ')), 'select')!==false) { $sql_array[$sql_count-1] .= ' (rows: '.mysql_num_rows($result).', time: '.$end_time.' s.)'; } else { $sql_array[$sql_count-1] .= ' (time: '.$end_time.' s.)'; } } return $result; }//\\exec_sql /** * sql . * @param string $sql SQL- * @param resource $db * @return array */ function exec_sql2array($sql, $db='') { //printr( debug_backtrace() ); //printr( $sql ); $result = array(); $data = exec_sql($sql, $db); $rows = mysql_num_rows($data); for ($i=0; $i<$rows; $i++) { $result[] = mysql_fetch_assoc($data); } mysql_free_result($data); return $result; }//\\exec_sql2array /** * sql . * @param string $sql SQL- * @param resource $db * @return array */ function exec_sql2list($sql, $db='', $tokey = null) { $result = array(); $data = exec_sql($sql, $db); if ($tokey === FALSE) { $fields = array(); $i = 0; while ($i < mysql_num_fields($data)) { $meta = mysql_fetch_field($data); $fields[] = $meta->name; $i++; } } $rows = mysql_num_rows($data); for ($i=0; $i<$rows; $i++) { $row = mysql_fetch_row($data); if (count($row) > 1) { $j = 0; $c = count($row) - 1; $r = &$result; foreach($row as $key => $val) { if ($tokey === FALSE) { if (!isset($result[$fields[$key]])) { $result[$fields[$key]] = array(); } } else if ($tokey == 3) { if (!isset($r[$val])) { if ($c == $key) { $r = $val; } else { $r[$val] = array(); } } if ($c != $key) { $r = &$r[$val]; } } else { if (!isset($result[$key])) { $result[$key] = array(); } } if ($tokey === TRUE) { $result[$key][$val] = $j; } else if ($tokey === FALSE) { $result[$fields[$key]][] = $val; } else if ($tokey == 3) { //$r = $val; } else { $result[$key][] = $val; } $j++; } } else { if ($tokey === TRUE) { $result[$row[0]] = $i; } else if ($tokey === FALSE) { $result[$fields[$i]] = $row[0]; } else { $result[] = $row[0]; } } } mysql_free_result($data); return $result; }//\\exec_sql2list /** * sql . * @param integer $srt * @param array $arr , * @param string $table * @return string sql */ function sort_type($srt, $arr, $table='') { if ($srt=='') { $srt = 1; } if ($table!='') { $table .= '.'; } if (fmod($srt, 2)==0) { $order = ' desc'; } else { $order = ''; } $i = (floor(($srt-1)/2)); if ($i < 0) { $i = 1; } $str = ' order by '.$table.$arr[$i].$order; return $str; }//\\sort_type /** * . * @param string * @param string * @param string * @return integer */ function get_sort($table, $key, $field='type') { global $sort_table; $sql = "select sort from ".$table." where ".$field."='".$key."'"; $result = exec_sql($sql); $rows = mysql_num_rows($result); if ($rows==0) { if ($table==$sort_table) { $sql = "insert into ".$table." (".$field.", sort) values ('".$key."', '1')"; $res = exec_sql($sql); } $record['sort'] = 1; } else { $record = mysql_fetch_assoc($result); } return $record['sort']; }//\\get_sort /** * . * @param array/string $tables * @param string $where WHERE * @return integer */ function get_count($tables, $where='') { if (!is_array($tables)) { $tables = array($tables); } $col = 0; foreach ($tables as $table) { $col += get_field($table, 'count(*) as col', $where); } return $col; }//\\get_count /** * . * @param string $table * @param string $where * @param string $fields * @return array */ function get_fields($table, $where='', $fields='*') { if (is_array($fields)) { $fields = implode(', ', $fields); } $sql = 'select '.$fields.' from '.$table.' '.$where; //print $sql."
"; $result = exec_sql($sql); $fields = (mysql_num_rows($result)) ? mysql_fetch_assoc($result) : array(); mysql_free_result($result); return $fields; }//\\get_fields /** * . * @param string $table * @param string $field * @param string $where * @return mixed */ function get_field($table, $field, $where='') { $sql = 'select '.$field.' from '.$table.' '.$where; //print $sql."
"; $result = exec_sql($sql); $record = mysql_fetch_row($result); return $record[0]; }//\\get_field /** * SQL-. * @param string $sql * @return string */ function send_error($sql) { $err_num = mysql_errno(); $err_text = mysql_error(); $mail_msg = ": ".date('H:i:s d.m.Y')."\n". ": ".$_SERVER['SERVER_NAME']."\n". ": ".$_SERVER['SCRIPT_NAME']."\n". " : ".((isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : '')."\n". ": http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']."\n". ": ".$sql."\n". " : ".$err_num."\n". " : ".$err_text."\n". "Backtrace: ".backtrace(); $default = ' .'; $user_msg = get_error_text($err_num, $err_text); if (1)//($user_msg!=$default) { mail(ERROR_MAIL, ' '.$_SERVER['SERVER_NAME'], $mail_msg, "Return-Path:".SENDER_MAIL."\nFrom:".SENDER_MAIL."\nContent-Type: text/plain; charset=windows-1251\n"); } return ($_SERVER['SERVER_ADDR'] !== $_SERVER['REMOTE_ADDR']) ? $user_msg : nl2br(htmlspecialchars($mail_msg)); }//\\send_error function get_error_text($err, $err_text, $default = ' .') { global $general_lang; $arr = array( 2003 => $general_lang['error_2003'], 1040 => $general_lang['error_1040_2013_2006'], 2013 => $general_lang['error_1040_2013_2006'], 2006 => $general_lang['error_1040_2013_2006'], ); $end = ''; return ((isset($arr[$err])) ? $arr[$err] : $default).$end; } ?> ? AND emailr=?', $id, '', 1); //exec_sql($sql); $groups = exec_sql2list("SELECT id FROM `".$mails_groups_table."` WHERE sending='1';"); if (count($groups) > 0) { $groups = implode(",", $groups); $sql = sp('INSERT INTO '.$send_mail_table.' (record_id, email) SELECT ? as record_id, email as email FROM '.$mails_table.' WHERE groups_id IN('.$groups.') AND email<>? AND sending=?', $id, '', 1); exec_sql($sql); $sql = "UPDATE ".$cron_table." SET enabled=1 WHERE id=1"; exec_sql($sql); } } function truncate_print_r($input) { $output = str_replace(' ', ' ', $input); $output = preg_replace('/Array\n[\s]*\(\n/', "Array(\n", $output); $output = preg_replace('/Array\(\n[\s]*\)/', 'Array()', $output); $output = preg_replace('/\)\n\n/', ")\n", $output); return $output; } function printr($var) { echo '
'.truncate_print_r(print_r($var,true)).'

'.chr(13).chr(10); } function format_price($price, $with_cents = false, $space = ' ') { $result = ''; $price = strval($price); if (strpos($price, '.')) { $p = split('\.', $price); $price = $p[0]; $cents = $p[1]; if (strlen($cents)>2) $cents = substr($cents, 0, 2); if (strlen($cents) == 1) $cents .= '0'; } else { if ($with_cents) $cents = '00'; else $cents = ''; } $p = 0; for ($i=strlen($price); $i>0; $i--) { if ($p++ % 3 == 0) $result = $space . $result; $result = $price{$i-1} . $result; } return trim($result).($cents?','.$cents:''); } function get_present_strings($temp_strings) { global $uri; $default_lang = $uri['language']['default']['id']; $_GET['lang'] = $uri['language']['current']['id']; $type = array(); $result = array(); foreach($temp_strings as $lang_id => $strings) { if (($lang_id != $default_lang)&&($lang_id != $_GET['lang'])) { $type = array_merge($strings, $type); } } if ((isset($temp_strings[$default_lang]))&&($default_lang != $_GET['lang'])) { $type = array_merge($type, $temp_strings[$default_lang]); } if (isset($temp_strings[$_GET['lang']])) { $type = array_merge($type, $temp_strings[$_GET['lang']]); } foreach($type as $key => $val) { $sub_key = explode('_', $key); if (count($sub_key) > 1) { $result[$sub_key[1]] = $val; } else { $result[$key] = $val; } } return $result; } function convert_group_id_from_db($groupid) { global $groups_table; $tmp=exec_sql2array(sp("SELECT name from `".$groups_table."` where id=?", $groupid)); if(count($tmp)) return $tmp[0]['name']; else return 'Undefined'; } function get_domain_params($root_domain = null) { global $lang_table; $domain_sufix = ''; $domain = $_SERVER['SERVER_NAME']; if (strpos($domain, '.') === false) { $domain_sufix = ''; } else if (($root_domain == null)||($root_domain != $domain)) { $domain_sufix = substr($domain, 0, strpos($domain, '.')); if (!empty($lang_table)) { $result_lang = exec_sql2array("SELECT `id` FROM `".$lang_table."` WHERE `urlname`='".$domain_sufix."';"); } else { $result_lang = array(); } if (count($result_lang) > 0) { if ($root_domain != null) { $domain = $root_domain; } else { $domain = substr($domain, strpos($domain, '.') + 1); } } else { $domain_sufix = ''; if ($root_domain != null) { $domain = $root_domain; } } } return array('domain' => $domain, 'domain_sufix' => $domain_sufix); } /* function getGalleryInfo($id, $use_temp = false) { global $gallery_dir, $gallery_inc; $images_files = array(); $gallery_link = $gallery_dir.(($use_temp) ? 'temp/' : '').$id; $gallery_this = $gallery_inc.(($use_temp) ? 'temp/' : '').$id; if(file_exists($gallery_this)) { if(is_dir($gallery_this)) { $getcontent_dir_type = dir($gallery_this); while (false !== ($entry_type = $getcontent_dir_type->read())) { if (($entry_type !== '.')&&($entry_type !== '..')) { if (filetype($gallery_this."/".$entry_type) == 'dir') { $images_files[$entry_type] = array(); $getcontent_dir = dir($gallery_this."/".$entry_type); $num = 0; while (false !== ($entry = $getcontent_dir->read())) { if (($entry !== '.')&&($entry !== '..')) { if (filetype($gallery_this."/".$entry_type."/".$entry) != 'dir') { $images_files[$entry_type][$entry] = $num; $num++; } } } } } } } } $gallery = array( 'images' => $images_files, 'link' => $gallery_link, 'inc' => $gallery_this, ); return $gallery; } */ function parseRawData($raw) { if (($contentPos = strpos($raw, "\r\n\r\n")) !== false) { $contentHeaders = substr($raw, 0, $contentPos); $headersLines = explode("\r\n", $contentHeaders); if (count($headersLines) > 0) { $headLines = explode(" ", $headersLines[0]); $protocol = explode("/", $headLines[0]); $header = array( "protocol" => $protocol[0], "version" => $protocol[1], "code" => $headLines[1], "message" => $headLines[2] ); } $headers = Array(); $names = Array(); for($index = 1; $index < count($headersLines); $index++) { if (($pos = strpos($headersLines[$index], ":")) !== false) { $name = substr($headersLines[$index], 0, $pos); $names[strtoupper($name)] = $name; if (isset($headers[$name])) { if (is_array($headers[$name])) { $headers[$name][] = trim(substr($headersLines[$index], $pos + 1)); } else { $headers[$name] = array($headers[$name], trim(substr($headersLines[$index], $pos + 1))); } } else { $headers[$name] = trim(substr($headersLines[$index], $pos + 1)); } } } $contentPos += 4; } $content = ""; if (isset($names['CONTENT-LENGTH'])) { $content = substr($raw, $contentPos, intval($headers[$names['CONTENT-LENGTH']])); } else { if (($contentLengthPos = strpos($raw, "\r\n", $contentPos)) !== false) { $contentLength = hexdec(substr($raw, $contentPos, $contentLengthPos - $contentPos)); $contentPos = $contentLengthPos + 2; if ($contentPos < strlen($raw)) { while($contentLength > 0) { $content .= substr($raw, $contentPos, $contentLength); $contentPos = $contentPos + $contentLength + 2; if ($contentPos < strlen($raw)) { if (($contentLengthPos = strpos($raw, "\r\n", $contentPos)) !== false) { $contentLength = hexdec(substr($raw, $contentPos, $contentLengthPos - $contentPos)); $contentPos = $contentLengthPos + 2; } else { $contentLength = 0; } } else { $contentLength = 0; } } } } } return array('head' => $header ,'headers' => $headers, 'names' => $names, 'content' => $content); } function get_rus_date($date) { preg_match('/^([0-9]+)-([0-9]+)-([0-9]+)/i',$date,$date_ar); $day_array=array( '1'=>'понедельник', '2'=>'вторник', '3'=>'среда', '4'=>'четверг', '5'=>'пятница', '6'=>'суббота', '7'=>'воскресение', ); $mouth_array=array( '01'=>'января', '02'=>'февраля', '03'=>'марта', '04'=>'апреля', '05'=>'мая', '06'=>'июня', '07'=>'июля', '08'=>'августа', '09'=>'сентября', '10'=>'октября', '11'=>'ноября', '12'=>'декабря', ); $day_count=date("w", mktime(0, 0, 0, $date_ar[2], $date_ar[3], $date_ar[1])); preg_match('/([123456789]+)/i',$date_ar[3],$day); //$date_rus=$day_array[$day_count].', '.$day[1].' '.$mouth_array[$date_ar[2]]; $date_rus=$date_ar[3].' '.$mouth_array[$date_ar[2]].' '.$date_ar[1].' г.'; return $date_rus; } function get_en_date($date) { preg_match('/^([0-9]+)-([0-9]+)-([0-9]+)/i',$date,$date_ar); //$day_count=date("w", mktime(0, 0, 0, $date_ar[2], $date_ar[3], $date_ar[1])); //preg_match('/([123456789]+)/i',$date_ar[3],$day); //$date_rus=$day_array[$day_count].', '.$day[1].' '.$mouth_array[$date_ar[2]]; $mouth_name=date("F", mktime(0, 0, 0, $date_ar[2], $date_ar[3], $date_ar[1])); $date_rus=$mouth_name.' '.$date_ar[3].', '.$date_ar[1]; return $date_rus; } //разложение на двойной массив с количеством-$fields компонентов в каждом function array_gallery($mass,$fields) { $i=-1; $str_i=-1; $str=count($mass)/$fields; while ($str_i<($str-1)) { $str_i++; $fields_i=-1; while (($fields_i<($fields-1)) and ($i<(count($mass)-1))) { $i++; $fields_i++; $new_mass[$str_i][$fields_i]=$mass[$i]; } } return $new_mass; } // определение каталога, страницы и сортировки function get_params($uri_params) { preg_match('/^([0-9a-zA-Z-_]+)*[\/]?([0-9a-zA-Z-\/_]*)$/i',trim($uri_params),$param_ar); if (!empty($param_ar[1])) $link_catalog=$param_ar[1]; else $link_catalog=''; if (!empty($param_ar[2])) { $no_item=true; preg_match('/^(page([0-9]+))*[-]*(sort-([a-zA-Z0-9_]+)-([a-z]+))*$/i',$param_ar[2],$page_ar); if (!empty($page_ar[1])) { $page=$page_ar[2]; $link_item=''; $no_item=false; } else $page=1; if (!empty($page_ar[3])) { $sort_field=$page_ar[4]; if (!empty($page_ar[5])) { $desc=$page_ar[5]; if ($desc=='up') {$sort_name='up'; $sort_order='desc';} else {$sort_order=''; $sort_name='down';} } else { $sort_order=''; $sort_name='down'; } $link_item=''; $no_item=false; } else { $sort_name='down'; $sort_field=''; $sort_order=''; } if ($no_item==true) { $link_item=$param_ar[2]; $page=1; $sort_field=''; $sort_order=''; $sort_name='down'; } } else { $link_item=''; $page=1; $sort_field=''; $sort_order=''; $sort_name='down'; } return array('link_catalog'=>$link_catalog,'link_item'=>$link_item,'page'=>$page,'sort_field'=>$sort_field,'sort'=>$sort_order,'sort_name'=>$sort_name); } // вывод ссылки на сортировку function sort_title($name,$name_link,$url='',$sort='',$desc='',$page='') { $url=$url.'/'; if ($sort==$name_link) { if ($desc=='up') $b_class=" class='up'"; else $b_class=" class='down'"; } else $b_class=''; if (!empty($page)) $url.='page'.$page; if (!empty($name_link)) { if (!empty($page)) $url.='-'; $url.='sort-'.$name_link; if (!empty($desc)) { if ($desc=='up') $url.='-down'; else $url.='-up'; } } return "".$name.""; } function sendmail($mail, $from, $data, $subject) { //ini_set('display_errors','on'); $to=$mail; require_once (dirname(__FILE__).'/../../../phpmailer/PHPMailerAutoload.php'); $mail1 = new PHPMailer(); $mail1->isHTML(true); $mail1->setFrom('info@successtraderealty.com', 'Successtraderealty'); //$mail->addReplyTo('replyto@example.com', 'First Last'); $mail1->addAddress($to, $to); //$mail1->addAddress('lexx@softaddicts.com', 'lexx@softaddicts.com'); //$mail1->addAddress('lexx@dev.softaddicts.com', 'lexx@dev.softaddicts.com'); $mail1->Subject = $subject; $mail1->Body = $data; if(!$mail1->send()) { return false; }else{ return true; } /*$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= "Content-type: text/html; charset=utf-8; \r\n"; $headers .= "From: ".$from."\r\n"; $subject = '=?utf-8?B?'.base64_encode($subject).'?='; if (!mail($mail, $subject, $data, $headers)) return false; else return true;*/ } function rt($val) { $val=str_replace(' ','_',$val); return $val; } // проверка есть ли дирректория function up_check_dir($dir) { if (!is_dir($dir)) { mkdir($dir, 0777); } return $dir; } // загрузка файлов function upload_file($files_load,$path,$width_array=array(),$extensions='',$only_pictures=false) { // делаем массив файлов //if (!is_array($files_load['name'])) $file=array($files_load); $file=$files_load; up_check_dir($path); // проходим по каждому $i=-1; while ($i<((count($file['name']))-1)) { $i++; if (!empty($file['name'][$i])) { // смотрим расширение $ext = strtolower('.'.pathinfo($file['name'][$i], PATHINFO_EXTENSION)); $dop=rand(0,10000); $file['name'][$i]=$dop."_".$file['name'][$i]; $file_main=$path."/".$file['name'][$i]; // проверка на разрешенные расширения $no_extension=true; if (is_array($extensions)) { foreach ($extensions as $val) { if ($val==$ext) $no_extension=false; } } else $no_extension=false; if ($no_extension==false) { // если картинка if (($ext == '.jpg') or ($ext == '.jpeg') or ($ext == '.gif') or ($ext == '.bmp') or ($ext == '.png')) { $sz = getimagesize($file['tmp_name'][$i]); // если массив ширины есть if (count($width_array)>0) { // если файл скопировался if (copy($file['tmp_name'][$i],$file_main)) { $num_file=0; foreach ($width_array as $num=>$size) { $num_file++; $file_new=$path."/".$num_file."_".$file['name'][$i]; // если такой файл есть - то удаляем его if (is_file($file_new)) { chmod($file_new, 0777); unlink($file_new); } // если размер картинки больше ужимаемого if (($sz[0] > $size) and ($size)) { switch ($ext){ case ('.jpg'): case ('.jpeg'): $imgcreate = imagecreatefromjpeg($file_main); break; case ('.png'): $imgcreate = imagecreatefrompng($file_main); break; case ('.gif'): $imgcreate = imagecreatefromgif($file_main); break; case ('.bmp'): $imgcreate = imagecreatefromwbmp($file_main); break; } // уменьшение картинки $width_new=$size; $height_new=$sz[1]*$width_new/$sz[0]; $dst=imagecreatetruecolor($width_new,$height_new); imagecopyresampled($dst, $imgcreate, 0, 0, 0, 0, ImageSX($dst), ImageSY($dst), ImageSX($imgcreate),ImageSY($imgcreate)); switch ($ext){ case ('.jpg'): case ('.jpeg'): imagejpeg($dst,$file_new,100); break; case ('.png'): imagepng($dst,$file_new,100); break; case ('.gif'): imagegif($dst,$file_new,100); break; case ('.bmp'): imagejpeg($dst,$file_new,100); break; } } else { copy($file_main, $file_new); } chmod($file_new, 0444); } unlink($file_main); } } $file_name[]=$file['name'][$i]; } else { if ($only_pictures==false) { // если файл // если такой файл есть - то удаляем его if (is_file($file_main)) { chmod($file_main, 0777); unlink($file_main); } copy($file['tmp_name'][$i],$file_main); chmod($file_main, 0444); $file_name[]=$file['name'][$i]; } } } } } if (!empty($file_name)) return $file_name; else return false; } ?>