Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\Xmf\Metagen::generateDescription() and xlanguage #86

Open
GregMage opened this issue Aug 17, 2021 · 2 comments
Open

\Xmf\Metagen::generateDescription() and xlanguage #86

GregMage opened this issue Aug 17, 2021 · 2 comments

Comments

@GregMage
Copy link

This method does not work with xlanguage. With the first language, no problem but if we activate the second then Xoops crashes.

To avoid the problem I wrote this in my module:

$xoTheme->addMeta('meta', 'description', \Xmf\Metagen::generateDescription(preg_replace("/\[.*?\]/", '', $content->getVar('content_text')), 30));

I don't know if it's really good what I'm doing. We can add this code to the method "asPlainText()"

$text = preg_replace('/\[.*?\]/', ' ', $text);

The full code:

    protected static function asPlainText($rawText)
    {
        $text = $rawText;
        $text = static::html2text($text);
        $text = static::purifyText($text);

        $text = str_replace(array("\n", "\r"), ' ', $text);
        $text = preg_replace('/[ ]* [ ]*/', ' ', $text);
        $text = preg_replace('/\[.*?\]/', ' ', $text);

        return trim($text);
    }
@zyspec zyspec transferred this issue from XOOPS/XoopsCore25 Dec 6, 2021
@geekwright
Copy link
Collaborator

To build a clean description, we need to have the xlanguage processing for the string field to be run.

I am thinking a preload could help out with this.

We could add a preload that would do the language based selection to xlanguage, and trigger an event in Metagen to condition the string before processing. If xlanguage is not installed there would be no processing, and no changes would be made to the string.

Would this solve the issues?

@GregMage
Copy link
Author

I solved the problem like this:

	public static function generateDescriptionTagSafe($text, $wordCount = 100)
    {
		if (xoops_isActiveModule('xlanguage')){
			$text = XoopsModules\Xlanguage\Utility::cleanMultiLang($text);
		}
		$text = \Xmf\Metagen::generateDescription($text, $wordCount);
		return $text;
	}
	
	public static function TagSafe($text)
    {
		if (xoops_isActiveModule('xlanguage')){
			$text = XoopsModules\Xlanguage\Utility::cleanMultiLang($text);
		}
		return $text;
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants