[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/comment/ -> comment_post.php (source)

   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  /*
  18   * Handling new comments from non-js comments interface
  19   *
  20   * @package   core
  21   * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  require_once('../config.php');
  25  require_once($CFG->dirroot . '/comment/lib.php');
  26  
  27  if (empty($CFG->usecomments)) {
  28      throw new comment_exception('commentsnotenabled', 'moodle');
  29  }
  30  
  31  $contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
  32  list($context, $course, $cm) = get_context_info_array($contextid);
  33  
  34  require_login($course, true, $cm);
  35  require_sesskey();
  36  
  37  $action    = optional_param('action',    '',  PARAM_ALPHA);
  38  $area      = optional_param('area',      '',  PARAM_AREA);
  39  $content   = optional_param('content',   '',  PARAM_RAW);
  40  $itemid    = optional_param('itemid',    '',  PARAM_INT);
  41  $returnurl = optional_param('returnurl', '/', PARAM_LOCALURL);
  42  $component = optional_param('component', '',  PARAM_COMPONENT);
  43  
  44  // Currently this script can only add comments
  45  if ($action !== 'add') {
  46      redirect($returnurl);
  47  }
  48  
  49  $cmt = new stdClass;
  50  $cmt->contextid = $contextid;
  51  $cmt->courseid  = $course->id;
  52  $cmt->cm        = $cm;
  53  $cmt->area      = $area;
  54  $cmt->itemid    = $itemid;
  55  $cmt->component = $component;
  56  $comment = new comment($cmt);
  57  
  58  if ($comment->can_post()) {
  59      $cmt = $comment->add($content);
  60      if (!empty($cmt) && is_object($cmt)) {
  61          redirect($returnurl);
  62      }
  63  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1