From c3a1bfe492ab76349dbeb175b766a37918ca5060 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Tue, 27 Jun 2017 23:25:16 +0200 Subject: [PATCH] Updated to 1.0.3 version --- CHANGELOG.md | 6 +- README.md | 2 +- composer.json | 12 +- config/assets.php | 4 +- config/info.php | 21 -- config/menu.php | 4 +- config/namespaces.php | 8 +- config/paths.php | 9 +- .../default.php => config/set-hooks.php | 16 +- config/{hooks.php => settings.php} | 9 +- eliasis-wordpress-plugin.php | 31 +- lib/vendor/composer/installed.json | 355 +++++++++--------- lib/vendor/composer/installers/.travis.yml | 17 +- .../eliasis-framework/eliasis/VERSION.txt | 2 +- .../eliasis-framework/eliasis/composer.json | 5 +- .../eliasis-framework/eliasis/config/info.php | 4 +- .../eliasis/config/modules.php | 20 + .../eliasis-framework/eliasis/src/App/App.php | 241 ++++++++---- .../eliasis/src/Controller/Controller.php | 9 +- .../eliasis/src/Model/Model.php | 42 ++- .../src/Module/Exception/ModuleException.php | 40 -- .../eliasis/src/Module/Module.php | 272 -------------- .../eliasis/src/View/View.php | 57 ++- lib/vendor/josantonius/hook/composer.json | 5 +- lib/vendor/josantonius/hook/src/Hook.php | 285 +++++++++----- lib/vendor/josantonius/json/composer.json | 2 +- lib/vendor/josantonius/json/src/Json.php | 29 +- lib/vendor/josantonius/url/composer.json | 2 +- lib/vendor/josantonius/url/src/Url.php | 69 +++- lib/vendor/josantonius/wp_menu/composer.json | 2 +- .../josantonius/wp_menu/src/WP_Menu.php | 190 ++++++++-- .../josantonius/wp_register/composer.json | 2 +- .../wp_register/src/WP_Register.php | 36 +- .../Admin/Page/{ => Options}/Options.php | 90 ++--- src/Controller/Launcher.php | 234 ------------ src/Controller/Launcher/Launcher.php | 181 +++++++++ src/Controller/Uninstall/Uninstall.php | 35 ++ .../Admin/Page/{ => Options}/Options.php | 6 +- src/Model/Launcher/Launcher.php | 51 +++ .../Uninstall}/Uninstall.php | 17 +- src/template/{elements => layout}/footer.php | 0 src/template/{elements => layout}/header.php | 0 src/template/{pages => page}/options.php | 2 +- uninstall.php | 6 +- 44 files changed, 1300 insertions(+), 1130 deletions(-) delete mode 100644 config/info.php rename src/template/layout/default.php => config/set-hooks.php (53%) rename config/{hooks.php => settings.php} (57%) create mode 100644 lib/vendor/eliasis-framework/eliasis/config/modules.php delete mode 100644 lib/vendor/eliasis-framework/eliasis/src/Module/Exception/ModuleException.php delete mode 100644 lib/vendor/eliasis-framework/eliasis/src/Module/Module.php rename src/Controller/Admin/Page/{ => Options}/Options.php (58%) delete mode 100644 src/Controller/Launcher.php create mode 100644 src/Controller/Launcher/Launcher.php create mode 100644 src/Controller/Uninstall/Uninstall.php rename src/Model/Admin/Page/{ => Options}/Options.php (82%) create mode 100644 src/Model/Launcher/Launcher.php rename src/{Controller => Model/Uninstall}/Uninstall.php (70%) rename src/template/{elements => layout}/footer.php (100%) rename src/template/{elements => layout}/header.php (100%) rename src/template/{pages => page}/options.php (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c6bbe2..4f8ebf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # CHANGELOG -## 1.0.0 - 2017-05-04 +## 1.0.3 - 2017-06-27 + +* Eliasis Framework has been updated to version 1.1.0. + +## 1.0.2 - 2017-05-04 * Eliasis Framework has been updated to version 1.0.5. diff --git a/README.md b/README.md index f3c138d..a98c967 100644 --- a/README.md +++ b/README.md @@ -98,4 +98,4 @@ This project is licensed under **GPL-2.0+**. See the [LICENSE](LICENSE) file for If you find it useful, let me know :wink: -You can contact me on [Twitter](https://twitter.com/Josantonius) or through my [email](mailto:hello@josantonius.com). \ No newline at end of file +You can contact me on [Twitter](https://twitter.com/Josantonius) or through my [email](mailto:hello@josantonius.com). diff --git a/composer.json b/composer.json index 89c9627..c606881 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "eliasis-framework/wordpress-plugin", - "version": "1.0.2", + "version": "1.0.3", "description": "Skeleton for create WordPress plugins with Eliasis Framework", "type": "wordpress-plugin", "keywords": [ @@ -31,11 +31,11 @@ }, "require": { "php": "^5.3 || ^7.0", - "eliasis-framework/eliasis" : "^1.0.5", - "Josantonius/Json" : "^1.1.1", - "Josantonius/Hook" : "^1.0.1", - "Josantonius/WP_Register" : "^1.0.0", - "Josantonius/WP_Menu" : "^1.0.0", + "eliasis-framework/eliasis" : "^1.1.0", + "Josantonius/Json" : "^1.1.2", + "Josantonius/Hook" : "^1.0.5", + "Josantonius/WP_Register" : "^1.0.2", + "Josantonius/WP_Menu" : "^1.0.3", "composer/installers" : "master" }, "autoload": { diff --git a/config/assets.php b/config/assets.php index e470dff..7e91138 100644 --- a/config/assets.php +++ b/config/assets.php @@ -11,8 +11,8 @@ use Eliasis\App\App; -$css = App::EliasisWordPress('url', 'css'); -$js = App::EliasisWordPress('url', 'js'); +$css = App::EliasisWordPress()->get('url', 'css'); +$js = App::EliasisWordPress()->get('url', 'js'); return [ diff --git a/config/info.php b/config/info.php deleted file mode 100644 index ce68a6d..0000000 --- a/config/info.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - - 'name' => dirname(dirname(plugin_basename( __FILE__))), - 'version' => '1.0.0', - 'minimum_wp_version' => '3.8', - 'minimum_php_version' => '5.3', - ], -]; diff --git a/config/menu.php b/config/menu.php index 1a64017..adc0301 100644 --- a/config/menu.php +++ b/config/menu.php @@ -11,9 +11,7 @@ use Eliasis\App\App; -$textdomain = App::EliasisWordPress('plugin', 'name'); - -$iconsUrl = App::EliasisWordPress('url', 'icons'); +$iconsUrl = App::EliasisWordPress()->get('url', 'icons'); return [ diff --git a/config/namespaces.php b/config/namespaces.php index 82e75cb..0cc7ee9 100644 --- a/config/namespaces.php +++ b/config/namespaces.php @@ -9,11 +9,13 @@ * @since 1.0.0 */ +$pluginName = 'EliasisWordPress'; + return [ - 'namespace' => [ + 'namespaces' => [ - 'admin-page' => 'EliasisWordPress\\Controller\\Admin\\Page\\', - 'controller' => 'EliasisWordPress\\Controller\\', + 'admin-page' => $pluginName . '\\Controller\\Admin\\Page\\', + 'controller' => $pluginName . '\\Controller\\', ], ]; diff --git a/config/paths.php b/config/paths.php index b0037b0..e45c060 100644 --- a/config/paths.php +++ b/config/paths.php @@ -18,10 +18,9 @@ 'path' => [ - 'public' => $ROOT.'public' .$DS, - 'json' => $ROOT.'public' .$DS.'json' .$DS, - 'layout' => $ROOT.'src' .$DS.'template'.$DS.'layout' .$DS, - 'pages' => $ROOT.'src' .$DS.'template'.$DS.'pages' .$DS, - 'elements' => $ROOT.'src' .$DS.'template'.$DS.'elements'.$DS, + 'public' => $ROOT.'public'.$DS, + 'json' => $ROOT.'public'.$DS.'json' .$DS, + 'layout' => $ROOT.'src' .$DS.'template'.$DS.'layout' .$DS, + 'page' => $ROOT.'src' .$DS.'template'.$DS.'page' .$DS, ], ]; diff --git a/src/template/layout/default.php b/config/set-hooks.php similarity index 53% rename from src/template/layout/default.php rename to config/set-hooks.php index b8e7722..2df1308 100644 --- a/src/template/layout/default.php +++ b/config/set-hooks.php @@ -6,11 +6,19 @@ * @copyright Copyright (c) 2017 * @license GPL-2.0+ * @link https://github.com/Eliasis-Framework/WordPress-Plugin.git - * @since 1.0.0 + * @since 1.0.3 */ use Eliasis\App\App; -require(App::EliasisWordPress('path', 'elements') . 'header.php'); -require(App::EliasisWordPress('path', 'pages') . 'options.php'); -require(App::EliasisWordPress('path', 'elements') . 'footer.php'); +$namespace = App::EliasisWordPress()->get('namespaces', 'admin-page'); + +$Options = $namespace . 'Options\Options'; + +return [ + + 'hooks' => [ + + ['example', [$Options, 'example'], 8, 0], + ] +]; diff --git a/config/hooks.php b/config/settings.php similarity index 57% rename from config/hooks.php rename to config/settings.php index f9a600b..b1aeea0 100644 --- a/config/hooks.php +++ b/config/settings.php @@ -6,12 +6,13 @@ * @copyright Copyright (c) 2017 * @license GPL-2.0+ * @link https://github.com/Eliasis-Framework/WordPress-Plugin.git - * @since 1.0.0 + * @since 1.0.3 */ return [ - 'hooks' => [ - 'example', - ], + 'slug' => dirname(dirname(plugin_basename( __FILE__))), + 'version' => '1.0.3', + 'minimum_wp_version' => '3.8', + 'minimum_php_version' => '5.3', ]; diff --git a/eliasis-wordpress-plugin.php b/eliasis-wordpress-plugin.php index 929aaa8..cfdec54 100644 --- a/eliasis-wordpress-plugin.php +++ b/eliasis-wordpress-plugin.php @@ -16,6 +16,8 @@ use Eliasis\App\App; +$DS = DIRECTORY_SEPARATOR; + /** * Don't expose information if this file called directly. */ @@ -24,23 +26,30 @@ echo 'I can do when called directly.'; die; } -$DS = DIRECTORY_SEPARATOR; - -define('ELIASIS_WP', 'EliasisWordPress'); - +/** + * Classloader. + */ require 'lib' . $DS . 'vendor' . $DS .'autoload.php'; -App::run(__DIR__, 'wordpress-plugin', ELIASIS_WP); - -$namespace = App::EliasisWordPress('namespace', 'controller'); - -$method = $namespace . 'Launcher::getInstance'; +/** + * Start application. + */ +App::run(__DIR__, 'wordpress-plugin', 'EliasisWordPress'); -$Launcher = call_user_func($method); +/** + * Get main instance. + */ +$Launcher = App::instance('Launcher', 'controller'); +/** + * Register hooks. + */ register_activation_hook(__FILE__, [$Launcher, 'activation']); register_deactivation_hook(__FILE__, [$Launcher, 'deactivation']); - + +/** + * Launch application. + */ $Launcher->init(); ?> \ No newline at end of file diff --git a/lib/vendor/composer/installed.json b/lib/vendor/composer/installed.json index f67a303..cc9a970 100644 --- a/lib/vendor/composer/installed.json +++ b/lib/vendor/composer/installed.json @@ -1,164 +1,4 @@ [ - { - "name": "josantonius/json", - "version": "1.1.1", - "version_normalized": "1.1.1.0", - "source": { - "type": "git", - "url": "https://github.com/Josantonius/PHP-Json.git", - "reference": "caecc1670322737229f06623d4d326f3ded60c80" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Josantonius/PHP-Json/zipball/caecc1670322737229f06623d4d326f3ded60c80", - "reference": "caecc1670322737229f06623d4d326f3ded60c80", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "time": "2017-03-18 17:14:43", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-4": { - "Josantonius\\Json\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Josantonius", - "email": "hello@josantonius.com", - "homepage": "https://josantonius.com", - "role": "Developer" - } - ], - "description": "PHP simple library for managing Json files.", - "keywords": [ - "Array to file", - "File to array", - "JavaScript Object Notation", - "data exchange", - "hhvm", - "javascript", - "json", - "php" - ] - }, - { - "name": "josantonius/url", - "version": "1.1.1", - "version_normalized": "1.1.1.0", - "source": { - "type": "git", - "url": "https://github.com/Josantonius/PHP-Url.git", - "reference": "a2f83106d22078195781dc347456691cfc3edeca" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Josantonius/PHP-Url/zipball/a2f83106d22078195781dc347456691cfc3edeca", - "reference": "a2f83106d22078195781dc347456691cfc3edeca", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "time": "2017-03-18 17:16:52", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-4": { - "Josantonius\\Url\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Josantonius", - "email": "hello@josantonius.com", - "homepage": "https://josantonius.com", - "role": "Developer" - } - ], - "description": "Library for urls manipulation.", - "keywords": [ - "hhvm", - "https", - "path", - "php", - "uri", - "url" - ] - }, - { - "name": "eliasis-framework/eliasis", - "version": "dev-master", - "version_normalized": "9999999-dev", - "source": { - "type": "git", - "url": "https://github.com/Eliasis-Framework/Eliasis.git", - "reference": "37f2bfa11e68a11f83895f3aa49e76c530c9613d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Eliasis-Framework/Eliasis/zipball/37f2bfa11e68a11f83895f3aa49e76c530c9613d", - "reference": "37f2bfa11e68a11f83895f3aa49e76c530c9613d", - "shasum": "" - }, - "require": { - "josantonius/url": "^1.1.1", - "php": "^5.6 || ^7.0" - }, - "time": "2017-04-29 21:06:11", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-4": { - "Eliasis\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Josantonius", - "email": "hello@josantonius.com", - "homepage": "https://josantonius.com", - "role": "Developer" - } - ], - "description": "Eliasis PHP Framework", - "keywords": [ - "Eliasis", - "framework", - "hmvc", - "php" - ] - }, { "name": "josantonius/hook", "version": "dev-master", @@ -166,18 +6,18 @@ "source": { "type": "git", "url": "https://github.com/Josantonius/PHP-Hook.git", - "reference": "9b4fcc1062b92141c4151fd397311d8446e29a34" + "reference": "c3489456ec2d964467ddc1ee75573b5f694537e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Josantonius/PHP-Hook/zipball/9b4fcc1062b92141c4151fd397311d8446e29a34", - "reference": "9b4fcc1062b92141c4151fd397311d8446e29a34", + "url": "https://api.github.com/repos/Josantonius/PHP-Hook/zipball/c3489456ec2d964467ddc1ee75573b5f694537e7", + "reference": "c3489456ec2d964467ddc1ee75573b5f694537e7", "shasum": "" }, "require": { "php": "^5.6 || ^7.0" }, - "time": "2017-03-20 07:37:59", + "time": "2017-06-26 02:16:52", "type": "library", "extra": { "branch-alias": { @@ -204,7 +44,10 @@ ], "description": "Library for handling hooks.", "keywords": [ + "Action Hooks", "HOOK", + "actions", + "hhvm", "php" ] }, @@ -215,18 +58,18 @@ "source": { "type": "git", "url": "https://github.com/Josantonius/WP_Register.git", - "reference": "d0d26e981a3e05ac0b3f22e65d4728d38cf8cd5c" + "reference": "272cb8566e8e7607359242e72deb260337cf917a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Josantonius/WP_Register/zipball/d0d26e981a3e05ac0b3f22e65d4728d38cf8cd5c", - "reference": "d0d26e981a3e05ac0b3f22e65d4728d38cf8cd5c", + "url": "https://api.github.com/repos/Josantonius/WP_Register/zipball/272cb8566e8e7607359242e72deb260337cf917a", + "reference": "272cb8566e8e7607359242e72deb260337cf917a", "shasum": "" }, "require": { "php": "^5.6 || ^7.0" }, - "time": "2017-03-27 08:55:55", + "time": "2017-06-17 18:10:59", "type": "library", "extra": { "branch-alias": { @@ -271,18 +114,18 @@ "source": { "type": "git", "url": "https://github.com/Josantonius/WP_Menu.git", - "reference": "560796cbe20e5327ed2c4ae20114a1bd651feb17" + "reference": "ae483bbac2fda294ea11ea611dc3375e56b6ae4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Josantonius/WP_Menu/zipball/560796cbe20e5327ed2c4ae20114a1bd651feb17", - "reference": "560796cbe20e5327ed2c4ae20114a1bd651feb17", + "url": "https://api.github.com/repos/Josantonius/WP_Menu/zipball/ae483bbac2fda294ea11ea611dc3375e56b6ae4a", + "reference": "ae483bbac2fda294ea11ea611dc3375e56b6ae4a", "shasum": "" }, "require": { "php": "^5.6 || ^7.0" }, - "time": "2017-03-30 01:00:10", + "time": "2017-05-28 22:23:55", "type": "library", "extra": { "branch-alias": { @@ -323,12 +166,12 @@ "source": { "type": "git", "url": "https://github.com/composer/installers.git", - "reference": "7a80a104e3da0a4dc0ce9a88fe09968b1b34aafb" + "reference": "ae73c5dfec9279bd4c35a49a49fcb6568aa8aba4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/installers/zipball/7a80a104e3da0a4dc0ce9a88fe09968b1b34aafb", - "reference": "7a80a104e3da0a4dc0ce9a88fe09968b1b34aafb", + "url": "https://api.github.com/repos/composer/installers/zipball/ae73c5dfec9279bd4c35a49a49fcb6568aa8aba4", + "reference": "ae73c5dfec9279bd4c35a49a49fcb6568aa8aba4", "shasum": "" }, "require": { @@ -342,7 +185,7 @@ "composer/composer": "1.0.*@dev", "phpunit/phpunit": "4.1.*" }, - "time": "2017-04-24 15:53:06", + "time": "2017-06-07 10:23:00", "type": "composer-plugin", "extra": { "class": "Composer\\Installers\\Plugin", @@ -431,5 +274,165 @@ "zend", "zikula" ] + }, + { + "name": "josantonius/url", + "version": "1.1.2", + "version_normalized": "1.1.2.0", + "source": { + "type": "git", + "url": "https://github.com/Josantonius/PHP-Url.git", + "reference": "2893ec8de40206c4c9d9d4989c391d1e27ce37d8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Josantonius/PHP-Url/zipball/2893ec8de40206c4c9d9d4989c391d1e27ce37d8", + "reference": "2893ec8de40206c4c9d9d4989c391d1e27ce37d8", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "time": "2017-05-09 14:19:44", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Josantonius\\Url\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josantonius", + "email": "hello@josantonius.com", + "homepage": "https://josantonius.com", + "role": "Developer" + } + ], + "description": "Library for urls manipulation.", + "keywords": [ + "hhvm", + "https", + "path", + "php", + "uri", + "url" + ] + }, + { + "name": "eliasis-framework/eliasis", + "version": "1.1.0", + "version_normalized": "1.1.0.0", + "source": { + "type": "git", + "url": "https://github.com/Eliasis-Framework/Eliasis.git", + "reference": "c955eda920a03fb17af7abb9f119b5ace93ae675" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Eliasis-Framework/Eliasis/zipball/c955eda920a03fb17af7abb9f119b5ace93ae675", + "reference": "c955eda920a03fb17af7abb9f119b5ace93ae675", + "shasum": "" + }, + "require": { + "josantonius/url": "^1.1.2", + "php": "^5.6 || ^7.0" + }, + "time": "2017-06-26 02:38:04", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Eliasis\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josantonius", + "email": "hello@josantonius.com", + "homepage": "https://josantonius.com", + "role": "Developer" + } + ], + "description": "Eliasis PHP Framework", + "keywords": [ + "Eliasis", + "framework", + "hmvc", + "php" + ] + }, + { + "name": "josantonius/json", + "version": "1.1.2", + "version_normalized": "1.1.2.0", + "source": { + "type": "git", + "url": "https://github.com/Josantonius/PHP-Json.git", + "reference": "3bd96f56e4157d774321d78cf5fc86191378ef66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Josantonius/PHP-Json/zipball/3bd96f56e4157d774321d78cf5fc86191378ef66", + "reference": "3bd96f56e4157d774321d78cf5fc86191378ef66", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "time": "2017-05-31 06:39:12", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Josantonius\\Json\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josantonius", + "email": "hello@josantonius.com", + "homepage": "https://josantonius.com", + "role": "Developer" + } + ], + "description": "PHP simple library for managing Json files.", + "keywords": [ + "Array to file", + "File to array", + "JavaScript Object Notation", + "data exchange", + "hhvm", + "javascript", + "json", + "php" + ] } ] diff --git a/lib/vendor/composer/installers/.travis.yml b/lib/vendor/composer/installers/.travis.yml index c2ec2d1..931191d 100644 --- a/lib/vendor/composer/installers/.travis.yml +++ b/lib/vendor/composer/installers/.travis.yml @@ -1,21 +1,30 @@ language: php +sudo: false + +dist: trusty + +git: + depth: 5 + php: - - 5.3 - 5.4 - 5.5 - 5.6 - 7.0 - 7.1 - hhvm + - nightly matrix: + include: + - dist: precise + php: 5.3 fast_finish: true allow_failures: - - php: 7.0 - - php: 7.1 + - php: nightly -before_script: +before_script: - composer self-update - composer install diff --git a/lib/vendor/eliasis-framework/eliasis/VERSION.txt b/lib/vendor/eliasis-framework/eliasis/VERSION.txt index 066a83f..bf93eb5 100644 --- a/lib/vendor/eliasis-framework/eliasis/VERSION.txt +++ b/lib/vendor/eliasis-framework/eliasis/VERSION.txt @@ -9,4 +9,4 @@ # @since 1.0.0 # # # ############################################################################ -1.0.5 \ No newline at end of file +1.0.8 \ No newline at end of file diff --git a/lib/vendor/eliasis-framework/eliasis/composer.json b/lib/vendor/eliasis-framework/eliasis/composer.json index b4d5e0c..aaade2c 100644 --- a/lib/vendor/eliasis-framework/eliasis/composer.json +++ b/lib/vendor/eliasis-framework/eliasis/composer.json @@ -1,6 +1,6 @@ { "name": "eliasis-framework/eliasis", - "version": "1.0.5", + "version": "1.1.0", "description": "Eliasis PHP Framework", "type": "library", "keywords": [ @@ -24,12 +24,13 @@ "source": "https://github.com/eliasis-framework/eliasis" }, "config": { + "vendor-dir": "lib/vendor", "preferred-install": "dist" }, "minimum-stability": "stable", "require": { "php": "^5.6 || ^7.0", - "Josantonius/Url" : "^1.1.1" + "Josantonius/Url" : "^1.1.2" }, "autoload": { "psr-4": { diff --git a/lib/vendor/eliasis-framework/eliasis/config/info.php b/lib/vendor/eliasis-framework/eliasis/config/info.php index b0211dd..4a33531 100644 --- a/lib/vendor/eliasis-framework/eliasis/config/info.php +++ b/lib/vendor/eliasis-framework/eliasis/config/info.php @@ -11,12 +11,10 @@ use Eliasis\App\App; -$versionFile = file(dirname(__DIR__) . App::DS . 'VERSION.txt'); - return [ 'eliasis' => [ - 'version' => trim(array_pop($versionFile)), + 'version' => '1.1.0', ], ]; diff --git a/lib/vendor/eliasis-framework/eliasis/config/modules.php b/lib/vendor/eliasis-framework/eliasis/config/modules.php new file mode 100644 index 0000000..3919a0d --- /dev/null +++ b/lib/vendor/eliasis-framework/eliasis/config/modules.php @@ -0,0 +1,20 @@ + [ + + 'default-state' => 'active', + 'default-action' => 'activation', + 'states-file' => '.modules-states.jsond', + ], +]; diff --git a/lib/vendor/eliasis-framework/eliasis/src/App/App.php b/lib/vendor/eliasis-framework/eliasis/src/App/App.php index b2b444f..1510527 100644 --- a/lib/vendor/eliasis-framework/eliasis/src/App/App.php +++ b/lib/vendor/eliasis-framework/eliasis/src/App/App.php @@ -25,16 +25,16 @@ class App { * * @since 1.0.2 * - * @var object + * @var array */ - protected static $instance; + protected static $instances; /** * Unique id for the application. * * @since 1.0.0 * - * @var object + * @var string */ public static $id; @@ -45,7 +45,7 @@ class App { * * @var array */ - protected static $settings = []; + protected $settings = []; /** * Set directory separator constant. @@ -65,9 +65,12 @@ class App { */ public static function getInstance() { - NULL === self::$instance and self::$instance = new self; + if (!isset(self::$instances[self::$id])) { + + self::$instances[self::$id] = new self; + } - return static::$instance; + return self::$instances[self::$id]; } /** @@ -83,33 +86,35 @@ public static function run($baseDirectory, $type = 'app', $id = '0') { self::$id = $id; - $instance = self::getInstance(); + $that = self::getInstance(); - $instance->_setPaths($baseDirectory); + $that->_setPaths($baseDirectory, $that); - $instance->_setUrls($baseDirectory, $type); + $that->_setUrls($baseDirectory, $type, $that); - $instance->_runErrorHandler(); + $that->_runErrorHandler(); - $instance->_runCleaner(); + $that->_runCleaner(); - $instance->_getSettings(); + $that->_getSettings($that); - $instance->_runHooks(); + $that->_runHooks($that); - $instance->_runModules(); + $that->_runModules(); - $instance->_runRoutes(); + $that->_runRoutes($that); } /** * Error Handler. * * @since 1.0.1 + * + * @link https://github.com/Josantonius/PHP-ErrorHandler */ private function _runErrorHandler() { - if (class_exists($class='Josantonius\\ErrorHandler\\ErrorHandler')) { + if (class_exists($class='Josantonius\ErrorHandler\ErrorHandler')) { new $class; } @@ -119,10 +124,12 @@ private function _runErrorHandler() { * Cleaning resources. * * @since 1.0.1 + * + * @link https://github.com/Josantonius/PHP-Cleaner */ private function _runCleaner() { - if (class_exists($Cleaner = 'Josantonius\\Cleaner\\Cleaner')) { + if (class_exists($Cleaner = 'Josantonius\Cleaner\Cleaner')) { $Cleaner::removeMagicQuotes(); $Cleaner::unregisterGlobals(); @@ -135,13 +142,13 @@ private function _runCleaner() { * @since 1.0.1 * * @param string $baseDirectory → directory where class is instantiated + * @param object $that → application instance */ - private function _setPaths($baseDirectory) { + private function _setPaths($baseDirectory, $that) { - $baseUrl = Url::getBaseUrl(); - - self::addOption("ROOT", $baseDirectory . App::DS); - self::addOption("CORE", dirname(dirname(__DIR__)) . App::DS); + $that->set("ROOT", $baseDirectory . App::DS); + $that->set("CORE", dirname(dirname(__DIR__)) . App::DS); + $that->set("MODULES", App::ROOT() . 'modules' . App::DS); } /** @@ -151,13 +158,14 @@ private function _setPaths($baseDirectory) { * * @param string $baseDirectory → directory where class is instantiated * @param string $type → application type + * @param object $that → application instance */ - private function _setUrls($baseDirectory, $type) { + private function _setUrls($baseDirectory, $type, $that) { switch ($type) { case 'wordpress-plugin': - $baseUrl = plugins_url(basename($baseDirectory)) . App::DS; + $baseUrl = plugins_url(basename($baseDirectory)) . '/'; break; default: @@ -165,16 +173,18 @@ private function _setUrls($baseDirectory, $type) { break; } - self::addOption("MODULES_URL", $baseUrl . 'modules' . App::DS); - self::addOption("PUBLIC_URL", $baseUrl . 'public' . App::DS); + $that->set("MODULES_URL", $baseUrl . 'modules/'); + $that->set("PUBLIC_URL", $baseUrl . 'public/'); } /** * Get settings. * * @since 1.0.0 + * + * @param object $that → application instance */ - private function _getSettings() { + private function _getSettings($that) { $path = [ @@ -192,11 +202,7 @@ private function _getSettings() { $config = require($dir . $file); - self::$settings[self::$id] = array_merge( - - self::$settings[self::$id], - $config - ); + $that->settings = array_merge($that->settings, $config); } } } @@ -205,13 +211,24 @@ private function _getSettings() { /** * Load hooks. * - * @since 1.0.1 + * @since 1.1.0 + * + * @param object $that → application instance + * + * @link https://github.com/Josantonius/PHP-Hook */ - private function _runHooks() { + private function _runHooks($that) { + + if (class_exists($Hook = 'Josantonius\Hook\Hook')) { + + $Hook::getInstance(self::$id); - if (class_exists($Hook = 'Josantonius\\Hook\\Hook')) { + if (isset($that->settings['hooks'])) { - $Hook::getInstance(); + $Hook::addActions($that->settings['hooks']); + + unset($that->settings['hooks']); + } } } @@ -219,28 +236,38 @@ private function _runHooks() { * Load Modules. * * @since 1.0.1 + * + * @link https://github.com/Eliasis-Framework/Module */ private function _runModules() { - $Module = 'Eliasis\\Module\\Module'; + if (is_dir($modulesPath = App::ROOT() . 'modules' . App::DS)) { - $Module::loadModules(self::path('modules')); - } + if (class_exists($Module = 'Eliasis\Module\Module')) { + + $Module::loadModules($modulesPath); + } + } + } /** * Load Routes. * * @since 1.0.1 + * + * @param object $that → application instance + * + * @link https://github.com/Josantonius/PHP-Router */ - private function _runRoutes() { + private function _runRoutes($that) { - if (class_exists($Router = 'Josantonius\\Router\\Router')) { + if (class_exists($Router = 'Josantonius\Router\Router')) { - if (isset(self::$settings[self::$id]['routes'])) { + if (isset($that->settings['routes'])) { - $Router::addRoute(self::$settings[self::$id]['routes']); + $Router::addRoute($that->settings['routes']); - unset(self::$settings[self::$id]['routes']); + unset($that->settings['routes']); $Router::dispatch(); } @@ -250,26 +277,107 @@ private function _runRoutes() { /** * Define new configuration settings. * - * @since 1.0.0 + * @since 1.0.9 * * @param string $option → option name or options array * @param mixed $value → value/s * - * @return + * @return mixed */ - public static function addOption($option, $value) { + public static function set($option, $value) { + + $that = self::getInstance(); + + if (!is_array($value)) { + + return $that->settings[$option] = $value; + } + + if (array_key_exists($option, $value)) { + + $that->settings[$option] = array_merge_recursive( - if (is_array($value)) { + $that->settings[$option], $value + ); + + } else { foreach ($value as $key => $value) { - self::$settings[self::$id][$option][$key] = $value; + $that->settings[$option][$key] = $value; + } + } + + return $that->settings[$option]; + } + + /** + * Get options saved. + * + * @since 1.0.9 + * + * @param array $params + * + * @return mixed + */ + public static function get(...$params) { + + $that = self::getInstance(); + + $key = array_shift($params); + + $col[] = isset($that->settings[$key]) ? $that->settings[$key] : 0; + + if (!count($params)) { + + return ($col[0]) ? $col[0] : ''; + } + + foreach ($params as $param) { + + $col = array_column($col, $param); + } + + return (isset($col[0])) ? $col[0] : ''; + } + + /** + * Get controller instance. + * + * @since 1.0.9 + * + * @param array $class → class name + * @param array $namespace → namespace index + * + * @return object|false → class instance or false + */ + public static function instance($class, $namespace = '') { + + $that = self::getInstance(); + + if (isset($that->settings['namespaces'])) { + + if (isset($that->settings['namespaces'][$namespace])) { + + $namespace = $that->settings['namespaces'][$namespace]; + + $class = $namespace . $class . '\\' . $class; + + return call_user_func([$class, 'getInstance']); } - return; + foreach ($that->settings['namespaces'] as $key => $namespace) { + + $instance = $namespace . $class . '\\' . $class; + + if (class_exists($instance)) { + + return call_user_func([$instance, 'getInstance']); + } + } } - self::$settings[self::$id][$option] = $value; + return false; } /** @@ -279,13 +387,13 @@ public static function addOption($option, $value) { * * @param string $id → application id * - * @return + * @return string → application id */ public static function id($id) { - self::$id = $id; + return self::$id = $id; } - + /** * Access the configuration parameters. * @@ -296,28 +404,19 @@ public static function id($id) { * * @return mixed */ - public static function __callstatic($index, $params = []) { + public static function __callstatic($index, $params = false) { - if (isset(self::$settings[$index])) { + if (array_key_exists($index, self::$instances)) { - self::$id = $index; - $index = array_shift($params); - } + self::id($index); - $settings = self::$settings[self::$id]; + $that = self::getInstance(); - $column[] = (isset($settings[$index])) ? $settings[$index] : null; - - if (!count($params)) { + return $that; + } - return (!is_null($column[0])) ? $column[0] : ''; - } + array_unshift($params, $index); - foreach ($params as $param) { - - $column = array_column($column, $param); - } - - return (isset($column[0])) ? $column[0] : ''; + return call_user_func_array([__CLASS__, 'get'], $params); } } diff --git a/lib/vendor/eliasis-framework/eliasis/src/Controller/Controller.php b/lib/vendor/eliasis-framework/eliasis/src/Controller/Controller.php index 7383c01..b3251f6 100644 --- a/lib/vendor/eliasis-framework/eliasis/src/Controller/Controller.php +++ b/lib/vendor/eliasis-framework/eliasis/src/Controller/Controller.php @@ -85,6 +85,8 @@ public static function getInstance() { * Get view instance. * * @since 1.0.0 + * + * @param object $instance → this */ protected static function getViewInstance($instance) { @@ -96,11 +98,14 @@ protected static function getViewInstance($instance) { * * @since 1.0.2 * + * @param object $instance → this + * @param string $controller → controller namespace + * * @return object → controller instance */ - protected static function getModelInstance($instance, $controller = '') { + protected static function getModelInstance($instance, $controller='') { - $controller = (empty($controller)) ? $controller : get_called_class(); + $controller = empty($controller) ? $controller : get_called_class(); $model = str_replace('Controller', 'Model', $controller); diff --git a/lib/vendor/eliasis-framework/eliasis/src/Model/Model.php b/lib/vendor/eliasis-framework/eliasis/src/Model/Model.php index fc1a0eb..4c23ce5 100644 --- a/lib/vendor/eliasis-framework/eliasis/src/Model/Model.php +++ b/lib/vendor/eliasis-framework/eliasis/src/Model/Model.php @@ -11,7 +11,8 @@ namespace Eliasis\Model; -use Eliasis\Model\Exception\ModelException; +use Eliasis\App\App, + Eliasis\Model\Exception\ModelException; /** * Model class. @@ -29,6 +30,15 @@ abstract class Model { */ protected static $instance; + /** + * Database instance. + * + * @since 1.0.6 + * + * @var object + */ + protected $db; + /** * Prevent creating a new model instance. * @@ -50,11 +60,41 @@ public static function getInstance() { if (!isset(self::$instance[$model])) { self::$instance[$model] = new $model; + + if (is_null(self::$instance[$model]->db)) { + + self::$instance[$model]->_getDatabaseInstance(); + } } return self::$instance[$model]; } + /** + * Get Database connection. + * + * This method will only be used if the Database class exists. + * + * @since 1.0.6 + * + * @uses Josantonius\\Database\\Database class + * + * @link https://github.com/Josantonius/PHP-Database + * + * @return object → controller instance + */ + private function _getDatabaseInstance() { + + if (class_exists($Database = 'Josantonius\\Database\\Database')) { + + $config = App::db(); + + $id = (is_array($config)) ? array_keys($config)[0] : 'app'; + + $this->db = $Database::getConnection($id); + } + } + /** * Prevents the object from being cloned. * diff --git a/lib/vendor/eliasis-framework/eliasis/src/Module/Exception/ModuleException.php b/lib/vendor/eliasis-framework/eliasis/src/Module/Exception/ModuleException.php deleted file mode 100644 index 266baef..0000000 --- a/lib/vendor/eliasis-framework/eliasis/src/Module/Exception/ModuleException.php +++ /dev/null @@ -1,40 +0,0 @@ -message = $msg; - $this->code = $error; - $this->statusCode = $status; - } -} diff --git a/lib/vendor/eliasis-framework/eliasis/src/Module/Module.php b/lib/vendor/eliasis-framework/eliasis/src/Module/Module.php deleted file mode 100644 index 4d99006..0000000 --- a/lib/vendor/eliasis-framework/eliasis/src/Module/Module.php +++ /dev/null @@ -1,272 +0,0 @@ -modules[App::$id][self::$moduleName] = $module; - - $instance->_getSettings(); - - $instance->_addResources(); - } - - /** - * Get modules info. - * - * @since 1.0.5 - * - * @return array $data → modules info - */ - public static function getModulesInfo() { - - $data = []; - - $instance = self::getInstance(); - - $modules = array_keys($instance->modules[App::$id]); - - foreach ($modules as $module) { - - $module = $instance->modules[App::$id][$module]; - - $name = $module['name']; - - $name = trim(implode(' ', preg_split("/(?=[A-Z])/", $name))); - - $data[] = [ - - 'id' => $module['name'], - 'name' => $name, - 'version' => $module['version'], - 'description' => $module['description'], - 'uri' => $module['uri'], - 'author' => $module['author'], - 'author-uri' => $module['author-uri'], - 'license' => $module['license'], - 'slug' => trim($module['folder'], App::DS), - ]; - } - - return $data; - } - - /** - * Get settings. - * - * @since 1.0.0 - */ - private function _getSettings() { - - $id = App::$id; - - $name = self::$moduleName; - - $path = $this->modules[$id][$name]['path'] . 'config'. App::DS; - - if (is_dir($path) && $handle = scandir($path)) { - - $files = array_slice($handle, 2); - - foreach ($files as $file) { - - $content = require($path . $file); - - $merge = array_merge($this->modules[$id][$name], $content); - - $this->modules[$id][$name] = $merge; - } - } - } - - /** - * Add module routes and hooks if exists. - * - * @since 1.0.1 - */ - private function _addResources() { - - $config = $this->modules[App::$id][self::$moduleName]; - - if (isset($config['hooks']) && count($config['hooks'])) { - - Hook::addHook($config['hooks']); - } - - if (isset($config['routes']) && count($config['routes'])) { - - Router::addRoute($config['routes']); - } - } - - /** - * Receives the name of the module to execute: Module::ModuleName(); - * - * @param string $index → module name - * @param array $params → params - * - * @throws ModuleException → Module not found - * - * @return mixed - */ - public static function __callstatic($index, $params = '') { - - $instance = self::getInstance(); - - if (!isset($instance->modules[App::$id][$index])) { - - $message = 'Module not found'; - throw new ModuleException($message . ': ' . $index . '.', 817); - } - - self::$moduleName = $index; - - $column[] = $instance->modules[App::$id][$index]; - - if (!count($params)) { - - return (!is_null($column[0])) ? $column[0] : ''; - } - - foreach ($params as $param) { - - $column = array_column($column, $param); - } - - return (isset($column[0])) ? $column[0] : ''; - } -} \ No newline at end of file diff --git a/lib/vendor/eliasis-framework/eliasis/src/View/View.php b/lib/vendor/eliasis-framework/eliasis/src/View/View.php index d96b964..c6802dc 100644 --- a/lib/vendor/eliasis-framework/eliasis/src/View/View.php +++ b/lib/vendor/eliasis-framework/eliasis/src/View/View.php @@ -2,8 +2,7 @@ /** * Eliasis PHP Framework * - * @author Josantonius - hello@josantonius.com - * @author Daveismyname - dave@daveismyname.com + * @author Josantonius - hello@josantonius.com * @copyright Copyright (c) 2017 * @license https://opensource.org/licenses/MIT - The MIT License (MIT) * @link https://github.com/Eliasis-Framework/Eliasis @@ -19,7 +18,7 @@ class View { * * @since 1.0.0 * - * @var object + * @var array */ protected static $instance; @@ -46,6 +45,8 @@ class View { * * @since 1.0.0 * + * @param string $controller → controller namespace + * * @return object → controller instance */ public static function getInstance() { @@ -60,21 +61,53 @@ public static function getInstance() { * * @since 1.0.0 * - * @param string $file → view name + * @param string $path → filepath + * @param string $file → filename * @param array $data → view content */ - public function renderizate($file, $data = '') { + public function renderizate($path, $file, $data = null) { + + $file = $path . $file . '.php'; - if (is_array($data)) { + if ($data) { - self::$data = $data; + self::$data[sha1($file)] = $data; } - $data = self::$data; + require_once $file; + } + + /** + * Get options saved. + * + * @since 1.0.9 + * + * @param array $params → parameters + * @param string $file → filepath + * + * @return mixed + */ + public static function get(...$params) { + + $trace = debug_backtrace(2, 1); + + $id = (isset($trace[0]['file'])) ? sha1($trace[0]['file']) : 0; + + $key = array_shift($params); - $path = $file . '.php'; + $col[] = isset(self::$data[$id][$key]) ? self::$data[$id][$key] : 0; - require $path; + if (!count($params)) { + + return ($col[0]) ? $col[0] : self::$data[$id]; + } + + foreach ($params as $param) { + + $col = array_column($col, $param); + } + + return (isset($col[0])) ? $col[0] : ''; } /** @@ -96,11 +129,11 @@ public function addHeader($header) { * * @param array $headers */ - public function addHeaders(array $headers = array()) { + public function addHeaders($headers = []) { self::$headers = array_merge(self::$headers, $headers); } - + /** * Send headers * diff --git a/lib/vendor/josantonius/hook/composer.json b/lib/vendor/josantonius/hook/composer.json index 2dd1784..27220d1 100644 --- a/lib/vendor/josantonius/hook/composer.json +++ b/lib/vendor/josantonius/hook/composer.json @@ -1,10 +1,13 @@ { "name": "josantonius/hook", - "version": "1.0.1", + "version": "1.0.5", "type": "library", "description": "Library for handling hooks.", "keywords": [ "Hook", + "Actions", + "Action Hooks", + "HHVM", "PHP" ], "license": "MIT", diff --git a/lib/vendor/josantonius/hook/src/Hook.php b/lib/vendor/josantonius/hook/src/Hook.php index 87c65f0..d796ec8 100644 --- a/lib/vendor/josantonius/hook/src/Hook.php +++ b/lib/vendor/josantonius/hook/src/Hook.php @@ -2,7 +2,6 @@ /** * Library for handling hooks. * - * @author Daveismyname - dave@daveismyname.com * @author Josantonius - hello@josantonius.com * @copyright Copyright (c) 2017 * @license https://opensource.org/licenses/MIT - The MIT License (MIT) @@ -22,22 +21,49 @@ class Hook { /** - * Available hooks. + * Instance id. * - * @since 1.0.0 + * @since 1.0.5 + * + * @var int + */ + protected static $id = '0'; + + /** + * Callbacks. + * + * @since 1.0.3 + * + * @var array + */ + protected $callbacks = []; + + /** + * Number of actions executed. + * + * @since 1.0.3 * * @var array */ - private static $_hooks = array(); + protected $actions = ['count' => 0]; + + /** + * Current action hook. + * + * @since 1.0.3 + * + * @var string|false + */ + protected static $current = false; /** - * Method name to use the singleton pattern and just create an instance. + * Method to use the singleton pattern and just create an instance. * * @since 1.0.0 * * @var string */ - private static $_singleton = 'getInstance'; + protected $singleton = 'getInstance'; /** * Instances. @@ -46,7 +72,7 @@ class Hook { * * @var array */ - private static $_instances = array(); + private static $_instances = []; /** * Get instance. @@ -57,24 +83,16 @@ class Hook { * * @return object → instance */ - public static function getInstance($id = 0) { + public static function getInstance($id = '0') { + + self::$id = $id; - if (isset(self::$_instances[$id])) { + if (isset(self::$_instances[self::$id])) { - return self::$_instances[$id]; + return self::$_instances[self::$id]; } - - self::setHook([ - 'meta', - 'css', - 'after-body', - 'footer', - 'js', - 'launch', - 'routes' - ]); - - return self::$_instances[$id] = new self; + + return self::$_instances[self::$id] = new self; } /** @@ -86,66 +104,50 @@ public static function getInstance($id = 0) { */ public static function setSingletonName($method) { - self::$_singleton = $method; + $that = self::getInstance(self::$id); + + $that->singleton = $method; } /** - * Add hook/hooks to hook list. + * Attach custom function to action hook. * - * @since 1.0.0 + * @since 1.0.3 * - * @param string|array $where → hook to add + * @param string $tag → action hook name + * @param callable $func → function to attach to action hook + * @param int $priority → order in which the action is executed + * @param int $args → number of arguments accepted * - * @return int → number hooks added + * @return boolean */ - public static function setHook($where) { + public static function addAction($tag, $func, $priority=8, $args=0) { - if (!is_array($where)) { + $that = self::getInstance(self::$id); - self::$_hooks[$where] = ''; + $that->callbacks[$tag][$priority][] = [ - return 1; - } - - foreach ($where as $where) { - - self::$_hooks[$where] = ''; - } - - return count($where); + 'function' => $func, + 'arguments' => $args + ]; + + return true; } /** - * Attach custom function to hook. + * Add actions hooks from array. * - * @since 1.0.0 + * @since 1.0.3 * - * @param array|string $where → hook to use - * @param string $function → function to attach to hook + * @param array $actions * - * @throws HookException → hook location not defined - * @return boolean → success with adding + * @return boolean */ - public static function addHook($where, $function = '') { + public static function addActions($actions) { - if (!is_array($where)) { + foreach ($actions as $arguments) { - $where = [$where => $function]; - } - - foreach ($where as $hook => $function) { - - if (!isset(self::$_hooks[$hook])) { - - $message = 'Hook location not defined'; - - throw new HookException($message . ': ' . $hook, 811); - } - - $theseHooks = explode('|', self::$_hooks[$hook]); - $theseHooks[] = $function; - - self::$_hooks[$hook] = implode('|', $theseHooks); + call_user_func_array([__CLASS__, 'addAction'], $arguments); } return true; @@ -154,84 +156,161 @@ public static function addHook($where, $function = '') { /** * Run all hooks attached to the hook. * - * By default it will look for the 'getInstance' method to use singleton + * By default it will look for getInstance method to use singleton * pattern and create a single instance of the class. If it does not * exist it will create a new object. * * @see setSingletonName() for change the method name. * - * @since 1.0.0 + * @since 1.0.3 * - * @param string $where → hook to run - * @param string $args → optional arguments + * @param string $tag → action hook name + * @param mixed $args → optional arguments + * @param boolean $remove → delete hook after executing actions * - * @throws HookException → the hook is not yet known - * @return object|false → returns the calling function + * @return returns the output of the last action or false */ - public static function run($where, $args='') { + public static function doAction($tag, $args = [], $remove = true) { - if (!isset(self::$_hooks[$where])) { + $that = self::getInstance(self::$id); - $message = 'Hook location not defined'; - - throw new HookException($message . ': ' . $where, 811); + self::$current = $tag; + + $that->actions['count']++; + + if (!array_key_exists($tag, $that->actions)) { + + $that->actions[$tag] = 0; + } + + $that->actions[$tag]++; + + $actions = $that->_getActions($tag, $remove); + + asort($actions); + + foreach ($actions as $priority) { + + foreach ($priority as $action) { + + $action = $that->_runAction($action, $args); + } } - $theseHooks = explode('|', self::$_hooks[$where]); + self::$current = false; + + return (isset($action)) ? $action : false; + } - foreach ($theseHooks as $hook) { + /** + * Run action hook. + * + * @since 1.0.3 + * + * @param string $action → action hook + * @param int $args → arguments + * + * @return callable|false → returns the calling function + */ + private function _runAction($action, $args) { - if (preg_match("/@/i", $hook)) { + $function = $action['function']; + $argsNumber = $action['arguments']; - $parts = explode('/', $hook); + $class = (isset($function[0])) ? $function[0] : false; + $method = (isset($function[1])) ? $function[1] : false; - $last = end($parts); + $args = $this->_getArguments($argsNumber, $args); - $segments = explode('@', $last); + if (!($class && $method) && function_exists($function)) { - $class = $segments[0]; + return call_user_func($function, $args); - $method = $segments[1]; + } else if ($obj = call_user_func([$class, $this->singleton])) { - if (method_exists($class, self::$_singleton)) { + if ($obj !== false) { - $instance = call_user_func([$class, self::$_singleton]); + return call_user_func_array([$obj, $method], $args); + } - call_user_func([$instance, $method], $args); + } else { - continue; - } + $instance = new $class; - $instance = new $class; + return call_user_func_array([$instance, $method], $args); + } + } - call_user_func([$instance, $method], $args); - - } else { + /** + * Get actions for hook + * + * @since 1.0.3 + * + * @param string $tag → action hook name + * @param boolean $remove → delete hook after executing actions + * + * @return object|false → returns the calling function + */ + private function _getActions($tag, $remove) { - if (function_exists($hook)) { + if (isset($this->callbacks[$tag])) { - call_user_func($hook, $result); - } + $actions = $this->callbacks[$tag]; + + if ($remove) { + + unset($this->callbacks[$tag]); } } + + return (isset($actions)) ? $actions : []; } /** - * Execute hooks attached to run and collect instead of running. + * Get arguments for action. * - * @since 1.0.0 + * @since 1.0.3 * - * @param string $where → hook - * @param string $args → optional arguments + * @param int $argsNumber → arguments number + * @param mixed $arguments → arguments * - * @return object → returns output of hook call + * @return array → arguments */ - public function collectHook($where, $args = null) { + private function _getArguments($argsNumber, $arguments) { + + if ($argsNumber == 1 && is_string($arguments)) { + + return [$arguments]; - ob_start(); + } else if ($argsNumber === count($arguments)) { + + return $arguments; + } + + for ($i=0; $i < $argsNumber; $i++) { + + if (array_key_exists($i, $arguments)) { + + $args[] = $arguments[$i]; - echo $this->run($where, $args); + continue; + } + + return $args; + } + + return []; + } + + /** + * Returns the current action hook. + * + * @since 1.0.3 + * + * @return string|false → current action hook + */ + public static function current() { - return ob_get_clean(); + return self::$current; } } diff --git a/lib/vendor/josantonius/json/composer.json b/lib/vendor/josantonius/json/composer.json index 911b45e..a0afa1d 100644 --- a/lib/vendor/josantonius/json/composer.json +++ b/lib/vendor/josantonius/json/composer.json @@ -1,6 +1,6 @@ { "name": "josantonius/json", - "version": "1.1.1", + "version": "1.1.2", "type": "library", "description": "PHP simple library for managing Json files.", "keywords": [ diff --git a/lib/vendor/josantonius/json/src/Json.php b/lib/vendor/josantonius/json/src/Json.php index 93572f0..1028de3 100644 --- a/lib/vendor/josantonius/json/src/Json.php +++ b/lib/vendor/josantonius/json/src/Json.php @@ -40,13 +40,15 @@ public static function arrayToFile($array, $pathfile) { mkdir($path, 0755, true); } - $json = json_encode($array); + $json = json_encode($array, JSON_PRETTY_PRINT); self::jsonLastError(); - if (!$file = fopen($pathfile, 'w+')) { + if (!$file = fopen($pathfile, 'w+')) { + + $message = 'Could not create file in'; - throw new JsonException('Could not create file in ' . $pathfile, 300); + throw new JsonException($message . ' ' . $pathfile, 605); } fwrite($file, $json); @@ -61,23 +63,22 @@ public static function arrayToFile($array, $pathfile) { * * @param string $pathfile → path to JSON file * - * @throws JsonException → there is no file - * @return array → JSON format + * @return array */ public static function fileToArray($pathfile) { - if (is_file($pathfile)) { + if (!is_file($pathfile)) { - $jsonString = file_get_contents($pathfile); - - $jsonArray = json_decode($jsonString, true); + self::arrayToFile([], $pathFile); + } - self::jsonLastError(); + $jsonString = file_get_contents($pathfile); + + $jsonArray = json_decode($jsonString, true); - return $jsonArray; - } + self::jsonLastError(); - throw new JsonException('File not found in ' . $pathfile, 605); + return $jsonArray; } /** @@ -108,4 +109,4 @@ public static function jsonLastError() { throw new JsonException('Unknown error', 995); } } -} \ No newline at end of file +} diff --git a/lib/vendor/josantonius/url/composer.json b/lib/vendor/josantonius/url/composer.json index 3e90ca2..926335a 100644 --- a/lib/vendor/josantonius/url/composer.json +++ b/lib/vendor/josantonius/url/composer.json @@ -1,6 +1,6 @@ { "name": "josantonius/url", - "version": "1.1.1", + "version": "1.1.2", "type": "library", "description": "Library for urls manipulation.", "keywords": [ diff --git a/lib/vendor/josantonius/url/src/Url.php b/lib/vendor/josantonius/url/src/Url.php index 78bba1b..8b2c6f9 100644 --- a/lib/vendor/josantonius/url/src/Url.php +++ b/lib/vendor/josantonius/url/src/Url.php @@ -21,6 +21,15 @@ */ class Url { + /** + * Directory separator. + * + * @since 1.1.2 + * + * @var string + */ + const DS = DIRECTORY_SEPARATOR; + /** * Get url from the current page. * @@ -30,17 +39,17 @@ class Url { */ public static function getCurrentPage() { - $protocol = static::getProtocol(); + $protocol = self::getProtocol(); - $host = static::getDomain(); + $host = self::getDomain(); - $port = ':' . static::getPort(); + $port = ':' . self::getPort(); $port = (($port == ':80') || ($port == ':443')) ? '' : $port; - $uri = static::getUri(); + $uri = self::getUri(); - return $protocol . '://' . $host . $port . $uri; + return $protocol . ':' . self::DS . self::DS . $host . $port . $uri; } /** @@ -52,11 +61,16 @@ public static function getCurrentPage() { */ public static function getBaseUrl() { - $uri = static::getUriMethods(); + $uri = self::addBackslash(self::getUriMethods(), 'both'); + + $url = self::addBackslash(self::getCurrentPage()); - $url = trim(str_replace($uri, '', static::getCurrentPage()), '/'); + if ($uri !== self::DS) { + + $url = trim(str_replace($uri, '', $url), self::DS); + } - return static::addBackslash($url); + return self::addBackslash($url); } /** @@ -70,7 +84,7 @@ public static function getProtocol() { $protocol = strtolower($_SERVER['SERVER_PROTOCOL']); - $protocol = substr($protocol, 0, strpos($protocol, '/')); + $protocol = substr($protocol, 0, strpos($protocol, self::DS)); $ssl = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'); @@ -86,7 +100,7 @@ public static function getProtocol() { */ public static function isSSL() { - return (static::getProtocol() === 'https'); + return (self::getProtocol() === 'https'); } /** @@ -122,9 +136,11 @@ public static function getUri() { */ public static function getUriMethods() { - $subfolder = trim(str_replace($_SERVER["DOCUMENT_ROOT"], '', getcwd()), '/'); + $root = str_replace($_SERVER["DOCUMENT_ROOT"], '', getcwd()); + + $subfolder = trim($root, self::DS); - return trim(str_replace($subfolder, '', static::getUri()), '/'); + return trim(str_replace($subfolder, '', self::getUri()), self::DS); } /** @@ -144,13 +160,30 @@ public static function getPort() { * * @since 1.0.0 * - * @param string $uri → url path - * - * @return string → path/url/ + * @param string $uri → url path + * @param string $position → place where the backslash is placed + * + * @return string → path/url/ | /path/url | /path/url/ */ - public static function addBackslash($uri = null) { + public static function addBackslash($uri, $position = 'end') { + + switch ($position) { + + case 'top': + + return (substr($uri, 1) === self::DS) ? $uri : self::DS.$uri; + + case 'end': + + return (substr($uri, -1) === self::DS) ? $uri : $uri.self::DS; - return (substr($uri, -1) === "/") ? $uri : $uri . "/"; + case 'both': + + $uri = self::addBackslash($uri, 'top'); + $uri = self::addBackslash($uri, 'end'); + + return $uri; + } } /** @@ -239,7 +272,7 @@ public static function segment($uri = null) { $uri = (!is_null($uri)) ? $uri : $_SERVER['REQUEST_URI']; - return explode('/', trim($uri, '/')); + return explode(self::DS, trim($uri, self::DS)); } /** diff --git a/lib/vendor/josantonius/wp_menu/composer.json b/lib/vendor/josantonius/wp_menu/composer.json index 80c1fc7..5465cdd 100644 --- a/lib/vendor/josantonius/wp_menu/composer.json +++ b/lib/vendor/josantonius/wp_menu/composer.json @@ -1,6 +1,6 @@ { "name": "josantonius/wp_menu", - "version": "1.0.0", + "version": "1.0.3", "type": "library", "description": "Add menu or submenu page in WordPress.", "keywords": [ diff --git a/lib/vendor/josantonius/wp_menu/src/WP_Menu.php b/lib/vendor/josantonius/wp_menu/src/WP_Menu.php index 956dd52..fa9930a 100644 --- a/lib/vendor/josantonius/wp_menu/src/WP_Menu.php +++ b/lib/vendor/josantonius/wp_menu/src/WP_Menu.php @@ -44,13 +44,20 @@ class WP_Menu { * string $data['icon_url'] // (optional) * int $data['position'] // (optional) * + * @param mixed $function → method to be called to output page content + * @param mixed $styles → method to be called to load page styles + * @param mixed $scripts → method to be called to load page scripts + * * @return boolean */ - public static function add($type, $data = [], $function = '') { + public static function add($type, $data = [], $function = '', $styles = '', $scripts = '') { $required = ['name', 'slug']; - if ($type === 'submenu') { array_push($required, 'parent'); } + if ($type === 'submenu') { + + array_push($required, 'parent'); + } foreach ($required as $field) { @@ -60,66 +67,71 @@ public static function add($type, $data = [], $function = '') { } } - if (!isset($data['title'])) { + $params = ['title', 'capability', 'icon_url', 'position']; - $data['title'] = $data['name']; - } + foreach ($params as $param) { - if (!isset($data['capability'])) { + if (isset($data[$param])) { continue; } - $data['capability'] = 'manage-options'; - } - - $data['function'] = $function; + switch ($param) { - $data['icon_url'] = isset($data['icon_url']) ? $data['icon_url'] : ''; - $data['position'] = isset($data['position']) ? $data['position'] : 20; - - self::$data[$type][$data['slug']] = $data; + case 'title': + $data[$param] = $data['name']; + break; - add_action('admin_menu', __CLASS__ .'::'. $type .'_'. $data['slug']); + case 'capability': + $data[$param] = 'manage-options'; + break; - return true; - } + case 'icon_url': + $data[$param] = ''; + break; - /** - * Validate permissions. - * - * @since 1.0.0 - * - * @uses current_user_can() → specific capability - * @uses wp_die() → kill WordPress execution and show error - */ - public static function checkPermissions($capability) { + case 'position': + $data[$param] = 20; + break; + } + } - if (!current_user_can($capability)) { + $function = (self::_validateMethod($function)) ? $function : ''; - $message = __('You don\'t have permissions to access this page.'); + $data['styles'] = $styles; + $data['scripts'] = $scripts; + $data['function'] = $function; - wp_die($message); - } + $slug = $data['slug']; + + self::$data[$type][$slug] = $data; + + add_action('admin_menu', function() use ($type, $slug) { + + self::_set($type, $slug); + }); + + return true; } /** - * Add menu and submenu admin. + * Set menu and submenu admin. * - * @param string $index - * @param array $params + * @since 1.0.1 + * + * @param string $type → menu|submenu + * @param string $slug */ - public static function __callstatic($index, $params = null) { - - $index = explode('_', $index); + private static function _set($type, $slug) { - $type = $index[0]; - $slug = $index[1]; + global $pagenow; $data = self::$data[$type][$slug]; - self::checkPermissions($data['capability']); + self::_checkPermissions($data['capability']); + + do_action('wp_menu/pre_add_' . $type . '_page'); if ($type === 'menu') { - add_menu_page( + $page = add_menu_page( $data['title'], $data['name'], $data['capability'], @@ -131,7 +143,7 @@ public static function __callstatic($index, $params = null) { } else { - add_submenu_page( + $page = add_submenu_page( $data['parent'], $data['title'], $data['name'], @@ -140,5 +152,101 @@ public static function __callstatic($index, $params = null) { $data['function'] ); } + + do_action('wp_menu/after_add_' . $type . '_page', 'load-'.$page); + + if ($pagenow === 'admin.php') { + + $fuction = $data['function']; + + self::_setAction('styles', $page, $fuction, $data['styles']); + self::_setAction('scripts', $page, $fuction, $data['scripts']); + } + } + + /** + * Validate permissions. + * + * @since 1.0.2 + * + * @uses current_user_can() → specific capability + * @uses wp_die() → kill WordPress execution and show error + */ + private static function _checkPermissions($capability) { + + if (!current_user_can($capability)) { + + $message = __('You don\'t have permissions to access this page.'); + + wp_die($message); + } + } + + /** + * Check if method exists. + * + * @since 1.0.2 + * + * @param array $method → [class|object, method] + * + * @return boolean + */ + private static function _validateMethod($method) { + + if (!empty($method) && isset($method[0]) && isset($method[1])) { + + if (method_exists($method[0], $method[1])) { + + return true; + } + } + + return false; + } + + /** + * Add actions to load styles and scripts that will be executed + * only when loading this page. + * + * @since 1.0.2 + * + * @param string $type → style|script + * @param string $page → slug of the page associated with the menu + * @param mixed $instance → output instance + * @param mixed $function → method to be called to load styles or scripts + * + * 1. Check if an existing method has been indicated. + * 2. If it does not exist, it checks if only the name of the method has + * been indicated and if it exists inside the output function. + * 3. If it does not exist, it is checked if there exists the method + * "addStyles" or "addScripts" inside the output function. + * + * @return boolean + */ + private static function _setAction($type, $page, $instance, $function) { + + if (!self::_validateMethod($function) && isset($instance[0])) { + + $method = $function; + + $instance = $instance[0]; + + $defaultMethod = 'add' . ucfirst($type); + + if (self::_validateMethod([$instance, $method])) { + + $function = [$instance, $function]; + + } else if (self::_validateMethod([$instance, $defaultMethod])) { + + $function = [$instance, $defaultMethod]; + + } else { + + return false; + } + } + + add_action('load-'.$page, $function); } } diff --git a/lib/vendor/josantonius/wp_register/composer.json b/lib/vendor/josantonius/wp_register/composer.json index 96e580d..4c13295 100644 --- a/lib/vendor/josantonius/wp_register/composer.json +++ b/lib/vendor/josantonius/wp_register/composer.json @@ -1,6 +1,6 @@ { "name": "josantonius/wp_register", - "version": "1.0.0", + "version": "1.0.2", "type": "library", "description": "Register css and JavaScript resources.", "keywords": [ diff --git a/lib/vendor/josantonius/wp_register/src/WP_Register.php b/lib/vendor/josantonius/wp_register/src/WP_Register.php index 184783d..d95c835 100644 --- a/lib/vendor/josantonius/wp_register/src/WP_Register.php +++ b/lib/vendor/josantonius/wp_register/src/WP_Register.php @@ -68,7 +68,7 @@ public static function add($type, $data = []) { if ($isAdmin && $place == 'admin' || !$isAdmin && $place == 'front') { - self::$data[$type][] = $data; + self::$data[$type][$data['name']] = $data; } else { @@ -77,7 +77,7 @@ public static function add($type, $data = []) { $type = ucfirst($type); - $hook = ($isAdmin) ? 'admin_init' : 'wp_enqueue_scripts'; + $hook = ($isAdmin) ? 'admin_enqueue_scripts' : 'wp_enqueue_scripts'; if (!isset(self::$data[$type][$hook])) { @@ -101,13 +101,11 @@ public static function add($type, $data = []) { * @uses wp_create_nonce() → creates a cryptographic token */ public static function addScripts() { - - $DS = DIRECTORY_SEPARATOR; foreach (self::$data['script'] as $data) { $params = [ - 'pluginUrl' => WP_PLUGIN_URL . $DS, + 'pluginUrl' => WP_PLUGIN_URL . '/', 'nonce' => wp_create_nonce($data['name'] . '-nonce') ]; @@ -157,4 +155,32 @@ public static function addStyles() { wp_enqueue_style($data['name']); } } + + /** + * Check if a particular style or script has been added to be enqueued. + * + * @since 1.0.1 + * + * @param string $type → script | style + * @param array $name → script or style name + * + * @return boolean + */ + public static function isSet($type, $name) { + + return (in_array($name, self::$data[$type][$name])) ? true : false; + } + + /** + * Remove before script or style have been enqueued. + * + * @since 1.0.1 + * + * @param string $type → script | style + * @param array $name → script or style name + */ + public static function remove($type, $name) { + + unset(self::$data[$type][$name]); + } } diff --git a/src/Controller/Admin/Page/Options.php b/src/Controller/Admin/Page/Options/Options.php similarity index 58% rename from src/Controller/Admin/Page/Options.php rename to src/Controller/Admin/Page/Options/Options.php index 6bee803..d7d95ff 100644 --- a/src/Controller/Admin/Page/Options.php +++ b/src/Controller/Admin/Page/Options/Options.php @@ -9,7 +9,7 @@ * @since 1.0.0 */ -namespace EliasisWordPress\Controller\Admin\Page; +namespace EliasisWordPress\Controller\Admin\Page\Options; use Josantonius\WP_Register\WP_Register, Josantonius\WP_Menu\WP_Menu, @@ -40,10 +40,21 @@ class Options extends Controller { */ public function init() { - $this->addScripts(); - $this->addStyles(); $this->getSettings(); - $this->addHooks(); + } + + /** + * Add menu and instance to associated method to display the page. + * + * @since 1.0.0 + */ + public function setMenu() { + + WP_Menu::add( + 'menu', + App::EliasisWordPress()->get('menu', 'top-level'), + [$this, 'render'] + ); } /** @@ -57,7 +68,7 @@ public function addSubmenuPage() { WP_Menu::add( 'submenu', - App::EliasisWordPress('submenu', 'options'), + App::EliasisWordPress()->get('submenu', 'options'), [$this, 'render'] ); } @@ -67,20 +78,12 @@ public function addSubmenuPage() { * * @since 1.0.0 */ - protected function addScripts() { - - $scripts = [ - 'eliasisfront', - 'eliasisadmin', - ]; - - foreach ($scripts as $script) { + public function addScripts() { - WP_Register::add( - 'script', - App::EliasisWordPress('assets', 'js', $script) - ); - } + WP_Register::add( + 'script', + App::EliasisWordPress()->get('assets', 'js', 'eliasisadmin') + ); } /** @@ -88,20 +91,12 @@ protected function addScripts() { * * @since 1.0.0 */ - protected function addStyles() { - - $styles = [ - 'eliasisfront', - 'eliasisadmin', - ]; + public function addStyles() { - foreach ($styles as $style) { - - WP_Register::add( - 'style', - App::EliasisWordPress('assets', 'css', $style) - ); - } + WP_Register::add( + 'style', + App::EliasisWordPress()->get('assets', 'css', 'eliasisadmin') + ); } /** @@ -111,22 +106,7 @@ protected function addStyles() { */ public function getSettings() { - App::id(EliasisWordPress); - - App::addOption('data', $this->model->getSettings()); - } - - /** - * Add hooks. - * - * @since 1.0.0 - */ - public function addHooks() { - - Hook::addHook([ - - 'example' => __CLASS__ . '@example', - ]); + App::EliasisWordPress()->set('data', $this->model->getSettings()); } /** @@ -138,7 +118,7 @@ public function addHooks() { */ public function example() { - print(App::EliasisWordPress('data', 'eliasis')); + print(App::EliasisWordPress()->get('data', 'eliasis')); } /** @@ -148,8 +128,16 @@ public function example() { */ public function render() { - $this->view->renderizate( - App::EliasisWordPress('path', 'layout') . 'default' - ); + $page = App::EliasisWordPress()->get('path', 'page'); + + $layout = App::EliasisWordPress()->get('path', 'layout'); + + Hook::getInstance(App::$id); + + $this->view->renderizate($layout, 'header'); + + $this->view->renderizate($page, 'options'); + + $this->view->renderizate($layout, 'footer'); } } \ No newline at end of file diff --git a/src/Controller/Launcher.php b/src/Controller/Launcher.php deleted file mode 100644 index 3790ce7..0000000 --- a/src/Controller/Launcher.php +++ /dev/null @@ -1,234 +0,0 @@ -setHooks(); - - if (is_admin()) { - - return $this->admin(); - } - - $this->front(); - } - - /** - * Hook plugin activation. | Executed only when activating the plugin. - * - * @since 1.0.0 - * - * @uses check_admin_referer() → user was referred from another admin page - * @uses flush_rewrite_rules() → remove rewrite rules and recreate - */ - public function activation() { - - check_admin_referer("activate-plugin_{$_REQUEST['plugin']}"); - - $this->setVersion(); - - flush_rewrite_rules(); - } - - /** - * Set plugin version. - * - * @since 1.0.0 - * - * @uses get_option() → option value based on an option name - * @uses add_option() → add a new option to Wordpress options - * @uses update_option() → update a named option/value - */ - protected function setVersion() { - - $pluginName = App::EliasisWordPress('plugin', 'name'); - - $actualVersion = App::EliasisWordPress('plugin', 'version'); - - if (!$installed_version = get_option($pluginName) . '-version') { - - add_option($pluginName . '-version', $actualVersion); - - } else { - - if ($installed_version < $actualVersion) { - - update_option($pluginName . '-version', $actualVersion); - } - } - } - - /** - * Hook plugin deactivation. Executed when deactivating the plugin. - * - * @since 1.0.0 - * - * @uses check_admin_referer() → tests if the current request is valid - * @uses flush_rewrite_rules() → remove rewrite rules and recreate - */ - public function deactivation() { - - check_admin_referer("deactivate-plugin_{$_REQUEST['plugin']}"); - - flush_rewrite_rules(); - } - - /** - * Set plugin texdomain for translations. - * - * @since 1.0.0 - */ - public function setLanguage() { - - $pluginName = App::EliasisWordPress('plugin', 'name'); - - load_plugin_textdomain( - 'search-inside', - false, - $pluginName. App::DS . 'languages' . App::DS - ); - } - - /** - * Set plugin hooks. - * - * @since 1.0.0 - */ - protected function setHooks() { - - Hook::setHook(App::EliasisWordPress('hooks')); - } - - /** - * Admin initializer method. - * - * @since 1.0.0 - * - * @uses add_action() → hooks a function on to a specific action - */ - public function admin() { - - WP_Menu::add('menu', App::EliasisWordPress('menu', 'top-level')); - - add_action('plugins_loaded', array($this, 'getCurrentScreen')); - } - - /** - * Get only current admin page. - * - * @since 1.0.0 - * - * @uses init() → initialize only the methods of the page visited - * - * @return - */ - public function getCurrentScreen() { - - foreach (App::EliasisWordPress('pages') as $page) { - - $page = App::EliasisWordPress('namespace', 'admin-page') . $page; - - if (class_exists($page)) { - - $page = call_user_func($page . '::getInstance'); - - $page->addSubmenuPage(); - - if (isset($_GET['page']) && $_GET['page'] == $page->slug) { - - return $page->init(); - } - } - } - } - - /** - * Front initializer method. - * - * @since 1.0.0 - */ - public function front() { - - $this->addStyles(); - - $this->addScripts(); - } - - /** - * Load scripts. - * - * @since 1.0.0 - */ - protected function addScripts() { - - $scripts = [ - 'eliasisfront', - 'eliasisadmin', - ]; - - foreach ($scripts as $script) { - - WP_Register::add( - 'script', - App::EliasisWordPress('assets', 'js', $script) - ); - } - } - - /** - * Load styles. - * - * @since 1.0.0 - */ - protected function addStyles() { - - $styles = [ - 'eliasisfront', - 'eliasisadmin', - ]; - - foreach ($styles as $style) { - - WP_Register::add( - 'style', - App::EliasisWordPress('assets', 'css', $style) - ); - } - } -} diff --git a/src/Controller/Launcher/Launcher.php b/src/Controller/Launcher/Launcher.php new file mode 100644 index 0000000..2348731 --- /dev/null +++ b/src/Controller/Launcher/Launcher.php @@ -0,0 +1,181 @@ +admin(); + } + + $this->front(); + } + + /** + * Hook plugin activation. | Executed only when activating the plugin. + * + * @since 1.0.0 + * + * @uses check_admin_referer() → user was referred from another admin page + * @uses flush_rewrite_rules() → remove rewrite rules and recreate + */ + public function activation() { + + check_admin_referer("activate-plugin_{$_REQUEST['plugin']}"); + + $this->model->setOptions(); + + flush_rewrite_rules(); + } + + /** + * Hook plugin deactivation. Executed when deactivating the plugin. + * + * @since 1.0.0 + * + * @uses check_admin_referer() → tests if the current request is valid + * @uses flush_rewrite_rules() → remove rewrite rules and recreate + */ + public function deactivation() { + + check_admin_referer("deactivate-plugin_{$_REQUEST['plugin']}"); + + flush_rewrite_rules(); + } + + /** + * Set plugin texdomain for translations. + * + * @since 1.0.0 + */ + public function setLanguage() { + + $slug = App::EliasisWordPress()->get('slug'); + + load_plugin_textdomain( + $slug, + false, + $slug . App::DS . 'languages' . App::DS + ); + } + + /** + * Admin initializer method. + * + * @since 1.0.0 + * + * @uses add_action() → hooks a function on to a specific action + */ + public function admin() { + + add_action('init', [$this, 'setLanguage']); + + $this->setMenus( + + App::EliasisWordPress()->get('pages'), + App::EliasisWordPress()->get('namespaces', 'admin-page') + ); + } + + /** + * Get current page and load submenu. + * + * @since 1.0.3 + * + * @param array $pages + * @param string $namespace + */ + public function setMenus($pages = [], $namespace = '') { + + foreach ($pages as $page) { + + $page = $namespace . $page . '\\' . $page; + + if (!class_exists($page)) { continue; } + + $instance = call_user_func($page . '::getInstance'); + + if (method_exists($instance, 'init')) { + + call_user_func([$instance, 'init']); + } + + if (method_exists($instance, 'setMenu')) { + + call_user_func([$instance, 'setMenu']); + } + + if (method_exists($instance, 'setSubmenu')) { + + call_user_func([$instance, 'setSubmenu']); + } + } + } + + /** + * Front initializer method. + * + * @since 1.0.0 + */ + public function front() { + + $this->addStyles(); + + $this->addScripts(); + } + + /** + * Load scripts. + * + * @since 1.0.0 + */ + protected function addScripts() { + + WP_Register::add( + 'script', + App::EliasisWordPress()->get('assets', 'js', 'eliasisfront') + ); + } + + /** + * Load styles. + * + * @since 1.0.0 + */ + protected function addStyles() { + + WP_Register::add( + 'style', + App::EliasisWordPress()->get('assets', 'css', 'eliasisfront') + ); + } +} diff --git a/src/Controller/Uninstall/Uninstall.php b/src/Controller/Uninstall/Uninstall.php new file mode 100644 index 0000000..39bb7cf --- /dev/null +++ b/src/Controller/Uninstall/Uninstall.php @@ -0,0 +1,35 @@ +model->removeAll(); + } +} diff --git a/src/Model/Admin/Page/Options.php b/src/Model/Admin/Page/Options/Options.php similarity index 82% rename from src/Model/Admin/Page/Options.php rename to src/Model/Admin/Page/Options/Options.php index 13bdc51..255e533 100644 --- a/src/Model/Admin/Page/Options.php +++ b/src/Model/Admin/Page/Options/Options.php @@ -9,7 +9,7 @@ * @since 1.0.0 */ -namespace EliasisWordPress\Model\Admin\Page; +namespace EliasisWordPress\Model\Admin\Page\Options; use Eliasis\Model\Model, Eliasis\App\App, @@ -24,9 +24,9 @@ class Options extends Model { protected function __construct() { - $jsonPath = App::EliasisWordPress('path', 'json'); + $jsonPath = App::EliasisWordPress()->get('path', 'json'); - $jsonFile = App::EliasisWordPress('file', 'settings'); + $jsonFile = App::EliasisWordPress()->get('file', 'settings'); $this->filepath = $jsonPath . $jsonFile; } diff --git a/src/Model/Launcher/Launcher.php b/src/Model/Launcher/Launcher.php new file mode 100644 index 0000000..d45fdc6 --- /dev/null +++ b/src/Model/Launcher/Launcher.php @@ -0,0 +1,51 @@ +get('slug'); + + $actualVersion = App::EliasisWordPress()->get('version'); + + if (!$installed_version = get_option($pluginName) . '-version') { + + add_option($pluginName . '-version', $actualVersion); + + } else { + + if ($installed_version < $actualVersion) { + + update_option($pluginName . '-version', $actualVersion); + } + } + } +} diff --git a/src/Controller/Uninstall.php b/src/Model/Uninstall/Uninstall.php similarity index 70% rename from src/Controller/Uninstall.php rename to src/Model/Uninstall/Uninstall.php index b1abda9..8a2ade6 100644 --- a/src/Controller/Uninstall.php +++ b/src/Model/Uninstall/Uninstall.php @@ -6,30 +6,31 @@ * @copyright Copyright (c) 2017 * @license GPL-2.0+ * @link https://github.com/Eliasis-Framework/WordPress-Plugin.git - * @since 1.0.0 + * @since 1.0.3 */ -namespace EliasisWordPress\Controller; +namespace EliasisWordPress\Model\Uninstall; -use Eliasis\App\App; +use Eliasis\App\App, + Eliasis\Model\Model; /** * Main method for cleaning and removal of components. * - * @since 1.0.0 + * @since 1.0.3 */ -class Uninstall { +class Uninstall extends Model { /** * Remove and uninstall the plugin components. * - * @since 1.0.0 + * @since 1.0.3 * * @uses delete_option() → removes option by name * @uses delete_site_option() → removes a option by name */ - public static function removeAll() { + public function removeAll() { - $pluginName = App::EliasisWordPress('plugin', 'name'); + $pluginName = App::EliasisWordPress()->get('slug'); delete_option($pluginName .'version'); // For site options in Multisite diff --git a/src/template/elements/footer.php b/src/template/layout/footer.php similarity index 100% rename from src/template/elements/footer.php rename to src/template/layout/footer.php diff --git a/src/template/elements/header.php b/src/template/layout/header.php similarity index 100% rename from src/template/elements/header.php rename to src/template/layout/header.php diff --git a/src/template/pages/options.php b/src/template/page/options.php similarity index 94% rename from src/template/pages/options.php rename to src/template/page/options.php index 65046dc..d7bba25 100644 --- a/src/template/pages/options.php +++ b/src/template/page/options.php @@ -25,7 +25,7 @@
- +
diff --git a/uninstall.php b/uninstall.php index 880f454..4e159a5 100644 --- a/uninstall.php +++ b/uninstall.php @@ -13,11 +13,13 @@ require 'lib' . $DS . 'vendor' . $DS .'autoload.php'; -use SearchInside\Controller\Uninstall; +use Eliasis\App\App; if (!defined('WP_UNINSTALL_PLUGIN')) { exit(); } -Uninstall::removeAll(); +App::run(__DIR__, 'wordpress-plugin', 'EliasisWordPress'); + +App::EliasisWordPress()->instance('Uninstall', 'controller')->removeAll();