1
SMEDrieben
Bug in custom code in class textsanitizer
  • 2015/10/16 19:14

  • SMEDrieben

  • Not too shy to talk

  • Posts: 173

  • Since: 2009/6/17


I have made a custom code in class textsanitizer. It worked fine till recently. I don't know if it went wrong after moving tot 2.5.7.1 of to php 5.4 (tested on 5.4.12 and 5.4.45-0+deb7u1).

This is the error:
le="color: #000000"><?php Fatal error: Cannot make static method MyTextSanitizerExtension::decode() non static in class MytsBldwz in C:wampwwwhttpdocsclasstextsanitizerbldwzbldwz.php on line 64


This is my custom code (bldwz.php) that is a modification of the readme.txt that is found in class/textsanitizer

<?php class MytsBldwz extends MyTextSanitizerExtension { // The encode function for dhtml editor function encode($textarea_id) { // If the extension has config data, load it $config = parent::loadConfig(dirname(__FILE__)); // Make sure that the icon is available /images/form/mycode.gif $code = "<img src='{$this->image_path}/bldwz.gif' alt='Bladwijzer' title='Bladwijzer' onclick='xoopsCodeBldwz("{$textarea_id}","" . htmlspecialchars("Voer de term met bladwijzer in", ENT_QUOTES) . "");' onmouseover='style.cursor="hand"'/>&nbsp;"; $javascript = <<<EOH  function xoopsCodeBldwz(id, enterBldwzPhrase){ if (enterBldwzPhrase == null) { enterBldwzPhrase = "Enter the content for the code."; } var selection = xoopsGetSelect(id); if (selection.length > 0) { var text = selection; }else { var text = prompt(enterBldwzPhrase, ""); } var domobj = xoopsGetElementById(id); if ( text != null && text != "" ) { var result = "[bldwz]" + text + "[/bldwz]"; xoopsInsertText(domobj, result); } domobj.focus(); } EOH; // Return the scripts to be displayed in editor form and the javascript for relevant actions return array($code, $javascript); } // The code parser function load(&$ts) { $ts->patterns[] = "/[bldwz](.*)[/bldwz]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/search.php?query=\1&action=results" target="_top">\1</a>'; $ts->patterns[] = "/[bldwz def](.*)[/bldwz]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/search.php?query=\1+Begrip:&andor=AND&mids%5B%5D=28&action=results" target="_top">\1</a>'; $ts->patterns[] = "/[bldwz stp](.*)[/bldwz]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/search.php?query=\1&mids%5B%5D=28&action=results" target="_top">\1</a>'; $ts->patterns[] = "/[bldwz ([0-9]*)](.*)[/bldwz]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/modules/smartfaq/faq.php?faqid=\1" target="_top">\2</a>'; $ts->patterns[] = "/[bldwz KKK=([0-9]*)](.*)[/bldwz]/sU"; $ts->replacements[] = '<a href="http://www.katholieknederland.nl/katholicisme/katechismus-van-de-katholieke-kerk/blok_FBlokNo\1.html" target="_blank">\2</a>'; $ts->patterns[] = "/[news ([0-9]*)](.*)[/news]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/modules/news/article.php?storyid=\1" target="_top">\2</a>'; $ts->patterns[] = "/[smeb ([0-9]*)](.*)[/smeb]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/modules/publisher/category.php?categoryid=\1" target="_top">\2</a>'; $ts->patterns[] = "/[smehf ([0-9]*)](.*)[/smehf]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/modules/publisher/item.php?itemid=\1" target="_top">\2</a>'; } // Processing the text function decode($text) { // Load config data if any $config = parent::loadConfig( dirname(__FILE__) ); if ( empty($text) || empty($config['enabled']) ) return $text; $ret = someFunctionToConvertTheTextToDefinedFormat($text); return $ret; } } ?>


Line 64 is almost the latest with only "}".

Any idea what is wrong ?

Thanks !

SMEDrieben

2
Mamba
Re: Bug in custom code in class textsanitizer
  • 2015/10/17 9:58

  • Mamba

  • Moderator

  • Posts: 11521

  • Since: 2004/4/23


If the function is declared "static" in the parent as in:

le="color: #000000"><?php static function decode()

you cannot then re-declare it as non-static:

le="color: #000000"><?php function decode($text)

You need to declare "static" as it was done in the parent, i.e.
le="color: #000000"><?php static function decode($text)
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

3
SMEDrieben
Re: Bug in custom code in class textsanitizer
  • 2015/10/17 11:43

  • SMEDrieben

  • Not too shy to talk

  • Posts: 173

  • Since: 2009/6/17


Thanks Mamba ! This solves the problem.

The php-code I used was copied from the class/texsanitizer/readme.txt. It should be changed there as well.

SMEDrieben

4
Mamba
Re: Bug in custom code in class textsanitizer
  • 2015/10/17 18:00

  • Mamba

  • Moderator

  • Posts: 11521

  • Since: 2004/4/23


Quote:
The php-code I used was copied from the class/texsanitizer/readme.txt. It should be changed there as well.

Thanks for letting us know about it - it has been updated now in SVN.

Thank you!
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

5
SMEDrieben
Re: Addtional textsanitizer extensions do not work
  • 2017/11/24 19:53

  • SMEDrieben

  • Not too shy to talk

  • Posts: 173

  • Since: 2009/6/17


This solution worked in 2.5.7.1. Now I am on 2.5.9. and the additional extensions don't work anymore.

I added the extensions to class/textsanitizer/config.php or config-custom.php

le="color: #000000"><?php "ref" => 1, "bldwz" => 1)


