[Hacked!] hacking main_activities block

Login / Search

actually the hacking was to BLOCK_MAIN_ACTIVITIES.tpl.

This is my first attempt at butchering some code.

I've started using the Activities addon as a way to provide important messages/notices across the top of my site by using the main_activities block set to only display activities by the admin. This in itself works pretty good, but I would like to make a few changes to make it even a little better if possible. I like the ease of using this because I only need to log in as admin (id=2) and make an activities entry under the activity tab on the profile page. No need to edit comcode pages to add messages.

Without any modification to the code, I get unwanted baggage. When no message (activity) displayed, there is a "No activities to display yet" message displayed. Also there is a line running across the page just above the message area.

This was easy enough to remove (which I did) by editing BLOCK_MAIN_ACTIVITIES.tpl, but removing this also affects all other uses of the main_activities block.

What I would like to do is make the displaying of the "No activities to display yet" message and the line conditional depending on if the main_activities block set to display activities by the admin (id=2). I would also like to change the pencil icon to something different using the same conditional treatment.

If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).

If so, please let others know about ocPortal whenever you see the opportunity.

If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.

If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.

This is functioning perfectly now as a site notice/message system. When there are no notices/messages showing, it is completely hidden. Now when I have a need to alert my members of any important news, such as the site going offline for maintenance, I just log in as admin, go to the activity tab on the profile page and enter the message. Any location I have a main_activities block set to show only the admin's ID, my messages are shown.

If anyone is interested in setting this up on their site, here are the changes I made to BLOCK_MAIN_ACTIVITIES.tpl…

This shows the "No activities to display yet." message when there are no messages.

Code

Next, I wanted the same thing for the title and the line directly below it. This had to always show whether the block was being used in the normal way or showing a site message, but never show if there were no site messages being displayed. To do this I needed to know the member id and if there is any content to show, so I made several changes to this

{+START,IF_PASSED,MAX} <script type="text/javascript">//<![CDATA[ // "Grow" means we should keep stacking new content on top of old. If not // then we should allow old content to "fall off" the bottom of the feed. {+START,IF,{GROW}} var activities_feed_grow=true; {+END} {+START,IF,{$NOT,{GROW}}} var activities_feed_grow=false; {+END} var activities_feed_max={MAX}; if (jQuery('#activities_feed').length!=0) { var ugdRefresh=setInterval(sUpdateGetData,30000); //Refreshes feed every 30 seconds var ugdCanICant=0; jQuery('form[id*="feed_remove_"]').submit(sUpdateRemove); } //]]></script>{+END}

For this to work, you will need to assign a member (in my case, admin) to be the message poster. That member's id (in my case, 2) is hard coded into two places in the logic.

Code

{$NEQ,{MEMBER_IDS},2}

When setting up the main_activities block, set mode to "some_members", member to the ID of the member you assigned, max to whatever number of messages/notices you may want to display at one time. If you set max to anything larger than "1", set grow to "1" or you will get pagination.

Caveat: Any member with admin abilities can delete these messages, so if you have members with admin abilities warn them the "x" is not for dismissing or closing the message from view, but for deleting it.