/** * Handles a comment submission * * @copyright Vincent Furia 2005 * @author Vincent Furia, vinny01 AT users DOT sourceforge DOT net * @return string HTML (possibly a refresh) */ function handleSubmit() { global $_CONF, $_TABLES, $_USER, $LANG03; $display = ''; $type = COM_applyFilter($_POST['type']); $sid = COM_applyFilter($_POST['sid']); switch ($type) { case 'article': $commentcode = DB_getItem($_TABLES['stories'], 'commentcode', "sid = '{$sid}'" . COM_getPermSQL('AND') . " AND (draft_flag = 0) AND (date <= NOW()) " . COM_getTopicSQL('AND')); if (!isset($commentcode) || $commentcode != 0) { return COM_refresh($_CONF['site_url'] . '/index.php'); } $ret = CMT_saveComment(strip_tags($_POST['title']), $_POST['comment'], $sid, COM_applyFilter($_POST['pid'], true), 'article', COM_applyFilter($_POST['postmode'])); if ($ret == -1) { $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $sid); $url .= (strpos($url, '?') ? '&' : '?') . 'msg=15'; $display = COM_refresh($url); } elseif ($ret > 0) { // failure //FIXME: some failures should not return to comment form $display .= COM_siteHeader('menu', $LANG03[1]) . CMT_commentForm($_POST['title'], $_POST['comment'], $sid, COM_applyFilter($_POST['pid']), $type, $LANG03[14], COM_applyFilter($_POST['postmode'])) . COM_siteFooter(); } else { // success $comments = DB_count($_TABLES['comments'], 'sid', $sid); DB_change($_TABLES['stories'], 'comments', $comments, 'sid', $sid); COM_olderStuff(); // update comment count in Older Stories block $display = COM_refresh(COM_buildUrl($_CONF['site_url'] . "/article.php?story={$sid}")); } break; default: // assume plugin if (!($display = PLG_commentSave($type, strip_tags($_POST['title']), $_POST['comment'], $sid, COM_applyFilter($_POST['pid'], true), COM_applyFilter($_POST['postmode'])))) { $display = COM_refresh($_CONF['site_url'] . '/index.php'); } break; } return $display; }
/** * Plugin function that is called after comment form is submitted. * Needs to at least save the comment and check return value. * Add any additional logic your plugin may need to perform on comments. * * $title comment title * $comment comment text * $id Item id to which $cid belongs * $pid comment parent * $postmode 'html' or 'text' * */ function _mg_savecomment($title, $comment, $id, $pid, $postmode) { global $_CONF, $_MG_CONF, $_TABLES, $LANG03; $retval = ''; $title = strip_tags($title); $pid = COM_applyFilter($pid, true); $postmode = COM_applyFilter($postmode); $ret = CMT_saveComment($title, $comment, $id, $pid, 'mediagallery', $postmode); if ($ret > 0) { $retval = ''; if (SESS_isSet('glfusion.commentpresave.error')) { $retval = COM_showMessageText(SESS_getVar('glfusion.commentpresave.error'), '', true); SESS_unSet('glfusion.commentpresave.error'); } $retval .= CMT_commentform($title, $comment, $id, $pid, 'mediagallery', $LANG03[14], $postmode); return $retval; } else { $comments = DB_count($_TABLES['comments'], array('sid', 'type'), array(DB_escapeString($id), 'mediagallery')); DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', DB_escapeString($id)); return COM_refresh($_MG_CONF['site_url'] . "/media.php?s={$id}#comments"); } }
/** * article: saves a comment * * @param string $title comment title * @param string $comment comment text * @param string $id Item id to which $cid belongs * @param int $pid comment parent * @param string $postmode 'html' or 'text' * @return mixed false for failure, HTML string (redirect?) for success */ function plugin_savecomment_article($title, $comment, $id, $pid, $postmode) { global $_CONF, $_TABLES, $LANG03, $_USER; $retval = ''; $commentcode = DB_getItem($_TABLES['stories'], 'commentcode', "(sid = '{$id}') AND (draft_flag = 0) AND (date <= NOW())" . COM_getPermSQL('AND')); if (!isset($commentcode) || ($commentcode != 0 || TOPIC_hasMultiTopicAccess('article', $id) < 2)) { // Need read access of topics to post comment COM_redirect($_CONF['site_url'] . '/index.php'); } $ret = CMT_saveComment($title, $comment, $id, $pid, 'article', $postmode); if ($ret == -1) { $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $id); $url .= (strpos($url, '?') ? '&' : '?') . 'msg=15'; COM_redirect($url); } elseif ($ret > 0) { // failure // FIXME: some failures should not return to comment form $retval .= CMT_commentForm($title, $comment, $id, $pid, 'article', $LANG03[14], $postmode); if (!defined('COMMENT_ON_SAME_PAGE')) { $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG03[1])); } else { if (!COMMENT_ON_SAME_PAGE) { $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG03[1])); } } } else { // success $comments = DB_count($_TABLES['comments'], array('type', 'sid'), array('article', $id)); DB_change($_TABLES['stories'], 'comments', $comments, 'sid', $id); // Comment count in Older Stories block may have changed so delete cache $cacheInstance = 'olderarticles__'; // remove all olderarticles instances CACHE_remove_instance($cacheInstance); COM_redirect(COM_buildUrl($_CONF['site_url'] . "/article.php?story={$id}")); } return $retval; }
/** * article: saves a comment * * @param string $title comment title * @param string $comment comment text * @param string $id Item id to which $cid belongs * @param int $pid comment parent * @param string $postmode 'html' or 'text' * @return mixed false for failure, HTML string (redirect?) for success */ function plugin_savecomment_article($title, $comment, $id, $pid, $postmode) { global $_CONF, $_TABLES, $LANG03, $_USER; $retval = ''; $commentcode = DB_getItem($_TABLES['stories'], 'commentcode', "(sid = '" . DB_escapeString($id) . "') AND (draft_flag = 0) AND (date <= NOW())" . COM_getPermSQL('AND')); if (!isset($commentcode) || $commentcode != 0) { return COM_refresh($_CONF['site_url'] . '/index.php'); } $ret = CMT_saveComment($title, $comment, $id, $pid, 'article', $postmode); if ($ret > 0) { // failure $msg = ''; if (SESS_isSet('glfusion.commentpresave.error')) { $msg = COM_showMessageText(SESS_getVar('glfusion.commentpresave.error'), '', 1, 'error'); SESS_unSet('glfusion.commentpresave.error'); } else { if (empty($title) || empty($comment)) { $msg = COM_showMessageText($LANG03[12], '', 1, 'error'); } } $retval .= $msg . CMT_commentForm($title, $comment, $id, $pid, 'article', $LANG03[14], $postmode); } else { // success $comments = DB_count($_TABLES['comments'], array('type', 'sid'), array('article', $id)); DB_change($_TABLES['stories'], 'comments', $comments, 'sid', $id); COM_olderStuff(); // update comment count in Older Stories block $retval = COM_refresh(COM_buildUrl($_CONF['site_url'] . "/article.php?story={$id}#comments")); } return $retval; }