Skip to Content
It is currently December 10th, 2023, 6:05 pm

All times are UTC - 6 hours [ DST ]




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

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (Germany)
Click here to get to the PHP8 update

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):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
                <?php if (isset($currentSong) && $currentSong->listeners > 0): ?>

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', '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):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', '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:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', '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:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
                $siblings = GetChildren($vals, ++$i);

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
                $i = $i + 1;
                $siblings = GetChildren($vals, $i);

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

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

Great investigative work.

Will you be able to post these files?


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

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (Germany)
tjoebgen (!empty($user->lang['WROTE'])) ? $user->lang['WROTE'] : ucwords(strtolower(str_replace('_', ' ', 'WROTE'))):
Will you be able to post these files?

Here you go:
(!empty($user->lang['ATTACHMENT'])) ? $user->lang['ATTACHMENT'] : ucwords(strtolower(str_replace('_', ' ', 'ATTACHMENT'))):
File comment: Changes as outlined above
update.zip [11.26 KiB]
Downloaded 911 times

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (Germany)
This one isn't actually reachable from the template code, so fixing it is completely optional.
Change library/common/form.php (Line 291):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while ($row = mysql_fetch_array($res)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', '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):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($a)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach($a as $key => $value) 


Change library/common/form.php (Line 22):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($in)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach($in as $key => $value) 


Change library/common/form.php (Line 72):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($data)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach($data as $key => $value) 


Change library/common/form.php (Line 144):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($req)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach($req as $key => $value) 


Change library/common/form.php (Line 185):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($form)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach($form as $key => $value) 


Change code/code.playlist.php (Line 26) from:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $val) = each($temp)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach ($temp as $key => $val) 


Same procedure in the XML parser:
Change library/Common/xml.php (Line 78) from:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($data)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach ($data as $key => $value) 


Change library/Common/xml.php (Line 161) from:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($data)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach ($data as $key => $value) 


Change library/Common/xml.php (Line 176) from:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($data)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach ($data as $key => $value) 


Change library/Common/xml.php (Line 222) from:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($a)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach ($a as $key => $value) 


Change library/Common/xml.php (Line 239) from:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    while (list($key, $value) = each($data)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
    foreach ($data as $key => $value) 


And one last time while to foreach refactoring.
Change code/classes/class.song.php (Line 181):
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
            while (list($key, $val) = each($search_words)) 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
            foreach ($search_words as $key => $val) 

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

Joined: January 1st, 2009, 8:50 pm
Posts: 147
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  
 
PostPosted: March 30th, 2018, 5:44 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (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:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
<?php

try 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
<?php
ini_set
('error_reporting', E_ALL);
display_errors(true);
try 


(!empty($user->lang['ATTACHMENT'])) ? $user->lang['ATTACHMENT'] : ucwords(strtolower(str_replace('_', ' ', '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 802 times

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (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)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

Joined: January 1st, 2009, 8:50 pm
Posts: 147
Mastacheata (!empty($user->lang['WROTE'])) ? $user->lang['WROTE'] : ucwords(strtolower(str_replace('_', ' ', '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:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
<?php

try 

To:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', '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.

(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', '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  
 
PostPosted: April 29th, 2018, 6:15 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (Germany)
tjoebgen (!empty($user->lang['WROTE'])) ? $user->lang['WROTE'] : ucwords(strtolower(str_replace('_', ' ', '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 (!empty($user->lang['WROTE'])) ? $user->lang['WROTE'] : ucwords(strtolower(str_replace('_', ' ', '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.

(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
<?php
ini_set
('display_errors''true');
error_reporting(E_ALL);
try {  

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

Joined: September 24th, 2007, 2:01 pm
Posts: 198
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

(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', '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  
 
PostPosted: November 26th, 2018, 9:24 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (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)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

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


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

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (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)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


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

Joined: September 24th, 2007, 2:01 pm
Posts: 198
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  
 
PostPosted: November 29th, 2018, 3:52 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (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)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

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


Top
 Profile  
 
Display posts from previous:  Sort by  
 [ 46 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 8 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:  
Powered by phpBB® Forum Software © phpBB Group