From c2027dcd67c96c20f59cf91e26b45f97ee2b93eb Mon Sep 17 00:00:00 2001 From: rinrynque Date: Tue, 18 Apr 2017 23:27:13 +0200 Subject: [PATCH 01/13] Fixing an error when using PostgreSQL Used $e->getMessage()); to display the error, but did not commit this change --- application/Core/Model.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/application/Core/Model.php b/application/Core/Model.php index 7602a2f..ceb0efc 100644 --- a/application/Core/Model.php +++ b/application/Core/Model.php @@ -33,9 +33,19 @@ private function openDatabaseConnection() // For example, fetch mode FETCH_ASSOC would return results like this: $result["user_name] ! // @see http://www.php.net/manual/en/pdostatement.fetch.php $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING); - + + //Setting the encoding is different when using PostgreSQL + $enc_opt = ""; + if(DB_TYPE=="pgsql") + { + $enc_opt=" options='--client_encoding=" . DB_CHARSET ."'"; + } + else + { + $enc_opt="; charset=".DB_CHARSET; + } // generate a database connection, using the PDO connector // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ - $this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET, DB_USER, DB_PASS, $options); + $this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME . $enc_opt, DB_USER, DB_PASS, $options); } } From 0f2addf5e4e049558dea37f623d77f0d3eea134d Mon Sep 17 00:00:00 2001 From: Bogdan Raica Date: Fri, 5 May 2017 21:25:02 +0300 Subject: [PATCH 02/13] Avoid methods that are not callable Avoid issues when someone tries to access a protected / private method which would not work. --- application/Core/Application.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/Core/Application.php b/application/Core/Application.php index f6976ed..b5235bb 100644 --- a/application/Core/Application.php +++ b/application/Core/Application.php @@ -37,8 +37,9 @@ public function __construct() $this->url_controller = new $controller(); // check for method: does such a method exist in the controller ? - if (method_exists($this->url_controller, $this->url_action)) { - + if (method_exists($this->url_controller, $this->url_action) && + is_callable(array($this->url_controller, $this->url_action))) { + if (!empty($this->url_params)) { // Call the method and pass arguments to it call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params); From 54c84b7f700ed18a78984f241339c8a604aa7adc Mon Sep 17 00:00:00 2001 From: Ole-Martin Bratteng Date: Tue, 18 Jul 2017 14:52:57 +0200 Subject: [PATCH 03/13] Get better URLs in nginx Fixed nginx config, so you can now have URLs like `/a/deep/path?param=true` Otherwise, to achieve the same result, you'd end up with URLs like `/a/deep/path¶m=true` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5656cc4..9419cc1 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ server { location / { index index.php; - try_files /$uri /$uri/ /index.php?url=$uri; + try_files /$uri /$uri/ /index.php?url=$uri&$args; } location ~ \.(php)$ { From 22ae682a727557d553a29713f385d8ccf4994ffd Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 10 Sep 2017 02:54:56 +0200 Subject: [PATCH 04/13] fix for uppercase libs folder issue --- application/{libs => Libs}/helper.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename application/{libs => Libs}/helper.php (100%) diff --git a/application/libs/helper.php b/application/Libs/helper.php similarity index 100% rename from application/libs/helper.php rename to application/Libs/helper.php From f52fb5cba09100f70c63ad399108e58073307c5c Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 10 Sep 2017 03:03:15 +0200 Subject: [PATCH 05/13] coding style changes for PostGreSQL fix --- application/Core/Model.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/application/Core/Model.php b/application/Core/Model.php index ceb0efc..7b2ba24 100644 --- a/application/Core/Model.php +++ b/application/Core/Model.php @@ -34,18 +34,15 @@ private function openDatabaseConnection() // @see http://www.php.net/manual/en/pdostatement.fetch.php $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING); - //Setting the encoding is different when using PostgreSQL - $enc_opt = ""; - if(DB_TYPE=="pgsql") - { - $enc_opt=" options='--client_encoding=" . DB_CHARSET ."'"; - } - else - { - $enc_opt="; charset=".DB_CHARSET; + // setting the encoding is different when using PostgreSQL + if (DB_TYPE == "pgsql") { + $databaseEncodingenc = " options='--client_encoding=" . DB_CHARSET . "'"; + } else { + $databaseEncodingenc = "; charset=" . DB_CHARSET; } + // generate a database connection, using the PDO connector // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ - $this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME . $enc_opt, DB_USER, DB_PASS, $options); + $this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME . $databaseEncodingenc, DB_USER, DB_PASS, $options); } } From b057b8b4d08a009848b8205fb135a3a72fd806dc Mon Sep 17 00:00:00 2001 From: Mark Hewitt Date: Wed, 28 Mar 2018 13:58:30 -0400 Subject: [PATCH 06/13] Error pages are now displayed in place, as opposed to redirecting the user --- application/Core/Application.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/Core/Application.php b/application/Core/Application.php index b5235bb..4e21326 100644 --- a/application/Core/Application.php +++ b/application/Core/Application.php @@ -53,11 +53,13 @@ public function __construct() // no action defined: call the default index() method of a selected controller $this->url_controller->index(); } else { - header('location: ' . URL . 'error'); + $page = new \Mini\Controller\ErrorController(); + $page->errorPage(); } } } else { - header('location: ' . URL . 'error'); + $page = new \Mini\Controller\ErrorController(); + $page->errorPage(); } } From b58aef019b6f052fd8c45723c534268b540c863a Mon Sep 17 00:00:00 2001 From: Mark Hewitt Date: Wed, 28 Mar 2018 14:00:19 -0400 Subject: [PATCH 07/13] Fixed method call from errorPage to index --- application/Core/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/Core/Application.php b/application/Core/Application.php index 4e21326..083674c 100644 --- a/application/Core/Application.php +++ b/application/Core/Application.php @@ -54,12 +54,12 @@ public function __construct() $this->url_controller->index(); } else { $page = new \Mini\Controller\ErrorController(); - $page->errorPage(); + $page->index(); } } } else { $page = new \Mini\Controller\ErrorController(); - $page->errorPage(); + $page->index(); } } From 5ec4888294535777c38ca044c5ac57ddd79b0dc1 Mon Sep 17 00:00:00 2001 From: Mark Hewitt Date: Thu, 29 Mar 2018 09:54:35 -0400 Subject: [PATCH 08/13] Added row count checking on getSong to return false if there are no rows --- application/Model/Song.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/Model/Song.php b/application/Model/Song.php index 1750116..7ff4812 100644 --- a/application/Model/Song.php +++ b/application/Model/Song.php @@ -89,7 +89,7 @@ public function getSong($song_id) $query->execute($parameters); // fetch() is the PDO method that get exactly one result - return $query->fetch(); + return ($query->rowcount() ? $query->fetch() : false); } /** From 766751dc78d3afe4f15ee611fb50b476bc0e32db Mon Sep 17 00:00:00 2001 From: Mark Hewitt Date: Thu, 29 Mar 2018 09:56:25 -0400 Subject: [PATCH 09/13] Load error page if editsong $song_id doesn't exist in db --- application/Controller/SongsController.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/application/Controller/SongsController.php b/application/Controller/SongsController.php index f572577..89bcfe3 100644 --- a/application/Controller/SongsController.php +++ b/application/Controller/SongsController.php @@ -97,11 +97,18 @@ public function editSong($song_id) // in a real application we would also check if this db entry exists and therefore show the result or // redirect the user to an error page or similar - - // load views. within the views we can echo out $song easily - require APP . 'view/_templates/header.php'; - require APP . 'view/songs/edit.php'; - require APP . 'view/_templates/footer.php'; + if (!$song) + { + $page = new \Mini\Controller\ErrorController(); + $page->index(); + } + else + { + // load views. within the views we can echo out $song easily + require APP . 'view/_templates/header.php'; + require APP . 'view/songs/edit.php'; + require APP . 'view/_templates/footer.php'; + } } else { // redirect user to songs index page (as we don't have a song_id) header('location: ' . URL . 'songs/index'); From 7faa39e6ee4bc2c7a6f7ac2514472405eccbdb3e Mon Sep 17 00:00:00 2001 From: Mark Hewitt Date: Thu, 29 Mar 2018 13:12:24 -0400 Subject: [PATCH 10/13] Cleaned up the braces, and changed the conditional --- application/Controller/SongsController.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/application/Controller/SongsController.php b/application/Controller/SongsController.php index 89bcfe3..b791c06 100644 --- a/application/Controller/SongsController.php +++ b/application/Controller/SongsController.php @@ -95,15 +95,11 @@ public function editSong($song_id) // do getSong() in model/model.php $song = $Song->getSong($song_id); - // in a real application we would also check if this db entry exists and therefore show the result or - // redirect the user to an error page or similar - if (!$song) - { + // If the song wasn't found, then it would have returned false, and we need to display the error page + if ($song === false) { $page = new \Mini\Controller\ErrorController(); $page->index(); - } - else - { + } else { // load views. within the views we can echo out $song easily require APP . 'view/_templates/header.php'; require APP . 'view/songs/edit.php'; From 90de632007bfb93322de30b04227aa3aeb2ea4db Mon Sep 17 00:00:00 2001 From: Diego Carvalho Date: Mon, 30 Jul 2018 15:48:18 -0300 Subject: [PATCH 11/13] Update config.php to mysql fullysupport UTF8 charset should be utf8mb4. https://mathiasbynens.be/notes/mysql-utf8mb4 https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html --- application/config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/config.php b/application/config/config.php index d756ce3..1cdbbcc 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -58,4 +58,4 @@ define('DB_NAME', 'mini'); define('DB_USER', 'root'); define('DB_PASS', '12345678'); -define('DB_CHARSET', 'utf8'); +define('DB_CHARSET', 'utf8mb4'); From b2965267e05a4cd91703aa60b11833603ec35eeb Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 25 Dec 2020 23:53:10 +0100 Subject: [PATCH 12/13] [PHP7] upgraded for PHP7 --- README.md | 6 +++--- _vagrant/Vagrantfile | 2 +- _vagrant/bootstrap.sh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9419cc1..3ee8115 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ of the original MINI, made by [JaoNoctus](https://github.com/JaoNoctus). Big tha ## Requirements -- PHP 5.6 or PHP 7.0 +- PHP 5.6 or PHP 7.x (PHP 8.0 should also work fine) - MySQL - mod_rewrite activated (see below for tutorials) - basic knowledge of Composer for sure @@ -39,10 +39,10 @@ Vagrant-file (defines your Vagrant box) and a demo bootstrap.sh which automatica PHPMyAdmin, git and Composer, sets a chosen password in MySQL and PHPMyadmin and even inside the application code, downloads the Composer-dependencies, activates mod_rewrite and edits the Apache settings, downloads the code from GitHub and runs the demo SQL statements (for demo data). This is 100% automatic, you'll end up after +/- 5 minutes with a fully -running installation of MINI3 inside an Ubuntu 14.04 LTS Vagrant box. +running installation of MINI3 inside an Ubuntu 20.04 Vagrant box on PHP 7.4.x. To do so, put `Vagrantfile` and `bootstrap.sh` from `_vagrant` inside a folder (and nothing else). -Do `vagrant box add ubuntu/trusty64` to add Ubuntu 14.04 LTS ("Trusty Thar") 64bit to Vagrant (unless you already have +Do `vagrant box add ubuntu/focal64` to add Ubuntu 20.04 64bit to Vagrant (unless you already have it), then do `vagrant up` to run the box. When installation is finished you can directly use the fully installed demo app on `192.168.33.66`. As this just a quick demo environment the MySQL root password and the PHPMyAdmin root password are set to `12345678`, the project is installed in `/var/www/html/myproject`. You can change this for sure inside diff --git a/_vagrant/Vagrantfile b/_vagrant/Vagrantfile index 0737289..42d9b39 100644 --- a/_vagrant/Vagrantfile +++ b/_vagrant/Vagrantfile @@ -7,7 +7,7 @@ VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "ubuntu/trusty64" + config.vm.box = "ubuntu/focal64" # Create a private network, which allows host-only access to the machine using a specific IP. config.vm.network "private_network", ip: "192.168.33.66" diff --git a/_vagrant/bootstrap.sh b/_vagrant/bootstrap.sh index c50878e..4b02af7 100644 --- a/_vagrant/bootstrap.sh +++ b/_vagrant/bootstrap.sh @@ -10,12 +10,12 @@ sudo apt-get update sudo apt-get -y upgrade sudo apt-get install -y apache2 -sudo apt-get install -y php5 +sudo apt-get install -y php sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $PASSWORD" sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $PASSWORD" sudo apt-get -y install mysql-server -sudo apt-get install php5-mysql +sudo apt-get install php-mysql sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true" sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $PASSWORD" From 50781c4c49032b249fc23bf8999efbe508b43274 Mon Sep 17 00:00:00 2001 From: foadmk Date: Tue, 2 Mar 2021 04:07:42 -0300 Subject: [PATCH 13/13] adding view and redirect function to clean up controllers --- .gitignore | 1 + application/Controller/ErrorController.php | 6 ++--- application/Controller/HomeController.php | 19 ++++++++------- application/Controller/SongsController.php | 28 +++++++++++----------- application/Core/Application.php | 4 +++- application/Core/CoreFunctions.php | 16 +++++++++++++ 6 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 .gitignore create mode 100644 application/Core/CoreFunctions.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..208a599 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor/* \ No newline at end of file diff --git a/application/Controller/ErrorController.php b/application/Controller/ErrorController.php index f87a7d5..3845a7d 100644 --- a/application/Controller/ErrorController.php +++ b/application/Controller/ErrorController.php @@ -20,8 +20,8 @@ class ErrorController public function index() { // load views - require APP . 'view/_templates/header.php'; - require APP . 'view/error/index.php'; - require APP . 'view/_templates/footer.php'; + view('_templates/header.php'); + view('error/index.php'); + view('_templates/footer.php'); } } diff --git a/application/Controller/HomeController.php b/application/Controller/HomeController.php index 0f3b0af..994e7a7 100644 --- a/application/Controller/HomeController.php +++ b/application/Controller/HomeController.php @@ -20,9 +20,10 @@ class HomeController public function index() { // load views - require APP . 'view/_templates/header.php'; - require APP . 'view/home/index.php'; - require APP . 'view/_templates/footer.php'; + view('_templates/header.php'); + view('home/index.php'); + view('_templates/footer.php'); + } /** @@ -33,9 +34,9 @@ public function index() public function exampleOne() { // load views - require APP . 'view/_templates/header.php'; - require APP . 'view/home/example_one.php'; - require APP . 'view/_templates/footer.php'; + view('_templates/header.php'); + view('home/example_one.php'); + view('_templates/footer.php'); } /** @@ -46,8 +47,8 @@ public function exampleOne() public function exampleTwo() { // load views - require APP . 'view/_templates/header.php'; - require APP . 'view/home/example_two.php'; - require APP . 'view/_templates/footer.php'; + view('_templates/header.php'); + view('home/example_two.php'); + view('_templates/footer.php'); } } diff --git a/application/Controller/SongsController.php b/application/Controller/SongsController.php index b791c06..1e10e3d 100644 --- a/application/Controller/SongsController.php +++ b/application/Controller/SongsController.php @@ -30,10 +30,10 @@ public function index() $songs = $Song->getAllSongs(); $amount_of_songs = $Song->getAmountOfSongs(); - // load views. within the views we can echo out $songs and $amount_of_songs easily - require APP . 'view/_templates/header.php'; - require APP . 'view/songs/index.php'; - require APP . 'view/_templates/footer.php'; + // load views. within the views we can echo out $songs and $amount_of_songs easily + view('_templates/header.php'); + view('songs/index.php', ["songs" => $songs]); + view('_templates/footer.php'); } /** @@ -51,11 +51,11 @@ public function addSong() // Instance new Model (Song) $Song = new Song(); // do addSong() in model/model.php - $Song->addSong($_POST["artist"], $_POST["track"], $_POST["link"]); + $Song->addSong($_POST["artist"], $_POST["track"], $_POST["link"]); } // where to go after song has been added - header('location: ' . URL . 'songs/index'); + redirect('songs/index'); } /** @@ -78,10 +78,10 @@ public function deleteSong($song_id) } // where to go after song has been deleted - header('location: ' . URL . 'songs/index'); + redirect('songs/index'); } - /** + /** * ACTION: editSong * This method handles what happens when you move to http://yourproject/songs/editsong * @param int $song_id Id of the to-edit song @@ -101,13 +101,13 @@ public function editSong($song_id) $page->index(); } else { // load views. within the views we can echo out $song easily - require APP . 'view/_templates/header.php'; - require APP . 'view/songs/edit.php'; - require APP . 'view/_templates/footer.php'; + view('_templates/header.php'); + view('songs/edit.php', ["song" => $song]); + view('_templates/footer.php'); } } else { // redirect user to songs index page (as we don't have a song_id) - header('location: ' . URL . 'songs/index'); + redirect('songs/index'); } } @@ -126,11 +126,11 @@ public function updateSong() // Instance new Model (Song) $Song = new Song(); // do updateSong() from model/model.php - $Song->updateSong($_POST["artist"], $_POST["track"], $_POST["link"], $_POST['song_id']); + $Song->updateSong($_POST["artist"], $_POST["track"], $_POST["link"], $_POST['song_id']); } // where to go after song has been added - header('location: ' . URL . 'songs/index'); + redirect('songs/index'); } /** diff --git a/application/Core/Application.php b/application/Core/Application.php index 083674c..ed42bff 100644 --- a/application/Core/Application.php +++ b/application/Core/Application.php @@ -2,6 +2,8 @@ /** For more info about namespaces plase @see http://php.net/manual/en/language.namespaces.importing.php */ namespace Mini\Core; +require APP . 'core/CoreFunctions.php'; + class Application { /** @var null The controller */ @@ -39,7 +41,7 @@ public function __construct() // check for method: does such a method exist in the controller ? if (method_exists($this->url_controller, $this->url_action) && is_callable(array($this->url_controller, $this->url_action))) { - + if (!empty($this->url_params)) { // Call the method and pass arguments to it call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params); diff --git a/application/Core/CoreFunctions.php b/application/Core/CoreFunctions.php new file mode 100644 index 0000000..4caccf1 --- /dev/null +++ b/application/Core/CoreFunctions.php @@ -0,0 +1,16 @@ + $v) { + $$k = $v; + } + require APP . "view/{$path}"; +} + + +function redirect($path) { + header('location: ' . URL . $path); +} \ No newline at end of file