vars=array(); } function load_page($page){ $page = basename($page); if(!is_file(PAGE_DIR.$this->sub_dir .$page.".php") && !glob(PAGE_DIR.$this->sub_dir .$page.".php.part.*")){ $page = DEFAULT_PAGE; } $this->page = PAGE_DIR.$this->sub_dir .$page.".php"; // find the page settings $settings_file = SETTINGS_DIR.$this->sub_dir.$page.".inc"; $this->page_settings = array(); if(is_file($settings_file)){ // load the settings $this->page_settings = @unserialize(file_get_contents($settings_file)); }else{ if(is_file(SETTINGS_DIR."/".DEFAULT_SETTINGS)){ $this->page_settings = @unserialize(file_get_contents(SETTINGS_DIR."/".DEFAULT_SETTINGS)); } } $this->set_vars($this->page_settings); } function display(){ // step1 - we get the vars (title, keywords, user specific, etc..) if(is_array($this->vars))extract($this->vars); // step2 - we include the requested page - ob_start(); $file = $this->page; if(!$file)$file = "pages/home.php"; // we try and load the "page parts"; // does this page or parts of this page exist???? $page_parts = glob($file.".part.*"); if(is_file($file) || count($page_parts)){ if(!is_array($page_parts)){ $page_parts=array(); }else{ // work out the id's of these parts... foreach($page_parts as $page_part_type => $file_name){ if(preg_match('/part\.(\d+)\.php$/',$file_name,$matches)){ if($matches[1] != $page_part_type){ $page_parts[$matches[1]] = $file_name; unset($page_parts[$page_part_type]); } } } } if(is_file($file)){ // put the main file first. $page_parts = array("m"=>$file) + $page_parts; } // now we sort these page parts with how they have been set $page_data_sorted = array(); $page_order = explode(",",$this->page_settings['part_order']); if(is_array($page_order)){ foreach($page_order as $page_data_id){ // if this page id exists, then we add it to the page sorted array. if($page_parts[$page_data_id]){ $page_data_sorted[$page_data_id] = $page_parts[$page_data_id]; // also remove it from the page_data array so that we dont add it to the end in default action belod unset($page_parts[$page_data_id]); } } } // default action, add any missing page data blocks to the end of this array.. foreach($page_parts as $page_data_id => $p){ $page_data_sorted[$page_data_id] = $page_parts[$page_data_id]; } // now ites time to incldue them all foreach($page_data_sorted as $file){ include($file); } }else{ echo "no files found"; echo $file; print_r($page_parts); } $html = ob_get_contents(); ob_end_clean(); // step3 - we wrap it all around the template $template = PAGE_DIR.$this->sub_dir . TEMPLATE; if(!is_file($template))$template = "global_template.php"; include($template); } function set_var($key,$val){ $this->vars[$key] = $val; } function set_vars($vars){ if(is_array($vars)) $this->vars = array_merge($this->vars, $vars); } } $request_uri = preg_replace('/(\?.*$)/','',$_SERVER['REQUEST_URI']); $request_uri = preg_replace('/'.preg_quote(FILE_EXT,"/").'$/','',$request_uri); $urlp = explode("/",$request_uri); // this stores the subdirectory we are in at the moment if any $sub_dir = "/"; // now we have to support directories.. we check if this is a directory: $dir_check = ""; for($x=1;$xsub_dir=$sub_dir; $bt->load_page($page); $bt->set_var("s",SITENAME); $bt->set_var("p",$page); $bt->display(); ?>