Warning: A non-numeric value encountered in...

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Tata
Posts: 2653
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Warning: A non-numeric value encountered in...

Post by Tata » Tue Dec 12, 2017 6:05 pm

I have built a "testing portal" for XH_1.7.1 plugins at http://plugins_171.cmsimple.sk.
There are also my three plugins:
[url=http://plugins_171.cmsimple.sk/?Plugins-Test/plugins-by-tata/sitr]sitr_XH[/url]
[url=http://plugins_171.cmsimple.sk/?Plugins-Test/plugins-by-tata/w-plan-pro]w-plan-pro[/url]
[url=http://plugins_171.cmsimple.sk/?Plugins-Test/plugins-by-tata/week-plan-xh]week-plan-xh[/url]

The plugins run without problem there (there is only one thing unsolved - week days depending on used language, you can see that only the US sorting is used)
Except of EN the order shall the week begin on Monday.

On localhost, however, the week_plan_xh plugin returns:
Warning: A non-numeric value encountered in /Users/msereday/webpages/171-plugins/plugins/week_plan_xh/index.php on line 42
Cannot modify header information - headers already sent (output started at /Users/msereday/webpages/171-plugins/plugins/week_plan_xh/index.php:42)
Plugins are downloadable on http://plugins_171.cmsimple.sk/?Plugins-Test
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Tata
Posts: 2653
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Warning: A non-numeric value encountered in... SOLVED

Post by Tata » Tue Dec 12, 2017 7:01 pm

There was in the line #42

Code: Select all

$next_day = $day_name[date('l',$time)+ 1];
Changing it to

Code: Select all

$next_day = date('Y-m-d', strtotime(' +1 day'));
seems to solve it locally (download actualized).
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 12436
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Warning: A non-numeric value encountered in... SOLVED

Post by cmb » Tue Dec 12, 2017 10:40 pm

Tata wrote:There was in the line #42

Code: Select all

$next_day = $day_name[date('l',$time)+ 1]; 
date('l') returns the name of the weekday as string; trying to add 1 to a string which is not numeric triggers a warning as of PHP 7.1.0, which is good since it often points out a bug.
Tata wrote:Changing it to

Code: Select all

$next_day = date('Y-m-d', strtotime(' +1 day')); 
seems to solve it locally (download actualized).
Yes, that's better. However, the PHP manual recommends against using strtotime() for date calculations. Also note that using the Calendar extension in this case might be beneficial.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

Tata
Posts: 2653
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Warning: A non-numeric value encountered in... SOLVED

Post by Tata » Wed Dec 13, 2017 12:23 am

cmb wrote:Also note that using the Calendar extension in this case might be beneficial.
Well, but then everyone using this plugin (if used functions of the extension) would need to make the same installation on his server.
Other thing is the difference in weekdays. I don't know how to support the right days order while changing the language.
Both in en.php and sk.php (de.php) the days are defined (in respective language) as

Code: Select all

$plugin_tx['week_plan_xh']['day_names'] = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"; 
Both in w-plan-prpo and week-plan-xh plugins shall the days flow be different. I tried to change the order of days change in language files, but the result is not as expected. Regardless the language, the week starts always on Sunday. What's the trick?
Also below the green header shall appear the content of the respective "tomorrow" page. But I don't know how to define it in

Code: Select all

newsbox($next_day)
e.g. today is Wednesday (the orange header), so below shall be about the same newsbox showing the content of "Thursday" page.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 12436
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Warning: A non-numeric value encountered in... SOLVED

Post by cmb » Wed Dec 13, 2017 12:53 pm

Tata wrote:Other thing is the difference in weekdays. I don't know how to support the right days order while changing the language.
Both in en.php and sk.php (de.php) the days are defined (in respective language) as

Code: Select all

$plugin_tx['week_plan_xh']['day_names'] = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
Both in w-plan-prpo and week-plan-xh plugins shall the days flow be different. I tried to change the order of days change in language files, but the result is not as expected. Regardless the language, the week starts always on Sunday. What's the trick?
The for loop in w_plan_weekend() (w_plan_pro_v1_2b.zip) has to be changed:

Code: Select all

    for ($i = 0; $i <= 6; $i++)

        $o .= "<div class='w_plan_content_weekend'>" 
                        . newsbox($day_name[date($i)]) . "
                </div>"; 
Firstly, you should fix the newsbox() call; there is no need to call date() at all, and it might cause errors:

Code: Select all

    for ($i = 0; $i <= 6; $i++)

        $o .= "<div class='w_plan_content_weekend'>" 
                        . newsbox($day_name[$i]) . "
                </div>"; 
As it is, it runs from 0 (Sunday) to 6 (Saturday). If you want it to run from Monday (1) to Sunday(0), use:

Code: Select all

    for ($i = 1; $i <= 7; $i++)

        $o .= "<div class='w_plan_content_weekend'>" 
                        . newsbox($day_name[$i % 7]) . "
                </div>"; 
Note that the $i % 7 does no harm regardless whether the loop runs from 0 to 6 or 1 to 7, so I'd suggest to always use it. You can also run the loop from 3 to 9 etc., if desired.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

Tata
Posts: 2653
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Warning: A non-numeric value encountered in...

Post by Tata » Wed Dec 13, 2017 1:55 pm

That's it. Now the warning on Localhost is gone and the week beginns on Monday. But Now it is on Monday in EN as well. Funnz. Why the nations don't just unify this :-)?

In the next plugin (week_plan_xh), which is basically the w_plan_pro extended clone remains the problem described in the code

Code: Select all

...
    $next_day = date('Y-m-d', strtotime(' + 1 day'));


// TEST: CONFIGURATION FOR show_next_day
// !!! PROBLEM: DOESN'T RETURN THE DATE IN RIGHT FORM - MISSING DAY NAME 
    $next_day_box = "";
     if(!$show_next_day || $show_next_day == 'never'){
         $next_day_box = "";
         }elseif ($show_next_day == 'today' || $show_next_day == 'always') {
         $next_day_box = "<div class='w_plan_content_tomorrow'>
                         <div class='w_plan_tomorrow'>" .
                              $tomorrow .
                         "</DIV>
                         <div class='w_plan_next_day'>" . 
// Here the page named by respective "tomorrow day" of week shall be loaded
                              newsbox($next_day) .     
                         "</div>
                         </div>";
         }else{
          $next_day_box = "";
     }
// END TEST



// RENDER CONTENT FOR ACTUAL AND NEXT DAY
$o = '';
$o .= " <div class='w_plan_content_today'>
            <div class='w_plan_day_time'>"
                . $day_name[date('w')].", ".date($plugin_tx['week_plan_xh']['dateformat'])."
            </div>" ; 
if($time < $startTime){
                    $o .= newsbox($day_name[date('w')]);
               }elseif($time > $stopTime){
                    $o .= newsbox($plugin_tx['week_plan_xh']['program_finished']);
               }elseif($stopTime < $time && $time < $startTime){
                    $o .= newsbox($day_name[date('w')]);
               }else 
            $o .= newsbox($day_name[date('w')]);
            $o .="</div>" .
            $next_day_box;
   
    return $o;
}
... 
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 12436
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Warning: A non-numeric value encountered in...

Post by cmb » Wed Dec 13, 2017 2:39 pm

Tata wrote:In the next plugin (week_plan_xh), which is basically the w_plan_pro extended clone remains the problem described in the code

Code: Select all

...
    $next_day = date('Y-m-d', strtotime(' + 1 day'));
This way $next_day contains something like "2017-12-13", but not the number of the weekday. Use the following instead:

Code: Select all

    $next_day = date('w', strtotime(' + 1 day')); 
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

Tata
Posts: 2653
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Warning: A non-numeric value encountered in...

Post by Tata » Wed Dec 13, 2017 3:02 pm

Well, it's a half way to what is expected. It shows the number of day in the newsbox instead of the page. There are pages "Monday", "Tuesday" etc. in the content. Just the same way they are defined in resp. language files. So today the tomorrow" box shaoul read the Thursday page. Now there is only the number "4".
screenshot-webpages 8888-2017-12-13-15-58-32.png
screenshot-webpages 8888-2017-12-13-15-58-32.png (4.37 KiB) Viewed 357 times
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Tata
Posts: 2653
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Warning: A non-numeric value encountered in...

Post by Tata » Wed Dec 13, 2017 3:25 pm

Now, changing these two lines it works, but only on localhost and only in main language. On the server there is still the "4" only both in main and 2lang.

Code: Select all

...
    $next_day = date('w', strtotime(' + 1 day'));
...
                         <div class='w_plan_next_day'>" . 
                              newsbox(date('l', strtotime(' + 1 day'))) .     
                         "</div>
... 
screenshot-webpages 8888-2017-12-13-16-22-49.png
AM LOCALHOST
screenshot-plugins_171.cmsimple.sk-2017-12-13-16-23-08.png
AM SERVER
screenshot-plugins_171.cmsimple.sk-2017-12-13-16-23-08.png (11.34 KiB) Viewed 357 times
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 12436
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Warning: A non-numeric value encountered in...

Post by cmb » Wed Dec 13, 2017 3:50 pm

Tata wrote:Now, changing these two lines it works, but only on localhost and only in main language.
Ah, yes, it has to be data('l', …) in this case.
Tata wrote:On the server there is still the "4" only both in main and 2lang.
I'm pretty sure that is a caching issue.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

Post Reply