mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-22 10:52:09 +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>
|
||||
*/
|
||||
|
||||
ini_set('display_errors', 'On');
|
||||
|
||||
class tag {
|
||||
|
||||
private $DOM;
|
||||
@ -60,13 +63,84 @@ class bold extends tag {
|
||||
|
||||
class article extends tag {
|
||||
public function render() {
|
||||
|
||||
$post = array( //testing purpose
|
||||
'title'=> "test",
|
||||
'url'=> "pokemon",
|
||||
'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
|
||||
);
|
||||
|
||||
|
||||
|
||||
$pok = $this->getDOM();
|
||||
$attr = $pok->getAttribute("column");
|
||||
|
||||
$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
|
||||
$content = file_get_contents("./test.html");
|
||||
|
||||
@ -76,22 +150,22 @@ function loadTags($ctnt) {
|
||||
$dom->loadHTML($ctnt);
|
||||
libxml_clear_errors();
|
||||
$list = $dom->getElementsByTagName("tag");
|
||||
var_dump($list);
|
||||
|
||||
|
||||
//list compoenents and load content
|
||||
foreach($list as $lst) {
|
||||
for ($i=0; $i < $list->count(); $i++) {
|
||||
$lst = $list->item($i);
|
||||
$tgs = $lst->getAttribute("type");
|
||||
//echo $tgs;
|
||||
echo $tgs;
|
||||
$tg = new $tgs($dom, $lst);
|
||||
//add to parent the result
|
||||
$lst->parentNode->appendChild($tg->render());
|
||||
$lst->parentNode->appendChild($tg->render());
|
||||
}
|
||||
|
||||
|
||||
//remove all tag components
|
||||
while($list->length >= 1) {
|
||||
/*while($list->length >= 1) {
|
||||
$list[0]->parentNode->removeChild($list[0]);
|
||||
}
|
||||
}*/
|
||||
$res = $dom->saveHTML();
|
||||
echo $res;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user