controleur/page.php utilise maintenant correctement les chemins des pages.
This commit is contained in:
parent
cdf7a1090f
commit
0314c47a41
|
@ -4,7 +4,9 @@ require_once("config.php");
|
||||||
|
|
||||||
// Protocole : http://site/actualités/?nouveau=Le%20titre
|
// Protocole : http://site/actualités/?nouveau=Le%20titre
|
||||||
|
|
||||||
// TODO : Constructeur.
|
// Invariants de sécurité :
|
||||||
|
// Page::chemin ne contient jamais de chaîne '../' ou autres bizarreries des chemins de fichiers.
|
||||||
|
// Donc on peut concaténer Page::chemin à un chemin dans le système de fichiers et être sûr d'être dans un sous-dossier.
|
||||||
|
|
||||||
class Page {
|
class Page {
|
||||||
// article/prop_article
|
// article/prop_article
|
||||||
|
@ -20,26 +22,28 @@ class Page {
|
||||||
$this->chemin = $chemin;
|
$this->chemin = $chemin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renvoie le chemin de la page dans le système de fichiers
|
||||||
|
private function chemin_fs() {
|
||||||
|
return concaténer_chemin($config_chemin_base, $this->chemin);
|
||||||
|
}
|
||||||
|
|
||||||
public function liste_enfants() {
|
public function liste_enfants() {
|
||||||
$lst = scandir($this->chemin);
|
$lst = scandir($this->chemin_fs());
|
||||||
$lst_enfants = Array();
|
$lst_enfants = Array();
|
||||||
if ($lst !== false) {
|
if ($lst !== false) {
|
||||||
foreach ($lst as $k => $v) {
|
foreach ($lst as $k => $v) {
|
||||||
// Construire un objet Page pour chacun (code commun avec Page::enfant(nom)).
|
$lst_enfants[] = $this->enfant($v);
|
||||||
$lst_enfants[] = new Page($this->chemin . '/' . $v); // TODO : . '/' . n'est pas portable !
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $lst_enfants;
|
return $lst_enfants;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enfant($nom) {
|
public function enfant($nom) {
|
||||||
// Récupéere le sous-dossier "nom"
|
return new Page($this->chemin . '/' . $nom); // TODO
|
||||||
// Construire un objet Page (code commun avec Page::liste_enfants()).
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parent() {
|
public function parent() {
|
||||||
// Récupère le dossier parent
|
return new Page($this->chemin . '/..'); // TODO
|
||||||
// Construire un objet Page (code commun avec Page::enfant(nom)).
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nouveau($nom) {
|
public function nouveau($nom) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user