Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* By Sirupsen ... SlimplCMS */
- class CMS {
- var $host;
- var $username;
- var $password;
- var $table;
- var $admin;
- var $error;
- var $BlogFileName;
- var $timefix;
- public function __construct() { //Aka Config!
- // Database stuff..
- $this->host = "localhost"; // Host
- $this->username = "sirupsen"; // Username to the databse
- $this->password = "asfasfasf"; // Password to the database
- $this->table = "sirupsen_dk_-_sirupsen"; // Database name
- // Page name stuff
- $this->BlogFileName = "index.php"; //Name of the file where the blog is outputed
- // Defaults
- $this->admin = "0";
- $this->timefix = "5550"; // Should usually be left "0", my server time is fucked so
- }
- public function isAdmin(){ // Admin check thing
- $call = "0";
- if($this->admin == "1") {
- $call = "1";
- }
- return $call;
- }
- /* public function UnixAgo($original) {
- $time = time();
- $second = 1;
- $minute = $second*60;
- $hour = $minute*60;
- $day = $hour*24;
- $week = $day*7;
- $month = $day*30;
- $year = $day*12;
- $difference = $time-$original;
- $wcount = 0;
- for($wcount = 0; $difference>$week; $wcount++) {
- $difference = $difference - $week;
- }
- $dcount = 0;
- for($dcount = 0; $difference>$day; $dcount++) {
- $difference = $difference - $day;
- }
- $hcount = 0;
- for($hcount = 0; $difference>$hour; $hcount++) {
- $difference = $difference - $hour;
- }
- $mcount = 0;
- for($mcount = 0; $difference>$minute;
- $mcount++) {
- $difference = $difference - $minute;
- }
- $result = " ago";
- if ($wcount > 1 && $dcount > 1 && $hcount > 1 && $mcount > 1 && $difference > 0) {
- return $wcount ." week(s) ago";
- }
- if ($dcount > 1 && $hcount > 1 && $mcount > 1 && $difference > 0) {
- return $dcount ." day(s) ago";
- }
- if ($hcount > 1 && $mcount > 60 && $difference > 60) {
- return $hcount ." hour(s) ago";
- }
- if ($mcount > 1 && $difference > 0) {
- return $mcount ." minute(s) ago";
- }
- if ($difference < 60) {
- return $difference ." seconds ago";
- }
- else {
- return date("d-m-Y - G:i:s", $fix+$this->timefix);
- }
- //Weeks ago: $wcount
- //Days ago: $dcount
- //Hours ago: $hcount
- //Minutes ago: $mcount
- //Seconds ago: $difference
- } */
- function calcElapsedTime($time){
- $diff = time()-$time;
- $yearsDiff = floor($diff/60/60/24/365);
- $diff -= $yearsDiff*60*60*24*365;
- $monthsDiff = floor($diff/60/60/24/30);
- $diff -= $monthsDiff*60*60*24*30;
- $weeksDiff = floor($diff/60/60/24/7);
- $diff -= $weeksDiff*60*60*24*7;
- $daysDiff = floor($diff/60/60/24);
- $diff -= $daysDiff*60*60*24;
- $hrsDiff = floor($diff/60/60);
- $diff -= $hrsDiff*60*60;
- $minsDiff = floor($diff/60);
- $diff -= $minsDiff*60;
- $secsDiff = $diff;
- $ago = 'ago';
- $years = $yearsDiff.' year'.(($yearsDiff <> 1) ? "s" : "");
- $months = $monthsDiff.' month'.(($monthsDiff <> 1) ? "s" : "");
- $weeks = $weeksDiff.' week'.(($weeksDiff <> 1) ? "s" : "");
- $days = $daysDiff.' day'.(($daysDiff <> 1) ? "s" : "");
- $hours = $hrsDiff.' hour'.(($hrsDiff <> 1) ? "s" : "");
- $mins = $minsDiff.' minute'.(($minsDiff <> 1) ? "s" : "");
- $secs = $secsDiff.' second'.(($secsDiff <> 1) ? "s" : "");
- if($years < 1) {
- $years = "";
- }
- if($months < 1) {
- $months = "";
- }
- if($weeks < 1) {
- $weeks = "";
- }
- if($days < 1) {
- $days = "";
- }
- if($hours < 1) {
- $hours = "";
- }
- if($mins < 1) {
- $mins = "";
- }
- if($secs < 1) {
- $secs = "";
- }
- return ('
- '.$years.'
- '.$months.'
- '.$weeks.'
- '.$days.'
- '.$hours.'
- '.$mins.'
- '.$secs.'
- '.$ago.'
- ');
- }
- public function UnixStamp($fix){ // Converts the Unix Timestamp which came from the database
- // to a normal date..!
- return date("d-m-Y - G:i:s", $fix+$this->timefix);
- }
- public function display_public() { // Display the different events
- $q = "SELECT * FROM slimplCMS_posts ORDER BY created DESC LIMIT 3";
- $r = mysql_query($q);
- if ( $r !== false && mysql_num_rows($r) > 0 ) {
- while ( $a = mysql_fetch_assoc($r) ) {
- $title = stripslashes($a['title']);
- $bodytext = stripslashes($a['bodytext']);
- $created = stripcslashes($a['created']);
- $timestamp = $this->calcElapsedTime($created);
- $entry_display .= <<<ENTRY_DISPLAY
- <div class="post">
- <h2>
- $title
- </h2>
- <p>
- $bodytext
- </p>
- <i>
- $timestamp
- </i>
- </div>
- ENTRY_DISPLAY;
- }
- } else {
- $entry_display = <<<ENTRY_DISPLAY
- <h2> This Page Is Under Construction </h2>
- <p>
- No entries have been made on this page.
- Please check back soon, or click the
- link below to add an entry!
- </p>
- ENTRY_DISPLAY;
- }
- $entry_display .= <<<ADMIN_OPTION
- <p class="admin_link">
- <a href="?admin=1">New</a>
- </p>
- ADMIN_OPTION;
- return $entry_display;
- }
- public function display_admin() { // Post new things
- return <<<ADMIN_FORM
- <form action="{$_SERVER['PHP_SELF']}" method="post">
- <label for="title">Title:</label><br />
- <input name="title" id="title" type="text" maxlength="150" />
- <div class="clear"></div>
- <label for="bodytext">Body Text:</label><br />
- <textarea name="bodytext" id="bodytext"></textarea>
- <div class="clear"></div>
- <input type="submit" value="Create" />
- </form>
- <br />
- <a href="$this->BlogFileName">Back to Home</a>
- ADMIN_FORM;
- }
- public function write($p) { // Write to the database from the form
- if ( $_POST['title'] )
- $title = mysql_real_escape_string($_POST['title']);
- if ( $_POST['bodytext'])
- $bodytext = mysql_real_escape_string($_POST['bodytext']);
- if ( $title && $bodytext ) {
- $created = time();
- $sql = "INSERT INTO slimplCMS_posts VALUES('$title','$bodytext','$created')";
- return mysql_query($sql);
- } else {
- $this->errorHandler("Error! You didn't fill out the fields. <a href='?admin=1'>Return</a>");
- }
- }
- public function errorHandler($error) { // Error handler
- echo "<p class='red'>$error</p>";
- }
- public function connect() { // Connect to databse!
- mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
- mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
- return $this->buildDB();
- }
- private function buildDB() { // Build the database
- $sql = <<<MySQL_QUERY
- CREATE TABLE IF NOT EXISTS slimplCMS_posts (
- title VARCHAR(150),
- bodytext TEXT,
- created VARCHAR(100)
- )
- MySQL_QUERY;
- return mysql_query($sql);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment