I had previously written a very simple CMS in PHP, but it wasn't very good looking so I decided to rewrite and improve it using the PHP standards.
Have I done this well, and what areas can be improved?
<?php
class ContentManager {
private $db;
public $websiteInfo = array();
public $pageInfo = array();
public $navigationBar;
//array of css files that should be included into the pages
public $stylesheets = array("style.css");
//set current page if no parameter given
public $current_page = "main";
public $doubleNavigationPages = array("user", "admin");
// this should be a valid link: $page_base_url . $_GET['id']
public $page_base_url = "/?id=";
public function __construct($db) {
$this->db = $db;
//maybe this into a function?
$stmt = $this->db->prepare("SELECT * FROM settings");
$stmt->execute();
$this->websiteInfo = $stmt->fetch();
$this->getNavigationBar();
//set page info
if($this->get('id') !== null) {
$this->current_page = strtolower($this->get('id'));
}
$this->getPage($this->current_page);
return true;
}
//get navigationbar data from db and put it into the var $this->navigation_bar
public function getNavigationBar() {...}
//get page data from db and put it into the array $this->pageInfo
public function getPage($pageId) {...}
public function get($key) {
if(isset($_GET[$key])) {
return $_GET[$key];
}
return null;
}
}
?>
And here is the HTML/template/output processing part (I don't know what to call it). It processes the dynamic content, the header, the navigation bar, the page content, and the footer.
<?php
$db = new PDO("mysql:host=LALALA;dbname=LALALA;", "LALALA", "LALALA");
$ContentManager = new ContentManager($db);
if($ContentManager->pageInfo['dynamic_page']) {
include($ContentManager->pageInfo['dynamic_file']);
} ?>
<!DOCTYPE html>
<html>
<head>
<title><?=$ContentManager->pageInfo['title'];?></title>
<link rel="icon" type="icon/ico" href="/favicon.ico" />
<?php foreach($ContentManager->stylesheets as $css_file) { ?><style type="text/css"><?=str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', str_replace(': ', ':', preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', file_get_contents($css_file))));?></style><?php } ?>
</head>
<body>
<div id="wrap">
<h1 id="title"><a href="//<?=$_SERVER['HTTP_HOST'];?>"><?=$ContentManager->websiteInfo['name'];?></a></h1>
<ul id="nav" class="nav"><li><a href="/"<?php if($ContentManager->current_page == 'main') { ?> id="active"<?php } ?>>Home</a></li>
<?php foreach($ContentManager->navigationBar as $page) { ?><li<?php if($ContentManager->current_page == $page['id']) {?> id="active"<?php } ?>>
<a href="<?php if(!$page['external_url']) { echo $ContentManager->page_base_url; } echo $page['id'];?>"><?=$page['title'];?></a>
</li><?php } ?>
</ul>
<?php
if(!in_array($ContentManager->current_page, $ContentManager->doubleNavigationPages)) { ?>
<div id="main">
<?php
}
include($ContentManager->pageInfo['file']);
?>
</div>
<div id="footer">
<p> Copyright © <?=date("Y");?> - <a href="//<?=$_SERVER['HTTP_HOST'];?>"><?=$ContentManager->websiteInfo['name'];?></a></p>
</div>
</div>
</body>
</html>