Skip to Content
It is currently October 23rd, 2019, 11:21 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: October 5th, 2019, 5:30 pm 
Offline
New User
New User

Joined: October 3rd, 2019, 1:36 am
Posts: 9
I edited the coming, playing and recent php pages to show album art for types S, A, N & V.

However, some of these audios have no album art and when they play the default (type S) album image shows.

What would a PHP code look like to differentiate audio type and display different default album art based on type?
My PHP is a bit rusty... does the logic go kind of like this?

If song has picture, display it.
else If empty picture and song type A display defaultads.jpg
else If empty picture and song type N display defaultnews.jpg
else If empty picture and song type V display defaultinterviews.jpg
else display default.jpg (this will display for type S and any other type)

Am I close with how to format this? And if so, how would the php look like?

I imagine the file class.song.php is the one to edit? I only see the following in around line 367:
Code:
   protected function set_picture($song) {
      $picture = PICTURE_URL_NA;
      if (!empty($song['PICTURE'])) {
         $picture = PICTURE_URL . $song['PICTURE'];
         $this->haspicture = true;
      }

      $this->picture = $picture;
   }


No idea how to make this happen. :(

Any reply to guide me in the right direction is most appreciated. :roll:

Thank you.


Top
 Profile  
Reply with quote  
PostPosted: October 7th, 2019, 8:46 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7878
Location: Aachen (Germany)
The problem with your logic is that it's for handling a fallback case when there's no picture.

The SAM logic does it the other way around and always sets the default picture, but will then overwrite it with whatever it could find in the database if anything.


You already found the right place, though: The set_picture function is called from setValues by making use of "variable variables". (i.e.: They call set_picture by setting the $method variable to set_picture and then calling $this->$method)

You can either turn the default logic upside down completely or just add a conditional switch to define the default case, but keep the "overwrite if not empty" logic (Here's an example for the latter - I'm not sure if SONGTYPE is right and not sure if you can just use filenames or need to add the URL prefix here. It's been a while since I last worked with the web templates due to switching jobs and no longer working with PHP on a daily basis)
Code:
      switch ($song['SONGTYPE']) {
        case 'A':
          $picture = 'defaultads.jpg';
          break;
        case 'N':
          $picture = 'defaultnews.jpg';
          break;
        case 'V':
          $picture = 'defaultinterviews.jpg';
          break;
        default:
          $picture = 'default.jpg';
          break;
      }

      if (!empty($song['PICTURE'])) {
         $picture = PICTURE_URL . $song['PICTURE'];
         $this->haspicture = true;
      }

      $this->picture = $picture;

_________________
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: October 11th, 2019, 10:02 am 
Offline
New User
New User

Joined: October 3rd, 2019, 1:36 am
Posts: 9
Mastacheata wrote:
The problem with your logic is that it's for handling a fallback case when there's no picture.

The SAM logic does it the other way around and always sets the default picture, but will then overwrite it with whatever it could find in the database if anything.


Thank you for that clarification!
I got it working by editing two files and of course by adding the JPG images into the pictures directory...

The config.php file:
Code:
/*
PICTURE_NA
   Use this picture for audios of songtype S (songs) with no picture.
   To disable the use of a default picture set value to empty string.
 */
define('PICTURE_URL_NA', PICTURE_URL.'default.jpg');
/*
PICTURE_A
   Use this picture for audios of songtype A (advertisements) with no picture.
 */
define('PICTURE_URL_A', PICTURE_URL.'defaultads.jpg');
/*
PICTURE_N
   Use this picture for audios of songtype N (news) with no picture.
 */
define('PICTURE_URL_N', PICTURE_URL.'defaultnews.jpg');
/*
PICTURE_V
   Use this picture for audios of songtype V (interviews) with no picture.
 */
define('PICTURE_URL_V', PICTURE_URL.'defaultinterviews.jpg');


Then I edited the set_picture function in class.song.php file to this:
Code:
   protected function set_picture($song) {
      switch ($song['SONGTYPE']) {
        case 'A':
          $picture = PICTURE_URL_A;
          break;
        case 'N':
          $picture = PICTURE_URL_N;
          break;
        case 'V':
          $picture = PICTURE_URL_V;
          break;
        default:
          $picture = PICTURE_URL_NA;
          break;
      }
      if (!empty($song['PICTURE'])) {
         $picture = PICTURE_URL . $song['PICTURE'];
         $this->haspicture = true;
      }

      $this->picture = $picture;
   }


Thank you.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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