Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

panel only visible to admins

edited January 2008 in Vanilla 1.0 Help
is it possible to have the panel on the comments page only displayed when you are logged in as a admin?


  • Options
    edited January 2008
    Hi, I see two ways to do it, I'll give you the cleanest:
    create a new theme and put a conditional statement around the code of panel.php (some code is stolen from appg/init_vanilla.php)
    // this code is not tested $DisplayPanel = false; if ( $Context->SelfUrl == "comments.php" ) { if ($Context->Session->UserID > 0) { $RequiredPermissions = array('PERMISSION_CHECK_FOR_UPDATES', 'PERMISSION_APPROVE_APPLICANTS', 'PERMISSION_MANAGE_REGISTRATION', 'PERMISSION_ADD_ROLES', 'PERMISSION_EDIT_ROLES', 'PERMISSION_REMOVE_ROLES', 'PERMISSION_ADD_CATEGORIES', 'PERMISSION_EDIT_CATEGORIES', 'PERMISSION_REMOVE_CATEGORIES', 'PERMISSION_SORT_CATEGORIES', 'PERMISSION_CHANGE_APPLICATION_SETTINGS', 'PERMISSION_MANAGE_EXTENSIONS', 'PERMISSION_MANAGE_LANGUAGE', 'PERMISSION_MANAGE_STYLES', 'PERMISSION_MANAGE_THEMES'); $RequiredPermissionsCount = count($RequiredPermissions); $i = 0; for ($i = 0; $i < $RequiredPermissionsCount; $i++) { if ($Context->Session->User->Permission($RequiredPermissions[$i])) { $DisplayPanel = true; break; } } } } if ( ! $Context->SelfUrl == "comments.php" OR $DisplayPanel ) { // old code in panel.php }
    This should always display the panel on other pages than somments.php, and if we're in comments.php, display the panel only if we are authenticated and have a permission among those listed.
  • Options
    woh, thanks so far, looks quite good but doesn't work ._.
    i get a php error because of the following lines

    if ( $Context->SelfUrl == "comments.php" )

    if ( ! $Context->SelfUrl == "comments.php" OR $DisplayPanel )

    i tried

    if (in_array($Context->SelfUrl, array("comments.php"))

    but it didn't work. any idea?
  • Options
    What's the error?
  • Options
    invalid argument
  • Options
    Paste us the whole thing.
  • Options
    sorry (i wasn't even right, shame on me) here it is:

    Notice: Undefined variable: Context in /kunden/121606_86830/monstrs/forum/themes/monstrs/panel.php on line 4 Notice: Undefined variable: Context in /kunden/121606_86830/monstrs/forum/themes/monstrs/panel.php on line 33
  • Options
    edited January 2008
    I think "$Context" needs to be changed to "$this->Context" (the theme patch is being called from within the Panel object).

    Also, wouldn't this be easier?

    // this code is not tested if ( ! $this->Context->SelfUrl == "comments.php" OR $this->Context->Session->User->RoleID > {whatever} ) { // old code in panel.php }
  • Options
    Sounds like timfire is on the money with the $this-> thing. I'm too tired to think about the other bit.
  • Options
    Must work now, Tim is right. Now for the precise condition, I first started to think like the last bit of code, but I'm not good at permissions and role ids and so on. I just copy-pasted the code in appg/init_vanilla.php to be sure to have something like an 'admin condition'. It depends on what Monstr wants.
This discussion has been closed.