-
-
Save ovomatik/3559541 to your computer and use it in GitHub Desktop.
A small MODX snippet to extract POST, GET, SESSION & COOKIE values - (c) 2012 ackwa.fr
This file contains 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 | |
/* | |
* A small MODX snippet to extract POST, GET, SESSION & COOKIE values - (c) 2012 ackwa.fr | |
* | |
* @version : 1.0.1 | |
* @see : https://gist.github.com/gists/2853625 | |
* | |
* @usage : [[!argv?key=`myparam`&default=`1`]] -> return the value | |
* [[!argv?key=`myparam`&default=`1`&toph=`1`]] -> set [[+argv.myparam]] | |
* [[!argv?key=`myparam`&from=`GP`]] -> return the value from GET or POST | |
* | |
* @history : 31/05/12 - 1.0.0 - Initial revision | |
* 31/08/12 - 1.0.1 - Add a source(s) priority parameter (default PGSC) | |
*/ | |
$sDefault = ((isset($default) && $default) ? $default : ''); | |
$sKey = ((isset($key) && $key) ? $key : ''); | |
$bPHolder = ((isset($toph) && $toph) ? true : false); | |
$sFrom = ((isset($from) && $from) ? $from : 'PGSC'); | |
/* | |
* Data sources | |
*/ | |
$lSources = array('P' => '_POST', 'G' => '_GET', 'S' => '_SESSION', 'C' => '_COOKIE'); | |
/* | |
* Test requested key | |
*/ | |
if ($sKey) { | |
$sValue = $sDefault; | |
foreach(str_split($sFrom) as $sSource) { | |
if (isset($GLOBALS[$lSources[$sSource]][$sKey])) { | |
$sValue = $GLOBALS[$lSources[$sSource]][$sKey]; | |
break; | |
} | |
} | |
} | |
else { | |
$sValue = $sDefault; | |
} | |
/* | |
* Test output mode : return value or set placeholder | |
*/ | |
if ($bPHolder) { | |
$modx->toPlaceholder($sKey, $sValue, 'argv'); | |
$sValue = ''; | |
} | |
return $sValue; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment