Location: PHPKode > projects > Dev's CMS > devscms/example.index.php
<?php

error_reporting(E_ALL | E_STRICT);
header ('Content-type: text/html; charset=utf-8');
date_default_timezone_set('Europe/Stockholm');

define('ROOT_DIR', '');
require('includes/class.system.php');

// Start system
$system = new system();

// Create objects
$documents = new documents($system->db);
$files = new files($system->db);
$news = new news($system->db);
$galleryAlbums = new galleryAlbums($system->db);
$galleryPictures = new galleryPictures($system->db);

// Menu
$system->mainTemplate->set('menu', $documents->generateMenu($documents->getAll('id,title,link,parent_id', 0, true)));

// If it is a page
if (empty($_GET) || isset($_GET['p'])) {
	$page = !isset($_GET['p']) ? '' : $_GET['p'];
	
	$document = $documents->getByLink($page);
	
	if (is_null($document)) {
		$system->render404();
		exit;
	}
	
	$includeKeys = $documents->getIncludeKeys($document['body'], array('files', 'albums', 'news'));
	
	// Add files
	if (!empty($includeKeys['files'])) {
		$filesTpl = new template('files');
		
		foreach ($includeKeys['files'] as $fileInclude) {
			$fileItems = $files->getAll('*');
			
			foreach ($fileItems as &$item) {
				$item = $files->getInfo($item);
			}
			
			$filesTpl->set('files', $fileItems);
			$document['body'] = str_replace($fileInclude['includeString'], $filesTpl->fetch(), $document['body']);
		}
	}
	
	// Add albums
	if (!empty($includeKeys['albums'])) {
		$albumsTpl = new template('albums');
		
		foreach ($includeKeys['albums'] as $albumInclude) {
			$filter = isset($albumInclude['parameters']['only']) ? array('name' => explode(',', $albumInclude['parameters']['only'])) : array();
			$invertedFilter = isset($albumInclude['parameters']['not']) ? array('name' => explode(',', $albumInclude['parameters']['not'])) : array();
			
			$albums = $galleryAlbums->getAll($filter, $invertedFilter);
			
			foreach ($albums as &$album) {
				$album['samples'] = $galleryPictures->getMany($album['tags'], 3, true);
			}

			$albumsTpl->set('albums', $albums);
			$document['body'] = str_replace($albumInclude['includeString'], $albumsTpl->fetch(), $document['body']);
		}
	}
	
	// Add news
	if (!empty($includeKeys['news'])) {
		$newsTpl = new template('news');
		
		foreach ($includeKeys['news'] as $newsInclude) {
			$newsTpl->set('news', $news->getAll('*', true));
			$document['body'] = str_replace($newsInclude['includeString'], $newsTpl->fetch(), $document['body']);
		}
	}
	
	$system->setPage('document');
	$system->contentTemplate->set('document', $document);
	$system->addIncludes('javascript.js');

// If it is an album
} else if (isset($_GET['a'])) {
	$page = !isset($_GET['a']) ? '' : $_GET['a'];
	
	$album = $galleryAlbums->getByLink($page);
	
	if ($album === false) {
		$system->render404();
		exit;
	}
	
	$system->setPage('album');
	$system->contentTemplate->set('album', $album);
	$system->contentTemplate->set('pictures', $galleryPictures->getMany($album['tags']));
	$system->addIncludes(array('fancybox/jquery-1.3.2.min.js', 'fancybox/jquery.easing.1.3.js', 'fancybox/jquery.fancybox-1.2.1.pack.js', 'fancybox/jquery.fancybox.css'));
}

$system->render();
Return current item: Dev's CMS