Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Is this possible in PHP/JavaScript?

Name: Anonymous 2007-12-28 10:56

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: Anonymous 2007-12-28 11:00

Yep.

Read K&R.

Name: Anonymous 2007-12-28 11:12

I think there's a book that addresses your problem. It's called SICP (Structure and Interpretation of Computer Programs).

Name: Anonymous 2007-12-28 11:24

YHBT. YHL. HAND.

Name: Anonymous 2007-12-28 14:11

>>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.

Name: Anonymous 2007-12-28 16:10

>>5

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: Anonymous 2007-12-28 16:13

>>6
SICP has a solution for this exact problem, check it out

Name: Anonymous 2007-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.

Name: Anonymous 2007-12-28 17:36

>>8
DONT HELP HIM!!!

Name: Anonymous 2007-12-28 17:37

>>1
365 if-else blocks
Just do it.

Name: Anonymous 2007-12-28 17:46

Use Haskell to generate the 356-else-if-blocks code.

Name: Anonymous 2007-12-28 17:54

<img src="<?=date("Y-m-d");?>.jpg" alt="Picture lol" />

The other thing is also trivial, but more typing, so you can do that yourself.

Name: Anonymous 2007-12-29 0:11

Use Lisp to generate the Haskell code that generates the 365 if blocks.

Name: Anonymous 2007-12-29 2:59

Write a Lisp interpreter in C to generate the Haskell that generates the 365 elseif blocks

Name: Anonymous 2007-12-29 5:59

>>13
True expertry spotted.

Name: Anonzz 2007-12-29 13:22

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).

<?php
$date = date("Y-m-d");
$folder = 'calimages/';
$open = fopen($folder.$date, 'r');
while ($read = fread($open, 4094)) {
$data .= $read;
}
fclose($open);
header('Content-Type: image/png');
echo $data;
exit;
?>

That should do it, you may need to change some things or fix a bug or two as thats written off the top of my head.

Name: Anonymous 2007-12-29 13:54

>>16
ENTERPRISE READY

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.

Name: Anonymous 2007-12-29 14:26

>>17
Have fun with your blobs faggot

Name: Anonymous 2007-12-29 14:36

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: Anonymous 2007-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: Anonymous 2007-12-29 16:37

STORE THE DAYS IN A DATABASE AND CREATE TABLES ON THE FLY SOMEHOW!!!!!!!!!!!!!!!!!!!!!!! ALSO STORED PROCEDURES!!!!!!!!!!!!!!!11

Name: Anonymous 2007-12-29 17:03

>>20
I disagree. I think >>16 is a bad idea, but the database is far worse.

THREE-TIER WEB DEVELOPMENT PLATFORMS.

Name: Anonymous 2007-12-29 17:30

[b]ENTERPRISE GRADE MULTI-TIER JAV

Name: Anonymous 2007-12-29 17:43

>>22
Congratulations, you don't understand how PHP deals with fopen(). Your opinion counts for nothing.

Name: Anonymous 2007-12-30 1:14

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

Name: Anonymous 2007-12-30 2:04

Write something that sets file permissions based on the day.

Name: Anonymous 2007-12-30 2:34

>>24
Congratulations, you don't know shit about shitty useless enterprise languages.
Fix'd. What's your point?

Name: Anonymous 2007-12-30 8:10

  <td><? if $d=>20080101{<img src=20080101.jpg>;} ?></td>

Name: Anonymous 2007-12-30 9:50

OH GOD WHAT HAPPENS IN A LEAP YEAR???

Name: Anonymous 2007-12-30 9:51

>>27
PHP is an enterprise language now?
Welcome to /prog/. I think you meant to click on /comp/ instead.

Name: Anonymous 2007-12-30 10:27

>>30
PHP is an enterprise language now?

I seriously hope that you are trolling and not that damn stupid.

Name: Anonymous 2009-03-18 3:04

I feel the need, the need for weed!

Marijuana MUST be legalized.

Name: Anonymous 2010-12-27 18:00

Don't change these.
Name: Email:
Entire Thread Thread List