From daa9664676fd1e646f08cb51a081b6a058318d77 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Wed, 27 Jan 2016 21:40:04 +0100 Subject: [PATCH 1/8] Added external css and js dependencies to module loader --- controllers/modules.php | 33 +++++++++++++++++++++++++++++---- modules/README.md | 9 ++++++++- modules/test-module/include.php | 13 +++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 modules/test-module/include.php diff --git a/controllers/modules.php b/controllers/modules.php index 8477cc48..63d966c0 100644 --- a/controllers/modules.php +++ b/controllers/modules.php @@ -1,11 +1,36 @@ '."\xA"); - //Add CSS file of module - print_r(''."\xA"); + //Load files to include + $include_files = include($module."/include.php"); + //Add Javascript files + foreach ($include_files["js_files"] as $file) { + //Check if js file is hosted on a remote server + if (preg_match('#^https?://#i', $file) === 1) { + print_r(''."\xA"); + } + //add local path to module folder + else{ + print_r(''."\xA"); + } + }; + //Add CSS files + foreach ($include_files["css_files"] as $file) { + //Check if css file is hosted on a remote server + if (preg_match('#^https?://#i', $file) === 1) { + print_r(''."\xA"); + } + //add local path to module folder + else{ + print_r(''."\xA"); + } + }; + //Get and add HTML Elements print_r(file_get_contents($module.'/elements.html')); + //Add the modules JS file + print_r(''."\xA"); + //Add the modules CSS file + print_r(''."\xA"); } ?> \ No newline at end of file diff --git a/modules/README.md b/modules/README.md index ef5c8ed9..7ce11bec 100644 --- a/modules/README.md +++ b/modules/README.md @@ -2,9 +2,16 @@ MagicMirror =========== ##Modules -A module has to contain three files: main.js, style.css and elements.html +A module has to contain four files: main.js, style.css, elements.html and include.php Other files can be loaded from within those. +### include.php +If you happen to need any other css or js file from remote host or a local file you can add it in include.php. +It will be loaded before the plugins main javascript, the plugins css and the plugins elements. + +Local files starting without http or https will be loaded from the root of the module folder. +If you have a file called test.js in your module just add test.js if you have the same file but in a folder called js inside your module folder add js/test.js. Same is valid for css files. Remote files will be loaded normally from the remote host, no need to specify anything. + ### elements.html Put your custom divs and other html elements in this file (don't include any body or header tags) diff --git a/modules/test-module/include.php b/modules/test-module/include.php new file mode 100644 index 00000000..de275f93 --- /dev/null +++ b/modules/test-module/include.php @@ -0,0 +1,13 @@ + array( + //"http://spiegel.local:1234/socket.io/socket.io.js", + //"js/somefile.js" + ), + 'css_files' => array( + //"css/randomfile.css", + //"https://example.com/test.css" + ) +); +?> \ No newline at end of file From 23c4a809d58b18570be499a44ea0c21be6bdd1bd Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Wed, 27 Jan 2016 21:40:58 +0100 Subject: [PATCH 2/8] Changed README Changed Extensions to Modules --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a721fee..ea50ece6 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Checks the git version and refreshes if a new version has been pulled. Takes the user's inserted location, language, unit type, and OpenWeatherMap API key and grabs the five day weather forecast from OpenWeatherMap. You need to set the API key in the config for this to work. (See *configuration*.) -##Extensions +##Modules ###[MagicMirror-Extensions by PaViRo](https://github.com/paviro/MagicMirror-Extensions) From 7247ffae7238131b2a781bfb171ac2e73fe7abe2 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Wed, 27 Jan 2016 22:22:09 +0100 Subject: [PATCH 3/8] Change loading order --- controllers/modules.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/modules.php b/controllers/modules.php index 63d966c0..e61f8e68 100644 --- a/controllers/modules.php +++ b/controllers/modules.php @@ -25,12 +25,12 @@ print_r(''."\xA"); } }; - - //Get and add HTML Elements - print_r(file_get_contents($module.'/elements.html')); + //Add the modules JS file print_r(''."\xA"); //Add the modules CSS file print_r(''."\xA"); + //Get and add HTML Elements + print_r(file_get_contents($module.'/elements.html')); } ?> \ No newline at end of file From 01ee51e0274e4ca69ee2381507552361c11ff7ab Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Thu, 28 Jan 2016 11:13:27 +0100 Subject: [PATCH 4/8] Added [module] shortcut [module] in elements.html get replaced by the modules path. --- controllers/modules.php | 2 +- modules/README.md | 10 +++++----- modules/test-module/elements.html | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/modules.php b/controllers/modules.php index e61f8e68..249f218d 100644 --- a/controllers/modules.php +++ b/controllers/modules.php @@ -31,6 +31,6 @@ //Add the modules CSS file print_r(''."\xA"); //Get and add HTML Elements - print_r(file_get_contents($module.'/elements.html')); + print_r(str_replace("[module]",$module ,file_get_contents($module.'/elements.html'))); } ?> \ No newline at end of file diff --git a/modules/README.md b/modules/README.md index 7ce11bec..5b280f04 100644 --- a/modules/README.md +++ b/modules/README.md @@ -2,18 +2,18 @@ MagicMirror =========== ##Modules -A module has to contain four files: main.js, style.css, elements.html and include.php +A module has to contain four files: `main.js`, `style.css`, `elements.html` and `include.php`. Other files can be loaded from within those. ### include.php -If you happen to need any other css or js file from remote host or a local file you can add it in include.php. +If you happen to need any other css or js file from remote host or a local file you can add it in `include.php`. It will be loaded before the plugins main javascript, the plugins css and the plugins elements. -Local files starting without http or https will be loaded from the root of the module folder. -If you have a file called test.js in your module just add test.js if you have the same file but in a folder called js inside your module folder add js/test.js. Same is valid for css files. Remote files will be loaded normally from the remote host, no need to specify anything. +Local files starting without `http` or `https` will be loaded from the `root` of the module folder. +If you have a file called `test.js` in your module just add `test.js` if you have the same file but in a folder called `js` inside your module folder add `js/test.js`. Same is valid for css files. Remote files will be loaded normally from the remote host, no need to specify anything. ### elements.html -Put your custom divs and other html elements in this file (don't include any body or header tags) +Put your custom divs and other html elements in this file (don't include any body or header tags). Any refrence of `[module]` will be replaced with the path to the modules root. `[module]/img/test.png` becomes `modules/name_of_module/img/test.png`. ### main.js Your plugins JavaScript. diff --git a/modules/test-module/elements.html b/modules/test-module/elements.html index 0934126a..2bf9bdef 100644 --- a/modules/test-module/elements.html +++ b/modules/test-module/elements.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file From 7627fd0f38fd94c1e14504c52000b541c52ff521 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Thu, 28 Jan 2016 11:34:12 +0100 Subject: [PATCH 5/8] Add div around module code --- controllers/modules.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/controllers/modules.php b/controllers/modules.php index 249f218d..a8ec85ab 100644 --- a/controllers/modules.php +++ b/controllers/modules.php @@ -1,6 +1,10 @@ ' ); + //Load files to include $include_files = include($module."/include.php"); //Add Javascript files @@ -32,5 +36,8 @@ print_r(''."\xA"); //Get and add HTML Elements print_r(str_replace("[module]",$module ,file_get_contents($module.'/elements.html'))); + + //Close module container + print_r(""); } ?> \ No newline at end of file From 8d9d1e8d9f451f6d980edb0f18f48b925ebcfae7 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Thu, 28 Jan 2016 11:42:43 +0100 Subject: [PATCH 6/8] Language fixes README --- modules/README.md | 8 ++++---- modules/test-module/style.css | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/README.md b/modules/README.md index 5b280f04..c9998167 100644 --- a/modules/README.md +++ b/modules/README.md @@ -7,16 +7,16 @@ Other files can be loaded from within those. ### include.php If you happen to need any other css or js file from remote host or a local file you can add it in `include.php`. -It will be loaded before the plugins main javascript, the plugins css and the plugins elements. +It will be loaded before the module's main javascript, the module's css and the module's elements. Local files starting without `http` or `https` will be loaded from the `root` of the module folder. If you have a file called `test.js` in your module just add `test.js` if you have the same file but in a folder called `js` inside your module folder add `js/test.js`. Same is valid for css files. Remote files will be loaded normally from the remote host, no need to specify anything. ### elements.html -Put your custom divs and other html elements in this file (don't include any body or header tags). Any refrence of `[module]` will be replaced with the path to the modules root. `[module]/img/test.png` becomes `modules/name_of_module/img/test.png`. +Put your custom divs and other html elements in this file (don't include any body or header tags). Any refrence of `[module]` will be replaced with the path to the module's root. `[module]/img/test.png` for example becomes `modules/name_of_module/img/test.png`. ### main.js -Your plugins JavaScript. +Your plugin's JavaScript. ### style.css -CSS for your HTML elements. \ No newline at end of file +CSS for your HTML elements. All module elements get loaded into a `div`. The `id` is the name of the module's folder, which acts as the module's name. \ No newline at end of file diff --git a/modules/test-module/style.css b/modules/test-module/style.css index e69de29b..e99a7785 100644 --- a/modules/test-module/style.css +++ b/modules/test-module/style.css @@ -0,0 +1,3 @@ +#test-module{ + +} \ No newline at end of file From 7aba85e941855a035cae4460ea3a32035ec67f7c Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Thu, 28 Jan 2016 11:53:26 +0100 Subject: [PATCH 7/8] Fixed typo --- controllers/modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/modules.php b/controllers/modules.php index a8ec85ab..45c736d9 100644 --- a/controllers/modules.php +++ b/controllers/modules.php @@ -1,7 +1,7 @@ ' ); From 18601aa9e17926a3e739f9a035a0514174e8b9a3 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Thu, 28 Jan 2016 11:53:52 +0100 Subject: [PATCH 8/8] Changed module mink --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea50ece6..80369124 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Runs as a php script on a web server with basically no external dependencies. *C ##Configuration -Modify `js/config.js` to change some general variables (language, weather location, compliments, news feed RSS and to add your own ICS calendar) +Modify `js/config.js` to change some general variables (language, weather location, compliments, news feed RSS and to add your own ICS calendars) To use the OpenWeatherMap API, you'll need a free API key. Checkout [this blogpost](http://michaelteeuw.nl/post/131504229357/what-happened-to-the-weather) for more information. @@ -46,7 +46,7 @@ Takes the user's inserted location, language, unit type, and OpenWeatherMap API ##Modules -###[MagicMirror-Extensions by PaViRo](https://github.com/paviro/MagicMirror-Extensions) +###[MagicMirror-Modules by PaViRo](https://github.com/paviro/MagicMirror-Modules) **Current features:** FRITZ!Box Callmonitor
**Future features:** Faceregognition, personalized views, online banking through HBCI and multiple calenders based on faceregognition. \ No newline at end of file