page.php (2204B)
1 <?php 2 3 class Page { 4 public $contenu = ""; 5 public $titre = ""; 6 public $sendfile_fichier = ""; 7 public $sendprop_chemin = ""; 8 public $sendprop_prop = ""; 9 public $redirect_destination = ""; 10 public $type = "page"; 11 12 public function __construct($a, $b, $type = "page") { 13 if ($type == "page") { 14 $this->set_page($a, $b); 15 } else if ($type == "sendfile") { 16 $this->set_sendfile($a); 17 } else if ($type == "sendprop") { 18 $this->set_sendprop($a, $b); 19 } else if ($type == "raw") { 20 $this->set_raw($a, $b); 21 } else if ($type == "redirect") { 22 $this->set_redirect($a, $b); 23 } 24 } 25 26 public function set_page($contenu, $titre) { 27 $this->contenu = $contenu; 28 $this->titre = $titre; 29 $this->type = "page"; 30 } 31 32 public function set_sendfile($fichier) { 33 $this->sendfile_fichier = $fichier; 34 $this->type = "sendfile"; 35 } 36 37 public function set_sendprop($chemin, $prop) { 38 $this->sendprop_chemin = $chemin; 39 $this->sendprop_prop = $prop; 40 $this->type = "sendprop"; 41 } 42 43 public function set_raw($données, $mime) { 44 $this->raw_données = $données; 45 $this->raw_mime = $mime; 46 $this->type = "raw"; 47 } 48 49 public function set_redirect($destination, $params = "") { 50 if (!is_string($destination)) $destination = $destination->get_url(); 51 $this->redirect_destination = $destination . $params; 52 $this->type = "redirect"; 53 } 54 55 public function envoyer() { 56 // Yeeeeeeeeeeeeeeeeeeeeeeha ! Et on envoie ! 57 if ($this->type == "page") { 58 echo Squelette::enrober($this); 59 } else if ($this->type == "sendfile") { 60 Système_fichiers::envoyer_fichier_directement($this->sendfile_fichier); 61 } else if ($this->type == "sendprop") { 62 Stockage::get_prop_sendfile($this->sendprop_chemin, $this->sendprop_prop); 63 } else if ($this->type == "raw") { 64 header("Content-Type: " . $this->raw_mime); 65 echo $this->raw_données; 66 } else if ($this->type == "redirect") { 67 header("Location: " . $this->redirect_destination); 68 /*echo "TODO : Redirection vers <a href=\"" 69 . $this->redirect_destination . "\">" 70 . $this->redirect_destination . "</a>";*/ 71 } 72 // TODO : else erreur 73 } 74 75 public static function is_page($obj) { 76 return is_object($obj) && get_class($obj) === __CLASS__; 77 } 78 } 79 80 ?>