closure.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <?php
  2. /**
  3. * <https://y.st./>
  4. * Copyright © 2016-2017 Alex Yst <mailto:copyright@y.st>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org./licenses/>.
  18. **/
  19. /**
  20. * Closures are for writing functions that aren't fit to be reused in
  21. * other projects. If a function isn't fit to be used in other
  22. * projects, it clearly hasn't been generalized enough. As such, the
  23. * code in this file really should be generalized more. I'll rewrite
  24. * this code as I figure out how to better generalize it.
  25. **/
  26. $¢_build_page = function($filename, $xhtml) {
  27. global $URI_path_minus_slash;
  28. global $entry;
  29. global $a;
  30. global $pgp;
  31. global $should_exist;
  32. global $coursework_nav;
  33. global $interval;
  34. global $latest_entry;
  35. if(substr('/'.$filename, -12) == '/index.xhtml'):
  36. $URI_path_minus_slash = substr($filename, 0, -11);
  37. else:
  38. $URI_path_minus_slash = $filename;
  39. endif;
  40. if(substr($filename, 0, 3) == 'en/'):
  41. $nav_en = true;
  42. endif;
  43. if($filename != 'en/coursework/index.xhtml' and substr($filename, 0, 14) == 'en/coursework/'):
  44. $nav_en_coursework = true;
  45. // It's less work to maintain this if we have the script dynamically
  46. // decide what the course code must be.
  47. $course_path_parts = explode('/', $filename);
  48. // If there's a an element number three, element two is the course
  49. // code. Otherwise, we have no course code at all because we're not
  50. // dealing with a course subdirectory.
  51. if(isset($course_path_parts[3])):
  52. $course_code_nav = $course_path_parts[2];
  53. endif;
  54. endif;
  55. if($filename != 'en/opinion/index.xhtml' and substr($filename, 0, 11) == 'en/opinion/'):
  56. $nav_en_opinion = true;
  57. endif;
  58. if(substr($filename, 0, 10) == 'en/weblog/'):
  59. $current_entry = substr($URI_path_minus_slash, 10);
  60. $current_entry = explode('/', $current_entry);
  61. $nav_en_weblog = true;
  62. switch(count($current_entry)):
  63. // Main weblog index:
  64. case 1:
  65. break;
  66. // Weblog year index:
  67. case 2:
  68. $nav_en_weblog_year = true;
  69. $datetime = new DateTimeImmutable("$current_entry[0]-01-01");
  70. $previous = $datetime->sub($interval['year'])->format('Y');
  71. $next = $datetime->add($interval['year'])->format('Y');
  72. break;
  73. case 3:
  74. // Weblog month index:
  75. if($current_entry[2] == ''):
  76. $nav_en_weblog_month = true;
  77. $current_entry[1] = explode('-', $current_entry[1])[0];
  78. $datetime = new DateTimeImmutable("$current_entry[0]-$current_entry[1]-01");
  79. $previous = $datetime->sub($interval['month'])->format('Y/m-F');
  80. $next = $datetime->add($interval['month'])->format('Y/m-F');
  81. // Weblog day entry:
  82. else:
  83. $nav_en_weblog_day = true;
  84. $current_entry[1] = explode('-', $current_entry[1])[0];
  85. $current_entry[2] = explode('.', $current_entry[2])[0];
  86. $datetime = new DateTimeImmutable("$current_entry[0]-$current_entry[1]-$current_entry[2]");
  87. $previous = $datetime->sub($interval['day'])->format('Y/m-F/d');
  88. $next = $datetime->add($interval['day'])->format('Y/m-F/d');
  89. $xhtml['subtitle'] = $entry($current_entry[0], $current_entry[1], $current_entry[2]);
  90. endif;
  91. break;
  92. default:
  93. throw new Exception("The weblog section of the source directory tree has an anomaly. File path \"$filename\" detected.");
  94. endswitch;
  95. // Automatic copyright dating of journal entries:
  96. if(empty($xhtml['copyright year']) and !empty($current_entry[0])):
  97. $xhtml['copyright year'] = $current_entry[0];
  98. endif;
  99. endif;
  100. ob_start();
  101. ?>
  102. <?xml version="1.0" encoding="utf-8"?>
  103. <!--
  104. h t t :: / / t /
  105. h t t :: // // t //
  106. h ttttt ttttt ppppp sssss // // y y sssss ttttt //
  107. hhhh t t p p s // // y y s t //
  108. h hh t t ppppp sssss // // yyyyy sssss t //
  109. h h t t p s :: / / y .. s t .. /
  110. h h t t p sssss :: / / yyyyy .. sssss t .. /
  111. <https://y.st./>
  112. Copyright © <?php echo $xhtml['copyright year']; ?> Alex Yst <mailto:copyright@y.st>
  113. This program is free software: you can redistribute it and/or modify
  114. it under the terms of the GNU General Public License as published by
  115. the Free Software Foundation, either version 3 of the License, or
  116. (at your option) any later version.
  117. This program is distributed in the hope that it will be useful,
  118. but WITHOUT ANY WARRANTY; without even the implied warranty of
  119. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  120. GNU General Public License for more details.
  121. You should have received a copy of the GNU General Public License
  122. along with this program. If not, see <https://www.gnu.org./licenses/>.
  123. -->
  124. <!DOCTYPE html>
  125. <html xmlns="http://www.w3.org/1999/xhtml">
  126. <head>
  127. <?php
  128. echo <<<END
  129. <base href="https://y.st./$URI_path_minus_slash" />
  130. END;
  131. ?>
  132. <title><?php echo strip_tags(str_replace(array(
  133. '<q>',
  134. '</q>',
  135. ), '&quot;', $xhtml['title']))." &lt;https://y.st./$URI_path_minus_slash&gt;"; ?></title>
  136. <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
  137. <?php
  138. if($filename == 'ErrorDocument/400.xhtml'):
  139. ?>
  140. <style type="text/css">
  141. <?php
  142. echo htmlspecialchars(file_get_contents(__DIR__.'/../static/link/basic.css'), ENT_XML1|ENT_QUOTES),
  143. htmlspecialchars(file_get_contents(__DIR__.'/../static/link/site-specific.css'), ENT_XML1|ENT_QUOTES);
  144. ?>
  145. </style>
  146. <?php
  147. else:
  148. ?>
  149. <link rel="stylesheet" type="text/css" href="/link/basic.css" />
  150. <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
  151. <script type="text/javascript" src="/script/javascript.js" />
  152. <?php
  153. endif;
  154. ?>
  155. <meta name="viewport" content="width=device-width" />
  156. </head>
  157. <body>
  158. <?php // Begin navigational header
  159. if(isset($nav_en)):
  160. ?>
  161. <nav>
  162. <p>
  163. <a href="/en/">Home</a> |
  164. <a href="/en/a/about.xhtml">About</a> |
  165. <a href="/en/a/contact.xhtml">Contact</a> |
  166. <a href="/a/canary.txt">Canary</a> |
  167. <a href="/en/URI_research/"><?php echo $a['URI']; ?> research</a> |
  168. <a href="/en/opinion/">Opinions</a> |
  169. <a href="/en/coursework/">Coursework</a> |
  170. <a href="/en/law/">Law</a> |
  171. <a href="/en/a/links.xhtml">Links</a> |
  172. <?php
  173. echo <<<END
  174. <a href="/$filename.asc">{this page}.asc</a>
  175. END;
  176. ?>
  177. </p>
  178. <hr/>
  179. <?php
  180. if(isset($nav_en_weblog)):
  181. ?>
  182. <p>
  183. Weblog index:
  184. <a href="/en/weblog/"><?php echo $a['ASCII']; ?> calendars</a> |
  185. <a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
  186. <a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
  187. </p>
  188. <hr/>
  189. <?php
  190. endif;
  191. if(isset($nav_en_weblog_year)):
  192. ?>
  193. <p>
  194. Jump to year:
  195. <?php
  196. if("/$filename" != '/en/weblog/2015/index.xhtml'):
  197. echo <<<END
  198. <a href="/en/weblog/2015/">&lt;&lt;First</a>
  199. END;
  200. endif;
  201. if(is_dir(__DIR__."/pages/en/weblog/$previous/")):
  202. echo <<<END
  203. <a rel="prev" href="/en/weblog/$previous/">&lt;Previous</a>
  204. END;
  205. endif;
  206. if(is_dir(__DIR__."/pages/en/weblog/$next/")):
  207. echo <<<END
  208. <a rel="next" href="/en/weblog/$next/">Next&gt;</a>
  209. END;
  210. endif;
  211. if("/$filename" != "$latest_entry[year]index.xhtml"):
  212. echo <<<END
  213. <a href="/en/weblog/latest_year.xhtml">Latest&gt;&gt;</a>
  214. END;
  215. endif;
  216. ?>
  217. </p>
  218. <hr/>
  219. <?php
  220. endif;
  221. if(isset($nav_en_weblog_month)): ?>
  222. <p>
  223. Jump to month:
  224. <?php
  225. if("/$filename" != '/en/weblog/2015/03-March/index.xhtml'):
  226. echo <<<END
  227. <a href="/en/weblog/2015/03-March/">&lt;&lt;First</a>
  228. END;
  229. endif;
  230. if(is_dir(__DIR__."/pages/en/weblog/$previous/")):
  231. echo <<<END
  232. <a rel="prev" href="/en/weblog/$previous/">&lt;Previous</a>
  233. END;
  234. endif;
  235. if(is_dir(__DIR__."/pages/en/weblog/$next/")):
  236. echo <<<END
  237. <a rel="next" href="/en/weblog/$next/">Next&gt;</a>
  238. END;
  239. endif;
  240. if("/$filename" != "$latest_entry[month]index.xhtml"):
  241. echo <<<END
  242. <a href="/en/weblog/latest_month.xhtml">Latest&gt;&gt;</a>
  243. END;
  244. endif;
  245. ?>
  246. </p>
  247. <hr/>
  248. <?php
  249. endif;
  250. if(isset($nav_en_weblog_day)):
  251. ?>
  252. <p>
  253. Jump to entry:
  254. <?php
  255. if("/$filename" != '/en/weblog/2015/03-March/07.xhtml'):
  256. echo <<<END
  257. <a href="/en/weblog/2015/03-March/07.xhtml">&lt;&lt;First</a>
  258. END;
  259. endif;
  260. if(file_exists(__DIR__."/pages/en/weblog/$previous.xhtml")):
  261. echo <<<END
  262. <a rel="prev" href="/en/weblog/$previous.xhtml">&lt;Previous</a>
  263. END;
  264. endif;
  265. if(file_exists(__DIR__."/pages/en/weblog/$next.xhtml")):
  266. echo <<<END
  267. <a rel="next" href="/en/weblog/$next.xhtml">Next&gt;</a>
  268. END;
  269. endif;
  270. if("/$filename" != $latest_entry['day']):
  271. echo <<<END
  272. <a href="/en/weblog/latest.xhtml">Latest&gt;&gt;</a>
  273. END;
  274. endif;
  275. ?>
  276. </p>
  277. <hr/>
  278. <?php
  279. endif;
  280. if(isset($nav_en_coursework)):
  281. ?>
  282. <p>
  283. <a href="/en/coursework/BUS1101/" title="Principles of Business Management">BUS 1101</a> |
  284. <span class="hyperlink_unavailable" title="Basic Accounting">BUS 1102</span> |
  285. <span class="hyperlink_unavailable" title="Principles of Marketing">BUS 2201</span> |
  286. <span class="hyperlink_unavailable" title="Multinational Management">BUS 2207</span> |
  287. <span class="hyperlink_unavailable" title="Business and Society">BUS 3306</span> |
  288. <a href="/en/coursework/CS1101/" title="Programming Fundamentals">CS 1101</a> |
  289. <a href="/en/coursework/CS1102/" title="Programming 1">CS 1102</a> |
  290. <a href="/en/coursework/CS1103/" title="Programming 2">CS 1103</a> |
  291. <span class="hyperlink_unavailable" title="Computer Systems">CS 1104</span> |
  292. <a href="/en/coursework/CS2203/" title="Databases 1">CS 2203</a> |
  293. <span class="hyperlink_unavailable" title="Communications and Networking">CS 2204</span> |
  294. <a href="/en/coursework/CS2205/" title="Web Programming 1">CS 2205</a> |
  295. <a href="/en/coursework/CS2301/" title="Operating Systems 1">CS 2301</a> |
  296. <span class="hyperlink_unavailable" title="Software Engineering 1">CS 2401</span> |
  297. <span class="hyperlink_unavailable" title="Data Structures">CS 3303</span> |
  298. <span class="hyperlink_unavailable" title="Analysis of Algorithms">CS 3304</span> |
  299. <span class="hyperlink_unavailable" title="Web Programming 2">CS 3305</span> |
  300. <span class="hyperlink_unavailable" title="Databases 2">CS 3306</span> |
  301. <span class="hyperlink_unavailable" title="Operating Systems 2">CS 3307</span> |
  302. <span class="hyperlink_unavailable" title="Information Retrieval">CS 3308</span> |
  303. <span class="hyperlink_unavailable" title="Comparative Programming Languages">CS 4402</span> |
  304. <span class="hyperlink_unavailable" title="Software Engineering 2">CS 4403</span> |
  305. <span class="hyperlink_unavailable" title="Advanced Networking and Data Security">CS 4404</span> |
  306. <span class="hyperlink_unavailable" title="Mobile Applications">CS 4405</span> |
  307. <span class="hyperlink_unavailable" title="Computer Graphics">CS 4406</span> |
  308. <span class="hyperlink_unavailable" title="Data Mining and Machine Learning">CS 4407</span> |
  309. <span class="hyperlink_unavailable" title="Artificial Intelligence">CS 4408</span> |
  310. <span class="hyperlink_unavailable" title="English Composition 2">ENGL 1102</span> |
  311. <span class="hyperlink_unavailable" title="World Literature">ENGL 1405</span> |
  312. <span class="hyperlink_unavailable" title="Introduction to Environmental Science">ENVS 1301</span> |
  313. <a href="/en/coursework/HIST1421/" title="Greek and Roman Civilization">HIST 1421</a> |
  314. <span class="hyperlink_unavailable" title="College Algebra">MATH 1201</span> |
  315. <span class="hyperlink_unavailable" title="Calculus">MATH 1211</span> |
  316. <span class="hyperlink_unavailable" title="Introduction to Statistics">MATH 1280</span> |
  317. <span class="hyperlink_unavailable" title="Discrete Mathematics">MATH 1302</span> |
  318. <span class="hyperlink_unavailable" title="Introduction to Philosophy">PHIL 1402</span> |
  319. <a href="/en/coursework/PHIL1404/" title="Ethics and Social Responsibility">PHIL 1404</a> |
  320. <a href="/en/coursework/POLS1503/" title="Globalization">POLS 1503</a> |
  321. <span class="hyperlink_unavailable" title="Introduction to Psychology">PSYC 1504</span> |
  322. <a href="/en/coursework/UNIV1001/" title="Online Education Strategies">UNIV 1001</a>
  323. </p>
  324. <hr/>
  325. <?php
  326. if(isset($course_code_nav)):
  327. echo "\t\t\t<p>\n\t\t\t\t{$coursework_nav[$course_code_nav]}\n\t\t\t</p>\n\t\t\t<hr/>\n";
  328. endif;
  329. endif;
  330. if(isset($nav_en_opinion)):
  331. ?>
  332. <p>
  333. <a href="/en/opinion/XML.xhtml"><?php echo $a['XML']; ?></a> |
  334. <a href="/en/opinion/code_indentation.xhtml">Code indentation</a> |
  335. <a href="/en/opinion/free_culture.xhtml">Free culture</a> |
  336. <a href="/en/opinion/free_software.xhtml">Free software</a> |
  337. <a href="/en/opinion/holidays.xhtml">Holidays</a> |
  338. <a href="/en/opinion/misuse_of_words.xhtml">Misuse of words</a>
  339. </p>
  340. <hr/>
  341. <?php
  342. endif;
  343. ?>
  344. </nav>
  345. <?php
  346. endif;
  347. // End navigational header
  348. if(isset($xhtml['subtitle'])):
  349. ?>
  350. <header>
  351. <?php
  352. endif;
  353. ?>
  354. <h1><?php echo $xhtml['title']; ?></h1>
  355. <?php
  356. if(isset($xhtml['subtitle'])):
  357. ?>
  358. <p><?php echo $xhtml['subtitle']; ?></p>
  359. </header>
  360. <?php
  361. endif;
  362. echo $xhtml['body'];
  363. ?>
  364. <hr/>
  365. <p>
  366. Copyright © <?php echo $xhtml['copyright year']; ?> Alex Yst;
  367. You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><?php echo $a['GNU'], ' ', $a['GPLv3+']; ?></a>.
  368. If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
  369. My address is in the source comments near the top of this document.
  370. This license also applies to embedded content such as images.
  371. For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
  372. </p>
  373. <p>
  374. <?php echo $a['W3C']; ?> standards are important.
  375. This document conforms to the <?php
  376. $checkpath = urlencode($URI_path_minus_slash);
  377. echo '<a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2F', $checkpath, '">', $a['XHTML'], ' 5.1</a>';
  378. ?> specification and uses style sheets that conform to the <?php
  379. echo '<a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2F', $checkpath, '">', $a['CSS'], '3</a>';
  380. ?> specification.
  381. </p>
  382. </body>
  383. </html>
  384. <?php
  385. $should_exist[$filename] = true;
  386. $should_exist["$filename.asc"] = true;
  387. $dirname = dirname(__DIR__."/../compiled/$filename");
  388. if(!is_dir($dirname)):
  389. mkdir($dirname, 0777, true);
  390. endif;
  391. \st\y\update_file(__DIR__."/../compiled/$filename", ob_get_clean(), $pgp);
  392. };