tb.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. $title = strip_tags(trim($title));
  106. $excerpt = strip_tags($excerpt);
  107. $blog_name = strip_tags($blog_name);
  108. if ($title == '') {
  109. $title = $url;
  110. }
  111. if (strlen($excerpt) > 255) {
  112. $excerpt = util::cutString($excerpt,252).'...';
  113. }
  114. $is_utf8 = util::isUTF8($title) || util::isUTF8($excerpt) || util::isUTF8($blog_name);
  115. if (dc_encoding != 'UTF-8' && $is_utf8)
  116. {
  117. $title = utf8_decode($title);
  118. $excerpt = utf8_decode($excerpt);
  119. $blog_name = utf8_decode($blog_name);
  120. }
  121. elseif (dc_encoding == 'UTF-8' && !$is_utf8)
  122. {
  123. $title = utf8_encode($title);
  124. $excerpt = utf8_encode($excerpt);
  125. $blog_name = utf8_encode($blog_name);
  126. }
  127. $comment = '<!-- TB -->'."\n".
  128. '<p><strong>'.$title.'</strong></p>'."\n".
  129. '<p>'.$excerpt.'</p>';
  130. require_once dirname(__FILE__).'/'.DC_ECRIRE.'/tools/spamplemousse/inc/tb.php';
  131. if ($blog->addComment($id,$blog_name,'',$url,$comment,true) !== false)
  132. {
  133. $content = '<error>0</error>';
  134. if (dc_comment_notification && $post->f('user_email') != '')
  135. {
  136. $n_titre = $blog->removeEntities($post->f('post_titre'));
  137. $n_mail = $post->f('user_email');
  138. $n_subject = util::mimeEncode('['.dc_blog_name.'] '.$n_titre,dc_encoding);
  139. $n_content =
  140. sprintf(__('Trackback for entry %s'),$n_titre)."\n\n".
  141. sprintf(__('By: %s'),$blog_name)."\n".
  142. sprintf(__('Website: %s'),$url)."\n".
  143. "\n".$title."\n\n".$excerpt."\n".
  144. "--\n".
  145. 'http://'.$_SERVER['HTTP_HOST'].$post->getPermURL();
  146. $n_headers =
  147. 'From: '.$n_mail."\r\n".
  148. 'Content-Type: text/plain; charset='.dc_encoding.";\r\n".
  149. "X-Mailer: DotClear\r\n".
  150. 'X-Blog: http://'.$_SERVER['HTTP_HOST'].dc_blog_url;
  151. @mail($n_mail,$n_subject,$n_content,$n_headers);
  152. }
  153. }
  154. else
  155. {
  156. $err = $blog->error(0);
  157. $content =
  158. '<error>1</error>'."\n".
  159. '<message>'.$err[0][1].'</message>';
  160. }
  161. }
  162. $con->close();
  163. }
  164. }
  165. echo $content."\n";
  166. echo '</response>';
  167. ?>