Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-11-13 09:35:42

shi
Member
Registered: 2005-12-09
Posts: 34

Online radio station and textpattern

Hello everyone,

I’m developing a website for a free online radio with Textpattern, and for the first time (in my TXP career ;) I can’t find a solution or addon for my problem(s). I must say that I have only a begginer knowledge of PHP.

1) I need is to display what radio show is currently playing (you’ll see a box Online (Now Playing) in the middle of the frontpage )
2) I need to make this timetable functional

At the moment all this is hardcoded (mostly static html).

Usual timing for a radio shows is, for instance, every Friday from 15h to 17h. Each show has it’s own article, and custom field values for starting and ending date, plus the custom field value for day of the week.

I guess that I need to make some conditional statements (actually lot’s of them for a timetable) or use zem_custom_event plugin. I’ve tried both but I didn’t make it work.

I tried to use smd_if plugin to compare value of current hour (%H) to the value of a custom field but it was giving me some bad results. I guess I messed up something with integers and strings. (I predefined $myvar in a code with (%H) )

<txp:smd_if field="custom1,sustom2" operator="ge:NUM,le:NUM" value="phpvar:myvar,phpvar:myvar" >
 <txp:article_custom section="radio-show" limit="1" form="now_playing" />
</txp:smd_if>

Then I tried to use zem_article_event too. After reading documentation all over the web I still couldnt find any conditional tag, or range of values, or anything that will help me accomplish my task.

Is there a way to do this in Textpattern without hard core PHP coding, or is there some plugin for this? Or maybe it can be done zem_event_manager or smd_if?

Please help. Any advice or suggestion will be great. Thanks in advance.

Last edited by shi (2008-11-13 09:56:15)

Offline

#2 2008-11-13 10:48:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: Online radio station and textpattern

Hi shi,

First off, that’s a nice lookin’ site :-)

Next, I think it’d be possible. zem_event, as you found, would probably work but you’d be using its own internal fields to store the start and end times rather than article custom fields. Using that event manager would allow you to offer some sort of automated, clickable calendar of shows instead of having to manage it yourself, which has merit when it comes to maintaining show schedules.

Have you tried posting over in the zem_event thread? I believe forum user pepebe is in the process of rewriting the plugin, so now might be a good time to present your conundrum and see what thoughts it sparks.

If you go the other way and do it all manually, smd_if should be able to handle it (depending on where you use it). For example, if you are trying to make up a manual ‘calendar’ and highlight which show is currently playing, you first need to make sure your variables are globally declared. So, somewhere else earlier on the page — not in the same form that checks each show or you’ll waste processing time calculating it — do this:

<txp:php>
  global $day_now, hour_now;
  $hour_now = date('H');
  $day_now = date('l');
</txp:php>

Then, assuming you have labelled your three custom fields: weekday, start_hour and end_hour and you are iterating over, say, an article_custom list you should be able to do something like this (untested):

<txp:smd_if field="weekday, start_hour, end_hour" operator="eq, ge:NUM, lt:NUM" value="phpvar:day_now, phpvar:hour_now, phpvar:hour_now">
  <txp:output_form form="now_playing" />
<txp:else />
  <txp:output_form form="show_info" />
</txp:smd_if>

That’ll test if the current article is set to play on the current day and hour, and highlight it if so. Otherwise it’ll just display the article’s details normally.

Perhaps if you twist that idea around you could do what you were initially trying to do and only list the current show, but you might need a lot of smd_if calls to make it work, or somehow store a table of shows to compare the current day/hour against, which is very time consuming to set up.

Incidentally, I’m not sure if you can use smd_if to get at zem_event’s variables. I’ve never tried it. If they are put on the URL address bar you can certainly get at them and test them.

I may have misunderstood how you are trying to set the site up, so if I’m way off base let me know and I’ll try and help you figure out something better / more useful.

Last edited by Bloke (2008-11-13 10:51:44)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2008-11-14 08:14:00

shi
Member
Registered: 2005-12-09
Posts: 34

Re: Online radio station and textpattern

Thanks a lot Bloke, and thanks for making this nice plugin.

That piece of PHP code really helped me cause I didn’t know that I need to make that variable global. Yeah, I’m a PHP noob… I was using $today = idate(“H”); before. So that part works now! I’m able to display “now playing show” at the homepage.

Timetable is left to be done. Hard part tbh… It’s probably best idea to try to make it with zem_event but the plugin is being rewriten atm, as you’ve said, and documentation for the old one is confusing. I’ll probably post in zem_event’s forum thread for this.

Offline

Board footer

Powered by FluxBB