mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-06-08 00:09:55 +00:00
TagHandler WIP
This commit is contained in:
parent
91076e1426
commit
cceeaeff71
@ -2,6 +2,9 @@
|
|||||||
/**
|
/**
|
||||||
* <tag type="pokemon" arg="pokemongo"><div class="pokemon-item"></div></tag>
|
* <tag type="pokemon" arg="pokemongo"><div class="pokemon-item"></div></tag>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ini_set('display_errors', 'On');
|
||||||
|
|
||||||
class tag {
|
class tag {
|
||||||
|
|
||||||
private $DOM;
|
private $DOM;
|
||||||
@ -60,13 +63,84 @@ class bold extends tag {
|
|||||||
|
|
||||||
class article extends tag {
|
class article extends tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
|
|
||||||
|
$post = array( //testing purpose
|
||||||
|
'title'=> "test",
|
||||||
|
'url'=> "pokemon",
|
||||||
|
'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$pok = $this->getDOM();
|
$pok = $this->getDOM();
|
||||||
|
$attr = $pok->getAttribute("column");
|
||||||
|
|
||||||
$doc = $this->getDoc();
|
$doc = $this->getDoc();
|
||||||
|
|
||||||
|
$parent = $pok->parentNode;
|
||||||
|
|
||||||
|
|
||||||
var_dump($pok->getElementsByTagName("test"));
|
|
||||||
|
if($attr == "content") {
|
||||||
|
appendHTML($pok->parentNode, $post[$attr]);
|
||||||
|
} else {
|
||||||
|
$txt = $doc->createTextNode($post[$attr]);
|
||||||
|
$pok->parentNode->appendChild($txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return $pok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class loosp extends tag {
|
||||||
|
public function render() {
|
||||||
|
$el = $this->getDOM();
|
||||||
|
|
||||||
|
$doc = $this->getDoc();
|
||||||
|
|
||||||
|
$limit = (int) $el->getAttribute("limite");
|
||||||
|
|
||||||
|
$parent = $el->parentNode;
|
||||||
|
var_dump($limit);
|
||||||
|
for ($i=0; $i < $limit; $i++) {
|
||||||
|
var_dump($el);
|
||||||
|
$parent->appendChild($el);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $el;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendHTML (DOMNode $parent, $source) {
|
||||||
|
$tmpDoc = new DOMDocument();
|
||||||
|
$tmpDoc->loadHTML ($source);
|
||||||
|
foreach ($tmpDoc->getElementsByTagName ('body')->item (0)->childNodes as $node) {
|
||||||
|
$importedNode = $parent->ownerDocument->importNode ($node, true);
|
||||||
|
$parent->parentNode->replaceChild ($importedNode, $parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renameTag( DOMElement $oldTag, $newTagName ) {
|
||||||
|
$oldTag = $oldTag->parentNode->appendChild($oldTag);
|
||||||
|
$document = $oldTag->ownerDocument;
|
||||||
|
|
||||||
|
$newTag = $document->createElement($newTagName);
|
||||||
|
$oldTag->parentNode->replaceChild($newTag, $oldTag);
|
||||||
|
|
||||||
|
foreach ($oldTag->attributes as $attribute) {
|
||||||
|
$newTag->setAttribute($attribute->name, $attribute->value);
|
||||||
|
}
|
||||||
|
foreach (iterator_to_array($oldTag->childNodes) as $child) {
|
||||||
|
$newTag->appendChild($oldTag->removeChild($child));
|
||||||
|
}
|
||||||
|
return $newTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//testing purpose
|
//testing purpose
|
||||||
$content = file_get_contents("./test.html");
|
$content = file_get_contents("./test.html");
|
||||||
|
|
||||||
@ -76,22 +150,22 @@ function loadTags($ctnt) {
|
|||||||
$dom->loadHTML($ctnt);
|
$dom->loadHTML($ctnt);
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
$list = $dom->getElementsByTagName("tag");
|
$list = $dom->getElementsByTagName("tag");
|
||||||
|
var_dump($list);
|
||||||
|
|
||||||
|
for ($i=0; $i < $list->count(); $i++) {
|
||||||
//list compoenents and load content
|
$lst = $list->item($i);
|
||||||
foreach($list as $lst) {
|
|
||||||
$tgs = $lst->getAttribute("type");
|
$tgs = $lst->getAttribute("type");
|
||||||
//echo $tgs;
|
echo $tgs;
|
||||||
$tg = new $tgs($dom, $lst);
|
$tg = new $tgs($dom, $lst);
|
||||||
//add to parent the result
|
//add to parent the result
|
||||||
$lst->parentNode->appendChild($tg->render());
|
$lst->parentNode->appendChild($tg->render());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//remove all tag components
|
//remove all tag components
|
||||||
while($list->length >= 1) {
|
/*while($list->length >= 1) {
|
||||||
$list[0]->parentNode->removeChild($list[0]);
|
$list[0]->parentNode->removeChild($list[0]);
|
||||||
}
|
}*/
|
||||||
$res = $dom->saveHTML();
|
$res = $dom->saveHTML();
|
||||||
echo $res;
|
echo $res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user