예제 #1
0
    public function start_control($compiler, $node)
    {
        echo "<?";
        ?>
		if(!($_formControlModel->modelCache->hasField('<?php 
        echo $node->getAttribute("name");
        ?>
'))) {
			echo '<div class="mvcControlWarning" style="color: red">Warning, model ' . $_formControlModel->modelName . ' has no member ' .
					'named <?php 
        echo $node->getAttribute("name");
        ?>
</div>';
		}
		<?php 
        echo "?>";
        $labelNodes = $node->getElementsByTagNameNS("http://simplemvc.org/ns/2010", "label");
        $labels = array();
        for ($i = 0; $i < $labelNodes->length; $i++) {
            $label = $labelNodes->item($i);
            $labels[$label->getAttribute("for")] = ViewCompiler::collect($label);
        }
        ?>
		<div class="mvcInput" id="inputFld<?php 
        echo $node->getAttribute("name");
        ?>
">
		 <label for="<?php 
        echo $node->getAttribute("name");
        ?>
"><?php 
        echo $labels["password"];
        ?>
</label>
		 <input type="password" name="<?php 
        echo $node->getAttribute("name");
        ?>
"
	 			/>
	    </div>
		<div class="mvcInput" id="inputFld<?php 
        echo $node->getAttribute("name");
        ?>
_verify">
		 <label for="<?php 
        echo $node->getAttribute("name");
        ?>
"><?php 
        echo $labels["password_verify"];
        ?>
</label>
		 <input type="password" name="<?php 
        echo $node->getAttribute("name");
        ?>
_verify"
	 			/>
	    </div>	    
		<?php 
        return false;
    }
예제 #2
0
    public function start_control($compiler, $node)
    {
        echo "<?";
        ?>
		if(!($_formControlModel->modelCache->hasField('<?php 
        echo $node->getAttribute("name");
        ?>
'))) {
			echo '<div class="mvcControlWarning" style="color: red">Warning, model ' . $_formControlModel->modelName . ' has no member ' .
					'named <?php 
        echo $node->getAttribute("name");
        ?>
</div>';
		}
		<?php 
        echo "?>";
        /*
         * If the node has children, then we assume that a label is also defined in the tag and we create the div and all. 
         * If not, we create just the input -elemnt
         */
        if ($node->hasChildNodes()) {
            echo $this->html->element("div", $this->html->element("label", ViewCompiler::collect($node), array("for" => $node->getAttribute("name"))) . $this->generateErrorCode($node->getAttribute("name")) . $this->html->element("input", null, ViewCompiler::attributesAsArray($node->attributes)), array("class" => "mvcInput", "id" => "inputFld" . $node->getAttribute("name")));
        } else {
            echo $this->html->element("input", null, ViewCompiler::attributesAsArray($node->attributes));
        }
        return false;
    }
예제 #3
0
    public function start_control($compiler, $node)
    {
        echo "<?\n";
        ?>
		$_formControlModel = Model::getModel('<?php 
        echo $node->getAttribute("model");
        ?>
');
		if(!isset($MVC_CURRENT_MODEL)) {
			$MVC_CURRENT_MODEL = $_formControlModel;
		}
		<?php 
        echo "\n?>";
        $parameters = ViewCompiler::attributesAsArray($node->attributes);
        /*
         * See if we need to automatically create a controller for this save action
         */
        if ($node->getAttribute("autocreate-controller") == "true") {
            $target = ControllerGenerator::generateSaveController($compiler->controller, $compiler->method, $node->getAttribute("model"), $node->getAttribute("redirect"));
            $parameters["method"] = "post";
            $parameters["action"] = $target;
        }
        unset($parameters["model"]);
        unset($parameters["redirect"]);
        unset($parameters["autocreate-controller"]);
        echo $this->html->startElement("form", $parameters);
        return true;
    }
예제 #4
0
파일: view.php 프로젝트: almaopen/SwissMVC
 public function render($vars, $controller, $function)
 {
     $this->controller = $controller;
     $this->html = new HtmlHelper(MVCContext::getContext()->getController());
     extract($vars);
     ob_start();
     include ViewCompiler::getView($this->path, $controller, $function, $this->html);
     $contents = ob_get_contents();
     ob_end_clean();
     $this->contents = $contents;
 }
예제 #5
0
 public static function generateBasicController($controller, $action, $code)
 {
     $controllerHash = md5($controller . "/" . $action);
     if (!isset(ControllerGenerator::$generatedControllers[$controllerHash])) {
         ControllerGenerator::$generatedControllers[$controllerHash] = 0;
     }
     ControllerGenerator::$generatedControllers[$controllerHash]++;
     $controllerFile = WEBAPP_ROOT . "/tmp/controllers/Temp{$controllerHash}_" . ControllerGenerator::$generatedControllers[$controllerHash] . ".php";
     $skeleton = file_get_contents(dirname(__FILE__) . "/controller-skeletons/basic-skeleton.phps");
     // Fill in the blanks
     $data = array("{name}" => "Temp{$controllerHash}_" . ControllerGenerator::$generatedControllers[$controllerHash], "{method}" => "func", "{code}" => ViewCompiler::cleanFileAfterCompilation($code));
     $controllerCode = str_replace(array_keys($data), array_values($data), $skeleton);
     file_put_contents($controllerFile, $controllerCode);
     ControllerGenerator::addRoute("/{$controllerHash}_" . ControllerGenerator::$generatedControllers[$controllerHash] . "/func", $controllerFile, "Temp{$controllerHash}_" . ControllerGenerator::$generatedControllers[$controllerHash] . "Controller");
     if (property_exists("AppConfiguration", "APP_PATH")) {
         $path_prefix = AppConfiguration::$APP_PATH;
     } else {
         $path_prefix = "";
     }
     return "{$path_prefix}/{$controllerHash}_" . ControllerGenerator::$generatedControllers[$controllerHash] . "/func";
 }
예제 #6
0
    public function start_control($compiler, $node)
    {
        /* Generate the controller based on the code */
        $code = ViewCompiler::collect($node);
        $path = ControllerGenerator::generateBasicController($compiler->controller, $compiler->method, $code);
        // If we don't have a parent, we create a hidden DIV that we can use to find our parent
        // and attach result to the parent of that div
        $divName = "mvcHiddenDiv" . time() . rand(100, 999);
        if (!$node->hasAttribute("target")) {
            ?>
			<div id="<?php 
            echo $divName;
            ?>
" style="display: none"></div>
			<?php 
        }
        /* 
         * Create JavaScript -functions to invoke this Ajax-script. If we have execute-on -defined, we automatically
         * create a <script>-wrapper and a function, if not, we assume the tag's inside a <script>-tag
         */
        if ($node->hasAttribute("execute-on")) {
            ob_start();
        }
        ?>
		$.post('<?php 
        echo $path;
        ?>
', 
			{
				<?php 
        /*
         * See which JS -variables to export to the PHP -script. If the code automatically generates
         * a function, then we export any parameters, if it's embedded in JS -code, we can
         * define the exported variables with the "export" parameter. Both expect a comma-separated
         * list
         */
        $exportVariables = $node->hasAttribute("parameters") ? explode(", ", $node->getAttribute("parameters")) : ($node->hasAttribute("export") ? explode(",", $node->getAttribute("export")) : array());
        if (!empty($exportVariables)) {
            foreach ($exportVariables as &$param) {
                $param = "'{$param}': {$param}";
            }
            echo join($exportVariables, ",");
        }
        ?>
			}, function(data) {
			<?php 
        if ($node->hasAttribute("target")) {
            ?>
				$('<?php 
            echo $node->getAttribute("target");
            ?>
').append(data);
			<?php 
        } else {
            ?>
			 	$('#<?php 
            echo $divName;
            ?>
').parent().append(data)
			 	$('#<?php 
            echo $divName;
            ?>
').remove();
			<?php 
        }
        ?>
		});
		<?php 
        /*
         * If we define the "execute-on" -parameter, then we create a function automatically.
         * 
         * TODO: Would be nice if this could be automatically bound to events, e.g:
         * 
         * execute-on="$('#foo').blur"
         */
        if ($node->hasAttribute("execute-on")) {
            $script = ob_get_contents();
            ob_end_clean();
            ?>
			<script language="JavaScript" type="text/javascript">
			<!--
			function <?php 
            echo $node->getAttribute("execute-on");
            ?>
(<?php 
            echo $node->getAttribute("parameters");
            ?>
) {
				<?php 
            echo $script;
            ?>
				
			}
			//-->
			</script>
			<?php 
        }
        return false;
    }
예제 #7
0
 /**
  * Generates a HTML-fragment from the children of the node.
  */
 public static function collect($elem)
 {
     $string = "";
     foreach ($elem->childNodes as $node) {
         if ($node->nodeType == XML_ELEMENT_NODE) {
             // Create normal HTML -element
             $elemBase = "<%s" . ($node->hasAttributes() ? " %s" : "") . ($node->hasChildNodes() ? ">" : "/>");
             $attributes = array();
             foreach ($node->attributes as $attribute) {
                 $attributes[] = $attribute->name . "=\"" . $attribute->value . "\"";
             }
             if ($node->hasChildNodes()) {
                 $string .= sprintf($elemBase, $node->tagName, join($attributes, " "));
                 $string .= ViewCompiler::collect($node);
                 $string .= "</" . $node->tagName . ">";
             } else {
                 $string .= sprintf($elemBase, $node->tagName, join($attributes, " "));
             }
         } else {
             $string .= (string) $node->nodeValue;
         }
     }
     return $string;
 }