-
+
@@ -51,7 +51,7 @@
-
+
Dans le même thème
-
-
Mettre en place un serveur web sous linux
-
- OPS
- 26-06-2018
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
Dum apud Persas, ut supra narravimus, perfidia regis motus agitat insperatos, - et in eois tractibus bella rediviva consurgunt, anno sexto decimo et eo diutius post Nepotiani exitium, saeviens - per urbem aeternam urebat cuncta Bellona, ex primordiis -
-
diff --git a/assets/php/Controller.php b/assets/php/Controller.php
new file mode 100644
index 0000000..2ff9422
--- /dev/null
+++ b/assets/php/Controller.php
@@ -0,0 +1,36 @@
+ $t) {
+ $loader->loadClass($key);
+ }
+ foreach (get_declared_classes() as $class) {
+ if(is_subclass_of( $class, 'App\Controller')) {
+ $r = new ReflectionClass($class);
+ foreach ($r->getMethods() as $method) {
+ preg_match_all('#@(.*?)\n#s', $method->getDocComment(), $annotations);
+ foreach ($annotations[1] as $annot) {
+ $arr = preg_split("/ /", $annot);
+ if($arr[0] === "route") {
+ if(preg_match($arr[1], $route)) {
+ $instance = new $class();
+ $function = ($method->getName());
+ return $instance->$function();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ }
+}
diff --git a/assets/php/Controller/HomeController.php b/assets/php/Controller/HomeController.php
new file mode 100644
index 0000000..0a0890e
--- /dev/null
+++ b/assets/php/Controller/HomeController.php
@@ -0,0 +1,28 @@
+
* return text
@@ -37,5 +39,11 @@ class Article extends Tag {
$txt = $doc->createTextNode($post->$col());
$pok->parentNode->insertBefore($txt, $pok);
}
+
+ $finder = new DomXPath($doc);
+ $nodes = $finder->query("//*[contains(@class, 'column-cat')]");
+
+ if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-cat", $post->getCategory()->getName() , $nodes[0]->getAttribute("class")));
+
}
}
diff --git a/assets/php/Tags/Loop.php b/assets/php/Tags/Loop.php
index 25a5521..a880086 100644
--- a/assets/php/Tags/Loop.php
+++ b/assets/php/Tags/Loop.php
@@ -21,9 +21,14 @@ class Loop extends Tag {
$doc = $this->getDoc();
$limit = (int) $el->getAttribute("limit");
+ $parent = $el->parentNode;
- if($el->getAttribute("category") !== null) {
- $posts = Post::listByCategory(Post::get($_GET["post"])->getCategory()->getId(), true, 6);
+ $isRecent = isset($_GET["recent"]) && $_GET["recent"] == "false" ? false : true;
+ $category = isset($_GET["category"]) && intval($_GET["category"]) ? (int) $_GET["category"] : -1;
+ $tag = isset($_GET["tag"]) && intval($_GET["tag"]) ? (int) $_GET["tag"] : -1;
+
+ if($el->getAttribute("category") != '') {
+ $posts = Post::listByCategory(Post::get($_GET["post"])->getCategory()->getId(), $isRecent, 6);
$postsList = array();
foreach ($posts as $post) {
if($post->getId() != $_GET["post"]) $postsList[] = $post;
@@ -34,9 +39,22 @@ class Loop extends Tag {
}
-
- $parent = $el->parentNode;
- //var_dump($parent);
+ if($category != -1) {
+ $posts = Post::listByCategory($category, $isRecent, 20);
+ } else {
+ $posts = Post::list($isRecent, 10);
+ }
+ if($tag != -1) {
+ $tposts = array();
+ foreach ($posts as $post) {
+ foreach ($post->getTags() as $ptag) {
+ if($tag == $ptag->getId()) {
+ $tposts[] = $post;
+ }
+ }
+ }
+ $posts = $tposts;
+ }
$limit = $limit > count($posts) ? count($posts) : $limit;
diff --git a/assets/php/Tags/Search.php b/assets/php/Tags/Search.php
new file mode 100644
index 0000000..6c32b32
--- /dev/null
+++ b/assets/php/Tags/Search.php
@@ -0,0 +1,122 @@
+getTags() as $ptag) {
+ if($tag == $ptag->getId()) {
+ $tposts[] = $post;
+ }
+ }
+ }
+ $posts = $tposts;
+ }
+
+ var_dump($posts);
+
+ }
+}
+
+class Loop extends Tag {
+ public function render() {
+ $el = $this->getElement();
+
+ $doc = $this->getDoc();
+
+ $limit = (int) $el->getAttribute("limit");
+ $parent = $el->parentNode;
+
+ $isRecent = isset($_GET["recent"]) && $_GET["recent"] == "false" ? false : true;
+ $category = isset($_GET["category"]) && intval($_GET["category"]) ? (int) $_GET["category"] : -1;
+ $tag = isset($_GET["tag"]) && intval($_GET["tag"]) ? (int) $_GET["tag"] : -1;
+
+ if($el->getAttribute("category") != '') {
+ $posts = Post::listByCategory(Post::get($_GET["post"])->getCategory()->getId(), $isRecent, 6);
+ $postsList = array();
+ foreach ($posts as $post) {
+ if($post->getId() != $_GET["post"]) $postsList[] = $post;
+ }
+ $posts = $postsList;
+ } else {
+ $posts = Post::list(true, 6);
+
+ }
+
+ if($category != -1) {
+ $posts = Post::listByCategory($category, $isRecent, 20);
+ } else {
+ $posts = Post::list($isRecent, 10);
+ }
+ if($tag != -1) {
+ $tposts = array();
+ foreach ($posts as $post) {
+ foreach ($post->getTags() as $ptag) {
+ if($tag == $ptag->getId()) {
+ $tposts[] = $post;
+ }
+ }
+ }
+ $posts = $tposts;
+ }
+
+
+ $limit = $limit > count($posts) ? count($posts) : $limit;
+
+ for ($i=0; $i < $limit; $i++) {
+ $pok = $el->childNodes->item(0)->cloneNode(true);
+
+ $parent->insertBefore($pok, $el);
+
+ $elements = $pok->getElementsByTagName("loop");
+
+ foreach ($elements as $ele) {
+ if($ele->getAttribute("column") == "content") {
+ Functions::appendHTML($ele->parentNode, $posts[$i]->getShort());
+ } elseif($ele->getAttribute("column") == "category") {
+ $txt = $doc->createTextNode($posts[$i]->getCategory()->getName());
+ $ele->parentNode->insertBefore($txt, $ele);
+ } else {
+ $col = 'get' . ucfirst($ele->getAttribute("column"));
+ $txt = $doc->createTextNode($posts[$i]->$col());
+ $ele->parentNode->insertBefore($txt, $ele);
+ }
+ }
+
+ $finder = new DomXPath($doc);
+ $nodes = $finder->query("//*[contains(@class, 'column-cat')]");
+
+ if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-category", $posts[$i]->getCategory()->getName() , $nodes[0]->getAttribute("class")));
+
+ $nodes = $finder->query("//*[contains(@class, 'column-link')]");
+
+ if(count($nodes) >= 1) $nodes[0]->setAttribute("href", "/post/".$posts[$i]->getId());
+ if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-link", "", $nodes[0]->getAttribute("class")));
+
+
+ $loop = $pok->getElementsByTagName("loop");
+
+ while ($loop->count() >= 1) {
+ $loop->item(0)->parentNode->removeChild($loop->item(0));
+ }
+
+
+ }
+ }
+}
diff --git a/assets/php/db/Post.php b/assets/php/db/Post.php
index 35ee936..7e46c6c 100644
--- a/assets/php/db/Post.php
+++ b/assets/php/db/Post.php
@@ -99,9 +99,12 @@ class Post {
return $this->dt;
}
+ /**
+ *
+ * @return \App\DB\Tag[]
+ */
public function getTags() {
$temp = array();
-
if ($this->tags == null) return $temp;
foreach ($this->tags as $tag) {
$temp[] = Tag::get($tag);
@@ -160,7 +163,17 @@ class Post {
$res = array();
foreach ($posts as $post) {
- $res[] = Post::fromArray($post);
+ $post = Post::fromArray($post);
+ $query = "SELECT * FROM post_tag WHERE post_id=". $post->getId();
+ $tagList = array();
+ $bool = $pdo->query($query);
+ // var_dump($bool->fetchAll());
+ if($bool) foreach ($pdo->query($query)->fetchAll() as $tag) {
+ $tagList[] = $tag["tag"];
+ }
+ $post->setTags($tagList);
+
+ $res[] = $post;
}
return $res;
diff --git a/assets/php/handler.php b/assets/php/handler.php
index 63417dd..f614007 100644
--- a/assets/php/handler.php
+++ b/assets/php/handler.php
@@ -2,11 +2,14 @@
error_reporting(E_ALL);
ini_set('display_errors', 'On');
-require_once "../../vendor/autoload.php";
-
+$loader = require "../../vendor/autoload.php";
+// var_dump($loader->getClassMap());
+define("CLASSMAP", $loader->getClassMap());
+define("DIR", str_replace("/php", "", __DIR__));
use App\Router;
use App\Functions;
use App\Tags\Tag;
+use App\Controller;
//renvoie vers le fichier css si il est demandé
if(Functions::endsWith($_GET["page"], ".css")) {
@@ -50,7 +53,9 @@ if(strlen($_GET['page']) > 1) {
// A ENLEVER LORS DES COMMITS DE FIN
// var_dump($_GET);
if($_GET["page"] == "/test/") {
- require_once "test.php";
+
+ // $controller = new Controller();
+ // echo $controller->getContent("/search", $loader);
die;
}
@@ -58,14 +63,18 @@ if($_GET["page"] == "/test/") {
* D�marrage du routage du contenu
*/
+
+
$router = new Router();
Functions::loadRoutes();
+$controller = new Controller();
+echo Tag::loadTags($controller->getContent($_GET["page"], $loader));
-//chargement des tags contenu sur la page
+// //chargement des tags contenu sur la page
-$pokemon = Tag::loadTags($router->search($_GET["page"])(), false);
+// $pokemon = Tag::loadTags($router->search($_GET["page"])(), false);
-echo $pokemon;
+// echo $pokemon;
diff --git a/assets/php/test.php b/assets/php/test.php
index 0620020..0fb1d5f 100644
--- a/assets/php/test.php
+++ b/assets/php/test.php
@@ -1,38 +1,40 @@
';
+// echo '';
-echo '
-
-';
+// document.querySelector("button").addEventListener("click", processForm);
+//
+// ';