Microblog show comments only when users are logged in

Snippets, useful things or other stuff here.

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

paragate
Master
Master
Posts: 151
Joined: Nov 13th, '14, 13:04
Location: Denmark, Odense

Microblog show comments only when users are logged in

Postby paragate » Nov 25th, '15, 11:51

HI.
Just a small thing to try out how actionmessage displays and the use of isLoggedIn() function in conjunction with ModulesSettings::model().
Its programmed into framework so remember to remove it again or include it for itself.

To have a button displayed in Module Settings / Micro Blog under the paragraph Comments Settings / Settings you have make an record in database table _module_settings.

insert into `Your databsae`.`upc_module_settings` (ìd` `property_key`, `property_value`, `property_source`, `property_length`, `property_type`, `module_code`, `description`, `is_required`, `name`, `property_group`) values (NULL, 'show_comments_loggedin', '1', '', '', 'bool', 'mblog', 'Specifies whether only to show comments to loggedin users', '1', 'Show Comments only loggedin', 'Comments Settings');

Then you have to place a variable in components/CommentsComponent.php around line 38 and insert:
$showCommentsLoggedin = ModulesSettings::model()->param('mblog', 'show_comments_loggedin');

Then around line 70 you insert this small function:

if (CAuth::isLoggedIn() and $showCommentsLoggedin == 0){
$output .= CHtml::openTag('div', array('class' => 'mblock_post_footer_comments'));
$output .= CHtml::openTag('div', array());
$output .= $contentLink;
$output .= CHtml::link(
A::t('mblog', 'Comments (').$commentsCount.')',
$href,
array('class' => 'mblock_comment_correct', 'onClick' => $onClick)
);
$output .= CHtml::closeTag('div');
$output .= CHtml::closeTag('div');
}else {
$actionMessage = 'You must be logged in to see all comments!';
if($actionMessage != ''){
echo $actionMessage;
$output .= '<br>';
}
}

If you look carefully, you will notice this is just a function wrapped around allready placed code, so remember to remove the code!

Return to “Snippets, Tutorials & Other Stuff”