/**
  * Indents the HTML content from the left.
  * @param  string UTF-8 encoding or 8-bit
  * @param  int
  * @param  string
  * @return string
  */
 public static function indent($s, $level = 1, $chars = "\t")
 {
     if ($level >= 1) {
         $s = String::replace($s, '#<(textarea|pre).*?</\\1#si', callback(create_function('$m', 'return strtr($m[0], " \\t\\r\\n", "\\x1F\\x1E\\x1D\\x1A");')));
         $s = String::indent($s, $level, $chars);
         $s = strtr($s, "", " \t\r\n");
     }
     return $s;
 }
Beispiel #2
0
 /**
  * Indents the HTML content from the left.
  * @param  string UTF-8 encoding or 8-bit
  * @param  int
  * @param  string
  * @return string
  */
 public static function indent($s, $level = 1, $chars = "\t")
 {
     if ($level >= 1) {
         $s = String::replace($s, '#<(textarea|pre).*?</\\1#si', function ($m) {
             return strtr($m[0], " \t\r\n", "");
         });
         $s = String::indent($s, $level, $chars);
         $s = strtr($s, "", " \t\r\n");
     }
     return $s;
 }
 private function getValidateScript(Rules $rules)
 {
     $res = '';
     foreach ($rules as $rule) {
         if (!is_string($rule->operation)) {
             continue;
         }
         if (strcasecmp($rule->operation, 'Nette\\Forms\\InstantClientScript::javascript') === 0) {
             $res .= "{$rule->arg}\n";
             continue;
         }
         $script = $this->getClientScript($rule->control, $rule->operation, $rule->arg);
         if (!$script) {
             continue;
         }
         if (!empty($rule->message)) {
             // this is rule
             $message = Rules::formatMessage($rule, FALSE);
             $res .= "{$script}\n" . "if (" . ($rule->isNegative ? '' : '!') . "res) " . "return " . Nette\Json::encode((string) $message) . (strpos($message, '%value') === FALSE ? '' : ".replace('%value', val);\n") . ";\n";
         }
         if ($rule->type === Rule::CONDITION) {
             // this is condition
             $innerScript = $this->getValidateScript($rule->subRules);
             if ($innerScript) {
                 $res .= "{$script}\nif (" . ($rule->isNegative ? '!' : '') . "res) {\n" . Nette\String::indent($innerScript) . "}\n";
                 if ($rule->control instanceof ISubmitterControl) {
                     $this->central = FALSE;
                 }
             }
         }
     }
     return $res;
 }