save.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Form for adding and editing comments
  4. *
  5. * @package Elgg
  6. *
  7. * @uses ElggEntity $vars['entity'] The entity being commented
  8. * @uses ElggComment $vars['comment'] The comment being edited
  9. * @uses bool $vars['inline'] Show a single line version of the form?
  10. * @uses bool $vars['is_edit_page'] Is this form on its own page?
  11. */
  12. if (!elgg_is_logged_in()) {
  13. return;
  14. }
  15. $entity = elgg_extract('entity', $vars);
  16. /* @var ElggEntity $entity */
  17. $comment = elgg_extract('comment', $vars);
  18. /* @var ElggComment $comment */
  19. $inline = elgg_extract('inline', $vars, false);
  20. $is_edit_page = elgg_extract('is_edit_page', $vars, false);
  21. $entity_guid_input = '';
  22. if ($entity) {
  23. $entity_guid_input = elgg_view('input/hidden', array(
  24. 'name' => 'entity_guid',
  25. 'value' => $entity->guid,
  26. ));
  27. }
  28. $comment_text = '';
  29. $comment_guid_input = '';
  30. if ($comment && $comment->canEdit()) {
  31. $entity_guid_input = elgg_view('input/hidden', array(
  32. 'name' => 'comment_guid',
  33. 'value' => $comment->guid,
  34. ));
  35. $comment_label = elgg_echo("generic_comments:edit");
  36. $submit_input = elgg_view('input/submit', array('value' => elgg_echo('save')));
  37. $comment_text = $comment->description;
  38. } else {
  39. $comment_label = elgg_echo("generic_comments:add");
  40. $submit_input = elgg_view('input/submit', array('value' => elgg_echo('comment')));
  41. }
  42. $cancel_button = '';
  43. if ($comment) {
  44. $cancel_button = elgg_view('input/button', array(
  45. 'value' => elgg_echo('cancel'),
  46. 'class' => 'elgg-button-cancel mlm',
  47. 'href' => $entity ? $entity->getURL() : '#',
  48. ));
  49. }
  50. if ($inline) {
  51. $comment_input = elgg_view('input/text', array(
  52. 'name' => 'generic_comment',
  53. 'value' => $comment_text,
  54. ));
  55. echo $comment_input . $entity_guid_input . $comment_guid_input . $submit_input;
  56. } else {
  57. $comment_input = elgg_view('input/longtext', array(
  58. 'name' => 'generic_comment',
  59. 'value' => $comment_text,
  60. ));
  61. $is_edit_page_input = elgg_view('input/hidden', array(
  62. 'name' => 'is_edit_page',
  63. 'value' => (int)$is_edit_page,
  64. ));
  65. echo <<<FORM
  66. <div>
  67. <label>$comment_label</label>
  68. $comment_input
  69. </div>
  70. <div class="elgg-foot">
  71. $is_edit_page_input
  72. $comment_guid_input
  73. $entity_guid_input
  74. $submit_input $cancel_button
  75. </div>
  76. FORM;
  77. }