Thereafter, [ref] appears in the text, it is not interpreted. This is ref.php
<?php class MytsRef extends MyTextSanitizerExtension { // The code parser public function load(&$ts) { $ts->patterns[] = "/[ref ([0-9]*)](.*)[/ref]/sU"; $ts->replacements[] = '<span class="refbal">&nbsp;\1&nbsp;<span><b>\1.</b>&nbsp;\2</span></span>'; $ts->patterns[] = "/[ref ([0-9]*) news=([0-9]*)](.*)[/ref]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/modules/news/article.php?storyid=\2" target="_top"><span class="refbal pointer">&nbsp;\1&nbsp;<span><b>\1.</b>&nbsp;\3</span></span></a>'; $ts->patterns[] = "/[ref ([0-9]*) smeb=([0-9]*)](.*)[/ref]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/modules/publisher/category.php?categoryid=\2" target="_top"><span class="refbal pointer">&nbsp;\1&nbsp;<span><b>\1.</b>&nbsp;\3</span></span></a>'; $ts->patterns[] = "/[ref ([0-9]*) smehf=([0-9]*)](.*)[/ref]/sU"; $ts->replacements[] = '<a href="' . XOOPS_URL . '/modules/publisher/item.php?itemid=\2" target="_top"><span class="refbal pointer">&nbsp;\1&nbsp;<span><b>\1.</b>&nbsp;\3</span></span></a>'; $ts->patterns[] = "/[ref ([0-9]*) url=(.*)](.*)[/ref]/sU"; $ts->replacements[] = '<a href="\2" target="_blank"><span class="refbal pointer">&nbsp;\1&nbsp;<span><b>\1.</b>&nbsp;\3</span></span></a>'; } // Processing the text public static function decode($text, $width, $height) { // Load config data if any $config = parent::loadConfig( dirname(__FILE__) ); if ( empty($text) || empty($config['enabled']) ) return $text; $ret = someFunctionToConvertTheTextToDefinedFormat($text); return $ret; } } ?>


refbal is defined as class in style.css of my theme.

In the debug, there is one warning (many times repeated):
le="color: #000000"><?php Waarschuwing: Parameter 1 to MytsRef::load() expected to be a reference, value given in bestand /class/module.textsanitizer.php regel 770


How can I get my extensions working ?

Thanks !

SMEDrieben

6
Mamba
Re: Addtional textsanitizer extensions do not work
  • 2017/11/24 20:49

  • Mamba

  • Moderator

  • Posts: 11521

  • Since: 2004/4/23


Try to remove the "&" so it is:

le="color: #000000"><?php load($ts)


see if it helps...
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

7
SMEDrieben
Re: Addtional textsanitizer extensions do not work
  • 2017/11/24 21:41

  • SMEDrieben

  • Not too shy to talk

  • Posts: 173

  • Since: 2009/6/17


That's even worse ! It generates both a parse error and a fatal error:

le="color: #000000"><?php Parse error: syntax error, unexpected '<' in C:wamp64wwwhttpdocsclassmodule.textsanitizer.php(445) : regexp code on line 1


le="color: #000000"><?php Fatal error: preg_replace(): Failed evaluating code: <a href="http://www.ntvg.nl/publicatie/vaststellen-van-hersendood-bij-orgaandonatie" target="_blank"><span class="refbal pointer">&nbsp;1&nbsp;<span><b>1.</b>&nbsp;E.J.O. Kompanje, J.L. Epker, Y.J. de Groot, E.F.M. Wijdicks, M. van der Jagt. Vaststellen van hersendood bij orgaandonatie. <em>Ned Tijdschr Geneeskd.</em> 2013;157:A6444</span></span></a> in C:wamp64wwwhttpdocsclassmodule.textsanitizer.php on line 445 Call Stack


Other suggestion ?

SMEDRieben

8
SMEDrieben
Re: Addtional textsanitizer extensions do not work
  • 2017/11/24 21:58

  • SMEDrieben

  • Not too shy to talk

  • Posts: 173

  • Since: 2009/6/17


But.... I switched "ref" => to 0, reloaded the page, switched back to 1, saved config,php again, reloaded the page and then ... it worked properly without the &

Cookie or cache problem ?

SMEDrieben

9
Mamba
Re: Addtional textsanitizer extensions do not work
  • 2017/11/25 0:53

  • Mamba

  • Moderator

  • Posts: 11521

  • Since: 2004/4/23


Sounds more like cache problem...

I'm glad that it's working now.
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

Who's Online

437 user(s) are online (387 user(s) are browsing Support Forums)


Members: 0


Guests: 437


more...

Donat-O-Meter

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

Latest GitHub Commits