PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/comment.php

http://github.com/s9y/Serendipity
PHP | 237 lines | 202 code | 24 blank | 11 comment | 54 complexity | 5a8f41e27a73578afaaf451bf4cea9cb MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
  3. # All rights reserved. See LICENSE file for licensing details
  4. #if ($_REQUEST['type'] == 'trackback') die('Disabled');
  5. include('serendipity_config.inc.php');
  6. include S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
  7. header('Content-Type: text/html; charset=' . LANG_CHARSET);
  8. $raw_post_data = file_get_contents("php://input");
  9. if (isset($serendipity['GET']['delete'], $serendipity['GET']['entry'], $serendipity['GET']['type']) && serendipity_checkFormToken()) {
  10. serendipity_deleteComment($serendipity['GET']['delete'], $serendipity['GET']['entry'], $serendipity['GET']['type']);
  11. if (serendipity_isResponseClean($_SERVER['HTTP_REFERER']) && preg_match('@^https?://' . preg_quote($_SERVER['HTTP_HOST'], '@') . '@imsU', $_SERVER['HTTP_REFERER'])) {
  12. header('Status: 302 Found');
  13. header('Location: '. $_SERVER['HTTP_REFERER']);
  14. exit;
  15. }
  16. }
  17. if (isset($serendipity['GET']['switch'], $serendipity['GET']['entry']) && serendipity_checkFormToken()) {
  18. serendipity_allowCommentsToggle($serendipity['GET']['entry'], $serendipity['GET']['switch']);
  19. }
  20. if (!empty($_REQUEST['c']) && !empty($_REQUEST['hash'])) {
  21. $res = serendipity_confirmMail($_REQUEST['c'], $_REQUEST['hash']);
  22. $serendipity['view'] = 'notification';
  23. $serendipity['GET']['action'] = 'custom';
  24. $serendipity['smarty_custom_vars'] = array(
  25. 'content_message' => ($res ? NOTIFICATION_CONFIRM_MAIL : NOTIFICATION_CONFIRM_MAIL_FAIL),
  26. 'subscribe_confirm_error' => !$res,
  27. 'subscribe_confirm_success' => $res,
  28. );
  29. include S9Y_INCLUDE_PATH . 'include/genpage.inc.php';
  30. $serendipity['smarty']->display(serendipity_getTemplateFile('index.tpl', 'serendipityPath'));
  31. exit;
  32. }
  33. if (!empty($_REQUEST['optin'])) {
  34. $res = serendipity_commentSubscriptionConfirm($_REQUEST['optin']);
  35. $serendipity['view'] = 'notification';
  36. $serendipity['GET']['action'] = 'custom';
  37. $serendipity['smarty_custom_vars'] = array(
  38. 'content_message' => ($res ? NOTIFICATION_CONFIRM_SUBMAIL : NOTIFICATION_CONFIRM_SUBMAIL_FAIL),
  39. 'subscribe_confirm_error' => !$res,
  40. 'subscribe_confirm_success' => $res,
  41. );
  42. include S9Y_INCLUDE_PATH . 'include/genpage.inc.php';
  43. $serendipity['smarty']->display(serendipity_getTemplateFile('index.tpl', 'serendipityPath'));
  44. exit;
  45. }
  46. serendipity_rememberComment();
  47. // Trackback logging. For developers: can be switched to true!
  48. $tb_logging = false;
  49. // Pingback logging. For developers: can be switched to true!
  50. $pb_logging = false;
  51. if ($pb_logging) {
  52. log_pingback('CONTENT_TYPE: ' . $_SERVER['CONTENT_TYPE']);
  53. log_pingback('HTTP_RAW_POST_DATA: ' . $tmp);
  54. }
  55. if (!($type = @$_REQUEST['type'])) {
  56. if ($pb_logging) {
  57. ob_start();
  58. print_r($raw_post_data);
  59. $tmp = ob_get_contents();
  60. ob_end_clean();
  61. log_pingback('NO TYPE HANDED!');
  62. }
  63. // WordPress pingbacks don't give any parameter. If it is a XML POST asume it's a pigback
  64. if ($_SERVER['CONTENT_TYPE'] == 'text/xml' && isset($raw_post_data)) {
  65. $type = 'pingback';
  66. }
  67. else {
  68. $type = 'normal';
  69. }
  70. }
  71. if ($type == 'trackback') {
  72. if ($tb_logging) {
  73. ob_start();
  74. print_r($_REQUEST);
  75. $tmp = ob_get_contents();
  76. ob_end_clean();
  77. log_trackback('RECEIVED TRACKBACK');
  78. log_trackback($tmp);
  79. }
  80. $uri = $_SERVER['REQUEST_URI'];
  81. if (isset($_REQUEST['entry_id'])) {
  82. $id = (int)$_REQUEST['entry_id'];
  83. } else if ($_REQUEST['amp;entry_id']) {
  84. // For possible buggy variable transmission caused by an intermediate CVS-release of s9y
  85. $id = (int)$_REQUEST['amp;entry_id'];
  86. } else if (preg_match('@/(\d+)_[^/]*$@', $uri, $matches)) {
  87. $id = (int)$matches[1];
  88. }
  89. log_trackback('Match on ' . $uri);
  90. log_trackback('ID: ' . $id);
  91. if (add_trackback($id, $_REQUEST['title'], $_REQUEST['url'], $_REQUEST['blog_name'], $_REQUEST['excerpt'])) {
  92. log_trackback('TRACKBACK SUCCESS');
  93. report_trackback_success();
  94. } else {
  95. log_trackback('TRACKBACK FAILURE');
  96. report_trackback_failure();
  97. }
  98. } else if ($type == 'pingback') {
  99. if ($pb_logging) {
  100. log_pingback('RECEIVED PINGBACK');
  101. # PHP 4.2.2 way of doing things
  102. ob_start();
  103. print_r($raw_post_data);
  104. $tmp = ob_get_contents();
  105. ob_end_clean();
  106. log_pingback('HTTP_RAW_POST_DATA: ' .$tmp);
  107. }
  108. if (add_pingback($_REQUEST['entry_id'], $raw_post_data)) {
  109. log_pingback('PINGBACK SUCCESS');;
  110. report_pingback_success();
  111. } else {
  112. log_pingback('PINGBACK FAILURE');;
  113. report_pingback_failure();
  114. }
  115. } else {
  116. $id = (int)(!empty($serendipity['POST']['entry_id']) ? $serendipity['POST']['entry_id'] : $serendipity['GET']['entry_id']);
  117. $serendipity['head_subtitle'] = COMMENTS;
  118. $serendipity['smarty_file'] = 'commentpopup.tpl';
  119. serendipity_smarty_init();
  120. if ($id == 0) {
  121. return false;
  122. } else {
  123. $serendipity['smarty']->assign('entry_id', $id);
  124. }
  125. if (isset($_GET['success']) && $_GET['success'] == 'true') {
  126. $serendipity['smarty']->assign(
  127. array(
  128. 'is_comment_added' => true,
  129. 'comment_url' => serendipity_specialchars($_GET['url']) . '&amp;serendipity[entry_id]=' . $id,
  130. 'comment_string' => explode('%s', COMMENT_ADDED_CLICK)
  131. )
  132. );
  133. } else if (!isset($serendipity['POST']['submit'])) {
  134. if ($serendipity['GET']['type'] == 'trackbacks') {
  135. $query = "SELECT title, timestamp FROM {$serendipity['dbPrefix']}entries WHERE id = '". $id ."'";
  136. $entry = serendipity_db_query($query);
  137. $entry = serendipity_archiveURL($id, $entry[0]['title'], 'baseURL', true, array('timestamp' => $entry[0]['timestamp']));
  138. $serendipity['smarty']->assign(
  139. array(
  140. 'is_showtrackbacks' => true,
  141. 'comment_url' => $serendipity['baseURL'] . 'comment.php?type=trackback&amp;entry_id=' . $id,
  142. 'comment_entryurl' => $entry
  143. )
  144. );
  145. } else {
  146. $query = "SELECT id, last_modified, timestamp, allow_comments, moderate_comments FROM {$serendipity['dbPrefix']}entries WHERE id = '" . $id . "'";
  147. $ca = serendipity_db_query($query, true);
  148. $comment_allowed = serendipity_db_bool($ca['allow_comments']) || !is_array($ca) ? true : false;
  149. $serendipity['smarty']->assign(
  150. array(
  151. 'is_showcomments' => true,
  152. 'is_comment_allowed' => $comment_allowed
  153. )
  154. );
  155. if ($comment_allowed) {
  156. serendipity_displayCommentForm($id, '?', NULL, $serendipity['POST'], true, serendipity_db_bool($ca['moderate_comments']), $ca);
  157. }
  158. }
  159. } else {
  160. $comment['url'] = $serendipity['POST']['url'];
  161. $comment['comment'] = trim($serendipity['POST']['comment']);
  162. $comment['name'] = $serendipity['POST']['name'];
  163. $comment['email'] = $serendipity['POST']['email'];
  164. $comment['subscribe'] = $serendipity['POST']['subscribe'];
  165. $comment['parent_id'] = $serendipity['POST']['replyTo'];
  166. if (!empty($comment['comment'])) {
  167. if (serendipity_saveComment($id, $comment, 'NORMAL')) {
  168. $sc_url = $serendipity['baseURL'] . 'comment.php?serendipity[entry_id]=' . $id . '&success=true&url=' . urlencode($_SERVER['HTTP_REFERER']);
  169. if (serendipity_isResponseClean($sc_url)) {
  170. header('Status: 302 Found');
  171. header('Location: ' . $sc_url);
  172. }
  173. exit;
  174. } else {
  175. $serendipity['smarty']->assign(
  176. array(
  177. 'is_comment_notadded' => true,
  178. 'comment_url' => serendipity_specialchars($_SERVER['HTTP_REFERER']),
  179. 'comment_string' => explode('%s', COMMENT_NOT_ADDED_CLICK)
  180. )
  181. );
  182. }
  183. } else {
  184. $serendipity['smarty']->assign(
  185. array(
  186. 'is_comment_empty' => true,
  187. 'comment_url' => serendipity_specialchars($_SERVER['HTTP_REFERER']),
  188. 'comment_string' => explode('%s', EMPTY_COMMENT)
  189. )
  190. );
  191. }
  192. }
  193. $serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath'));
  194. }
  195. // Debug logging for pingback receiving
  196. function log_pingback($message){
  197. global $pb_logging;
  198. if ($pb_logging) {
  199. $fp = fopen('pingback.log', 'a');
  200. fwrite($fp, '[' . date('d.m.Y H:i') . '] ' . $message . "\n");
  201. fclose($fp);
  202. }
  203. }
  204. // Debug logging for trackback receiving
  205. function log_trackback($message){
  206. global $tb_logging;
  207. if ($tb_logging) {
  208. $fp = fopen('trackback2.log', 'a');
  209. fwrite($fp, '[' . date('d.m.Y H:i') . '] ' . $message . "\n");
  210. fclose($fp);
  211. }
  212. }
  213. /* vim: set sts=4 ts=4 expandtab : */