' ); define( 'DOMAIN', 'CoyoteTours.us' ); // class page { //Declare class properties private $db; //Declare HTML properties private $markupHead; private $markupBody; private $markupFoot; private $markup; //Declare page properties directly related to the markup of the dynamic template protected $id; protected $name; protected $title; protected $path; protected $parentId; protected $nLevel; protected $nLeft; protected $nRight; protected $keywords; protected $description; protected $type; protected $active; //Retrieve an array of columns from the database row associated with the top level of the URL path private function page_columns( $urlPath, $db ) { //Send query to the database for the row whose url_path column is the same as the URL path top-level $result = $db->query( 'select * from pages where url_path = "' . $db->real_escape_string( $urlPath ) . '" limit 1' ); //Display an error page when there is no matching record in the database if( $result->num_rows > 0 ) { //Create an object from the query result row $row = $result->fetch_object( ); //Define the page properties $this->id = $row->page_id; $this->name = $row->name; $this->title = $row->title; $this->path = $row->url_path; $this->parentId = $row->parent_id; $this->nLevel = $row->nlevel; $this->nLeft = $row->nleft; $this->nRight = $row->nright; $this->keywords = $row->meta_keywords; $this->description = $row->meta_description; $this->type = $row->type; $this->active = $row->active; } else { //Redirect to page not found and exit application header( 'Location: 404.txt' ); exit; } } //Determine the URL path top level by parsing the url_path query string variable private function path_toplevel( $urlPath ) { //Create an array from the folders of the URL path $folders = explode( '/', $urlPath ); //Returns top level of URL path, the last key in the array return( $folders[ ( count( $folders ) - 1 ) ] ); } // public function __construct( $urlPath, $db ) { //Define a reference to the database object $this->db = $db; //Determine the URL path's top level, the current page //$this->urlPath_topLevel = $this->path_toplevel( $urlPath ); //Create an associative array whose keys have the values of the columns belonging to the row associated with the top-level of the URL path $this->page_columns( $this->path_toplevel( $urlPath ), $this->db ); $this->markupHead = $this->markup_head( ); $this->markupBody = $this->markup_body( $this->type ); $this->markupFoot = $this->markup_foot( ); $this->markup = $this->markup_compile( ); } //Create the HTML for the page header private function markup_head( ) { // $markup = DOCTYPE . "\n"; $markup .= '' . "\n"; $markup .= ' ' . "\n"; $markup .= ' ' . $this->title . ' - ' . DOMAIN . '' . "\n"; $markup .= ' ' . "\n"; $markup .= ' ' . "\n"; $markup .= ' ' . "\n"; $markup .= ' ' . "\n"; $markup .= '
' . "\n"; $markup .= ' ' . "\n"; $markup .= ' ' . "\n"; // return( $markup ); } //Create the HTML for the page body based upon the type of content within the body private function markup_body( $type ) { // switch ( $type ) { // case 'home': $markup = new contentHome( $this->db ); break; } return( $markup->markup ); } //Create the HTML for the footer of the page private function markup_foot( ) { $markup = '
' . "\n"; $markup .= ' ' . "\n"; $markup .= '' . "\n"; return( $markup ); } //Compile all elements of the page into one string private function markup_compile( ) { return( $this->markupHead . $this->markupBody . $this->markupFoot ); } // public function __get( $attribute ) { // switch( $attribute ) { // case 'markup': return( $this->markup ); } } } // class contentHome { // private $db; private $heading; private $text; private $markup; // public function __construct( $db ) { //Create a shorthand reference to the database $this->db = $db; // $this->content_attributes( $this->db ); // $this->markup = $this->markup_body( ); } // private function content_attributes( $db ) { //Send query to the database for the home page contents $result = $db->query( 'select * from content_home' ); //Create an object from the database query result $row = $result->fetch_object( ); //Define the content properties $this->heading = $row->heading; $this->text = $row->text; } // private function markup_body( ) { // $markup = '
' . "\n"; $markup .= '

' . $this->heading . '

' . "\n"; $markup .= '

' . $this->text . '

' . "\n"; $markup .= '
' . "\n"; // return( $markup ); } // public function __get( $attribute ) { // switch ( $attribute ) { // case 'markup': return( $this->markup ); break; } } } //Create a connection to the database $db = new mysqli( 'localhost', 'coyotetours', 'mr7Urtle', 'coyote_tours' ); //Create a shorthand reference to the URL variable $urlPath = $_GET[ 'url_path' ]; // $page = new page( $urlPath, $db ); // echo $page->markup; ?>