* * @Author: shacka :: shacka@weandcat.te.ua * @URL: http://www.weandcat.te.ua/ * * ------------------------------------------------------------- */ require_once('lib/debug.inc.php'); $curr_page = preg_replace('|^'.WEB_PATH.'|', '', $_SERVER['REQUEST_URI']); $curr_page = substr(preg_replace('/\?.*$/', '', $curr_page), 1); $curr_page = preg_replace('|/$|', '', $curr_page); $lang = array_shift(explode('/', $curr_page)); require_once 'class/DB/Lang/DLang.php'; $DLang = new DLang(); $lang = $DLang->validName($lang); $curr_page = preg_replace("/^$lang\/?/", '', $curr_page); //vdie($curr_page, $lang); define('CURR_LANG', $lang); define('CURR_PAGE', $curr_page); $parent_page = preg_replace('/\/[^\/]+\/?$/', '', $curr_page); define('PARENT_PAGE', $parent_page); if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] ) { include(WWW_PATH.'/main'); exit(); } function getAction($url) { $action = preg_replace("|$url/?|", "", CURR_PAGE); return $action; } function array2json($data = array(), $indentchr = null, $indentlvl = 0) { return json_encode($data); $indent = (is_null($indentchr))? '' : str_repeat($indentchr,$indentlvl); $indent2= is_null($indentchr)?'':"\n$indent$indentchr"; $indentlvl++; $rows = array(); foreach($data as $k=>$v){ $rows[] = str_repeat("\t", $indentlvl)."$k:".(is_array($v)?array2json($v,$indentchr,$indentlvl):(is_int($v)?$v:"'".addslashes(preg_replace("!\r?\n!","\\n",$v))."'")); } return "{\n".$indent2.implode(",\n$indent2",$rows).(is_null($indent)?'':"\n$indent").str_repeat("\t", $indentlvl-1)."}"; } function url_format($url) { if (!preg_match('/^(http|https)\:\/\//', $url)) { return 'http://'.$url; } return $url; } function emailEncode($orgStr) { $encStr = ""; $nowStr = ""; $rndNum = -1; $orgLen = strlen($orgStr); for($i=0; $i < $orgLen; $i++) { if(version_compare("4.2", php_version)) // a pre php version 4.2, rand should be seeded { list($usec, $sec) = explode(' ', microtime()); srand( (float) $sec + ((float) $usec * 100000) ); } $encMod = rand(1,5); // make chances of coding as follows: Decimal 2/5, Hex 2/5, None 1/5 switch($encMod) { case 1: // Decimal case 2: // Decimal $nowStr = "&#" . ord($orgStr[$i]) . ";"; break; case 3: // Hexadecimal case 4: // Hexadecimal $nowStr = "&#x" . dechex(ord($orgStr[$i])) . ";"; break; default: // Normal (case 5) $nowStr = $orgStr[$i]; break; } $encStr .= $nowStr; } return $encStr; } ############## // Takes: // $data, multidim array // $keys, array(array(key=>col1, sort=>desc), array(key=>col2, type=>numeric)) function php_multisort($data, $keys) { // List As Columns foreach ($data as $key => $row) { foreach ($keys as $k){ $cols[$k['key']][$key] = $row[$k['key']]; } } // List original keys $idkeys=array_keys($data); // Sort Expression $i=0; foreach ($keys as $k) { if($i>0) { $sort.=','; } $sort.='$cols['.$k['key'].']'; if($k['sort']) { $sort.=',SORT_'.strtoupper($k['sort']); } if($k['type']) { $sort.=',SORT_'.strtoupper($k['type']); } $i++; } $sort.=',$idkeys'; // Sort Funct $sort='array_multisort('.$sort.');'; eval($sort); // Rebuild Full Array foreach($idkeys as $idkey) { $result[$idkey]=$data[$idkey]; } return $result; } function array_flat($aNonFlat) { if (!is_array($aNonFlat)) $aNonFlat = array(); $objTmp = (object) array('aFlat' => array()); array_walk_recursive($aNonFlat, create_function('&$v, $k, &$t', '$t->aFlat[] = $v;'), $objTmp); return $objTmp->aFlat; } function sendDeveloperEmail($error, $data = null) { if (!defined('DEBUG_DEVELOPER_EMAIL')) { return false; } $emails = split('[, ;]', DEBUG_DEVELOPER_EMAIL); if (!is_array($emails) || empty($emails)) { return false; } $text = 'Error: '.$error."\n"; $url = BASE_URL.'/'.CURR_PAGE_FULL; if (!empty($_SERVER['QUERY_STRING'])) { $url .= '?'.$_SERVER['QUERY_STRING']; } $text .= 'URL: '.$url."\n"; if (!empty($_SERVER['HTTP_REFERER'])) { $text .= 'HTTP_REFERER: '.$_SERVER['HTTP_REFERER']."\n"; } $backrtace = debug_backtrace(); if (is_array($backrtace) && !empty($backrtace)) { $text .= "\nBACKTRACE: \n"; foreach ($backrtace as $k=>$v) { $text .= 'Line '.$v['line'].', Function "'.$v['function'].'", File "'.$v['file']."\"\n"; } } if ($data) { $text .= "\nDATA:\n".print_r($data, true); } $text .= "\n_SERVER:\n".print_r($_SERVER, true); $subject = ' Error Dump'; $headers = 'From: debug@'.$_SERVER['SERVER_NAME'] . "\n" . 'Reply-To: webmaster@example.com' . "\n" . 'X-Mailer: PHP/' . phpversion(); foreach ($emails as $email) { mail($email, $subject, $text, $headers); } }