Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-07-17 04:36:17

J-zef
New Member
From: Russia, Saratov
Registered: 2019-03-16
Posts: 5
Website

Help with plugin

I have little plugin, that estimate time, that user spend for reading the article, and it produces an error/attention notice:

Tag error: <txp:estimate_time_reading /> -> Warning: Use of undefined constant body - assumed 'body' (this will throw an Error in a future version of PHP) while parsing form excerpted on page default

estimate_time_reading()
textpattern/vendors/Textpattern/Tag/Registry.php:139 call_user_func()
textpattern/lib/txplib_publish.php:543 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_publish.php:403 processTags()
textpattern/lib/txplib_misc.php:3294 parse()
textpattern/publish.php:1150 parse_form()
textpattern/publish.php:1257 doArticles()
textpattern/publish.php:921 parseArticles()
article()
textpattern/vendors/Textpattern/Tag/Registry.php:139 call_user_func()

The code of plugin:

if (class_exists('\Textpattern\Tag\Registry')) {
Txp::get('\Textpattern\Tag\Registry')
->register('estimate_time_reading');
}

function estimate_time_reading() {
global $thisarticle;
$words = str_word_count ( strip_tags ( $thisarticle[body] ), 0, "АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя" );
$minutes = round ( $words / 150 );
$divide = $minutes % 10;
if ( ( $minutes >= 5 ) and ( $minutes <= 20 ) ) {
$plural = "";
} elseif ( ( $divide >= 2 ) and ( $divide <= 4 ) ) {
$plural = "ы";
} elseif ( ( $divide >= 5 ) and ( $divide <= 9 ) ) {
$plural = "";
} elseif( $divide = 0 ) {
$plural = "";
} elseif( $divide = 1 ) {
$plural = "у";
} else {
$plural = "";
}
$read = $minutes." минут".$plural;
return $read;
}

What shall I do to solve this problem? Help, please :)

Last edited by J-zef (2021-07-17 04:42:25)


Credendo vidas!

Offline

#2 2021-07-17 11:14:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Help with plugin

Try $thisarticle['Body']. That should fix it. Might be lowercase, can’t remember offhand.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2021-07-19 07:41:10

J-zef
New Member
From: Russia, Saratov
Registered: 2019-03-16
Posts: 5
Website

Re: Help with plugin

Bloke wrote #331039:

Try $thisarticle['Body']. That should fix it. Might be lowercase, can’t remember offhand.

It doesn’t work – either $thisarticle['Body'] and $thisarticle['body'] produce the same notice :(


Credendo vidas!

Offline

#4 2021-07-19 08:29:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,456
Website GitHub

Re: Help with plugin

Weird. I pasted your code in and tried it on my site and it worked fine with the apostrophes. It’s not cached the output has it?

P.S. it’s good practice to use a three-letter prefix for your plugins. This will allow you to take advantage of shortcut syntax when writing tags. ‘zef’ is available.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2021-07-19 09:08:21

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Help with plugin

J-zef, are you testing this online or on a local install?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB