.tb.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. # Chemin vers la racine de l'application (si vous changer le fichier de place)
  23. $app_path = '/';
  24. require dirname(__FILE__).$app_path.'/inc/prepend.php';
  25. # Si on est là, alors on a un _POST
  26. # Connexion et création du blog
  27. header('Content-Type: text/xml');
  28. echo '<?xml version="1.0" encoding="'.dc_encoding.'"?>'."\n";
  29. echo '<response>'."\n";
  30. $content = '';
  31. if (empty($_GET['id']))
  32. {
  33. $content = '<error>1</error>'."\n".
  34. '<message>No ID.</message>';
  35. }
  36. else
  37. {
  38. $id = $_GET['id'];
  39. $con = new Connection(DB_USER,DB_PASS,DB_HOST,DB_DBASE);
  40. if($con->error())
  41. {
  42. $content = '<error>1</error>'."\n".
  43. '<message>MySQL connection error : '.$con->error().'</message>';
  44. }
  45. else
  46. {
  47. $blog = new blog($con,DB_PREFIX,1,dc_encoding);
  48. $blog->setURL('post',dc_blog_url.dc_format_post_url);
  49. $post = $blog->getPostByID($id);
  50. if ($post->isEmpty())
  51. {
  52. $content = '<error>1</error>'."\n".
  53. '<message>No post for this ID.</message>';
  54. }
  55. elseif (!dc_allow_trackbacks || !$post->f('post_open_tb')
  56. || (dc_comments_ttl!=0 && time()-(dc_comments_ttl*86400) > $post->getTS()))
  57. {
  58. $content = '<error>1</error>'."\n".
  59. '<message>Trackbacks are not allowed for this post or weblog.</message>';
  60. }
  61. elseif (isset($_REQUEST['__info']))
  62. {
  63. $content =
  64. '<error>0</error>'."\n".
  65. '<engine>DotClear</engine>'."\n".
  66. '<version>'.DC_VERSION.'</version>'."\n".
  67. '<encoding>'.dc_encoding.'</encoding>'."\n";
  68. }
  69. elseif (!empty($_REQUEST['__mode']) && $_REQUEST['__mode'] == 'rss')
  70. {
  71. $tb_url = 'http://'.$_SERVER['HTTP_HOST'].dc_trackback_uri.'&amp;id='.$id;
  72. if ($post->f('post_chapo') != '') {
  73. $post_excerpt = $post->f('post_chapo');
  74. } else {
  75. $post_excerpt = $post->f('post_content');
  76. }
  77. $post_excerpt = util::cutString(strip_tags($post_excerpt),255);
  78. $content =
  79. '<error>0</error>'."\n".
  80. '<rss version="0.91"><channel>'."\n".
  81. '<title>'.dc_blog_name.' - Trackback</title>'."\n".
  82. '<link>'.$tb_url.'</link>'."\n".
  83. '<description>TrackBack item for this blog</description>'."\n".
  84. '<language>fr</language>'."\n".
  85. '<item>'."\n".
  86. '<title>'.$blog->toXML($post->f('post_titre'),0).'</title>'."\n".
  87. '<link>http://'.$_SERVER['HTTP_HOST'].$post->getPermURL().'</link>'."\n".
  88. '<description>'.$post_excerpt.'</description>'."\n".
  89. '</item>'."\n".
  90. '</channel>'."\n".
  91. '</rss>';
  92. }
  93. elseif (empty($_REQUEST['url']))
  94. {
  95. $content =
  96. '<error>1</error>'."\n".
  97. '<message>URL parameter is requiered.</message>';
  98. }
  99. else
  100. {
  101. $url = $_REQUEST['url'];
  102. $title = (!empty($_REQUEST['title'])) ? $_REQUEST['title'] : $url;
  103. $excerpt = (!empty($_REQUEST['excerpt'])) ? $_REQUEST['excerpt'] : '';
  104. $blog_name = (!empty($_REQUEST['blog_name'])) ? $_REQUEST['blog_name'] : '';
  105. if (trim($title) == '') {
  106. $title = $url;
  107. }
  108. if (strlen($excerpt) > 255) {
  109. $excerpt = util::cutString($excerpt,252).'...';
  110. }
  111. # On poste de l'UTF-8 ou pas ?
  112. if (dc_encoding == 'UTF-8' && (empty($_REQUEST['utf8']) || $_REQUEST['utf8'] != 1))
  113. {
  114. $title = utf8_encode($title);
  115. $excerpt = utf8_encode($excerpt);
  116. $blog_name = utf8_encode($blog_name);
  117. }
  118. $comment = '<!-- TB -->'."\n".
  119. '<p><strong>'.$title.'</strong></p>'."\n".
  120. '<p>'.$excerpt.'</p>';
  121. if ($blog->addComment($id,$blog_name,'',$url,$comment,true) !== false)
  122. {
  123. $content = '<error>0</error>';
  124. if (dc_comment_notification && $post->f('user_email') != '')
  125. {
  126. $n_titre = $blog->removeEntities($post->f('post_titre'));
  127. $n_mail = $post->f('user_email');
  128. $n_subject = util::mimeEncode('['.dc_blog_name.'] '.$n_titre,dc_encoding);
  129. $n_content =
  130. sprintf(__('Trackback for entry %s'),$n_titre)."\n\n".
  131. sprintf(__('By: %s'),$blog_name)."\n".
  132. sprintf(__('Website: %s'),$url)."\n".
  133. "\n".$title."\n\n".$excerpt."\n".
  134. "--\n".
  135. 'http://'.$_SERVER['HTTP_HOST'].$post->getPermURL();
  136. $n_headers =
  137. 'From: '.$n_mail."\r\n".
  138. 'Content-Type: text/plain; charset='.dc_encoding.";\r\n".
  139. "X-Mailer: DotClear\r\n".
  140. 'X-Blog: http://'.$_SERVER['HTTP_HOST'].dc_blog_url;
  141. @mail($n_mail,$n_subject,$n_content,$n_headers);
  142. }
  143. }
  144. else
  145. {
  146. $err = $blog->error(0);
  147. $content =
  148. '<error>1</error>'."\n".
  149. '<message>'.$err[0][1].'</message>';
  150. }
  151. }
  152. $con->close();
  153. }
  154. }
  155. echo $content."\n";
  156. echo '</response>';
  157. ?>