get_template_vars('comments'); for ($i=0; $i < count($all_comments) ; $i++) { $comment = &$all_comments[$i]; if (isset($comment['U_DELETE'])) { $comment['U_ID'] = $this->getCommentId($comment['U_DELETE']); $comment['DATE'] .= ' - '; $comment['DATE'] .= 'Edit'; $comment['DATE'] .= ''; } } } /** * Check whether a comment edit or update is requested. */ function loc_end_index() { $comment_id = ""; $action = $this->isCommentEdit($_SERVER['QUERY_STRING'], $comment_id); switch ($action) { case CE_ACTION_EDIT: // Edit $this->editComment($comment_id); break; case CE_ACTION_UPDATE: $this->updateComment(); break; case CE_ACTION_NONE: // Not an edit mode break; } } /* ************************ */ /* ** Private functions ** */ /* ************************ */ function getTemplate($p_template = 'edit.tpl') { return realpath(CE_TEMPLATE . $p_template); } function isCommentEdit($p_query_string, &$p_comment_id) { $params = split('\&', $p_query_string); $action = CE_ACTION_NONE; $comment_id = ""; foreach ($params as $current_param) { $key_value = split('=', $current_param); if (isset($key_value[1])) { if (CE_ACTION == $key_value[0] && CE_ACTION_NONE == $action) { //CE_ACTION_EDIT == $lKeyVal[1] switch ($key_value[1]) { case CE_ACTION_EDIT: case CE_ACTION_UPDATE: $action = $key_value[1]; break; } } if (CE_ID == $key_value[0]) { $comment_id = $key_value[1]; } } } if (CE_ACTION_EDIT == $action) { $p_comment_id = $comment_id; } return $action; } function isEditAllowed($p_comment) { if (is_admin()) { return true; } global $user; return $p_comment->isAuthor($user['username']); } function editComment($p_comment_id) { // Include language advices load_language('plugin.lang', CE_PATH); $comment = new CE_Comment($p_comment_id); $infos = array(); if (!$this->isEditAllowed($comment)) { // Not allowed array_push($infos, l10n('comment_edit_forbidden')); $this->displayError($infos); return; } $this->displayComment($comment); } function updateComment() { // Include language advices load_language('plugin.lang', CE_PATH); $infos = array(); if (!isset($_POST['commentid'])) { array_push($infos, l10n('comment_access_invalid')); $this->displayError($infos); return; } $comment = new CE_Comment($_POST['commentid']); if (!$this->isEditAllowed($comment)) { array_push($infos, l10n('comment_edit_forbidden')); $this->displayError($infos); return; } if (isset($_POST['author'])) { $comment->setInfo('author', $_POST['author']); } else if (isset($_POST['freeauthorck'])) { // Free author $new_author = trim(stripslashes($_POST['freeauthor'])); $new_author = $comment->validateAuthor($new_author); $comment->setInfo('author', $new_author); } $comment_array = array( 'author' => trim( stripslashes($comment->getInfo('author')) ), 'content' => trim( stripslashes($_POST['content']) ), 'image_id' => $_POST['imageid'], 'comment_id' => $_POST['commentid'], ); $comment_action = update_user_comment($comment_array, @$_POST['key'], $infos ); switch ($comment_action) { case 'moderate': array_push( $infos, l10n('comment_to_validate') ); case 'validate': array_push( $infos, l10n('comment_added')); break; case 'reject': set_status_header(403); array_push($infos, l10n('comment_not_added') ); break; default: trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); } // allow plugins to notify what's going on trigger_action( 'user_comment_insertion', array_merge($comment_array, array('action'=>$comment_action))); if ($comment_action=='reject') { $this->displayError($infos); } else { $this->displayInfo($infos); } } function getCommentId($p_string_delete) { $comment_id = ""; $elements = split('\?', $p_string_delete); if (count($elements) > 1) { $elem_var = split('\&', $elements[1]); foreach ($elem_var as $var) { $key_value = split('=', $var); if (count($key_value) > 1) { switch ($key_value[0]) { case 'comment_to_delete': case 'delete': $comment_id = $key_value[1]; break; default: // No ID } } } } return $comment_id; } function displayError($p_error) { $this->displayMessage($p_error, CE_TYPE_ERROR, CE_ERRORS); } function displayInfo($p_info) { $this->displayMessage($p_info, CE_TYPE_INFO, CE_INFOS); } function displayMessage($p_message, $p_type, $p_image) { // Include language advices load_language('plugin.lang', CE_PATH); $messages = array(); foreach ($p_message as $message) { array_push($messages, $message); } $message_array = array( 'TYPE' => $p_type, 'IMG' => $p_image, 'TITLE' => l10n($p_type), 'MSG' => $messages ); global $template; $template->set_filenames(array('ce_message'=>$this->getTemplate('message.tpl'))); $template->block_html_head( '', '', $smarty, $repeat); $begin = 'PLUGIN_INDEX_CONTENT_BEFORE'; $template->assign('message', $message_array); $old_begin = $template->get_template_vars($begin); $template->assign($begin, $template->parse('ce_message', true)); $template->concat($begin, $old_begin); } function displayComment($p_comment) { global $template; $template->set_filenames(array('ce_edit'=>$this->getTemplate())); $template->block_html_head( '', '', $smarty, $repeat); $begin = 'PLUGIN_INDEX_CONTENT_BEFORE'; $end = 'PLUGIN_INDEX_CONTENT_AFTER'; $template->assign($begin, null); $template->assign($end, null); $tplComment = array( 'CONTENT' => $p_comment->getInfo('content'), 'KEY' => $p_comment->getInfo('comment_id'), 'AUTHOR' => $p_comment->getInfo('author'), 'IMAGE' => $p_comment->getInfo('image_id'), 'DISABLED' => !is_admin(), 'USERS' => CE_Comment::getUsers(), 'F_ACTION' => $this->getUpdateUrlPrefix(), 'FREEAUTHOR'=> ($p_comment->isKnownAuthor())?'':'checked="checked"' ); $template->assign('comment', $tplComment); $template->concat($begin, $template->parse('ce_edit', true)); } function getEditUrlPrefix() { return self::$url_prefix . CE_ACTION_EDIT . '&' . CE_ID . '='; } function getUpdateUrlPrefix() { return self::$url_prefix . CE_ACTION_UPDATE; } } ?>