| @@ -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));
 | |
| 40 | - $path = __DIR__.$s."hamle".$s."$class.php"; | |
| 41 | - if(is_file($path)) include_once($path); | |
| 39 | +    $class = str_replace("\\", $s, substr($class, 14));
 | |
| 40 | + $path = __DIR__ . $s . "hamle" . $s . "$class.php"; | |
| 41 | + if (is_file($path)) include_once($path); | |
| 42 | 42 | } | 
| 43 | -},true,true); | |
| 43 | +},true, true); | |
| 44 | 44 | |
| @@ -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 | |
| @@ -124,7 +124,7 @@ discard block | ||
| 124 | 124 |    function getInputAttStatic(&$atts, &$type, &$content) {
 | 
| 125 | 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,7 +142,7 @@ discard block | ||
| 142 | 142 | } | 
| 143 | 143 | |
| 144 | 144 |    function getLabelAttStatic(&$atts, &$type, &$content) {
 | 
| 145 | - $atts['class'][] = str_replace(['Seufert\\','\\'],['','_'],get_class($this)); | |
| 145 | + $atts['class'][] = str_replace(['Seufert\\', '\\'], ['', '_'], get_class($this)); | |
| 146 | 146 | $atts["for"] = $this->form . "_" . $this->name; | 
| 147 | 147 | $content = array($this->opt['label']); | 
| 148 | 148 | } | 
| @@ -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 | |
| @@ -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 | |
| @@ -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"; | 
| @@ -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'); | 
| @@ -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 | |
| @@ -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) ? "/>" : ">"; | 
| @@ -43,8 +43,9 @@ | ||
| 43 | 43 |        if ($this->escape) { | 
| 44 | 44 | $parse = new H\Text($s, $strtype); | 
| 45 | 45 | $this->content[] = $parse->toHTML(); | 
| 46 | - } else | |
| 47 | - $this->content[] = $s; | |
| 46 | +      } else { | |
| 47 | + $this->content[] = $s; | |
| 48 | + } | |
| 48 | 49 | } | 
| 49 | 50 | } | 
| 50 | 51 | |
| @@ -61,7 +61,7 @@ discard block | ||
| 61 | 61 | foreach ($labelTags as $tag) | 
| 62 | 62 | if ($tag instanceOf Html) | 
| 63 | 63 |          foreach ($tag->source as $source) { | 
| 64 | - if(isset($fields[$source])) | |
| 64 | + if (isset($fields[$source])) | |
| 65 | 65 | $fields[$source]->getLabelAttStatic($tag->opt, $tag->type, $tag->content); | 
| 66 | 66 | else | 
| 67 | 67 | $tag->opt['style'] = "display:none;"; | 
| @@ -70,7 +70,7 @@ discard block | ||
| 70 | 70 | foreach ($inputTags as $tag) | 
| 71 | 71 | if ($tag instanceOf Html) | 
| 72 | 72 |          foreach ($tag->source as $source) { | 
| 73 | - if(isset($fields[$source])) | |
| 73 | + if (isset($fields[$source])) | |
| 74 | 74 | $fields[$source]->getHintAttStatic($tag->opt, $tag->type, $tag->content); | 
| 75 | 75 | else | 
| 76 | 76 | $tag->opt['style'] = "display:none;"; | 
| @@ -79,7 +79,7 @@ discard block | ||
| 79 | 79 | foreach ($inputTags as $tag) | 
| 80 | 80 | if ($tag instanceOf Html) | 
| 81 | 81 |          foreach ($tag->source as $source) { | 
| 82 | -          if(isset($fields[$source])) { | |
| 82 | +          if (isset($fields[$source])) { | |
| 83 | 83 | $fields[$source]->getInputAttStatic($tag->opt, $tag->type, $tag->content); | 
| 84 | 84 | unset($fields[$source]); | 
| 85 | 85 | } else | 
| @@ -87,10 +87,10 @@ discard block | ||
| 87 | 87 | } | 
| 88 | 88 |      foreach ($fields as $n => $f) { | 
| 89 | 89 |        if (!$f instanceOf Button) { | 
| 90 | -        $this->addChild($label = new DynHtml("label", [],[],"",$n)); | |
| 90 | +        $this->addChild($label = new DynHtml("label", [], [], "", $n)); | |
| 91 | 91 | $f->getLabelAttStatic($label->opt, $label->type, $label->content); | 
| 92 | 92 | } | 
| 93 | -      $this->addChild($input = new DynHtml("input", [],[],"",$n)); | |
| 93 | +      $this->addChild($input = new DynHtml("input", [], [], "", $n)); | |
| 94 | 94 | $f->getInputAttStatic($input->opt, $input->type, $input->content); | 
| 95 | 95 | } | 
| 96 | 96 |      return "<form " . implode(" ", $out) . "><?php \$form = " . $this->var->toPHP() . "; \$form->process(); ?>"; | 
| @@ -41,12 +41,15 @@ discard block | ||
| 41 | 41 |    function __construct($param) { | 
| 42 | 42 | parent::__construct(); | 
| 43 | 43 |      $param = explode(' ', $param); | 
| 44 | -    if (count($param) < 2) throw new ParseError("|form requires 2 arguments, form type, and instance"); | |
| 44 | +    if (count($param) < 2) { | |
| 45 | +      throw new ParseError("|form requires 2 arguments, form type, and instance"); | |
| 46 | + } | |
| 45 | 47 | $this->var = new H\Text($param[1]); | 
| 46 | -    if (preg_match('/^(.*)\((.*)\)/', $param[0], $m)) | |
| 47 | - $this->form = new $m[1]($m[2]); | |
| 48 | - else | |
| 49 | - $this->form = new $param[0]; | |
| 48 | +    if (preg_match('/^(.*)\((.*)\)/', $param[0], $m)) { | |
| 49 | + $this->form = new $m[1]($m[2]); | |
| 50 | +    } else { | |
| 51 | + $this->form = new $param[0]; | |
| 52 | + } | |
| 50 | 53 | } | 
| 51 | 54 | |
| 52 | 55 |    function renderStTag() { | 
| @@ -58,32 +61,38 @@ discard block | ||
| 58 | 61 | } | 
| 59 | 62 | $fields = $this->form->getFields(); | 
| 60 | 63 |      $labelTags = $this->find(array(array("type" => "label"))); | 
| 61 | - foreach ($labelTags as $tag) | |
| 62 | - if ($tag instanceOf Html) | |
| 64 | +    foreach ($labelTags as $tag) { | |
| 65 | + if ($tag instanceOf Html) | |
| 63 | 66 |          foreach ($tag->source as $source) { | 
| 64 | 67 | if(isset($fields[$source])) | 
| 65 | 68 | $fields[$source]->getLabelAttStatic($tag->opt, $tag->type, $tag->content); | 
| 66 | - else | |
| 67 | - $tag->opt['style'] = "display:none;"; | |
| 69 | + } | |
| 70 | +          else { | |
| 71 | + $tag->opt['style'] = "display:none;"; | |
| 72 | + } | |
| 68 | 73 | } | 
| 69 | 74 |      $inputTags = $this->find(array(array("type" => "hint"))); | 
| 70 | - foreach ($inputTags as $tag) | |
| 71 | - if ($tag instanceOf Html) | |
| 75 | +    foreach ($inputTags as $tag) { | |
| 76 | + if ($tag instanceOf Html) | |
| 72 | 77 |          foreach ($tag->source as $source) { | 
| 73 | 78 | if(isset($fields[$source])) | 
| 74 | 79 | $fields[$source]->getHintAttStatic($tag->opt, $tag->type, $tag->content); | 
| 75 | - else | |
| 76 | - $tag->opt['style'] = "display:none;"; | |
| 80 | + } | |
| 81 | +          else { | |
| 82 | + $tag->opt['style'] = "display:none;"; | |
| 83 | + } | |
| 77 | 84 | } | 
| 78 | 85 |      $inputTags = $this->find(array(array("type" => "input"))); | 
| 79 | - foreach ($inputTags as $tag) | |
| 80 | - if ($tag instanceOf Html) | |
| 86 | +    foreach ($inputTags as $tag) { | |
| 87 | + if ($tag instanceOf Html) | |
| 81 | 88 |          foreach ($tag->source as $source) { | 
| 82 | 89 |            if(isset($fields[$source])) { | 
| 83 | 90 | $fields[$source]->getInputAttStatic($tag->opt, $tag->type, $tag->content); | 
| 91 | + } | |
| 84 | 92 | unset($fields[$source]); | 
| 85 | - } else | |
| 86 | - $tag->opt['style'] = "display:none;"; | |
| 93 | +          } else { | |
| 94 | + $tag->opt['style'] = "display:none;"; | |
| 95 | + } | |
| 87 | 96 | } | 
| 88 | 97 |      foreach ($fields as $n => $f) { | 
| 89 | 98 |        if (!$f instanceOf Button) { | 
| @@ -31,8 +31,9 @@ discard block | ||
| 31 | 31 | protected $commentstyle; | 
| 32 | 32 | |
| 33 | 33 |    function __construct($type) { | 
| 34 | - if ($type == "/") | |
| 35 | - $this->commentstyle = "HTML"; | |
| 34 | +    if ($type == "/") { | |
| 35 | + $this->commentstyle = "HTML"; | |
| 36 | + } | |
| 36 | 37 | } | 
| 37 | 38 | |
| 38 | 39 |    function renderStTag() { | 
| @@ -40,11 +41,12 @@ discard block | ||
| 40 | 41 | } | 
| 41 | 42 | |
| 42 | 43 |    function renderContent($pad = "", $oneliner = false) { | 
| 43 | - if ($this->commentstyle == "HTML") | |
| 44 | - if (count($this->content) > 1) | |
| 44 | +    if ($this->commentstyle == "HTML") { | |
| 45 | + if (count($this->content) > 1) | |
| 45 | 46 |          return $pad . "  " . implode("\n$pad", $this->content) . "\n"; | 
| 46 | - else | |
| 47 | - return current($this->content); | |
| 47 | +    } else { | |
| 48 | + return current($this->content); | |
| 49 | + } | |
| 48 | 50 | return ""; | 
| 49 | 51 | } | 
| 50 | 52 | |