Location: PHPKode > projects > KISSCMS > kisscms-1.5.0/app/controllers/main.php
<?php

class Main extends KISS_Auth {
	private $category = false;
	
	//This function maps the controller name and function name to the file location of the .php file to include
	function index( $params ) {
		
		// get the page details stored in the database
		$is_page = $this->getPage();
		$is_category = $this->getCategoryPages( $is_page );
		// check if this is a category page
		if(!$is_page && !$is_category){
			$this->getNewPage();
		}
		// FIX: add the new page link for category pages
		if(!$is_page && $is_category){
			$this->data['status']="new";
		}
		
		// render the page
		$this->render();
	}


	// Main render method
	function render() {
			
		// display the page
		Template::output($this->data);
	}
	
	
	// - Helpers
	function getPage( ) {
		
		$data = array();
		// if there is no path, load the index
		if( empty( $this->data['path'] ) ){
			$page = new Page(1);
		} else { 
			$page = new Page();
			$page->get_page_from_path($this->data['path']);
		}

		// see if we have found a page
		if( $page->get('id') ){
			// store the information of the page
			$data['id'] = $this->data['id'] = $page->get('id');
			$data['title'] = stripslashes( $page->get('title') );
			$data['content'] = stripslashes( $page->get('content') );
			$data['tags'] = stripslashes( $page->get('tags') );
			$data['date'] = strtotime( stripslashes( $page->get('date') ) );
			// check if the page has been classified as a category
			$this->category = ( strpos( $data['tags'], "category" ) > -1) ? true : false;
			
			$data['path']= $this->data['path'];
			$data['view'] = getPath('views/main/body.php');
			$this->data['body'][] = $data;
			// FIX #38: copy data of "static" pages in a seperate array for easy access
			$this->data['_page'] = $data;
			$this->data['template'] = stripslashes( $page->get('template') );
			return true;
		} else {
			return false;			
		}

	}
	
	function getCategoryPages($is_page=false) {

		if( $is_page && !$this->category ) return false; 
		
		$page=new Page();
		$page->tablename = "pages";
		
		// add a leading slash to the path
		$path = ( substr($this->data['path'], -1) == "/" ) ? $this->data['path'] : $this->data['path'].'/';
		
		$pages = $page->retrieve_many("path like '". $this->data['path'] ."%'");
		
		if( count($pages) > 0 ){ 
			foreach( $pages as $data ){
				$data['view'] = getPath('views/main/category.php');
				$this->data['body'][] = $data;
			}
			return true;
		} else {
			return false;
		}
		
	}
	

	function getNewPage() {
		
		if( array_key_exists('admin', $_SESSION) && $_SESSION['admin'] ){ 
			// forward to create a new page
			$data['status']= $this->data['status']="new";
			$data['path']= $this->data['path'];
			$data['view']= getPath('views/admin/confirm_new.php');
			$this->data['body'][] = $data;
		} else { 
			// show 404 error if not loggedin
			$data['view']= getPath('views/main/404.php');
			$this->data['body'][] = $data;
		} 
		
	}
	

}


?>
Return current item: KISSCMS