No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ---
  2. layout: homepage
  3. title: Stuff and Things
  4. excerpt:
  5. ---
  6. <?php
  7. require_once('../private/_config.php');
  8. $dsn = 'mysql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'] . ';charset=' . $config['db']['charset'];
  9. $user = $config['db']['user'];
  10. $password = $config['db']['password'];
  11. // TODO: consider changing .foreign-url to mf2 'syndicate'
  12. $html_template = <<<EOT
  13. <li class="%s">
  14. <figure class="h-entry chr-card">
  15. <figcaption class="p-name chr-card__title">%s</figcaption>
  16. <blockquote class="e-content chr-card__content" cite="%s">
  17. %s
  18. </blockquote>
  19. <footer>
  20. <!-- TODO: link to specific types -->
  21. <!-- TODO: JS progressive enhancement brings data in stream instead of navigating to other page -->
  22. <a class="interactions-link" href="http://chromic.org/update/%s#interactions">
  23. <ul class="interaction-icons" data-webmention-count data-url="https://chromic.org/update/%s">
  24. <li class="interaction-icon comments">
  25. <span class="num">0</span>
  26. <span class="fa fa-comments"></span>
  27. <span class="sr-only">mentions</span>
  28. </li>
  29. <li class="interaction-icon likes">
  30. <span class="num">0</span>
  31. <span class="fa fa-heart"></span>
  32. <span class="sr-only">likes</span>
  33. </li>
  34. <li class="interaction-icon repeats">
  35. <span class="num">0</span>
  36. <span class="fa fa-recycle"></span>
  37. <span class="sr-only">repeats</span>
  38. </li>
  39. </ul>
  40. </a>
  41. <a class="u-url" href="/update/%s">
  42. <time class="dt-published timeago" datetime="%s">%s</time>
  43. </a>
  44. via
  45. <a class="foreign-url" href="%s">
  46. <img class="foreign-service" src="/images/homepage/%s.png" title="%s" alt="%s">
  47. </a>
  48. </footer>
  49. </figure>
  50. </li>
  51. EOT;
  52. try {
  53. $dbh = new PDO($dsn, $user, $password);
  54. } catch (PDOException $e) {
  55. die('Connection failed: ' . $e->getMessage());
  56. }
  57. $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
  58. // If GET[page] was set to an invalid int,
  59. // $page will be 0. We don't want that.
  60. if ($page === 0) {
  61. $page = 1;
  62. }
  63. $limit = ($page - 1) * 10 . ", 10"; // 10 items per page
  64. $sql = 'SELECT event.id, title, content, published, foreign_url, object_type, object_verb, subscription.type FROM event ' .
  65. 'INNER JOIN subscription ON event.subscription_id = subscription.id ' .
  66. 'ORDER BY published DESC LIMIT ' . $limit;
  67. $res = $dbh->query($sql);
  68. $html = '<ol class="stream__activities">';
  69. $nbRows = 0;
  70. $datePublished = new DateTime();
  71. $tz = new DateTimeZone("America/Toronto");
  72. $utc = new DateTimeZone("UTC");
  73. while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
  74. $nbRows++;
  75. $datePublished->setTimeZone($utc);
  76. $datePublished->modify(str_replace(' ', 'T', $row['published']) . '+00:00');
  77. $datePublished->setTimeZone($tz);
  78. $classAttrVal = implode(' ', array($row['type'], $row['object_type'], $row['object_verb']));
  79. $html .= sprintf(
  80. $html_template,
  81. $classAttrVal,
  82. $row['title'],
  83. $row['foreign_url'],
  84. $row['content'],
  85. $row['id'],
  86. $row['id'],
  87. $row['id'],
  88. $datePublished->format('c'),
  89. $datePublished->format('Y-m-d H:i:s (T)'),
  90. $row['foreign_url'],
  91. $row['type'],
  92. $row['type'],
  93. $row['type']
  94. );
  95. }
  96. $html .= '</ol>' . "\n";
  97. $html .= '<nav class="pagination" role="navigation">' . "\n";
  98. if ($page !== 1) {
  99. $html .= '<a rel="next" class="btn" href="?page=' . ($page - 1) . '">Newer</a>' . "\n";
  100. }
  101. // Print next link
  102. // Note: this will link to an empty page when total number of events
  103. // is a multiple of 10.
  104. if ($nbRows === 10) {
  105. $html .= '<a rel="prev" class="btn" href="?page=' . ($page + 1) . '">Older</a>' . "\n";
  106. }
  107. echo $html . '</nav>' . "\n";
  108. ?>
  109. <script>
  110. ( function() {
  111. "use strict";
  112. window.ls = {
  113. "port": <?php echo $config['websockets']['port'] ?>,
  114. "secure_port": <?php echo $config['websockets']['secure_port'] ?>
  115. }
  116. }() );
  117. </script>