From e8d5bbc99c2147f214c49a96caa33d3bfcc55be3 Mon Sep 17 00:00:00 2001
From: Avior <2bazert@gmail.com>
Date: Tue, 20 Nov 2018 16:48:41 +0100
Subject: [PATCH] TAG MANAGER FINIS ! BOOM (je met une doc plus tard)
---
project/assets/php/tagHandler.php | 180 +++++++++++++++++++++++-------
1 file changed, 140 insertions(+), 40 deletions(-)
diff --git a/project/assets/php/tagHandler.php b/project/assets/php/tagHandler.php
index 515a695..87203c0 100644
--- a/project/assets/php/tagHandler.php
+++ b/project/assets/php/tagHandler.php
@@ -5,15 +5,19 @@
ini_set('display_errors', 'On');
+$debug = false;
+
+
class tag {
private $DOM;
private $doc;
+ private $debug;
- public function __construct(DOMDocument $doc, DOMElement $DOMContent) {
+ public function __construct(DOMDocument $doc, DOMElement $DOMContent, bool $debug) {
$this->doc = $doc;
$this->DOM = $DOMContent;
-
+ $this->debug = $debug;
}
public function getDoc() {
@@ -24,24 +28,16 @@ class tag {
return $this->DOM;
}
- public function render() {
- return $this->DOM;
+ public function isDebugging() {
+ return $this->debug;
}
+
+ public function render() {}
}
+//ce tag est juste la pour donner les possibilité de mon composant
+//input
pouet
" -); - -$posts = array( - $post, - $post, - $post, - $post, -); - +//result test class bold extends tag { public function render() { //recuperation de la balise de base (i
", + 'date'=> "2018-09-20" + ), + array( + 'title'=> "b", + 'url'=> "f", + 'content'=> "j
", + 'date'=> "2018-09-21" + ), + array( + 'title'=> "c", + 'url'=> "g", + 'content'=> "k
", + 'date'=> "2018-09-22" + ), + array( + 'title'=> "d", + 'url'=> "h", + 'content'=> "l
", + 'date'=> "2018-09-23" + ), + array( + 'title'=> "z", + 'url'=> "z", + 'content'=> "z
", + 'date'=> "2018-10-23" + ), + ); + + //if($limit == 0) $limit = count($posts); $parent = $el->parentNode; - var_dump($limit); + //var_dump($parent); for ($i=0; $i < $limit; $i++) { - var_dump($el); - $parent->appendChild($el); + //var_dump($i); + $pok = $el->childNodes->item(1)->cloneNode(true); + $parent->insertBefore($pok, $el); + + $elements = $pok->getElementsByTagName("loop"); + + foreach ($elements as $ele) { + + if($ele->getAttribute("column") == "content") { + appendHTML($ele, $posts[$i][$ele->getAttribute("column")]); + } else { + $txt = $doc->createTextNode($posts[$i][$ele->getAttribute("column")]); + $ele->parentNode->insertBefore($txt, $ele); + } + } + } + + $loop = $parent->getElementsByTagName("loop"); + + while ($loop->length >= 1 && !$this->isDebugging()) { + $loop[0]->parentNode->removeChild($loop[0]); } - return $el; } } -function appendHTML (DOMNode $parent, $source) { +function appendHTML(DOMNode $parent, $source) { $tmpDoc = new DOMDocument(); $tmpDoc->loadHTML ($source); - foreach ($tmpDoc->getElementsByTagName ('body')->item (0)->childNodes as $node) { + foreach ($tmpDoc->getElementsByTagName('body')->item(0)->childNodes as $node) { $importedNode = $parent->ownerDocument->importNode ($node, true); $parent->parentNode->replaceChild ($importedNode, $parent); } @@ -144,31 +245,30 @@ function renameTag( DOMElement $oldTag, $newTagName ) { //testing purpose $content = file_get_contents("./test.html"); -function loadTags($ctnt) { + +function loadTags($ctnt, $debug) { $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($ctnt); libxml_clear_errors(); $list = $dom->getElementsByTagName("tag"); - var_dump($list); for ($i=0; $i < $list->count(); $i++) { $lst = $list->item($i); $tgs = $lst->getAttribute("type"); - echo $tgs; - $tg = new $tgs($dom, $lst); - //add to parent the result - $lst->parentNode->appendChild($tg->render()); + + $tg = new $tgs($dom, $lst, $debug); + + $tg->render(); } //remove all tag components - /*while($list->length >= 1) { + while($list->length >= 1 && !$debug) { $list[0]->parentNode->removeChild($list[0]); - }*/ + } $res = $dom->saveHTML(); echo $res; } -loadTags($content); -?> \ No newline at end of file +loadTags($content, $debug);