Example #1
0
 function button($content, $data, $attributes)
 {
     if (array_key_exists("type", $attributes)) {
         $type = $attributes["type"];
     } else {
         if (array_key_exists("to", $attributes)) {
             $type = "to";
             $to = TemplateLogic::content($attributes["to"], $data);
         } else {
             $type = "submit";
         }
     }
     $result = "";
     $name = TemplateLogic::content($attributes["name"], $data);
     $options = Options::parse($attributes["options"]);
     if (array_key_exists("action", $attributes)) {
         $options["action"] = $attributes["action"];
     }
     switch (strToLower($type)) {
         case "back":
             $result = buttonBack($name, $options);
             break;
         case "action":
             $result = buttonAction($name, $options);
             break;
         case "to":
             $result = buttonTo($name, $to, $options);
             break;
         case "reset":
             $result = buttonReset($name);
             break;
         case "submit":
         default:
             $result = submit_tag($name, $options);
             break;
     }
     return $result;
 }
Example #2
0
 function process($source)
 {
     $tagsPattern = '/\\<(?:(?i)mate):([^\\s]*?)(?(?=[\\s])(.*?))(?(?=[\\/])\\/>|\\>(.*?)\\<\\/(?:(?i)mate:\\1)\\>)/s';
     //$contentPattern = '/\{(.*?)\}/';
     preg_match_all($tagsPattern, $source, $matches);
     $tags = array();
     $contents = array();
     for ($m = 0; $m < count($matches[0]); $m++) {
         $attributes["tagid"] = "";
         $tag = $matches[0][$m];
         $attributesString = $matches[2][$m];
         $content = $matches[3][$m];
         $tags[] = $tag;
         $attributes = TemplateLogic::getAttributes($attributesString);
         $tagName = strToLower($matches[1][$m]);
         if (substr($tagName, 0, 4) == "loop") {
             $attributes["tagid"] = substr($tagName, 4);
             $tagName = "loop";
         }
         if (substr($tagName, 0, 2) == "if") {
             $attributes["tagid"] = substr($tagName, 2);
             $tagName = "if";
         }
         if (array_key_exists("options", $attributes) === FALSE) {
             $attributes["options"] = "";
         }
         switch ($tagName) {
             case "comment":
                 break;
             case "view":
             case "loop":
             case "literal":
             case "ulist":
             case "combo":
             case "form":
             case "table":
                 $contents[] = $this->{$tagName}($content, $attributes);
                 break;
             case "if":
                 $contents[] = $this->condition($content, $attributes);
                 break;
             default:
                 $contents[] = TemplateLogic::render($tagName, $this->data, $content, $attributes);
                 break;
         }
     }
     $resultFromLogic = str_replace($tags, $contents, $source);
     if ($tagName == "literal") {
         return $resultFromLogic;
     } else {
         return TemplateLogic::content($resultFromLogic, $this->data);
     }
 }