Last active
November 5, 2020 15:08
-
-
Save jcamachott/6126869 to your computer and use it in GitHub Desktop.
isAdmin: MODx snippet for displaying content if user is logged into mgr or has a specified IP address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ver 1.1.20201105a | |
// | |
// Most recent: https://gist.github.com/jcamachott/6126869 | |
// | |
// should always be called uncached | |
// Usage: | |
// [[!isAdmin:is=`1`:then=`Do this`:else=`Do that`? &check=`mgr` &disable=`0`]] | |
// | |
// $check - get (has GET var admin=1) or mgr (manager logged in) or ip (ip address set in ++admin_ip) | |
// | |
// $disable - when 1, will always output `Do this` | |
// CHANGELOG: | |
// | |
// Nov 5, 2020: Using $_SERVER['HTTP_X_FORWARDED_FOR'] before $_SERVER['REMOTE_ADDR'] | |
// | |
// | |
$continue = 0; | |
if ($disable==1) { | |
$continue = 1; | |
} | |
if ($check=='get' && $_GET['admin']==1) { | |
$continue = 1; | |
} | |
else | |
{ | |
if (($check=='ip')) | |
{ | |
// only check if admin's IP is in system variable | |
$ip = $modx->config['admin_ip']; | |
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
$remote_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
} else { | |
$remote_ip = $_SERVER['REMOTE_ADDR']; | |
} | |
if ($ip==$remote_ip) | |
{ | |
$continue = 1; | |
} | |
} | |
if ($check=='mgr') | |
{ | |
if ($modx->user instanceof modUser) { | |
if ($modx->user->hasSessionContext('mgr')) { | |
$continue = 1; | |
} | |
} | |
} | |
} | |
return $continue; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment