e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
321 stars 213 forks source link

download meta description - bad result (parsing) #4687

Open Jimmi08 opened 2 years ago

Jimmi08 commented 2 years ago

Bug Description

The download meta description is generated from the download description, that is TinyMCE field.

Lines are getting to one line for meta description without space between lines... and text is not correctly readable.

Normal description with tinymce used: image

lines are getting together in meta field:

image

How to Reproduce

Steps to reproduce the behavior:

  1. Go to download, add more line description and check result in source code

Expected Behavior

The new line should be replaced by space.

Server Information

PHP 7.4 e107 2.3.1 stable

Additional information

This code is used now:

$metaDescription                = $tp->toHTML($row['download_description'],true);
$metaDescription                = preg_replace('/\v(?:[\v\h]+)/', '', $metaDescription); // remove all line-breaks and excess whitespace
        $metaDescription                = $tp->text_truncate($metaDescription, 290); // + '...'

        e107::meta('description',       $tp->toText($metaDescription));
  1. $tp->text_truncate() is already using $tp->toText() so it is doubled

  2. not sure what should preg_replace do, value is not changed, line breaks are still there...

  3. toText() does this:

    
    $text = str_replace("\n", '', $text); // clean-out line-breaks.
    $text = str_ireplace(array('<br>', '<br />', '<br/>'), "\n", $text);

and it was fixed after change - replaced \n with space.
`$text = str_replace("\n", ' ', $text);` 
Jimmi08 commented 2 years ago

https://github.com/e107inc/e107/issues/4094

Moc commented 2 years ago

If you have a minute, can you try the following fix?

        $metaDescription = e107::getParser()->toText($row['download_description']); 
        $metaDescription = e107::getParser()->truncate($metaDescription, 150);

        e107::meta('description',       $metaDescription);
Moc commented 2 years ago

Actually that doesn't work. @CaMer0n Can you have a look please?

CaMer0n commented 2 years ago

@Moc I believe the issue is that the field was never designed for this this kind of use case. ie. multiple paragraphs of field data, rather than an actual descriptive sentence. Even if the parser did 'work' in this case, the site would be left with misleading meta-descriptions that could have a negative affect on SEO.

Other solutions: a custom plugin to expand the downloads fields with an additional field to store this other data.

Add a meta-description field to the downloads plugin, like we have for news and pages, so that it could be customized (overridden) when needed.

Moc commented 2 years ago

I understand.

I've cleaned up the mess I made but the current situation is not ideal, so I'm leaving this issue open.