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.

updates.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. // composer
  3. require 'composer/autoload.php';
  4. use \FeedWriter\ATOM;
  5. // FIXME: De-dupe (/index.php, /updates/index.php)
  6. require_once('../private/_config.php');
  7. $dsn = 'mysql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'] . ';charset=' . $config['db']['charset'];
  8. $user = $config['db']['user'];
  9. $password = $config['db']['password'];
  10. try {
  11. $dbh = new PDO($dsn, $user, $password);
  12. } catch (PDOException $e) {
  13. die('Connection failed: ' . $e->getMessage());
  14. }
  15. $sql = 'SELECT event.id, title, content, published, foreign_url, object_type, object_verb, subscription.type FROM event ' .
  16. 'INNER JOIN subscription ON event.subscription_id = subscription.id ' .
  17. 'ORDER BY published DESC LIMIT 10';
  18. $res = $dbh->query($sql);
  19. $feed = new ATOM;
  20. $feed->setTitle('chimo\'s updates');
  21. $feed->setLink('https://chromic.org');
  22. $feed->setDate(new DateTime());
  23. $feed->setChannelElement('author', array('name' => 'chimo'));
  24. $feed->setSelfLink('https://chromic.org/updates.xml');
  25. $feed->setAtomLink('https://push.chromic.org', 'hub');
  26. while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
  27. $newItem = $feed->createNewItem();
  28. $newItem->setTitle(strip_tags($row['title']));
  29. $newItem->setLink('http://chromic.org/update/' . $row['id']);
  30. $newItem->setDate($row['published']);
  31. $newItem->setAuthor('chimo', 'chimo@chromic.org');
  32. $newItem->setContent($row['content']);
  33. $feed->addItem($newItem);
  34. }
  35. $feed->printFeed();