Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
539 views
in Q2A Core by

Hello, the link to the question appears well, as in the attached image

But in the sitemap, it appears with many letters.

You select this option.

But then it appears as numbers only

How can I make it appear in the sitemap as it is in the link bar? Like the first
picture

Thank you for your help in advance

Q2A version: 1.8.6

1 Answer

+1 vote
by

The problem is in the qa_slugify() function in the file: qa-include/util/string.php

The qa_slugify() function is old and needs a simple but very useful update:

See on my own site an example of a page in the Russian language where the url was: https://q2aweb.com/410989/ after the update I made: https://q2aweb.com/410989/cto-mozno-sdelat-dla-ulucsenia-klientskogo-servisa

Let's fix this problem now!

Open the file: qa-include/util/string.php and replace the lines:

// convert accents to ASCII, then remove all remaining non-ASCII characters

$string = qa_string_remove_accents($string);

$string = preg_replace('/[^ a-zA-Z0-9-]/', '', $string);

$string = preg_replace('/-{2,}/', '-', trim($string, '-'));

per
$string = html_entity_decode($string, ENT_QUOTES, 'utf-8');
if (function_exists('transliterator_transliterate')) {
// PHP 5.4 + intl
$string = transliterator_transliterate('Any-Latin; Latin-ASCII', $string);
}
if (function_exists('normalizer_normalize')) {
// PHP 5.3 + intl
$string = normalizer_normalize(preg_replace('/\\p{Mn}+/u', '', normalizer_normalize($string, Normalizer::FORM_D)), Normalizer::FORM_C);
}
if (function_exists('iconv') && ICONV_IMPL == 'glibc') {
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
}
// version incomplète (limitée au latin1)
$patterns = array('~&([A-za-z])(?:grave|acute|circ|tilde|uml|ring|cedil|slash|caron);~' => '\\1', '~&([A-za-z]{2})lig;~' => '\\1', '~&[^;]+;~' => ' ');
$string = htmlentities($string, ENT_NOQUOTES, 'UTF-8');
$string = preg_replace(array_keys($patterns), array_values($patterns), $string);
$string = str_replace(array('[\', \']'), '', $string);
$string = preg_replace('/\[.*\]/U', '', $string);
$string = htmlentities($string, ENT_QUOTES, 'UTF-8');
$string = preg_replace('/&(amp;)?#?[a-zA-Z0-9]+;/i', '-', $string);
$string = htmlentities($string, ENT_COMPAT, 'utf-8');
$string = preg_replace('/&([A-za-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);/i', '', $string);
$string = preg_replace(array('/[^a-zA-Z0-9]/i', '/[-]+/') , '-', $string);
You are welcome!
by
edited by
+1

First, thank you

I appreciate your help in solving this problem

I am really grateful to you for that

I want to ask you in the old text shows a blank space

When replacing the new text does not appear

Will this be a problem?

Excuse my ignorance, I really don't know about this.

Please see the attached picture

 

by
In this specific case, there's no problem leaving it that way.

But if you find it weird or want better formatting, I leave the code of my function qa_slugify for you to copy if you want.


function qa_slugify($string, $asciiOnly = true, $maxLength = null)
{
    if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }

    $words = qa_string_to_words($string, true, false, false);

    if ($maxLength !== null) {
        $wordlength = array();
        foreach ($words as $index => $word) {
            $wordlength[$index] = qa_strlen($word);
        }

        $remaining = $maxLength;
        if (array_sum($wordlength) > $remaining) {
            arsort($wordlength, SORT_NUMERIC); // sort with longest words first

            foreach ($wordlength as $index => $length) {
                if ($remaining > 0) {
                    $remaining -= $length;
                } else {
                    unset($words[$index]);
                }
            }
        }
    }

    $string = implode('-', $words);

    if ($asciiOnly) {
       
        //NOVO SCRIPT QUE ACEITA URL DE IDIOMAS COM CARACTERES ESTRANHOS
        $string = html_entity_decode($string, ENT_QUOTES, 'utf-8');
        if (function_exists('transliterator_transliterate')) {
        // PHP 5.4 + intl
        $string = transliterator_transliterate('Any-Latin; Latin-ASCII', $string);
        }
        if (function_exists('normalizer_normalize')) {
        // PHP 5.3 + intl
        $string = normalizer_normalize(preg_replace('/\\p{Mn}+/u', '', normalizer_normalize($string, Normalizer::FORM_D)), Normalizer::FORM_C);
        }
        if (function_exists('iconv') && ICONV_IMPL == 'glibc') {
        $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
        }
        // version incomplète (limitée au latin1)
        $patterns = array('~&([A-za-z])(?:grave|acute|circ|tilde|uml|ring|cedil|slash|caron);~' => '\\1', '~&([A-za-z]{2})lig;~' => '\\1', '~&[^;]+;~' => ' ');
        $string = htmlentities($string, ENT_NOQUOTES, 'UTF-8');
        $string = preg_replace(array_keys($patterns), array_values($patterns), $string);
        $string = str_replace(array('[\', \']'), '', $string);
        $string = preg_replace('/\[.*\]/U', '', $string);
        $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
        $string = preg_replace('/&(amp;)?#?[a-zA-Z0-9]+;/i', '-', $string);
        $string = htmlentities($string, ENT_COMPAT, 'utf-8');
        $string = preg_replace('/&([A-za-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);/i', '', $string);
        $string = preg_replace(array('/[^a-zA-Z0-9]/i', '/[-]+/') , '-', $string);

        //ANTIGO SCRIPT QUE REMOVIA URL DE IDIOMAS COM CARACTERES ESTRANHOS
        // convert accents to ASCII, then remove all remaining non-ASCII characters
        //$string = qa_string_remove_accents($string);
        //$string = preg_replace('/[^ a-zA-Z0-9-]/', '', $string);
        //$string = preg_replace('/-{2,}/', '-', trim($string, '-'));
    }

    return $string;
}
by
I copied the text and it works fine, but the problem is that the writing language in the link has changed to another language

https://www.ask-1000.com/31/madha-tf-l-nd-hdwth-tsrb-llghaz-wkyf-ttsrf-bhkmt-m-hdha-alshan-
by
The url will be generated with characters a-z and 0-9, but if you translate the url text from Arabic to another language it arrives at the correct page title, eg:

madha-tf-l-nd-hdwth-tsrb-llghaz-wkyf-ttsrf-bhkmt-m-hdha-alshan-
sem "-": madha tf l nd hdwth tsrb llghaz wkyf ttsrf bhkmt m hdha alshan

Translating on Google Translate to any other language, look at how it looks:
https://i.imgur.com/S1EOaN6.png as I am not familiar with your language I thought it was correct, but from what I understood you want the url to be in this format ex:"https://www.ask-1000.com/31/ماذا تفعل عند حدوث تسرب للغاز وكيف تتصرف بحكمة مع هذا الشأن؟"

In this case I really don't know how to help you leave something like this: https://www.ask-1000.com/31/ماذا تفعل عند حدوث تسرب للغاز وكيف تتصرف بحكمة مع هذا الشأن؟

In my case and simpler, because my language is Brazilian Portuguese the letters are a-z and 0-9 and accents.
by
edited by
+1
Yes, I want it to appear in the same language.
Maybe someone can find a solution to this.
But you have provided a lot of help with this problem.
Thank you and have a nice day.

Welcome to the Q&A site for Question2Answer.

If you have a question about Q2A, please ask here, in English.

To report a bug, please create a new issue on Github or ask a question here with the bug tag.

If you just want to try Q2A, please use the demo site.

Categories

...