HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


[Hacked!] hacking main_activities block

Login / Search

 [ Join | More ]
 Add topic 
Posted
Item has a rating of 5 (Liked by Chris Graham)  
Rating:
#96338 (In Topic #19135)
Avatar

Community saint

actually the hacking was to BLOCK_MAIN_ACTIVITIES.tpl.

This is my first attempt at butchering some code.  :nerd:

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.

This is the BLOCK_MAIN_ACTIVITIES.tpl code:

Code

<div class="float_surrounder">
   <div id="activities_feed">
      {+START,IF_NON_EMPTY,{TITLE}}
         <h2 class="activities_icon">{TITLE*}</h2>
      {+END}

      <div id="activitiesfeed_info" mode="{MODE*}" member_ids="{MEMBER_IDS*}"></div>
      <ul class="float_surrounder activities_holder" id="activities_holder">
         {+START,IF_EMPTY,{CONTENT}}
            <li id="-1"><p class="nothing_here">{!NO_ACTIVITIES}</p></li>
         {+END}

         {+START,LOOP,CONTENT}
            <li id="{LIID*}" class="activities_box box">
               {+START,INCLUDE,ACTIVITY}{+END}
            </li>
         {+END}
      </ul>
   </div>

The two lines I think I need to make conditional is

Code

<h2 class="activities_icon">{TITLE*}</h2>
and

Code

<li id="-1"><p class="nothing_here">{!NO_ACTIVITIES}</p></li>
And, I think I need to use this

Code

member_ids="{MEMBER_IDS*}"
in some way to know which ID is being shown.

What I've done that hasn't worked is

Code

{+START,IF,{$NOT,{MEMBER_IDS*}}}
    {+START,IF_EMPTY,{CONTENT}}
   <li id="-1"><p class="nothing_here">{!NO_ACTIVITIES}</p></li>
    {+END}
{+END}
and a few other variations on using member_ids="{MEMBER_IDS*}" without success.

How do I find the value of "{MEMBER_IDS*}"? Am I on the right path, or on the road to disaster?





Steve
Back to the top
 
Posted
Item has a rating of 5 (Liked by sholzyLiked by Jean)  
Rating:
#96339
Avatar

Probably {+START,IF,{$NEQ,{MEMBER_IDS},2}}


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • 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.
Back to the top
 
Posted
Item has a rating of 5 (Liked by FletchLiked by Jean)  
Rating:
#96340
Avatar

Community saint

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

         {+START,IF_EMPTY,{CONTENT}}
            <li id="-1"><p class="nothing_here">{!NO_ACTIVITIES}</p></li>
         {+END}
I did not want this to show when I had no messages displayed, but I still wanted it to function correctly for normal use, so I added 2 extra lines:

Code

         {+START,IF,{$NEQ,{MEMBER_IDS},2}}
            {+START,IF_EMPTY,{CONTENT}}
               <li id="-1"><p class="nothing_here">{!NO_ACTIVITIES}</p></li>
            {+END}
         {+END}

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

Code

      {+START,IF_NON_EMPTY,{TITLE}}
         <h2 class="activities_icon">{TITLE*}</h2>
      {+END}

      <div id="activitiesfeed_info" mode="{MODE*}" member_ids="{MEMBER_IDS*}"></div>

This required relocating a line of code

Code

      <div id="activitiesfeed_info" mode="{MODE*}" member_ids="{MEMBER_IDS*}"></div>
to above the title logic so I could pick up the member id. Not doing that gave a critical error.

Next, I needed logic to always display the title, but not when there were no site messages by admin. The code changes for that was

Code

         {+START,IF,{$AND,{IF_EMPTY,{CONTENT}},{$NEQ,{MEMBER_IDS},2}}}
            {+START,IF_NON_EMPTY,{TITLE}}
               <h2 class="activities_icon">{TITLE*}</h2>
            {+END}
         {+END}
         
         {+START,IF_NON_EMPTY,{CONTENT}}
            {+START,IF_NON_EMPTY,{TITLE}}
               <h2 class="activities_icon">{TITLE*}</h2>
            {+END}
         {+END}
I'm sure the Chief nerd would have coded the extra logic into one line… :cool:

The full code

Code

<div class="float_surrounder">
   <div id="activities_feed">
      <div id="activitiesfeed_info" mode="{MODE*}" member_ids="{MEMBER_IDS*}"></div>
         {+START,IF,{$AND,{IF_EMPTY,{CONTENT}},{$NEQ,{MEMBER_IDS},2}}}
            {+START,IF_NON_EMPTY,{TITLE}}
               <h2 class="activities_icon">{TITLE*}</h2>
            {+END}
         {+END}
         
         {+START,IF_NON_EMPTY,{CONTENT}}
            {+START,IF_NON_EMPTY,{TITLE}}
               <h2 class="activities_icon">{TITLE*}</h2>
            {+END}
         {+END}
      
      <ul class="float_surrounder activities_holder" id="activities_holder">
         {+START,IF,{$NEQ,{MEMBER_IDS},2}}
            {+START,IF_EMPTY,{CONTENT}}
               <li id="-1"><p class="nothing_here">{!NO_ACTIVITIES}</p></li>
            {+END}
         {+END}

         {+START,LOOP,CONTENT}
            <li id="{LIID*}" class="activities_box box">
               {+START,INCLUDE,ACTIVITY}{+END}
            </li>
         {+END}
      </ul>
   </div>

   {PAGINATION}
</div>

{+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.

I hope I've covered everything.  :)


Steve
Back to the top
 
Posted
Rating:
#96357
Avatar

Community saint

Nice!:cool:
Love it and thanks for sharing, Steve!
:thumbs:

Jean
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: