WordPress.org

Forums

Radio Station
Auto-export content of DJ Widget as txt file (2 posts)

  1. paulradiobiz
    Member
    Posted 1 year ago #

    Hello all,

    I'm trying to find a clever way of displaying the content of [dj-widget] in a basic text file on our web server, which automatically updates when a new show comes on.

    Reason.. we'd like to use this output to feed the scrolling text display on DAB digital radio.

    Any ideas very appreciated.

    P

    https://wordpress.org/plugins/radio-station/

  2. Nikki Blight
    Member
    Plugin Author

    Posted 1 year ago #

    Hmm...

    Well, one way to accomplish something like that would be to copy the function that generates the [dj-widget] content into just a plain old .php file in your webroot, and modify it so that it only outputs what you need for your display. Then you could use WGET to access that URL from a cron job on your server to update the file on a regular basis.

    So, for example, you create http://www.mysite.com/nowOn.php:

    $default_name = 'Default DJ Name';
    
    if(file_exists('wp-load.php')) {
    	require('wp-load.php');
    }
    
    //find out which DJ(s) are currently scheduled to be on-air and display them
    $djs = dj_get_current();
    $playlist = myplaylist_get_now_playing();
    
    //begin building the string for output
    $dj_str = '';
    
    //echo the show/dj currently on-air
    if($djs['type'] == 'override') {  //start by checking for schedule overrides
    	$dj_str .= $djs['all'][0]['title'];
    
    	//display the override's schedule
    	if($time == 12) {
    		$dj_str .= '<span class="on-air-dj-sched">'.$djs['all'][0]['sched']['start_hour'].':'.$djs['all'][0]['sched']['start_min'].' '.$djs['all'][0]['sched']['start_meridian'].'-'.$djs['all'][0]['sched']['end_hour'].':'.$djs['all'][0]['sched']['end_min'].' '.$djs['all'][0]['sched']['end_meridian'].'</span><br />';
    	}
    	else {
    		$djs['all'][0]['sched'] = station_convert_schedule_to_24hour($djs['all'][0]['sched']);
    
    		$dj_str .= '<span class="on-air-dj-sched">'.$djs['all'][0]['sched']['start_hour'].':'.$djs['all'][0]['sched']['start_min'].' '.'-'.$djs['all'][0]['sched']['end_hour'].':'.$djs['all'][0]['sched']['end_min'].'</span><br />';
    	}
    }
    else { //no overrides - just display the normal schedule
    	if(isset($djs['all']) && count($djs['all']) > 0) {
    		foreach($djs['all'] as $dj) {
    
    			//show name
    			$dj_str .= $dj->post_title;
    
    			//names of DJs
    			$names = get_post_meta($dj->ID, 'show_user_list', true);
    			$count = 0;
    			if($names) {
    				$dj_str .= ' with ';
    				foreach($names as $name) {
    					$count ++;
    					$user_info = get_userdata($name);
    					$dj_str .= $user_info->display_name;
    
    					if( ($count == 1 && count($names) == 2) || (count($names) > 2 && $count == count($names)-1) ) {
    						$dj_str .= ' and ';
    					}
    					elseif($count < count($names) && count($names) > 2) {
    						$dj_str .= ', ';
    					}
    					else {
    						//do nothing
    					}
    				}
    			}
    
    			//schedules
    			$scheds = get_post_meta($dj->ID, 'show_sched', true);
    			$current_sched = station_current_schedule($scheds);
    			if($current_sched) {
    				$dj_str .= ' '.__($current_sched['day'], 'radio-station').', '.$current_sched['start_hour'].':'.$current_sched['start_min'].' '.$current_sched['start_meridian'].'-'.$current_sched['end_hour'].':'.$current_sched['end_min'].' '.$current_sched['end_meridian'];
    			}
    
    		}
    	}
    	else {
    		$dj_str .= $default_name;
    	}
    }
    
    file_put_contents ( 'onNow.txt' , $dj_str );

    Then in your server's crontab file, depending on how often you wanted to update the text file, you would add something like:
    0 0 * * * /usr/bin/wget -O http://www.mysite.com/nowOn.php > /dev/null 2>&1

    I think that's how I'd probably do it, anyway. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Radio Station
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.