mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-22 10:52:09 +00:00
TAG MANAGER FINIS ! BOOM
(je met une doc plus tard)
This commit is contained in:
parent
cceeaeff71
commit
e8d5bbc99c
@ -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 <tag type="bold">test</tag>
|
||||
|
||||
$post = array(
|
||||
'title'=> "test",
|
||||
'url'=> "pokemon",
|
||||
'content'=> "<p>pouet</p>"
|
||||
);
|
||||
|
||||
$posts = array(
|
||||
$post,
|
||||
$post,
|
||||
$post,
|
||||
$post,
|
||||
);
|
||||
|
||||
//result <span style="font-weight: bold">test</span>
|
||||
class bold extends tag {
|
||||
public function render() {
|
||||
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
|
||||
@ -49,7 +45,7 @@ class bold extends tag {
|
||||
//recuperation du document (necessaire a la création de balises
|
||||
$doc = $this->getDoc();
|
||||
//creation de la balise "div"
|
||||
$res = $doc->createElement("div");
|
||||
$res = $doc->createElement("span");
|
||||
//creation du texte et assignation du texte se trouvant dans la balise de base
|
||||
$text = $doc->createTextNode($pok->textContent);
|
||||
//on rajoute a notre balise div notre texte
|
||||
@ -57,10 +53,14 @@ class bold extends tag {
|
||||
//on rajoute a la balise div du style pour le mettre en gras
|
||||
$res->setAttribute("style", "font-weight: bold");
|
||||
//on retourne la div
|
||||
return $res;
|
||||
|
||||
//enfin on met la div final dans le fichier
|
||||
$pok->parentNode->insertBefore($res, $pok);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//inputs <tag type="article" column="(voir les collones de la table post)
|
||||
//return #text
|
||||
class article extends tag {
|
||||
public function render() {
|
||||
|
||||
@ -85,38 +85,139 @@ class article extends tag {
|
||||
appendHTML($pok->parentNode, $post[$attr]);
|
||||
} else {
|
||||
$txt = $doc->createTextNode($post[$attr]);
|
||||
$pok->parentNode->appendChild($txt);
|
||||
$pok->parentNode->insertBefore($txt, $pok);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $pok;
|
||||
}
|
||||
}
|
||||
|
||||
class loosp extends tag {
|
||||
class isLoggedIn extends tag {
|
||||
public function render() {
|
||||
|
||||
$el = $this->getDOM();
|
||||
|
||||
//debugging purpose
|
||||
$loggedin = false;
|
||||
|
||||
foreach ($el->getElementsByTagName("if") as $element) {
|
||||
if($element->hasAttribute("true") && $loggedin){
|
||||
$r = $element->childNodes->item(1);
|
||||
$el->parentNode->insertBefore($r, $el);
|
||||
} elseif ($element->hasAttribute("false")) {
|
||||
$r = $element->childNodes->item(1);
|
||||
$el->parentNode->insertBefore($r, $el);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class author extends tag {
|
||||
public function render() {
|
||||
|
||||
$post = array( //testing purpose
|
||||
'name'=> "test",
|
||||
'image'=> "pokemon",
|
||||
'linkedin'=> "pouet"
|
||||
);
|
||||
|
||||
|
||||
|
||||
$pok = $this->getDOM();
|
||||
$attr = $pok->getAttribute("column");
|
||||
|
||||
$doc = $this->getDoc();
|
||||
|
||||
$txt = $doc->createTextNode($post[$attr]);
|
||||
|
||||
$pok->parentNode->insertBefore($txt, $pok);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* input <tag type="loop" for="(table)" limit="(nombre-max généré)">
|
||||
*/
|
||||
class loop extends tag {
|
||||
public function render() {
|
||||
$el = $this->getDOM();
|
||||
|
||||
$doc = $this->getDoc();
|
||||
|
||||
$limit = (int) $el->getAttribute("limite");
|
||||
$limit = (int) $el->getAttribute("limit");
|
||||
|
||||
//testing purpose variable
|
||||
$posts = array(
|
||||
array(
|
||||
'title'=> "a",
|
||||
'url'=> "e",
|
||||
'content'=> "<p>i</p>",
|
||||
'date'=> "2018-09-20"
|
||||
),
|
||||
array(
|
||||
'title'=> "b",
|
||||
'url'=> "f",
|
||||
'content'=> "<p>j</p>",
|
||||
'date'=> "2018-09-21"
|
||||
),
|
||||
array(
|
||||
'title'=> "c",
|
||||
'url'=> "g",
|
||||
'content'=> "<p>k</p>",
|
||||
'date'=> "2018-09-22"
|
||||
),
|
||||
array(
|
||||
'title'=> "d",
|
||||
'url'=> "h",
|
||||
'content'=> "<p>l</p>",
|
||||
'date'=> "2018-09-23"
|
||||
),
|
||||
array(
|
||||
'title'=> "z",
|
||||
'url'=> "z",
|
||||
'content'=> "<p>z</p>",
|
||||
'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);
|
||||
?>
|
||||
loadTags($content, $debug);
|
||||
|
Loading…
x
Reference in New Issue
Block a user