Skip to Content
It is currently January 25th, 2020, 6:46 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: March 26th, 2018, 4:30 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
These changes should make samPHPweb work with more recent PHP versions than PHP 5.5 (Tested up to PHP7.2)

There's an edge case where the $currentSong variable might be set, but empty and has no properties and thus the first check isn't enough.
Change display/display.header.php (Line 50):
Code:
                <?php if (isset($currentSong) && $currentSong->listeners > 0): ?>

To:
Code:
                <?php if (!empty($currentSong) && $currentSong->listeners > 0): ?>


In the form helper library remove the leading zeroes in the days array (leading 0 indicates an octal number, but there are no 8 and 9 digits in the octal system).
Change library/comon/form.php (Lines 43-55):
Code:
    $m = (int) $m;
    $days[01] = 31;
    $days[02] = 28;
    $days[03] = 31;
    $days[04] = 30;
    $days[05] = 31;
    $days[06] = 30;
    $days[07] = 31;
    $days[08] = 31;
    $days[09] = 30;
    $days[10] = 31;
    $days[11] = 30;
    $days[12] = 31

To:
Code:
    $m = (int) $m;
    $days[ 1] = 31;
    $days[ 2] = 28;
    $days[ 3] = 31;
    $days[ 4] = 30;
    $days[ 5] = 31;
    $days[ 6] = 30;
    $days[ 7] = 31;
    $days[ 8] = 31;
    $days[ 9] = 30;
    $days[10] = 31;
    $days[11] = 30;
    $days[12] = 31


Modify the XML parsing code to no longer inline-modify a value that is passed by reference.
Change library/common/xml.php (Line 25) from:
Code:
                $siblings = GetChildren($vals, ++$i); 

To:
Code:
                $i = $i + 1;
                $siblings = GetChildren($vals, $i); 

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: March 28th, 2018, 7:03 am 
Offline
Senior User
Senior User

Joined: January 1st, 2009, 8:50 pm
Posts: 137
We bow to the Masta!

Great investigative work.

Will you be able to post these files?


Top
 Profile  
Reply with quote  
PostPosted: March 28th, 2018, 5:25 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
tjoebgen wrote:
Will you be able to post these files?

Here you go:
Attachment:
File comment: Changes as outlined above
update.zip [11.26 KiB]
Downloaded 197 times

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
 Post subject: Optional changes
PostPosted: March 28th, 2018, 5:41 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
This one isn't actually reachable from the template code, so fixing it is completely optional.
Change library/common/form.php (Line 291):
Code:
    while ($row = mysql_fetch_array($res)) 

To:
Code:
    while ($row = mysqli_fetch_array($res)) 


As far as I can tell all the while to foreach conversions are merely cosmetic. I just stumbled upon that strange notation due to similar problems in another project. The while, list, each combo will keep working for arrays, but fails when the variable inside each is actually a traversable object or string. In those cases foreach will properly iterate the items where each will not. If I'm not mistaken all these instances listed here only handle arrays and will continue working unchanged in the future.

Change library/common/form.php (Line 10):
Code:
    while (list($key, $value) = each($a)) 

To:
Code:
    foreach($a as $key => $value) 


Change library/common/form.php (Line 22):
Code:
    while (list($key, $value) = each($in)) 

To:
Code:
    foreach($in as $key => $value) 


Change library/common/form.php (Line 72):
Code:
    while (list($key, $value) = each($data)) 

To:
Code:
    foreach($data as $key => $value) 


Change library/common/form.php (Line 144):
Code:
    while (list($key, $value) = each($req)) 

To:
Code:
    foreach($req as $key => $value) 


Change library/common/form.php (Line 185):
Code:
    while (list($key, $value) = each($form)) 

To:
Code:
    foreach($form as $key => $value) 


Change code/code.playlist.php (Line 26) from:
Code:
    while (list($key, $val) = each($temp)) 

To:
Code:
    foreach ($temp as $key => $val) 


Same procedure in the XML parser:
Change library/Common/xml.php (Line 78) from:
Code:
    while (list($key, $value) = each($data)) 

To:
Code:
    foreach ($data as $key => $value) 


Change library/Common/xml.php (Line 161) from:
Code:
    while (list($key, $value) = each($data)) 

To:
Code:
    foreach ($data as $key => $value) 


Change library/Common/xml.php (Line 176) from:
Code:
    while (list($key, $value) = each($data)) 

To:
Code:
    foreach ($data as $key => $value) 


Change library/Common/xml.php (Line 222) from:
Code:
    while (list($key, $value) = each($a)) 

To:
Code:
    foreach ($a as $key => $value) 


Change library/Common/xml.php (Line 239) from:
Code:
    while (list($key, $value) = each($data)) 

