xoops forums

Bleekk

Theme Designer
Posted on: 7/4 7:31
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 906
Since: 2002/12/14
#1

Xoops Tags and char limit in modules

Hi all,

I hope someone of the module developers can help here.
Following problem:
When you set a limit to the chars of a article, like in the latest news, the xoops tags will be counted as chars. Which result in a problem because they will be cut off if the limit of chars exeeds. The next problem is that then the html is not valid.
If you have something like this
[b]this is a bold line[/b]
then the it counts 26 chars instead of 19. And if it cuts of the closing tag then the rest of the article, maybe the complete website is bold.
You can see it here https://xoops.org/modules/publisher/
The first article destroys the design of the complete website.
This is not a probem with publisher but with all other modules.

Mage

Core Developer
Posted on: 7/5 14:45
Mage
Mage (Show more)
Core Developer
Posts: 167
Since: 2009/8/2 1
#2

Re: Xoops Tags and char limit in modules

Hi,

The solution is to not cut the text in php. You have to cut the text with smarty. The truncat function can do this:

http://www.smarty.net/docsv2/en/language.modifier.truncate.tpl

But I'm not sure it works for your problem.

Mamba

Moderator
Posted on: 7/5 15:28
Mamba
Mamba (Show more)
Moderator
Posts: 10418
Since: 2004/4/23
#3

Re: Xoops Tags and char limit in modules

I think, Goffy used a "autosummary" function from WF-Downloads to have something like this.
Can you check with him?

Actually, it was a function called "truncateHtml", see here:
https://github.com/ggoffy/wgteams/comm ... a9e89278157de3f6f14810d9d
Support XOOPS => DONATE
Use 2.5.9 | Docs | Modules | Bugs

geekwright

Quite a regular
Posted on: 7/5 15:57
geekwright
geekwright (Show more)
Quite a regular
Posts: 225
Since: 2010/10/15
#4

Re: Xoops Tags and char limit in modules

You can't just cut out a section and expect it to be valid -- you need to work with the DOM.

This sample code takes whatever you cropped, and turns it into valid HTML with all the tags closed:
// $croppedInput is your cropped summary
$doc = new DOMDocument();
$doc->loadHTML($croppedInput);
$docBody $doc->getElementsByTagName('body')->item(0);
$validOutput '';
foreach (
$docBody->childNodes as $childNode) {
    
$validOutput .= $doc->saveHTML($childNode);
}
// $validOutput should now be valid HTML

Bleekk

Theme Designer
Posted on: 7/5 16:32
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 906
Since: 2002/12/14
#5

Re: Xoops Tags and char limit in modules

Does this also prevent that xoops tags will be counted as chars?

geekwright

Quite a regular
Posted on: 7/5 18:08
geekwright
geekwright (Show more)
Quite a regular
Posts: 225
Since: 2010/10/15
#6

Re: Xoops Tags and char limit in modules

Quote:

Bleekk wrote:

Does this also prevent that xoops tags will be counted as chars?


Sorry, I misread things.

That works on HTML, not XoopsCode.

You would render first with MyTextSanitizer::xoopsCodeDecode(),
then crop the resulting HTML,
then run through that code to make sure the result is valid.

It isn't perfect, but it should fix the "article destroys the design of the complete website" issue.

Since some modules/configurations might allow HTML, a solution that works with the HTML would be best? We should have a standard function to do that, but we don't yet. Its on my list now.

Mamba

Moderator
Posted on: 7/25 20:19
Mamba
Mamba (Show more)
Moderator
Posts: 10418
Since: 2004/4/23
#7

Re: Xoops Tags and char limit in modules

Would Smarty work for this?

http://devcodepro.com/view/12/1/Smarty-Remove-BBCode

function smarty_modifier_removebb($string)
{
    
$find    '|[[/!]*?[^[]]*?]|si';
    
$replace '';

    return 
preg_replace($find$replace$string);
}
Support XOOPS => DONATE
Use 2.5.9 | Docs | Modules | Bugs