mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-06-08 00:09:55 +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');
|
ini_set('display_errors', 'On');
|
||||||
|
|
||||||
|
$debug = false;
|
||||||
|
|
||||||
|
|
||||||
class tag {
|
class tag {
|
||||||
|
|
||||||
private $DOM;
|
private $DOM;
|
||||||
private $doc;
|
private $doc;
|
||||||
|
private $debug;
|
||||||
|
|
||||||
public function __construct(DOMDocument $doc, DOMElement $DOMContent) {
|
public function __construct(DOMDocument $doc, DOMElement $DOMContent, bool $debug) {
|
||||||
$this->doc = $doc;
|
$this->doc = $doc;
|
||||||
$this->DOM = $DOMContent;
|
$this->DOM = $DOMContent;
|
||||||
|
$this->debug = $debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDoc() {
|
public function getDoc() {
|
||||||
@ -24,24 +28,16 @@ class tag {
|
|||||||
return $this->DOM;
|
return $this->DOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function isDebugging() {
|
||||||
return $this->DOM;
|
return $this->debug;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$post = array(
|
public function render() {}
|
||||||
'title'=> "test",
|
}
|
||||||
'url'=> "pokemon",
|
//ce tag est juste la pour donner les possibilité de mon composant
|
||||||
'content'=> "<p>pouet</p>"
|
//input <tag type="bold">test</tag>
|
||||||
);
|
|
||||||
|
|
||||||
$posts = array(
|
|
||||||
$post,
|
|
||||||
$post,
|
|
||||||
$post,
|
|
||||||
$post,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
//result <span style="font-weight: bold">test</span>
|
||||||
class bold extends tag {
|
class bold extends tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
|
//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
|
//recuperation du document (necessaire a la création de balises
|
||||||
$doc = $this->getDoc();
|
$doc = $this->getDoc();
|
||||||
//creation de la balise "div"
|
//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
|
//creation du texte et assignation du texte se trouvant dans la balise de base
|
||||||
$text = $doc->createTextNode($pok->textContent);
|
$text = $doc->createTextNode($pok->textContent);
|
||||||
//on rajoute a notre balise div notre texte
|
//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
|
//on rajoute a la balise div du style pour le mettre en gras
|
||||||
$res->setAttribute("style", "font-weight: bold");
|
$res->setAttribute("style", "font-weight: bold");
|
||||||
//on retourne la div
|
//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 {
|
class article extends tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
|
|
||||||
@ -85,31 +85,132 @@ class article extends tag {
|
|||||||
appendHTML($pok->parentNode, $post[$attr]);
|
appendHTML($pok->parentNode, $post[$attr]);
|
||||||
} else {
|
} else {
|
||||||
$txt = $doc->createTextNode($post[$attr]);
|
$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() {
|
public function render() {
|
||||||
$el = $this->getDOM();
|
$el = $this->getDOM();
|
||||||
|
|
||||||
$doc = $this->getDoc();
|
$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;
|
$parent = $el->parentNode;
|
||||||
var_dump($limit);
|
//var_dump($parent);
|
||||||
for ($i=0; $i < $limit; $i++) {
|
for ($i=0; $i < $limit; $i++) {
|
||||||
var_dump($el);
|
//var_dump($i);
|
||||||
$parent->appendChild($el);
|
$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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,31 +245,30 @@ function renameTag( DOMElement $oldTag, $newTagName ) {
|
|||||||
//testing purpose
|
//testing purpose
|
||||||
$content = file_get_contents("./test.html");
|
$content = file_get_contents("./test.html");
|
||||||
|
|
||||||
function loadTags($ctnt) {
|
|
||||||
|
function loadTags($ctnt, $debug) {
|
||||||
$dom = new DOMDocument();
|
$dom = new DOMDocument();
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
$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++) {
|
for ($i=0; $i < $list->count(); $i++) {
|
||||||
$lst = $list->item($i);
|
$lst = $list->item($i);
|
||||||
$tgs = $lst->getAttribute("type");
|
$tgs = $lst->getAttribute("type");
|
||||||
echo $tgs;
|
|
||||||
$tg = new $tgs($dom, $lst);
|
$tg = new $tgs($dom, $lst, $debug);
|
||||||
//add to parent the result
|
|
||||||
$lst->parentNode->appendChild($tg->render());
|
$tg->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//remove all tag components
|
//remove all tag components
|
||||||
/*while($list->length >= 1) {
|
while($list->length >= 1 && !$debug) {
|
||||||
$list[0]->parentNode->removeChild($list[0]);
|
$list[0]->parentNode->removeChild($list[0]);
|
||||||
}*/
|
}
|
||||||
$res = $dom->saveHTML();
|
$res = $dom->saveHTML();
|
||||||
echo $res;
|
echo $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadTags($content);
|
loadTags($content, $debug);
|
||||||
?>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user