Author Topic: error in ajax-dashboard.php (Saratoga template)  (Read 958 times)

0 Members and 1 Guest are viewing this topic.

Offline zmarfak

  • Contributor
  • ***
  • Posts: 135
    • Matar
error in ajax-dashboard.php (Saratoga template)
« on: July 26, 2018, 09:59:41 AM »
Hi,
in my error log there is always this error :

PHP Warning:  A non-numeric value encountered in /var/www/vhosts/matar.be/httpdocs/weather/ajax-dashboard.php on line 491

The code :
Code: [Select]
  <?php $wr $imagesDir $wrName $dirlabel $wrType// normal wind rose
        $wrtext langtransstr('Wind from') ." " langtransstr($dirlabel);
if ( (strip_units($avgspd) + strip_units($gstspd) < 0.1 ) and
     ($wrCalm <> '') ) { // use calm instead
  $wr $imagesDir $wrCalm;
  $wrtext $bftspeedtext;
 }

  ?>


Line 491 : 
Code: [Select]
if ( (strip_units($avgspd) + strip_units($gstspd) < 0.1 ) and
I'm not a php specialist , can I do something about it or live with it (?) it seams not to effect the working of the website but I find it annoying.

Thanks for any help.

Patrick
Davis Vantage Pro2 with a Meteobridge NANO SD and WL (6.04) on a Intel NUC 
https://www.matar.be

Offline wvdkuil

  • Wim van der kuil
  • Forecaster
  • *****
  • Posts: 1986
    • My PWS at Leuven Belgium Europe
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #1 on: July 26, 2018, 10:17:25 AM »
Probably you are running your site with PHP 7, and the latest versions want numerics to be really numeric.

Go to the funtion stripunits (around line 1140)
Code: [Select]
//=========================================================================
// strip trailing units from a measurement
// i.e. '30.01 in. Hg' becomes '30.01'
function strip_units ($data) {
  preg_match('/([\d\,\.\+\-]+)/',$data,$t);
  return $t[1];
}
And change the line with   
Code: [Select]
return $t[1]; to 
Code: [Select]
return (float) $t[1];
It could result in problems at some other place, so if this is the only warning, change your line 491 from
Code: [Select]
if ( (strip_units($avgspd) + strip_units($gstspd) < 0.1 ) and to
Code: [Select]
if ( ( (float) strip_units($avgspd) + (float) strip_units($gstspd) < 0.1 ) and
By adding the (float) before a numeric value, PHP will discard all other characters so that only the numeric values is processed.

Wim

Offline zmarfak

  • Contributor
  • ***
  • Posts: 135
    • Matar
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #2 on: July 27, 2018, 01:31:50 AM »
Wim,
thanks for the advice
You are correct, I changed a few months ago to php 7.2.6

I changed the function.
My first impression is that this is ok,  I will keep an eye on the error log following days.
When this is solved I can check for other errors, because this was overwhelming  in the log.
Patrick
Davis Vantage Pro2 with a Meteobridge NANO SD and WL (6.04) on a Intel NUC 
https://www.matar.be

Offline zmarfak

  • Contributor
  • ***
  • Posts: 135
    • Matar
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #3 on: July 27, 2018, 01:42:57 AM »
@Ken or Wim,
What is the best way to make a note in the script, so that I not overwrite it with a next update of the template ?
Now I always use winmerge (http://winmerge.org/ to compare scripts before I update 

Thanks for the advice
Patrick
Davis Vantage Pro2 with a Meteobridge NANO SD and WL (6.04) on a Intel NUC 
https://www.matar.be

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #4 on: August 04, 2018, 11:50:27 AM »
I'm neither of those two experts but this is one way to do it:

Change this :

Code: [Select]
return (float) $t[1];
to this:

Code: [Select]
return (float) $t[1]; //Comments go here
and this:

Code: [Select]
if ( ( (float) strip_units($avgspd) + (float) strip_units($gstspd) < 0.1 ) and
to this:

Code: [Select]
if ( ( (float) strip_units($avgspd) + (float) strip_units($gstspd) < 0.1 ) and //Comments go here

Offline zmarfak

  • Contributor
  • ***
  • Posts: 135
    • Matar
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #5 on: August 05, 2018, 09:19:52 AM »
Thanks tmabell for the suggestion.
I'm afraid my question wasn't specific enough.

With the parameter :
Code: [Select]
check-fetch-times.php?show=versions you can see what version you're on
So you can download the corrected templates.
It would be nice to see already in this list if I can overwrite it without checking the content (is this a bad idea?) or that I have to use winmerge to check the files.

I would think to change  the comment in the "version" line
Code: [Select]
$ADBversion = 'ajax-dashboard.php - Version 1.26 - 12-Jan-2013 - Multilingual';but is this a good idea or not ?


 
Patrick
Davis Vantage Pro2 with a Meteobridge NANO SD and WL (6.04) on a Intel NUC 
https://www.matar.be

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #6 on: August 05, 2018, 09:27:49 AM »
To me personally, I think comparing files before overwriting them is always the best approach.  I use "Compare It!"

Offline gwwilk

  • Southeast Lincoln Weather
  • Forecaster
  • *****
  • Posts: 2578
    • SouthEast Lincoln, NE Weather
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #7 on: August 05, 2018, 09:33:29 AM »
To me personally, I think comparing files before overwriting them is always the best approach.  I use "Compare It!"
+1 for 'Compare It!' which is commercial software but well worth it.  It also helps to leave some notes in original files if something needs to be there that isn't in the new file.
Regards, Jerry Wilkins
gwwilk@gmail.com

Offline ConligWX

  • Forecaster
  • *****
  • Posts: 840
  • #conligwx
    • conligwx.org
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #8 on: August 05, 2018, 11:16:28 AM »
Personally I use Notepad++ and the Compare extension, which is free for any changes to source code. ;)
Regards Simon
Davis Vantage Pro2 Plus (6162UK) • Daytime FARS • WeatherLink Live • AirLink • PurpleAir PA-II-SD • CumulusMX •


Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #9 on: August 05, 2018, 11:48:48 AM »
I'm an old Unix hacker, so I use "diff"  :grin:

I keep all of the Saratoga file versions and when something new comes along, I diff ("-w"; ignore whitespace) between the new and the previous Saratoga files and apply those changes to my file - if still applicable.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline zmarfak

  • Contributor
  • ***
  • Posts: 135
    • Matar
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #10 on: August 05, 2018, 12:15:45 PM »
Ok guys,
message came over, keep comparing anyhow to be safe
normally I use Winmerge but the compare tool with notepad++ seems nice also

Thanks
Patrick
Davis Vantage Pro2 with a Meteobridge NANO SD and WL (6.04) on a Intel NUC 
https://www.matar.be

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #11 on: August 05, 2018, 04:35:03 PM »
So, how to update.. the last (and enduring question).

If you use the update tool page to get the Template updates, a handy text file is included in the .zip with my estimation on how you should handle the replacement.  It assumes you don't modify any of the support scripts and do your customization in Settings.php/Settings-weather.php for all localization (except for wx...php pages that require some extra customization).

If you modify the support scripts, then using compare (of many flavors) is your best bet to incorporate my changes into your changes.  If there's a major update to a script, it's probably best to refit your mods to the new script than trying to update the old script with the major changes.
Personally, I use UltraCompare Professional (V18) from https://www.ultraedit.com/products/ultracompare/ for my diffs...
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline zmarfak

  • Contributor
  • ***
  • Posts: 135
    • Matar
Re: error in ajax-dashboard.php (Saratoga template)
« Reply #12 on: August 06, 2018, 04:42:39 AM »
Ken,
the creation of the zip file I find super handy.
Thanks for the tip how to handle the major changes.
Patrick
Davis Vantage Pro2 with a Meteobridge NANO SD and WL (6.04) on a Intel NUC 
https://www.matar.be