1
Bleekk
Xoops Tags and char limit in modules
  • 2017/7/4 7:31

  • Bleekk

  • Theme Designer

  • Posts: 940

  • Since: 2002/12/14


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 herehttps://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.

2
Mage
Re: Xoops Tags and char limit in modules
  • 2017/7/5 14:45

  • Mage

  • Core Developer

  • Posts: 206

  • Since: 2009/8/2 1


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.

3
Mamba
Re: Xoops Tags and char limit in modules
  • 2017/7/5 15:28

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


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/commit/e8a146ca0e73356a9e89278157de3f6f14810d9d
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

4
geekwright
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

5
Bleekk
Re: Xoops Tags and char limit in modules
  • 2017/7/5 16:32

  • Bleekk

  • Theme Designer

  • Posts: 940

  • Since: 2002/12/14


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

6
geekwright
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.

7
Mamba
Re: Xoops Tags and char limit in modules
  • 2017/7/25 20:19

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


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.10 | Docs | Modules | Bugs

Login

Who's Online

236 user(s) are online (128 user(s) are browsing Support Forums)


Members: 0


Guests: 236


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits