Sign Up! Login: Password: New User? Forgot? Support
Code 
 
 
Forums 
Forums : Layout & Theme > Widget Access Levels
Mottie (SuperAdmin) 2/21/2011 12:51 PM EST : Widget Access Levels
ACK!
Mottie
Posts: 3883

0
Like

0
Dislike

Widget Access Levels

GuildPortal admin site link to original post

This script will allow you to have a widget that is only visible to guild members or one only visible to officers, etc. Essentially, you hide ALL of your widgets, then this code will sort through the titles to find matches, then figure out which ones to show.

The main problem with this script is that if someone knows what to look for, they can find and view this hidden information. So it's not perfect. The best place for information you don't want visible to others would be to add an entire page only visible to users with that access level.

Code

This is now a Mod
Control Panel > Site Mods > Get Site Mods >
Look for "Widget Access Levels"


  • CSS: Add the following css to your custom css (Control Panel > Custom HTML & Script > Custom CSS > CSS Additions to Standard). It will hide all of the widgets on your page.
    .gpWidget { display: none; }
  • Script: Add this script to your custom script area (Control Panel > Custom HTML & Script > Custom Javascript/JQuery > Additional Functions tab). Make sure the "Enabled?" box is checked before clicking [ Save ].
    (function(){
     // Enter Widget title then in parenthesis include the access level number
     // One widget:  "Title(#)" // the "#" in parenthesis is the access level number of that widget
     // Two widgets: "Title 1(#), Title 2(#)" // separate the titles with a comma
     // The title must EXACTLY match the widget title before this script will work
     // access level: public = 1, associate = 1.5, member = 2, council = 2.5, officer = 3, super admin = 4


     var widgetAccess = "Voice Chat (2), Contact Info(2), Council Updates(2.5), Officer Updates (3)"

     /* Don't change anything below */
     ,accessIt = function(cb, t, h){
      if (!cb.length) { return; }
      h = h || 1; // no access level = make public
      var access = parseInt("$block[userlevelnumber]".replace(/\s+/,''),10);
      if (access >= h) { cb.show(); }
     }, a = [], j, n = [], t, list = widgetAccess.split(',');
     for ( j=0; j < list.length; j++ ){
      t = list[j].match(/([^(]*)\(([^)]*)/);
      n.push($.trim(t[1])||''); // widget name
      a.push($.trim(t[2])||1); // access level
     }
     $('.gpWidget').each(function(){
      t = $.trim( $(this).find('.ContentBoxTitle,.ContentBoxTitleNoBackground').text() );
      j = $.inArray(t,n);
      if (j < 0 || widgetAccess.indexOf(t) < 0) {
       $(this).show();
      } else {
       accessIt($(this), n[j], a[j]);
      }
     });
    }());
Customizing

Modify the "widgetAccess" varible to add specific widgets that need an access level. Follow this template:
var widgetAccess = "Title1(#), Title2(2)"
  • The "Title" in blue must EXACTLY match the widget title, spaces included.
  • The access level must be wrapped in parenthesis and follow the title.
  • Access Levels are as follows:

    • public = 1
    • associate = 1.5
    • member = 2
    • council = 2.5
    • officer = 3
    • super admin = 4

  • Add more titles by separating each one with a comma
Characters: Mottie Motty Mortie Ooshiny Mot Fudgems
TopBottom

 
 
Key 
New posts No new posts
New posts ( popular ) No new posts ( popular )
New posts ( sticky ) No new posts ( sticky )
New posts ( locked ) No new posts ( locked )
 
 
Who's Online 
There are   members online.
 
 
So-and-so has logged on!
%title%
%message%