DeeEmm

Pragmatism in code

Waxing lyrical about life the universe and everything software related since lunchtime 2006.

Allow guests to view JomSocial activity stream comments

I have recently migrated a site from Dolphin to JomSocial and needed to modify the way that the activity stream was displayed to visitors. By default the replies and likes of activity stream posts are only displayed to friends of the original poster. This means that the comments are very limited in their reach.

The overall effect of hiding activity stream comments and likes from guests is that this valuable activity is wasted. I wanted to show this activity to guest visitors so that they could see how active the site is. This in turn encourages them to join and hopefully encourages them to comment. 

Of course, this may not be suitable for all sites, but in the case of this site, there was no activity that is 'secret' or 'private'; the activity stream is public viewable, and so should be the comments.

The modification you need to do this is pretty straightforward, it simply involves removing or commenting out two lines of code. 

Modification Instructions

open the following file...

components/com_community/templates/YOUR_TEMPLATE/activities.index.php

Look for the following line of code at around line 223

<?php if( $allowComment ) { ?>

Replace it with the following

<?php //if( $allowComment ) { ?>

Next look for the following line of code at about line 263

<?php } ?>

Replace it with the following

<?php //} ?>

 

This simply comments out the lines. You can also opt to delete them completely if you wish.

Now your activity stream will display comments and likes to visitors as well as all members. The only caveat to this is is that if you are logged in it will display the 'reply' link but will not allow you to actually reply unless you are a friend of the original poster. What happens when you are not a friend of the original poster and you try to post a reply is that you will simply see a popup message box saying 'permission denied'. There are two ways that you can deal with this. These are as follows.

1. Change the message.

To change the message to something a little more meaningful you can do the following...

Edit the file components/com_community/controllers/system.php

At around line 1460 look for the following code...

$objResponse->addAlert('Permission denied');

Simply change this message to something else - for example...

$objResponse->addAlert('Only friends can reply');

 

2. Allow non-friends to post.

If you want to let anyone be able to post to the Activity stream you can do the following...

The easy way...

Enable the following setting in the admin panel

components > jomsocial > configuration > site >  activity > allow everyone to comment

 

The hard way...

Find the same line mentioned above, but this time replace it with the following code...

			$table =& JTable::getInstance('Wall', 'CTable');
			$table->type 		= $act->comment_type;
			$table->contentid 	= $act->comment_id;
			$table->post_by 	= $my->id;
			$table->comment 	= $comment;
			$table->store();

			$cache	= CFactory::getFastCache();
			$cache->clean(array('activities'));

			$comment = CWall::formatComment($table);
			$objResponse->addScriptCall('joms.miniwall.insert', $actid, $comment);

			CFactory::load( 'libraries' , 'notification' );
			$params		= new CParameter( '' );
			$params->set( 'message' , $table->comment );
			$url			= 'index.php?option=com_community&view=profile&userid=' . $act->actor.'&actid='.$actid;
			$params->set( 'url' , $url );
			$params->set( 'stream' , JText::_('COM_COMMUNITY_SINGULAR_STREAM') );
			$params->set( 'stream_url' , $url );


			CNotificationLibrary::add( 'profile_activity_add_comment' , $my->id , $act->actor , JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_EMAIL_SUBJECT' ) , '' , 'profile.activitycomment' , $params );

Now anyone can reply to any post in the activity stream. Additionally anyone can also post directly to another users profile page. cool huh?!?

 

NOTE

 

Well I guess that this modification will not be for everybody, but if like me you have a community site this might just increase your activity.

/DM

Macbook dies in freak plane accident
Mobile Joomla Mobile Template

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Guest
Tuesday, 25 April 2017
If you'd like to register, please fill in the username, password and name fields.

Captcha Image