示例#1
0
 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
             $res .= "{$script}\n" . "if (" . ($rule->isNegative ? '' : '!') . "res) " . "return " . json_encode((string) vsprintf($rule->control->translate($rule->message, is_int($rule->arg) ? $rule->arg : NULL), (array) $rule->arg)) . ";\n";
         }
         if ($rule->type === Rule::CONDITION) {
             // this is condition
             $innerScript = $this->getValidateScript($rule->subRules);
             if ($innerScript) {
                 $res .= "{$script}\nif (" . ($rule->isNegative ? '!' : '') . "res) {\n" . String::indent($innerScript) . "}\n";
                 if ($rule->control instanceof ISubmitterControl) {
                     $this->central = FALSE;
                 }
             }
         }
     }
     return $res;
 }
示例#2
0
			</div>
		<?php 
} else {
    echo $this->element('header');
    ?>
			<div id="app">
				<?php 
    echo $this->element('mainMenu');
    ?>
				<?php 
    echo $this->element('flashMessage');
    ?>
				<div id="content">
					<?php 
    echo @$content;
    ?>
				</div>
				<?php 
    echo $this->element('footer');
    ?>
			</div>
			<?php 
}
if (isset($JavaScript)) {
    $JavaScript->addFiles(array('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js', 'js.class.core', 'php.custom.min', 'swfobject.js', 'jquery.placeholder/jquery.placeholder.js', 'jquery.plugin.fieldselection', 'jquery.plugin.dialog', 'jquery.plugin.simplePreview', 'admin', 'tabs'));
    echo String::indent($JavaScript->render(), 2, TAB, 1);
}
echo $this->element('debug/dump');
?>
	</body>
</html>
 /**
  * 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 = preg_replace_callback('#<(textarea|pre).*?</\\1#si', array(__CLASS__, 'indentCb'), $s);
         $s = String::indent($s, $level, $chars);
         $s = strtr($s, "", "\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 " . 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" . String::indent($innerScript) . "}\n";
                 if ($rule->control instanceof ISubmitterControl) {
                     $this->central = FALSE;
                 }
             }
         }
     }
     return $res;
 }
示例#5
0
 /**
  * indent test.
  * @return void
  */
 public function testIndent()
 {
     $this->assertEquals("", String::indent(""));
     $this->assertEquals("\n", String::indent("\n"));
     $this->assertEquals("\tword", String::indent("word"));
     $this->assertEquals("\n\tword", String::indent("\nword"));
     $this->assertEquals("\n\tword", String::indent("\nword"));
     $this->assertEquals("\n\tword\n", String::indent("\nword\n"));
     $this->assertEquals("\r\n\tword\r\n", String::indent("\r\nword\r\n"));
     $this->assertEquals("\r\n\t\tword\r\n", String::indent("\r\nword\r\n", 2));
     $this->assertEquals("\r\n      word\r\n", String::indent("\r\nword\r\n", 2, '   '));
 }
示例#6
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', 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;
 }
示例#7
0
 private function renderOptUsage(array $optionInfo, $width = 80)
 {
     $optionValue = '';
     if (isset($optionInfo['dest']) && isset($optionInfo['type']) && $optionInfo['type'] != self::TYPE_BOOL) {
         $optionValue .= ' ' . strtoupper($optionInfo['dest']);
     }
     // collect short and long options
     $argList = array();
     if (!empty($optionInfo['short'])) {
         $argList[] = '-' . $optionInfo['short'] . $optionValue;
     }
     if (!empty($optionInfo['long'])) {
         $argList[] = '--' . $optionInfo['long'] . $optionValue;
     }
     $argListRendered = '  ' . implode(', ', $argList);
     $usage = $argListRendered;
     // add description to argument hint if set
     if (isset($optionInfo['help'])) {
         // if the usage parameters is to long, put help to the next line
         if (strlen($usage) > 22) {
             $usage .= LF;
             $helpMessage = wordwrap($optionInfo['help'], $width - 24 - 2, LF, true);
             $usage .= String::indent($helpMessage, 24, ' ');
             // or add the parameter help message in the next line, indented
         } else {
             $usage .= str_repeat(' ', 24 - strlen($usage));
             $m = wordwrap($optionInfo['help'], $width - 24, LF, true);
             $a = explode(LF, $m);
             $usage .= array_shift($a);
             if (count($a) > 0) {
                 $usage .= LF;
             }
             $usage .= String::indent(implode(LF, $a), 24, ' ');
         }
     }
     return $usage;
 }