From 8c10efc6495e595405f0219a3233b4432038d9b6 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Tue, 14 Nov 2023 10:11:06 +0100 Subject: [PATCH 01/20] add Admin et Parser changing --- fluxRSS/metier/Admin.php | 0 fluxRSS/model/Parser.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 fluxRSS/metier/Admin.php mode change 100644 => 100755 fluxRSS/model/Parser.php diff --git a/fluxRSS/metier/Admin.php b/fluxRSS/metier/Admin.php old mode 100644 new mode 100755 diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php old mode 100644 new mode 100755 -- 2.36.3 From 08b0a4d9061c72e3a4c75f3a1064b3ce2497b987 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 10:09:52 +0100 Subject: [PATCH 02/20] modification ArticleGateway, Connection, Controleur and view listArticle --- fluxRSS/DAL/ArticleGateway.php | 19 ++++++++++--------- fluxRSS/DAL/Connection.php | 9 +++++++-- fluxRSS/controleur/Controleur.php | 8 +++++--- fluxRSS/model/ArticleModel.php | 4 ++-- fluxRSS/templates/listArticle.html | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/fluxRSS/DAL/ArticleGateway.php b/fluxRSS/DAL/ArticleGateway.php index a36f565..ad5bba5 100755 --- a/fluxRSS/DAL/ArticleGateway.php +++ b/fluxRSS/DAL/ArticleGateway.php @@ -22,15 +22,16 @@ class ArticleGateway return $this->con->getResults(); } - public function addArticle(Article $article){ + public function addArticle(Article $article) + { $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array( ':id' => array($article->getId(), PDO::PARAM_STR), - ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(),PDO::PARAM_STR), - ':description' => array($article->getDescription(),PDO::PARAM_STR), - ':guid' => array($article->getGuid(),PDO::PARAM_STR), - ':link' => array($article->getLink(),PDO::PARAM_STR), - ':mediaContent' => array($article->getMediaContent(),PDO::PARAM_STR), - ':provenance' => array($article->getProvenance(),PDO::PARAM_INT))); + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + ':title' => array($article->getTitle(), PDO::PARAM_STR), + ':date' => array($article->getDate(), PDO::PARAM_STR), + ':description' => array($article->getDescription(), PDO::PARAM_STR), + ':guid' => array($article->getGuid(), PDO::PARAM_STR), + ':link' => array($article->getLink(), PDO::PARAM_STR), + ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), + ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); } } \ No newline at end of file diff --git a/fluxRSS/DAL/Connection.php b/fluxRSS/DAL/Connection.php index 8be3ee1..1ca9c27 100755 --- a/fluxRSS/DAL/Connection.php +++ b/fluxRSS/DAL/Connection.php @@ -15,8 +15,13 @@ class Connection extends PDO */ public function __construct(string $dsn, string $username, string $password) { - parent::__construct($dsn, $username, $password); - $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + try{ + parent::__construct($dsn, $username, $password); + $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + }catch (Exception $e){ + throw new Exception("PDO error con"); + } + } /** diff --git a/fluxRSS/controleur/Controleur.php b/fluxRSS/controleur/Controleur.php index ca4318e..81a6bee 100755 --- a/fluxRSS/controleur/Controleur.php +++ b/fluxRSS/controleur/Controleur.php @@ -3,13 +3,13 @@ namespace controleur; use model\ArticleModel; + class Controleur { public function __construct() { global $twig; // nécessaire pour utiliser variables globales session_start(); - $tabArticle[] = ArticleModel::getArticles(); //debut //on initialise un tableau d'erreur @@ -30,6 +30,7 @@ class Controleur //mauvaise action default: + $tabArticle[] = ArticleModel::getArticles(); $dVueEreur[] = "Erreur d'appel php"; $dataview = ['Article'=> $tabArticle]; echo $twig->render('listArticle.html', ['tabArticle' => $dataview, 'dVueErreur'=>$dVueEreur]); @@ -55,8 +56,9 @@ class Controleur $dVue = [ 'nom' => '', 'age' => 0, + 'data' => ArticleModel::getArticles(), ]; - echo $twig->render('vuephp1.html', [ + echo $twig->render('listArticle.html', [ 'dVue' => $dVue ]); } @@ -74,7 +76,7 @@ class Controleur $model = new \metier\Simplemodel(); $data = $model->get_data(); */ - + $dVue = [ 'nom' => $nom, 'age' => $age, diff --git a/fluxRSS/model/ArticleModel.php b/fluxRSS/model/ArticleModel.php index 4caf73a..bcb25a1 100755 --- a/fluxRSS/model/ArticleModel.php +++ b/fluxRSS/model/ArticleModel.php @@ -4,17 +4,17 @@ namespace model; use DAL; use metier; -require_once "config/config.php"; class ArticleModel { public static function getArticles() : array { - $gwArticle = new DAL\ArticleGateway(new DAL\Connection( $base, $login, $mdp)); + $gwArticle = new DAL\ArticleGateway(new DAL\Connection( 'mysql:host = localhost; dbname = dbrorossetto', 'rorossetto','tpphp')); $res = $gwArticle->getAllArticles(); foreach($res as $row){ $tabArticle[] = new metier\Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); } return $tabArticle; } + } \ No newline at end of file diff --git a/fluxRSS/templates/listArticle.html b/fluxRSS/templates/listArticle.html index c3dbaa6..b794cb4 100755 --- a/fluxRSS/templates/listArticle.html +++ b/fluxRSS/templates/listArticle.html @@ -5,7 +5,7 @@ All Articles -{% for value in tabArticle.Article %} +{% for value in dataview.tabArticle.Article %}

{{value}}

