weblog_index.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * <https://y.st./>
  4. * Copyright (C) 2015-2016 //y.st. <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 <http://www.gnu.org./licenses/>.
  18. **/
  19. use st\y\calendar;
  20. foreach(scandir(__DIR__.'/pages/en/weblog') as $year):
  21. if($year != '.' and $year != '..'):
  22. $calendar = array();
  23. foreach($months as $monthnum => $monthdir):
  24. if(is_dir(__DIR__."/pages/en/weblog/$year/$monthdir")):
  25. $calendar[$monthnum] = <<<END
  26. <pre>/--------------------\\
  27. | $year {$monthheads[$monthnum]} |
  28. END;
  29. foreach(new calendar($year, $monthnum) as $week):
  30. $calendar[$monthnum] .= "\n|--+--+--+--+--+--+--|\n|";
  31. foreach($week as $datetime):
  32. $date = $datetime->format('Y/m-F/d');
  33. $key_year = $datetime->format('Y');
  34. $key_month = $datetime->format('m');
  35. $key_day = $datetime->format('d');
  36. $date_linktext = $entry($key_year, $key_month, $key_day);
  37. $date_linktext_li = substr($date_linktext, 11);
  38. // Needed because Links is broken.
  39. $date_li_value = substr($date_linktext, 4, 5);
  40. if(file_exists(__DIR__."/pages/en/weblog/$date.xhtml") and $datetime->format('n') == $monthnum):
  41. // The graphical calendar day:
  42. $calendar[$monthnum] .= "<a href=\"/en/weblog/$date.xhtml\" title=\"$date_linktext\">$key_day</a>|";
  43. // The list-based calendar day:
  44. $ol_array[$key_year][$key_month][$key_day] = "<li value=\"$date_li_value\"><a href=\"/en/weblog/$date.xhtml\">$date_linktext_li</a></li>";
  45. // We need to know what entry comes first:
  46. /**
  47. * This is a better way to handle list item numbers than using the
  48. * "value" attribute on every last <li/> tag, but the Links Web browser
  49. * is broken. It cannot handle starting from zero and cannot handle
  50. * reversed lists at all.
  51. **/
  52. # if(!isset($ol_start[$key_year][$key_month])):
  53. # $ol_start[$key_year][$key_month] = substr($date_linktext, 4, 5);
  54. # endif;
  55. // We also need to know which entry comes last:
  56. # $ol_end[$key_year][$key_month] = substr($date_linktext, 4, 5);
  57. // Set up RSS entries:
  58. $RSS_entry[] = array(
  59. // We don't actually know the title yet until we require the entry file.
  60. # 'title' => '',
  61. 'path' => $date,
  62. 'date' => $datetime->format(DateTime::RSS),
  63. );
  64. else:
  65. $calendar[$monthnum] .= ' |';
  66. endif;
  67. endforeach;
  68. endforeach;
  69. $calendar[$monthnum] .= "\n\\--------------------/</pre>";
  70. $¢_build_page("en/weblog/$year/$monthdir/index.xhtml", array(
  71. 'title' => "Weblog: $year ".substr($monthdir, 3),
  72. 'copyright year' => $year,
  73. 'body' => '<div class="weblogindex">'.$calendar[$monthnum].'</div>',
  74. ));
  75. endif;
  76. endforeach;
  77. $yearcal[$year] = implode("\n", $calendar);
  78. $¢_build_page("en/weblog/$year/index.xhtml", array(
  79. 'title' => "Weblog: $year",
  80. 'copyright year' => $year,
  81. 'body' => '<div class="weblogindex">'.$yearcal[$year].'</div>',
  82. ));
  83. endif;
  84. endforeach;
  85. // The semi-graphical weblog index:
  86. $¢_build_page('en/weblog/index.xhtml', array(
  87. 'title' => "Weblog",
  88. 'copyright year' => "2015-$latest_copyright_year",
  89. 'body' => '<div class="weblogindex">'.implode("\n", $yearcal).'</div>',
  90. ));
  91. // The list-based weblog indexes:
  92. $month_list_ascending = array();
  93. $month_list_descending = array();
  94. foreach($ol_array as $key_year => $year):
  95. foreach($year as $key_month => $month):
  96. // Ascending
  97. # $start = $ol_start[$key_year][$key_month];
  98. $list = implode("\n", $month);
  99. // Links is broken and cannot handle this if start="0".
  100. # $month_list_ascending[] = "<ol start=\"$start\">\n$list\n</ol>";
  101. $month_list_ascending[] = "<ol>\n$list\n</ol>";
  102. // Descending
  103. # $start = $ol_end[$key_year][$key_month];
  104. $list = implode("\n", array_reverse($month));
  105. // Links is broken and cannot handle revered lists.
  106. # $month_list_descending[] = "<ol start=\"$start\" reversed=\"reversed\">\n$list\n</ol>";
  107. $month_list_descending[] = "<ol>\n$list\n</ol>";
  108. endforeach;
  109. endforeach;
  110. $list_ascending = implode("\n\n", $month_list_ascending);
  111. $list_descending = implode("\n\n", array_reverse($month_list_descending));
  112. // Ascending
  113. $¢_build_page('en/weblog/index_ol_ascending.xhtml', array(
  114. 'title' => 'Weblog',
  115. 'copyright year' => "2015-$latest_copyright_year",
  116. 'body' => $list_ascending,
  117. ));
  118. // Descending
  119. $¢_build_page('en/weblog/index_ol_descending.xhtml', array(
  120. 'title' => 'Weblog',
  121. 'copyright year' => "2015-$latest_copyright_year",
  122. 'body' => $list_descending,
  123. ));
  124. // The latest weblog entry should always be available on this page:
  125. copy(__DIR__."/../compiled$latest_entry[day]", __DIR__.'/../compiled/en/weblog/latest.xhtml');
  126. $should_exist['en/weblog/latest.xhtml'] = true;
  127. // The latest weblog month index should always be available on this page:
  128. copy(__DIR__."/../compiled$latest_entry[month]/index.xhtml", __DIR__.'/../compiled/en/weblog/latest_month.xhtml');
  129. $should_exist['en/weblog/latest_month.xhtml'] = true;
  130. // The latest weblog year index should always be available on this page:
  131. copy(__DIR__."/../compiled$latest_entry[year]/index.xhtml", __DIR__.'/../compiled/en/weblog/latest_year.xhtml');
  132. $should_exist['en/weblog/latest_year.xhtml'] = true;
  133. /*
  134. // RSS feed (I need more information to complete this. What is the correct XML namespace to use?):
  135. $build_date = new DateTime();
  136. $RSS_feed = <<<END
  137. <?xml version="1.0" encoding="utf-8"?>
  138. <!--
  139. <https://y.st./>
  140. Copyright (C) 2015-2016 //y.st. <mailto:copyright@y.st>
  141. This program is free software: you can redistribute it and/or modify
  142. it under the terms of the GNU General Public License as published by
  143. the Free Software Foundation, either version 3 of the License, or
  144. (at your option) any later version.
  145. This program is distributed in the hope that it will be useful,
  146. but WITHOUT ANY WARRANTY; without even the implied warranty of
  147. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  148. GNU General Public License for more details.
  149. You should have received a copy of the GNU General Public License
  150. along with this program. If not, see <http://www.gnu.org./licenses/>.
  151. -->
  152. <rss version="2.0">
  153. <channel>
  154. <title>Yst Dawson&apos;s weblog</title>
  155. <description>My daily journal</description>
  156. <link>https://authorednansyxlu.onion/en/weblog/</link>
  157. <lastBuildDate>{$build_date->format(DateTime::RSS)}</lastBuildDate>
  158. <pubDate>Wed, 09 Mar 2016 15:35:57 -0800</pubDate>
  159. <ttl>1800</ttl>
  160. END;
  161. foreach($RSS_entry as $RSS_item):
  162. require __DIR__."/pages/en/weblog/$RSS_item[path].xhtml";
  163. $RSS_feed .= <<<END
  164. <item>
  165. <title>$xhtml[title]</title>
  166. <!-- description>Not implemented</description -->
  167. <link>https://authorednansyxlu.onion/en/weblog/$RSS_item[path].xhtml</link>
  168. <guid isPermaLink="true">https://authorednansyxlu.onion/en/weblog/$RSS_item[path].xhtml</guid>
  169. <pubDate>$RSS_item[date]</pubDate>
  170. </item>
  171. END;
  172. endforeach;
  173. $RSS_feed .= "\t</channel>\n</rss>\n";
  174. */