diff options
| author | Max Kremmel <xing@synapse.plus.com> | 2009-01-11 09:00:39 +0000 |
|---|---|---|
| committer | Max Kremmel <xing@synapse.plus.com> | 2009-01-11 09:00:39 +0000 |
| commit | 15b68311196e19cbd0809d85346f5e2837679beb (patch) | |
| tree | b56d292f88f5d2266a83f9691c1d4cad264fe1be | |
| parent | 75b143730b1c61fbbb011dc74a9189e7d8ce5144 (diff) | |
| download | liberty-15b68311196e19cbd0809d85346f5e2837679beb.tar.gz liberty-15b68311196e19cbd0809d85346f5e2837679beb.tar.bz2 liberty-15b68311196e19cbd0809d85346f5e2837679beb.zip | |
more code cleanup
| -rw-r--r-- | comments_inc.php | 226 |
1 files changed, 115 insertions, 111 deletions
diff --git a/comments_inc.php b/comments_inc.php index fce86e6..a9381af 100644 --- a/comments_inc.php +++ b/comments_inc.php @@ -3,12 +3,12 @@ * comment_inc * * @author spider <spider@steelsun.com> - * @version $Revision: 1.53 $ + * @version $Revision: 1.54 $ * @package liberty * @subpackage functions */ -// $Header: /cvsroot/bitweaver/_bit_liberty/comments_inc.php,v 1.53 2008/12/28 00:15:24 pppspoonman Exp $ +// $Header: /cvsroot/bitweaver/_bit_liberty/comments_inc.php,v 1.54 2009/01/11 09:00:39 squareing 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. @@ -25,29 +25,32 @@ // this script may only be included - so its better to die if called directly. + /** -* @param $commentsParentId = the content id of the object where a new comment will be attached - mandatory -* @param $commentsParentIds = the list of content id of object the comments will be displayed - if not defined $commentsParentId -* @param $comments_return_url + * Parameters that need to be set when calling this file + * @param numeric $commentsParentId The content id of the object where a new comment will be attached (required) + * @param array $commentsParentIds The list of content id of object the comments will be displayed - if not defined $commentsParentId (required if $commentsParentId is not set) + * @param string $comments_return_url The URL the user should be sent to after posting the comment (required) **/ + /** * required setup */ -require_once (LIBERTY_PKG_PATH.'LibertyComment.php'); +require_once( LIBERTY_PKG_PATH.'LibertyComment.php' ); global $commentsLib, $gBitSmarty, $gBitSystem; -if ($gBitSystem->isPackageActive('bitboards')) { +if( $gBitSystem->isPackageActive( 'bitboards' )) { require_once(BITBOARDS_PKG_PATH.'BitBoardTopic.php'); } -if ($gBitSystem->isPackageActive('tickets')) { - require_once(TICKETS_PKG_PATH.'BitTicket.php'); +if( $gBitSystem->isPackageActive( 'tickets' )) { + require_once( TICKETS_PKG_PATH.'BitTicket.php' ); } $postComment = array(); $formfeedback = array(); -$gBitSmarty->assign_by_ref('formfeedback', $formfeedback); +$gBitSmarty->assign_by_ref( 'formfeedback', $formfeedback ); // make sure that we don't feed ajax comments if we don't have javascript enabled if( !BitThemes::isJavascriptEnabled() ) { @@ -59,22 +62,24 @@ if( $gBitSystem->isFeatureActive( 'comments_ajax' ) && !empty( $gContent ) && is $gBitThemes->loadAjax( 'mochikit', array( 'Iter.js', 'DOM.js', 'Style.js', 'Color.js', 'Position.js', 'Visual.js' )); } -if( @BitBase::verifyId($_REQUEST['delete_comment_id']) ) { +if( @BitBase::verifyId( $_REQUEST['delete_comment_id'] )) { $deleteComment = new LibertyComment($_REQUEST['delete_comment_id']); - if( $deleteComment->isValid() && $gContent->hasUserPermission('p_liberty_admin_comments') ) { + if( $deleteComment->isValid() && $gContent->hasUserPermission( 'p_liberty_admin_comments' )) { $deleteComment->deleteComment(); } } -if( @BitBase::verifyId($_REQUEST['post_comment_id']) && $gContent->hasUserPermission( 'p_liberty_post_comments', TRUE, TRUE )) { +if( @BitBase::verifyId( $_REQUEST['post_comment_id'] ) && $gContent->hasUserPermission( 'p_liberty_post_comments', TRUE, TRUE )) { $post_comment_id = $_REQUEST['post_comment_id']; - $editComment = new LibertyComment($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'])){ - $gBitSmarty->assign('comments_ajax', FALSE); //even if ajax is on - we force it off in this case + 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 ) ) { + + if( $editComment->mInfo['content_id'] ) { + if( $editComment->userCanUpdate( $gContent )) { $postComment['data'] = $editComment->mInfo['data']; $postComment['title'] = $editComment->mInfo['title']; } else { @@ -94,46 +99,51 @@ if( @BitBase::verifyId($_REQUEST['post_comment_id']) && $gContent->hasUserPermis $gBitSmarty->assign('post_comment_id', $post_comment_id); // Store comment posts -if (!empty($_REQUEST['post_comment_submit']) && $gContent->hasUserPermission( 'p_liberty_post_comments', TRUE, TRUE )) { - $storeComment = new LibertyComment(@BitBase::verifyId($editComment->mCommentId) ? $editComment->mCommentId : NULL); +if( !empty( $_REQUEST['post_comment_submit'] ) && $gContent->hasUserPermission( 'p_liberty_post_comments', TRUE, TRUE )) { + $storeComment = new LibertyComment( @BitBase::verifyId( $editComment->mCommentId ) ? $editComment->mCommentId : NULL ); $storeRow = array(); $storeRow['title'] = $_REQUEST['comment_title']; $storeRow['edit'] = $_REQUEST['comment_data']; - if (empty($_REQUEST['post_comment_id'])&&$gBitSystem->isPackageActive('bitboards')) { - $content_type = $gBitUser->getPreference('signature_content_type'); - $content_data = $gBitUser->getPreference('signature_content_data'); - if (!empty($content_type) && !empty($content_data)) { + + if( empty( $_REQUEST['post_comment_id'] ) && $gBitSystem->isPackageActive( 'bitboards' )) { + $content_type = $gBitUser->getPreference( 'signature_content_type' ); + $content_data = $gBitUser->getPreference( 'signature_content_data' ); + if( !empty( $content_type ) && !empty( $content_data )) { $storeRow['edit'] .= "\n{renderer format_guid=$content_type class=mb-signature}$content_data{/renderer}"; } } + $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); - if( !empty( $_REQUEST['captcha'] ) ) { + + if( !empty( $_REQUEST['captcha'] )) { $storeRow['captcha'] = $_REQUEST['captcha']; } - if (!empty($_REQUEST['comment_name'])) { + if( !empty($_REQUEST['comment_name'] )) { $storeRow['anon_name'] = $_REQUEST['comment_name']; } - if (!empty( $_REQUEST['format_guid'] ) ) { + if( !empty( $_REQUEST['format_guid'] )) { $storeRow['format_guid'] = $_REQUEST['format_guid']; } + $ticketValid = TRUE; - if( $gBitSystem->isPackageActive('tickets')) { - $ticketValid = $gContent->storeOnlyHeader($_REQUEST['ticket']); + if( $gBitSystem->isPackageActive( 'tickets' )) { + $ticketValid = $gContent->storeOnlyHeader( $_REQUEST['ticket'] ); if( $ticketValid ) { $gContent->loadTicketHistory(); $storeRow['edit'] = "{history id=".$_REQUEST['ticket']['historyIds'][0]."} ".$storeRow['edit']; } } - if(!($gBitSystem->isPackageActive('bitboards') && BitBoardTopic::isLockedMsg($storeRow['parent_id']))) { - if( $ticketValid && $storeComment->storeComment($storeRow) ) { - if($gBitSystem->isPackageActive('bitboards') && $gBitSystem->isFeatureActive('bitboards_thread_track')) { - $topic_id = substr($storeComment->mInfo['thread_forward_sequence'],0,10); + + if( !( $gBitSystem->isPackageActive( 'bitboards' ) && BitBoardTopic::isLockedMsg( $storeRow['parent_id'] ))) { + if( $ticketValid && $storeComment->storeComment( $storeRow )) { + if( $gBitSystem->isPackageActive('bitboards') && $gBitSystem->isFeatureActive( 'bitboards_thread_track' )) { + $topic_id = substr( $storeComment->mInfo['thread_forward_sequence'], 0, 10 ); $data = BitBoardTopic::getNotificationData($topic_id); - foreach ($data['users'] as $login => $user) { - if($data['topic']->mInfo['llc_last_modified']>$user['track_date'] && $data['topic']->mInfo['llc_last_modified']>$user['track_notify_date']) { - $data['topic']->sendNotification($user); + foreach( $data['users'] as $login => $user ) { + if( $data['topic']->mInfo['llc_last_modified'] > $user['track_date'] && $data['topic']->mInfo['llc_last_modified'] > $user['track_notify_date'] ) { + $data['topic']->sendNotification( $user ); } } } @@ -145,8 +155,10 @@ if (!empty($_REQUEST['post_comment_submit']) && $gContent->hasUserPermission( 'p if( !empty( $_REQUEST['comment_name'] ) ) { $postComment['anon_name'] = $_REQUEST['comment_name']; } + $_REQUEST['post_comment_request'] = TRUE; - $_REQUEST['post_comment_preview'] = TRUE; //this is critical and triggers other settings if store fails - do not remove without looking at what preview effects + //this is critical and triggers other settings if store fails - do not remove without looking at what preview effects + $_REQUEST['post_comment_preview'] = TRUE; } } else { $formfeedback['warning']="The selected Topic is Locked posting is disabled"; @@ -154,6 +166,7 @@ if (!empty($_REQUEST['post_comment_submit']) && $gContent->hasUserPermission( 'p } elseif(!empty($_REQUEST['post_comment_request']) && !$gContent->hasUserPermission( 'p_liberty_post_comments', TRUE, TRUE )) { $formfeedback['warning']="You don't have p_liberty_post_comments"; } + // $post_comment_request is a flag indicating whether or not to display the comment input form if( empty( $_REQUEST['post_comment_request'] ) && !$gBitSystem->isFeatureActive( 'comments_auto_show_form' ) ) { $post_comment_request = NULL; @@ -171,19 +184,21 @@ if( !empty( $_REQUEST['post_comment_cancel'] ) ) { } // $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'] ) ) { - if ( isset($_REQUEST['no_js_preview']) && $_REQUEST['no_js_preview']=="y" ){ +if( !empty( $_REQUEST['post_comment_preview'] )) { + if( isset( $_REQUEST['no_js_preview'] ) && $_REQUEST['no_js_preview']=="y" ) { $no_js_preview = $_REQUEST['no_js_preview']; - $gBitSmarty->assign('comments_ajax', FALSE); //even if ajax is on - we force it off in this case + + //even if ajax is on - we force it off in this case + $gBitSmarty->assign( 'comments_ajax', FALSE ); } else { $no_js_preview = "n"; } - $gBitSmarty->assign_by_ref('no_js_preview', $no_js_preview); + $gBitSmarty->assign_by_ref( 'no_js_preview', $no_js_preview ); $postComment['user_id'] = $gBitUser->mUserId; $postComment['title'] = $_REQUEST['comment_title']; - if (!empty($_REQUEST['comment_name'])) { + if( !empty( $_REQUEST['comment_name'] )) { $postComment['anon_name'] = $_REQUEST['comment_name']; } $postComment['data'] = $_REQUEST['comment_data']; @@ -195,87 +210,87 @@ if( !empty( $_REQUEST['post_comment_preview'] ) ) { } // $post_comment_reply_id is the content_id which a post is replying to -if (@BitBase::verifyId($_REQUEST['post_comment_reply_id'])) { +if( @BitBase::verifyId( $_REQUEST['post_comment_reply_id'] )) { $post_comment_reply_id = $_REQUEST['post_comment_reply_id']; - $tmpComment = new LibertyComment(NULL, $post_comment_reply_id); - if (!empty($_REQUEST['quote'])) { + $tmpComment = new LibertyComment( NULL, $post_comment_reply_id ); + if( !empty( $_REQUEST['quote'] )) { $postComment['data'] = $tmpComment->getQuoted(); } - if (preg_match('/^' . tra('Re:') . '/', $tmpComment->mInfo['title'])) { + if( preg_match( '/^' . tra( 'Re:' ) . '/', $tmpComment->mInfo['title'] )) { $comment_prefix = ''; } else { - $comment_prefix = tra('Re:') . " "; + $comment_prefix = tra( 'Re:' ) . " "; } + //this always overrides the title with "Re: Parent Title" -- not sure what it really should do so I put in this conditional for previews - if (!isset($_REQUEST['comment_title'])){ - $postComment['title'] = $comment_prefix . $tmpComment->mInfo['title']; + if( !isset( $_REQUEST['comment_title'] )) { + $postComment['title'] = $comment_prefix.$tmpComment->mInfo['title']; } - $gBitSmarty->assign('post_comment_reply_id', $post_comment_reply_id); + $gBitSmarty->assign( 'post_comment_reply_id', $post_comment_reply_id ); } -if (!empty($_SESSION['liberty_comments_per_page'])) { +if( !empty( $_SESSION['liberty_comments_per_page'] )) { $maxComments = $_SESSION['liberty_comments_per_page']; } else { $maxComments = $gBitSystem->getConfig( 'comments_per_page', 10 ); } -if (!empty($_REQUEST["comments_maxComments"])) { + +if( !empty( $_REQUEST["comments_maxComments"] )) { $maxComments = $_REQUEST["comments_maxComments"]; $comments_at_top_of_page = 'y'; $_SESSION['liberty_comments_per_page'] = $maxComments; } - -if (!empty($_SESSION['liberty_comments_ordering'])) { +if( !empty( $_SESSION['liberty_comments_ordering'] )) { $comments_sort_mode = $_SESSION['liberty_comments_ordering']; } else { $comments_sort_mode = $gBitSystem->getConfig( 'comments_default_ordering', 'commentDate_desc' ); } -if (!empty($_REQUEST["comments_sort_mode"])) { + +if( !empty( $_REQUEST["comments_sort_mode"] )) { $comments_sort_mode = $_REQUEST["comments_sort_mode"]; $comments_at_top_of_page = 'y'; $_SESSION['liberty_comments_ordering'] = $comments_sort_mode; } -if (!empty($_SESSION['liberty_comments_display_mode'])) { +if( !empty( $_SESSION['liberty_comments_display_mode'] )) { $comments_display_style = $_SESSION['liberty_comments_display_mode']; } else { $comments_display_style = $gBitSystem->getConfig( 'comments_default_display_mode', 'threaded' ); } + if( !empty( $_REQUEST["comments_style"] ) ) { $comments_display_style = $_REQUEST["comments_style"]; $comments_at_top_of_page = 'y'; $_SESSION['liberty_comments_display_mode'] = $comments_display_style; } -//if( !empty( $_REQUEST['list_page'] ) || !empty( $_REQUEST['post_comment_request'] ) ) { if( !empty( $_REQUEST['comment_page'] ) || !empty( $_REQUEST['post_comment_request'] ) ) { $comments_at_top_of_page = 'y'; } -//$commentOffset = !empty( $_REQUEST['list_page'] ) ? ($_REQUEST['list_page'] - 1) * $maxComments : 0; $commentOffset = !empty( $_REQUEST['comment_page'] ) ? ($_REQUEST['comment_page'] - 1) * $maxComments : 0; -if (empty($gComment)) { +if( empty( $gComment )) { $gComment = new LibertyComment( NULL, $gContent->mContentId ); } -//$currentPage = !empty( $_REQUEST['list_page'] ) ? $_REQUEST['list_page'] : 1; $currentPage = !empty( $_REQUEST['comment_page'] ) ? $_REQUEST['comment_page'] : 1; -if ($currentPage < 1) { +if( $currentPage < 1 ) { $currentPage = 1; } -#logic to support displaying a single comment -- used when we need a URL pointing to a comment -if (!empty($_REQUEST['view_comment_id'])) { - $commentOffset = $gComment->getNumComments_upto($_REQUEST['view_comment_id']); +# logic to support displaying a single comment -- used when we need a URL pointing to a comment +if( !empty( $_REQUEST['view_comment_id'] )) { + $commentOffset = $gComment->getNumComments_upto( $_REQUEST['view_comment_id'] ); # echo "commentOffset =$commentOffset= maxComments=$maxComments=\n"; $comments_sort_mode = 'commentDate_asc'; $comments_display_style = 'flat'; $comments_at_top_of_page = 'y'; $maxComments = 1; - $currentPage = ceil( $commentOffset+1 / $maxComments ); + $currentPage = ceil( $commentOffset + 1 / $maxComments ); } else { - $commentOffset = ($currentPage - 1) * $maxComments; + $commentOffset = ( $currentPage - 1 ) * $maxComments; } @@ -290,7 +305,7 @@ if( !@BitBase::verifyId( $commentsParentId ) ) { $parents = $commentsParentId; } // pass in a reference to the root object so that we can do proper permissions checks - if ( is_object( $gContent ) ){ + if ( is_object( $gContent )) { $gComment->mRootObj = $gContent; } $numComments = $gComment->getNumComments( $commentsParentId ); @@ -301,71 +316,60 @@ if( !@BitBase::verifyId( $commentsParentId ) ) { $comments = $gComment->getComments( $parents, $maxComments, $commentOffset, $comments_sort_mode, $comments_display_style ); } -if ($comments_display_style == 'flat') { +if( $comments_display_style == 'flat' ) { $commentsTree = $comments; } else { $commentsTree = array(); - foreach ($comments as $id => $node){ - if (!empty( $comments[ $node['parent_id'] ])) { + foreach( $comments as $id => $node ){ + if( !empty( $comments[ $node['parent_id'] ] )) { $comments[ $node['parent_id'] ]['children'][$id] = &$comments[$id]; } - if ($node['parent_id'] == $node['root_id'] or empty( $comments[ $node['parent_id'] ])){ + if( $node['parent_id'] == $node['root_id'] || empty( $comments[ $node['parent_id'] ] )) { $comments[$id]['level'] = 0; $commentsTree[$id] = &$comments[$id]; } } } -$gBitSmarty->assign_by_ref('comments', $commentsTree); -$gBitSmarty->assign('maxComments', $maxComments); +$gBitSmarty->assign_by_ref( 'comments', $commentsTree ); +$gBitSmarty->assign( 'maxComments', $maxComments ); $numCommentPages = ceil( $numComments / $maxComments ); -$comments_return_url = $comments_return_url.(!strpos( $comments_return_url, '?' ) ? '?' : ''); +$comments_return_url = $comments_return_url.( !strpos( $comments_return_url, '?' ) ? '?' : '' ); // libertypagination smarty function setup $commentsPgnHash = array( - 'numPages' => $numCommentPages, - 'pgnName' => 'comment_page', - 'page' => $currentPage, - 'comment_page' => $currentPage, - 'url' => $comments_return_url, + 'numPages' => $numCommentPages, + 'pgnName' => 'comment_page', + 'page' => $currentPage, + 'comment_page' => $currentPage, + 'url' => $comments_return_url, 'comments_page' => ( empty( $comments_on_separate_page ) ? FALSE : $comments_on_separate_page ), - 'ianchor' => 'editcomments', + 'ianchor' => 'editcomments', ); $gBitSmarty->assign_by_ref( 'commentsPgnHash', $commentsPgnHash ); -/* -# Parameters for Bitweaver standard pagination module -$listInfo = array ( -'total_records' => $numComments, -'total_pages' => $numCommentPages, -'current_page' => $currentPage, -); -# Values in $listInfo['parameters'] will be passed back in on subsequent calls -$listInfo['parameters'] = array ( -'comments_page' => ( empty( $comments_on_separate_page ) ? FALSE : $comments_on_separate_page ), -'ianchor' => 'editcomments', -); -$gBitSmarty->assign( 'listInfo', $listInfo ); -$gBitSmarty->assign( 'returnUrl', $comments_return_url ); - */ - - -$gBitSmarty->assign_by_ref('postComment', $postComment); -$gBitSmarty->assign_by_ref('gComment', $gComment); +$gBitSmarty->assign_by_ref( 'postComment', $postComment ); +$gBitSmarty->assign_by_ref( 'gComment', $gComment ); -$gBitSmarty->assign('currentTimestamp', time()); -$gBitSmarty->assign('comments_return_url', $comments_return_url ); -$gBitSmarty->assign('comments_at_top_of_page', ( isset( $comments_at_top_of_page ) && $gBitSystem->getConfig( 'comments_reorganise_page_layout', 'n' ) == 'y' ) ? $comments_at_top_of_page : NULL ); -$gBitSmarty->assign('comments_style', $comments_display_style); -$gBitSmarty->assign('comments_sort_mode', $comments_sort_mode); -$gBitSmarty->assign('textarea_id', 'commentpost'); -$gBitSmarty->assign('comments_count', $numComments); +$gBitSmarty->assign( 'currentTimestamp', time() ); +$gBitSmarty->assign( 'comments_return_url', $comments_return_url ); +$gBitSmarty->assign( 'comments_at_top_of_page', ( isset( $comments_at_top_of_page ) && $gBitSystem->getConfig( 'comments_reorganise_page_layout', 'n' ) == 'y' ) ? $comments_at_top_of_page : NULL ); +$gBitSmarty->assign( 'comments_style', $comments_display_style ); +$gBitSmarty->assign( 'comments_sort_mode', $comments_sort_mode ); +$gBitSmarty->assign( 'textarea_id', 'commentpost' ); +$gBitSmarty->assign( 'comments_count', $numComments ); -if (!empty($_REQUEST['post_comment_request'])) { - if ($gBitSystem->isPackageActive('bitboards') && BitBoardTopic::isLockedMsg( (@BitBase::verifyId($storeComment->mInfo['parent_id']) ? $storeComment->mInfo['parent_id'] : (!@BitBase::verifyId($_REQUEST['post_comment_reply_id']) ? $commentsParentId : $_REQUEST['post_comment_reply_id'])))) { - unset($_REQUEST['post_comment_request']); - unset($_GET['post_comment_request']); - unset($_POST['post_comment_request']); +if( !empty( $_REQUEST['post_comment_request'] )) { + if( $gBitSystem->isPackageActive( 'bitboards' ) + && ( + BitBoardTopic::isLockedMsg( @BitBase::verifyId( $storeComment->mInfo['parent_id'] ) + ? $storeComment->mInfo['parent_id'] : ( !@BitBase::verifyId( $_REQUEST['post_comment_reply_id'] ) + ? $commentsParentId : $_REQUEST['post_comment_reply_id'] )) + ) + ) { + unset( $_REQUEST['post_comment_request'] ); + unset( $_GET['post_comment_request'] ); + unset( $_POST['post_comment_request'] ); $formfeedback['warning']="The selected Topic is Locked posting is disabled"; } } |
