$deleteComment->loadComment(); if ($deleteComment->isValid() && $gContent->hasUserPermission('p_liberty_admin_comments')) { // delete entire thread $deleteComment->expunge(); } } if (@BitBase::verifyId($_REQUEST['post_comment_id']) && $gContent->hasUserPermission('p_liberty_post_comments')) { $post_comment_id = $_REQUEST['post_comment_id']; $editComment = new LibertyComment($post_comment_id); //if we are passed a comment id but not going to store it then turn off ajax if (!isset($_REQUEST['post_comment_submit']) && !isset($_REQUEST['post_comment_cancel'])) { //even if ajax is on - we force it off in this case $gBitSmarty->assign('comments_ajax', FALSE); } if ($editComment->mInfo['content_id']) { if ($editComment->userCanUpdate($gContent)) { $postComment['data'] = $editComment->mInfo['data']; $postComment['title'] = $editComment->mInfo['title']; } else { $formfeedback['error'] = "You do not have permission to edit this comment."; $editComment = NULL; $post_comment_id = NULL; } } else { $formfeedback['error'] = "Comment does not exist."; $editComment = NULL; $post_comment_id = NULL; } } else { $post_comment_id = NULL; $editComment = NULL;
function getComments($pContentId = NULL, $pMaxComments = NULL, $pOffset = NULL, $pSortOrder = NULL, $pDisplayMode = NULL) { if ($pDisplayMode != "flat") { if ($pSortOrder == "commentDate_asc") { $pSortOrder = 'thread_asc'; } else { $pSortOrder = 'thread_desc'; } } $contentId = NULL; $ret = array(); if (!$pContentId && $this->mContentId) { $contentId = $this->mContentId; } elseif ($pContentId) { $contentId = $pContentId; } $mid = ""; $sort_order = "ASC"; $mid = 'created ASC'; if (!empty($pSortOrder)) { if ($pSortOrder == 'commentDate_desc') { $mid = 'created DESC'; } else { if ($pSortOrder == 'commentDate_asc') { $mid = 'created ASC'; } elseif ($pSortOrder == 'thread_asc') { $mid = 'thread_forward_sequence ASC'; // thread newest first is harder... } elseif ($pSortOrder == 'thread_desc') { $mid = 'thread_reverse_sequence ASC'; } else { $mid = $this->mDb->convertSortmode($pSortOrder); } } } $mid = 'order by ' . $mid; $bindVars = array(); if (is_array($pContentId)) { $mid2 = 'in (' . implode(',', array_fill(0, count($pContentId), '?')) . ')'; $bindVars = $pContentId; $select1 = ', lcp.`content_type_guid` as parent_content_type_guid, lcp.`title` as parent_title '; $join1 = " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content` lcp ON (lcp.`content_id` = lcom.`parent_id`) "; } elseif ($pContentId) { $mid2 = '=?'; $bindVars = array($pContentId); $select1 = ''; $join1 = ''; } $joinSql = $selectSql = $whereSql = ''; $pListHash = array('content_id' => $contentId, 'max_records' => $pMaxComments, 'offset' => $pOffset, 'sort_mode' => $pSortOrder, 'display_mode' => $pDisplayMode, 'has_comment_view_perm' => TRUE); $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, $this, $pListHash); if ($pContentId) { $sql = "SELECT lcom.`comment_id`, lcom.`parent_id`, lcom.`root_id`, lcom.`thread_forward_sequence`, lcom.`thread_reverse_sequence`, lcom.`anon_name`, lc.*, uu.`email`, uu.`real_name`, uu.`login` {$selectSql} {$select1}\n\t\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_comments` lcom\n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON (lcom.`content_id` = lc.`content_id`)\n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON (lc.`user_id` = uu.`user_id`) {$joinSql} {$join1}\n\t\t\t\t WHERE lcom.root_id {$mid2} {$whereSql} {$mid}"; $flat_comments = array(); if ($result = $this->mDb->query($sql, $bindVars, $pMaxComments, $pOffset)) { while ($row = $result->FetchRow()) { $row['parsed_data'] = $this->parseData($row); $row['level'] = substr_count($row['thread_forward_sequence'], '.') - 1; $c = new LibertyComment(); $c->mInfo = $row; $c->mRootObj = $this->getRootObj(); $row['is_editable'] = $c->userCanUpdate($c->mRootObj); global $gBitSystem; if ($gBitSystem->isFeatureActive('comments_allow_attachments')) { // get attachments for each comment global $gLibertySystem; $query = "SELECT * FROM `" . BIT_DB_PREFIX . "liberty_attachments` la WHERE la.`content_id`=? ORDER BY la.`pos` ASC, la.`attachment_id` ASC"; if ($result2 = $this->mDb->query($query, array((int) $row['content_id']))) { while ($row2 = $result2->fetchRow()) { if ($func = $gLibertySystem->getPluginFunction($row2['attachment_plugin_guid'], 'load_function', 'mime')) { // we will pass the preferences by reference that the plugin can easily update them if (empty($row['storage'][$row2['attachment_id']])) { $row['storage'][$row2['attachment_id']] = array(); } $row['storage'][$row2['attachment_id']] = $func($row2, $row['storage'][$row2['attachment_id']]); } else { print "No load_function for " . $row2['attachment_plugin_guid']; } } } // end get attachements for each comment } $flat_comments[$row['content_id']] = $row; } } # now select comments wanted $ret = $flat_comments; } return $ret; }