Пример #1
0
 static function evalMixedPhpCode($sHtmlAndPhpCode, $amContextVars = array())
 {
     //check security setting
     if (self::isPhpEvalEnabled()) {
         $sReturn = "";
         if (self::contentHasPhpCode($sHtmlAndPhpCode)) {
             //rebuild context vars
             foreach ($amContextVars as $sVarName => $mVarValue) {
                 ${$sVarName} = $mVarValue;
             }
             self::debug("evalPhpCode: Evaluating some PHP code...");
             self::ob_start_capture("evalPhpCode");
             try {
                 $result = eval('?>' . $sHtmlAndPhpCode);
                 if ($result === false) {
                     $sReturn = AnwUtils::ob_end_capture("evalPhpCode");
                     throw new AnwUnexpectedException("Eval failed");
                 }
             } catch (AnwRunInterruptionException $e) {
                 //php code exited, let's continue Anwiki execution...
             }
             $sReturn = AnwUtils::ob_end_capture("evalPhpCode");
         } else {
             self::debug("evalPhpCode: No PHP code found for evaluation...");
             $sReturn = $sHtmlAndPhpCode;
         }
     } else {
         //eval is disabled in configuration
         $sReturn = AnwComponent::g_("err_phpeval_disabled");
     }
     return $sReturn;
 }