Commit ad6b6861 authored by Ryan Wade's avatar Ryan Wade

Subcomponent php files are now objects.

Each object has been standardized to include a constructor and render();
This was done to improve code legibility and create consistency across all php files.
parent 72d5d437
<?php
class SQL_ROW
{
//private $data = null;
public function SQL_ROW($data)
{
$this->data = $data;
}
public function GET_ATTRIBUTE($attr)
{
return $this->data[$attr];
}
public function SET_ATTRIBUTE($attr, $val)
{
$this->data[$attr] = $val;
}
}
class SQL
{
//private $pages = null;
function SQL()
{
$this->pages =
[new SQL_ROW([0,-1,"Home" , null , null ,"This is the homepage" ]),
new SQL_ROW([1, 0,"Page1" ,"Page 1 Description" , "./title.jpg" ,"This is page 1 html content" ]),
new SQL_ROW([2, 0,"Page2" ,"Page 2 Description" , "./title.jpg" ,"This is page 2 html content</br><button>Logon</button>" ]),
new SQL_ROW([3, 0,"Page3" ,"Page 3 Description" , "./title.jpg" ,"This is page 3 html content" ]),
new SQL_ROW([4, 0,"Page4" ,"Page 4 Description" , "./title.jpg" ,"This is page 4 html content" ]),
new SQL_ROW([5, 3,"Page5" , null , null ,"This is SUB page 5 html content" ]),
new SQL_ROW([6, 3,"Page6" , null , null ,"This is SUB page 6 html content" ]),
new SQL_ROW([7, 3,"Page7" , null , null ,"This is SUB page 7 html content" ]),
new SQL_ROW([8, 6,"Page8" , null , null ,"This is SUB SUB page 8 html content" ])
];
}
private function getFile($location)
{
$myfile = fopen($location,"r");
return fread($myfile,filesize($location));
}
public function GET_SITE_TITLE()
{
return "My Website";
}
public function GET_SITE_LOGO()
{
return "./logo.png";
}
public function GET_PAGE($id)
{
if(($id!=null)&&($id>=0) && ($id<count($this->pages)))
return $this->pages[$id];
return new SQL_ROW(null);
}
function QUERY_PARENT_ID($id)
{
$i=0;
foreach($this->pages as $page)
{
if(($page->GET_ATTRIBUTE(1)==$id)||(($id==0)&&($page->GET_ATTRIBUTE(0)==0)))
{
$Query[$i]=$page;
$i++;
}
}
if(!isset($Query))
return null;
return $Query;
}
// ID PID Title Description Image Content
// Name Password (Hashed) AccessLevel
}
?>
\ No newline at end of file
<div id="body">
<div id="bodyBox" class="bodyText">
<?php
//This is text. It is the wonderful text that makes up the body. The body, that is, the content of a page. All of its eloquence laid out to bear. Dirty laundry drifting in the wind. Exposed to all the snooping robots and spambots scouring the web for tasty prey.
echo $_GLOBAL["pageHTML"];
class Body
{
private $src = "";
function Body($src)
{
$this->src = $src;
}
public function render()
{
?>
</div>
</div>
\ No newline at end of file
<div id="body">
<div id="bodyBox" class="bodyText">
<?php echo $this->src; ?>
</div>
</div>
<?php
}
}
?>
\ No newline at end of file
<?php
$bc_id = $_GLOBAL["pageId"];
$bc_title = $_GLOBAL["pageTitle"];
$bc_link = "<a class='breadcrumbLink' href='viewpage.php?id=".$bc_id."'>".$bc_title."</a>";
if($bc_id != -1)
<?php
class Breadcrumb
{
$bc_id = $_GLOBAL["SQL"][$bc_id][1];//SQL get parent id
while($bc_id != -1)
private $SQL = null;
private $id = null;
private $title = "";
function Breadcrumb($SQL, $id, $title)
{
$bc_title = $_GLOBAL["SQL"][$bc_id][2];//SQL get Title
$bc_link = "<a class='breadcrumbLink' href='viewpage.php?id=".$bc_id."'>".$bc_title."</a>"." > ".$bc_link;
$bc_id = $_GLOBAL["SQL"][$bc_id][1];//SQL get parent id
$this->SQL = $SQL;
$this->id = $id;
$this->title = $title;
}
public function render()
{
/*$t_id = $this->id;
$t_title = $this->title;
$link = "<a class='breadcrumbLink' href='viewpage.php?id=".$t_id."'>".$t_title."</a>";
if($t_id != -1)
{
$t_id = $this->SQL->GET_PAGE($t_id).GET_ATTRIBUTE(1);
while($t_id != -1)
{
$t_title = $this->SQL->GET_PAGE($t_id).GET_ATTRIBUTE(2);//SQL get Title
$link = "<a class='breadcrumbLink' href='viewpage.php?id=".$t_id."'>".$t_title."</a>"." > ".$link;
$t_id = $this->SQL->GET_PAGE($t_id).GET_ATTRIBUTE(1);
}
}*/
$t_id = $this->id;
$t_title = $this->title;
$link = "";
//if($t_id == -1)
//$link = "<a class='breadcrumbLink' href='viewpage.php?id=".$t_id."'>".$t_title."</a>";
while(true)
{
$link = " > <a class='breadcrumbLink' href='viewpage.php?id=".$t_id."'>".$t_title."</a>".$link;
$t_id = $this->SQL->GET_PAGE($t_id)->GET_ATTRIBUTE(1);
if($t_id == -1||$t_id==null)
break;
$t_title = $this->SQL->GET_PAGE($t_id)->GET_ATTRIBUTE(2);//SQL get Title
}
$link = substr($link,3);
?>
<div id="breadcrumb">
<div id="breadcrumbBox">
<div id="breadcrumbText">
<?php echo $link;?>
</div>
</div>
</div>
<?php
}
}
?>
<div id="breadcrumb">
<div id="breadcrumbBox">
<div id="breadcrumbText">
<?php echo $bc_link;?>
</div>
</div>
</div>
\ No newline at end of file
<?php
class CSS
{
public function render()
{
?>
<link rel='stylesheet' type='text/css' href='sitemap.css'>
<link rel='stylesheet' type='text/css' href='home.css'>
<link rel='stylesheet' type='text/css' href='global.css'>
<link rel='stylesheet' type='text/css' href='header.css'>
<link rel='stylesheet' type='text/css' href='nav.css'>
<link rel='stylesheet' type='text/css' href='title.css'>
<link rel='stylesheet' type='text/css' href='breadcrumb.css'>
<link rel='stylesheet' type='text/css' href='body.css'>
<link rel='stylesheet' type='text/css' href='footer.css'>
<?php
}
}
?>
\ No newline at end of file
<footer id="footer">
<div class="footerText">
<a class="footerLink" href="viewpage.php?id=-1">Site Map</a>
</div>
</footer>
\ No newline at end of file
<?php
class Footer
{
public function render()
{
?>
<footer id="footer">
<div class="footerText">
<a class="footerLink" href="viewpage.php?id=-1">Site Map</a>
</div>
</footer>
<?php
}
}
?>
\ No newline at end of file
<div id="header" class="center">
<img id="headerLogo" src="<?php echo $_GLOBAL["Site_Logo"];?>">
<div id="headerTitle"><?php echo $_GLOBAL["Site_Title"];?></div>
<?php
//include "./nav.php";
?>
</div>
\ No newline at end of file
<?php
class Header
{
private $title = "";
private $logo = "";
public function Header($title, $logo)
{
$this->title = $title;
$this->logo = $logo;
}
public function render()
{
?>
<div id="header" class="center">
<img id="headerLogo" src="<?php echo $this->logo;?>">
<div id="headerTitle"><?php echo $this->title;?></div>
</div>
<?php
}
}
?>
\ No newline at end of file
<nav id="navBar">
<?php
function SQL_QUERY_PARENT_ID($t_id,$t_SQL)
<?php
class Nav
{
function Nav($SQL, $s_id)
{
$i=0;
foreach($t_SQL as $page)
{
if($page[1]==$t_id||($t_id==0&&$page[0]==0))
{
$Query[$i]=$page;
$i++;
}
}
if(!isset($Query))
return null;
return $Query;
$this->SQL = $SQL;
$this->s_id = $s_id;
}
function createLevel($level,$t_SQL,$t_select)
private function createLevel($level)
{
if(!isset($level))
return "";
$navbar = "\r\n<ul class='topul'>\r\n";
$navbar = "\r\n<ul>\r\n";
foreach($level as $page)
{
$id=$page[0];
if($id==$t_select)
$id=$page->GET_ATTRIBUTE(0);
if($id==$this->s_id)
$linkType="NavSelected";
else
$linkType="NavLink";
$title=$page[2];
$title=$page->GET_ATTRIBUTE(2);
$navbar .= "<li><a class='".$linkType."' href='viewpage.php?id=".$id."'>".$title."</a>";
if($page[0]!=0)
$navbar .= createLevel(SQL_QUERY_PARENT_ID($page[0],$t_SQL),$t_SQL,$t_select);
if($id != 0)
$navbar .= $this->createLevel($this->SQL->QUERY_PARENT_ID($id));
$navbar .= "</li>\r\n";
}
$navbar .= "</ul>\r\n";
return $navbar;
}
$nav_SQL = $_GLOBAL["SQL"];
$nav_id = $_GLOBAL["pageId"];
$level = createLevel(SQL_QUERY_PARENT_ID(0,$nav_SQL),$nav_SQL,$nav_id);
echo $level;
?>
</nav>
\ No newline at end of file
public function render()
{
?>
<nav id="navBar">
<?php echo $this->createLevel($this->SQL->QUERY_PARENT_ID(0)); ?>
</nav>
<?php
}
}
?>
\ No newline at end of file
<div id="sitemap">
<?php
function createSitemap($level,$t_SQL,$t_select)
<?php
class Sitemap
{
private $SQL = null;
function Sitemap($SQL)
{
$this->SQL = $SQL;
}
private function createSitemap($level)
{
if(!isset($level))
return "";
$sitemap = "\r\n<ul>\r\n";
foreach($level as $page)
{
$id=$page[0];
$title=$page[2];
$id=$page->GET_ATTRIBUTE(0);
$title=$page->GET_ATTRIBUTE(2);
$sitemap .= "<li><a href='viewpage.php?id=".$id."'>".$title."</a>";
if($page[0]!=0)
$sitemap .= createLevel(SQL_QUERY_PARENT_ID($page[0],$t_SQL),$t_SQL,$t_select);
if($id != 0)
$sitemap .= $this->createSitemap($this->SQL->QUERY_PARENT_ID($id));
$sitemap .= "</li>\r\n";
}
$sitemap .= "</ul>\r\n";
return $sitemap;
}
$sitemap_SQL = $_GLOBAL["SQL"];
$sitemap_id = $_GLOBAL["pageId"];
$level = createSitemap(SQL_QUERY_PARENT_ID(0,$nav_SQL),$nav_SQL,$nav_id);
echo $level;
?>
</div>
\ No newline at end of file
public function render()
{
?>
<div id="sitemap">
<?php echo $this->createSitemap($this->SQL->QUERY_PARENT_ID(0)); ?>
</div>
<?php
}
}
?>
\ No newline at end of file
<?php
if(isset($_POST["id"])||true)
class Title
{
//TODO
//Get Title, Desc, and image location from SQL Database
$Title = $_GLOBAL["pageTitle"];
if(isset($_GLOBAL["pageDesc"]))
private $id = 0;
private $title = "";
private $desc = null;
private $img = null;
function Title($id, $title, $desc=null, $img=null)
{
$Desc = $_GLOBAL["pageDesc"];
$Img = $_GLOBAL["pageImg"];
?>
<div id="Title">
<div id="TitleImg" <?php echo "style=\"background-image: url('".$Img."');\"";?>>
<div id="TitleBox">
<p id="TitleText"><?php echo $Title;?></p>
<p id="TitleDesc"><?php echo $Desc;?></p>
$this->id = $id;
$this->title = $title;
$this->desc = $desc;
$this->img = $img;
}
function render()
{
if($this->img != null)
{
?>
<div id="Title">
<div id="TitleImg" <?php echo "style=\"background-image: url('".$this->img."');\"";?>>
<div id="TitleBox">
<p id="TitleText"><?php echo $this->title;?></p>
<p id="TitleDesc"><?php echo $this->desc;?></p>
</div>
</div>
</div>
</div>
<?php
}
else
{
?>
<div id="Title">
<div id="TitleOnly">
<p id="TitleText"><?php echo $Title;?></p>
<?php
}
else
{
?>
<div id="Title">
<div id="TitleOnly">
<p id="TitleText"><?php echo $this->title;?></p>
<?php if($this->desc != null) { ?>
<p id="TitleDesc"><?php echo $this->desc;?></p>
<?php } ?>
</div>
</div>
</div>
<?php
<?php
}
}
}
?>
\ No newline at end of file
<?php
//Include all components
include "./SQL.php";
include "./css.php";
include "./header.php";
include "./nav.php";
include "./title.php";
include "./breadcrumb.php";
include "./body.php";
include "./sitemap.php";
include "./footer.php";
//Initialize SQL database object
$SQL = new SQL();
//Get Basic Site Info
$site_title = $SQL->GET_SITE_TITLE();
$site_logo = $SQL->GET_SITE_LOGO();
//Get ID from HTML GET REQUEST or set to 0
$page_id = 0;
if(isset($_GET["id"]))
$page_id = $_GET["id"];
//Identify special pages and get page info;
$page_title = null;
$page_desc = null;
$page_img = null;
$page_src = null;
switch ($page_id)
{
case -1:
$page_title = "Sitemap";
break;
default:
$page_title = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(2);
$page_desc = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(3);
$page_img = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(4);
$page_src = $SQL->GET_PAGE($page_id)->GET_ATTRIBUTE(5);
break;
}
//Initialize page component objects
$css = new CSS();
$header = new Header($site_title, $site_logo);
$nav = new NAV($SQL, $page_id);
$title = new Title($page_id, $page_title, $page_desc, $page_img);
$breadcrumb = new Breadcrumb($SQL, $page_id, $page_title);
$body = new Body($page_src);
$sitemap = new Sitemap($SQL);
$footer = new footer();
//render HTML output
?>
<html>
<head>
<?php $css->render();?>
</head>
<body>
<div id="webpage" class="center">
<div id="navigation">
<?php $header->render(); ?>
<?php $nav->render(); ?>
</div>
<div id="content">
<?php
$title->render();
$breadcrumb->render();
switch ($page_id)
{
case -1:
$sitemap->render();
break;
default:
$body->render();
break;
}
?>
</div>
<?php $footer->render(); ?>
</div>
</body>
</html>
<?php
/*
//Grab site info from the database
include "./fakeSQL.php";
$_GLOBAL["SQL"] = $pages;
......@@ -70,4 +154,5 @@
?>
</div>
</body>
</html>
\ No newline at end of file
</html>
*/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment