We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4192
    • 43 Posts
    OK - I have found the culprit: I was using an extended version of the same PHP script, and I loaded it as a separate snippet with a different name. When I deleted that second snipped, the first one started back to correctly show updated icons and data.
    But I still have a problem: as I’d like to use the "extended" PHP script inside a separate page, how can I use it without interfering with the first snippet? Just in case, below is the "extended" script I’m working on:

    // Adaptation by Diego Meozzi of a php script originally developed by I Ketut Sukandia (www.balidwipa.com and www.nusa-penida.com)
    
    if (!$accid) {
    	$accid="ITXX0056"; # Your default city location code, please change to your city ACCID code.
    }
    
    if (!$tp) {
    	$tp=C; # Your Default temperature unit (C for Celsius, F for Fahrenheit)
    }
    
    # Fonts Setting
    ################
    $fontface="\"Trebuchet MS\", Verdana, Arial, Sans-Serif";
    $fontcolor1="#000000";
    $fontcolor2="red";
    $fontsize1="1";
    $fontsize2="3";
    $fontsize3="4";
    
    //-- define output
    $output='';
    
    $url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";
    
    $fa = fopen($url,"r");
    		
      $v_City    = "";
      $v_SubDiv  = "";
      $v_Country = "";
      $v_Region  = "";
      $v_Temp    = "";
      $v_CIcon   = "";
      $v_WindS   = "";
      $v_WindD   = "";
      $v_Baro    = "";
      $v_Humid   = "";
      $v_Real    = "";
      $v_UV      = "";
      $v_Vis     = "";
      $v_LastUp  = "";
      $v_Fore    = "";
      $v_Acid    = "";
      $v_ConText = "";
    
    $v_Text[] = "Dati non disponibili";
    $v_Text[1] = "Pioggia e vento";
    $v_Text[3] = "Pioggia e temporali";
    $v_Text[4] = "Temporali";
    $v_Text[5] = "Coperto";
    $v_Text[6] = "";
    $v_Text[7] = "Neve e gelo";
    $v_Text[8] = "";
    $v_Text[9] = "";
    $v_Text[10] = "";
    $v_Text[11] = "Piovaschi";
    $v_Text[12] = "Pioggia";
    $v_Text[13] = "Scattered Flurreis";
    $v_Text[14] = "Nevicata leggera";
    $v_Text[15] = "";
    $v_Text[16] = "";
    $v_Text[17] = "";
    $v_Text[18] = "";
    $v_Text[19] = "Polvere";
    $v_Text[20] = "Nebbia";
    $v_Text[21] = "Foschia";
    $v_Text[22] = "Fumo";
    $v_Text[23] = "Vento";
    $v_Text[24] = "Coperto con vento";
    $v_Text[25] = "Freddo estremo";
    $v_Text[26] = "Nuvoloso";
    $v_Text[27] = "Molto nuvoloso";
    $v_Text[28] = "Molto nuvoloso";
    $v_Text[29] = "Parzialmente nuvoloso";
    $v_Text[30] = "Parzialmente nuvoloso";
    $v_Text[31] = "Parzialmente nuvoloso";
    $v_Text[32] = "Sereno";
    $v_Text[33] = "Sereno";
    $v_Text[34] = "Poco nuvoloso";
    $v_Text[35] = "";
    $v_Text[36] = "Caldo estremo";
    $v_Text[37] = "Temporali isolati";
    $v_Text[38] = "Temporali sparsi";
    $v_Text[39] = "Rovesci";
    $v_Text[40] = "Rovesci";
    $v_Text[41] = "Neve";
    $v_Text[41] = "Vento leggero";
    $v_Text[43] = "Neve e vento";
    $v_Text[44] = "Parzialmente nuvoloso";
    
    
    
      while (!feof($fa))
         {
         $grabline = fgets($fa, 4096);
         $grabline= trim($grabline) . "\n";
         if (substr($grabline,7,4) == "City")    { $v_City    = substr($grabline,15,20); }
         if (substr($grabline,7,6) == "SubDiv")  { $v_SubDiv  = substr($grabline,17,20); }
         if (substr($grabline,7,7) == "Country") { $v_Country = substr($grabline,18,20); }
         if (substr($grabline,7,6) == "Region")  { $v_Region  = substr($grabline,17,20); }
         if (substr($grabline,7,5) == "Temp ")    { $v_Temp    = substr($grabline,15,20); }
         if (substr($grabline,7,5) == "CIcon")   { $v_CIcon   = substr($grabline,16,20); }
         if (substr($grabline,7,5) == "WindS")   { $v_WindS   = substr($grabline,16,20); }
         if (substr($grabline,7,5) == "WindD")   { $v_WindD   = substr($grabline,16,20); }
         if (substr($grabline,7,4) == "Baro")    { $v_Baro    = substr($grabline,15,20); }
         if (substr($grabline,7,5) == "Humid")   { $v_Humid   = substr($grabline,16,20); }
         if (substr($grabline,7,4) == "Real")    { $v_Real    = substr($grabline,15,20); }
         if (substr($grabline,7,2) == "UV")      { $v_UV      = substr($grabline,13,20); }
         if (substr($grabline,7,3) == "Vis")     { $v_Vis     = substr($grabline,14,20); }
         if (substr($grabline,7,6) == "LastUp")  { $v_LastUp  = substr($grabline,17,200); }
         if (substr($grabline,7,7) == "ConText") { $v_ConText = substr($grabline,16,20); } 
    
    
         if (substr($grabline,7,4) == "Fore")    { $v_Fore    = substr($grabline,15,200); }
         if (substr($grabline,7,4) == "Acid")    { $v_Acid    = substr($grabline,15,20); }
    //     print $grabline . "\n";
         }
    
      $v_City    = substr($v_City,0,strlen($v_City)-3);
      $v_SubDiv  = substr($v_SubDiv,0,strlen($v_SubDiv)-3);
      $v_Country = substr($v_Country,0,strlen($v_Country)-3);
      $v_Region  = substr($v_Region,0,strlen($v_Region)-3);
      $v_Temp    = substr($v_Temp,0,strlen($v_Temp)-3);
      $v_CIcon   = substr($v_CIcon,0,strlen($v_CIcon)-3);
      $v_WindS   = substr($v_WindS,0,strlen($v_WindS)-3);
      $v_WindD   = substr($v_WindD,0,strlen($v_WindD)-3);
      $v_Baro    = substr($v_Baro,0,strlen($v_Baro)-3);
      $v_Humid   = substr($v_Humid,0,strlen($v_Humid)-3);
      $v_Real    = substr($v_Real,0,strlen($v_Real)-3);
      $v_UV      = substr($v_UV,0,strlen($v_UV)-3);
      $v_Vis     = substr($v_Vis,0,strlen($v_Vis)-3);
      $v_LastUp  = substr($v_LastUp,0,strlen($v_LastUp)-3);
      $v_Fore    = substr($v_Fore,0,strlen($v_Fore)-3);
      $v_Acid    = substr($v_Acid,0,strlen($v_Acid)-3);
    
    
    $v_Fore = explode("|", $v_Fore);
    
    $output.= "<h4>Condizioni attuali:</h4><div class=\"table\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>";
    
    $output.= "<td align=\"center\">";
    $output.= "<img src=\"http://www.trevignanoromano.it/i/".$v_CIcon . ".gif\" align=\"absmiddle\"><br>";
    $output.= "<b> ".$v_Text[$v_CIcon]." </b>";
    
    $output.= "</b></td><td>     </td><td><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>";
    
    $v_Baro_nice = PreNumber($v_Baro, $tp);
    $v_WindS_nice = VelNumber($v_WindS, $tp);
    $v_Real_nice = CelNumber2($v_Real, $tp);
    $v_Vis_nice = LenNumber($v_Vis, $tp);
    
    $output.= "<font color=\"navy\">Temperatura percepita: </font></td><td><font><b>$v_Real_nice</b></td>";
    $output.= "<td>   </td><td><font color=\"navy\">Indice UV: </font></td><td><font><b>$v_UV/16</b></td></tr><tr>";
    $output.= "<td><font color=\"navy\">Umidità:</font></td><td><font><b>$v_Humid%</b></td>";
    $output.= "<td>   </td><td><font color=\"navy\">Vento:</font></td><td><font ><b>$v_WindS_nice da $v_WindD</b></td></tr><tr>";
    $output.= "<td><font color=\"navy\">Visibilità:</font></td><td><font><b>$v_Vis_nice</b></td>";
    $output.= "<td>   </td><td><font color=\"navy\">Pressione: </font></td><td><font><b>$v_Baro_nice</b></td>";
    
    $output.= "</tr></table></td></tr></table></div><hr size=1 noshade color=#999999><h4>Previsioni per 5 giorni:</h4><table cellpadding=\"4\" cellspacing=\"0\" border=\"0\"><tr><td align=center><font size=\"1\"><b>";
    
    $output.= Fore($v_Fore[0]);
    if ($tp == "C") {
    $output.= "</b></font><br><font size=\"1\" color=\"red\">Max: ";
    $output.= CelNumber($v_Fore[20]);
    $output.= "</font><br><font size=\"1\" color=\"navy\">Min: ";
    $output.= CelNumber($v_Fore[40]);
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    } else if ($tp=="F") {
    $output.= "</b><br><font size=\"1\" color=\"red\">Hi: ";
    $output.= "$v_Fore[20]°F";
    $output.= "</font><br><font size=\"1\" color=\"navy\">Lo: ";
    $output.= "$v_Fore[40]°F";
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    }
    
    $output.= Fore($v_Fore[1]);
    if ($tp == "C") {
    $output.= "</b></font><br><font size=\"1\" color=\"red\">Max: ";
    $output.= CelNumber($v_Fore[21]);
    $output.= "</font><br><font size=\"1\" color=\"navy\">Min: ";
    $output.= CelNumber($v_Fore[41]);
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    } else if ($tp=="F") {
    $output.= "</b><br><font size=\"1\" color=\"red\">Hi: ";
    $output.= "$v_Fore[21]°F";
    $output.= "</font><br><font size=\"1\" color=\"navy\">Lo: ";
    $output.= "$v_Fore[41]°F";
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    }
    
    $output.= Fore($v_Fore[2]);
    if ($tp == "C") {
    $output.= "</b></font><br><font size=\"1\" color=\"red\">Max: ";
    $output.= CelNumber($v_Fore[22]);
    $output.= "</font><br><font size=\"1\" color=\"navy\">Min: ";
    $output.= CelNumber($v_Fore[42]);
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    } else if ($tp=="F") {
    $output.= "</b><br><font size=\"1\" color=\"red\">Hi: ";
    $output.= "$v_Fore[22]°F";
    $output.= "</font><br><font size=\"1\" color=\"navy\">Lo: ";
    $output.= "$v_Fore[42]°F";
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    }
    
    $output.= Fore($v_Fore[3]);
    if ($tp == "C") {
    $output.= "</b></font><br><font size=\"1\" color=\"red\">Max: ";
    $output.= CelNumber($v_Fore[23]);
    $output.= "</font><br><font size=\"1\" color=\"navy\">Min: ";
    $output.= CelNumber($v_Fore[43]);
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    } else if ($tp=="F") {
    $output.= "</b><br><font size=\"1\" color=\"red\">Hi: ";
    $output.= "$v_Fore[23]°F";
    $output.= "</font><br><font size=\"1\" color=\"navy\">Lo: ";
    $output.= "$v_Fore[43]°F";
    $output.= "</font></td><td align=center><font size=\"1\"><b>";
    }
    
    $output.= Fore($v_Fore[4]);
    if ($tp == "C") {
    $output.= "</b></font><br><font size=\"1\" color=\"red\">Max: ";
    $output.= CelNumber($v_Fore[24]);
    $output.= "</font><br><font size=\"1\" color=\"navy\">Min: ";
    $output.= CelNumber($v_Fore[44]);
    $output.= "</font></td></tr><tr>";
    } else if ($tp=="F") {
    $output.= "</b><br><font size=\"1\" color=\"red\">Hi: ";
    $output.= "$v_Fore[24]°F";
    $output.= "</font><br><font size=\"1\" color=\"navy\">Lo: ";
    $output.= "$v_Fore[44]°F";
    $output.= "</font></td></tr><tr>";
    }
    
    $output.= "<td align=center><img src=\"http://www.trevignanoromano.it/i/".$v_Fore[10].".gif\"></td><td align=center>";
    $output.= "<img src=\"http://www.trevignanoromano.it/i/".$v_Fore[11].".gif\"></td><td align=center>";
    $output.= "<img src=\"http://www.trevignanoromano.it/i/".$v_Fore[12].".gif\"></td><td align=center>";
    $output.= "<img src=\"http://www.trevignanoromano.it/i/".$v_Fore[13].".gif\"></td><td align=center>";
    $output.= "<img src=\"http://www.trevignanoromano.it/i/".$v_Fore[14].".gif\"></td></tr><tr>";
    $output.= "<td align=center><font size=\"1\" color=\"black\">".$v_Text[$v_Fore[10]]."</font></td>";
    $output.= "<td align=center><font size=\"1\" color=\"black\">".$v_Text[$v_Fore[11]]."</font></td>";
    $output.= "<td align=center><font size=\"1\" color=\"black\">".$v_Text[$v_Fore[12]]."</font></td>";
    $output.= "<td align=center><font size=\"1\" color=\"black\">".$v_Text[$v_Fore[13]]."</font></td>";
    $output.= "<td align=center><font size=\"1\" color=\"black\">".$v_Text[$v_Fore[14]]."</font></td>";
    
    $output.= "</b></font></tr></table>";
    
    fclose($fa);
    
    return $output;
    
    function CelNumber($number) {
    	$number = $number-32;
    	$number = $number * 5;
    	$number = $number / 9;
    	$number = round ($number);
    	return $number."°C";
    }
        
    function CelNumber2($number,$tp) {
            if ($tp == "C") {                $number = $number-32;
    	        $number = $number * 5;
    	        $number = $number / 9;
    	        $number = round ($number);
    	        return "$number°C";
            }       else {                return "$number°F";       } }
    
    
    function PreNumber($number,$tp) {
    	if ($tp == "C") {
    		$number = $number *33.86;
    		$number = round ($number);
    		return "$number mbar";
    	}
    	else {
    		return "$number inHg";
    	}
    }
    
    function LenNumber($number,$tp) {
    	if ($tp == "C") {
    		$number = $number * 1.852;
    		$number = round ($number);
            if ($number == 0)
            {
                    return "N/A";
            }
            else {
    		return "$number km";
    	}
            }else {
    	 if ($number == 0)
               {
    	return "N/A";
               }
    
    
    	else {
    		return "$number mi";
    	}
    }
       } 
    
    function VelNumber($number,$tp) {
    	if ($tp == "C") {
    		$number = $number * 0.44704;
    		$number = round ($number);
    		return "$number m/s";
    	}
    	else {
    		return "$number mph";
    	}
    }
    
    function Fore($numbers) {
    	if ($numbers == "1") {
    		$date="DOMENICA";
    		echo "$date";
    	}
    	elseif ($numbers == "2") {
    		$date="LUNED&#204";
    		echo "$date";
    	}
    	elseif ($numbers == "3") {
    		$date="MARTED&#204";
    		echo "$date";
    	}
    	elseif ($numbers == "4") {
    		$date="MERCOLED&#204";
    		echo "$date";
    	}
    	elseif ($numbers == "5") {
    		$date="GIOVED&#204";
    		echo "$date";
    	}
    	elseif ($numbers == "6") {
    		$date="VENERDÌ";
    		echo "$date";
    	} else {
    		$date="SABATO";
    		echo "$date";
    	}
    }				
      • 10487 MODX Staff
      • 1,535 Posts
      There’s been issues reported with other snippets where you can’t have more than one version of the snippet running on the page. I’ve not had chance to look into it any further at the moment though.

      Am I right in saying that the extended snippet will provide a page with all the extra weather information on it? If that’s the case, you could make it so that the first snippet isn’t displayed on that page - by using a second template that doesn’t load the first snippet or by using a TV on the same template.

      It’s only an idea, but might help. Anybody else got any suggestions?

      Cheers, Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 4192
        • 43 Posts
        I believe there are still some problems either with the snipped-converted script or with MODx cache, because there is often a difference in the data presented by the PHP page and the page served through MODx. The latter is always somewhat late, and it doesn’t update itself for hours (instead of aboout once per hour).
        And Garryn, comparing the original PHP script with the snippet you converted, I have found these bits are missing:

        function WeatherIndex($tp) {
        global $accid, $tp;
        


        Maybe those are the ones that are causing those strange update delays with the snippet?
          • 10487 MODX Staff
          • 1,535 Posts
          I’m suspecting a caching issue at the moment. How are you calling the snippet? If you are calling it like: [[weather]] then you might want to try [!weather!]

          Other than that, have you got a link to the original downloaded script? That way, I can get more of a picture of what’s going on and can give it a full test with the images etc.

          Thanks, Garry

            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 2762
            • 1,198 Posts
            wow Nice works garry!!

            @Brin bello il sito di Trevignano Romano! grin
              Free MODx Graphic resources and Templates www.tattoocms.it
              -----------------------------------------------------

              MODx IT  www.modx.it
              -----------------------------------------------------

              bubuna.com - Web & Multimedia Design
              • 4192
              • 43 Posts
              Quote from: garryn at Mar 07, 2006, 03:50 AM

              have you got a link to the original downloaded script?
              The original script is called Easyweather 1.15 and you can donwload it from here.
              Quote from: banzai at Mar 07, 2006, 03:56 AM
              bello il sito di Trevignano Romano! grin
              Glad you liked it! As a matter of fact, I simply adapted the default MODx template to a new graphic layout. But now I’ve got some problems with the placement of the breadcrumbs... Are you willing to help me with it? wink
                • 2762
                • 1,198 Posts
                Sure, you can also open a new thread for breadcrumbs, in italian forum if you like grin (i suppose you’re Italian..)
                Ciao
                  Free MODx Graphic resources and Templates www.tattoocms.it
                  -----------------------------------------------------

                  MODx IT  www.modx.it
                  -----------------------------------------------------

                  bubuna.com - Web & Multimedia Design
                  • 4192
                  • 43 Posts
                  OK, I’m almost getting there... The snippet is 90% operative, as you can see here.
                  However, I still can’t make it show the 5 days of the week above the max and min temperatures. Again, for a direct comparison, you may have a look at the working PHP script.
                  The original PHP script used this function:
                  function Fore($numbers) {
                  	if ($numbers == "1") {
                  		$date="DOMENICA";
                  		echo "$date";
                  	}
                  	elseif ($numbers == "2") {
                  		$date="LUNEDÌ";
                  		echo "$date";
                  	}
                  	elseif ($numbers == "3") {
                  		$date="MARTEDÌ";
                  		echo "$date";
                  	}
                  	elseif ($numbers == "4") {
                  		$date="MERCOLEDÌ";
                  		echo "$date";
                  	}
                  	elseif ($numbers == "5") {
                  		$date="GIOVEDÌ";
                  		echo "$date";
                  	}
                  	elseif ($numbers == "6") {
                  		$date="VENERDÌ";
                  		echo "$date";
                  	} else {
                  		$date="SABATO";
                  		echo "$date";
                  	}
                  


                  That is controlled by this line:

                  $v_Fore = explode("|", $v_Fore);

                  and then it is made visible through this line (there are 5 copies of it, each for a single day of the week):

                  $output.= Fore($v_Fore[0]);

                  Now, MODx snippets don’t like echo command, and one must use $output.= command instead. The problem is that even changing the echo command in the Fore($numbers) function, the days of the week are still missing. So, I beileve that also the explode command isn’t recognized correctly by MODx.

                  Is there any PHP expert that could help me with this issue?

                  Thanks a million!
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Echo works fine with snippets, as does explode. I’ve used them both extensively.

                    However, your code has another problem, I would do it this way:

                    function Fore($numbers) {
                    switch($numbers) {
                      case 1:
                        return "DOMENICA";
                        break;
                      case 2:
                        return "LUNEDI";
                        break;
                    ... etc ...
                      default:
                        return "SABATO";
                        break;
                    } // end switch
                    } // end function Fore
                    
                    $output .= Fore($numbers);
                    


                    Because your function does not return anything, the $output variable never gets any values.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 4192
                      • 43 Posts
                      Thank you so much, sottwell! Now the script is working 100% ! I will try to translate back to English, so other MODx users may use it.
                      As a final PHP question, the original script is taking the date and time using the $v_LastUp function, which is grabbed from a text file (that you can find here) using these lines:

                      while (!feof($fa))
                          {
                          $grabline = fgets($fa, 4096);
                          $grabline= trim($grabline) . "\n";
                      if (substr($grabline,7,6) == "LastUp")  { $v_LastUp  = substr($grabline,17,200); }
                      }

                      $v_LastUp  = substr($v_LastUp,0,strlen($v_LastUp)-3);

                      Doing this way, it shows the US time of the latest update of the weather data, with a text string like this:

                      03/09/2006 02:45:00

                      What I would like to do is to convert the date format into the European standard (d/m/y instead of m/d/y) and to add +7 hours to take into account the different time zone.

                      Do you know how can I do it?

                      Thanks again for your great help!