function rewriteGetPageUrl($idcatside, $idlang, $force_langprefix = false) { global $con_side, $cfg_client, $cms_db, $sess, $lang; $rewrite_use_automatic = false; //look if automatic is in use if (is_array($con_side) && $idlang == $lang) { $rewrite_use_automatic = $con_side[$idcatside]['rewrite_use_automatic']; } else { $ado =& sf_factoryGetObjectCache('DATABASE', 'Ado'); $sql = "SELECT *\n\t\t\t\tFROM\n\t\t\t\t\t" . $cms_db['cat_side'] . " CS LEFT JOIN\n\t\t\t\t\t" . $cms_db['side_lang'] . " SL USING(idside)\n\t\t\t\tWHERE \n\t\t\t\t\tCS.idcatside = '" . $idcatside . "'\n\t\t\t\t\tAND SL.idlang = '" . $idlang . "'"; $rs = $ado->Execute($sql); if ($rs === false) { return false; } if ($rs->EOF) { return false; } $rewrite_use_automatic = $rs->fields['rewrite_use_automatic']; } if ($rewrite_use_automatic == 1) { $alias = rewriteGetCatUrl($con_side[$idcatside]['idcat'], $idlang, $force_langprefix); $string = rewriteGetPageAlias($idcatside, $idlang); return $alias . $string . $cfg_client['url_rewrite_suffix']; } else { $sessionstring = $sess->mode == 'getrewrite' ? $sess->id . '/' : ''; return $sessionstring . rewriteGetPageAlias($idcatside, $idlang); } }
public function getMappedCmsLinks($code, $options = array()) { if ($code == '') { return $code; } $def_options = array('force_http_path' => FALSE, 'force_entitydecode' => FALSE, 'force_langprefix' => FALSE); $options = array_merge($def_options, $options); $all_searches = array(); $all_replaces = array(); $matches = array(); $sess = $this->cfg->sess(); $is_rewrite2 = $this->cfg->env('is_frontend_rewrite2'); $use_idlang_in_rewrite2 = $this->cfg->client('url_langid_in_defaultlang') == '1'; preg_match_all("!cms://(idcat|idcatside)=(\\d+)(\\?([^'\"><\\s]+))?!", $code, $matches); if (count($matches) > 0) { //init common vars $is_backend = $this->cfg->env('is_backend'); $view = $is_backend ? $this->cfg->env('view') : FALSE; $is_rewrite1 = $this->cfg->env('is_frontend_rewrite1'); $current_idlang = $this->cfg->env('idlang'); $idstartlang = $this->cfg->env('idstartlang'); $is_https_enabled = $this->cfg->client('https') == '1' ? TRUE : FALSE; $contentfile = $this->cfg->client('contentfile'); $path_http = $this->cfg->env('path_frontend_http'); $sep = '&'; $pageinfos = $catinfos = $path_https = FALSE; if ($is_https_enabled) { $pageinfos = sf_api('PAGE', 'Pageinfos'); $catinfos = sf_api('PAGE', 'Catinfos'); $path_https = str_replace('http://', 'https://', $path_http); } //sort uris $uris = $matches['0']; $cmp = create_function('$a,$b', 'if (strlen($a) == strlen($b)) { return 0; } return strlen($a) > strlen($b) ? -1 : 1;'); uasort($uris, $cmp); $uris = array_unique($uris); foreach ($uris as $k => $search) { //idcatside or idcat $type = $matches['1'][$k]; $parms = $matches['4'][$k]; $local_sep = $sep; $local_parmstr = ''; $local_lang = FALSE; $local_langstr = ''; $local_langprefix = FALSE; $local_view = ''; $replace = ''; $parmarr = array(); if ($parms != '') { $parms = str_replace('&', '&', $parms); $parmpairs = explode('&', $parms); foreach ($parmpairs as $pv) { $key = $val = ''; list($key, $val) = explode('=', $pv, 2); $parmarr[$key] = $val; } // use '&' or '&' as separator if (array_key_exists('sf_entitydecode', $parmarr) || $options['force_entitydecode']) { if ($parmarr['sf_entitydecode'] == 'true' || $options['force_entitydecode'] === TRUE) { $local_sep = '&'; unset($parmarr['sf_entitydecode']); } } //use lang id if (array_key_exists('lang', $parmarr)) { $local_lang = (int) $parmarr['lang']; unset($parmarr['lang']); } //handle view parm if (array_key_exists('view', $parmarr)) { if ($is_backend) { $local_view = $parmarr['view']; } unset($parmarr['view']); } //handle mod_rewrite2 langprefix if (array_key_exists('sf_langprefix', $parmarr) || $options['force_langprefix']) { if ($parmarr['sf_langprefix'] == 'true') { $local_langprefix = TRUE; } unset($parmarr['sf_langprefix']); } if (count($parmarr) > 0) { $parmarr2 = array(); foreach ($parmarr as $pk => $pv) { array_push($parmarr2, $pk . '=' . $pv); } $local_parmstr = implode($local_sep, $parmarr2); } } if ($is_backend) { if ($idstartlang != $current_idlang && $local_lang < 1) { $local_lang = $current_idlang; } if ($local_lang > 0) { $local_langstr = 'lang=' . $local_lang . $local_sep; } if ($local_view != '') { $local_view = 'view=' . $local_view; } else { $local_view = 'view=' . $view; } if ($local_parmstr != '') { $local_parmstr = $local_sep . $local_parmstr; } $replace = $sess->url($contentfile . '?' . $local_langstr . $type . '=' . $matches['2'][$k] . $local_sep . $local_view . $local_parmstr); } else { if ($is_rewrite1) { if ($local_lang > 0) { if ($local_lang != $current_idlang) { $local_langstr = '-' . $local_lang; } } if ($local_parmstr != '') { $local_parmstr = '?' . $local_parmstr; } $pre = $type == 'idcatside' ? 'page' : 'cat'; $replace = $sess->url($pre . $matches['2'][$k] . $local_langstr . '.html' . $local_parmstr); } else { if ($is_rewrite2) { if ($local_parmstr != '') { $local_parmstr = '?' . $local_parmstr; } $local_langid = $local_lang > 0 ? $local_lang : $current_idlang; if ($use_idlang_in_rewrite2 || $idstartlang != $local_langid) { $local_langprefix = TRUE; } if ($type == 'idcatside') { $replace = rewriteGetPageUrl($matches['2'][$k], $local_langid, $local_langprefix) . $local_parmstr; } else { $replace = rewriteGetCatUrl($matches['2'][$k], $local_langid, $local_langprefix) . $local_parmstr; } } else { if ($local_lang > 0) { if ($local_lang != $current_idlang) { $local_langstr = 'lang=' . $local_lang . $local_sep; } } if ($local_parmstr != '') { $local_parmstr = $local_sep . $local_parmstr; } $replace = $sess->url($contentfile . '?' . $local_langstr . $type . '=' . $matches['2'][$k] . $local_parmstr); } } } //https mappings if ($is_https_enabled) { $this_page_hase_https_enabled = $type == 'idcatside' ? $pageinfos->getIsHttps($matches['2'][$k]) == '1' : $catinfos->getStartpageIsHttps($matches['2'][$k]); if (!$this->cfg->env('is_https') && $this_page_hase_https_enabled) { $replace = $path_https . $replace; } else { if ($this->cfg->env('is_https') && !$this_page_hase_https_enabled) { $replace = $path_http . $replace; } } } //Force http path if ($options['force_http_path']) { if (substr($replace, 0, 4) != 'http') { $replace = $path_http . $replace; } } array_push($all_searches, $search); array_push($all_replaces, $replace); } $code = str_replace($all_searches, $all_replaces, $code); //if mod rewrite 2: handle local anchor links if ($is_rewrite2) { $code = preg_replace("!(<a[\\s]+[^>]*?href[\\s]?=[\\s\"\\']+)#(.*?)([\"\\'])!i", '\\1' . str_replace('&', '&', $_SERVER['REQUEST_URI']) . '#\\2\\3', $code); } } return $code; }