PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/plugin/comment.inc.php

https://github.com/miya5n/pukiwiki
PHP | 133 lines | 105 code | 19 blank | 9 comment | 26 complexity | 87a7a0553f462fc499e30309e4da1fb7 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // PukiWiki - Yet another WikiWikiWeb clone
  3. // $Id: comment.inc.php,v 1.41 2011/01/25 15:01:01 henoheno Exp $
  4. // Copyright (C)
  5. // 2002-2007 PukiWiki Developers Team
  6. // 2001-2002 Originally written by yu-ji
  7. // License: GPL v2 or (at your option) any later version
  8. //
  9. // Comment plugin
  10. define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
  11. define('PLUGIN_COMMENT_SIZE_MSG', 70);
  12. define('PLUGIN_COMMENT_SIZE_NAME', 15);
  13. // ----
  14. define('PLUGIN_COMMENT_FORMAT_MSG', '$msg');
  15. define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
  16. define('PLUGIN_COMMENT_FORMAT_NOW', '&new{$now};');
  17. define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
  18. function plugin_comment_action()
  19. {
  20. global $script, $vars, $now, $_title_updated, $_no_name;
  21. global $_msg_comment_collided, $_title_comment_collided;
  22. if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
  23. if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
  24. $vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs
  25. $head = '';
  26. $match = array();
  27. if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
  28. $head = & $match[1];
  29. $vars['msg'] = & $match[2];
  30. }
  31. if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
  32. $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
  33. if(isset($vars['name']) || ($vars['nodate'] != '1')) {
  34. $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
  35. $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
  36. $_now = ($vars['nodate'] == '1') ? '' :
  37. str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
  38. $comment = str_replace("\x08MSG\x08", $comment, PLUGIN_COMMENT_FORMAT_STRING);
  39. $comment = str_replace("\x08NAME\x08", $_name, $comment);
  40. $comment = str_replace("\x08NOW\x08", $_now, $comment);
  41. }
  42. $comment = '-' . $head . ' ' . $comment;
  43. $postdata = '';
  44. $comment_no = 0;
  45. $above = (isset($vars['above']) && $vars['above'] == '1');
  46. foreach (get_source($vars['refer']) as $line) {
  47. if (! $above) $postdata .= $line;
  48. if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
  49. if ($above) {
  50. $postdata = rtrim($postdata) . "\n" .
  51. $comment . "\n" .
  52. "\n"; // Insert one blank line above #commment, to avoid indentation
  53. } else {
  54. $postdata = rtrim($postdata) . "\n" .
  55. $comment . "\n";
  56. }
  57. }
  58. if ($above) $postdata .= $line;
  59. }
  60. $title = $_title_updated;
  61. $body = '';
  62. if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) {
  63. $title = $_title_comment_collided;
  64. $body = $_msg_comment_collided . make_pagelink($vars['refer']);
  65. }
  66. page_write($vars['refer'], $postdata);
  67. $retvars['msg'] = $title;
  68. $retvars['body'] = $body;
  69. $vars['page'] = $vars['refer'];
  70. return $retvars;
  71. }
  72. function plugin_comment_convert()
  73. {
  74. global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
  75. static $numbers = array();
  76. static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
  77. if (PKWK_READONLY) return ''; // Show nothing
  78. if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
  79. $comment_no = $numbers[$vars['page']]++;
  80. $options = func_num_args() ? func_get_args() : array();
  81. if (in_array('noname', $options)) {
  82. $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
  83. $_msg_comment . '</label>';
  84. } else {
  85. $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
  86. $_btn_name . '</label>' .
  87. '<input type="text" name="name" id="_p_comment_name_' .
  88. $comment_no . '" size="' . PLUGIN_COMMENT_SIZE_NAME .
  89. '" />' . "\n";
  90. }
  91. $nodate = in_array('nodate', $options) ? '1' : '0';
  92. $above = in_array('above', $options) ? '1' :
  93. (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
  94. $script = get_script_uri();
  95. $s_page = htmlsc($vars['page']);
  96. $string = <<<EOD
  97. <br />
  98. <form action="$script" method="post">
  99. <div>
  100. <input type="hidden" name="plugin" value="comment" />
  101. <input type="hidden" name="refer" value="$s_page" />
  102. <input type="hidden" name="comment_no" value="$comment_no" />
  103. <input type="hidden" name="nodate" value="$nodate" />
  104. <input type="hidden" name="above" value="$above" />
  105. <input type="hidden" name="digest" value="$digest" />
  106. $nametags
  107. <input type="text" name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
  108. <input type="submit" name="comment" value="$_btn_comment" />
  109. </div>
  110. </form>
  111. EOD;
  112. return $string;
  113. }
  114. ?>