Browse Source

Finished development

With a little delay because of exams
Jeroen De Meerleer 6 years ago
parent
commit
babd72c0f1
20 changed files with 481 additions and 83 deletions
  1. 3 1
      .gitignore
  2. 3 1
      .htaccess
  3. 24 0
      config.php
  4. BIN
      content/images/JeroenED.jpg
  5. 0 0
      content/images/jeroenED.png
  6. 87 0
      content/instantbugfix.js
  7. 16 9
      style.css
  8. 44 0
      controller.class.php
  9. 23 0
      controllers.php
  10. 52 0
      controllers/apiClass.php
  11. 44 0
      controllers/pageClass.php
  12. 4 1
      database.sql
  13. 20 0
      dbcon.php
  14. BIN
      images/navicon.png
  15. 31 14
      index.php
  16. 0 57
      instantbugfix.js
  17. 23 0
      models.php
  18. 29 0
      models/fix.php
  19. 29 0
      models/page.php
  20. 49 0
      views/index.tpl

+ 3 - 1
.gitignore

@@ -214,4 +214,6 @@ pip-log.txt
 #Mr Developer
 .mr.developer.cfg
 
-nbproject
+##My Settings
+nbproject
+compiled_templates

+ 3 - 1
.htaccess

@@ -1,4 +1,6 @@
 Options -indexes
 
-RewriteEngine On 
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteRule . index.php [QSA]

+ 24 - 0
config.php

@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * Change this file to suit your needs and rename it to config.php
+ */
+
+/*
+ * 
+ *   _____       _______       ____           _____ ______ 
+ *  |  __ \   /\|__   __|/\   |  _ \   /\    / ____|  ____|
+ *  | |  | | /  \  | |  /  \  | |_) | /  \  | (___ | |__   
+ *  | |  | |/ /\ \ | | / /\ \ |  _ < / /\ \  \___ \|  __|  
+ *  | |__| / ____ \| |/ ____ \| |_) / ____ \ ____) | |____ 
+ *  |_____/_/    \_\_/_/    \_\____/_/    \_\_____/|______|
+ *                                                                                                             
+ * 
+ */
+
+define('DB_HOST', 'localhost');
+define('DB_USER', 'root');
+define('DB_PASS', 'letmein');
+define('DB_NAME', 'instantbugfix');
+define('DB_PREFIX', 'ibf_');
+

BIN
content/images/JeroenED.jpg


images/jeroenED.png → content/images/jeroenED.png


+ 87 - 0
content/instantbugfix.js

@@ -0,0 +1,87 @@
+/* 
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+$(document).ready(function() {
+
+    $(window).resize();
+
+});
+
+$(window).resize(function() {
+    $('#bugfix').css({
+        position: 'absolute',
+        left: 0,
+        top: ($(window).height() - $('#bugfix').outerHeight()) / 2,
+        width: $(window).width()
+    });
+});
+
+$(document).click(function() {
+    history.pushState(null, "Instant Bug Fix", "/");
+    $("#page").remove();
+});
+function openAboutPage() {
+    
+    history.pushState(null, "About Me", "/page/about");
+    ibfCall("getPage?slug=about");
+    
+}
+
+function ibfCall(apiCall) {
+    console.log("ibfCall called");
+    if (typeof apiCall === undefined) return;
+    if (apiCall == "none") return;
+    var ajCall = $.ajax('/api/' + apiCall, {
+        cache: false
+    });
+    ajCall.done(function(data) {
+        var JSON = $.parseJSON(data);
+        var key = JSON.type;
+        switch (key) {
+            case "Bugfix":
+                parseBugfix(JSON.data);
+                break;
+            case "Page":
+                createPage(JSON.data);
+        }
+
+    });
+}
+
+function parseBugfix(bugfix) {
+    dom = $("body").html();
+    dom = dom.replace(/%fix%/g, bugfix.fix);
+    dom = dom.replace(/%id%/g, bugfix.fixID);
+    $("body").html(dom);
+    $(window).resize();
+}
+
+function createPage(pageData) {
+    $("body").append("<div id='page'>" + pageData.content + "</div>");
+    $('#page').css({
+        "position": 'absolute',
+        "width": "640",
+        "height": "480",
+        "left": ($(window).width() - 640) / 2,
+        "top": ($(window).height() - 480) / 2,
+        "background-color": "#000000",
+        "opacity": 0
+    });
+    $("#page").animate({
+        opacity: 0.9,
+    }, 100);
+}

+ 16 - 9
style.css

@@ -49,21 +49,14 @@ a {
     position: absolute;
 }
 
-#navigation {
+#about {
     position: absolute;
     right: 5px;
     top: 5px;
     text-align: right;
     line-height: 20px;
 }
-#navcontent {
-    display: none;
-    position: absolute;
-    width: 250px;
-}
-#navcontent ul {
-    list-style: none;
-}
+
 
 #permalink {
     position: absolute;
@@ -82,6 +75,20 @@ a {
     bottom: 5px;
 }
 
+#page {
+    padding: 15px;
+}
+
+#page ul {
+    padding-left: 30px;
+}
+#page img {
+    padding: 15px;
+}
+#page h2 {
+    padding-top: 5px;
+}
+
 @media screen and (max-device-width: 480px) {
     
     #bugfix p {    

+ 44 - 0
controller.class.php

@@ -0,0 +1,44 @@
+<?php
+
+/*
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Description of model
+ *
+ * @author Jeroen De Meerleer <me@jeroened.be>
+ */
+class controller {
+    
+    public $id;
+    public $controller;
+    public $method;
+    
+    function create_template($template, $model) {
+        $tpl = new SpoonTemplate();
+        $tpl->setForceCompile(true);
+        $tpl->setCompileDirectory('compiled_templates');
+
+        // assign some variables
+        foreach($model as $key => $value) {
+            $tpl->assign($key, $value);
+        }
+
+        // show the output, using 'template.tpl'
+        $tpl->display("views/" . $template);
+    }
+}

