Action: Hidden Content


Current version: 1.2
Credits: Tann San


{{hiddencontent username="User1,User2,User3" usergroup="Admins" text="Hidden text" alt="Shown to users who dont meet the login requirements"}}


/actions/hiddencontent.php


<?php
/*
      {{Hidden Content Wrapper

      Version 1.2
      David Millington aka Tann San

      Shows hidden content based on user group or user name

      1.1 - Added optional alt attribute which shows content to users who don't meet the login requirements
      1.2 - Updated to work with Wacko r5.0

      [$username=<comma deliminated list of user names>] - optional - $username="TannSan,BillyBob"
      [$usergroup=a single user group name] - optional - $usergroup="Admins"
      [$text=text to display if user meets login requirements]
      [$alt=alternative text to display to users who do not meet the login requirements] - optional

      http://wackowiki.org/Dev/PatchesHacks/HiddenContent
      }}
*/

if (!defined('IN_WACKO'))
{
    exit;
}

if(!isset(
$usergroup)) $usergroup '';
if(!isset(
$username)) $username '';
if(!isset(
$text)) $text '';
if(!isset(
$alt)) $alt '';

if(
$usergroup !== '' || $username !== '')
{
    
$show_content false;

    
// Check if user is the named user
    
if(in_array($this->get_user_name(), explode(','$username)))
    {
        
$show_content true;
    }
    else if (
is_array($this->config['aliases']))
    {
        
// Check if current user is in the specified $usergroup
        // don't bother if we already identified the user as having access
        
foreach ($this->config['aliases'] as $gname => $gusers)
        {
            if(
$gname === $usergroup)
            {
                if(
in_array($this->get_user_name(), explode(','$gusers)))
                {
                    
$show_content true;
                    break;
                }
            }
        }
    }

    if(
$show_content)
    {
        echo 
$this->format($text);
    }
}
else if(
$alt !== '')
{
    echo 
$this->format($alt);
}

?>



<?php
/*
      {{Hidden Content Wrapper
      
      Version 1.1
      David Millington aka Tann San

      Shows hidden content based on user group or user name
      1.1 - added optional alt attribute which shows content to users who don't meet the login requirements

      [$username=<comma deliminated list of user names>] - optional - $username="TannSan,BillyBob"
      [$usergroup=a single user group name] - optional - $usergroup="Admins"
      [$text=text to display if user meets login requirements]
      [$alt=alternative text to display to users who do not meet the login requirements] - optional
      
      http://wackowiki.org/Dev/PatchesHacks/HiddenContent
      }}
   */
   
   
if(!$usergroup$usergroup "";
   if(!
$username$username "";
   if(!
$text$text "";
   if(!
$alt$alt "";
   
   if(
$usergroup !== "" || $username !== "")
      {
         
$show_content false;
         
         
// Check if user is the named user
         
if(in_array($this->GetUserName(), explode(",",$username)))
            {          
               
$show_content true;
            }                        
         else if (
is_array($this->config['aliases'])) 
            {
               
// Check if current user is in the specified $usergroup
               // don't bother if we already identified the user as having access                
               
foreach ($this->config['aliases'] as $gname => $gusers
                  {
                     if(
$gname === $usergroup)
                        {
                           if(
in_array($this->GetUserName(), explode(",",$gusers)))
                              {
                                 
$show_content true;
                                 break;
                              }
                        }                           
                  }
            }
            
      if(
$show_content)
         {
            echo 
$this->Format($text);
         }
      }
   else if(
$alt !== "")
      {         
         echo 
$this->Format($alt);
      }   
?>

Documentation


Hides content on a page based on either the currently logged in users name or their user group. The username attribute lets you use a comma deliminated list of user names or just one on its own. The usergroup attribute lets you specify a single user group. You can use either one or both of the attributes so you could for example allow the entire “Admins” group and five non admin users to view the content or you could just allow a single user. The text attribute lets you use wiki text so you can still apply all the wiki formatting to the hidden content. To split it onto new lines use the wiki newline tag.


Note that this action does not prevent people from simply editing the page and reading the hidden content. It is meant to be used on pages which other logged in users do not have edit access to. Say Bob owns pageA. Alice once logged in can read pageA but not edit it. Bob can write a message on the page that only Alice can read using this action. Other logged in users who do not have edit access to the page cannot see the text. Non logged in users also cannot read the text.


Referring pages:

  1. Dev/PatchesHacks