Last active
December 24, 2015 21:39
-
-
Save npardington/6866847 to your computer and use it in GitHub Desktop.
Bad example of a framework. Used in a blog post about frameworks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Page | |
{ | |
//add a private called leader that is an instance of the leader class | |
public $title; | |
public $content; | |
public $script; | |
public $debug = false; //used for development used in Debug() | |
private $loggedIn = false; | |
public $contentHeading; | |
private $leader; | |
private $leaderEmail; | |
function Page(){ | |
$this->CheckLoggedIn(); //there may be a cookie in place so we check | |
// $this->leader = LeaderName(); | |
//$this->leaderEmail = LeaderEmail(); | |
} | |
function CheckLoggedIn(){ | |
if ($_SESSION['auth'] || $_COOKIE['loggedin'] == "yes"){ | |
$this->loggedIn = true; | |
} else { | |
$this->loggedIn = false; | |
} | |
} | |
function SetScript($_script){ | |
$this->script = $_script; | |
} | |
function GetScript(){ | |
return $this->script; | |
} | |
function SetTitle($_title) { | |
$this->title = $_title; | |
} | |
function SetContent($_content) { | |
$this->content = $_content; | |
} | |
function GetTitle(){ | |
return $this->title; | |
} | |
function GetContent(){ | |
return $this->content; | |
} | |
function SetContentHeading($_contentHeading){ | |
$this->contentHeading = $_contentHeading; | |
} | |
function AreLoggedIn(){ | |
return $this->loggedIn; | |
} | |
/*---------------- | |
Purpose: Force people to be logged in when viewing a page. | |
Usage: Call this function before you do any printing out to the page. | |
-----------------*/ | |
function RequireLogin(){ | |
if (!$this->loggedIn) | |
$this->DisplayLoginPage(); | |
} | |
function RequireLazyLogin(){ | |
if ($_COOKIE['worker'] == "yes" || $_SESSION['worker'] == "yes" || $this->loggedIn){ | |
} else{ | |
$this->DisplayLoginPage(); | |
} | |
} | |
/*-------------- | |
Purpose: Display the page and populate the necessary items. | |
Usage: Call at the end of each page. | |
---------------*/ | |
function RenderPage(){ | |
$title = $this->title; | |
$content = $this->content; | |
$contentHeading = $this->contentHeading; | |
$script = $this->script; | |
include_once("./templates/generate.php"); | |
} | |
/*-------------- | |
Purpose: Mainly for devloping | |
Usage: In order to view you have to change the $debug variable at the top to true. | |
Problems: Does not allow for you do debug pages that redirect because if you | |
already have output to the screen you cannot redirect. | |
---------------*/ | |
function Debug(){ | |
if ($this->debug){ | |
echo "SESSION: "; | |
print_r($_SESSION); | |
echo "<br><br>COOKIE: "; | |
print_r($_COOKIE); | |
echo "<br><br>Leader Name: " . $this->leader; | |
echo "<br><br>Leader Email: " . $this->leaderEmail; | |
} | |
} | |
/*------------- | |
Purpose: This page gets displeyed when a user attempts to go to a page that requires a login. | |
Usage: Internal function that gets called by RequireLogin() | |
--------------*/ | |
protected function DisplayLoginPage(){ | |
header("Location: " . "http://". $_SERVER['HTTP_HOST'] . "/" . substr(dirname($_SERVER['PHP_SELF']), strpos(dirname($_SERVER['PHP_SELF']), "/")+1) . "/login.php" ); | |
} | |
} //End class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment