I am making two pages. The first one displays a picture depending on the day - so if it's January 10 2008, the displayed pic is 2008-01-10.jpg
Next, I want to make a calendar, with each day linking to the appropriate pic of the day. However, I want to make it so it's impossible to view pics before their day, either by not making them hyperlinks, or by making it so nothing happens when they are clicked on. Problem is, I have no clue as to how to approach this problem aside from making 365 if-else blocks.
Any ideas?
Name:
Anonymous2007-12-28 11:00
Yep.
Read K&R.
Name:
Anonymous2007-12-28 11:12
I think there's a book that addresses your problem. It's called SICP (Structure and Interpretation of Computer Programs).
>>1
[pseudocode]
set date D to [1st Jan 2008]
do while date D < [1st Jan 2009]
output opening html for date D
if date D <= today then
link to picture
else
don't link to picture
endif
output closing html for date D
advance date D by one day
loop
[/pseudocode]
To prevent people from manually going to the pictures, you might want to name (and link to) them with using a hash function of the date and a secret not known to the user.
I don't care about protecting access to the files themselves - I just don't want to make it obvious. If somebody wants to spoil the whole year for himself, that's his problem, not mine. So long as the front end behaves correctly, I'm happy.
Hopefully I'll be able to upgrade on the code and try to make a calendar structure with tables before the new year hits. I'm starting to have an idea as to how exactly I could place the HTML strategy but I think I'll have to sleep on it before I can make something viable.
Name:
Anonymous2007-12-28 16:13
>>6
SICP has a solution for this exact problem, check it out
Name:
Anonymous2007-12-28 17:26
You don't need 365 if/else blocks. Only 365 ifs
if (today > Jan1st) {
...
if (today > Jan2nd) {
...
)))))))....)))))
And so Ive fixed all your problems. And you didn't have to read SICP.
We assume you have 365(6) images one for each day..., simple use a img src to this script, it will only display the current days image and they won't be able to find the url (gets around just using the header function).
Seriously, if you're willing to waste that much in overhead, you're better off just storing the images in a database in binary format and reading from that. That way people can't see all of your images when they manage to guess the actual URL.
OP here, I had already figured the first page out; I was just looking for the most effective way to approach the calendar problem.
I'm mostly leaning towards >>12's answer, adapted to the proper sauce. Basically, I design the calendar structure from the get go, but the actual links appear depending on date, so I'd get something more or less like
$d = [current date];
<table>
<tr>
<td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>
<td><? if $d=>20080102{<img src=20080102.jpg>;} ?></td>
<td><? if $d=>20080103{<img src=20080103.jpg>;} ?></td>
and so on and so forth.
I could also add some code so that each table-month only appears once the date reaches a certain point. It's a lot clearer in my head now that I've had time to idly think about it. The rest of the work is trying to make the code as compact as possible.
Once again, I don't care if the end user finds out the URL for each pic - it's yyyy-mm-dd and I'll upload the entire year in a single go, so that I can let the "pic of the day" thing run itself without management.
Name:
Anonymous2007-12-29 15:19
>>18
It's obviously a bad idea to do it with a database, but it's a far worse idea to do it the way >>16 suggested.
Lurk the fuck more, asswipe.
Name:
Anonymous2007-12-29 16:37
STORE THE DAYS IN A DATABASE AND CREATE TABLES ON THE FLY SOMEHOW!!!!!!!!!!!!!!!!!!!!!!! ALSO STORED PROCEDURES!!!!!!!!!!!!!!!11