+ 23 - 0
controllers.php

@@ -0,0 +1,23 @@
+<?php
+
+/* 
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+foreach (glob("controllers/*.php") as $filename)
+{
+    include_once $filename;
+}

+ 52 - 0
controllers/apiClass.php

@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Description of apiClass
+ *
+ * @author Jeroen De Meerleer <me@jeroened.be>
+ */
+class apiClass {
+    
+    Public function getBugfix() {
+        global $db;
+        $array["type"] = "Bugfix";
+        
+        if(isset($_GET['fix'])) {
+            $array["data"] = $db->getRecord('SELECT * FROM ' . DB_PREFIX . 'fixes WHERE fixID = ? ',filter_input(INPUT_GET, 'fix') );          
+        }else {
+            $array["data"] = $db->getRecord('SELECT * FROM ' . DB_PREFIX . 'fixes ORDER BY RAND() LIMIT 1,1');
+        }
+        echo json_encode($array);
+        exit;
+    }
+    
+    Public Function getPage() {
+        global $db;
+        $slug = filter_input(INPUT_GET, "slug");
+        $array["type"] = "Page";
+        $array["data"] = $db->getRecord('SELECT * '
+                . 'FROM ' . DB_PREFIX . 'revisions '
+                . 'WHERE pageslug = ? '
+                . 'AND isCurrent = 1', $slug);
+        echo json_encode($array);
+        exit;
+    }
+    
+}

+ 44 - 0
controllers/pageClass.php

@@ -0,0 +1,44 @@
+<?php
+
+/*
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Description of homeClass
+ *
+ * @author Jeroen De Meerleer <me@jeroened.be>
+ */
+class pageClass extends controller{
+    
+    public function index() {
+        $model = new page();
+        $model->apiCall[]["call"] = "getBugFix";
+        $this->create_template("index.tpl", $model);
+    }
+    
+    public function about() {
+        $model = new page();
+        $model->apiCall[]["call"] = "getBugFix";
+        $model->apiCall[]["call"] = "getPage?slug=about";
+        $this->create_template("index.tpl", $model);
+    }
+    public function fix() {
+        $model = new page();
+        $model->apiCall[]["call"] = "getBugFix?fix=" . $this->id;
+        $this->create_template("index.tpl", $model);
+    }
+}

File diff suppressed because it is too large
+ 4 - 1
database.sql


+ 20 - 0
dbcon.php

@@ -0,0 +1,20 @@
+<?php
+
+/* 
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+$db = New SpoonDatabase('mysql', DB_HOST, DB_USER, DB_PASS, DB_NAME);

BIN
images/navicon.png


+ 31 - 14
index.php

@@ -18,24 +18,31 @@
  */
 
 // define location of your library
-define('PATH_LIBRARY', '/home/www/htdocs/instantbugfix.local');
+//define('PATH_LIBRARY', dirname(__FILE__) . "/spoon");
+error_reporting(E_ALL);
+ini_set('display_errors', '1');
 
 // add this to the include path
-set_include_path(get_include_path() . PATH_SEPARATOR . PATH_LIBRARY);
-
-// require spoon
+//set_include_path(get_include_path() . PATH_SEPARATOR . PATH_LIBRARY);
+// Initialize framework
 require_once 'spoon/spoon.php';
