コード例 #1
0
ファイル: mod_esi.php プロジェクト: poef/ariadne
 function esiExpression($expression)
 {
     /*  Regexp now matches $(HTTP_COOKIE{stuff});
     			TODO:
     			Add matching for:
     				[v] $(HTTP_COOKIE{stuff}|default)
     				[v] $(HTTP_COOKIE{stuff}|'default blah')
     
     			Add variable replacement for:
     				[v] HTTP_ACCEPT_LANGUAGE
     				[v] HTTP_HOST
     				[v] HTTP_REFERER
     				[v] QUERY_STRING
     
     				HTTP_USER_AGENT
     			FIXME: ariadne cookies are serialized by default, which would break HTTP_COOKIE usage in other ESI processors
     		*/
     $result = preg_replace_callback('!\\$\\(([^)|{]*)(\\{(([^}]*))\\})?(\\|([^)]*))?\\)!', function ($matches) {
         // print_r($matches);
         switch ($matches[1]) {
             case 'HTTP_COOKIE':
                 $cookie = ldGetUserCookie($matches[3]);
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return $cookie ? $cookie : $default;
                 break;
             case 'HTTP_HOST':
                 $host = ldGetServerVar('HTTP_HOST');
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return $host ? $host : $default;
                 break;
             case 'HTTP_REFERER':
                 $referer = ldGetServerVar('HTTP_REFERER');
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return $referer ? $referer : $default;
                 break;
             case 'HTTP_ACCEPT_LANGUAGE':
                 $acceptLanguage = ldGetServerVar('HTTP_ACCEPT_LANGUAGE');
                 $acceptLanguage = strtolower(str_replace(", ", ",", $acceptLanguage));
                 $languages = explode(",", $acceptLanguage);
                 if (in_array(strtolower($matches[3]), $languages)) {
                     return 1;
                 }
                 return 0;
                 break;
             case 'QUERY_STRING':
                 $value = ar_loader::getvar($matches[3], "GET");
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return isset($value) ? $value : $default;
                 break;
         }
     }, $expression);
     return $result;
 }
コード例 #2
0
ファイル: ar.php プロジェクト: poef/ariadne
 public function getvar($name)
 {
     global $ARCurrent, $ARConfig;
     if ($ARCurrent->arCallStack) {
         $arCallArgs = end($ARCurrent->arCallStack);
         if ($name == 'arCallArgs') {
             return $arCallArgs;
         }
         if (isset($arCallArgs[$name])) {
             return $arCallArgs[$name];
         }
     } else {
         if ($name == 'arCallArgs') {
             return ar_loader::getvar();
         }
     }
     if (isset($ARCurrent->{$name})) {
         return $ARCurrent->{$name};
     }
     return ar_loader::getvar($name);
 }