To:
Code:
    foreach ($data as $key => $value) 


And one last time while to foreach refactoring.
Change code/classes/class.song.php (Line 181):
Code:
            while (list($key, $val) = each($search_words)) 

To:
Code:
            foreach ($search_words as $key => $val) 

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: March 29th, 2018, 5:50 am 
Offline
Senior User
Senior User

Joined: January 1st, 2009, 8:50 pm
Posts: 137
Thank you, Mastacheata.

Unfortunately, this didn't solve the problem I have with playing.php always displaying a blank page (with the browser loading forever) - regardless of the php version.

So, for now I'm using the old php script for queue and history display, and using the new script for playlist (requests). These work in all 5.x versions.


Top
 Profile  
Reply with quote  
PostPosted: March 30th, 2018, 5:44 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
If it shows a blank page, there's a PHP error, but your webserver is set to not disclose errors to the website visitors.
Usually there's a Log area in your webhosts control panel or you can access the log files directly through your FTP access.
If you manage to find the logs and tell me what they say, I'll most likely be able to tell you what's the problem.

Otherwise as a temporary "fix" you can explicitly enable error displaying in the web/playing.php:
Change:
Code:
<?php

try 

To:
Code:
<?php
ini_set
('error_reporting', E_ALL);
display_errors(true);
try 


Attachment:
File comment: Rename to playing.php and replace the web/playing.php if you're uncomfortable with performing the changes above by hand
playing.php.txt [482 Bytes]
Downloaded 149 times

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: April 11th, 2018, 5:32 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
The non-optional fixes are now part of the standard distribution of SAM Broadcaster (as of SAM Broadcaster 2018.3).
Thanks a lot for the immediate reaction.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: April 28th, 2018, 10:27 am 
Offline
Senior User
Senior User

Joined: January 1st, 2009, 8:50 pm
Posts: 137
Mastacheata wrote:
If it shows a blank page, there's a PHP error, but your webserver is set to not disclose errors to the website visitors.
Usually there's a Log area in your webhosts control panel or you can access the log files directly through your FTP access.
If you manage to find the logs and tell me what they say, I'll most likely be able to tell you what's the problem.


Are you referring to the server logs? I downloaded them but they just show file access events, not errors. So I looked in each folder under samPHPweb and no new error_log files exist (I cleared the old ones after I made the final php version change to 5.6 earlier this month).


[quote="Mastacheata"]Otherwise as a temporary "fix" you can explicitly enable error displaying in the web/playing.php:
Change:
Code:
<?php

try 

To:
Code:
<?php
ini_set
('error_reporting', E_ALL);
display_errors(true);
try 


I added the code to playing.php. Now when I load samPHPweb/index.php, it doesn't endlessly load, it stops as if the page is done - but it is blank. It created a new error_log file, but the error is about a call to undefined function.

[28-Apr-2018 11:56:44 America/Detroit] PHP Fatal error: Call to undefined function display_errors() in /home/.../samPHPweb/web/playing.php on line 3



This is my modified playing.php.

Code:
<?php
ini_set('error_reporting', E_ALL);
display_errors(true);

try {
   // Get the configuration
   require_once('../config/config.php');

   // Get the code for this page
   require_once('../code/code.playing.php');

   // Get the display for this page
   require_once('../display/display.playing.php');

} catch (Exception $ex) {
   // The error page will be displayed if anything goes wrong above
   var_dump($ex);
   $message = $ex->getMessage();
   require_once('../display/display.error.php');
}


Top
 Profile  
Reply with quote  
PostPosted: April 29th, 2018, 6:15 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
tjoebgen wrote:
Are you referring to the server logs? I downloaded them but they just show file access events, not errors. So I looked in each folder under samPHPweb and no new error_log files exist (I cleared the old ones after I made the final php version change to 5.6 earlier this month).

Usually you have 2 kinds of logs: The Access Log and the Error Log.

tjoebgen wrote:
I added the code to playing.php. Now when I load samPHPweb/index.php, it doesn't endlessly load, it stops as if the page is done - but it is blank. It created a new error_log file, but the error is about a call to undefined function.

Sorry my fault. I mixed up display_errors and error_reporting.

Code:
<?php
ini_set
('display_errors''true');
error_reporting(E_ALL);
try {  

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: November 25th, 2018, 8:57 pm 
Offline
Senior User
Senior User

Joined: September 24th, 2007, 2:01 pm
Posts: 182
I am working through the changes above, but still have one error showing. I have changed the file on line 239 as instructed, but still this error shows.


Deprecated: The each() function is deprecated. This message will be suppressed on further calls in C:\wamp64\www\library\Common\xml.php on line 239
Call Stack
# Time Memory Function Location
1 0.0002 404080 {main}( ) ...\playing.php:0
2 0.0003 404448 require_once( 'C:\wamp64\www\config\config.php' ) ...\playing.php:5
3 0.0006 406288 Database::getInstance( ) ...\config.php:150
4 0.0007 406288 Database::InitFromXMLConfig( ) ...\Database.php:41
5 0.0015 407880 EmptyNodeCleanUp( ) ...\Database.php:71
6 0.0015 407880 each ( ) ...\xml.php:239


My editor seems to be highlighting two errors in this code

Code:
function EmptyNodeCleanUp(&$data) {         (THE & IN THIS LINE)
   while (list($key, $val) = each($data)) {      
   if (is_array($val)) {
         $data[$key] = "";
      }
   }// while loop
}

function echoXML($xml) {
   XMLheader();

   if (is_array($xml)) {
      echo Array2XML($xml);
   } else {
      echo $xml;
   }
}

?>      (AND THE > IN THIS ONE)


But when I change the code to

function EmptyNodeCleanUp(&$data) {     THE & STILL SHOWS AS AN ERROR
   foreach ($data as $key => $value) {       THE > NOW SHOWS AS AN ERROR
   if (is_array($val)) {
         $data[$key] = "";
      }
   }// while loop
}

function echoXML($xml) {
   XMLheader();

   if (is_array($xml)) {
      echo Array2XML($xml);
   } else {
      echo $xml;
   }
}

?>    AND THE > STILL SHOWS AS AN ERROR


Top
 Profile  
Reply with quote  
PostPosted: November 26th, 2018, 9:24 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
each() has only been deprecated recently in PHP7.2 and is probably not gonna go away until PHP8, so it doesn't have any effect on the code working or not. It's just showing up as a warning, that this might stop working in the future.

It's usually a good idea to log such complaints, but don't show them in a production system. (display_errors should be off on all production websites)

No idea why your editor complains about the foreach. I don't see what might cause a misinterpretation here.
This is the official manual and the description of the foreach control structure: http://php.net/manual/de/control-structures.foreach.php

Passing function parameters by reference (prepending the argument declaration with an ampersand) is bad coding style and obviously discouraged, but it's news to me that this would be an error PHP complains about itself.

Closing a file with ?> is optional, but hasn't been deprecated as far as I know. It's discouraged because you need to be super careful to not have any whitespace after the closing PHP tag. You can leave that away if it's only used to mark the end of your file.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: November 26th, 2018, 10:54 am 
Offline
Senior User
Senior User

Joined: September 24th, 2007, 2:01 pm
Posts: 182
Oh, so switching off display errors was enough to fix it! Thank you


Top
 Profile  
Reply with quote  
PostPosted: November 26th, 2018, 12:06 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
You should probably fix the while each, though as there will be a date when that functionality is gone and things will stop working.
display_errors is really just about showing the errors to the visitors of your site. Just because you can't see the error anymore, doesn't mean it's gone.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: November 29th, 2018, 8:17 am 
Offline
Senior User
Senior User

Joined: September 24th, 2007, 2:01 pm
Posts: 182
I totally agree, but unfortunately I have absolutely no idea where to start to fix it. I have already made all the changes specified above. I am just copying and pasting. I have no real understanding of it.


Top
 Profile  
Reply with quote  
PostPosted: November 29th, 2018, 3:52 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7903
Location: Aachen (Germany)
Ohh, sorry. I assumed you got at least some experience with PHP as you were brave enough to dig in the php.ini config file and find the display_errors switch. Most people with little or no IT knowledge would immediately make a step backwards when they encounter a huge text based config file like the php.ini :D

If you changed the one last while ( each ) snippet that you missed in the first place, you should be fine. The rest is just cosmetics, but definitely not forbidden or going away anytime soon.
The next easiest thing on the list of cosmetic changes is removing the ?> at the very last line of every .php file. (just make sure to only remove it if it's in the very last line. If you see that somewhere in the middle of a file there's usually a very good reason for it being there.)
But again, that's a completely cosmetic/usability change/

The problem with the closing PHP tag is a bit complicated:
A PHP file is valid if you put text, text + whitespace or nothing after the closing PHP tag.
A PHP file will inevitably fail (and any file referencing it will fail too) when there is only whitespace after the closing PHP tag (?>).

The closing PHP tag is completely optional though: A PHP file will automatically end with the end of the file anywas, so if you're not gonna put anything after the closing tag it's completely redundant to put it there.
That's why it's considered bad style to include a closing PHP tag these days.

The SAM files are built in a way that this shouldn't matter, but there's always a risk that you might break something by accident when editing the files.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group