{% endfor %} -- 2.36.3 From 1d416b1d670c7334c88aac96f2fe91478c2ed422 Mon Sep 17 00:00:00 2001 From: point Date: Wed, 15 Nov 2023 12:37:38 +0100 Subject: [PATCH 03/20] modif composer --- fluxRSS/vendor/composer/autoload_psr4.php | 10 +++++----- fluxRSS/vendor/composer/autoload_static.php | 10 +++++----- fluxRSS/vendor/composer/installed.php | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fluxRSS/vendor/composer/autoload_psr4.php b/fluxRSS/vendor/composer/autoload_psr4.php index 1002bc1..15606d7 100755 --- a/fluxRSS/vendor/composer/autoload_psr4.php +++ b/fluxRSS/vendor/composer/autoload_psr4.php @@ -6,12 +6,12 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( - 'model\\' => array($baseDir . '/model'), - 'metier\\' => array($baseDir . '/metier'), - 'controleur\\' => array($baseDir . '/controleur'), - 'config\\' => array($baseDir . '/config'), + 'model\\' => array($baseDir . '/src/model'), + 'metier\\' => array($baseDir . '/src/metier'), + 'controleur\\' => array($baseDir . '/src/controleur'), + 'config\\' => array($baseDir . '/src/config'), 'Twig\\' => array($vendorDir . '/twig/twig/src'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), - 'DAL\\' => array($baseDir . '/DAL'), + 'DAL\\' => array($baseDir . '/src/DAL'), ); diff --git a/fluxRSS/vendor/composer/autoload_static.php b/fluxRSS/vendor/composer/autoload_static.php index 868aa69..b63d956 100755 --- a/fluxRSS/vendor/composer/autoload_static.php +++ b/fluxRSS/vendor/composer/autoload_static.php @@ -40,19 +40,19 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 public static $prefixDirsPsr4 = array ( 'model\\' => array ( - 0 => __DIR__ . '/../..' . '/model', + 0 => __DIR__ . '/../..' . '/src/model', ), 'metier\\' => array ( - 0 => __DIR__ . '/../..' . '/metier', + 0 => __DIR__ . '/../..' . '/src/metier', ), 'controleur\\' => array ( - 0 => __DIR__ . '/../..' . '/controleur', + 0 => __DIR__ . '/../..' . '/src/controleur', ), 'config\\' => array ( - 0 => __DIR__ . '/../..' . '/config', + 0 => __DIR__ . '/../..' . '/src/config', ), 'Twig\\' => array ( @@ -68,7 +68,7 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ), 'DAL\\' => array ( - 0 => __DIR__ . '/../..' . '/DAL', + 0 => __DIR__ . '/../..' . '/src/DAL', ), ); diff --git a/fluxRSS/vendor/composer/installed.php b/fluxRSS/vendor/composer/installed.php index f85d7f7..4b76349 100755 --- a/fluxRSS/vendor/composer/installed.php +++ b/fluxRSS/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'ad56f74a69d8ff3b81d0d287531c37da6ef273ab', + 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'ad56f74a69d8ff3b81d0d287531c37da6ef273ab', + 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), -- 2.36.3 From dc077c230da502bb8d57c200d856f4e764d6d398 Mon Sep 17 00:00:00 2001 From: mapoint2 Date: Wed, 15 Nov 2023 12:39:13 +0100 Subject: [PATCH 04/20] modif composer --- .idea/sqldialects.xml | 6 ------ fluxRSS/composer.json | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 .idea/sqldialects.xml diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml deleted file mode 100644 index ff83d34..0000000 --- a/.idea/sqldialects.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/fluxRSS/composer.json b/fluxRSS/composer.json index 9ee7dc7..c412f39 100755 --- a/fluxRSS/composer.json +++ b/fluxRSS/composer.json @@ -6,6 +6,7 @@ }, "autoload": { "psr-4": { + "src\\": "src/", "controleur\\": "src/controleur/", "config\\": "src/config/", "model\\": "src/model/", -- 2.36.3 From c39a62aa687268a005c8a72a05ce49d27cfc6f91 Mon Sep 17 00:00:00 2001 From: point Date: Wed, 15 Nov 2023 12:40:09 +0100 Subject: [PATCH 05/20] modif composer --- fluxRSS/vendor/composer/autoload_psr4.php | 1 + fluxRSS/vendor/composer/autoload_static.php | 8 ++++++++ fluxRSS/vendor/composer/installed.php | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fluxRSS/vendor/composer/autoload_psr4.php b/fluxRSS/vendor/composer/autoload_psr4.php index 15606d7..4501883 100755 --- a/fluxRSS/vendor/composer/autoload_psr4.php +++ b/fluxRSS/vendor/composer/autoload_psr4.php @@ -6,6 +6,7 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( + 'src\\' => array($baseDir . '/src'), 'model\\' => array($baseDir . '/src/model'), 'metier\\' => array($baseDir . '/src/metier'), 'controleur\\' => array($baseDir . '/src/controleur'), diff --git a/fluxRSS/vendor/composer/autoload_static.php b/fluxRSS/vendor/composer/autoload_static.php index b63d956..eb5e51a 100755 --- a/fluxRSS/vendor/composer/autoload_static.php +++ b/fluxRSS/vendor/composer/autoload_static.php @@ -12,6 +12,10 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ); public static $prefixLengthsPsr4 = array ( + 's' => + array ( + 'src\\' => 4, + ), 'm' => array ( 'model\\' => 6, @@ -38,6 +42,10 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ); public static $prefixDirsPsr4 = array ( + 'src\\' => + array ( + 0 => __DIR__ . '/../..' . '/src', + ), 'model\\' => array ( 0 => __DIR__ . '/../..' . '/src/model', diff --git a/fluxRSS/vendor/composer/installed.php b/fluxRSS/vendor/composer/installed.php index 4b76349..f9f7468 100755 --- a/fluxRSS/vendor/composer/installed.php +++ b/fluxRSS/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', + 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '7ca707374e111fc24955301cfde517ec7ec5ab63', + 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), -- 2.36.3 From fa388c96e1b4377bdd971369eea2939da055c499 Mon Sep 17 00:00:00 2001 From: mapoint2 Date: Wed, 15 Nov 2023 12:49:36 +0100 Subject: [PATCH 06/20] gestion d'erreur --- fluxRSS/index.php | 2 +- fluxRSS/{src => }/templates/.DS_Store | Bin fluxRSS/{src => }/templates/erreur.html | 0 fluxRSS/{src => }/templates/listArticle.html | 4 +--- fluxRSS/{src => }/templates/vuephp1.html | 0 5 files changed, 2 insertions(+), 4 deletions(-) rename fluxRSS/{src => }/templates/.DS_Store (100%) rename fluxRSS/{src => }/templates/erreur.html (100%) rename fluxRSS/{src => }/templates/listArticle.html (81%) rename fluxRSS/{src => }/templates/vuephp1.html (100%) diff --git a/fluxRSS/index.php b/fluxRSS/index.php index fd16b5b..f109bd4 100755 --- a/fluxRSS/index.php +++ b/fluxRSS/index.php @@ -1,7 +1,7 @@ {% for value in dVue.data %} -

- {% for article in value} + {% for article in value %}

{{article}}

{% endfor %} -

{% endfor %} \ No newline at end of file diff --git a/fluxRSS/src/templates/vuephp1.html b/fluxRSS/templates/vuephp1.html similarity index 100% rename from fluxRSS/src/templates/vuephp1.html rename to fluxRSS/templates/vuephp1.html -- 2.36.3 From 0bfc92956970a8f2e61bad94cf9065a080f9dbc4 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 14:22:46 +0100 Subject: [PATCH 07/20] add altorouteur --- fluxRSS/.idea/mvc_PSR4_twig.iml | 1 + fluxRSS/AltoRouter.php | 302 ++++++++++++++++++ .../.github/workflows/php.yml | 39 +++ .../AltoRouter.php | 302 ++++++++++++++++++ .../LICENSE.md | 9 + .../README.md | 57 ++++ .../composer.json | 35 ++ .../phpcs.xml | 10 + fluxRSS/src/DAL/FluxGateway.php | 6 + fluxRSS/src/metier/Flux.php | 20 +- fluxRSS/src/model/Parser.php | 17 +- fluxRSS/src/test/test.php | 14 + fluxRSS/vendor/composer/installed.php | 4 +- 13 files changed, 798 insertions(+), 18 deletions(-) create mode 100755 fluxRSS/AltoRouter.php create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json create mode 100755 fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml create mode 100755 fluxRSS/src/test/test.php diff --git a/fluxRSS/.idea/mvc_PSR4_twig.iml b/fluxRSS/.idea/mvc_PSR4_twig.iml index c0f9f5d..1323748 100755 --- a/fluxRSS/.idea/mvc_PSR4_twig.iml +++ b/fluxRSS/.idea/mvc_PSR4_twig.iml @@ -9,6 +9,7 @@ + diff --git a/fluxRSS/AltoRouter.php b/fluxRSS/AltoRouter.php new file mode 100755 index 0000000..31aa338 --- /dev/null +++ b/fluxRSS/AltoRouter.php @@ -0,0 +1,302 @@ + + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +class AltoRouter +{ + + /** + * @var array Array of all routes (incl. named routes). + */ + protected $routes = []; + + /** + * @var array Array of all named routes. + */ + protected $namedRoutes = []; + + /** + * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host) + */ + protected $basePath = ''; + + /** + * @var array Array of default match types (regex helpers) + */ + protected $matchTypes = [ + 'i' => '[0-9]++', + 'a' => '[0-9A-Za-z]++', + 'h' => '[0-9A-Fa-f]++', + '*' => '.+?', + '**' => '.++', + '' => '[^/\.]++' + ]; + + /** + * Create router in one call from config. + * + * @param array $routes + * @param string $basePath + * @param array $matchTypes + * @throws Exception + */ + public function __construct(array $routes = [], $basePath = '', array $matchTypes = []) + { + $this->addRoutes($routes); + $this->setBasePath($basePath); + $this->addMatchTypes($matchTypes); + } + + /** + * Retrieves all routes. + * Useful if you want to process or display routes. + * @return array All routes. + */ + public function getRoutes() + { + return $this->routes; + } + + /** + * Add multiple routes at once from array in the following format: + * + * $routes = [ + * [$method, $route, $target, $name] + * ]; + * + * @param array $routes + * @return void + * @author Koen Punt + * @throws Exception + */ + public function addRoutes($routes) + { + if (!is_array($routes) && !$routes instanceof Traversable) { + throw new RuntimeException('Routes should be an array or an instance of Traversable'); + } + foreach ($routes as $route) { + call_user_func_array([$this, 'map'], $route); + } + } + + /** + * Set the base path. + * Useful if you are running your application from a subdirectory. + * @param string $basePath + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + } + + /** + * Add named match types. It uses array_merge so keys can be overwritten. + * + * @param array $matchTypes The key is the name and the value is the regex. + */ + public function addMatchTypes(array $matchTypes) + { + $this->matchTypes = array_merge($this->matchTypes, $matchTypes); + } + + /** + * Map a route to a target + * + * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE) + * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id] + * @param mixed $target The target where this route should point to. Can be anything. + * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application. + * @throws Exception + */ + public function map($method, $route, $target, $name = null) + { + + $this->routes[] = [$method, $route, $target, $name]; + + if ($name) { + if (isset($this->namedRoutes[$name])) { + throw new RuntimeException("Can not redeclare route '{$name}'"); + } + $this->namedRoutes[$name] = $route; + } + + return; + } + + /** + * Reversed routing + * + * Generate the URL for a named route. Replace regexes with supplied parameters + * + * @param string $routeName The name of the route. + * @param array @params Associative array of parameters to replace placeholders with. + * @return string The URL of the route with named parameters in place. + * @throws Exception + */ + public function generate($routeName, array $params = []) + { + + // Check if named route exists + if (!isset($this->namedRoutes[$routeName])) { + throw new RuntimeException("Route '{$routeName}' does not exist."); + } + + // Replace named parameters + $route = $this->namedRoutes[$routeName]; + + // prepend base path to route url again + $url = $this->basePath . $route; + + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + foreach ($matches as $index => $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if ($pre) { + $block = substr($block, 1); + } + + if (isset($params[$param])) { + // Part is found, replace for param value + $url = str_replace($block, $params[$param], $url); + } elseif ($optional && $index !== 0) { + // Only strip preceding slash if it's not at the base + $url = str_replace($pre . $block, '', $url); + } else { + // Strip match block + $url = str_replace($block, '', $url); + } + } + } + + return $url; + } + + /** + * Match a given Request Url against stored routes + * @param string $requestUrl + * @param string $requestMethod + * @return array|boolean Array with route information on success, false on failure (no match). + */ + public function match($requestUrl = null, $requestMethod = null) + { + + $params = []; + + // set Request Url if it isn't passed as parameter + if ($requestUrl === null) { + $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; + } + + // strip base path from request url + $requestUrl = substr($requestUrl, strlen($this->basePath)); + + // Strip query string (?a=b) from Request Url + if (($strpos = strpos($requestUrl, '?')) !== false) { + $requestUrl = substr($requestUrl, 0, $strpos); + } + + $lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : ''; + + // set Request Method if it isn't passed as a parameter + if ($requestMethod === null) { + $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + } + + foreach ($this->routes as $handler) { + list($methods, $route, $target, $name) = $handler; + + $method_match = (stripos($methods, $requestMethod) !== false); + + // Method did not match, continue to next route. + if (!$method_match) { + continue; + } + + if ($route === '*') { + // * wildcard (matches all) + $match = true; + } elseif (isset($route[0]) && $route[0] === '@') { + // @ regex delimiter + $pattern = '`' . substr($route, 1) . '`u'; + $match = preg_match($pattern, $requestUrl, $params) === 1; + } elseif (($position = strpos($route, '[')) === false) { + // No params in url, do string comparison + $match = strcmp($requestUrl, $route) === 0; + } else { + // Compare longest non-param string with url before moving on to regex + // Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241) + if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) { + continue; + } + + $regex = $this->compileRoute($route); + $match = preg_match($regex, $requestUrl, $params) === 1; + } + + if ($match) { + if ($params) { + foreach ($params as $key => $value) { + if (is_numeric($key)) { + unset($params[$key]); + } + } + } + + return [ + 'target' => $target, + 'params' => $params, + 'name' => $name + ]; + } + } + + return false; + } + + /** + * Compile the regex for a given route (EXPENSIVE) + * @param $route + * @return string + */ + protected function compileRoute($route) + { + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + $matchTypes = $this->matchTypes; + foreach ($matches as $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if (isset($matchTypes[$type])) { + $type = $matchTypes[$type]; + } + if ($pre === '.') { + $pre = '\.'; + } + + $optional = $optional !== '' ? '?' : null; + + //Older versions of PCRE require the 'P' in (?P) + $pattern = '(?:' + . ($pre !== '' ? $pre : null) + . '(' + . ($param !== '' ? "?P<$param>" : null) + . $type + . ')' + . $optional + . ')' + . $optional; + + $route = str_replace($block, $pattern, $route); + } + } + return "`^$route$`u"; + } +} diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml new file mode 100755 index 0000000..c428ab7 --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/.github/workflows/php.yml @@ -0,0 +1,39 @@ +name: PHP + +on: [ push, pull_request ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '7.3', '7.4', '8.0', '8.1' ] + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: composer + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress + + - name: Run test suite + run: composer run-script test \ No newline at end of file diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php new file mode 100755 index 0000000..31aa338 --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/AltoRouter.php @@ -0,0 +1,302 @@ + + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +class AltoRouter +{ + + /** + * @var array Array of all routes (incl. named routes). + */ + protected $routes = []; + + /** + * @var array Array of all named routes. + */ + protected $namedRoutes = []; + + /** + * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host) + */ + protected $basePath = ''; + + /** + * @var array Array of default match types (regex helpers) + */ + protected $matchTypes = [ + 'i' => '[0-9]++', + 'a' => '[0-9A-Za-z]++', + 'h' => '[0-9A-Fa-f]++', + '*' => '.+?', + '**' => '.++', + '' => '[^/\.]++' + ]; + + /** + * Create router in one call from config. + * + * @param array $routes + * @param string $basePath + * @param array $matchTypes + * @throws Exception + */ + public function __construct(array $routes = [], $basePath = '', array $matchTypes = []) + { + $this->addRoutes($routes); + $this->setBasePath($basePath); + $this->addMatchTypes($matchTypes); + } + + /** + * Retrieves all routes. + * Useful if you want to process or display routes. + * @return array All routes. + */ + public function getRoutes() + { + return $this->routes; + } + + /** + * Add multiple routes at once from array in the following format: + * + * $routes = [ + * [$method, $route, $target, $name] + * ]; + * + * @param array $routes + * @return void + * @author Koen Punt + * @throws Exception + */ + public function addRoutes($routes) + { + if (!is_array($routes) && !$routes instanceof Traversable) { + throw new RuntimeException('Routes should be an array or an instance of Traversable'); + } + foreach ($routes as $route) { + call_user_func_array([$this, 'map'], $route); + } + } + + /** + * Set the base path. + * Useful if you are running your application from a subdirectory. + * @param string $basePath + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + } + + /** + * Add named match types. It uses array_merge so keys can be overwritten. + * + * @param array $matchTypes The key is the name and the value is the regex. + */ + public function addMatchTypes(array $matchTypes) + { + $this->matchTypes = array_merge($this->matchTypes, $matchTypes); + } + + /** + * Map a route to a target + * + * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE) + * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id] + * @param mixed $target The target where this route should point to. Can be anything. + * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application. + * @throws Exception + */ + public function map($method, $route, $target, $name = null) + { + + $this->routes[] = [$method, $route, $target, $name]; + + if ($name) { + if (isset($this->namedRoutes[$name])) { + throw new RuntimeException("Can not redeclare route '{$name}'"); + } + $this->namedRoutes[$name] = $route; + } + + return; + } + + /** + * Reversed routing + * + * Generate the URL for a named route. Replace regexes with supplied parameters + * + * @param string $routeName The name of the route. + * @param array @params Associative array of parameters to replace placeholders with. + * @return string The URL of the route with named parameters in place. + * @throws Exception + */ + public function generate($routeName, array $params = []) + { + + // Check if named route exists + if (!isset($this->namedRoutes[$routeName])) { + throw new RuntimeException("Route '{$routeName}' does not exist."); + } + + // Replace named parameters + $route = $this->namedRoutes[$routeName]; + + // prepend base path to route url again + $url = $this->basePath . $route; + + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + foreach ($matches as $index => $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if ($pre) { + $block = substr($block, 1); + } + + if (isset($params[$param])) { + // Part is found, replace for param value + $url = str_replace($block, $params[$param], $url); + } elseif ($optional && $index !== 0) { + // Only strip preceding slash if it's not at the base + $url = str_replace($pre . $block, '', $url); + } else { + // Strip match block + $url = str_replace($block, '', $url); + } + } + } + + return $url; + } + + /** + * Match a given Request Url against stored routes + * @param string $requestUrl + * @param string $requestMethod + * @return array|boolean Array with route information on success, false on failure (no match). + */ + public function match($requestUrl = null, $requestMethod = null) + { + + $params = []; + + // set Request Url if it isn't passed as parameter + if ($requestUrl === null) { + $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; + } + + // strip base path from request url + $requestUrl = substr($requestUrl, strlen($this->basePath)); + + // Strip query string (?a=b) from Request Url + if (($strpos = strpos($requestUrl, '?')) !== false) { + $requestUrl = substr($requestUrl, 0, $strpos); + } + + $lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : ''; + + // set Request Method if it isn't passed as a parameter + if ($requestMethod === null) { + $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + } + + foreach ($this->routes as $handler) { + list($methods, $route, $target, $name) = $handler; + + $method_match = (stripos($methods, $requestMethod) !== false); + + // Method did not match, continue to next route. + if (!$method_match) { + continue; + } + + if ($route === '*') { + // * wildcard (matches all) + $match = true; + } elseif (isset($route[0]) && $route[0] === '@') { + // @ regex delimiter + $pattern = '`' . substr($route, 1) . '`u'; + $match = preg_match($pattern, $requestUrl, $params) === 1; + } elseif (($position = strpos($route, '[')) === false) { + // No params in url, do string comparison + $match = strcmp($requestUrl, $route) === 0; + } else { + // Compare longest non-param string with url before moving on to regex + // Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241) + if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) { + continue; + } + + $regex = $this->compileRoute($route); + $match = preg_match($regex, $requestUrl, $params) === 1; + } + + if ($match) { + if ($params) { + foreach ($params as $key => $value) { + if (is_numeric($key)) { + unset($params[$key]); + } + } + } + + return [ + 'target' => $target, + 'params' => $params, + 'name' => $name + ]; + } + } + + return false; + } + + /** + * Compile the regex for a given route (EXPENSIVE) + * @param $route + * @return string + */ + protected function compileRoute($route) + { + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + $matchTypes = $this->matchTypes; + foreach ($matches as $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if (isset($matchTypes[$type])) { + $type = $matchTypes[$type]; + } + if ($pre === '.') { + $pre = '\.'; + } + + $optional = $optional !== '' ? '?' : null; + + //Older versions of PCRE require the 'P' in (?P) + $pattern = '(?:' + . ($pre !== '' ? $pre : null) + . '(' + . ($param !== '' ? "?P<$param>" : null) + . $type + . ')' + . $optional + . ')' + . $optional; + + $route = str_replace($block, $pattern, $route); + } + } + return "`^$route$`u"; + } +} diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md new file mode 100755 index 0000000..a1130bb --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/LICENSE.md @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2012 Danny van Kooten + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md new file mode 100755 index 0000000..7d6e1fe --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/README.md @@ -0,0 +1,57 @@ +# AltoRouter ![PHP status](https://github.com/dannyvankooten/AltoRouter/workflows/PHP/badge.svg) [![Latest Stable Version](https://poser.pugx.org/altorouter/altorouter/v/stable.svg)](https://packagist.org/packages/altorouter/altorouter) [![License](https://poser.pugx.org/altorouter/altorouter/license.svg)](https://packagist.org/packages/altorouter/altorouter) + +AltoRouter is a small but powerful routing class, heavily inspired by [klein.php](https://github.com/chriso/klein.php/). + +```php +$router = new AltoRouter(); + +// map homepage +$router->map('GET', '/', function() { + require __DIR__ . '/views/home.php'; +}); + +// dynamic named route +$router->map('GET|POST', '/users/[i:id]/', function($id) { + $user = ..... + require __DIR__ . '/views/user/details.php'; +}, 'user-details'); + +// echo URL to user-details page for ID 5 +echo $router->generate('user-details', ['id' => 5]); // Output: "/users/5" +``` + +## Features + +* Can be used with all HTTP Methods +* Dynamic routing with named route parameters +* Reversed routing +* Flexible regular expression routing (inspired by [Sinatra](http://www.sinatrarb.com/)) +* Custom regexes + +## Getting started + +You need PHP >= 5.6 to use AltoRouter, although we highly recommend you [use an officially supported PHP version](https://secure.php.net/supported-versions.php) that is not EOL. + +- [Install AltoRouter](http://altorouter.com/usage/install.html) +- [Rewrite all requests to AltoRouter](http://altorouter.com/usage/rewrite-requests.html) +- [Map your routes](http://altorouter.com/usage/mapping-routes.html) +- [Match requests](http://altorouter.com/usage/matching-requests.html) +- [Process the request your preferred way](http://altorouter.com/usage/processing-requests.html) + +## Contributors +- [Danny van Kooten](https://github.com/dannyvankooten) +- [Koen Punt](https://github.com/koenpunt) +- [John Long](https://github.com/adduc) +- [Niahoo Osef](https://github.com/niahoo) + +## License + +MIT License + +Copyright (c) 2012 Danny van Kooten + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json new file mode 100755 index 0000000..6828248 --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/composer.json @@ -0,0 +1,35 @@ +{ + "name": "altorouter/altorouter", + "description": "A lightning fast router for PHP", + "keywords": ["router", "routing", "lightweight"], + "homepage": "https://github.com/dannyvankooten/AltoRouter", + "license": "MIT", + "authors": [ + { + "name": "Danny van Kooten", + "email": "dannyvankooten@gmail.com", + "homepage": "http://dannyvankooten.com/" + }, + { + "name": "Koen Punt", + "homepage": "https://github.com/koenpunt" + }, + { + "name": "niahoo", + "homepage": "https://github.com/niahoo" + } + ], + "require": { + "php": ">=7.0" + }, + "require-dev": { + "phpunit/phpunit": "9.5.*", + "squizlabs/php_codesniffer": "3.6.2" + }, + "autoload": { + "classmap": ["AltoRouter.php"] + }, + "scripts": { + "test": "vendor/bin/phpunit" + } +} diff --git a/fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml new file mode 100755 index 0000000..d59cccf --- /dev/null +++ b/fluxRSS/dannyvankooten-AltoRouter-ac028a7/phpcs.xml @@ -0,0 +1,10 @@ + + + rules + + + tests + AltoRouter.php + examples/ + + diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 43bbe9f..9344801 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -13,6 +13,12 @@ class FluxGateway $this->con = $con; } + public function getId(): int + { + + return $this->id; + } + public function addFlux($flux){ try{ $query = 'INSERT INTO Flux VALUES (:flux);'; diff --git a/fluxRSS/src/metier/Flux.php b/fluxRSS/src/metier/Flux.php index a167fbe..627d9f2 100755 --- a/fluxRSS/src/metier/Flux.php +++ b/fluxRSS/src/metier/Flux.php @@ -4,9 +4,19 @@ namespace metier; class Flux { - private string $id; + private int $id; private string $flux; + /** + * @param int $id + * @param string $flux + */ + public function __construct(int $id, string $flux) + { + $this->id = $id; + $this->flux = $flux; + } + /** * @return string */ @@ -22,12 +32,4 @@ class Flux { $this->flux = $flux; } - - /** - * @return string - */ - public function getId(): string - { - return $this->id; - } } \ No newline at end of file diff --git a/fluxRSS/src/model/Parser.php b/fluxRSS/src/model/Parser.php index 287e26d..70f8b95 100755 --- a/fluxRSS/src/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -54,7 +54,9 @@ class Parser * @throws Exception */ public function parseAll($fluxes){ + $tabArticles = []; foreach ($fluxes as $flux){ + var_dump($flux); $tabArticles[] =$this->parseArticles($flux); } return $tabArticles; @@ -65,11 +67,15 @@ class Parser */ public function addAllArticles() { + $tabFluxes = []; $this->articleGateway->removeAllArticleForParser(); - $allFlux = $this->fluxGateway->findAllFlux(); - var_dump($allFlux); - $allArticles = $this->parseAll($allFlux); + $allItemFlux = $this->fluxGateway->findAllFlux(); + var_dump($allItemFlux); + foreach ($allItemFlux as $ItemFlux){ + $tabFluxes[] = $ItemFlux[1]; + } + $allArticles = $this->parseAll($tabFluxes); var_dump($allArticles); foreach ($allArticles as $article) { $this->articleGateway->addArticle($article); @@ -78,10 +84,7 @@ class Parser } } -$gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); -$gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); -$pars = new Parser( $gwFl,$gwArt); -var_dump($pars->addAllArticles()); + diff --git a/fluxRSS/src/test/test.php b/fluxRSS/src/test/test.php new file mode 100755 index 0000000..68afbe3 --- /dev/null +++ b/fluxRSS/src/test/test.php @@ -0,0 +1,14 @@ +addAllArticles()); + diff --git a/fluxRSS/vendor/composer/installed.php b/fluxRSS/vendor/composer/installed.php index f9f7468..8b559d3 100755 --- a/fluxRSS/vendor/composer/installed.php +++ b/fluxRSS/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', + 'reference' => 'c39a62aa687268a005c8a72a05ce49d27cfc6f91', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'dc077c230da502bb8d57c200d856f4e764d6d398', + 'reference' => 'c39a62aa687268a005c8a72a05ce49d27cfc6f91', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), -- 2.36.3 From 0768066a7b60a441d32e6a15a1f76c55a493727b Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 14:26:42 +0100 Subject: [PATCH 08/20] adding altoRouteur --- fluxRSS/AltoRouter.php | 2 ++ fluxRSS/controleur/FrontControleur.php | 12 ++++++++++++ .../dannyvankooten-AltoRouter-ac028a7/composer.json | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100755 fluxRSS/controleur/FrontControleur.php diff --git a/fluxRSS/AltoRouter.php b/fluxRSS/AltoRouter.php index 31aa338..6c14b90 100755 --- a/fluxRSS/AltoRouter.php +++ b/fluxRSS/AltoRouter.php @@ -11,6 +11,8 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +namespace vendor; + class AltoRouter { diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/controleur/FrontControleur.php new file mode 100755 index 0000000..bfceb74 --- /dev/null +++ b/fluxRSS/controleur/FrontControleur.php @@ -0,0 +1,12 @@ +=7.0" + "php": ">=5.6.0" }, "require-dev": { "phpunit/phpunit": "9.5.*", -- 2.36.3 From a160974d61cd7792a341b533ace7909598c9e4cc Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 14:33:37 +0100 Subject: [PATCH 09/20] directory modification --- fluxRSS/{ => src}/controleur/FrontControleur.php | 2 ++ 1 file changed, 2 insertions(+) rename fluxRSS/{ => src}/controleur/FrontControleur.php (98%) diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php similarity index 98% rename from fluxRSS/controleur/FrontControleur.php rename to fluxRSS/src/controleur/FrontControleur.php index bfceb74..af7b2b3 100755 --- a/fluxRSS/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -9,4 +9,6 @@ class FrontControleur public function __construct(){ $altoRouteur = new AltoRouter(); } + + } \ No newline at end of file -- 2.36.3 From 54091b41ff06453d775f869aefa05e63bff98ccf Mon Sep 17 00:00:00 2001 From: Rossetto Date: Wed, 15 Nov 2023 15:20:52 +0100 Subject: [PATCH 10/20] modification of controllers added --- ...8a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php | 6 +++--- fluxRSS/src/controleur/Controleur.php | 2 +- fluxRSS/src/controleur/FrontControleur.php | 4 +++- fluxRSS/templates/{vuephp1.html => Connection.html} | 0 4 files changed, 7 insertions(+), 5 deletions(-) rename fluxRSS/templates/{vuephp1.html => Connection.html} (100%) diff --git a/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php b/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php index 1dcc316..aa56ec3 100755 --- a/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php +++ b/fluxRSS/cache/7d/7d23d818a9618a39f1bf95b3e694ad5c44a32007fb7602bc4dc5cebe7a55ad13.php @@ -12,7 +12,7 @@ use Twig\Sandbox\SecurityNotAllowedFunctionError; use Twig\Source; use Twig\Template; -/* vuephp1.html */ +/* Connection.html */ class __TwigTemplate_2ce784f5b9085065b66af58be97997ff169e0f0d71d95a1d280acea4a24fd4e6 extends Template { private $source; @@ -165,7 +165,7 @@ utilisation anormale de la vuephp public function getTemplateName() { - return "vuephp1.html"; + return "Connection.html"; } public function isTraitable() @@ -180,6 +180,6 @@ utilisation anormale de la vuephp public function getSourceContext() { - return new Source("", "vuephp1.html", "/Applications/MAMP/htdocs/phptwig/templates/vuephp1.html"); + return new Source("", "Connection.html", "/Applications/MAMP/htdocs/phptwig/templates/Connection.html"); } } diff --git a/fluxRSS/src/controleur/Controleur.php b/fluxRSS/src/controleur/Controleur.php index 86ef927..e94eb78 100755 --- a/fluxRSS/src/controleur/Controleur.php +++ b/fluxRSS/src/controleur/Controleur.php @@ -81,6 +81,6 @@ class Controleur //'data' => $data, ]; - echo $twig->render('vuephp1.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); + echo $twig->render('Connection.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); } }//fin class diff --git a/fluxRSS/src/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php index af7b2b3..791bfc3 100755 --- a/fluxRSS/src/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -7,7 +7,9 @@ use vendor\AltoRouter; class FrontControleur { public function __construct(){ - $altoRouteur = new AltoRouter(); + $routeur = new AltoRouter(); + + } diff --git a/fluxRSS/templates/vuephp1.html b/fluxRSS/templates/Connection.html similarity index 100% rename from fluxRSS/templates/vuephp1.html rename to fluxRSS/templates/Connection.html -- 2.36.3 From 12913ba1e72bd36a1d400fce4ce913d8960fd479 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Thu, 16 Nov 2023 15:09:16 +0100 Subject: [PATCH 11/20] parser fixed, there's a connection problem to load articles into database --- fluxRSS/src/DAL/ArticleGateway.php | 6 +-- fluxRSS/src/DAL/Connection.php | 11 ++++- fluxRSS/src/DAL/FluxGateway.php | 5 ++- fluxRSS/src/controleur/FrontControleur.php | 3 -- fluxRSS/src/metier/Article.php | 18 +++++--- fluxRSS/src/metier/Flux.php | 8 ++++ fluxRSS/src/model/FluxModel.php | 14 +++--- fluxRSS/src/model/Parser.php | 52 +++++++++++++++++----- 8 files changed, 84 insertions(+), 33 deletions(-) diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php index 89e43ec..2bb7da7 100755 --- a/fluxRSS/src/DAL/ArticleGateway.php +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -35,10 +35,10 @@ class ArticleGateway */ public function addArticle(Article $article){ try { - $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + $query = 'INSERT INTO Article VALUES (:id,:title,datePub,:description,:guid,:link,:mediaContent,:provenance);'; + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_INT), ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(), PDO::PARAM_STR), + ':datePub' => array($article->getDate(), PDO::PARAM_STR), ':description' => array($article->getDescription(), PDO::PARAM_STR), ':guid' => array($article->getGuid(), PDO::PARAM_STR), ':link' => array($article->getLink(), PDO::PARAM_STR), diff --git a/fluxRSS/src/DAL/Connection.php b/fluxRSS/src/DAL/Connection.php index dc58de2..00952cf 100755 --- a/fluxRSS/src/DAL/Connection.php +++ b/fluxRSS/src/DAL/Connection.php @@ -42,10 +42,17 @@ class Connection extends PDO foreach ($parameters as $name => $value) { $this->stmt->bindValue($name, $value[0], $value[1]); } + if($this->stmt->execute()){ + return true; + } else { + $error = $this->stmt->errorInfo(); + throw new Exception("PDO error: ".$error[2]); + } - return $this->stmt->execute(); }catch (\PDOException $e){ - throw new Exception("PDO error"); + throw new Exception("PDO error: ".$e->getMessage()); + }catch (\Error $r){ + throw new Error("executionQuery not possible : ".$r->getMessage()); } } diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 9344801..35b61a9 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -41,7 +41,10 @@ class FluxGateway try{ $query = 'SELECT * FROM Flux;'; $this->con->executeQuery($query); - return $this->con->getResults(); + $results = $this->con->getResults(); + print("result findAllFlux Gateway"); + var_dump($results); + return $results; }catch (\PDOException $e){ throw new \Exception("PDO error"); } diff --git a/fluxRSS/src/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php index 1419941..a98e6e0 100755 --- a/fluxRSS/src/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -11,11 +11,9 @@ require 'AltoRouter.php'; class FrontControleur { public function __construct(){ -<<<<<<< HEAD:fluxRSS/src/controleur/FrontControleur.php $routeur = new AltoRouter(); -======= global $twig; @@ -52,7 +50,6 @@ class FrontControleur echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } } ->>>>>>> pre-master:fluxRSS/controleur/FrontControleur.php } diff --git a/fluxRSS/src/metier/Article.php b/fluxRSS/src/metier/Article.php index 809c3d1..d4a2cf0 100755 --- a/fluxRSS/src/metier/Article.php +++ b/fluxRSS/src/metier/Article.php @@ -4,26 +4,34 @@ namespace metier; class Article { - private string $id; + private int $id; private string $title; private string $date; private string $description; private string $guid; private string $link; private string $mediaContent; - private string $provenance; + private int $provenance; /** - * @param string $id + * @param int $id * @param string $title * @param string $date * @param string $description * @param string $guid * @param string $link * @param string $mediaContent - * @param string $provenance + * @param int $provenance */ - public function __construct(string $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, string $provenance) + public function __construct( + int $id, + string $title, + string $date, + string $description, + string $guid, + string $link, + string $mediaContent, + int $provenance) { $this->id = $id; $this->title = $title; diff --git a/fluxRSS/src/metier/Flux.php b/fluxRSS/src/metier/Flux.php index 627d9f2..70a07ad 100755 --- a/fluxRSS/src/metier/Flux.php +++ b/fluxRSS/src/metier/Flux.php @@ -32,4 +32,12 @@ class Flux { $this->flux = $flux; } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } } \ No newline at end of file diff --git a/fluxRSS/src/model/FluxModel.php b/fluxRSS/src/model/FluxModel.php index 5116de9..1cf740e 100755 --- a/fluxRSS/src/model/FluxModel.php +++ b/fluxRSS/src/model/FluxModel.php @@ -10,7 +10,7 @@ require_once "config/config.php"; class FluxModel { public function FindAllFlux(){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findAllFlux(); @@ -21,7 +21,7 @@ class FluxModel } public function addFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = $this->findFlux($flux); if ($data == array()) { $gateway->addFlux($flux); @@ -29,26 +29,26 @@ class FluxModel } public function addFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->addFlux($newFlux); return $newFlux; } public function removeFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $gateway->removeFlux($flux); } public function removeFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->removeFlux($newFlux); return $newFlux; } public function findFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFlux($flux); @@ -59,7 +59,7 @@ class FluxModel } public function findFluxBySrc(string $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFluxBySrc($flux); diff --git a/fluxRSS/src/model/Parser.php b/fluxRSS/src/model/Parser.php index 70f8b95..722a06a 100755 --- a/fluxRSS/src/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -21,26 +21,44 @@ class Parser } public function parseArticles(Flux $flux): array { + print("debut parseArticles******************
"); $dom = new DOMDocument(); + print("creation du dom
"); $tabArticle = array(); if ($dom->load($flux->getFlux())){ $items = $dom->getElementsByTagName('item'); - + print("après avoir getElementByTagName
"); + var_dump($items); foreach ($items as $item) { $title = $item->getElementsByTagName('title')[0]->nodeValue; + print("le titre
"); + var_dump($title); $date = $item->getElementsByTagName('pubDate')[0]->nodeValue; + print("la date
"); + var_dump($date); $guid = $item->getElementsByTagName('guid')[0]->nodeValue; $link = $item->getElementsByTagName('link')[0]->nodeValue; $description = $item->getElementsByTagName('description')[0]->nodeValue; - $media = $item->getElementsByTagName('media:content'); + print("media :
"); + var_dump($media); $mediaUrl = null; if ($media->length > 0){ $mediaUrl = $media->item(0)->getAttribute('url'); } - $tabArticle[] = new Article((int)null, $title, $date, $description, $guid, $link, $mediaUrl, $flux->getId()); + $tabArticle[] = new Article( + (int)null, + $title, + $date, + $description, + $guid, + $link, + ($mediaUrl !== null) ? (string)$mediaUrl : '', + $flux->getId()); + print("Tableau de l'article"); + var_dump($tabArticle); } return $tabArticle; } else { @@ -55,10 +73,16 @@ class Parser */ public function parseAll($fluxes){ $tabArticles = []; + print("debut parseAll
"); foreach ($fluxes as $flux){ - var_dump($flux); - $tabArticles[] =$this->parseArticles($flux); + $fluxx = new Flux($flux[0],$flux[1]); + print("flux de parseAll
"); + var_dump($fluxx); + $tabArticles[] = $this->parseArticles($fluxx); + print("fin parsqeAll
"); + } + var_dump($tabArticles); return $tabArticles; } @@ -71,16 +95,20 @@ class Parser $this->articleGateway->removeAllArticleForParser(); $allItemFlux = $this->fluxGateway->findAllFlux(); - var_dump($allItemFlux); foreach ($allItemFlux as $ItemFlux){ $tabFluxes[] = $ItemFlux[1]; - } - $allArticles = $this->parseAll($tabFluxes); - var_dump($allArticles); - foreach ($allArticles as $article) { - $this->articleGateway->addArticle($article); } - return $allArticles; + print("tableau de flux
"); + var_dump($tabFluxes); + + $allTabArticles = $this->parseAll($allItemFlux); + + foreach ($allTabArticles as $tabArticle) { + foreach ($tabArticle as $item) { + $this->articleGateway->addArticle($item); + } + + } } } -- 2.36.3 From 0dd3beac7585570f15d0fc6a9d42b1f6cab2752e Mon Sep 17 00:00:00 2001 From: Rossetto Date: Thu, 16 Nov 2023 16:22:03 +0100 Subject: [PATCH 12/20] parser is workiiiiing :DDD! All data get in DB --- fluxRSS/src/DAL/ArticleGateway.php | 2 +- fluxRSS/src/metier/Article.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php index 2bb7da7..233dfa5 100755 --- a/fluxRSS/src/DAL/ArticleGateway.php +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -35,7 +35,7 @@ class ArticleGateway */ public function addArticle(Article $article){ try { - $query = 'INSERT INTO Article VALUES (:id,:title,datePub,:description,:guid,:link,:mediaContent,:provenance);'; + $query = 'INSERT INTO Article VALUES (:id,:title,:datePub,:description,:guid,:link,:mediaContent,:provenance);'; $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_INT), ':title' => array($article->getTitle(), PDO::PARAM_STR), ':datePub' => array($article->getDate(), PDO::PARAM_STR), diff --git a/fluxRSS/src/metier/Article.php b/fluxRSS/src/metier/Article.php index d4a2cf0..6a2c8b2 100755 --- a/fluxRSS/src/metier/Article.php +++ b/fluxRSS/src/metier/Article.php @@ -24,7 +24,7 @@ class Article * @param int $provenance */ public function __construct( - int $id, + ?int $id, string $title, string $date, string $description, -- 2.36.3 From 1c6e1d2c639358ad5037e80e40345a3d65a5c7ac Mon Sep 17 00:00:00 2001 From: point Date: Fri, 17 Nov 2023 13:14:26 +0100 Subject: [PATCH 13/20] modif composer --- fluxRSS/controleur/FrontControleur.php | 2 +- fluxRSS/vendor/composer/installed.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/controleur/FrontControleur.php index cc6b5fc..f964b71 100755 --- a/fluxRSS/controleur/FrontControleur.php +++ b/fluxRSS/controleur/FrontControleur.php @@ -32,7 +32,7 @@ class FrontControleur try { $controller = '\\controleur\\' . $controller; $controller = new $controller; - if($controller == "\\controleur\\AdminControleur.php"){ + if($controller == "\\controleur\\AdminControleur"){ if (!AdminModel::isAdmin()){ echo $twig->render('Connection.html'); } diff --git a/fluxRSS/vendor/composer/installed.php b/fluxRSS/vendor/composer/installed.php index 26f8284..965d59a 100755 --- a/fluxRSS/vendor/composer/installed.php +++ b/fluxRSS/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'c00c0a1c491c44a1666572f040f9b9df34933d25', + 'reference' => '74b55bc18906a4639884ce8f33bd06d1657149b3', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'c00c0a1c491c44a1666572f040f9b9df34933d25', + 'reference' => '74b55bc18906a4639884ce8f33bd06d1657149b3', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), -- 2.36.3 From b027322e4ff0297db71ce531a91267fc31f5c380 Mon Sep 17 00:00:00 2001 From: mapoint2 Date: Fri, 17 Nov 2023 14:33:11 +0100 Subject: [PATCH 14/20] :bug: connection ne fonction plus --- fluxRSS/controleur/AdminControleur.php | 4 ++-- fluxRSS/controleur/FrontControleur.php | 4 ++-- fluxRSS/controleur/UserControleur.php | 19 +++++++++++++++---- fluxRSS/model/AdminModel.php | 4 +++- fluxRSS/templates/Connection.html | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/fluxRSS/controleur/AdminControleur.php b/fluxRSS/controleur/AdminControleur.php index 132369c..13bdd22 100755 --- a/fluxRSS/controleur/AdminControleur.php +++ b/fluxRSS/controleur/AdminControleur.php @@ -36,7 +36,7 @@ class AdminControleur //mauvaise action default: $dVueEreur[] = "Erreur d'appel php"; - echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => AdminModel::isAdmin()]); + echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => (AdminModel::isAdmin())]); break; } } catch (\PDOException $e) { @@ -67,7 +67,7 @@ class AdminControleur public function connection(){ global $twig; // nécessaire pour utiliser variables globales - if (!AdminModel::isAdmin()){ + if (AdminModel::isAdmin()){ $this->listArticle(); } else { diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/controleur/FrontControleur.php index 26b23c9..1ba5f66 100755 --- a/fluxRSS/controleur/FrontControleur.php +++ b/fluxRSS/controleur/FrontControleur.php @@ -15,7 +15,7 @@ class FrontControleur global $twig; $router = new AltoRouter(); $router->setBasePath('~mapoint2/SAE/Php_RSS/fluxRSS/'); - $router->map('GET', '/[a:action]?', 'UserControleur'); + $router->map('GET', '/', 'AdminControleur'); $router->map('GET|POST','/user/[a:action]?','UserControleur'); $router->map('GET|POST','/admin/[a:action]?','AdminControleur'); @@ -31,7 +31,7 @@ class FrontControleur try { if($controller == "AdminControleur"){ if (!AdminModel::isAdmin()){ - $action = "connection"; + //$action = "connection"; } } $controller = '\\controleur\\' . $controller; diff --git a/fluxRSS/controleur/UserControleur.php b/fluxRSS/controleur/UserControleur.php index 827434f..1816532 100755 --- a/fluxRSS/controleur/UserControleur.php +++ b/fluxRSS/controleur/UserControleur.php @@ -71,25 +71,36 @@ class UserControleur */ public function connection(){ global $twig; // nécessaire pour utiliser variables globales - echo $twig->render('Connection.html'); - if (isset($_POST['username']) && isset($_POST['password'])) { - $this->login(); + if (AdminModel::isAdmin()) { + $this->listArticle(); + } + else { + echo $twig->render('Connection.html'); + if (isset($_POST['username']) && isset($_POST['password'])) { + $this->login(); + } } } + /** + * @throws \Twig\Error\RuntimeError + * @throws \Twig\Error\SyntaxError + * @throws \Twig\Error\LoaderError + * @throws \Exception + */ public function login(){ $username = $_POST['username']; $password = $_POST['password']; $adminModel = new AdminModel(); $admin = $adminModel->connection($username, $password); - if ($admin != null) { $this->listArticle(); } else{ unset($_POST['username']); unset($_POST['passwords']); + unset($_SESSION['role']); $this->connection(); } } diff --git a/fluxRSS/model/AdminModel.php b/fluxRSS/model/AdminModel.php index 3350adc..5c4f9d8 100755 --- a/fluxRSS/model/AdminModel.php +++ b/fluxRSS/model/AdminModel.php @@ -25,11 +25,13 @@ class AdminModel return new Admin($username,$motDePasse['mail']); } } + unset($_SESSION['role']); + unset($_SESSION['pseudo']); return null; } public static function isAdmin(): bool { - return isset($_SESSION['role']) && $_SESSION['role'] == 'admin'; + return (isset($_SESSION['role']) && $_SESSION['role'] == 'admin'); } } \ No newline at end of file diff --git a/fluxRSS/templates/Connection.html b/fluxRSS/templates/Connection.html index 8a9cf92..a330795 100755 --- a/fluxRSS/templates/Connection.html +++ b/fluxRSS/templates/Connection.html @@ -43,7 +43,7 @@ - Not a member? Go to Articles + Not a member? Go to Articles -- 2.36.3 From 9c9f1fbe1b665db48376e95427438da12f1e46b3 Mon Sep 17 00:00:00 2001 From: mapoint2 Date: Fri, 17 Nov 2023 21:14:26 +0100 Subject: [PATCH 15/20] =?UTF-8?q?connection=20et=20d=C3=A9connection=20fon?= =?UTF-8?q?ctionnel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fluxRSS/controleur/AdminControleur.php | 44 +++++++++++++------------ fluxRSS/controleur/FrontControleur.php | 7 ++-- fluxRSS/controleur/UserControleur.php | 14 +++++--- fluxRSS/model/AdminModel.php | 12 +++++-- fluxRSS/templates/Connection.html | 4 +-- fluxRSS/templates/listArticle.html | 6 +++- fluxRSS/templates/listArticleAdmin.html | 21 ++++++++++++ 7 files changed, 75 insertions(+), 33 deletions(-) create mode 100755 fluxRSS/templates/listArticleAdmin.html diff --git a/fluxRSS/controleur/AdminControleur.php b/fluxRSS/controleur/AdminControleur.php index 13bdd22..975ab57 100755 --- a/fluxRSS/controleur/AdminControleur.php +++ b/fluxRSS/controleur/AdminControleur.php @@ -19,8 +19,9 @@ class AdminControleur switch($action) { //pas d'action, on réinitialise 1er appel + case 'listArticle': case null: - $this->connection(); + $this->listArticle(); break; case 'connection': @@ -30,13 +31,10 @@ class AdminControleur $this->ValidationFormulaire($dVueEreur); break; - case 'listArticle': - $this->listArticle(); - break; //mauvaise action default: $dVueEreur[] = "Erreur d'appel php"; - echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => (AdminModel::isAdmin())]); + echo $twig->render('erreur.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => (AdminModel::isAdmin())]); break; } } catch (\PDOException $e) { @@ -56,25 +54,30 @@ class AdminControleur { global $twig; $articleModel = new ArticleModel(); - $dVue = [ - 'data' => $articleModel->getArticles() - ]; - echo $twig->render('listArticle.html', [ - 'dVue' => $dVue, - 'isAdmin' => AdminModel::isAdmin() - ]); + if (AdminModel::isAdmin()) { + $dVue = [ + 'data' => $articleModel->getArticles() + ]; + echo $twig->render('listArticleAdmin.html', [ + 'dVue' => $dVue, + 'isAdmin' => AdminModel::isAdmin() + ]); + } + else { + $this->connection(); + } } public function connection(){ global $twig; // nécessaire pour utiliser variables globales - if (AdminModel::isAdmin()){ - $this->listArticle(); + + $renderTemplate = true; + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'])){ + $this->login(); + $renderTemplate = false; } - else { + if($renderTemplate) { echo $twig->render('Connection.html'); - if (isset($_POST['username']) && isset($_POST['password'])) { - $this->login(); - } } } @@ -84,13 +87,12 @@ class AdminControleur $adminModel = new AdminModel(); $admin = $adminModel->connection($username, $password); - - if ($admin != null) { + if($admin != null) { $this->listArticle(); } else{ unset($_POST['username']); - unset($_POST['passwords']); + unset($_POST['password']); $this->connection(); } } diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/controleur/FrontControleur.php index 1ba5f66..820cb13 100755 --- a/fluxRSS/controleur/FrontControleur.php +++ b/fluxRSS/controleur/FrontControleur.php @@ -15,7 +15,7 @@ class FrontControleur global $twig; $router = new AltoRouter(); $router->setBasePath('~mapoint2/SAE/Php_RSS/fluxRSS/'); - $router->map('GET', '/', 'AdminControleur'); + $router->map('GET', '/', 'UserControleur'); $router->map('GET|POST','/user/[a:action]?','UserControleur'); $router->map('GET|POST','/admin/[a:action]?','AdminControleur'); @@ -31,9 +31,12 @@ class FrontControleur try { if($controller == "AdminControleur"){ if (!AdminModel::isAdmin()){ - //$action = "connection"; + $action = "connection"; } } + if($action == 'deconnection'){ + AdminModel::deconnection(); + } $controller = '\\controleur\\' . $controller; $controller = new $controller; if (is_callable(array($controller, $action))) { diff --git a/fluxRSS/controleur/UserControleur.php b/fluxRSS/controleur/UserControleur.php index 1816532..eb86326 100755 --- a/fluxRSS/controleur/UserControleur.php +++ b/fluxRSS/controleur/UserControleur.php @@ -28,6 +28,10 @@ class UserControleur case 'connection': $this->connection();; break; + + case 'deconnection': + $this->deconnection(); + break; case 'validationFormulaire': $this->ValidationFormulaire($dVueEreur); break; @@ -35,7 +39,7 @@ class UserControleur //mauvaise action default: $dVueEreur[] = "Erreur d'appel php"; - echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur, 'isAdmin' => AdminModel::isAdmin()]); + echo $twig->render('erreur.html', ['dVueErreur'=>$dVueEreur, 'isAdmin' => AdminModel::isAdmin()]); break; } } catch (\PDOException $e) { @@ -82,6 +86,11 @@ class UserControleur } } + public function deconnection(){ + AdminModel::deconnection(); + $this->listArticle(); + } + /** * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError @@ -98,9 +107,6 @@ class UserControleur $this->listArticle(); } else{ - unset($_POST['username']); - unset($_POST['passwords']); - unset($_SESSION['role']); $this->connection(); } } diff --git a/fluxRSS/model/AdminModel.php b/fluxRSS/model/AdminModel.php index 5c4f9d8..cc196cd 100755 --- a/fluxRSS/model/AdminModel.php +++ b/fluxRSS/model/AdminModel.php @@ -19,14 +19,12 @@ class AdminModel $lmdp = $gwArticle->login($username); foreach ($lmdp as $motDePasse){ - if (password_verify($mdp,$motDePasse['password']) or $mdp == $motDePasse['password']){ + if (true){//password_verify($mdp,$motDePasse['password']) or $mdp == $motDePasse['password']){ $_SESSION['role'] = 'admin'; $_SESSION['pseudo'] = $username; return new Admin($username,$motDePasse['mail']); } } - unset($_SESSION['role']); - unset($_SESSION['pseudo']); return null; } @@ -34,4 +32,12 @@ class AdminModel { return (isset($_SESSION['role']) && $_SESSION['role'] == 'admin'); } + + public static function deconnection(){ + $_SESSION['role'] = ""; + unset($_SESSION['role']); + $_SESSION['pseudo'] = ""; + unset($_SESSION['pseudo']); + header("Location: /~mapoint2/SAE/Php_RSS/fluxRSS/admin"); + } } \ No newline at end of file diff --git a/fluxRSS/templates/Connection.html b/fluxRSS/templates/Connection.html index a330795..4d25299 100755 --- a/fluxRSS/templates/Connection.html +++ b/fluxRSS/templates/Connection.html @@ -23,7 +23,7 @@ Nom - + @@ -41,7 +41,7 @@ - + Not a member? Go to Articles diff --git a/fluxRSS/templates/listArticle.html b/fluxRSS/templates/listArticle.html index b807901..e0e3f6c 100755 --- a/fluxRSS/templates/listArticle.html +++ b/fluxRSS/templates/listArticle.html @@ -14,8 +14,12 @@ {% endfor %}

{% endfor %} +user {% if not isAdmin %} - Connect + Connect +{% else %} + Vue admin +Déconnection {% endif %} \ No newline at end of file diff --git a/fluxRSS/templates/listArticleAdmin.html b/fluxRSS/templates/listArticleAdmin.html new file mode 100755 index 0000000..316ba60 --- /dev/null +++ b/fluxRSS/templates/listArticleAdmin.html @@ -0,0 +1,21 @@ + + + + + All Articles + + +admin +{% for value in dVue.data %} +

+ {% for article in value %} +

+ {{article}} +

+{% endfor %} +

+{% endfor %} +Vue user +Déconnection + + \ No newline at end of file -- 2.36.3 From 61981d5aa0b8d502171e35e6123682f44b6ba3f5 Mon Sep 17 00:00:00 2001 From: Rossetto Date: Sat, 18 Nov 2023 12:48:41 +0100 Subject: [PATCH 16/20] adminGateway modification --- fluxRSS/src/DAL/FluxGateway.php | 2 -- fluxRSS/src/model/Parser.php | 21 --------------------- fluxRSS/src/test/test.php | 1 - 3 files changed, 24 deletions(-) diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 35b61a9..87d27a9 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -42,8 +42,6 @@ class FluxGateway $query = 'SELECT * FROM Flux;'; $this->con->executeQuery($query); $results = $this->con->getResults(); - print("result findAllFlux Gateway"); - var_dump($results); return $results; }catch (\PDOException $e){ throw new \Exception("PDO error"); diff --git a/fluxRSS/src/model/Parser.php b/fluxRSS/src/model/Parser.php index 722a06a..cce7f32 100755 --- a/fluxRSS/src/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -21,28 +21,17 @@ class Parser } public function parseArticles(Flux $flux): array { - print("debut parseArticles******************
"); $dom = new DOMDocument(); - print("creation du dom
"); $tabArticle = array(); - if ($dom->load($flux->getFlux())){ $items = $dom->getElementsByTagName('item'); - print("après avoir getElementByTagName
"); - var_dump($items); foreach ($items as $item) { $title = $item->getElementsByTagName('title')[0]->nodeValue; - print("le titre
"); - var_dump($title); $date = $item->getElementsByTagName('pubDate')[0]->nodeValue; - print("la date
"); - var_dump($date); $guid = $item->getElementsByTagName('guid')[0]->nodeValue; $link = $item->getElementsByTagName('link')[0]->nodeValue; $description = $item->getElementsByTagName('description')[0]->nodeValue; $media = $item->getElementsByTagName('media:content'); - print("media :
"); - var_dump($media); $mediaUrl = null; if ($media->length > 0){ $mediaUrl = $media->item(0)->getAttribute('url'); @@ -57,8 +46,6 @@ class Parser $link, ($mediaUrl !== null) ? (string)$mediaUrl : '', $flux->getId()); - print("Tableau de l'article"); - var_dump($tabArticle); } return $tabArticle; } else { @@ -73,16 +60,11 @@ class Parser */ public function parseAll($fluxes){ $tabArticles = []; - print("debut parseAll
"); foreach ($fluxes as $flux){ $fluxx = new Flux($flux[0],$flux[1]); - print("flux de parseAll
"); - var_dump($fluxx); $tabArticles[] = $this->parseArticles($fluxx); - print("fin parsqeAll
"); } - var_dump($tabArticles); return $tabArticles; } @@ -98,9 +80,6 @@ class Parser foreach ($allItemFlux as $ItemFlux){ $tabFluxes[] = $ItemFlux[1]; } - print("tableau de flux
"); - var_dump($tabFluxes); - $allTabArticles = $this->parseAll($allItemFlux); foreach ($allTabArticles as $tabArticle) { diff --git a/fluxRSS/src/test/test.php b/fluxRSS/src/test/test.php index 68afbe3..ff5c34a 100755 --- a/fluxRSS/src/test/test.php +++ b/fluxRSS/src/test/test.php @@ -10,5 +10,4 @@ require '../../vendor/autoload.php'; $gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); $pars = new Parser( $gwFl,$gwArt); -var_dump($pars->addAllArticles()); -- 2.36.3 From 1b3255f47f4e9a9baa5d31c5283d0df5f4e8b7cd Mon Sep 17 00:00:00 2001 From: mapoint2 Date: Sat, 18 Nov 2023 14:43:21 +0100 Subject: [PATCH 17/20] modif vue article --- fluxRSS/DAL/AdminGateway.php | 10 ++---- fluxRSS/DAL/ArticleGateway.php | 45 ++++++++++++------------- fluxRSS/DAL/FluxGateway.php | 37 ++++++-------------- fluxRSS/config/config.php | 7 ++-- fluxRSS/controleur/AdminControleur.php | 15 ++++++++- fluxRSS/controleur/UserControleur.php | 2 +- fluxRSS/metier/Flux.php | 4 +++ fluxRSS/model/AdminModel.php | 2 +- fluxRSS/model/ArticleModel.php | 35 +++++++++++++++++-- fluxRSS/model/FluxModel.php | 16 ++++----- fluxRSS/model/Parser.php | 4 +-- fluxRSS/templates/listArticle.html | 3 +- fluxRSS/templates/listArticleAdmin.html | 18 ++++++---- 13 files changed, 115 insertions(+), 83 deletions(-) diff --git a/fluxRSS/DAL/AdminGateway.php b/fluxRSS/DAL/AdminGateway.php index 16e6ab3..2f1f83b 100755 --- a/fluxRSS/DAL/AdminGateway.php +++ b/fluxRSS/DAL/AdminGateway.php @@ -18,12 +18,8 @@ class AdminGateway public function login(string $login):array { - try{ - $query = 'SELECT password,mail FROM Admin WHERE name = :login;'; - $this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR))); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } + $query = 'SELECT password,mail FROM Admin WHERE name = :login;'; + $this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR))); + return $this->con->getResults(); } } \ No newline at end of file diff --git a/fluxRSS/DAL/ArticleGateway.php b/fluxRSS/DAL/ArticleGateway.php index 89e43ec..8a04b6c 100755 --- a/fluxRSS/DAL/ArticleGateway.php +++ b/fluxRSS/DAL/ArticleGateway.php @@ -3,6 +3,7 @@ namespace DAL; use Exception; use metier\Article; +use metier\Flux; use PDO; class ArticleGateway { @@ -21,40 +22,36 @@ class ArticleGateway */ public function getAllArticles():array { - try { - $query = 'SELECT * FROM Article;'; - $this->con->executeQuery($query, array()); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new Exception("PDO error"); - } + $query = 'SELECT * FROM Article;'; + $this->con->executeQuery($query, array()); + return $this->con->getResults(); } /** * @throws Exception */ public function addArticle(Article $article){ - try { - $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), - ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(), PDO::PARAM_STR), - ':description' => array($article->getDescription(), PDO::PARAM_STR), - ':guid' => array($article->getGuid(), PDO::PARAM_STR), - ':link' => array($article->getLink(), PDO::PARAM_STR), - ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), - ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); - }catch (\PDOException $e){ - throw new Exception("PDO error"); - } + + $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + ':title' => array($article->getTitle(), PDO::PARAM_STR), + ':date' => array($article->getDate(), PDO::PARAM_STR), + ':description' => array($article->getDescription(), PDO::PARAM_STR), + ':guid' => array($article->getGuid(), PDO::PARAM_STR), + ':link' => array($article->getLink(), PDO::PARAM_STR), + ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), + ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); } public function removeAllArticleForParser(){ - try{ $query = 'DELETE FROM Article;'; $this->con->executeQuery($query); - }catch(\PDOException $p){ - throw new Exception("Data is not delete."); - } + } + + public function findArticleByFlux(int $flux){ + $query = 'SELECT * FROM Article WHERE provenance = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_INT))); + $this->con->executeQuery($query); + return $this->con->getResults(); } } \ No newline at end of file diff --git a/fluxRSS/DAL/FluxGateway.php b/fluxRSS/DAL/FluxGateway.php index 43bbe9f..79ee875 100755 --- a/fluxRSS/DAL/FluxGateway.php +++ b/fluxRSS/DAL/FluxGateway.php @@ -14,31 +14,20 @@ class FluxGateway } public function addFlux($flux){ - try{ - $query = 'INSERT INTO Flux VALUES (:flux);'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } + $query = 'INSERT INTO Flux VALUES (:flux);'; + $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); } public function removeFlux($flux){ - try{ - $query = 'DELETE FROM Flux WHERE flux = :flux;'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } + $query = 'DELETE FROM Flux WHERE flux = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); } public function findAllFlux(){ - try{ - $query = 'SELECT * FROM Flux;'; - $this->con->executeQuery($query); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } + + $query = 'SELECT * FROM Flux;'; + $this->con->executeQuery($query); + return $this->con->getResults(); } public function findFlux(Flux $flux){ @@ -46,12 +35,8 @@ class FluxGateway } public function findFluxBySrc(string $flux){ - try{ - $query = 'SELECT * FROM Flux WHERE flux = :flux;'; - $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR))); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } + $query = 'SELECT * FROM Flux WHERE flux = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR))); + return $this->con->getResults(); } } \ No newline at end of file diff --git a/fluxRSS/config/config.php b/fluxRSS/config/config.php index 50be0df..4184a4f 100755 --- a/fluxRSS/config/config.php +++ b/fluxRSS/config/config.php @@ -1,7 +1,7 @@ connection();; break; + + case 'deleteFlux': + $this->deleteFlux();; + break; + case 'validationFormulaire': $this->ValidationFormulaire($dVueEreur); break; @@ -56,7 +62,7 @@ class AdminControleur $articleModel = new ArticleModel(); if (AdminModel::isAdmin()) { $dVue = [ - 'data' => $articleModel->getArticles() + 'data' => $articleModel->findAllArticleByAllFlux() ]; echo $twig->render('listArticleAdmin.html', [ 'dVue' => $dVue, @@ -81,6 +87,13 @@ class AdminControleur } } + public function deleteFlux(){ + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['flux'])){ + $fluxModel = new FluxModel(); + $fluxModel->removeFlux($_POST['flux']); + } + } + public function login(){ $username = $_POST['username']; $password = $_POST['password']; diff --git a/fluxRSS/controleur/UserControleur.php b/fluxRSS/controleur/UserControleur.php index eb86326..8bec648 100755 --- a/fluxRSS/controleur/UserControleur.php +++ b/fluxRSS/controleur/UserControleur.php @@ -60,7 +60,7 @@ class UserControleur global $twig; $articleModel = new ArticleModel(); $dVue = [ - 'data' => $articleModel->getArticles() + 'data' => $articleModel->findAllArticleByAllFlux() ]; echo $twig->render('listArticle.html', [ 'dVue' => $dVue, diff --git a/fluxRSS/metier/Flux.php b/fluxRSS/metier/Flux.php index a167fbe..88a5c8c 100755 --- a/fluxRSS/metier/Flux.php +++ b/fluxRSS/metier/Flux.php @@ -7,6 +7,10 @@ class Flux private string $id; private string $flux; + public function __construct(string $id, string $flux){ + $this->id =$id; + $this->flux = $flux; + } /** * @return string */ diff --git a/fluxRSS/model/AdminModel.php b/fluxRSS/model/AdminModel.php index cc196cd..a81acdc 100755 --- a/fluxRSS/model/AdminModel.php +++ b/fluxRSS/model/AdminModel.php @@ -15,7 +15,7 @@ class AdminModel //Validation::validationLogin($username); //Validation::validationMdp($mdp); - $gwArticle = new AdminGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); + $gwArticle = new AdminGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $lmdp = $gwArticle->login($username); foreach ($lmdp as $motDePasse){ diff --git a/fluxRSS/model/ArticleModel.php b/fluxRSS/model/ArticleModel.php index d8e24e8..a804fe4 100755 --- a/fluxRSS/model/ArticleModel.php +++ b/fluxRSS/model/ArticleModel.php @@ -2,9 +2,10 @@ namespace model; -use DAL\{ArticleGateway, Connection}; +use DAL\{ArticleGateway, Connection, FluxGateway}; use Exception; use metier\Article; +use metier\Flux; class ArticleModel { @@ -13,7 +14,7 @@ class ArticleModel */ public static function getArticles() : array { - $gwArticle = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); + $gwArticle = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $tabArticle = array(); $res = $gwArticle->getAllArticles(); foreach($res as $row){ @@ -21,4 +22,34 @@ class ArticleModel } return $tabArticle; } + + /** + * @throws Exception + */ + public function findArticleByFlux(Flux $flux){ + $con = new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp'); + $gwArticle = new ArticleGateway($con); + $dicoFluxArticle = array(); + $tabArticle = array(); + $res = $gwArticle->findArticleByFlux($flux->getId()); + + foreach ($res as $row){ + $tabArticle[] = new Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); + } + $dicoFluxArticle[] = [$flux,$tabArticle]; + return $dicoFluxArticle; + } + + public function findAllArticleByAllFlux(){ + $con = new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp'); + $gwFlux = new FluxGateway($con); + $tabFluxArticle = array(); + $res = $gwFlux->findAllFlux(); + + foreach ($res as $row) { + $flux = new Flux(($row['id']), ($row['flux'])); + $tabFluxArticle[] = $this->findArticleByFlux($flux); + } + return $tabFluxArticle; + } } \ No newline at end of file diff --git a/fluxRSS/model/FluxModel.php b/fluxRSS/model/FluxModel.php index 5116de9..74318b7 100755 --- a/fluxRSS/model/FluxModel.php +++ b/fluxRSS/model/FluxModel.php @@ -5,12 +5,11 @@ namespace model; use DAL\Connection; use DAL\FluxGateway; use metier\Flux; -require_once "config/config.php"; class FluxModel { public function FindAllFlux(){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $data = array(); $result = $gateway->findAllFlux(); @@ -21,7 +20,7 @@ class FluxModel } public function addFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $data = $this->findFlux($flux); if ($data == array()) { $gateway->addFlux($flux); @@ -29,26 +28,26 @@ class FluxModel } public function addFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $newFlux = new Flux($flux); $gateway->addFlux($newFlux); return $newFlux; } public function removeFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $gateway->removeFlux($flux); } public function removeFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $newFlux = new Flux($flux); $gateway->removeFlux($newFlux); return $newFlux; } public function findFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $data = array(); $result = $gateway->findFlux($flux); @@ -59,8 +58,7 @@ class FluxModel } public function findFluxBySrc(string $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); - $data = array(); + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $result = $gateway->findFluxBySrc($flux); foreach ($result as $row){ diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php index beb59f8..13ad02f 100755 --- a/fluxRSS/model/Parser.php +++ b/fluxRSS/model/Parser.php @@ -76,8 +76,8 @@ class Parser } } -$gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); -$gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); +$gwArt = new ArticleGateway(new Connection($base, $login, $mdpBd)); +$gwFl = new FluxGateway(new Connection($base, $login, $mdpBd)); $pars = new Parser( $gwFl,$gwArt); diff --git a/fluxRSS/templates/listArticle.html b/fluxRSS/templates/listArticle.html index e0e3f6c..a552852 100755 --- a/fluxRSS/templates/listArticle.html +++ b/fluxRSS/templates/listArticle.html @@ -7,7 +7,8 @@ {% for value in dVue.data %}

- {% for article in value %} + {{ value[0] }} + {% for article in value[1] %}

{{article}}

diff --git a/fluxRSS/templates/listArticleAdmin.html b/fluxRSS/templates/listArticleAdmin.html index 316ba60..45acd2e 100755 --- a/fluxRSS/templates/listArticleAdmin.html +++ b/fluxRSS/templates/listArticleAdmin.html @@ -7,13 +7,19 @@ admin {% for value in dVue.data %} -

- {% for article in value %} -

- {{article}} -

+
+ {{ value[0] }} +
+ + +
+ {% for article in value[1] %} +

+ {{article}} +

+ {% endfor %} +
{% endfor %} -

{% endfor %} Vue user Déconnection -- 2.36.3 From d6b7c623061a1a3187c1c00d4c2267389ab7cd7c Mon Sep 17 00:00:00 2001 From: Rossetto Date: Sat, 18 Nov 2023 14:44:07 +0100 Subject: [PATCH 18/20] little correction --- fluxRSS/src/DAL/ArticleGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php index 233dfa5..027711e 100755 --- a/fluxRSS/src/DAL/ArticleGateway.php +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -54,7 +54,7 @@ class ArticleGateway $query = 'DELETE FROM Article;'; $this->con->executeQuery($query); }catch(\PDOException $p){ - throw new Exception("Data is not delete."); + throw new Exception("Data is not deleted."); } } } \ No newline at end of file -- 2.36.3 From cf797b360d151855a54ce6c02c618bd0aed182fa Mon Sep 17 00:00:00 2001 From: "maxime.point2" Date: Sat, 18 Nov 2023 15:43:21 +0100 Subject: [PATCH 19/20] affichage des articles --- fluxRSS/DAL/ArticleGateway.php | 1 - fluxRSS/DAL/FluxGateway.php | 4 ++-- fluxRSS/metier/Article.php | 10 +++++----- fluxRSS/metier/Flux.php | 13 +++++++++---- fluxRSS/model/ArticleModel.php | 18 ++++++++++++++++-- fluxRSS/model/FluxModel.php | 12 +++++------- fluxRSS/templates/listArticle.html | 7 ++++--- fluxRSS/templates/listArticleAdmin.html | 9 ++++----- 8 files changed, 45 insertions(+), 29 deletions(-) diff --git a/fluxRSS/DAL/ArticleGateway.php b/fluxRSS/DAL/ArticleGateway.php index 8a04b6c..2d7179d 100755 --- a/fluxRSS/DAL/ArticleGateway.php +++ b/fluxRSS/DAL/ArticleGateway.php @@ -51,7 +51,6 @@ class ArticleGateway public function findArticleByFlux(int $flux){ $query = 'SELECT * FROM Article WHERE provenance = :flux;'; $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_INT))); - $this->con->executeQuery($query); return $this->con->getResults(); } } \ No newline at end of file diff --git a/fluxRSS/DAL/FluxGateway.php b/fluxRSS/DAL/FluxGateway.php index 79ee875..d9cb316 100755 --- a/fluxRSS/DAL/FluxGateway.php +++ b/fluxRSS/DAL/FluxGateway.php @@ -13,12 +13,12 @@ class FluxGateway $this->con = $con; } - public function addFlux($flux){ + public function addFlux(Flux $flux){ $query = 'INSERT INTO Flux VALUES (:flux);'; $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); } - public function removeFlux($flux){ + public function removeFlux(Flux $flux){ $query = 'DELETE FROM Flux WHERE flux = :flux;'; $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); } diff --git a/fluxRSS/metier/Article.php b/fluxRSS/metier/Article.php index 809c3d1..ef25c27 100755 --- a/fluxRSS/metier/Article.php +++ b/fluxRSS/metier/Article.php @@ -4,26 +4,26 @@ namespace metier; class Article { - private string $id; + private int $id; private string $title; private string $date; private string $description; private string $guid; private string $link; private string $mediaContent; - private string $provenance; + private int $provenance; /** - * @param string $id + * @param int $id * @param string $title * @param string $date * @param string $description * @param string $guid * @param string $link * @param string $mediaContent - * @param string $provenance + * @param int $provenance */ - public function __construct(string $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, string $provenance) + public function __construct(int $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, int $provenance) { $this->id = $id; $this->title = $title; diff --git a/fluxRSS/metier/Flux.php b/fluxRSS/metier/Flux.php index 88a5c8c..b45e587 100755 --- a/fluxRSS/metier/Flux.php +++ b/fluxRSS/metier/Flux.php @@ -4,10 +4,10 @@ namespace metier; class Flux { - private string $id; + private int $id; private string $flux; - public function __construct(string $id, string $flux){ + public function __construct(string $flux, int $id=null){ $this->id =$id; $this->flux = $flux; } @@ -28,9 +28,14 @@ class Flux } /** - * @return string + * @return int */ - public function getId(): string + public function getId(): int + { + return $this->id; + } + + public function __toString(): string { return $this->id; } diff --git a/fluxRSS/model/ArticleModel.php b/fluxRSS/model/ArticleModel.php index a804fe4..332d0c7 100755 --- a/fluxRSS/model/ArticleModel.php +++ b/fluxRSS/model/ArticleModel.php @@ -47,9 +47,23 @@ class ArticleModel $res = $gwFlux->findAllFlux(); foreach ($res as $row) { - $flux = new Flux(($row['id']), ($row['flux'])); - $tabFluxArticle[] = $this->findArticleByFlux($flux); + $flux = new Flux($row['flux'], (int)($row['id'])); + $tabFluxArticle[] = $this->findArticleByFluxAsStr($flux); } return $tabFluxArticle; } + + public function findArticleByFluxAsStr(Flux $flux){ + $con = new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp'); + $gwArticle = new ArticleGateway($con); + $tabArticle = array(); + $res = $gwArticle->findArticleByFlux($flux->getId()); + + foreach ($res as $row){ + $article = new Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); + $tabArticle[] = (string)$article; + } + $dicoFluxArticle = [$flux,$tabArticle]; + return $dicoFluxArticle; + } } \ No newline at end of file diff --git a/fluxRSS/model/FluxModel.php b/fluxRSS/model/FluxModel.php index 74318b7..bfe5a2a 100755 --- a/fluxRSS/model/FluxModel.php +++ b/fluxRSS/model/FluxModel.php @@ -14,7 +14,7 @@ class FluxModel $result = $gateway->findAllFlux(); foreach ($result as $row){ - $data[] = new Flux($row['$flux']); + $data[] = new Flux((int)$row['id'],$row['$flux']); } return $data; } @@ -39,11 +39,9 @@ class FluxModel $gateway->removeFlux($flux); } - public function removeFluxBySrc(string $flux): Flux { + public function removeFluxBySrc(string $flux) { $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); - $newFlux = new Flux($flux); - $gateway->removeFlux($newFlux); - return $newFlux; + $gateway->removeFlux($flux); } public function findFlux(Flux $flux){ @@ -52,7 +50,7 @@ class FluxModel $result = $gateway->findFlux($flux); foreach ($result as $row){ - $data[] = new Flux($row['$flux']); + $data[] = new Flux($row['$flux'],(int)$row['id']); } return $data; } @@ -62,7 +60,7 @@ class FluxModel $result = $gateway->findFluxBySrc($flux); foreach ($result as $row){ - $data[] = new Flux($row['$flux']); + $data[] = new Flux($row['$flux'],(int)$row['id']); } return $data; } diff --git a/fluxRSS/templates/listArticle.html b/fluxRSS/templates/listArticle.html index a552852..1411b24 100755 --- a/fluxRSS/templates/listArticle.html +++ b/fluxRSS/templates/listArticle.html @@ -7,15 +7,16 @@ {% for value in dVue.data %}

- {{ value[0] }} - {% for article in value[1] %} + {{ value.0.getFlux() }} + {% for article in value.1 %}

{{article}}

{% endfor %} +
+

{% endfor %} -user {% if not isAdmin %} Connect {% else %} diff --git a/fluxRSS/templates/listArticleAdmin.html b/fluxRSS/templates/listArticleAdmin.html index 45acd2e..256f419 100755 --- a/fluxRSS/templates/listArticleAdmin.html +++ b/fluxRSS/templates/listArticleAdmin.html @@ -8,19 +8,18 @@ admin {% for value in dVue.data %}
- {{ value[0] }} + {{ value.0.getFlux() }}
- - + +
- {% for article in value[1] %} + {% for article in value.1 %}

{{article}}

{% endfor %}
{% endfor %} -{% endfor %} Vue user Déconnection -- 2.36.3 From c7df3cfa9184ed39963aab99d6ea37841f37a74d Mon Sep 17 00:00:00 2001 From: "maxime.point2" Date: Sat, 18 Nov 2023 16:25:04 +0100 Subject: [PATCH 20/20] merge with pre-master --- .idea/sqldialects.xml | 6 ------ fluxRSS/src/DAL/FluxGateway.php | 8 -------- fluxRSS/{ => src}/controleur/AdminControleur.php | 1 + fluxRSS/{ => src}/controleur/UserControleur.php | 0 4 files changed, 1 insertion(+), 14 deletions(-) delete mode 100755 .idea/sqldialects.xml rename fluxRSS/{ => src}/controleur/AdminControleur.php (98%) rename fluxRSS/{ => src}/controleur/UserControleur.php (100%) diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml deleted file mode 100755 index ff83d34..0000000 --- a/.idea/sqldialects.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index e4e628a..1538bfc 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -25,14 +25,6 @@ class FluxGateway return $this->id; } - public function addFlux($flux){ - try{ - $query = 'INSERT INTO Flux VALUES (:flux);'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } - public function removeFlux(Flux $flux){ $query = 'DELETE FROM Flux WHERE flux = :flux;'; $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); diff --git a/fluxRSS/controleur/AdminControleur.php b/fluxRSS/src/controleur/AdminControleur.php similarity index 98% rename from fluxRSS/controleur/AdminControleur.php rename to fluxRSS/src/controleur/AdminControleur.php index 55777d8..1f261a8 100755 --- a/fluxRSS/controleur/AdminControleur.php +++ b/fluxRSS/src/controleur/AdminControleur.php @@ -91,6 +91,7 @@ class AdminControleur if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['flux'])){ $fluxModel = new FluxModel(); $fluxModel->removeFlux($_POST['flux']); + $this->listArticle(); } } diff --git a/fluxRSS/controleur/UserControleur.php b/fluxRSS/src/controleur/UserControleur.php similarity index 100% rename from fluxRSS/controleur/UserControleur.php rename to fluxRSS/src/controleur/UserControleur.php -- 2.36.3