-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletters.php
executable file
·94 lines (93 loc) · 2.82 KB
/
letters.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// header('HTTP/1.1 301 Moved Permanently');
// header('Location: http://inck.net/letters/');
$title = "Letters to the Editor";
include('inc/head.php');
// Get article list from feed.
$feed_xml = `php feed.php`;
$feed = new SimpleXMLElement($feed_xml);
$article_numbers[] = substr($feed->channel->item[0]->guid, 32);
$article_numbers[] = substr($feed->channel->item[1]->guid, 32);
$article_numbers[] = substr($feed->channel->item[2]->guid, 32);
$article_numbers[] = substr($feed->channel->item[3]->guid, 32);
?>
<li class="column one_unit">
<ul>
<li class="module flag secondary">
<h3><a href="./"><span class="letter_i">I</span><span class="letter_n">n</span><span class="letter_c">c</span><span class="letter_k">k</span></a></h3>
</li>
</ul>
</li>
<li class="space nine_units"></li>
<li class="column two_units">
<ul>
<li class="module edition secondary">
<cite><?php echo $edition; ?></cite>
<cite>Letters to the Editor</cite>
</li>
</ul>
</li>
<li class="column twelve_units contained">
<ul>
<li class="module rule"></li>
</ul>
</li>
<?php
foreach($article_numbers as $key => $article_number) {
?>
<li class="column three_units<?php if(!$key) echo ' contained'; ?>">
<ul>
<?php
$article = file_get_contents('pages/' . $article_number . '.txt'); $lines = explode("\n", $article);
$article_title = trim($lines[0]);
$article_date = trim($lines[1]);
?>
<li class="module leader contained">
<h2><a href="page.php?number=<?php echo $article_number; ?>"><?php echo $article_title; ?></a></h2>
<cite>by Nicholas Hall on <em><?php echo $article_date; ?></em></cite>
</li>
<?php
if($letters_together = file_get_contents('letters/' . $article_number . '.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) {
$letters = explode("\n\n-----------------\n\n", $letters_together); array_pop($letters);
$letters = array_reverse($letters);
foreach($letters as $letter) {
$lines = explode("\n", $letter);
$time = array_shift($lines);
$name = array_pop($lines);
?>
<li class="module letter_box two_units">
<ul>
<li class="module letter">
<em><?php if(date('zY') != date('zY', $time)) { echo date('F jS, Y', $time); } else { echo date('g:i a', $time); } ?></em>
<p class="prompt">Dear Sir:</p>
<?php
foreach($lines as $line) {
$line = trim($line);
if($line) {
?>
<p><?php echo $line; ?></p>
<?php
}
}
?>
<p class="prompt">Sincerely,</p>
<cite><?php echo $name; ?></cite>
</li>
</ul>
</li>
<?php
}
} else {
?>
<li class="module leader contained">
<p><a href="page.php?number=<?php echo $article_number; ?>">Write a Letter to the Editor.</a></p>
</li>
<?php
}
?>
</ul>
</li>
<?php
}
include('inc/foot.php');
?>