예제 #1
0
 /**
  * Clean output before caching and running.
  */
 protected function clean($sContentHtmlAndPhp)
 {
     try {
         if (trim($sContentHtmlAndPhp) == "") {
             return $sContentHtmlAndPhp;
         }
         $sReturn = $sContentHtmlAndPhp;
         //strip out <fix> tags
         $sReturn = self::cleanFixTags($sReturn);
         $sReturn = $this->doBindLinksToPreferedLang($sReturn);
         $sReturn = AnwPlugins::vhook('output_clean', $sReturn, $this->oPage);
         //print nl2br(htmlentities($sReturn)).'<hr/>';
         return $sReturn;
     } catch (AnwException $e) {
         self::debug("local_exec_dynamic_error: " . $e);
         return AnwComponent::g_("local_exec_dynamic_error");
     }
 }
 protected function renderEditInput($sInputValue, $sSuffix, $nInputNumber)
 {
     $sInputName = $this->getInputName($sSuffix);
     $sInputId = $this->getInputId($sInputName, $nInputNumber);
     $asInputParameters = array('dir' => AnwComponent::g_("local_html_dir"));
     $HTML = $this->getDatatype()->renderInput($sInputName, $sInputValue, $sInputId, $asInputParameters);
     return $HTML;
 }
예제 #3
0
 static function reportError($oException, $nErrorNumber = null)
 {
     if (AnwComponent::globalCfgReportFileEnabled() || AnwComponent::globalCfgReportMailEnabled()) {
         if (!$nErrorNumber) {
             $nErrorNumber = time();
         }
         $sExceptionName = get_class($oException);
         $sExceptionMessage = $oException->getMessage();
         self::log("=== exception " . $sExceptionName . " - logged as error #" . $nErrorNumber . " : " . $sExceptionMessage);
         self::endLog();
         $sLoggedStr = "\n\n";
         $sLoggedStr .= "********* BEGIN ERROR LOG #" . $nErrorNumber . "*********\n";
         $sLoggedStr .= "Date : " . date("Y-m-d H:i:s") . "\n";
         $sLoggedStr .= "Exception : " . $sExceptionName . "\n";
         $sLoggedStr .= "Message : " . $sExceptionMessage . "\n";
         $sLoggedStr .= "Stack trace below :\n";
         $sLoggedStr .= " * File " . $oException->getFile() . ", line " . $oException->getLine() . "\n";
         $asTrace = $oException->getTrace();
         foreach ($asTrace as $sTrace) {
             $sLoggedStr .= ' * ';
             if (isset($sTrace['class'])) {
                 $sLoggedStr .= $sTrace['class'];
             }
             if (isset($sTrace['type'])) {
                 $sLoggedStr .= $sTrace['type'];
             }
             $sLoggedStr .= $sTrace['function'];
             //hide args for security reasons
             if (is_array(@$sTrace['args'])) {
                 foreach ($sTrace['args'] as $i => $sArg) {
                     $sTrace['args'][$i] = 'p' . ($i + 1);
                     //$sTrace['args'][$i] = serialize($sArg);
                 }
                 $sLoggedStr .= '(' . implode($sTrace['args'], ", ") . ') - ';
             }
             $sLoggedStr .= 'File ' . @$sTrace['file'] . ', line ' . @$sTrace['line'];
             $sLoggedStr .= "\n";
         }
         $sLoggedStr .= "Execution log below :\n\n";
         $sLoggedStr .= implode("\n", self::$log) . "\n";
         $sLoggedStr .= "********* END ERROR LOG #" . $nErrorNumber . " *********\n";
         if (AnwComponent::globalCfgReportFileEnabled()) {
             try {
                 AnwUtils::file_put_contents(ANWPATH_ERRORLOG, $sLoggedStr, LOCK_EX | FILE_APPEND);
             } catch (AnwException $e) {
             }
         }
         if (AnwComponent::globalCfgReportMailEnabled()) {
             $sSubject = AnwComponent::g_("err_mailreport_subject", array("errornumber" => $nErrorNumber));
             $sBody = AnwComponent::g_("err_mailreport_body", array("website" => AnwComponent::globalCfgWebsiteName()));
             $sBody .= "\n\n" . $sLoggedStr;
             $asEmail = AnwComponent::globalCfgReportMailAddresses();
             foreach ($asEmail as $sEmail) {
                 AnwUtils::mail($sEmail, $sSubject, $sBody);
             }
         }
         return $nErrorNumber;
     }
     return false;
 }
예제 #4
0
 function getDisplayName()
 {
     if (!$this->sDisplayName && !$this->exists()) {
         return AnwComponent::g_("user_displayname_anonymous");
     }
     return $this->sDisplayName;
 }
예제 #5
0
 static function g_err_need_write_file($sFileName)
 {
     return AnwComponent::g_("err_need_write_file", array('filename' => $sFileName, 'processuser' => AnwEnv::getProcessUser(), 'processgroup' => AnwEnv::getProcessGroup()));
 }
예제 #6
0
 function updateContentFromEdition()
 {
     try {
         //update content from post
         $this->getRender(true);
         //check errors
         if ($this->hasErrors()) {
             throw new AnwInvalidContentException();
         }
         return $this->getContent();
     } catch (AnwInvalidContentException $e) {
         $sError = AnwComponent::g_("err_contentinvalid");
         throw new AnwStructuredContentEditionFormException($sError);
     } catch (AnwAclPhpEditionException $e) {
         $sError = $e->getMessage();
         throw new AnwStructuredContentEditionFormException($sError);
     } catch (AnwUnexpectedException $e) {
         $sError = AnwComponent::g_("err_ex_unexpected_p");
         $nErrorNumber = AnwDebug::reportError($e);
         if ($nErrorNumber) {
             $sError .= '<br/>' . $this->g_("err_ex_report", array("errornumber" => $nErrorNumber));
         }
         throw new AnwStructuredContentEditionFormException($sError);
     }
 }
 function getDisplayName()
 {
     return AnwComponent::g_("user_displayname_installassistant");
 }
