Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /* Created by Sirius / James Walston, All rights are reserved.
- Failure to comply to the NOTICE of this and/or claim of own
- written code is by of losing all legitimacy of the script itself. */
- include "errors.php";
- interface webclass {
- public function __construct($html_file);
- public function append_header($tag, $value);
- public function delete_header($tag);
- public function commit();
- }
- final class WebPage implements webclass {
- public $page;
- public $page_headers;
- // Initializes construction of the class
- public function __construct($html_file) {
- if(file_exists($_SERVER["DOCUMENT_ROOT"] . "/templates/{$html_file}")) {
- $this->page = file_get_contents($_SERVER["DOCUMENT_ROOT"] . "/templates/{$html_file}");
- $this->page_headers = [];
- }
- else die("The file {$html_file} does not exist.");
- }
- // Creates for allowable appending to headers list
- public function append_header($tag, $value) {
- if(!empty($this->page_headers[$tag])) {
- die("This tag already exists.");
- }
- else $this->page_headers[$tag] = $value;
- }
- // Deletes a tag in the headers list
- public function delete_header($tag) {
- if(!in_array($tag, $this->page_headers)) {
- die("This tag does not exist.");
- }
- else unset($this->page_headers[$tag]);
- }
- // Begins re-modifying the headers/tags for the page
- public function commit() {
- if(!empty($this->page_headers)) {
- foreach($this->page_headers as $header_tag => $value) {
- # Works as: str_replace(find text, change to this text, inside var);
- $this->page = str_replace(
- $header_tag,
- $value,
- $this->page
- );
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment