diff options
| -rw-r--r-- | LibertyComment.php | 128 | ||||
| -rw-r--r-- | comments_inc.php | 16 | ||||
| -rw-r--r-- | templates/comments_post_inc.tpl | 14 | ||||
| -rw-r--r-- | templates/display_comment.tpl | 4 |
4 files changed, 59 insertions, 103 deletions
diff --git a/LibertyComment.php b/LibertyComment.php index 7803a36..ff3de03 100644 --- a/LibertyComment.php +++ b/LibertyComment.php @@ -3,7 +3,7 @@ * Management of Liberty Content * * @package liberty - * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyComment.php,v 1.27 2006/07/12 17:15:50 sylvieg Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyComment.php,v 1.28 2006/07/26 22:41:45 hash9 Exp $ * @author spider <spider@steelsun.com> */ @@ -109,10 +109,11 @@ class LibertyComment extends LibertyContent { $this->mInfo['thread_reverse_sequence'] = strtr($parent_sequence_forward . sprintf("%09d.",$this->mCommentId), '0123456789', '9876543210'); - $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_comments` (`comment_id`, `content_id`, `parent_id`, `root_id`, `thread_forward_sequence`, `thread_reverse_sequence`) VALUES (?,?,?,?,?,?)"; + $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_comments` (`comment_id`, `content_id`, `parent_id`, `root_id`, `anon_name`, `thread_forward_sequence`, `thread_reverse_sequence`) VALUES (?,?,?,?,?,?,?)"; $this->mDb->query($sql, array($this->mCommentId, $pStorageHash['content_id'], $pStorageHash['parent_id'], - $pStorageHash['root_id'], $this->mInfo['thread_forward_sequence'], $this->mInfo['thread_reverse_sequence'])); + $pStorageHash['root_id'], $pStorageHash['anon_name'], + $this->mInfo['thread_forward_sequence'], $this->mInfo['thread_reverse_sequence'])); $this->mInfo['parent_id'] = $pStorageHash['parent_id']; $this->mInfo['content_id'] = $pStorageHash['content_id']; $this->mInfo['root_id'] = $pStorageHash['root_id']; @@ -146,6 +147,12 @@ class LibertyComment extends LibertyContent { $sql = "DELETE FROM `".BIT_DB_PREFIX."liberty_comments` WHERE `comment_id` = ?"; $rs = $this->mDb->query($sql, array($this->mCommentId)); + if (method_exists($this,'expungeMetaData')) { + $this->expungeMetaData(); + } elseif ($gBitSystem->isPackageActive('bitboards')) { + BitBoardPost::expungeMetaData($this->mContentId); + } + if( LibertyAttachable::expunge() ) { $ret = TRUE; $this->mDb->CompleteTrans(); @@ -153,25 +160,24 @@ class LibertyComment extends LibertyContent { $this->mDb->RollbackTrans(); } } - return $ret; + return $ret; } function userCanEdit($pUserId = NULL) { global $gBitUser; if (empty($pUserId)) { - if (!empty($gBitUser)) { - return ($gBitUser->isAdmin() || $gBitUser->mUserId == $this->mInfo['user_id']); - } else { - return FALSE; - } + $tmpUser = new BitUser($pUserId); + $tmpUser->load(); + } else { + $tmpUser = $gBitUser; } - if ($pUserId == $this->mInfo['user_id']) { - return TRUE; + if($tmpUser->isRegistered()) { + return ($tmpUser->isAdmin() || ($tmpUser->mUserId == $this->mInfo['user_id'])); + } elseif($this->mInfo['user_id']==ANONYMOUS_USER_ID) { + return (($_SERVER['REMOTE_ADDR']==$this->mInfo['ip'])&&(($this->mInfo['created']-time())<3600)); } - $tmpUser = new BitUser($pUserId); - $tmpUser->load(); - return ($tmpUser->isAdmin()); + return FALSE; } /** @@ -235,10 +241,11 @@ class LibertyComment extends LibertyContent { // left outer join on root so updater works $query = "SELECT" - . " lcm.`comment_id` as comment_id, " - . " lc.`content_id` as content_id, " - . " lcm.`parent_id` as parent_id, " - . " lcm.`root_id` as root_id, " + . " lcm.`comment_id` AS comment_id, " + . " lc.`content_id` AS content_id, " + . " lcm.`parent_id` AS parent_id, " + . " lcm.`anon_name` AS anon_name, " + . " lcm.`root_id` AS root_id, " . " lc.`title` AS `content_title`, " . " rlc.`title` AS `root_content_title`, " . " lc.`created` as created, " @@ -327,90 +334,22 @@ class LibertyComment extends LibertyContent { FROM `".BIT_DB_PREFIX."liberty_comments` tc LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` tcn ON (tc.`content_id` = tcn.`content_id`) - where tc.root_id =? and last_modified < ? + where tc.`root_id` =? and `last_modified` < ? $mid"; $commentCount = $this->mDb->getOne($sql, array($contentId, $last_modified)); } return $commentCount; } - - //input is a set of nested hashes - //output is a single flat hash of comments in thread order -// function flatten_threads($threaded_comments = NULL) { -// $flat_comments = array(); -// foreach ($threaded_comments as $threaded_comment) { -// $flat_comments[] = $threaded_comment; -// if (!empty($threaded_comment['children'])) { -// $children = $this->flatten_threads($threaded_comment['children']); -// foreach ($children as $child) { -// array_push($flat_comments, $child ); -// } -// } -// } -// return $flat_comments; -// } - // Returns a hash containing the comment tree of comments related to this content function getComments( $pContentId = NULL, $pMaxComments = NULL, $pOffset = NULL, $pSortOrder = NULL, $pDisplayMode = NULL ) { - if( $pDisplayMode == "flat" ) { - return $this->getComments_flat ($pContentId, $pMaxComments, $pOffset, $pSortOrder); - } else { - #return $this->getComments_threaded ($pContentId, $pMaxComments, $pOffset, $pSortOrder); - //use flat mode retreival so we get exactly the number of messages requested. + if( $pDisplayMode != "flat" ) { if ($pSortOrder == "commentDate_asc") { - return $this->getComments_flat ($pContentId, $pMaxComments, $pOffset, 'thread_asc'); + $pSortOrder = 'thread_asc'; } else { - //descending thread order is not currently supported correctly, but we make an attempt anyway - return $this->getComments_flat ($pContentId, $pMaxComments, $pOffset, 'thread_desc'); - } - } - } - - // returns a set of nested hashes - function getComments_threaded( $pContentId = NULL, $pMaxComments = NULL, $pOffset = NULL, $pSortOrder = NULL ) { - static $curLevel = 0; - - $contentId = NULL; - $ret = array(); - if (!$pContentId && $this->mContentId) { - $contentId = $this->mContentId; - } elseif ($pContentId) { - $contentId = $pContentId; - } - - - $sort_order = "ASC"; - if (!empty($pSortOrder)) { - if ($pSortOrder == 'commentDate_desc') { - $sort_order = 'DESC'; - } elseif ($pSortOrder == 'commentDate_asc') { - $sort_order = 'ASC'; - } - } - - if ($contentId) { - $sql = "SELECT lcom.`comment_id` FROM `".BIT_DB_PREFIX."liberty_comments` lcom, `".BIT_DB_PREFIX."liberty_content` lc - WHERE lcom.`parent_id` = ? AND lcom.`content_id` = lc.`content_id` ORDER BY lc.`created` $sort_order"; - if( $rows = $this->mDb->getAll( $sql, array($contentId), $pMaxComments, $pOffset ) ) { - foreach ($rows as $row) { - $comment = new LibertyComment( $row['comment_id'] ); - $comment->mInfo['level'] = $curLevel; - $curLevel++; - $comment->mInfo['children'] = $this->getComments_threaded($comment->mInfo['content_id']); - $comment->mInfo['parsed_data'] = $this->parseData($comment->mInfo); - $curLevel--; - $ret[] = $comment->mInfo; - } + $pSortOrder = 'thread_desc'; } } - return $ret; - } - - - // Returns a hash containing the comment tree of comments related to this content - function getComments_flat( $pContentId = NULL, $pMaxComments = NULL, $pOffset = NULL, $pSortOrder = NULL ) { - static $curLevel = 0; $contentId = NULL; $ret = array(); @@ -444,8 +383,8 @@ class LibertyComment extends LibertyContent { 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) "; + $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 ); @@ -457,7 +396,7 @@ class LibertyComment extends LibertyContent { $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, $this ); if ($pContentId) { - $sql = "SELECT lcom.comment_id, lcom.parent_id, lcom.root_id, lcom.thread_forward_sequence, lcom.thread_reverse_sequence, lc.*, uu.`email`, uu.`real_name`, uu.`login` $selectSql $select1 + $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 FROM `".BIT_DB_PREFIX."liberty_comments` lcom LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lcom.`content_id` = lc.`content_id`) LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uu ON (lc.`user_id` = uu.`user_id`) $joinSql $join1 @@ -467,6 +406,9 @@ class LibertyComment extends LibertyContent { 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; + $row['editable'] = $c->userCanEdit(); $flat_comments[] = $row; } } diff --git a/comments_inc.php b/comments_inc.php index c57887b..994e94f 100644 --- a/comments_inc.php +++ b/comments_inc.php @@ -3,12 +3,12 @@ * comment_inc * * @author spider <spider@steelsun.com> - * @version $Revision: 1.21 $ + * @version $Revision: 1.22 $ * @package liberty * @subpackage functions */ -// $Header: /cvsroot/bitweaver/_bit_liberty/comments_inc.php,v 1.21 2006/07/22 15:08:34 hash9 Exp $ +// $Header: /cvsroot/bitweaver/_bit_liberty/comments_inc.php,v 1.22 2006/07/26 22:41:45 hash9 Exp $ // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. // All Rights Reserved. See copyright.txt for details and a complete list of authors. @@ -92,6 +92,7 @@ if (!empty($_REQUEST['post_comment_submit']) && $gBitUser->hasPermission( 'p_lib $storeRow['root_id'] = $commentsParentId; $storeRow['parent_id'] = (@BitBase::verifyId($storeComment->mInfo['parent_id']) ? $storeComment->mInfo['parent_id'] : (!@BitBase::verifyId($_REQUEST['post_comment_reply_id']) ? $commentsParentId : $_REQUEST['post_comment_reply_id'])); $storeRow['content_id'] = (@BitBase::verifyId($storeComment->mContentId) ? $storeComment->mContentId : NULL); + $storeRow['anon_name'] = $_REQUEST['comment_name']; if (!empty( $_REQUEST['format_guid'] ) ) { $storeRow['format_guid'] = $_REQUEST['format_guid']; } @@ -124,10 +125,14 @@ $gBitSmarty->assign_by_ref('post_comment_request', $post_comment_request); // $post_comment_preview is a flag indicating that the user wants to preview their comment prior to saving it if( !empty( $_REQUEST['post_comment_preview'] ) ) { + $postComment['user_id'] = $gBitUser->mUserId; $postComment['title'] = $_REQUEST['comment_title']; + $postComment['anon_name'] = $_REQUEST['comment_name']; $postComment['data'] = $_REQUEST['comment_data']; $postComment['format_guid'] = PLUGIN_GUID_TIKIWIKI; $postComment['parsed_data'] = LibertyComment::parseData( $postComment ); + $postComment['created'] = time(); + $postComment['last_modified'] = time(); $gBitSmarty->assign('post_comment_preview', TRUE); } @@ -226,8 +231,9 @@ $commentsPgnHash = array( 'comments_style' => $comments_display_style, 'ianchor' => 'editcomments', ); -$gBitSmarty->assign( 'commentsPgnHash', $commentsPgnHash ); -$gBitSmarty->assign('postComment', $postComment); +$gBitSmarty->assign_by_ref( 'commentsPgnHash', $commentsPgnHash ); +$gBitSmarty->assign_by_ref('postComment', $postComment); +$gBitSmarty->assign_by_ref('gComment', $gComment); $gBitSmarty->assign('currentTimestamp', time()); $gBitSmarty->assign('comments_return_url', $comments_return_url); @@ -245,4 +251,4 @@ if (!empty($_REQUEST['post_comment_request'])) { } } -?> +?>
\ No newline at end of file diff --git a/templates/comments_post_inc.tpl b/templates/comments_post_inc.tpl index 9095f5e..5493780 100644 --- a/templates/comments_post_inc.tpl +++ b/templates/comments_post_inc.tpl @@ -1,8 +1,8 @@ {if !$hide || $smarty.request.post_comment_request || $smarty.request.post_comment_preview} <a name="editcomments"></a> - {if $post_comment_preview} - <h2>{tr}Comments Preview{/tr}</h2> + {if $post_comment_preview && !$preview_override} + <h2>{tr}{$post_title} Preview{/tr}</h2> <div class="preview"> {include file='bitpackage:liberty/display_comment.tpl' comment=$postComment} </div><!-- end .preview --> @@ -27,9 +27,17 @@ {/forminput} </div> + <div class="row"> + {formlabel label="Name" for="comments-name"} + {forminput} + <input type="text" size="50" name="comment_name" id="comments-name" value="{$postComment.anon_name|escape:html}" /> + {formhelp note=""} + {/forminput} + </div> + {assign var=textarea_id value="commentpost"} - {include file="bitpackage:liberty/edit_format.tpl"} + {include file="bitpackage:liberty/edit_format.tpl" gContent=$gComment} {if $gBitSystem->isPackageActive( 'smileys' )} {include file="bitpackage:smileys/smileys_full.tpl"} diff --git a/templates/display_comment.tpl b/templates/display_comment.tpl index 61e04fc..8defaaa 100644 --- a/templates/display_comment.tpl +++ b/templates/display_comment.tpl @@ -9,7 +9,7 @@ {if $gBitUser->hasPermission( 'p_liberty_post_comments' )} <a href="{$comments_return_url}&post_comment_reply_id={$comment.content_id}&post_comment_request=1#editcomments" rel="nofollow">{biticon ipackage="liberty" iname="reply" iexplain="Reply to this comment"}</a> {/if} - {if $gBitUser->isAdmin() || ($gBitUser && $comment.user_id == $gBitUser->mInfo.user_id)} + {if $comment.editable} <a href="{$comments_return_url}&post_comment_id={$comment.comment_id}&post_comment_request=1#editcomments" rel="nofollow">{biticon ipackage="liberty" iname="edit" iexplain="Edit"}</a> {/if} {if $gBitUser->isAdmin()} @@ -18,7 +18,7 @@ </div> <h3>{$comment.title|escape}</h3> - <div class="date">{tr}by{/tr} {displayname hash=$comment}, {$comment.last_modified|bit_long_datetime}</div> + <div class="date">{tr}by{/tr} {if $comment.user_id < 0}{$comment.anon_name|escape}{else}{displayname hash=$comment}{/if}, {$comment.last_modified|bit_long_datetime}</div> <div class="content"> {include file="bitpackage:liberty/services_inc.tpl" serviceLocation='body' serviceHash=$comment} {$comment.parsed_data} |
