コード例 #1
0
function tep_href_old_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true, $force_language_id = false)
{
    global $request_type, $session_started, $SID, $languages_id;
    if ($force_language_id !== false) {
        $newlanguages_id = $force_language_id;
    } else {
        $newlanguages_id = $languages_id;
    }
    if (!tep_not_null($page)) {
        die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
    }
    if ($connection == 'NONSSL') {
        $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
    } elseif ($connection == 'SSL') {
        if (ENABLE_SSL == true) {
            $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
        } else {
            $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
        }
    } else {
        die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');
    }
    $separator = '?';
    if (tep_not_null($parameters)) {
        $product_name = '';
        switch ($page) {
            case FILENAME_PRODUCT_INFO:
            case FILENAME_DEFAULT:
                $manufacturer_name = '';
                $product_name = '';
                $new_parameter_list = array();
                $cPath_list = array();
                foreach (explode('&', $parameters) as $pair) {
                    $pair_array = explode('=', $pair);
                    switch ($pair_array[0]) {
                        case 'action':
                            $link .= $page . '?' . tep_output_string($parameters);
                            $separator = '&';
                            break 3;
                        case 'cPath':
                            $parent_id = 0;
                            // CONTROLEER ALS ER SEO URL IN DATABASE IS
                            if (strstr($pair_array[1], '_')) {
                                $cpath_id = end(explode('_', $pair_array[1]));
                            } else {
                                $cpath_id = $pair_array[1];
                            }
                            $get_seo_categories_query = tep_db_query("select url from seo_urls where categories_id = '" . (int) $cpath_id . "' AND language_id = '" . (int) $newlanguages_id . "'");
                            if (tep_db_num_rows($get_seo_categories_query) > 0) {
                                $get_seo_categories = tep_db_fetch_array($get_seo_categories_query);
                                $cPath_list[] = substr($get_seo_categories['url'], 1);
                            } else {
                                $catpath = tep_get_full_cpath($cpath_id);
                                foreach (explode('_', $catpath) as $category_id) {
                                    $category_name_query = tep_db_query("select cd.categories_name from categories_description cd, categories c where cd.categories_id=c.categories_id and cd.categories_id='" . (int) $category_id . "' and cd.language_id='" . (int) $newlanguages_id . "' and c.parent_id='" . (int) $parent_id . "'");
                                    if ($category_name_array = tep_db_fetch_array($category_name_query)) {
                                        $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($category_name_array['categories_name'])))));
                                        $parent_id = $category_id;
                                    }
                                }
                            }
                            $seo_type = 'categories_id';
                            $seo_val = $category_id;
                            break;
                        case 'products_id':
                            // CONTROLEER ALS ER SEO URL IN DATABASE IS
                            $get_seo_product_query = tep_db_query("select url from seo_urls where products_id = '" . (int) $pair_array[1] . "'");
                            if (tep_db_num_rows($get_seo_product_query) > 0) {
                                $get_seo_product = tep_db_fetch_array($get_seo_product_query);
                                $seo_url_cache = $get_seo_product['url'];
                            } else {
                                //ZONIET, SEO URL AANMAKEN
                                $seo_url_cache = '';
                                $product_name_query = tep_db_query("select p.products_model, pd.products_name from products p JOIN products_description pd using (products_id) where p.products_id='" . (int) $pair_array[1] . "' and pd.language_id='" . (int) $languages_id . "'");
                                if ($product_name_array = tep_db_fetch_array($product_name_query)) {
                                    if ($seo_type != 'categories_id' && SEO_URL_PRODUCT_LAYERED != 'false') {
                                        $product_categories_query = tep_db_query("select categories_id from products_to_categories where products_id='" . (int) $pair_array[1] . "'");
                                        if ($product_categories_array = tep_db_fetch_array($product_categories_query)) {
                                            foreach (explode('_', tep_get_full_cpath($product_categories_array['categories_id'])) as $this_category_id) {
                                                $category_name_query = tep_db_query("select categories_name from categories_description where language_id='" . (int) $languages_id . "' and categories_id='" . (int) $this_category_id . "'");
                                                while ($category_name_array = tep_db_fetch_array($category_name_query)) {
                                                    $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($category_name_array['categories_name'])))));
                                                }
                                            }
                                        }
                                    }
                                }
                                if (SEO_URL_PRODUCTS_MODEL == 'only') {
                                    $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($product_name_array['products_model'])))));
                                } elseif (SEO_URL_PRODUCTS_MODEL != 'false') {
                                    if (SEO_URL_PRODUCTS_MODEL == 'after') {
                                        $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($product_name_array['products_name']))))) . '-' . RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($product_name_array['products_model'])))));
                                    } else {
                                        $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($product_name_array['products_model']))))) . '-' . RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($product_name_array['products_name'])))));
                                    }
                                } else {
                                    $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode(trim($product_name_array['products_name'])))));
                                }
                            }
                            //die($tester);
                            //die(print_r($cPath_list));
                            $seo_type = 'products_id';
                            $seo_val = $pair_array[1];
                            break;
                        case 'manufacturers_id':
                            $manufacturer_name_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id='" . (int) $pair_array[1] . "'");
                            if ($manufacturer_array = tep_db_fetch_array($manufacturer_name_query)) {
                                $manufacturer_name = $manufacturer_array['manufacturers_name'];
                            }
                            $seo_type = 'manufacturers_id';
                            $seo_val = $pair_array[1];
                            break;
                        case 'filter_id':
                            $filter_query = tep_db_query('SELECT categories_name FROM categories_description WHERE categories_id = "' . (int) $pair_array[1] . '" AND language_id = "' . (int) $languages_id . '"');
                            if ($filter = tep_db_fetch_array($filter_query)) {
                                $filter_name = $filter['categories_name'];
                            }
                            $seo_type = 'manufacturers_id';
                            $seo_val .= '_' . $pair_array[1];
                            break;
                        case '':
                            break;
                        default:
                            if (tep_not_null($pair)) {
                                $new_parameter_list[] = $pair;
                            }
                    }
                }
                if ($seo_url_cache != '') {
                    unset($cPath_list);
                    $cPath_list[] = substr($seo_url_cache, 1);
                } else {
                    if (tep_not_null($manufacturer_name)) {
                        $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode($manufacturer_name))));
                    }
                    if (tep_not_null($filter_name)) {
                        $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode($filter_name))));
                    }
                    if (tep_not_null($infopage_name)) {
                        if ($p_infopage_parent_name != '') {
                            $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode($p_infopage_parent_name))));
                        }
                        if ($infopage_parent_name != '') {
                            $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode($infopage_parent_name))));
                        }
                        if ($infopage_name != '') {
                            $cPath_list[] = RemoveUnwantedCharacters(str_replace("+", "-", strtolower(urlencode($infopage_name))));
                        }
                    }
                }
                $separator = '?';
                $link .= preg_replace('/%2F/', '%20', implode('/', $cPath_list));
                if (tep_not_null($new_parameter_list)) {
                    $link .= $separator . implode('&', $new_parameter_list);
                    $separator = '&';
                }
                break;
            case FILENAME_INFOPAGE:
                $new_parameter_list = array();
                foreach (explode('&', $parameters) as $pair) {
                    global $languages_id;
                    $pair_array = explode('=', $pair);
                    switch ($pair_array[0]) {
                        case 'action':
                            $link .= $page . '?' . tep_output_string($parameters);
                            $separator = '&';
                            break 3;
                        case 'page':
                            $parent_id = 0;
                            // CONTROLEER ALS ER SEO URL IN DATABASE IS
                            $get_seo_infopage_query = tep_db_query("select url from seo_urls where infopages_id = '" . $pair_array[1] . "'");
                            if (tep_db_num_rows($get_seo_infopage_query) > 0) {
                                $get_seo_infopage = tep_db_fetch_array($get_seo_infopage_query);
                                $seo_url_cache = $get_seo_infopage['url'];
                            } else {
                                //ZONIET, SEO URL AANMAKEN
                                $seo_url_cache = '';
                                $parent_id_query = tep_db_query("select parent_id from navigatie where link='i_" . $pair_array[1] . "'");
                                if ($parent_id_array = tep_db_fetch_array($parent_id_query)) {
                                    $parent_id = $parent_id_array['parent_id'];
                                    $infopage_parent_link_query = tep_db_query("select parent_id, link from navigatie where id='" . (int) $parent_id . "'");
                                    if ($infopage_parent_link_array = tep_db_fetch_array($infopage_parent_link_query)) {
                                        $infopage_parent_link = str_replace('i_', '', $infopage_parent_link_array['link']);
                                        $p_parent_id = 0;
                                        $p_parent_id_query = tep_db_query("select parent_id from navigatie where link='i_" . $infopage_parent_link . "'");
                                        if ($p_parent_id_array = tep_db_fetch_array($p_parent_id_query)) {
                                            $p_parent_id = $p_parent_id_array['parent_id'];
                                            $p_infopage_parent_link_query = tep_db_query("select parent_id, link from navigatie where id='" . (int) $p_parent_id . "'");
                                            if ($p_infopage_parent_link_array = tep_db_fetch_array($p_infopage_parent_link_query)) {
                                                $p_infopage_parent_link = str_replace('i_', '', $p_infopage_parent_link_array['link']);
                                            }
                                        }
                                        $p_infopage_parent_name_query = tep_db_query("select infopages_title from infopages_text where infopages_id='" . (int) $p_infopage_parent_link . "' and language_id='" . (int) $languages_id . "'");
                                        if ($p_infopage_parent_name_array = tep_db_fetch_array($p_infopage_parent_name_query)) {
                                            $p_infopage_parent_name = RemoveSpecialCharacters(str_replace('-', '+', $p_infopage_parent_name_array['infopages_title']));
                                        }
                                    }
                                }
                                $infopage_parent_name_query = tep_db_query("select infopages_title from infopages_text where infopages_id='" . (int) $infopage_parent_link . "' and language_id='" . (int) $languages_id . "'");
                                if ($infopage_parent_name_array = tep_db_fetch_array($infopage_parent_name_query)) {
                                    $infopage_parent_name = RemoveSpecialCharacters(str_replace('-', '+', $infopage_parent_name_array['infopages_title']));
                                }
                                $infopage_name_query = tep_db_query("select infopages_title from infopages_text where infopages_id='" . (int) $pair_array[1] . "' and language_id='" . (int) $languages_id . "'");
                                if ($infopage_array = tep_db_fetch_array($infopage_name_query)) {
                                    $infopage_name = RemoveSpecialCharacters(str_replace('-', '+', $infopage_array['infopages_title']));
                                }
                            }
                            $seo_type = 'infopages_id';
                            $seo_val = $pair_array[1];
                            break;
                        case '':
                            break;
                        default:
                            if (tep_not_null($pair)) {
                                $new_parameter_list[] = $pair;
                            }
                    }
                }
                if ($seo_url_cache != '') {
                    unset($cPath_list);
                    $cPath_list[] = substr($seo_url_cache, 1);
                } else {
                    if (tep_not_null($manufacturer_name)) {
                        $cPath_list[] = str_replace("+", "-", strtolower(urlencode($manufacturer_name)));
                    }
                    if (tep_not_null($infopage_name)) {
                        if ($p_infopage_parent_name != '') {
                            $cPath_list[] = str_replace("+", "-", strtolower(urlencode($p_infopage_parent_name)));
                        }
                        if ($infopage_parent_name != '') {
                            $cPath_list[] = str_replace("+", "-", strtolower(urlencode($infopage_parent_name)));
                        }
                        if ($infopage_name != '') {
                            $cPath_list[] = str_replace("+", "-", strtolower(urlencode($infopage_name)));
                        }
                    }
                }
                $separator = '?';
                $link .= preg_replace('/%2F/', '%20', implode('/', $cPath_list));
                if (tep_not_null($new_parameter_list)) {
                    $link .= $separator . implode('&', $new_parameter_list);
                    $separator = '&';
                }
                break;
            default:
                $link .= $page . '?' . tep_output_string($parameters);
                $separator = '&';
        }
    } else {
        $link .= $page;
        $separator = '?';
    }
    while (substr($link, -1) == '&' || substr($link, -1) == '?') {
        $link = substr($link, 0, -1);
    }
    // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
    if ($add_session_id == true && $session_started == true && SESSION_FORCE_COOKIE_USE == 'False') {
        if (tep_not_null($SID)) {
            /*FORUM*/
            //$_sid = $SID;
            /*FORUM*/
        } elseif ($request_type == 'NONSSL' && $connection == 'SSL' && ENABLE_SSL == true || $request_type == 'SSL' && $connection == 'NONSSL') {
            if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
                $_sid = tep_session_name() . '=' . tep_session_id();
            }
        }
    }
    if (SEARCH_ENGINE_FRIENDLY_URLS == 'true' && $search_engine_safe == true) {
        while (strstr($link, '&&')) {
            $link = str_replace('&&', '&', $link);
        }
        $link = str_replace('?', '/', $link);
        $link = str_replace('&', '/', $link);
        $link = str_replace('=', '/', $link);
        $link = str_replace('+', '-', $link);
        $separator = '?';
    }
    //SAVE TO DB
    if (isset($_sid)) {
        $link .= $separator . $_sid;
    }
    if ($seo_type == '') {
        $seo_type = 'navigatie_id';
    }
    if (TransformSeoUrl($link) != '/') {
        $get_seo_query = tep_db_query("select id from seo_urls where " . $seo_type . " = '" . $seo_val . "' AND language_id = '" . (int) $newlanguages_id . "'");
        if (tep_db_num_rows($get_seo_query) < 1) {
            tep_db_query("INSERT INTO seo_urls (language_id, " . $seo_type . ", url) VALUES ('" . $newlanguages_id . "', '" . $seo_val . "', '" . TransformSeoUrl($link) . "')");
        }
    }
    //SAVE TO DB
    return $link;
}
コード例 #2
0
ファイル: seo.php プロジェクト: CristianCCIT/shop4office
function RemoveUnwantedCharacters($text)
{
    $text = str_replace('/', '-', $text);
    $text = str_replace('%2f', '-', $text);
    $text = str_replace('%2b', '', $text);
    $text = str_replace('%2c', '', $text);
    $text = str_replace('%26quot%3b', '', $text);
    $text = str_replace('%26prime%3b', '', $text);
    $text = str_replace('%28', '', $text);
    $text = str_replace('%29', '', $text);
    $text = str_replace('"', '', $text);
    $text = str_replace("'", "", $text);
    if (strpos($text, '--')) {
        $text = RemoveUnwantedCharacters(str_replace('--', '-', $text));
    }
    return $text;
}