$value) $result[$value] = $key; return $result; } function slice(&$array, &$keys) { $result = array(); foreach ($keys as $sliced) $result[$sliced] = $array[$sliced]; return $result; } # NEW /** * UnHtmlEntities for titles, keywords, descriptions * PHP4 must be die(); * * @param string $string * @param string $charset * @return string * */ function unhtmlentities($string, $charset = 'utf-8') { if (version_compare(PHP_VERSION, '4.3.0', '>')) { $string = html_entity_decode($string, ENT_COMPAT, $charset); } else { // replace numeric entities $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string); // replace literal entities $trans_tbl = get_html_translation_table(HTML_ENTITIES); if (strtolower($charset) == 'utf-8') { foreach($trans_tbl as $charkey => $char) { $charkey = utf8_encode($charkey); $trans_tbl[$charkey]= utf8_encode($char); } } $trans_tbl = array_flip($trans_tbl); $string = strtr($string, $trans_tbl); } return $string; } /** * Get content with curl or not * * @param string $url * @param bool $useCurl * @param bool $file_use_include_path * @return mixed */ function getContents($url, $useCurl = false, $file_use_include_path = false) { if (function_exists('file_get_contents') && (ini_get('allow_url_fopen') || $file_use_include_path) && !$useCurl) { return $contents = file_get_contents($url, $file_use_include_path); } $url_parts = parse_url($url); if (stristr($url, "http") === FALSE) $url = "http://".$url; if ($useCurl && extension_loaded('curl')) { $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); $contents = curl_exec($c); curl_close($c); } elseif (is_resource($sock = @fsockopen(gethostbyname($url_parts['host']), 80, $errno, $errstr))) { @fputs($sock, "GET ".$url_parts['path']."?".$url_parts['query']." HTTP/1.0\r\nHost:".$url_parts['host']."\r\n\r\n"); while ($answer = @fgets($sock)) $contents .= $answer; @fclose($sock); $contents = substr($contents, strpos($contents, "\r\n\r\n") + 4); } else return false; return $contents; } function array_get_max_val($a) { arsort($a); $max = current($a); return $max; } function getbigger() { foreach (func_get_args() as $val) $_tmp[] = $val; return array_get_max_val($_tmp); } $root = null; function getRoot() { global $root; if($root) return $root; if(preg_match('/^(\/.+?\/)/', $_SERVER['SCRIPT_NAME'], $rootPath)) { $rootPath = $rootPath[1]; } else { $rootPath = '/'; } return $root = $rootPath; } function incomin() { include 'config.php'; $rootPath = '/'; if(preg_match('/^(\/.+?\/)/', $_SERVER['REQUEST_URI'], $Path)) $rootPath = $Path[1]; $url = preg_replace("/[^\x20-\xFF]/", "", strval(trim($_SERVER['REQUEST_URI']))); $url = rtrim($url, "/"); $urlparts = explode("/", $url); $exp = explode(".", trim(end($urlparts), '/')); $uri = strtok(str_replace($rootPath, "", $_SERVER['REQUEST_URI']), '?'); $uri = rawurldecode($uri); $result = array(); $mask_type = ''; foreach ($config['url_masks'] as $mask_type => $masks) { foreach($masks as $country => $mask) { $form = str_replace('%s','(.*?)','|^'.$mask.'$|'); if (preg_match($form, $uri, $matches) && $country != 'lang_by_domain') { $result['type'] = $mask_type; $result['match'] = $matches[1]; $result['country'] = $country; } if(!empty($result['type'])) break; } if(!empty($result['type'])) break; } $afl = ltrim($_SERVER['REQUEST_URI'], '/'); if(is_readable('./lang/es/articles/'.$afl) && $_SERVER['REQUEST_URI'] != '/') { $result['type'] = 'pages'; $result['match'] = 'articles'; return $result; } // if(!empty($_GET['id']) && !empty($_GET['category'])) // { // $result['type'] = 'pages'; $result['match'] = 'articles'; // } $_al_available = !empty($config['aliases_available']) ? $config['aliases_available'] : array('cart','tell_friend','coupon','generic','news','articles','sitemap','sitemap-xml','subscribe','bonuses','blisters','policy',''); if(empty($result) && in_array($exp[0], $_al_available) && empty($_GET['category'])) { $result['match'] = strlen($exp[0]) ? $exp[0] : 'index'; $result['type'] = 'pages'; return $result; } if(isset($result['type']) && $result['type'] == 'products') $_GET['product'] = $result['match']; elseif(isset($result['type']) && $result['type'] == 'categories') $_GET['category'] = $result['match']; elseif(isset($result['type']) && $result['type'] == 'letters') $_GET['letter'] = $result['match']; elseif(isset($result['type']) && $result['type'] == 'pages' && $result['match'] != 'articles') $result['page'] = $result['match']; if(empty($result['match']) && empty($_GET)) { go('404',$config); header("HTTP/1.0 404 Not Found"); } if(!empty($result['match']) && $result['type'] == 'generics') { $_GET['search'] = $result['match']; $_GET['generic'] = true; } if(!empty($result['country'])) $_GET['url_country'] = $result['country']; return $result; } /** * Transform 1-st array level to output array where keys transform to uppercase and add PREFIX_ if exist * * $arr ['key'=>'1'] --> $out ['PREFIX_KEY' => '1'] * * @param array * @param string $prefix * @return array */ function get_out_vars($arr,$prefix=''){ $out = array(); $prefix = $prefix !=='' ? $prefix.'_' :''; foreach($arr as $k => $v){ if (!is_array($v)) $out[strtoupper($prefix.$k)] = $v; } return $out; } function CreateCustomParamIndex(&$params){ if(file_exists($pathFileUpd='.htcache/admin/HomePage.upd')&&empty($_GET['search'])){ if($PageParam=unserialize(file_get_contents($pathFileUpd))){ $params['type']=$PageParam['type']; $params['NamePage']=$PageParam['name']; } if(!empty($params['type'])&&$params['type']=='pages'){ $params['match']=$params['NamePage']; } else $_GET[$params['type']]=!empty($_GET['product'])?$_GET['product']:$params['NamePage']; } } function go($mode='404',$config) { if(!$config['allow404301tomain']) return; if($mode == '404') { header("HTTP/1.1 301 Moved Permanently"); header('Location: /404.php'); exit; } } function compress_html($compress) { $compress = str_replace("\n", '', $compress); $compress = str_replace("\s", '', $compress); $compress = str_replace("\r", '', $compress); $compress = str_replace("\t", '', $compress); $compress = preg_replace('/(?:(?<=\>)|(?<=\/\>))\s+(?=\<\/?)/', '', $compress); if (FALSE === strpos($c, '.*)/', '', $compress); $compress = preg_replace('/\/\*.*?\*\//', '', $compress); return preg_replace("#\\s+#ism"," ",$compress); }