Imagine that you could use the great mootools syntax inside PHP. Doesn’t it sound great?
mooHP is PHP framework who’s syntax is based on the mootools javascript framework. I’m using mootools since release 0.86 and I am very happy with it. I thought that it would be great to have some server side compatible language so I can alter the DOM of the page on the server-side. The first attempt to make this thing was with Classic ASP because ASP can be written with JScript and this framework would be exactly like mootools, but it went unsuccessfully because of the poor DOM class that ASP has. So this is the second attempt and it’s only a draft version and any of the code is written just to test the possibilities of the PHP and I think this time it’s successful. For now it works only on PHP 5.2.1 and above.
The code behind the demo:
<?php include("mooHP2/dom.class.php"); include("mooHP2/element.class.php"); include("mooHP2/css.class.php"); include("mooHP2/utility.class.php"); //New instance of the dom class $t = new dom(); //Loads a template from file $t->loadFile("base.html"); //Gets element by css selector and sets it's HTML content. $t->SE("body")->setHTML(""); //Selected ellement: body adopts new element $t->SE("body")->adopt( $t->element("div", array("id"=>"header") ,"Hello world!") ); //Body adopts <br /> $t->SE("body")->newLine(); $picked = ""; if (isset( $_GET["cd"] )) { $picked = " you have selected #".$_GET["cd"]; } //Body adopts new element div: with assigned properties as second argument and text as content; $t->SE("body")->adopt( $t->element("div", array("style"=>"margin:10px; padding:10px; border:1px solid #444;"), "Counting down:".$picked) ); // $select = new Element() $select = $t->element("select", array("name"=>"cd"), ""); //Body adopts new element of type form $t->SE("body")->adopt( $t->element("form", array("id"=>"newForm","method"=>"get") ) ); //Selects new element by ID and adopts previously defined element $select $t->S("newForm")->adopt( $select ); // #newForm adopts new Element input $t->S("newForm")->adopt( $t->element("input", array("type"=>"submit", "value"=>"CLICK!") ) ); for ($i=1; $i<=20; $i++) { //$newOption is new option element $newOption = $t->element("option", array("value"=>$i), "Count down: " . $i ); //$select adopt as it's first child the $newOption element $select->adoptTop( $newOption ); if ( isset($_GET["cd"]) && $_GET["cd"] == $i ) { //Setting an attribute to an element $newOption->setProperty("selected","selected"); } } //Body accepts new style rules $t->SE("body")->setStyle("margin","10px"); //Body adopts <br/> $t->SE("body")->newLine(); //Appending text to the body $t->SE("body")->appendText("and here comes the appended text"); //Body is adopting the inc.html contents $t->SE("body")->adopt( $t->includeFile("inc.html") ); if (!isset( $_GET["cd"] )) { //Make simple alert with javascript $t->alert("Hello and welcome to mooHP"); } //Setting the <title> tah innerHTML $t->setPageTitle("..:: Hello and welcome to mooHP ::.."); //Creating new instance of the css class $newCss = new css(); //Setting rule in css $newCss->setStyle("color","#ff9900"); //Setting rules in css $newCss->setStyles(array("font-weight"=>"bold","font-size"=>"24px" )); //Writing the defined css to element $newCss->writeToElement( $t->S("header") ); //Creating new instance of the css class $newCss2 = new css(); //Setting rule in css $newCss2->setStyle("border","10px solid #DDD"); //Setting rule in css $newCss2->setStyle("padding","10px"); //Writing the defined css as #newForm selector in $t dom instance $newCss2->writeToDom("#newForm", $t); //Writing the page if true is passed as argument the page will be compresed $t->writePage(true); ?>
















