Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class miniCMS {
- var $host;
- var $username;
- var $password;
- var $table;
- var $i;
- public function display_menu(){
- $q = "SELECT * FROM PAGES ORDER BY created";
- $r = mysql_query($q);
- if ( $r !== false && mysql_num_rows($r) > 0 ) {
- while ( $a = mysql_fetch_assoc($r) ) {
- $title = stripslashes($a['title']);
- $id = stripslashes($a['id']);
- if($_SESSION['admin'] == true){
- $entry_display .= <<<ADMIN_OPTION
- <div class="menu">
- <a href="?p={$id}">{$title}</a>
- </div>
- ADMIN_OPTION;
- }
- else{
- $entry_display .= <<<ENTRY_DISPLAY
- <div class="menu">
- <a href="?p={$id}">{$title}</a>
- </div>
- ENTRY_DISPLAY;
- }
- }
- }
- return $entry_display;
- }
- public function display_page() {
- $q = "SELECT * FROM PAGES WHERE id = {$_GET['p']} ";
- $r = mysql_query($q);
- if ( $r !== false && mysql_num_rows($r) > 0 ) {
- $i=1;
- while ( $a = mysql_fetch_assoc($r) ) {
- $title = stripslashes($a['title']);
- $bodytext = stripslashes($a['bodytext']);
- if($_SESSION['admin'] == false){
- $entry_display .= <<<ENTRY_DISPLAY
- <div class="post">
- <p class="admin_link">{$a['created']}</p>
- <h2>$title</h2><p> $bodytext</p></div>
- ENTRY_DISPLAY;
- }
- if($_SESSION['admin'] == true){
- $entry_display .= <<<ENTRY_DISPLAY
- <div class="post">
- <p class="admin_link">{$a['created']}</p>
- <h2>$title </h2><p>$bodytext
- <p class="admin_link"><a href="{$_SERVER['PHP_SELF']}?delp={$a['id']}"><img src="x-ico.png"></a></p></p>
- </div>
- ENTRY_DISPLAY;
- }
- }
- }
- return $entry_display;
- }
- public function display_public() {
- $q = "SELECT * FROM DB ORDER BY created DESC LIMIT 10";
- $r = mysql_query($q);
- if ( $r !== false && mysql_num_rows($r) > 0 ) {
- $i=1;
- while ( $a = mysql_fetch_assoc($r) ) {
- $title = stripslashes($a['title']);
- $bodytext = stripslashes($a['bodytext']);
- if($_SESSION['admin'] == true){
- $entry_display .= <<<ENTRY_DISPLAY
- <div class="post">
- <p class="admin_link">{$a['created']}</p>
- <h2>$title</h2><p>$bodytext
- <p class="admin_link"><a href="{$_SERVER['PHP_SELF']}?del={$a['id']}"><img src="x-ico.png"></a></p></p>
- </div>
- ENTRY_DISPLAY;
- }
- if($_SESSION['admin'] == false){
- $entry_display .= <<<ENTRY_DISPLAY
- <div class="post">
- <p class="admin_link">{$a['created']}</p>
- <h2>$title</h2><p>$bodytext</p>
- </div>
- ENTRY_DISPLAY;
- }
- $i++;
- }
- }
- else{
- $entry_display = <<<ENTRY_DISPLAY
- <h2>Wpisy</h2><p>Brak wpisów</p>
- ENTRY_DISPLAY;
- }
- if($_SESSION['admin'] == true){
- $entry_display .= <<<ADMIN_OPTION
- <p class="admin_link">
- <a href="{$_SERVER['PHP_SELF']}?addtweet"><img src="add.png"</a>
- </p>
- ADMIN_OPTION;
- }
- return $entry_display;
- }
- public function display_admin() {
- if($_SESSION['admin'] == true) {
- return <<<ADMIN_FORM
- <h1>NOWY WPIS</h1>
- <form action="{$_SERVER['PHP_SELF']}" method="post">
- <label for="title">Nickname:</label><br />
- <input name="title" id="title" type="text" maxlength="150" />
- <div class="clear"></div>
- <label for="bodytext">Wpis:</label><br />
- <textarea name="bodytext" id="bodytext"></textarea>
- <div class="clear"></div>
- <input type="submit" name="add" value="Wrzuć" />
- </form>
- <h1>NOWA PODSTRONA</h1>
- <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">BODYTEXT:</label><br />
- <textarea name="bodytext" id="bodytext"></textarea>
- <div class="clear"></div>
- <input type="submit" name="addp" value="Wrzuć" />
- </form><br/>
- <a href="display.php">Powrót na główną</a>
- <a href="display.php?logout">Wyloguj</a>
- ADMIN_FORM;
- }
- else{
- return <<<ADMIN_FORM
- <form action=""{$_SERVER['PHP_SELF']}" method="post">
- <table>
- <tr><th align="right">Login:</th><td align="left"><input type='text' id='login' name='login'></td></tr>
- <tr><th align="right">Hasło:</th><td align="left"><input type='password' id='haslo' name='haslo'></td></tr>
- <tr><td align="center" colspan="2"><input type='submit' value='Zaloguj' name='logowanie'></td></tr>
- </table>
- </form>
- ADMIN_FORM;
- }
- }
- public function write() {
- if ( $_POST['title'] )
- $title = mysql_real_escape_string($_POST['title']);
- if ( $_POST['bodytext'])
- $bodytext = mysql_real_escape_string($_POST['bodytext']);
- if ( $title && $bodytext ) {
- $created = date('Y-m-d H:i:s');
- $sql = "INSERT INTO DB VALUES('','$title','$bodytext','$created')";
- return mysql_query($sql);
- }
- else{
- return false;
- }
- }
- public function writepage() {
- if ( $_POST['title'] )
- $title = mysql_real_escape_string($_POST['title']);
- if ( $_POST['bodytext'])
- $bodytext = mysql_real_escape_string($_POST['bodytext']);
- if ( $title && $bodytext ) {
- $created = date('Y-m-d H:i:s');
- $sql = "INSERT INTO PAGES VALUES('','$title','$bodytext','$created')";
- return mysql_query($sql);
- }
- else{
- return false;
- }
- }
- public function delete() {
- $sql = "DELETE FROM DB where id = {$_GET['del']} ";
- mysql_query($sql);
- header( 'refresh: 0.1; url=display.php' );
- }
- public function deletep() {
- $sql = "DELETE FROM PAGES where id = {$_GET['delp']} ";
- mysql_query($sql);
- header( 'refresh: 0.1; url=display.php' );
- }
- public function login() {
- if(htmlspecialchars($_POST['login']) == 'admin' && htmlspecialchars($_POST['haslo']) == 'admin'){
- $_SESSION['admin'] = true;
- }
- }
- public function logout() {
- $_SESSION['admin'] = 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 DB (
- id SERIAL,
- title VARCHAR(150),
- bodytext TEXT,
- created VARCHAR(100)
- )
- MySQL_QUERY;
- $sql2 = <<<MySQL_QUERY
- CREATE TABLE IF NOT EXISTS PAGES (
- id SERIAL,
- title VARCHAR(150),
- bodytext TEXT,
- created VARCHAR(100)
- )
- MySQL_QUERY;
- mysql_query($sql);
- mysql_query($sql2);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment