XoopsModules25x/xlanguage

Problem with title on different modules

Opened this issue · 13 comments

Hi,

I used xlanguage in the xmnews module (but same trouble with other modules)

For a news, the content is ok (french and english, xfr / xen ) but the title no :

<title>Prix-l-039-innovation-janvier-2021-xf-Actualité-xfr-xen-News-xen - Mon XOOPS (https://www.monxoops.fr)</title>

this news

It should be

<title>Prix-l-039-innovation-janvier-2021-Actualité-Mon XOOPS (https://www.monxoops.fr)</title>

or

<title>Prix-l-039-innovation-janvier-2021-News-Mon XOOPS (https://www.monxoops.fr)</title>

The code for the title :
$xoopsTpl->assign('xoops_pagetitle', Metagen::generateSeoTitle($news->getVar('news_title') . '-' . $xoopsModule->name()));

This is a general comment about what you describe, not anything specific to xlanguage.

The stated purpose of Metagen::generateSeoTitle() is to "Create an SEO slug." That is not intended to be the page title. It is intended for things like suggesting a "Short URL" for publisher, so your page could be accessed by something like https://www.monxoops.fr/prix-de-l-innovation-janvier-2021

That requires extras from the server (i.e. mod_rewrite.) The readable url is recommended by many to boost search result ranking.

That function knows nothing about xlanguage markup, so it is trying to make sense of them.

My advice is leave Metagen::generateSeoTitle() out of it, and just assign the string to 'xoops_pagetitle'.

Ok, I pass this information on to my developer, Greg! ;-)

That's right, thank you for this feedback!

I have another problem, in the adminstration of my module, I use:

				if (strlen($category_arr[$i]->getVar('category_description', 'e')) > 300){
					$category['description'] = substr($category_arr[$i]->getVar('category_description', 'e'), 0, 300) . '...';
				} else {
					$category['description'] = $category_arr[$i]->getVar('category_description', 'e');
				}

This is problematic with tags because if the description is longer then the tags are not closed and there is a big display problem.

So I decided to do:

$category['description'] = $category_arr[$i]->getVar('category_description', 'e');

and use truncat in the templates. It doesn't work either. How to do?

Up !
I still get this problem on the description fields in xmnews and xmtutorial

As Richard has explained above, it is not a problem of xLanguage, but an issue that should be resolved at an individual module level.

The first part ok, on the other hand my second question is important! I don't see how to change in the module for the second part!

Lexikon has implemented a limit of string length that you can set in the Preferences, and based on that, you can then truncate the text.
Maybe that would work for you? If the field is 255 characters, and you have 3 languages, you could set it up at 70 or something like this? I don't know, just thinking loud here...
Look at the truncateTagSafe() method in /class/Utility.php

Thanks for your feedback but it doesn't work! The html tags use "<>" and the xlanguage tags "[]" moreover I do not see the usefulness of this function because xoops manages this very well.

Sorry, then I'm out of ideas :(

The big problem comes from:

$xoTheme->addMeta('meta', 'description', \Xmf\Metagen::generateDescription($content->getVar('content_text'), 30));

The description causes the website to crash because the xlanguage tag is open but never closed ... You have to modify the code:
$xoTheme->addMeta('meta', 'description', \Xmf\Metagen::generateDescription(preg_replace("/\[.*?\]/", '', $content->getVar('content_text')), 30));

\Xmf\Metagen::generateDescription()

and integrate:

preg_replace("/\[.*?\]/", '', $body)

What do you think?

I think we need to get a good grasp on what xlanguage actually does to understand what needs to be fixed. I'm not an expert on xlanguage, so if I am missing something, please correct me. I've looked over the code quickly, and this is what I see.

Once installed and configured, xlanguage in api.php will call ob_start('XoopsModules\Xlanguage\Utility::cleanMultiLang');

When the task's output is flushed (as the php process is winding down,) Utility::cleanMultiLang() will search through the entire page output, processing the language tags, leaving only the non-tagged text and the text inside active language tags. This processed output is returned as a string, and php sends that in the http response.

Important to note here is that cleanMultiLang() is invoked after all the code has run, after the templates are processed, pretty much after everything.

This means that things that try to truncate or otherwise transform fields that contain tags will likely create garbage output. The xlanguage selection hasn't been made when the transformation is performed.

What can be done?

It appears that cleanMultiLang() could be run on any string, and would return anything that is outside of any tag and anything for the matching language tag.

This could be run on individual fields that need to be further transformed (i.e. truncated, keyword extracted, etc.) and the results used instead of the whole string with unprocessed tags.

This would require that scripts be aware of xlanguage being active to take the different approach, but it would enable the output transformations you are attempting to take place.

I understand the proposed solution but it is complicated, you have to modify all the modules to make them compatible with xlanguage. This problem might appear with another module that uses tags (I don't have example modules). Should we modify all modules for each module that uses tags?

Can't find another solution in xlanguage? Or create a new function in xoops which allows text truncation and who knows how to use xlanguage if it is installed?

This last solution also requires modifying the modules but it is a centralized solution in xoops. This makes it possible to integrate other specificities into this function if necessary.

For example
\Xmf\???:: truncateTagSafe()