-$site = new init();
-echo "working-dir: " . $site->get_working_directory() . "<br>";
-echo "controller: " . $site->get_controller() . "<br>";
-echo "method: " . $site->get_method() . "<br>";
-echo "id: " . $site->get_id() . "<br>";
+
+// Add required shizzle
+require_once "config.php";
+require_once "controller.class.php";
+require_once "controllers.php";
+require_once "models.php";
+require_once "dbcon.php";
+
 
 
+// Let's hit the road
+$site = new init();
+
 class init {
     
     public $working_dir;
-    public $controller = "homeClass";
+    public $controller = "pageClass";
     public $method = "index";
     public $id = "0";
     
@@ -44,23 +51,33 @@ class init {
         $this->controller = $this->get_controller();
         $this->method = $this->get_method();
         $this->id = $this->get_id();
+        
+        // Hit that monster
+        $monster = new $this->controller();
+        $monster->controller = $this->controller;
+        $monster->method = $this->method;
+        $monster->id = $this->id;
+        $monster->{$this->method}();
+        
     }
     
     public function get_controller() {
         $query_array = explode('/', filter_input(INPUT_SERVER, 'REQUEST_URI'));
-        $r_value = (isset($query_array[1])) ? $query_array[1] : "homeClass";
+        $controller = (!empty($query_array[1])) ? $query_array[1] : "page";
+        $r_value = $controller . "Class";
         return $r_value;
     }
     
     public function get_method() {
-        $query_array = explode('/', filter_input(INPUT_SERVER, 'REQUEST_URI'));
-        $r_value = (isset($query_array[2])) ? $query_array[2] : "index";
+        $query = explode('?', filter_input(INPUT_SERVER, 'REQUEST_URI'));
+        $query_array = explode('/', $query[0]);
+        $r_value = (!empty($query_array[2])) ? $query_array[2] : "index";
         return $r_value;
     } 
     
     public function get_id() {
         $query_array = explode('/', filter_input(INPUT_SERVER, 'REQUEST_URI'));
-        $r_value = (isset($query_array[3])) ? $query_array[3] : "1";
+        $r_value = (!empty($query_array[3])) ? $query_array[3] : -1;
         return $r_value;
     }
     

+ 0 - 57
instantbugfix.js

@@ -1,57 +0,0 @@
-/* 
- * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-$(document).ready(function () {
-    $(window).resize(function () {
-        
-        $('#bugfix').css({
-            position: 'absolute',
-            left: 0,
-            top: ($(window).height() - $('#bugfix').outerHeight()) / 2,
-            width: $(window).width()
-        });
-
-
-    });
-
-
-    $(window).resize();
-    
-    // To initially run the function:
-    $("#navhead").click(function () {
-        if ($("#navcontent").css("display") == "none") {
-            $("#navcontent").css({
-                display: "block",
-                right: "25px"
-            });
-            $("#navcontent").animate({
-                right: "5px"
-            }, 400);
-        } else {
-            $("#navcontent").css({
-                display: "none"
-            });
-        }
-    });
-
-    $("#navcontent ul li a").click(function () {
-
-        $("#bugfix p").html("You cannot return flase");
-
-        //$(this).html()
-        history.pushState(null, "contact", "/contact");
-    })
-})

+ 23 - 0
models.php

@@ -0,0 +1,23 @@
+<?php
+
+/* 
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+foreach (glob("models/*.php") as $filename)
+{
+    include_once $filename;
+}

+ 29 - 0
models/fix.php

@@ -0,0 +1,29 @@
+<?php
+
+/*
+ * Copyright (C) 2014 Jeroen
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * Description of fix
+ *
+ * @author Jeroen
+ */
+class fix {
+    public $fixID;
+    public $fixText;
+}

+ 29 - 0
models/page.php

@@ -0,0 +1,29 @@
+<?php
+
+/*
+ * Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Description of fixModel
+ *
+ * @author Jeroen De Meerleer <me@jeroened.be>
+ */
+class page {
+    
+    Public $apiCall;
+    
+}

+ 49 - 0
views/index.tpl

@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<!--
+Copyright (C) 2014 Jeroen De Meerleer <me@jeroened.be>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<html>
+    <head>
+        <title>Instant Bug Fix</title>
+        <link href="/content/style.css" rel="stylesheet" type="text/css" media="screen">
+        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
+        <script src="/content/instantbugfix.js" type="text/javascript"></script>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width">
+        <script type="text/javascript">
+            {iteration:apiCall}
+                ibfCall("{$apiCall.call}");
+            {/iteration:apiCall}
+        </script>
+    </head>
+    <body>
+        <div id="bugfix">
+            <p>%fix%</p>
+        </div>
+        <div id="about">
+            <a href="#" onclick="return openAboutPage();">About me</a>
+        </div>
+        <div id="permalink">
+            <a href="#" onclick="prompt('Copy this and share the bugfix', 'http://instantbugfix.jeroened.be/page/fix/%id%');">Permalink</a>
+        </div>
+        <div id="tweetthis">
+            <a href="https://twitter.com/intent/tweet?text=%fix%&url=http%3A%2F%2Finstantbugfix.jeroened.be%2Fpage%2Ffix%2F%id%" target="_blank">Tweet</a>
+        </div>
+        <div id="badge">
+            <a href="http://www.jeroened.be" target="_blank"><img src="/content/images/jeroenED.png" alt="created by Jeroen De Meerleer"></a>
+        </div>
+    </body>
+</html>