· 9 years ago · May 31, 2017, 06:54 AM
1HERES THE FRIGGIN manage-content.php
2
3 <?php
4
5 include_once('../_class/simpleCMS.php');
6 $obj = new simpleCMS();
7
8 /* CHANGE THESE SETTINGS FOR YOUR OWN DATABASE */
9 $obj->host = 'localhost';
10 $obj->username = 'root';
11 $obj->password = '';
12 $obj->table = 'modernCMS';
13 $obj->connect();
14
15 if($_GET['delete']):
16 $obj->delete_content($_GET['delete']);
17 endif;
18 }
19
20 $obj->manage_content();
21
22?>
23
24HERES THE FRIGGIN simpleCMS.php
25
26<?php
27
28class simpleCMS {
29
30 var $host;
31 var $username;
32 var $password;
33 var $table;
34
35 public function display_public() {
36 $q = "SELECT * FROM testDB ORDER BY created DESC LIMIT 3";
37 $r = mysql_query($q);
38
39 if ( $r !== false && mysql_num_rows($r) > 0 ) {
40 while ( $a = mysql_fetch_assoc($r) ) {
41 $title = stripslashes($a['title']);
42 $bodytext = stripslashes($a['bodytext']);
43
44 $entry_display .= <<<ENTRY_DISPLAY
45
46 <div class="post">
47 yeh rite
48 <h2>
49 $title
50 </h2>
51 <p>
52 $bodytext
53 </p>
54 </div>
55
56ENTRY_DISPLAY;
57 }
58 } else {
59 $entry_display = <<<ENTRY_DISPLAY
60
61 <h2> This Page Is Under Construction </h2>
62 <p>
63 No entries have been made on this page.
64 Please check back soon, or click the
65 link below to add an entry!
66 </p>
67
68ENTRY_DISPLAY;
69 }
70 $entry_display .= <<<ADMIN_OPTION
71
72 <p class="admin_link">
73 <a href="create.php#tab2">Add a New Entry</a>
74 </p>
75
76ADMIN_OPTION;
77
78 return $entry_display;
79 }
80
81 public function display_admin() {
82 return <<<ADMIN_FORM
83
84 <form action="{$_SERVER['PHP_SELF']}" method="post">
85
86 <p><div><label>Title:</label>
87<input class="text-input small-input" type="text" id="title" name="title" />
88 <br /><small>Lorem Ipusm dolor sam amet.</small></div>
89
90 <p><div><label>Body Text:</label>
91<textarea class="text-input textarea wysiwyg" id="bodytext" name="bodytext" cols="79" rows="15"></textarea></div>
92
93<p><div><input class="button" type="submit" value="Submit" /></div>
94
95 </form>
96
97 <br />
98
99 <p><a href="create.php"><p>Back to Home</a>
100
101ADMIN_FORM;
102 }
103
104 public function write($p) {
105
106 $sucess = '<div class="notification success png_bg">
107 <a href="#" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
108 <div>
109 Success notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vulputate, sapien quis fermentum luctus, libero.
110 </div></div>';
111 $fail = '<div class="notification error png_bg">
112 <a href="#" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
113 <div>
114 Error notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vulputate, sapien quis fermentum luctus, libero.
115 </div>
116 </div>';
117
118 if ( $_POST['title'] )
119 $title = mysql_real_escape_string($_POST['title']);
120 if ( $_POST['bodytext'])
121 $bodytext = mysql_real_escape_string($_POST['bodytext']);
122 if ( $title && $bodytext ) {
123 echo $sucess;
124 $created = time();
125 $sql = "INSERT INTO testDB VALUES('$title','$bodytext','$created')";
126 return mysql_query($sql);
127
128 } else {
129 return false;
130 }
131 }
132
133 public function connect() {
134 mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
135 mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
136
137 return $this->buildDB();
138 }
139
140 private function buildDB() {
141 $sql = <<<MySQL_QUERY
142CREATE TABLE IF NOT EXISTS testDB (
143title VARCHAR(150),
144bodytext TEXT,
145created VARCHAR(100)
146)
147MySQL_QUERY;
148
149 return mysql_query($sql);
150 }
151
152 function manage_content() {
153 $sql = "SELECT * FROM testDB";
154 $res = mysql_query($sql) or die(mysql_error());
155 while($row = mysql_fetch_assoc($res)) :
156 ?>
157
158 <div>
159 <h3><?php echo $row['title']; ?></h3>
160 <a href="?delete=<?php echo $row['id'] ?>">Delete</a>
161 </div>
162 <?php
163 endwhile;
164
165 function delete_content($id) {
166 if(!$id) {
167 return false;
168 }else {
169 $id = mysql_real_escape_string($id);
170 $sql = "DELETE FROM testDB WHERE id = '$id'";
171 $res = mysql_query($sql) or die(mysql_error());
172 echo "Content Deleted!";
173 endwhile;
174
175
176 }
177 }
178 }
179
180
181?>