Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * +--------------------------------------------------------------+
- * | Volkova PHP & MySQL CMS |
- * +--------------------------------------------------------------+
- * | |
- * | Author: Ryan |
- * | Version: 0.01 |
- * | |
- * | |
- * | |
- * +--------------------------------------------------------------+
- */
- class simpleCMS {
- var $host;
- var $username;
- var $password;
- var $table;
- public function display_id($id) {
- $id = mysql_real_escape_string(htmlentities($id));
- $q = "SELECT * FROM testDB WHERE created = '$id'";
- $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']);
- $id = stripslashes($a['created']);
- $date = date('H:i:s d-m-Y', $id);
- $entry_display = <<<ENTRY_DISPLAY
- <div class="post">
- <h2>
- $title
- </h2>
- <h4>
- $date
- </h4>
- <div class="post-body">
- <p>
- $bodytext
- </p>
- </div>
- </div>
- ENTRY_DISPLAY;
- }
- } else {
- $entry_display = <<<ENTRY_DISPLAY
- <h2> Article Not Found </h2>
- <p>
- This article has not been found.
- It may have been moved or deleted..
- </p>
- ENTRY_DISPLAY;
- }
- return $entry_display;
- }
- public function display_public() {
- $amount_page = 3;
- $pages = "<div id=\"pages\">";
- $SQL = "SELECT COUNT(created) from testDB";
- $result = mysql_query($SQL);
- $row = mysql_fetch_row($result);
- $total_records = $row[0];
- $total_pages = ceil($total_records / $amount_page);
- if (isset($_GET["page"])) { $currentpage = $_GET["page"]; } else { $currentpage = 1; };
- $currentpage = mysql_real_escape_string(htmlentities($currentpage));
- $pages .= "<span class=\"pages\">";
- if ($total_pages > 0 && $currentpage > 1) {
- $pages .= "<a href=\"?page=" . (intval($currentpage) - 1) . "\">Prev « </a>";
- }
- if ($total_pages > 1) {
- for ( $i= 1; $i <= $total_pages; $i++) {
- $pages .= "<a href=\"?page=$i\"> $i </a> ";
- if ($i != $total_pages) {
- $pages .= " - ";
- }
- }
- }
- if ($total_pages > 0 && $currentpage != $total_pages && $total_pages > 1) {
- $pages .= "<a href=\"?page=" . (intval($currentpage) + 1) . "\"> » Next </a>";
- }
- $pages .= "</span>\n</div>";
- if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page = 1; };
- $start_from = ($page-1) * $amount_page;
- $q = "SELECT * FROM testDB ORDER BY created DESC LIMIT $start_from, $amount_page";
- $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']);
- $id = stripslashes($a['created']);
- $date = date('H:i d-m-Y', $id);
- $entry_display .= <<<ENTRY_DISPLAY
- <div class="post">
- <h2>
- $title
- </h2>
- <h4>
- $date
- </h4>
- <div class="post-body">
- <p>
- $bodytext
- </p>
- </div>
- <h4>
- <a href="{$_SERVER['PHP_SELF']}?id=$id">Read more... </a>
- </h4>
- </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="{$_SERVER['PHP_SELF']}?admin=1">Add a New Entry</a>
- </p>
- ADMIN_OPTION;
- $entry_display .= $pages;
- return $entry_display;
- }
- public function display_register() {
- $frfff = "INSERT INTO users VALUES (NULL, '$user','202cb962ac59075b964b07152d234b70\',\'user\',\'none\', 1307894307, 1307894307);";
- return <<<REGISTER_FORM
- <form action="{$_SERVER['PHP_SELF']}" method="post">
- <label for="username">Username:</label><br />
- <input name="username" id="username" type="text" maxlength="150" />
- <div class="clear"></div>
- <label for="password">Password:</label><br />
- <input name="password" id="password" type="text" maxlength="150" />
- <div class="clear"></div>
- <label for="repassword">Re-enter Password:</label><br />
- <input name="repassword" id="repassword" type="text" maxlength="150" />
- <div class="clear"></div>
- <input type="submit" value="Login!" />
- </form>
- <br />
- <a href="index.php">Back to Home</a> | <a href="{$_SERVER['PHP_SELF']}?admin=1">Login</a>
- REGISTER_FORM;
- }
- public function display_admin($loggedin) {
- if ( $_COOKIE['username'] && $loggedin == 0) {
- $username = mysql_real_escape_string(htmlentities($_COOKIE['username']));
- $md5pass = mysql_real_escape_string(htmlentities($_COOKIE['md5pass']));
- return $this->login($username,$md5pass);
- }
- if ($loggedin && $_GET['larticles'] != 1) {
- return <<<ADMIN_FORM
- <div id="adminmenu">
- <ul class="ulmenu">
- <li><a href="{$_SERVER['PHP_SELF']}?admin=1&larticles=1" title="List Articles">List Articles</a></li>
- <li><a href="/" title="Stuff">Stuff</a></li>
- <li><a href="/" title="Other stuff">Other Stuff</a></li>
- </ul>
- </div>
- <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 This Entry!" />
- </form>
- <br />
- <a href="index.php">Back to Home</a> | <a href="{$_SERVER['PHP_SELF']}?logout=1">Logout</a>
- ADMIN_FORM;
- } elseif ($loggedin && $_GET['larticles'] == 1) {
- if ($_GET['action'] == 'delete') {
- $created = mysql_real_escape_string(htmlentities($_GET['id']));
- $q = "DELETE FROM testDB WHERE created = '$created'";
- $r = mysql_query($q);
- }
- if ($_GET['action'] == 'edit') {
- $created = mysql_real_escape_string(htmlentities($_GET['id']));
- $q = "SELECT * FROM testDB WHERE created = '$created' ";
- $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= stripslashes($a['created']);
- }
- }
- return <<<EDIT_FORM
- <form action="{$_SERVER['PHP_SELF']}" method="post">
- <label for="created">ID:</label><br />
- <input name="created" id="created" type="text" maxlength="150" value="$created"/>
- <div class="clear"></div>
- <label for="title">Title:</label><br />
- <input name="edtitle" id="title" type="text" maxlength="150" value="$title"/>
- <div class="clear"></div>
- <label for="bodytext">Body Text:</label><br />
- <textarea name="edbodytext" id="bodytext">$bodytext</textarea>
- <div class="clear"></div>
- <input type="submit" value="Edit This Entry!" />
- </form>
- <br />
- EDIT_FORM;
- } else {
- $q = "SELECT * FROM testDB ORDER BY created DESC LIMIT 6";
- $r = mysql_query($q);
- $articles = "";
- if ( $r !== false && mysql_num_rows($r) > 0 ) {
- while ( $a = mysql_fetch_assoc($r) ) {
- $title = stripslashes($a['title']);
- $bodytext = stripslashes($a['bodytext']);
- $created = stripslashes($a['created']);
- $articles .= $title . " - Created: " . date('H:m d-m-y', $created) . "<br> ";
- $articles .= "<div class='buttons'>\n";
- $articles .= "<input type=\"button\" value=\"Delete\" class='inputdelete' onClick=\"delete_article('$created')\" >\n";
- $articles .= "<input type=\"button\" value=\"Edit\" class='inputedit' onClick=\"parent.location='?admin=1&larticles=1&action=edit&id=$created';\" > <br>\n";
- $articles .= "</div>\n";
- }
- }
- return <<<ADMIN_FORM
- <div id="adminmenu">
- <ul class="ulmenu">
- <li><a href="{$_SERVER['PHP_SELF']}?admin=1" title="New Article">New Article</a></li>
- <li><a href="{$_SERVER['PHP_SELF']}?admin=1&larticles=1" title="List Articles">List Articles</a></li>
- <li><a href="/" title="Stuff">Stuff</a></li>
- <li><a href="/" title="Other stuff">Other Stuff</a></li>
- </ul>
- </div>
- $articles
- <br />
- <a href="index.php">Back to Home</a> | <a href="{$_SERVER['PHP_SELF']}?logout=1">Logout</a>
- ADMIN_FORM;
- }
- } else {
- return <<<LOGIN_FORM
- You are not logged in<br />
- <form action="{$_SERVER['PHP_SELF']}" method="post">
- <label for="username">Username:</label><br />
- <input name="username" id="username" type="text" maxlength="150" />
- <div class="clear"></div>
- <label for="password">Password:</label><br />
- <input name="password" id="password" type="text" maxlength="150" />
- <div class="clear"></div>
- <input type="submit" value="Login!" />
- </form>
- <br />
- <a href="index.php">Back to Home</a> | <a href="{$_SERVER['PHP_SELF']}?register=1">Register</a>
- LOGIN_FORM;
- }
- }
- public function update($p) {
- if ( $_POST['edtitle'] )
- $title = mysql_real_escape_string(htmlentities($_POST['edtitle']));
- if ( $_POST['edbodytext'])
- $bodytext = mysql_real_escape_string(htmlentities($_POST['edbodytext']));
- if ( $_POST['created'])
- $created = mysql_real_escape_string(htmlentities($_POST['created']));
- if ( $title && $bodytext ) {
- $SQL = "UPDATE testDB SET title = '$title' WHERE created = '$created'";
- mysql_query($SQL);
- $SQL = "UPDATE testDB SET bodytext = '$bodytext' WHERE created = '$created'";
- mysql_query($SQL);
- }
- }
- public function write($p) {
- if ( $_POST['title'] )
- $title = mysql_real_escape_string(htmlentities($_POST['title']));
- if ( $_POST['bodytext'])
- $bodytext = mysql_real_escape_string(htmlentities($_POST['bodytext']));
- if ( $title && $bodytext ) {
- $created = time();
- $sql = "INSERT INTO testDB VALUES('$title','$bodytext','$created')";
- return mysql_query($sql);
- } else {
- return false;
- }
- }
- public function logout() {
- print "<script>SetCookie('username','$username',-7);</script>";
- print "<script>SetCookie('md5pass','$md5pass',-7);</script>";
- return $this->display_public();
- }
- public function login($username, $md5pass) {
- if ( $_POST['username'] )
- $username = mysql_real_escape_string(htmlentities($_POST['username']));
- if ( $_POST['password'])
- $md5pass = md5(mysql_real_escape_string(htmlentities($_POST['password'])));
- $SQL = "SELECT user_id FROM users WHERE username='$username' and password='$md5pass'";
- $result=mysql_query($SQL);
- $loggedin=mysql_num_rows($result);
- while ($db_field = mysql_fetch_assoc($result)) {
- $id = $db_field['user_id'];
- }
- if($loggedin==1) {
- print "<script>SetCookie('username','$username',7);</script>";
- print "<script>SetCookie('md5pass','$md5pass',7);</script>";
- //print "You are logged in";
- } else {
- return false;
- }
- return $this->display_admin($loggedin);
- }
- public function upload($p) {
- if ( $_POST['title'] )
- $title = mysql_real_escape_string($_POST['title']);
- else
- return false;
- }
- public function connect() {
- 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() {
- $sql = <<<MySQL_QUERY
- CREATE TABLE IF NOT EXISTS testDB (
- title VARCHAR(150),
- bodytext TEXT,
- created VARCHAR(100)
- )
- MySQL_QUERY;
- return mysql_query($sql);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment