@@ -110,6 +110,9 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | + /** |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 113 | 116 | function getValue() {
|
| 114 | 117 | if (!is_null($this->setValue)) return $this->setValue; |
| 115 | 118 | if (isset($_REQUEST[$this->form . "_" . $this->name])) {
|
@@ -173,6 +176,9 @@ discard block |
||
| 173 | 176 | } |
| 174 | 177 | } |
| 175 | 178 | |
| 179 | + /** |
|
| 180 | + * @param boolean $submit |
|
| 181 | + */ |
|
| 176 | 182 | function doProcess($submit) {
|
| 177 | 183 | if ($submit) {
|
| 178 | 184 | $value = $this->getValue(); |
@@ -66,7 +66,9 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | function __call($name, $valarray) {
|
| 69 | - if (count($valarray) < 1) return $this->__get($name); |
|
| 69 | + if (count($valarray) < 1) { |
|
| 70 | + return $this->__get($name); |
|
| 71 | + } |
|
| 70 | 72 | $val = count($valarray) == 1 ? current($valarray) : $valarray; |
| 71 | 73 | switch ($name) {
|
| 72 | 74 | case "name": |
@@ -111,12 +113,15 @@ discard block |
||
| 111 | 113 | } |
| 112 | 114 | |
| 113 | 115 | function getValue() {
|
| 114 | - if (!is_null($this->setValue)) return $this->setValue; |
|
| 116 | + if (!is_null($this->setValue)) { |
|
| 117 | + return $this->setValue; |
|
| 118 | + } |
|
| 115 | 119 | if (isset($_REQUEST[$this->form . "_" . $this->name])) {
|
| 116 | - if (get_magic_quotes_runtime()) |
|
| 117 | - return stripslashes($_REQUEST[$this->form . "_" . $this->name]); |
|
| 118 | - else |
|
| 119 | - return $_REQUEST[$this->form . "_" . $this->name]; |
|
| 120 | + if (get_magic_quotes_runtime()) { |
|
| 121 | + return stripslashes($_REQUEST[$this->form . "_" . $this->name]); |
|
| 122 | + } else { |
|
| 123 | + return $_REQUEST[$this->form . "_" . $this->name]; |
|
| 124 | + } |
|
| 120 | 125 | } |
| 121 | 126 | return $this->opt['default']; |
| 122 | 127 | } |
@@ -133,12 +138,15 @@ discard block |
||
| 133 | 138 | if (!$this->valid) {
|
| 134 | 139 | $atts['class'][] = "hamleFormError"; |
| 135 | 140 | } |
| 136 | - if ($this->opt["disabled"]) |
|
| 137 | - $atts['disabled'] = "disabled"; |
|
| 138 | - if ($this->opt['required']) |
|
| 139 | - $atts['required'] = "required"; |
|
| 140 | - if ($this->opt['help']) |
|
| 141 | - $atts['title'] = $this->opt['help']; |
|
| 141 | + if ($this->opt["disabled"]) { |
|
| 142 | + $atts['disabled'] = "disabled"; |
|
| 143 | + } |
|
| 144 | + if ($this->opt['required']) { |
|
| 145 | + $atts['required'] = "required"; |
|
| 146 | + } |
|
| 147 | + if ($this->opt['help']) { |
|
| 148 | + $atts['title'] = $this->opt['help']; |
|
| 149 | + } |
|
| 142 | 150 | } |
| 143 | 151 | |
| 144 | 152 | function getLabelAttStatic(&$atts, &$type, &$content) {
|
@@ -176,10 +184,12 @@ discard block |
||
| 176 | 184 | function doProcess($submit) {
|
| 177 | 185 | if ($submit) {
|
| 178 | 186 | $value = $this->getValue(); |
| 179 | - if ($this->opt['required']) |
|
| 180 | - $this->valid = $this->valid && strlen($value); |
|
| 181 | - if ($this->opt['regex']) |
|
| 182 | - $this->valid = $this->valid && preg_match($this->opt['regex'], $value); |
|
| 187 | + if ($this->opt['required']) { |
|
| 188 | + $this->valid = $this->valid && strlen($value); |
|
| 189 | + } |
|
| 190 | + if ($this->opt['regex']) { |
|
| 191 | + $this->valid = $this->valid && preg_match($this->opt['regex'], $value); |
|
| 192 | + } |
|
| 183 | 193 | } |
| 184 | 194 | } |
| 185 | 195 | |
@@ -112,19 +112,19 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | function getValue() {
|
| 114 | 114 | if (!is_null($this->setValue)) return $this->setValue; |
| 115 | - if (isset($_REQUEST[$this->form . "_" . $this->name])) {
|
|
| 115 | + if (isset($_REQUEST[$this->form."_".$this->name])) {
|
|
| 116 | 116 | if (get_magic_quotes_runtime()) |
| 117 | - return stripslashes($_REQUEST[$this->form . "_" . $this->name]); |
|
| 117 | + return stripslashes($_REQUEST[$this->form."_".$this->name]); |
|
| 118 | 118 | else |
| 119 | - return $_REQUEST[$this->form . "_" . $this->name]; |
|
| 119 | + return $_REQUEST[$this->form."_".$this->name]; |
|
| 120 | 120 | } |
| 121 | 121 | return $this->opt['default']; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | function getInputAttStatic(&$atts, &$type, &$content) {
|
| 125 | - $atts['id'] = $atts['name'] = $this->form . "_" . $this->name; |
|
| 125 | + $atts['id'] = $atts['name'] = $this->form."_".$this->name; |
|
| 126 | 126 | $atts['type'] = "text"; |
| 127 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 127 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | function getInputAttDynamic(&$atts, &$type, &$content) {
|
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | function getLabelAttStatic(&$atts, &$type, &$content) {
|
| 145 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 146 | - $atts["for"] = $this->form . "_" . $this->name; |
|
| 145 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 146 | + $atts["for"] = $this->form."_".$this->name; |
|
| 147 | 147 | $content = array($this->opt['label']); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | function getHintAttStatic(&$atts, &$type, &$content) {
|
| 154 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); |
|
| 154 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); |
|
| 155 | 155 | $atts['class'][] = "hamleFormHint"; |
| 156 | 156 | } |
| 157 | 157 | |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | namespace Seufert\Hamle; |
| 27 | 27 | |
| 28 | -use Seufert\Hamle\Exception\RunTime; |
|
| 28 | +use Seufert\Hamle\Exception\RunTime; |
|
| 29 | 29 | use Seufert\Hamle\Model; |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -54,10 +54,11 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | static function popInstance() {
|
| 56 | 56 | array_pop(self::$hamleList); |
| 57 | - if (self::$hamleList) |
|
| 58 | - self::$hamle = self::$hamleList[count(self::$hamleList) - 1]; |
|
| 59 | - else |
|
| 60 | - self::$hamle = NULL; |
|
| 57 | + if (self::$hamleList) { |
|
| 58 | + self::$hamle = self::$hamleList[count(self::$hamleList) - 1]; |
|
| 59 | + } else { |
|
| 60 | + self::$hamle = NULL; |
|
| 61 | + } |
|
| 61 | 62 | } |
| 62 | 63 | |
| 63 | 64 | /** |
@@ -116,7 +117,9 @@ discard block |
||
| 116 | 117 | static function modelId($id, $sortDir = 0, $sortField = "", $limit = 0, $offset = 0) {
|
| 117 | 118 | $o = self::$hamle->setup->getModelDefault($id, |
| 118 | 119 | $sortDir, $sortField, $limit, $offset); |
| 119 | - if (!$o instanceOf Model) throw new RunTime("Application must return instance of hamleModel");
|
|
| 120 | + if (!$o instanceOf Model) { |
|
| 121 | + throw new RunTime("Application must return instance of hamleModel"); |
|
| 122 | + } |
|
| 120 | 123 | return $o; |
| 121 | 124 | } |
| 122 | 125 | |
@@ -17,6 +17,9 @@ |
||
| 17 | 17 | /** @var Model[] Assoc array of Models by Scope Name */ |
| 18 | 18 | static $namedScopes = array(); |
| 19 | 19 | |
| 20 | + /** |
|
| 21 | + * @param Model $model |
|
| 22 | + */ |
|
| 20 | 23 | static function add($model, $name = null) {
|
| 21 | 24 | if (!$model instanceOf Model) |
| 22 | 25 | throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface");
|
@@ -1,9 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Seufert\Hamle; |
| 3 | 3 | |
| 4 | -use Seufert\Hamle\Exception\OutOfScope; |
|
| 5 | -use Seufert\Hamle\Exception\Unsupported; |
|
| 6 | -use Seufert\Hamle\Exception\RunTime; |
|
| 4 | +use Seufert\Hamle\Exception\OutOfScope; |
|
| 5 | +use Seufert\Hamle\Exception\Unsupported; |
|
| 6 | +use Seufert\Hamle\Exception\RunTime; |
|
| 7 | 7 | use Seufert\Hamle\Model; |
| 8 | 8 | |
| 9 | 9 | /** |
@@ -18,12 +18,14 @@ discard block |
||
| 18 | 18 | static $namedScopes = array(); |
| 19 | 19 | |
| 20 | 20 | static function add($model, $name = null) {
|
| 21 | - if (!$model instanceOf Model) |
|
| 22 | - throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface");
|
|
| 23 | - if ($name) |
|
| 24 | - self::$namedScopes[$name] = $model; |
|
| 25 | - else |
|
| 26 | - self::$scopes[] = $model; |
|
| 21 | + if (!$model instanceOf Model) { |
|
| 22 | + throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
| 23 | + } |
|
| 24 | + if ($name) { |
|
| 25 | + self::$namedScopes[$name] = $model; |
|
| 26 | + } else { |
|
| 27 | + self::$scopes[] = $model; |
|
| 28 | + } |
|
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | static function done() {
|
@@ -41,15 +43,21 @@ discard block |
||
| 41 | 43 | */ |
| 42 | 44 | static function get($id = 0) {
|
| 43 | 45 | if (0 == $id) {
|
| 44 | - if ($scope = end(self::$scopes)) |
|
| 45 | - return $scope; |
|
| 46 | + if ($scope = end(self::$scopes)) { |
|
| 47 | + return $scope; |
|
| 48 | + } |
|
| 46 | 49 | throw new OutOfScope("Unable to find Scope ($id)");
|
| 47 | 50 | } |
| 48 | 51 | $key = $id - 1; |
| 49 | - if ($id < 0) $key = count(self::$scopes) + $id - 1; |
|
| 50 | - if ($id == 0) $key = count(self::$scopes) - 1; |
|
| 51 | - if (!isset(self::$scopes[$key])) |
|
| 52 | - throw new OutOfScope("Unable to find Scope ($id) or $key");
|
|
| 52 | + if ($id < 0) { |
|
| 53 | + $key = count(self::$scopes) + $id - 1; |
|
| 54 | + } |
|
| 55 | + if ($id == 0) { |
|
| 56 | + $key = count(self::$scopes) - 1; |
|
| 57 | + } |
|
| 58 | + if (!isset(self::$scopes[$key])) { |
|
| 59 | + throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
| 60 | + } |
|
| 53 | 61 | return self::$scopes[$key]; |
| 54 | 62 | } |
| 55 | 63 | |
@@ -64,8 +72,9 @@ discard block |
||
| 64 | 72 | if ($name && isset(self::$namedScopes[$name])) {
|
| 65 | 73 | self::$namedScopes[$name]->rewind(); |
| 66 | 74 | return self::$namedScopes[$name]; |
| 67 | - } else |
|
| 68 | - throw new RunTime("Unable to find scope ($name)");
|
|
| 75 | + } else { |
|
| 76 | + throw new RunTime("Unable to find scope ($name)"); |
|
| 77 | + } |
|
| 69 | 78 | } |
| 70 | 79 | |
| 71 | 80 | } |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | /** |
| 49 | 49 | * Open the default model when only an ID is specified in the template |
| 50 | 50 | * |
| 51 | - * @param mixed $id Identifier when no type is passed |
|
| 52 | - * @param array $sort |
|
| 51 | + * @param string $id Identifier when no type is passed |
|
| 52 | + * @param integer $sort |
|
| 53 | 53 | * @param int $limit Results Limit |
| 54 | 54 | * @param int $offset Results Offset |
| 55 | 55 | * @return Model Instance of model class that implements hamleModel |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * Open a specific model type with id |
| 61 | 61 | * |
| 62 | 62 | * @param array[] $typeId Type ID array [type=>[id]] or [page=>[3]] |
| 63 | - * @param array $sort |
|
| 63 | + * @param integer $sort |
|
| 64 | 64 | * @param int $limit Results Limit |
| 65 | 65 | * @param int $offset Results Offset |
| 66 | 66 | * @return Model |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Return Iterator containing results from search of tags |
| 77 | 77 | * |
| 78 | 78 | * @param array[] $typeTags Type Tag Array [type=>[tag1,tag2],type2=>[]] |
| 79 | - * @param array $sort |
|
| 79 | + * @param integer $sort |
|
| 80 | 80 | * @param int $limit Results Limit |
| 81 | 81 | * @param int $offset Results Limit |
| 82 | 82 | * @return Model Instance of Iterable model class |
@@ -41,7 +41,9 @@ discard block |
||
| 41 | 41 | public function cachePath($f) {
|
| 42 | 42 | $s = DIRECTORY_SEPARATOR; |
| 43 | 43 | $dir = implode($s,[__DIR__,"..","..","cache",""]); |
| 44 | - if(!is_dir($dir)) mkdir($dir); |
|
| 44 | + if(!is_dir($dir)) { |
|
| 45 | + mkdir($dir); |
|
| 46 | + } |
|
| 45 | 47 | return $dir.$f; |
| 46 | 48 | } |
| 47 | 49 | |
@@ -67,8 +69,9 @@ discard block |
||
| 67 | 69 | * @throws Exception\RunTime |
| 68 | 70 | */ |
| 69 | 71 | public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) {
|
| 70 | - if(count($typeId) > 1) |
|
| 71 | - throw new Exception\RunTime("Unable to open more than one ID at a time");
|
|
| 72 | + if(count($typeId) > 1) { |
|
| 73 | + throw new Exception\RunTime("Unable to open more than one ID at a time"); |
|
| 74 | + } |
|
| 72 | 75 | return new Model\Zero(); |
| 73 | 76 | } |
| 74 | 77 | |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function cachePath($f) {
|
| 42 | 42 | $s = DIRECTORY_SEPARATOR; |
| 43 | - $dir = implode($s,[__DIR__,"..","..","cache",""]); |
|
| 44 | - if(!is_dir($dir)) mkdir($dir); |
|
| 43 | + $dir = implode($s, [__DIR__, "..", "..", "cache", ""]); |
|
| 44 | + if (!is_dir($dir)) mkdir($dir); |
|
| 45 | 45 | return $dir.$f; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @throws Exception\RunTime |
| 68 | 68 | */ |
| 69 | 69 | public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) {
|
| 70 | - if(count($typeId) > 1) |
|
| 70 | + if (count($typeId) > 1) |
|
| 71 | 71 | throw new Exception\RunTime("Unable to open more than one ID at a time");
|
| 72 | 72 | return new Model\Zero(); |
| 73 | 73 | } |
@@ -13,6 +13,9 @@ |
||
| 13 | 13 | protected $s; |
| 14 | 14 | protected $type; |
| 15 | 15 | |
| 16 | + /** |
|
| 17 | + * @param string $s |
|
| 18 | + */ |
|
| 16 | 19 | function __construct($s, $type = self::TOKEN_HTML) { |
| 17 | 20 | $this->s = str_replace('\\$', "$", $s); |
| 18 | 21 | $this->type = $type; |
@@ -23,8 +23,9 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | function toHTML($escape = false) { |
| 26 | - if ($this->type == self::TOKEN_CODE) |
|
| 27 | - return $this->s; |
|
| 26 | + if ($this->type == self::TOKEN_CODE) { |
|
| 27 | + return $this->s; |
|
| 28 | + } |
|
| 28 | 29 | return htmlspecialchars($this->s); |
| 29 | 30 | } |
| 30 | 31 | } |
| 31 | 32 | \ No newline at end of file |
@@ -38,7 +38,9 @@ |
||
| 38 | 38 | $s = DIRECTORY_SEPARATOR; |
| 39 | 39 | $class = str_replace("\\",$s,substr($class,14));
|
| 40 | 40 | $path = __DIR__.$s."hamle".$s."$class.php"; |
| 41 | - if(is_file($path)) include_once($path); |
|
| 41 | + if(is_file($path)) { |
|
| 42 | + include_once($path); |
|
| 43 | + } |
|
| 42 | 44 | } |
| 43 | 45 | },true,true); |
| 44 | 46 | |
@@ -34,11 +34,11 @@ |
||
| 34 | 34 | * @param string $class Class name to be autoloaded |
| 35 | 35 | */ |
| 36 | 36 | spl_autoload_register(function($class) {
|
| 37 | - if(strpos($class, "Seufert\\Hamle\\") === 0) {
|
|
| 37 | + if (strpos($class, "Seufert\\Hamle\\") === 0) {
|
|
| 38 | 38 | $s = DIRECTORY_SEPARATOR; |
| 39 | - $class = str_replace("\\",$s,substr($class,14));
|
|
| 39 | + $class = str_replace("\\", $s, substr($class, 14));
|
|
| 40 | 40 | $path = __DIR__.$s."hamle".$s."$class.php"; |
| 41 | - if(is_file($path)) include_once($path); |
|
| 41 | + if (is_file($path)) include_once($path); |
|
| 42 | 42 | } |
| 43 | -},true,true); |
|
| 43 | +},true, true); |
|
| 44 | 44 | |
@@ -34,14 +34,18 @@ |
||
| 34 | 34 | static function filterText($s) { |
| 35 | 35 | $as = explode("\n", $s); |
| 36 | 36 | $indent = -1; |
| 37 | - foreach ($as as $line) |
|
| 38 | - if (preg_match('/^(\s+).*$/', $line, $m)) { |
|
| 37 | + foreach ($as as $line) { |
|
| 38 | + if (preg_match('/^(\s+).*$/', $line, $m)) { |
|
| 39 | 39 | $lnInd = strlen($m[1]); |
| 40 | - if ($indent < 0) $indent = $lnInd; |
|
| 40 | + } |
|
| 41 | + if ($indent < 0) { |
|
| 42 | + $indent = $lnInd; |
|
| 43 | + } |
|
| 41 | 44 | $indent = min($indent, $lnInd); |
| 42 | 45 | } |
| 43 | - foreach ($as as $k => $v) |
|
| 44 | - $as[$k] = substr($v, $indent); |
|
| 46 | + foreach ($as as $k => $v) { |
|
| 47 | + $as[$k] = substr($v, $indent); |
|
| 48 | + } |
|
| 45 | 49 | $s = implode("\n", $as); |
| 46 | 50 | |
| 47 | 51 | require_once ME_DIR . "/lib/phpsass/SassParser.php"; |
@@ -44,13 +44,13 @@ |
||
| 44 | 44 | $as[$k] = substr($v, $indent); |
| 45 | 45 | $s = implode("\n", $as); |
| 46 | 46 | |
| 47 | - require_once ME_DIR . "/lib/phpsass/SassParser.php"; |
|
| 47 | + require_once ME_DIR."/lib/phpsass/SassParser.php"; |
|
| 48 | 48 | $sp = new SassParser(array("cache" => FALSE, |
| 49 | 49 | "style" => stdConf::get("me.developer") ? SassRenderer::STYLE_EXPANDED : SassRenderer::STYLE_COMPRESSED, |
| 50 | 50 | "syntax" => SassFile::SASS, 'debug' => TRUE)); |
| 51 | 51 | $tree = $sp->toTree($s); |
| 52 | 52 | $out = $tree->render(); |
| 53 | 53 | $pad = str_pad("", $indent, " "); |
| 54 | - return $pad . str_replace("\n", "\n$pad", trim($out)); |
|
| 54 | + return $pad.str_replace("\n", "\n$pad", trim($out)); |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -53,39 +53,48 @@ discard block |
||
| 53 | 53 | $pos = 0; |
| 54 | 54 | $this->nodes = array(); |
| 55 | 55 | $rFlag = PREG_OFFSET_CAPTURE + PREG_SET_ORDER; |
| 56 | - if (strlen(trim($s)) == 0) return; |
|
| 56 | + if (strlen(trim($s)) == 0) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 57 | 59 | if ($mode == self::TOKEN_CONTROL) { |
| 58 | 60 | if (preg_match('/^"(.*)"$/', trim($s), $m)) { |
| 59 | 61 | $this->nodes[] = new Text($m[1]); |
| 60 | - } else |
|
| 61 | - $this->nodes[] = new Text\Complex(trim($s)); |
|
| 62 | + } else { |
|
| 63 | + $this->nodes[] = new Text\Complex(trim($s)); |
|
| 64 | + } |
|
| 62 | 65 | return; |
| 63 | 66 | } |
| 64 | 67 | preg_match_all(self::REGEX_HTML, $s, $m, $rFlag); |
| 65 | 68 | foreach ($m as $match) { |
| 66 | 69 | if ($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
| 67 | - if ($match[2][1] != $pos) |
|
| 68 | - $this->nodes[] = new Text\Plain( |
|
| 70 | + if ($match[2][1] != $pos) { |
|
| 71 | + $this->nodes[] = new Text\Plain( |
|
| 69 | 72 | substr($s, $pos, $match[2][1] - $pos), $mode); |
| 73 | + } |
|
| 70 | 74 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
| 71 | 75 | $pos = $match[2][1] + strlen($match[2][0]); |
| 72 | 76 | } elseif ($mode & self::FIND_DOLLARVAR) { |
| 73 | - if ($match[1][1] > 0 && $s[$match[1][1] - 1] == '\\') continue; |
|
| 74 | - if ($match[1][1] != $pos) |
|
| 75 | - $this->nodes[] = new Text\Plain( |
|
| 77 | + if ($match[1][1] > 0 && $s[$match[1][1] - 1] == '\\') { |
|
| 78 | + continue; |
|
| 79 | + } |
|
| 80 | + if ($match[1][1] != $pos) { |
|
| 81 | + $this->nodes[] = new Text\Plain( |
|
| 76 | 82 | substr($s, $pos, $match[1][1] - $pos), $mode); |
| 83 | + } |
|
| 77 | 84 | $this->nodes[] = new Text\SimpleVar($match[1][0]); |
| 78 | 85 | $pos = $match[1][1] + strlen($match[1][0]); |
| 79 | 86 | } |
| 80 | 87 | } |
| 81 | - if ($pos != strlen($s)) |
|
| 82 | - $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
|
| 88 | + if ($pos != strlen($s)) { |
|
| 89 | + $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
|
| 90 | + } |
|
| 83 | 91 | } |
| 84 | 92 | |
| 85 | 93 | function toHTML($escape = false) { |
| 86 | 94 | $out = array(); |
| 87 | - foreach ($this->nodes as $string) |
|
| 88 | - $out[] = $string->toHTML($escape); |
|
| 95 | + foreach ($this->nodes as $string) { |
|
| 96 | + $out[] = $string->toHTML($escape); |
|
| 97 | + } |
|
| 89 | 98 | return implode("", $out); |
| 90 | 99 | } |
| 91 | 100 | |
@@ -95,8 +104,9 @@ discard block |
||
| 95 | 104 | |
| 96 | 105 | function toPHP() { |
| 97 | 106 | $out = array(); |
| 98 | - foreach ($this->nodes as $string) |
|
| 99 | - $out[] = $string->toPHP(); |
|
| 107 | + foreach ($this->nodes as $string) { |
|
| 108 | + $out[] = $string->toPHP(); |
|
| 109 | + } |
|
| 100 | 110 | return implode(".", $out); |
| 101 | 111 | } |
| 102 | 112 | |
@@ -107,8 +117,9 @@ discard block |
||
| 107 | 117 | static function varToCode($var) { |
| 108 | 118 | if (is_array($var)) { |
| 109 | 119 | $code = array(); |
| 110 | - foreach ($var as $key => $value) |
|
| 111 | - $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
| 120 | + foreach ($var as $key => $value) { |
|
| 121 | + $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
| 122 | + } |
|
| 112 | 123 | return 'array(' . implode(",", $code) . ')'; //remove unnecessary coma |
| 113 | 124 | } elseif (is_bool($var)) { |
| 114 | 125 | return ($var ? 'TRUE' : 'FALSE'); |
@@ -101,15 +101,15 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function doEval() { |
| 104 | - return eval('return ' . $this->toPHP() . ';'); |
|
| 104 | + return eval('return '.$this->toPHP().';'); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | static function varToCode($var) { |
| 108 | 108 | if (is_array($var)) { |
| 109 | 109 | $code = array(); |
| 110 | 110 | foreach ($var as $key => $value) |
| 111 | - $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
| 112 | - return 'array(' . implode(",", $code) . ')'; //remove unnecessary coma |
|
| 111 | + $code[] = self::varToCode($key)."=>".self::varToCode($value); |
|
| 112 | + return 'array('.implode(",", $code).')'; //remove unnecessary coma |
|
| 113 | 113 | } elseif (is_bool($var)) { |
| 114 | 114 | return ($var ? 'TRUE' : 'FALSE'); |
| 115 | 115 | } elseif (is_int($var) || is_float($var) || is_numeric($var)) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | } elseif ($var instanceof Text) { |
| 118 | 118 | return $var->toPHP(); |
| 119 | 119 | } else { |
| 120 | - return "'" . str_replace(array('$', "'"), array('\\$', "\\'"), $var) . "'"; |
|
| 120 | + return "'".str_replace(array('$', "'"), array('\\$', "\\'"), $var)."'"; |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -60,11 +60,14 @@ |
||
| 60 | 60 | $out = "<" . $d['type'] . " "; |
| 61 | 61 | foreach ($d['opt'] as $k => $v) { |
| 62 | 62 | if (is_array($v)) { |
| 63 | - foreach ($v as $k2 => $v2) |
|
| 64 | - if ($v[$k2] instanceof Text) $v[$k2] = eval('return ' . $v[$k2]->toPHP() . ';'); |
|
| 63 | + foreach ($v as $k2 => $v2) { |
|
| 64 | + if ($v[$k2] instanceof Text) $v[$k2] = eval('return ' . $v[$k2]->toPHP() . ';'); |
|
| 65 | + } |
|
| 65 | 66 | $v = implode(" ", $v); |
| 66 | 67 | } |
| 67 | - if ($v instanceOf H\Text) $v = eval('return ' . $v->toPHP() . ';'); |
|
| 68 | + if ($v instanceOf H\Text) { |
|
| 69 | + $v = eval('return ' . $v->toPHP() . ';'); |
|
| 70 | + } |
|
| 68 | 71 | $out .= $k . "=\"" . htmlspecialchars($v) . "\" "; |
| 69 | 72 | } |
| 70 | 73 | $out .= in_array($d['type'], self::$selfCloseTags) ? "/>" : ">"; |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | $this->source[] = $ref; |
| 39 | 39 | $this->baseType = $tag; |
| 40 | 40 | self::$var++; |
| 41 | - $this->varname = "\$dynhtml" . self::$var; |
|
| 41 | + $this->varname = "\$dynhtml".self::$var; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function render($indent = 0, $doIndent = true) { |
| 45 | 45 | $data = H\Text::varToCode(array("base" => $this->baseType, "type" => $this->type, "opt" => $this->opt, "source" => $this->source, "content" => $this->content)); |
| 46 | - $out = "<?php " . $this->varname . "=$data; echo Hamle\\Tag\\DynHtml::toStTag(" . $this->varname . ",\$form)."; |
|
| 47 | - $out .= "implode(\"\\n\"," . $this->varname . "['content'])."; |
|
| 48 | - $out .= "Hamle\\Tag\\DynHtml::toEnTag(" . $this->varname . ",\$form)?>\n"; |
|
| 46 | + $out = "<?php ".$this->varname."=$data; echo Hamle\\Tag\\DynHtml::toStTag(".$this->varname.",\$form)."; |
|
| 47 | + $out .= "implode(\"\\n\",".$this->varname."['content'])."; |
|
| 48 | + $out .= "Hamle\\Tag\\DynHtml::toEnTag(".$this->varname.",\$form)?>\n"; |
|
| 49 | 49 | return $out; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | foreach ($d["source"] as $source) { |
| 58 | 58 | $form->getField($source)->getDynamicAtt($d['base'], $d['opt'], $d['type'], $d['content']); |
| 59 | 59 | } |
| 60 | - $out = "<" . $d['type'] . " "; |
|
| 60 | + $out = "<".$d['type']." "; |
|
| 61 | 61 | foreach ($d['opt'] as $k => $v) { |
| 62 | 62 | if (is_array($v)) { |
| 63 | 63 | foreach ($v as $k2 => $v2) |
| 64 | - if ($v[$k2] instanceof Text) $v[$k2] = eval('return ' . $v[$k2]->toPHP() . ';'); |
|
| 64 | + if ($v[$k2] instanceof Text) $v[$k2] = eval('return '.$v[$k2]->toPHP().';'); |
|
| 65 | 65 | $v = implode(" ", $v); |
| 66 | 66 | } |
| 67 | - if ($v instanceOf H\Text) $v = eval('return ' . $v->toPHP() . ';'); |
|
| 68 | - $out .= $k . "=\"" . htmlspecialchars($v) . "\" "; |
|
| 67 | + if ($v instanceOf H\Text) $v = eval('return '.$v->toPHP().';'); |
|
| 68 | + $out .= $k."=\"".htmlspecialchars($v)."\" "; |
|
| 69 | 69 | } |
| 70 | 70 | $out .= in_array($d['type'], self::$selfCloseTags) ? "/>" : ">"; |
| 71 | 71 | return $out; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | static function toEnTag($d, $form) { |
| 75 | - return in_array($d['type'], self::$selfCloseTags) ? "" : "</" . $d['type'] . ">"; |
|
| 75 | + return in_array($d['type'], self::$selfCloseTags) ? "" : "</".$d['type'].">"; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -33,6 +33,11 @@ |
||
| 33 | 33 | protected $varname; |
| 34 | 34 | protected $baseType; |
| 35 | 35 | |
| 36 | + /** |
|
| 37 | + * @param string $tag |
|
| 38 | + * @param string $id |
|
| 39 | + * @param integer $ref |
|
| 40 | + */ |
|
| 36 | 41 | function __construct($tag, $class, $param, $id, $ref) { |
| 37 | 42 | parent::__construct($tag, $class, $param, $id); |
| 38 | 43 | $this->source[] = $ref; |