All pastes #749548 Raw Edit

du

public php v1 · immutable
#749548 ·published 2007-10-25 19:33 UTC
rendered paste body
<?php  //Turn error reporting on for development  error_reporting( E_ERROR || E_WARNING || E_PARSE || E_NOTICE );  //Define values that never change  define( 'DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' );  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 .= '<html>' . "\n";      $markup .= '  <head>' . "\n";      $markup .= '    <title>' . $this->title . ' - ' . DOMAIN . '</title>' . "\n";      $markup .= '    <meta type="keywords" content="' . $this->keywords . '" />' . "\n";      $markup .= '    <meta type="description" content="' . $this->description . '" />' . "\n";      $markup .= '  </head>' . "\n";      $markup .= '  <body style="margin: 0 auto; text-align: center; padding: 0; width: 100%; height: 100%;">'  . "\n";      $markup .= '    <div id="container" style="width: 700px; height: 100%; background-color: green;">' . "\n";      $markup .= '      <div id="banner" style="width: 100%; height: 200px; background-color: black;">' . "\n";      $markup .= '      </div>' . "\n";      $markup .= '      <div id="menuTop" style="width: 100%; height: 40px; background-color: red;">' . "\n";      $markup .= '      </div>' . "\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  = '    </div>' . "\n";      $markup .= '  </body>'  . "\n";      $markup .= '</html>'    . "\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  = '      <div style="width: 100%; height: 100%; background-color: green; text-align: left;">' . "\n";      $markup .= '        <h1>' . $this->heading . '</h1>' . "\n";      $markup .= '        <p>'  . $this->text    . '</p>'  . "\n";      $markup .= '      </div>' . "\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;?>