diff --git a/controleur/chemin_page.php b/controleur/chemin_page.php new file mode 100644 index 0000000..5361665 --- /dev/null +++ b/controleur/chemin_page.php @@ -0,0 +1,42 @@ +chemin = CheminPage::nettoyer_chemin($chemin); + } + + public function get() { + return $this->chemin; + } + + public function enfant($nom) { + return $this->chemin . '/' . CheminPage::nettoyer_chemin($nom); + } + + public function parent() { + $slash = strrpos($this->chemin, '/'); + if ($slash !== false) { + return substr($this->chemin, 0, $slash); + } else { + return '/'; + } + } + + public static function nettoyer_chemin($chemin) { + // SECURITE : $chemin_nettoyé + // * Ne contient pas '\0' + // * Ne contient pas '../' + // * Ne contient pas de double occurence de '/' + // * Ni d'autres bizarreries des chemins de fichiers. + // * Ne contient pas _prop_ + // * Ne se termine pas par '/' + // * Commence par '/' + + // TODO + return $chemin; + } + +} \ No newline at end of file diff --git a/controleur/page.php b/controleur/page.php index ecd7fa7..3087239 100644 --- a/controleur/page.php +++ b/controleur/page.php @@ -1,57 +1,48 @@ chemin = nettoyer_chemin($chemin); - } - - // Nettoie un chemin de page pour qu'il respecte l'invariant de sécurité. - public static function nettoyer_chemin($chemin) { - return $chemin; + $this->chemin = new CheminPage($chemin); } // Renvoie le chemin de la page dans le système de fichiers private function chemin_fs() { - return concaténer_chemin_fs($config_chemin_base, $this->chemin); + global $config_chemin_base; + return concaténer_chemin_fs($config_chemin_base, $this->chemin->get()); } public function liste_enfants() { - $lst = scandir($this->chemin_fs()); - $lst_enfants = Array(); - if ($lst !== false) { - foreach ($lst as $k => $v) { - $lst_enfants[] = $this->enfant($v); - } + $scandir = scandir($this->chemin_fs()); + if ($scandir === false) { error_log("Impossible d'accéder à la liste des pages enfant de " . $this->chemin->get()); } + + $enfants = Array(); + foreach ($scandir as $k => $v) { + $enfants[] = $this->enfant($v); } - return $lst_enfants; + return $enfants; } public function enfant($nom) { - return new Page(nettoyer_chemin($this->chemin) . '/' . nettoyer_chemin($nom)); + return new Page($this->chemin->enfant($nom)); } public function parent() { - return new Page(nettoyer_chemin($this->chemin) . '/..'); // TODO + return new Page($this->chemin->parent()); } public function nouveau($nom) { @@ -78,11 +69,11 @@ class Page { public function url() { // calculer l'url de cette page en fonction de son chemin et de l'url de base global $config_url_base; - return $config_url_base . $this->chemin; + return $config_url_base . $this->chemin->get(); } public function vue() { - return "Aucune vue pour «" . $this->chemin . "» ."; + return "Aucune vue pour «" . $this->chemin->get() . "» ."; } }