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;
- var $pageLimit;
- public function __construct() { //Aka Config!
- // Database stuff..
- $this->host = "localhost"; // Host
- $this->username = "sirupsen"; // Username to the databse
- $this->password = "safasdf"; // 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
- // Layout configuration
- $this->pageLimit = "10";
- // Defaults
- $this->admin = "0";
- $this->timefix = "5550"; // Should usually be left "0", my server time is fucked so
- }
- public function UnixStamp($fix){ // Converts the Unix Timestamp which came from the database
- // to a normal date, and plus a number if the GMT is different..
- return date("d-m-Y - G:i:s", $fix+$this->timefix);
- }
- public function cTime($date) { // This makes the time more relevant like:
- // Posted.. 2 hours ago, or 2 minutes ago!
- if(empty($date)) { // Checks if there's any date
- return "No date provided";
- }
- $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
- $lengths = array("60","60","24","7","4.35","12","10");
- $now = time();
- // is it future date or past date
- if($now > $datee) {
- $difference = $now - $date;
- $tense = "ago";
- } else {
- $difference = $date - $now;
- $tense = "from now";
- }
- for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
- $difference /= $lengths[$j];
- }
- $difference = round($difference);
- if($difference != 1) {
- $periods[$j].= "s";
- }
- return "$difference $periods[$j] {$tense}";
- }
- public function display_public() { // Display the different events
- $q = "SELECT * FROM slimplCMS_posts ORDER BY created DESC LIMIT 0,$this->pageLimit";
- $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->cTime($created); // Returns the "cool" time
- $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> No entries </h2>
- <p>
- No entries yet in this system, check back later!
- </p>
- ENTRY_DISPLAY;
- }
- $entry_display .= <<<ADMIN_OPTION
- <p class="post_link">
- <a href="?post=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='?post=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