block_comments.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * The comments block
  18. *
  19. * @package block_comments
  20. * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. // Obviously required
  25. require_once($CFG->dirroot . '/comment/lib.php');
  26. class block_comments extends block_base {
  27. function init() {
  28. $this->title = get_string('pluginname', 'block_comments');
  29. }
  30. function specialization() {
  31. // require js for commenting
  32. comment::init();
  33. }
  34. function applicable_formats() {
  35. return array('all' => true);
  36. }
  37. function instance_allow_multiple() {
  38. return false;
  39. }
  40. function get_content() {
  41. global $CFG, $PAGE;
  42. if ($this->content !== NULL) {
  43. return $this->content;
  44. }
  45. if (!$CFG->usecomments) {
  46. $this->content = new stdClass();
  47. $this->content->text = '';
  48. if ($this->page->user_is_editing()) {
  49. $this->content->text = get_string('disabledcomments');
  50. }
  51. return $this->content;
  52. }
  53. $this->content = new stdClass();
  54. $this->content->footer = '';
  55. $this->content->text = '';
  56. if (empty($this->instance)) {
  57. return $this->content;
  58. }
  59. list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
  60. $args = new stdClass;
  61. $args->context = $PAGE->context;
  62. $args->course = $course;
  63. $args->area = 'page_comments';
  64. $args->itemid = 0;
  65. $args->component = 'block_comments';
  66. $args->linktext = get_string('showcomments');
  67. $args->notoggle = true;
  68. $args->autostart = true;
  69. $args->displaycancel = false;
  70. $comment = new comment($args);
  71. $comment->set_view_permission(true);
  72. $comment->set_fullwidth();
  73. $this->content = new stdClass();
  74. $this->content->text = $comment->output(true);
  75. $this->content->footer = '';
  76. return $this->content;
  77. }
  78. }