Guest User

Untitled

a guest
Jun 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.79 KB | None | 0 0
  1. <?php
  2. /* By Sirupsen ... SlimplCMS */
  3. class CMS {
  4.  
  5. var $host;
  6. var $username;
  7. var $password;
  8. var $table;
  9. var $admin;
  10. var $error;
  11. var $BlogFileName;
  12. var $timefix;
  13.  
  14. public function __construct() { //Aka Config!
  15.  
  16. // Database stuff..
  17. $this->host = "localhost"; // Host
  18. $this->username = "sirupsen"; // Username to the databse
  19. $this->password = "asfasfasf"; // Password to the database
  20. $this->table = "sirupsen_dk_-_sirupsen"; // Database name
  21.  
  22.  
  23. // Page name stuff
  24. $this->BlogFileName = "index.php"; //Name of the file where the blog is outputed
  25.  
  26.  
  27. // Defaults
  28. $this->admin = "0";
  29. $this->timefix = "5550"; // Should usually be left "0", my server time is fucked so
  30. }
  31.  
  32. public function isAdmin(){ // Admin check thing
  33. $call = "0";
  34.  
  35. if($this->admin == "1") {
  36. $call = "1";
  37. }
  38.  
  39. return $call;
  40. }
  41.  
  42. /* public function UnixAgo($original) {
  43. $time = time();
  44.  
  45. $second = 1;
  46. $minute = $second*60;
  47. $hour = $minute*60;
  48. $day = $hour*24;
  49. $week = $day*7;
  50. $month = $day*30;
  51. $year = $day*12;
  52.  
  53. $difference = $time-$original;
  54.  
  55. $wcount = 0;
  56. for($wcount = 0; $difference>$week; $wcount++) {
  57. $difference = $difference - $week;
  58. }
  59.  
  60. $dcount = 0;
  61. for($dcount = 0; $difference>$day; $dcount++) {
  62. $difference = $difference - $day;
  63. }
  64.  
  65. $hcount = 0;
  66. for($hcount = 0; $difference>$hour; $hcount++) {
  67. $difference = $difference - $hour;
  68. }
  69.  
  70. $mcount = 0;
  71. for($mcount = 0; $difference>$minute;
  72. $mcount++) {
  73. $difference = $difference - $minute;
  74. }
  75.  
  76. $result = " ago";
  77.  
  78. if ($wcount > 1 && $dcount > 1 && $hcount > 1 && $mcount > 1 && $difference > 0) {
  79. return $wcount ." week(s) ago";
  80. }
  81.  
  82. if ($dcount > 1 && $hcount > 1 && $mcount > 1 && $difference > 0) {
  83. return $dcount ." day(s) ago";
  84. }
  85.  
  86. if ($hcount > 1 && $mcount > 60 && $difference > 60) {
  87. return $hcount ." hour(s) ago";
  88. }
  89.  
  90. if ($mcount > 1 && $difference > 0) {
  91. return $mcount ." minute(s) ago";
  92. }
  93.  
  94. if ($difference < 60) {
  95. return $difference ." seconds ago";
  96. }
  97.  
  98. else {
  99. return date("d-m-Y - G:i:s", $fix+$this->timefix);
  100. }
  101.  
  102. //Weeks ago: $wcount
  103. //Days ago: $dcount
  104. //Hours ago: $hcount
  105. //Minutes ago: $mcount
  106. //Seconds ago: $difference
  107.  
  108. } */
  109.  
  110. function calcElapsedTime($time){
  111.  
  112. $diff = time()-$time;
  113. $yearsDiff = floor($diff/60/60/24/365);
  114. $diff -= $yearsDiff*60*60*24*365;
  115. $monthsDiff = floor($diff/60/60/24/30);
  116. $diff -= $monthsDiff*60*60*24*30;
  117. $weeksDiff = floor($diff/60/60/24/7);
  118. $diff -= $weeksDiff*60*60*24*7;
  119. $daysDiff = floor($diff/60/60/24);
  120. $diff -= $daysDiff*60*60*24;
  121. $hrsDiff = floor($diff/60/60);
  122. $diff -= $hrsDiff*60*60;
  123. $minsDiff = floor($diff/60);
  124. $diff -= $minsDiff*60;
  125. $secsDiff = $diff;
  126.  
  127. $ago = 'ago';
  128. $years = $yearsDiff.' year'.(($yearsDiff <> 1) ? "s" : "");
  129. $months = $monthsDiff.' month'.(($monthsDiff <> 1) ? "s" : "");
  130. $weeks = $weeksDiff.' week'.(($weeksDiff <> 1) ? "s" : "");
  131. $days = $daysDiff.' day'.(($daysDiff <> 1) ? "s" : "");
  132. $hours = $hrsDiff.' hour'.(($hrsDiff <> 1) ? "s" : "");
  133. $mins = $minsDiff.' minute'.(($minsDiff <> 1) ? "s" : "");
  134. $secs = $secsDiff.' second'.(($secsDiff <> 1) ? "s" : "");
  135.  
  136. if($years < 1) {
  137. $years = "";
  138. }
  139.  
  140. if($months < 1) {
  141. $months = "";
  142. }
  143.  
  144. if($weeks < 1) {
  145. $weeks = "";
  146. }
  147.  
  148. if($days < 1) {
  149. $days = "";
  150. }
  151.  
  152. if($hours < 1) {
  153. $hours = "";
  154. }
  155.  
  156. if($mins < 1) {
  157. $mins = "";
  158. }
  159.  
  160. if($secs < 1) {
  161. $secs = "";
  162. }
  163.  
  164. return ('
  165.  
  166. '.$years.'
  167. '.$months.'
  168. '.$weeks.'
  169. '.$days.'
  170. '.$hours.'
  171. '.$mins.'
  172. '.$secs.'
  173. '.$ago.'
  174.  
  175. ');
  176. }
  177.  
  178. public function UnixStamp($fix){ // Converts the Unix Timestamp which came from the database
  179. // to a normal date..!
  180. return date("d-m-Y - G:i:s", $fix+$this->timefix);
  181. }
  182.  
  183. public function display_public() { // Display the different events
  184. $q = "SELECT * FROM slimplCMS_posts ORDER BY created DESC LIMIT 3";
  185. $r = mysql_query($q);
  186.  
  187. if ( $r !== false && mysql_num_rows($r) > 0 ) {
  188. while ( $a = mysql_fetch_assoc($r) ) {
  189. $title = stripslashes($a['title']);
  190. $bodytext = stripslashes($a['bodytext']);
  191. $created = stripcslashes($a['created']);
  192.  
  193. $timestamp = $this->calcElapsedTime($created);
  194.  
  195. $entry_display .= <<<ENTRY_DISPLAY
  196.  
  197. <div class="post">
  198. <h2>
  199. $title
  200. </h2>
  201. <p>
  202. $bodytext
  203. </p>
  204. <i>
  205. $timestamp
  206. </i>
  207. </div>
  208.  
  209. ENTRY_DISPLAY;
  210. }
  211. } else {
  212. $entry_display = <<<ENTRY_DISPLAY
  213.  
  214. <h2> This Page Is Under Construction </h2>
  215. <p>
  216. No entries have been made on this page.
  217. Please check back soon, or click the
  218. link below to add an entry!
  219. </p>
  220.  
  221. ENTRY_DISPLAY;
  222. }
  223. $entry_display .= <<<ADMIN_OPTION
  224.  
  225. <p class="admin_link">
  226. <a href="?admin=1">New</a>
  227. </p>
  228.  
  229. ADMIN_OPTION;
  230.  
  231. return $entry_display;
  232. }
  233.  
  234. public function display_admin() { // Post new things
  235. return <<<ADMIN_FORM
  236.  
  237. <form action="{$_SERVER['PHP_SELF']}" method="post">
  238.  
  239. <label for="title">Title:</label><br />
  240. <input name="title" id="title" type="text" maxlength="150" />
  241. <div class="clear"></div>
  242.  
  243. <label for="bodytext">Body Text:</label><br />
  244. <textarea name="bodytext" id="bodytext"></textarea>
  245. <div class="clear"></div>
  246.  
  247. <input type="submit" value="Create" />
  248. </form>
  249.  
  250. <br />
  251.  
  252. <a href="$this->BlogFileName">Back to Home</a>
  253.  
  254. ADMIN_FORM;
  255. }
  256.  
  257. public function write($p) { // Write to the database from the form
  258. if ( $_POST['title'] )
  259. $title = mysql_real_escape_string($_POST['title']);
  260. if ( $_POST['bodytext'])
  261. $bodytext = mysql_real_escape_string($_POST['bodytext']);
  262. if ( $title && $bodytext ) {
  263. $created = time();
  264. $sql = "INSERT INTO slimplCMS_posts VALUES('$title','$bodytext','$created')";
  265. return mysql_query($sql);
  266. } else {
  267. $this->errorHandler("Error! You didn't fill out the fields. <a href='?admin=1'>Return</a>");
  268. }
  269. }
  270.  
  271. public function errorHandler($error) { // Error handler
  272. echo "<p class='red'>$error</p>";
  273. }
  274.  
  275. public function connect() { // Connect to databse!
  276. mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
  277. mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
  278.  
  279. return $this->buildDB();
  280. }
  281.  
  282. private function buildDB() { // Build the database
  283. $sql = <<<MySQL_QUERY
  284. CREATE TABLE IF NOT EXISTS slimplCMS_posts (
  285. title VARCHAR(150),
  286. bodytext TEXT,
  287. created VARCHAR(100)
  288. )
  289. MySQL_QUERY;
  290.  
  291. return mysql_query($sql);
  292. }
  293.  
  294. }
  295.  
  296. ?>
Add Comment
Please, Sign In to add comment