From 21afd0461daf596ad07e1759ea697479b6d4c9f4 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Mon, 27 Jul 2009 07:32:56 +0000 Subject: [PATCH] "MDL-19118, remove moodleforms, check contextlevel, remove trailing whitespace" --- comment/comment_ajax.php | 6 +++- comment/comment_post.php | 8 +++-- lib/commentlib.php | 70 +++++++++++++++++++--------------------- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/comment/comment_ajax.php b/comment/comment_ajax.php index f1cd0f2afc..93c9bb232c 100644 --- a/comment/comment_ajax.php +++ b/comment/comment_ajax.php @@ -25,7 +25,11 @@ $courseid = optional_param('courseid', SITEID, PARAM_INT); $contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT); $context = get_context_instance_by_id($contextid); -$cm = get_coursemodule_from_id('', $context->instanceid); +if ($context->contextlevel == CONTEXT_MODULE) { + $cm = get_coursemodule_from_id('', $context->instanceid); +} else { + $cm = null; +} require_login($courseid, true, $cm); $err = new stdclass; diff --git a/comment/comment_post.php b/comment/comment_post.php index ca557f370d..9ebad5d70f 100644 --- a/comment/comment_post.php +++ b/comment/comment_post.php @@ -25,7 +25,11 @@ $courseid = optional_param('courseid', SITEID, PARAM_INT); $contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT); $context = get_context_instance_by_id($contextid); -$cm = get_coursemodule_from_id('', $context->instanceid); +if ($context->contextlevel == CONTEXT_MODULE) { + $cm = get_coursemodule_from_id('', $context->instanceid); +} else { + $cm = null; +} require_login($courseid, true, $cm); $err = new stdclass; @@ -60,7 +64,7 @@ switch ($action) { case 'add': $cmt = $comment->add($content); if (!empty($cmt) && is_object($cmt)) { - redirect($returnurl, get_string('pageshouldredirect')); + redirect($returnurl, get_string('pageshouldredirect'), 0); } else if ($cmt === COMMENT_ERROR_DB) { print_error('dbupdatefailed'); } else if ($cmt === COMMENT_ERROR_MODULE_REJECT) { diff --git a/lib/commentlib.php b/lib/commentlib.php index 53ca35bd0c..a56dd3f55c 100644 --- a/lib/commentlib.php +++ b/lib/commentlib.php @@ -20,24 +20,6 @@ define('COMMENT_ERROR_INSUFFICIENT_CAPS', 2); define('COMMENT_ERROR_MODULE_REJECT', 3); require_once($CFG->dirroot.'/lib/formslib.php'); -class comment_form extends moodleform { - - // Define the form - function definition () { - global $USER, $CFG, $COURSE; - - $mform =& $this->_form; - - $mform->addElement('textarea', 'content', get_string('addcomment')); - $mform->addElement('hidden', 'contextid'); - $mform->addElement('hidden', 'itemid'); - $mform->addElement('hidden', 'area'); - $mform->addElement('hidden', 'courseid'); - $mform->addElement('hidden', 'returnurl'); - - $this->add_action_buttons(); - } -} /** * comment is class to process moodle comments * @@ -65,7 +47,7 @@ class comment { */ private $commentarea; /** - * itemid is used to associate with commenting content + * itemid is used to associate with commenting content * @var integer */ private $itemid; @@ -98,13 +80,12 @@ class comment { */ private $linktext; private static $nonjs = false; - private static $commentform = null; // will be used by non-js comments UI private static $comment_itemid = null; private static $comment_context = null; - private static $comment_area = null; + private static $comment_area = null; /** - * Construct function of comment class, initilize + * Construct function of comment class, initilize * class members * @param object $options */ @@ -153,7 +134,7 @@ class comment { // load template $this->template = <<___picture___ +
___picture___
___name___ - ___time___
___content___
@@ -192,7 +173,7 @@ EOD; self::$comment_context = optional_param('comment_context', '', PARAM_INT); self::$comment_area = optional_param('comment_area', '', PARAM_ALPHAEXT); if (!empty(self::$nonjs)) { - self::$commentform = new comment_form($CFG->httpswwwroot . '/comment/comment_post.php?action=add'); + //self::$commentform = new comment_form($CFG->httpswwwroot . '/comment/comment_post.php?action=add'); } $PAGE->requires->yui_lib('yahoo')->in_head(); @@ -253,7 +234,7 @@ EOD; /** * check posting comments permission * It will check based on user roles and ask modules - * If you need to check permission by modules, a + * If you need to check permission by modules, a * function named $pluginname_check_comment_post must be implemented */ private function _check_permissions() { @@ -269,7 +250,7 @@ EOD; /** * Prepare comment code in html - * @param boolean + * @param boolean $return * @return mixed */ public function init($return = true) { @@ -314,7 +295,7 @@ EOD; // print commenting icon and tooltip $html = << -{$this->linktext} +{$this->linktext} {$this->linktext}
@@ -330,7 +311,7 @@ EOD; $html .= <<
-
+ @@ -366,8 +347,8 @@ EOD; } /** - * Return matched comments - * @param int $page + * Return matched comments + * @param int $page * @return mixed */ public function get_comments($page = '') { @@ -407,7 +388,7 @@ EOD; $c->avatar = print_user_picture($user, $this->course->id, NULL, NULL, true); if (($USER->id == $c->userid) || !empty($candelete)) { $c->delete = true; - } + } $comments[] = $c; } } @@ -449,7 +430,7 @@ EOD; /** * Add a new comment - * @param string $content + * @param string $content * @return mixed */ public function add($content) { @@ -489,8 +470,8 @@ EOD; } /** - * delete a comment - * @param int $commentid + * Delete a comment + * @param int $commentid * @return mixed */ public function delete($commentid) { @@ -509,10 +490,10 @@ EOD; global $DB, $CFG; $html = ''; if (!(self::$comment_itemid == $this->options->itemid && - self::$comment_context == $this->options->context->id && + self::$comment_context == $this->options->context->id && self::$comment_area == $this->options->commentarea)) { $page = 0; - } + } $comments = $this->get_comments($page); $html .= '

'.get_string('comments').'

'; @@ -525,7 +506,22 @@ EOD; $html .= $list; $html .= ''; $html .= $this->get_pagination($page); - self::$commentform->set_data(array('itemid'=>$this->itemid, 'courseid'=>$this->course->id, 'contextid'=>$this->contextid, 'area'=>$this->commentarea, 'returnurl'=>qualified_me())); + $sesskey = sesskey(); + $returnurl = qualified_me(); + $strsubmit = get_string('submit'); + $html .= << + + + + + + + + + + +EOD; if ($return) { //ob_start(); //self::$commentform->display(); -- 2.39.5