atom.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. require dirname(__FILE__).'/inc/prepend.php';
  23. require dirname(__FILE__).'/layout/lib.cache.php';
  24. require dirname(__FILE__).'/layout/class.xblog.php';
  25. require dirname(__FILE__).'/layout/class.xblogpost.php';
  26. require dirname(__FILE__).'/layout/class.xblogcomment.php';
  27. $type = (!empty($_GET['type']) && $_GET['type'] == 'co') ? 'co' : 'blog';
  28. $cat = (!empty($_GET['cat'])) ? $_GET['cat'] : '';
  29. $lang = (!empty($_GET['lang'])) ? $_GET['lang'] : '';
  30. # Connexion MySQL
  31. $con = new Connection(DB_USER,DB_PASS,DB_HOST,DB_DBASE);
  32. if ($con->error()) { exit; }
  33. # Création de l'objet de type weblog avec uniquement les billets
  34. # publiés
  35. $blog = new xblog($con,DB_PREFIX,1,dc_encoding);
  36. $blog->rs_blogpost = 'xblogpost';
  37. $blog->rs_blogcomment = 'xblogcomment';
  38. $blog->setURL('post','http://'.$_SERVER['HTTP_HOST'].dc_blog_url.dc_format_post_url);
  39. # Si type = co on fait un fil des commentaires
  40. if ($type == 'co')
  41. {
  42. if (!empty($_GET['post'])) {
  43. $comments = $blog->getComments($_GET['post'],'DESC');
  44. } else {
  45. $comments = $blog->getComments('','DESC',20);
  46. }
  47. $title = dc_blog_name.' - Commentaires';
  48. $ts = time();
  49. $items = $seq = '';
  50. }
  51. else
  52. {
  53. # Dernières nouvelles
  54. $news = $blog->getLastNews(10,$cat,'post_dt DESC',false,$lang);
  55. $ts = strtotime($blog->getEarlierDate());
  56. $title = dc_blog_name;
  57. }
  58. # Cache HTTP
  59. if (dc_http_cache && defined('DC_UPDATE_FILE_W') && DC_UPDATE_FILE_W)
  60. {
  61. $mod_files = get_included_files();
  62. $mod_files[] = DC_UPDATE_FILE;
  63. $mod_files[] = dirname(__FILE__).'/conf/dotclear.ini';
  64. cache::http($mod_files);
  65. }
  66. header('Content-Type: text/xml; charset='.dc_encoding);
  67. echo '<?xml version="1.0" encoding="'.dc_encoding.'" ?>'."\n";
  68. /*
  69. echo '<?xml-stylesheet href="'.$rss_css.'" type="text/css"?>'."\n";
  70. //*/
  71. ?>
  72. <feed xmlns="http://purl.org/atom/ns#" version="0.3"
  73. xmlns:dc="http://purl.org/dc/elements/1.1/"
  74. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  75. xml:lang="<?php echo DC_LANG; ?>">
  76. <title><?php echo $blog->toXML($title); ?></title>
  77. <link rel="alternate" type="text/html" href="http://<?php echo $_SERVER['HTTP_HOST'].dc_blog_url; ?>"/>
  78. <tagline type="text/plain" mode="escaped"><?php echo htmlspecialchars(dc_blog_desc); ?></tagline>
  79. <modified><?php echo dt::iso8601($ts); ?></modified>
  80. <generator version="<?php echo DC_VERSION; ?>" url="http://www.dotclear.net/">DotClear</generator>
  81. <sy:updatePeriod>daily</sy:updatePeriod>
  82. <sy:updateFrequency>1</sy:updateFrequency>
  83. <sy:updateBase><?php echo dt::iso8601($ts); ?></sy:updateBase>
  84. <?php
  85. if ($type == 'co')
  86. {
  87. while(!$comments->EOF()) {
  88. echo $comments->getAtomEntry(dc_short_feeds);
  89. $comments->moveNext();
  90. }
  91. }
  92. else
  93. {
  94. while(!$news->EOF()) {
  95. echo $news->getAtomEntry(dc_short_feeds);
  96. $news->moveNext();
  97. }
  98. }
  99. $con->close();
  100. ?>
  101. </feed>