-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplist-sectioned.php
More file actions
238 lines (201 loc) · 6.72 KB
/
Copy pathplist-sectioned.php
File metadata and controls
238 lines (201 loc) · 6.72 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
function encodeXML($string)
{
$string = strip_tags($string);
$string = str_replace('ó', '-', $string);
$string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
$string = unhtmlentities($string);
$string = safe_cr($string);
$string = str_replace("&", "&", $string);
return $string;
}
function unhtmlentities($string)
{
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
function safe_cr($string){
$cr = array(
// http://intertwingly.net/stories/2004/04/14/i18n.html#CleaningWindows
'€' => '€',
'' => '',
'‚' => '‚',
'ƒ' => 'ƒ',
'„' => '„',
'…' => '…',
'†' => '†',
'‡' => '‡',
'ˆ' => 'ˆ',
'‰' => '‰',
'Š' => 'Š',
'‹' => '‹',
'Œ' => 'Œ',
'' => '',
'Ž' => 'Ž',
'' => '',
'' => '',
'‘' => '‘',
'’' => '’',
'“' => '“',
'”' => '”',
'•' => '•',
'–' => '–',
'—' => '—',
'˜' => '˜',
'™' => '™',
'š' => 'š',
'›' => '›',
'œ' => 'œ',
'' => '',
'ž' => 'ž',
'Ÿ' => 'Ÿ' );
return strtr($string,$cr);
}
header("Content-Type: application/xml; charset=UTF-8");
echo '<?xml version="1.0" encoding="UTF-8" ?>';
include("dbconnect.php");
include("getcurrentdate.php");
// romanToArabic written 2001 by Mark Wilton-Jones. Version 1.1.1
// http://www.howtocreate.co.uk/php/
// http://www.howtocreate.co.uk/jslibs/termsOfUse.html
function romanToArabic( $myRomanNum, $htmlelement = '_', $htmlelement2 = '' ) {
//convert into single characters
$htmlelement = strtoupper(addslashes($htmlelement));
$htmlelement2 = strtoupper(addslashes($htmlelement2));
$myRomanNum = strtoupper($myRomanNum);
$myRomanNum = str_replace($htmlelement."M".$htmlelement2,"N",$myRomanNum);
$myRomanNum = str_replace($htmlelement."D".$htmlelement2,"O",$myRomanNum);
$myRomanNum = str_replace($htmlelement."C".$htmlelement2,"P",$myRomanNum);
$myRomanNum = str_replace($htmlelement."L".$htmlelement2,"Q",$myRomanNum);
$myRomanNum = str_replace($htmlelement."X".$htmlelement2,"R",$myRomanNum);
$myRomanNum = str_replace($htmlelement."V".$htmlelement2,"S",$myRomanNum);
//prepare Arabic numerals
$rom_to_ar['N'] = 1000000;
$rom_to_ar['O'] = 500000;
$rom_to_ar['P'] = 100000;
$rom_to_ar['Q'] = 50000;
$rom_to_ar['R'] = 10000;
$rom_to_ar['S'] = 5000;
$rom_to_ar['M'] = 1000;
$rom_to_ar['D'] = 500;
$rom_to_ar['C'] = 100;
$rom_to_ar['L'] = 50;
$rom_to_ar['X'] = 10;
$rom_to_ar['V'] = 5;
$rom_to_ar['I'] = 1;
$myArabicNum = 0;
if( isset( $myRomanNum ) && $myRomanNum == '' ) { return 0; }
//go forever 'till you get it
for( $x = 0; $x >= 0; $x++ ) {
//if you get to the end, you have finished
if( substr($myRomanNum,$x,1) == '' ) { return $myArabicNum; }
//check for valid characters
if( $rom_to_ar[substr($myRomanNum,$x,1)] ) {
//the character is valid. check for valid format, then do we add or delete?
if( $rom_to_ar[substr($myRomanNum,$x,1)] < $rom_to_ar[substr($myRomanNum,$x+2,1)] && $rom_to_ar[substr($myRomanNum,$x+1,1)] < $rom_to_ar[substr($myRomanNum,$x+2,1)] ) {
//for example IIX is invalid. so is VIX. so is IVX. they are ambiguous
//IXI will be allowed as it is not ambiguous. Try to show a better way of writing it.
return "not convertable, format invalid. Only one lower value character may preceed a higher value character.";
}
if( $rom_to_ar[substr($myRomanNum,$x,1)] >= $rom_to_ar[substr($myRomanNum,$x+1,1)] ) {
//add
$myArabicNum += $rom_to_ar[substr($myRomanNum,$x,1)];
} else {
//delete
$myArabicNum -= $rom_to_ar[substr($myRomanNum,$x,1)];
}
} else {
return "not convertable, invalid character '".htmlentities(substr($myRomanNum,$x,1))."' used.";
}
}
}
function volToYears($vol) {
return (1870+$vol)."-".(1871+$vol);
}
?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Rows</key>
<array>
<?php
$volumes_result = mysql_query("
select `id`, `numeral` from volume where `numeral` <> 'CXXXII'
");
while($volume = mysql_fetch_assoc($volumes_result))
{
?>
<dict>
<key>Title</key>
<string><?="Vol. ".romanToArabic($volume["numeral"])." (".volToYears(romanToArabic($volume["numeral"])).")"?></string>
<key>Children</key>
<array>
<?php
$volume_result = mysql_query("
select
date_format(issue_date, '%b %e, %Y') as date,
issue_date,
issue_number
from issue
where volume_id = '".$volume["id"]."'
");
while($issue = mysql_fetch_assoc($volume_result))
{
?>
<dict>
<key>Title</key>
<string>No. <?=$issue["issue_number"]?> (<?=$issue["date"]?>)</string>
<key>Children</key>
<array>
<?php for ($i = 0; $i < 5; $i++) { ?>
<dict>
<key>Number</key>
<string><?=$i?></string>
<key>Children</key>
<array>
<?php
$articles = mysql_query("
select
section_id,
priority,
title
from
article
where date = '".$issue["issue_date"]."' and section_id = '".($i+1)."'
order by section_id, priority
") or die(mysql_error());
while($article = mysql_fetch_assoc($articles))
{
?>
<dict>
<key>Title</key>
<string><?=utf8_encode(htmlspecialchars($article["title"]))?></string>
<key>Section</key>
<string><?=($article["section_id"]-1)?></string>
<key>URL</key>
<string>http://orient.bowdoin.edu/orient/article_iphone.php?date=<?=$issue["issue_date"]?>&section=<?=$article["section_id"]?>&id=<?=$article["priority"]?></string>
</dict>
<?php
}
?>
</array>
</dict>
<?php } ?>
</array>
</dict>
<?php
}
?>
</array>
</dict>
<?php
}
?>
</array>
</dict>
</plist>