예제 #8
0
 function getComment()
 {
     return AnwUtils::xText(parent::getComment()) . ' <span class="change_similars">(' . AnwComponent::g_("change_similars", array('count' => count($this->aoSimilarChanges))) . ')</span>';
 }
예제 #9
0
    function renderInput($sInputName, $asInputValues, $sInputId, $asInputParameters = array())
    {
        $sCssClass = $sInputName;
        $sInputName .= '[]';
        $sInputName = AnwUtils::xQuote($sInputName);
        $sInputParameters = $this->inputParametersToHtml($sInputId, $asInputParameters);
        $sChkAll = AnwComponent::g_('in_chkall');
        $sChkNone = AnwComponent::g_('in_chknone');
        $HTML = <<<EOF

\t<fieldset class="contentfield_checkboxgroup">
\t\t<legend>
\t\t\t<a href="#" onclick="AnwUtils.chkall('{$sCssClass}',\$(this).up().up()); return false;">{$sChkAll}</a> 
\t\t\t<a href="#" onclick="AnwUtils.chknone('{$sCssClass}',\$(this).up().up()); return false;">{$sChkNone}</a>
\t\t</legend>
EOF;
        $asEnumValues = $this->getEnumValues();
        $nEnumId = 0;
        foreach ($asEnumValues as $mEnumValue => $sEnumLegend) {
            $mEnumValue = AnwUtils::xQuote($mEnumValue);
            $sSelected = in_array($mEnumValue, $asInputValues) ? ' checked="checked"' : '';
            $sEnumId = $sInputId . $nEnumId;
            $HTML .= <<<EOF

\t\t<div class="checkboxgroup_item">
\t\t<input type="checkbox" id="{$sEnumId}" name="{$sInputName}" class="{$sCssClass}" value="{$mEnumValue}"{$sSelected}/><label for="{$sEnumId}">{$sEnumLegend}</label>
\t\t</div>
EOF;
            $nEnumId++;
        }
        $HTML .= <<<EOF
\t</fieldset>
EOF;
        return $HTML;
    }
예제 #10
0
 private function anwloop_cbk_anwif($asMatches)
 {
     $sCondInstructions = $asMatches[1];
     $sIfContents = $asMatches[2];
     $asKnownOperators = array(self::ANWIF_GT, self::ANWIF_LT, self::ANWIF_EQ, self::ANWIF_NEQ);
     $sReturn = '';
     try {
         list($sOp1, $sOperator, $sOp2) = self::parseOperator($asKnownOperators, $sCondInstructions);
         //evaluate operands - throws AnwUnexpectedException if variable is not in current context
         $sOp1Value = $this->getOperandValue($sOp1);
         $sOp2Value = $this->getOperandValue($sOp2);
         //evaluate the test
         $bTestResult = false;
         switch ($sOperator) {
             case self::ANWIF_GT:
                 $bTestResult = $sOp1Value > $sOp2Value;
                 break;
             case self::ANWIF_LT:
                 $bTestResult = $sOp1Value < $sOp2Value;
                 break;
             case self::ANWIF_EQ:
                 $bTestResult = $sOp1Value == $sOp2Value;
                 break;
             case self::ANWIF_NEQ:
                 $bTestResult = $sOp1Value != $sOp2Value;
                 break;
             default:
                 self::debug("ERROR anwif : Unrecognized operator : " . $sOperator);
                 throw new AnwUnexpectedException("Unrecognized operator : " . $sOperator);
         }
         self::debug("anwif: {$sOp1} ({$sOp1Value}) ; {$sOperator} ; {$sOp2} ({$sOp2Value}) :: " . ($bTestResult ? 'TRUE' : 'FALSE'));
         //return the appropriate block
         $sRegexpElse = '!(.*?)<' . self::TAG_ANWELSE . '/>(.*?)$!si';
         $sTestTrueContents = $sIfContents;
         $sTestFalseContents = "";
         if (preg_match($sRegexpElse, $sIfContents, $asMatchesElse)) {
             $sTestTrueContents = $asMatchesElse[1];
             $sTestFalseContents = $asMatchesElse[2];
         }
         if ($bTestResult) {
             //test is verified, let's add <anwif> contents but not <anwelse>
             $sReturn = $sTestTrueContents;
         } else {
             //test is not verified, let's add only <anwelse> contents (if any)
             $sReturn = $sTestFalseContents;
         }
     } catch (AnwParserException $e) {
         //variable was not in current context, parse it later.
         self::debug("anwif : parse it later");
         return $asMatches[0];
         //just return original value
     } catch (AnwUnexpectedException $e) {
         self::debug("anwif: ERROR, condition not understood : " . $sCondInstructions);
         $sReturn = '[' . AnwComponent::g_("local_exec_condition_error") . ';' . $sCondInstructions . ']';
     }
     return $sReturn;
 }
예제 #11
0
    protected function renderEditInput($sInputValue, $sSuffix, $nInputNumber)
    {
        $sInputName = $this->getInputName($sSuffix);
        $sInputId = $this->getInputId($sInputName, $nInputNumber);
        $asInputParameters = array('dir' => AnwComponent::g_("local_html_dir"));
        $HTML = $this->getDatatype()->renderInput($sInputName, $sInputValue, $sInputId, $asInputParameters);
        $HTML .= <<<EOF

\t<script type="text/javascript">document.observe("dom:loaded", function(){anwLockAutoRenew(\$('{$sInputId}'));});</script>
EOF;
        return $HTML;
    }
예제 #12
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;
 }