From 2b20ecce3c0d074a7ea554ffbb4d1f359cbd42f6 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 29 May 2015 14:22:37 +0100 Subject: [PATCH 01/67] fixed widgets and added a shortcode fix --- Herbert/Framework/API.php | 17 ++++++++++++++--- Herbert/Framework/Notifier.php | 2 +- Herbert/Framework/Shortcode.php | 25 +++++++++++++++++++++++-- Herbert/Framework/Widget.php | 2 +- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Herbert/Framework/API.php b/Herbert/Framework/API.php index f1cee73..aee15b7 100644 --- a/Herbert/Framework/API.php +++ b/Herbert/Framework/API.php @@ -1,6 +1,6 @@ methods[$method] = $fn; } + /** + * Gets a method. + * + * @param string $method + * @return Callable + */ + public function get($method) + { + return array_get($this->methods, $method); + } + /** * Magic call from the function collection. * @@ -46,9 +57,9 @@ public function add($method, $fn) */ public function __call($method, $params) { - if (!isset($this->methods[$method])) + if ( ! isset($this->methods[$method])) { - throw new WP_Error('broke', "Method '{$method}' not set!"); + throw new Exception("Method '{$method}' not set!"); } return $this->app->call( diff --git a/Herbert/Framework/Notifier.php b/Herbert/Framework/Notifier.php index c72d98a..f7555d4 100644 --- a/Herbert/Framework/Notifier.php +++ b/Herbert/Framework/Notifier.php @@ -8,7 +8,7 @@ class Notifier { /** * The notifier instance. * - * @var \Herbet\Framework\Notifier + * @var \Herbert\Framework\Notifier */ protected static $instance; diff --git a/Herbert/Framework/Shortcode.php b/Herbert/Framework/Shortcode.php index 50d454a..4f69f21 100644 --- a/Herbert/Framework/Shortcode.php +++ b/Herbert/Framework/Shortcode.php @@ -1,5 +1,7 @@ renameArguments($arguments, $attributes); } + if (strpos($callable, '::') !== false) + { + list($api, $method) = explode('::', $callable); + + global $$api; + + if ($$api === null) + { + throw new Exception("API '{$api}' not set!"); + } + + $callable = $$api->get($method); + + if ($callable === null) + { + throw new Exception("Method '{$method}' not set!"); + } + } + return $this->app->call( $callable, array_merge([ diff --git a/Herbert/Framework/Widget.php b/Herbert/Framework/Widget.php index 5a2d775..c4e9a92 100644 --- a/Herbert/Framework/Widget.php +++ b/Herbert/Framework/Widget.php @@ -60,7 +60,7 @@ public function boot() public function add($widget, Plugin $plugin = null) { $this->widgets[] = [ - 'widget' => $widget, + 'class' => $widget, 'plugin' => $plugin ]; } From 4c2d487bc612750ce4934936f817ccf53b6cdc33 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 29 May 2015 14:23:00 +0100 Subject: [PATCH 02/67] bumped version number to 0.9.4 --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 211a51e..acc5b03 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -12,7 +12,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.2'; + const VERSION = '0.9.4'; /** * The application's version. From af80542148ba59bb1a28601d2e95c4b981dc86b7 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 29 May 2015 16:24:48 +0100 Subject: [PATCH 03/67] fixed plugin loading path --- bootstrap/autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index adc77e3..87616ef 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -28,7 +28,7 @@ /** * Load all herbert.php files in plugin roots. */ -$iterator = new DirectoryIterator(ABSPATH . 'wp-content/plugins'); +$iterator = new DirectoryIterator(ABSPATH . ltrim(substr(plugin_dir_url(''), strlen(home_url())), '/')); foreach ($iterator as $directory) { From aa0c88d00cf12c67dd4f95322cc95c12dfa112e1 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Fri, 29 May 2015 16:30:25 +0100 Subject: [PATCH 04/67] Update version --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index acc5b03..cae896b 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -12,7 +12,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.4'; + const VERSION = '0.9.5'; /** * The application's version. From e0dabcdae82c1f74baac8e946593419285f36db9 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 29 May 2015 17:08:34 +0100 Subject: [PATCH 05/67] fix to custom wp setups --- bootstrap/autoload.php | 12 ++++++++---- bootstrap/helpers.php | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 87616ef..8703820 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -28,7 +28,8 @@ /** * Load all herbert.php files in plugin roots. */ -$iterator = new DirectoryIterator(ABSPATH . ltrim(substr(plugin_dir_url(''), strlen(home_url())), '/')); +$iterator = new DirectoryIterator(plugin_directory()); + foreach ($iterator as $directory) { @@ -46,7 +47,10 @@ $config = $herbert->getPluginConfig($root); - register_activation_hook($root . '/plugin.php', function () use ($herbert, $config, $root) + $plugin = substr($root . '/plugin.php', strlen(plugin_directory())); + $plugin = ltrim($plugin, '/'); + + register_activation_hook($plugin, function () use ($herbert, $config, $root) { if ( ! $herbert->pluginMatches($config)) { @@ -58,12 +62,12 @@ $herbert->activatePlugin($root); }); - register_deactivation_hook($root . '/plugin.php', function () use ($herbert, $root) + register_deactivation_hook($plugin, function () use ($herbert, $root) { $herbert->deactivatePlugin($root); }); - if ( ! is_plugin_active(substr($root, strlen(ABSPATH . 'wp-content/plugins/')) . '/plugin.php')) + if ( ! is_plugin_active($plugin)) { continue; } diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 9aa15f8..a4f5d8c 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -15,6 +15,19 @@ function dd() } } +if ( ! function_exists('plugin_directory')) +{ + /** + * Gets the plugin directory. + * + * @return string + */ + function plugin_directory() + { + return WP_PLUGIN_DIR; + } +} + if ( ! function_exists('response')) { /** From b031d54cd899f208ec125193a5fc074f1eebf26c Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Tue, 2 Jun 2015 11:29:00 +0100 Subject: [PATCH 06/67] added plugin uninstall hooks and finished up on the table creation / deletion systme --- Herbert/Framework/Application.php | 99 +++++++++++++++++++++++++++++++ bootstrap/autoload.php | 4 ++ 2 files changed, 103 insertions(+) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index cae896b..b0a650f 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -3,6 +3,8 @@ use Illuminate\Support\ServiceProvider; use vierbergenlars\SemVer\version as SemVersion; use vierbergenlars\SemVer\expression as SemVersionExpression; +use Illuminate\Database\Capsule\Manager as CapsuleManager; +use Illuminate\Database\Schema\Blueprint as SchemaBlueprint; /** * @see http://getherbert.com @@ -481,6 +483,24 @@ public function activatePlugin($root) $config = $this->getPluginConfig($root); + foreach (array_get($config, 'tables', []) as $table => $class) + { + if ( ! class_exists($class)) + { + continue; + } + + if (CapsuleManager::schema()->hasTable($table)) + { + continue; + } + + CapsuleManager::schema()->create($table, function (SchemaBlueprint $table) use ($class) + { + $this->call($class . '@activate', ['table' => $table, 'app' => $this]); + }); + } + foreach (array_get($config, 'activators', []) as $activator) { if ( ! file_exists($activator)) @@ -535,6 +555,85 @@ public function deactivatePlugin($root) 'widget' ]); } + + foreach (array_get($config, 'tables', []) as $table => $class) + { + if ( ! class_exists($class)) + { + continue; + } + + if ( ! CapsuleManager::schema()->hasTable($table)) + { + continue; + } + + CapsuleManager::schema()->table($table, function (SchemaBlueprint $table) use ($class) + { + $this->call($class . '@deactivate', ['table' => $table, 'app' => $this]); + }); + } + } + + /** + * Deletes a plugin. + * + * @see register_uninstall_hook + * @param $root + */ + public function deletePlugin($root) + { + $plugins = array_filter($this->plugins, function (Plugin $plugin) use ($root) + { + return $plugin->getBasePath() === $root; + }); + + foreach ($plugins as $plugin) + { + if ( ! method_exists($plugin, 'delete')) + { + continue; + } + + $plugin->deactivate(); + } + + $config = $this->getPluginConfig($root); + + foreach (array_get($config, 'deleters', []) as $deleter) + { + if ( ! file_exists($deleter)) + { + continue; + } + + $this->loadWith($deleter, [ + 'http', + 'router', + 'enqueue', + 'panel', + 'shortcode', + 'widget' + ]); + } + + foreach (array_get($config, 'tables', []) as $table => $class) + { + if ( ! class_exists($class)) + { + continue; + } + + if ( ! CapsuleManager::schema()->hasTable($table)) + { + continue; + } + + CapsuleManager::schema()->table($table, function (SchemaBlueprint $table) use ($class) + { + $this->call($class . '@delete', ['table' => $table, 'app' => $this]); + }); + } } /** diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 8703820..4b7e308 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -67,6 +67,10 @@ $herbert->deactivatePlugin($root); }); + // Ugly hack to make the install hook work correctly + // as WP doesn't allow closures to be passed here + register_uninstall_hook($plugin, create_function('', 'herbert()->deletePlugin(\'' . $root . '\');')); + if ( ! is_plugin_active($plugin)) { continue; From e4cdf2ea4cc736d1c800bdb51a3713503b52721b Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Tue, 2 Jun 2015 17:49:07 +0100 Subject: [PATCH 07/67] Panels now support different controller methods based action --- Herbert/Framework/Panel.php | 45 ++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index e16aaac..f70fa22 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -25,6 +25,11 @@ class Panel { */ protected $app; + /** + * @var \Herbert\Framework\Http + */ + protected $http; + /** * @var array */ @@ -41,10 +46,12 @@ class Panel { * Adds the WordPress hook during construction. * * @param \Herbert\Framework\Application $app + * @param \Herbert\Framework\Http $http */ - public function __construct(Application $app) + public function __construct(Application $app, Http $http) { $this->app = $app; + $this->http = $http; add_action('admin_menu', [$this, 'boot']); } @@ -146,7 +153,7 @@ protected function addPanel($panel) $panel['title'], 'manage_options', $panel['slug'], - $this->makeCallable($panel['uses']), + $this->makeCallable($panel), isset($panel['icon']) ? $this->fetchIcon($panel['icon']) : '' ); @@ -214,13 +221,13 @@ protected function fetchIcon($icon) /** * Makes a callable for the panel hook. * - * @param $callable + * @param $panel * @return callable */ - protected function makeCallable($callable) + protected function makeCallable($panel) { - return function () use ($callable) { - $this->call($callable); + return function () use ($panel) { + $this->handler($panel); }; } @@ -317,4 +324,30 @@ protected function namespaceAs($as) return $this->namespace . '::' . $as; } + + /** + * Return the correct callable based on action + * + * @param $panel + * @return void + */ + protected function handler($panel) + { + $callable = $panel['uses']; + + if($this->http->has('action')) + { + $action = $this->http->get('action'); + + if(isset($panel[$action])) + { + $callable = $panel[$action]; + } + } + + $this->call($callable); + + return; + } + } From 93ea803c0030677e6a6ebc8e02fac101d37b7c9f Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 12:21:14 +0100 Subject: [PATCH 08/67] added session data using Symfony's session lib --- .../Providers/HerbertServiceProvider.php | 22 +++++ Herbert/Framework/RedirectResponse.php | 98 +++++++++++++++++++ Herbert/Framework/Route.php | 8 +- Herbert/Framework/Router.php | 5 + Herbert/Framework/Session.php | 9 ++ bootstrap/helpers.php | 56 +++++++++++ 6 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 Herbert/Framework/RedirectResponse.php create mode 100644 Herbert/Framework/Session.php diff --git a/Herbert/Framework/Providers/HerbertServiceProvider.php b/Herbert/Framework/Providers/HerbertServiceProvider.php index 5b8c476..54409cb 100644 --- a/Herbert/Framework/Providers/HerbertServiceProvider.php +++ b/Herbert/Framework/Providers/HerbertServiceProvider.php @@ -2,6 +2,8 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Support\ServiceProvider; +use Illuminate\Cookie\CookieJar; +use Herbert\Framework\Session; /** * @see http://getherbert.com @@ -83,6 +85,16 @@ public function register() 'widget', 'Herbert\Framework\Widget' ); + + $this->app->instance( + 'session', + $this->app->make('Herbert\Framework\Session', ['app' => $this->app]) + ); + + $this->app->alias( + 'session', + 'Herbert\Framework\Session' + ); } /** @@ -111,4 +123,14 @@ protected function registerEloquent() $capsule->bootEloquent(); } + /** + * Boots the service provider. + * + * @return void + */ + public function boot() + { + $this->app['session']->start(); + } + } diff --git a/Herbert/Framework/RedirectResponse.php b/Herbert/Framework/RedirectResponse.php new file mode 100644 index 0000000..7b7dff6 --- /dev/null +++ b/Herbert/Framework/RedirectResponse.php @@ -0,0 +1,98 @@ +target = $url; + $this->updateBody(); + $this->updateHeaders(); + } + + /** + * Update the body. + * + * @return void + */ + protected function updateBody() + { + $this->body = sprintf(' + + + + + + Redirecting to %1$s + + + Redirecting to %1$s. + +', htmlspecialchars($this->target, ENT_QUOTES, 'UTF-8')); + } + + /** + * Update the headers. + * + * @return void + */ + protected function updateHeaders() + { + array_set($this->headers, 'Location', $this->target); + } + + /** + * Flashes the :key of value :val to the session. + * + * @param string $key + * @param mixed $val + * @return \Herbert\Framework\RedirectResponse + */ + public function with($key, $val) + { + array_set($this->data, $key, $val); + + return $this; + } + + /** + * Actually flashes in the session data. + * + * @return \Herbert\Framework\RedirectResponse + */ + public function flash() + { + $bag = session()->getFlashBag(); + + foreach ($this->data as $key => $val) + { + $bag->add($key, $val); + } + + return $this; + } + +} diff --git a/Herbert/Framework/Route.php b/Herbert/Framework/Route.php index 82b6c23..457fd73 100644 --- a/Herbert/Framework/Route.php +++ b/Herbert/Framework/Route.php @@ -1,6 +1,6 @@ app = $app; $this->parameters = $parameters; $this->uri = $data['uri']; - $this->name = isset($data['as']) ? $data['as'] : $this->uri; + $this->name = array_get($data, 'as', $this->uri); $this->uses = $data['uses']; } @@ -73,7 +73,7 @@ public function handle() return new JsonResponse($response); } - var_dump($response); + throw new Exception('Unknown response type!'); } /** @@ -85,7 +85,7 @@ public function handle() */ public function parameter($name, $default = null) { - if (!isset($this->parameters[$name])) + if ( ! isset($this->parameters[$name])) { return $default; } diff --git a/Herbert/Framework/Router.php b/Herbert/Framework/Router.php index 8455f35..baae0f1 100644 --- a/Herbert/Framework/Router.php +++ b/Herbert/Framework/Router.php @@ -264,6 +264,11 @@ protected function processRequest(Route $route) { $response = $route->handle(); + if ($response instanceof RedirectResponse) + { + $response->flash(); + } + status_header($response->getStatusCode()); foreach ($response->getHeaders() as $key => $value) diff --git a/Herbert/Framework/Session.php b/Herbert/Framework/Session.php new file mode 100644 index 0000000..815f499 --- /dev/null +++ b/Herbert/Framework/Session.php @@ -0,0 +1,9 @@ +get($key, $default); + } +} + +if ( ! function_exists('session_flashed')) +{ + /** + * Gets the session flashbag or a key from the session flashbag. + * + * @param string $key + * @param mixed $default + * @return \Illuminate\Session\Store|mixed + */ + function session_flashed($key = null, $default = []) + { + if ($key === null) + { + return herbert('session')->getFlashBag(); + } + + return herbert('session')->getFlashBag()->get($key, $default); + } +} + if ( ! function_exists('view')) { /** From 85cd5c9d8f505bd1279ece5941f3f09f1cfce382 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 12:21:54 +0100 Subject: [PATCH 09/67] tidied up Panel@handler a bit --- Herbert/Framework/Panel.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index f70fa22..e562296 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -335,19 +335,17 @@ protected function handler($panel) { $callable = $panel['uses']; - if($this->http->has('action')) + if ($this->http->has('action')) { $action = $this->http->get('action'); - if(isset($panel[$action])) + if (isset($panel[$action])) { $callable = $panel[$action]; } } $this->call($callable); - - return; } } From 499bf08a2c2330355e763c9f20f410659b8cbf04 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 12:51:36 +0100 Subject: [PATCH 10/67] added HttpErrorException --- .../Exceptions/HttpErrorException.php | 35 +++++++++++++++++++ Herbert/Framework/Panel.php | 21 +++++++++-- Herbert/Framework/Router.php | 25 +++++++++---- 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 Herbert/Framework/Exceptions/HttpErrorException.php diff --git a/Herbert/Framework/Exceptions/HttpErrorException.php b/Herbert/Framework/Exceptions/HttpErrorException.php new file mode 100644 index 0000000..b574643 --- /dev/null +++ b/Herbert/Framework/Exceptions/HttpErrorException.php @@ -0,0 +1,35 @@ +status = $status; + } + + /** + * Gets the Http status code. + * + * @return integer + */ + public function getStatus() + { + return $this->status; + } + +} diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index e562296..957959a 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -3,6 +3,7 @@ use Illuminate\Contracts\Support\Jsonable; use InvalidArgumentException; use JsonSerializable; +use Herbert\Framework\Exceptions\HttpErrorException; /** * @see http://getherbert.com @@ -192,7 +193,7 @@ protected function addSubPanel($panel) $panel['title'], 'manage_options', $panel['slug'], - isset($panel['rename']) && $panel['rename'] ? null : $this->makeCallable($panel['uses']) + isset($panel['rename']) && $panel['rename'] ? null : $this->makeCallable($panel) ); } @@ -264,6 +265,8 @@ protected function call($callable) return; } + + throw new Exception('Unknown response type!'); } /** @@ -345,7 +348,21 @@ protected function handler($panel) } } - $this->call($callable); + try { + $this->call($callable); + } catch (HttpErrorException $e) { + global $wp_query; + $wp_query->set_404(); + + status_header($e->getStatus()); + + define('HERBERT_HTTP_ERROR_CODE', $e->getStatus()); + define('HERBERT_HTTP_ERROR_MESSAGE', $e->getMessage()); + + Notifier::error('' . $e->getStatus() . ': ' . $e->getMessage()); + + do_action('admin_notices'); + } } } diff --git a/Herbert/Framework/Router.php b/Herbert/Framework/Router.php index baae0f1..6b1c3a5 100644 --- a/Herbert/Framework/Router.php +++ b/Herbert/Framework/Router.php @@ -2,6 +2,7 @@ use Closure; use InvalidArgumentException; +use Herbert\Framework\Exceptions\HttpErrorException; /** * @see http://getherbert.com @@ -232,12 +233,24 @@ public function parseRequest($wp) $data['parameters'][$key] = $wp->query_vars['herbert_param_' . $key]; } - $this->processRequest( - $this->buildRoute( - $route, - $data['parameters'] - ) - ); + try { + $this->processRequest( + $this->buildRoute( + $route, + $data['parameters'] + ) + ); + } catch (HttpErrorException $e) { + global $wp_query; + $wp_query->set_404(); + + status_header($e->getStatus()); + + define('HERBERT_HTTP_ERROR_CODE', $e->getStatus()); + define('HERBERT_HTTP_ERROR_MESSAGE', $e->getMessage()); + + @include get_404_template(); + } die; } From ed75de2170e4054c02d7105b90ab71be79a2fc92 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 16:24:08 +0100 Subject: [PATCH 11/67] fixing panel routing for different Http verbs --- Herbert/Framework/Panel.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 957959a..1b56c30 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -210,8 +210,8 @@ protected function fetchIcon($icon) return ''; } - if (substr($icon, 0, 9) === "dashicons" || substr($icon, 0, 5) === "data:" - || substr($icon, 0, 2) === "//" || $icon == 'none') + if (substr($icon, 0, 9) === 'dashicons' || substr($icon, 0, 5) === 'data:' + || substr($icon, 0, 2) === '//' || $icon == 'none') { return $icon; } @@ -337,15 +337,14 @@ protected function namespaceAs($as) protected function handler($panel) { $callable = $panel['uses']; + $method = $this->http->method(); - if ($this->http->has('action')) - { - $action = $this->http->get('action'); + $callable = array_get($panel, $method, $callable); - if (isset($panel[$action])) - { - $callable = $panel[$action]; - } + if ($action = $this->http->get('action')) + { + $callable = array_get($panel, $action, $callable); + $callable = array_get($panel, "{$method}.{$action}", $callable); } try { From e350b080b1251f014860341b6b35ea492ba7242f Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 16:29:07 +0100 Subject: [PATCH 12/67] lowercased the http verbs and action --- Herbert/Framework/Panel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 1b56c30..7d3ef1c 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -337,11 +337,11 @@ protected function namespaceAs($as) protected function handler($panel) { $callable = $panel['uses']; - $method = $this->http->method(); + $method = strtolower($this->http->method()); $callable = array_get($panel, $method, $callable); - if ($action = $this->http->get('action')) + if ($action = strtolower($this->http->get('action'))) { $callable = array_get($panel, $action, $callable); $callable = array_get($panel, "{$method}.{$action}", $callable); From 51a47d9a21c3417e1b65123e2b28837ea98bb9d6 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 16:33:47 +0100 Subject: [PATCH 13/67] allow passing of an array to ->with() --- Herbert/Framework/RedirectResponse.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Herbert/Framework/RedirectResponse.php b/Herbert/Framework/RedirectResponse.php index 7b7dff6..6a9a177 100644 --- a/Herbert/Framework/RedirectResponse.php +++ b/Herbert/Framework/RedirectResponse.php @@ -71,9 +71,17 @@ protected function updateHeaders() * @param mixed $val * @return \Herbert\Framework\RedirectResponse */ - public function with($key, $val) + public function with($key, $val = null) { - array_set($this->data, $key, $val); + if ( ! is_array($key)) + { + $key = [$key => $val]; + } + + foreach ($key as $k => $v) + { + array_set($this->data, $k, $v); + } return $this; } From 2e56afba6b7c8b7c97481db7755fadad404d2f6b Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 17:09:14 +0100 Subject: [PATCH 14/67] speed up the redirect --- Herbert/Framework/Panel.php | 9 ++++++++- Herbert/Framework/RedirectResponse.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 7d3ef1c..64f75ae 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -228,7 +228,7 @@ protected function fetchIcon($icon) protected function makeCallable($panel) { return function () use ($panel) { - $this->handler($panel); + return $this->handler($panel); }; } @@ -245,6 +245,11 @@ protected function call($callable) ['app' => $this->app] ); + if ($response instanceof RedirectResponse) + { + $response->flash(); + } + if ($response instanceof Response) { echo $response->getBody(); @@ -349,6 +354,8 @@ protected function handler($panel) try { $this->call($callable); + + die; } catch (HttpErrorException $e) { global $wp_query; $wp_query->set_404(); diff --git a/Herbert/Framework/RedirectResponse.php b/Herbert/Framework/RedirectResponse.php index 6a9a177..c979a4b 100644 --- a/Herbert/Framework/RedirectResponse.php +++ b/Herbert/Framework/RedirectResponse.php @@ -44,7 +44,7 @@ protected function updateBody() - + Redirecting to %1$s From bb1ac0b5c6aea190f755535095145f1e0f60577a Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 17:09:33 +0100 Subject: [PATCH 15/67] bump herbert version up --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index b0a650f..e56e1f5 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.5'; + const VERSION = '0.9.6'; /** * The application's version. From d6298948bc1bd3aa8aefe075c98cc263a810a635 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Wed, 3 Jun 2015 17:17:08 +0100 Subject: [PATCH 16/67] remove the die --- Herbert/Framework/Panel.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 64f75ae..a04148d 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -354,8 +354,6 @@ protected function handler($panel) try { $this->call($callable); - - die; } catch (HttpErrorException $e) { global $wp_query; $wp_query->set_404(); From 031fdd8856332115caf5dbcb7a48958dca73213f Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Thu, 4 Jun 2015 10:56:56 +0100 Subject: [PATCH 17/67] added JS to redirect to speed it up a bit; added arg passing to _url helpers and changed Panel@url to not depend on WP's admin_menu state --- Herbert/Framework/Panel.php | 34 ++++++++++++++++++++++---- Herbert/Framework/RedirectResponse.php | 2 ++ bootstrap/helpers.php | 10 +++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index a04148d..e7c9272 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -54,6 +54,7 @@ public function __construct(Application $app, Http $http) $this->app = $app; $this->http = $http; + // add_action('init', [$this, 'bootRoutes']); add_action('admin_menu', [$this, 'boot']); } @@ -133,7 +134,7 @@ public function add($data, $uses = null) $data['as'] = $this->namespaceAs($data['as']); } - if (isset($data['parent'])) + if ($data['type'] === 'sub-panel' && isset($data['parent'])) { $data['parent'] = $this->namespaceAs($data['parent']); } @@ -275,12 +276,12 @@ protected function call($callable) } /** - * Get the URL to a panel. + * Gets a panel. * * @param string $name - * @return string + * @return array */ - public function url($name) + protected function getPanel($name) { foreach ($this->panels as $panel) { @@ -289,12 +290,35 @@ public function url($name) continue; } - return menu_page_url(array_get($panel, 'slug'), false); + return $panel; } return null; } + /** + * Get the URL to a panel. + * + * @param string $name + * @return string + */ + public function url($name) + { + if (($panel = $this->getPanel($name)) === null) + { + return null; + } + + $slug = array_get($panel, 'slug'); + + if (array_get($panel, 'type') === 'wp-sub-panel') + { + return admin_url(add_query_arg('page', $slug, array_get($panel, 'parent'))); + } + + return admin_url('admin.php?page=' . $slug); + } + /** * Sets the current namespace. * diff --git a/Herbert/Framework/RedirectResponse.php b/Herbert/Framework/RedirectResponse.php index c979a4b..4be38af 100644 --- a/Herbert/Framework/RedirectResponse.php +++ b/Herbert/Framework/RedirectResponse.php @@ -50,6 +50,8 @@ protected function updateBody() Redirecting to %1$s. + + ', htmlspecialchars($this->target, ENT_QUOTES, 'UTF-8')); } diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 7a312d2..dc935af 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -158,11 +158,12 @@ function view($name, $context = []) * Gets the url to a panel. * * @param string $name + * @param array $query * @return string */ - function panel_url($name) + function panel_url($name, $query = []) { - return herbert('panel')->url($name); + return esc_url(add_query_arg($query, herbert('panel')->url($name))); } } @@ -173,10 +174,11 @@ function panel_url($name) * * @param string $name * @param array $args + * @param array $query * @return string */ - function route_url($name, $args = []) + function route_url($name, $args = [], $query = []) { - return herbert('router')->url($name, $args); + return esc_url(add_query_arg($query, herbert('router')->url($name, $args))); } } From 753bed2f1c7876722a7803561434e337cb36e844 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Thu, 4 Jun 2015 11:00:36 +0100 Subject: [PATCH 18/67] remove esc_url filter from _url helpers --- bootstrap/helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index dc935af..2d93395 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -163,7 +163,7 @@ function view($name, $context = []) */ function panel_url($name, $query = []) { - return esc_url(add_query_arg($query, herbert('panel')->url($name))); + return add_query_arg($query, herbert('panel')->url($name)); } } @@ -179,6 +179,6 @@ function panel_url($name, $query = []) */ function route_url($name, $args = [], $query = []) { - return esc_url(add_query_arg($query, herbert('router')->url($name, $args))); + return add_query_arg($query, herbert('router')->url($name, $args)); } } From e9e480c9b0ea04af92d43594d23daa14abbe9c61 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Thu, 4 Jun 2015 11:45:55 +0100 Subject: [PATCH 19/67] guard against array usage in Panel --- Herbert/Framework/Panel.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index e7c9272..3475fbc 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -376,6 +376,11 @@ protected function handler($panel) $callable = array_get($panel, "{$method}.{$action}", $callable); } + if (is_array($callable)) + { + $callable = $panel['uses']; + } + try { $this->call($callable); } catch (HttpErrorException $e) { From 26ec2a4c71abf4f0d677923924cdf97d3f188120 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Thu, 4 Jun 2015 12:50:20 +0100 Subject: [PATCH 20/67] added content_directory helper and fixed the twig directory for caches --- Herbert/Framework/Providers/TwigServiceProvider.php | 4 +++- bootstrap/helpers.php | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/TwigServiceProvider.php b/Herbert/Framework/Providers/TwigServiceProvider.php index b1ef8e6..80f22bc 100644 --- a/Herbert/Framework/Providers/TwigServiceProvider.php +++ b/Herbert/Framework/Providers/TwigServiceProvider.php @@ -35,7 +35,7 @@ public function register() return [ 'debug' => $this->app->environment() === 'local', 'charset' => 'utf-8', - 'cache' => ABSPATH . 'wp-content/twig-cache', + 'cache' => content_directory() . '/twig-cache', 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true, @@ -49,6 +49,8 @@ public function register() 'dd', 'herbert', 'view', + 'content_directory', + 'plugin_directory', 'panel_url', 'route_url' ]; diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 2d93395..d6e298f 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -15,6 +15,19 @@ function dd() } } +if ( ! function_exists('content_directory')) +{ + /** + * Gets the content directory. + * + * @return string + */ + function content_directory() + { + return WP_CONTENT_DIR; + } +} + if ( ! function_exists('plugin_directory')) { /** From 928f5967e5724686c39c46a105c3797ce3f8e488 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Thu, 4 Jun 2015 15:48:28 +0100 Subject: [PATCH 21/67] Changed the notifier to allow for flashes and adds a fallback for wp shutdown --- Herbert/Framework/Notifier.php | 63 ++++++++++++++----- .../Providers/HerbertServiceProvider.php | 10 +++ 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/Herbert/Framework/Notifier.php b/Herbert/Framework/Notifier.php index f7555d4..7563eb3 100644 --- a/Herbert/Framework/Notifier.php +++ b/Herbert/Framework/Notifier.php @@ -24,51 +24,74 @@ class Notifier { */ public function __construct() { + if ( ! self::$instance) + { + self::$instance = $this; + + $this->gatherFlashed(); + } + add_action('admin_notices', [$this, 'sendNotices']); + add_action('shutdown', [$this, 'sendNotices']); } /** * Adds a notice. * - * @param $message - * @param string $class + * @param string $message + * @param string $class + * @param boolean $flash */ - protected function notify($message, $class = 'updated') + protected function notify($message, $class = 'updated', $flash = false) { - $this->notices[] = [ + $notification = [ 'message' => $message, 'class' => $class ]; + + if ( ! $flash) + { + $this->notices[] = $notification; + + return; + } + + $notices = session('__notifier_flashed', []); + $notices[] = $notification; + session()->getFlashBag()->set('__notifier_flashed', $notices); } /** * Adds a success notice. * - * @param $message + * @param string $message + * @param boolean $flash */ - protected function success($message) + protected function success($message, $flash = false) { - $this->notify($message, 'updated'); + $this->notify($message, 'updated', $flash); } /** * Adds a warning notice. * - * @param $message + * @param string $message + * @param boolean $flash */ - protected function warning($message) + protected function warning($message, $flash = false) { - $this->notify($message, 'update-nag'); + $this->notify($message, 'update-nag', $flash); } /** * Adds an error notice. * - * @param $message + * @param string $message + * @param boolean $flash */ - protected function error($message) + protected function error($message, $flash = false) { - $this->notify($message, 'error'); + $this->notify($message, 'error', $flash); } /** @@ -82,6 +105,18 @@ public function sendNotices() { echo "

{$notice['message']}

"; } + + $this->notices = []; + } + + /** + * Gathers all the flashed notify messages. + * + * @return void + */ + protected function gatherFlashed() + { + $this->notices = session()->getFlashBag()->get('__notifier_flashed', []); } /** @@ -95,7 +130,7 @@ public static function __callStatic($name, $arguments) { if ( ! self::$instance) { - self::$instance = new self; + new self; } return call_user_func_array([self::$instance, $name], $arguments); diff --git a/Herbert/Framework/Providers/HerbertServiceProvider.php b/Herbert/Framework/Providers/HerbertServiceProvider.php index 54409cb..cd07dc2 100644 --- a/Herbert/Framework/Providers/HerbertServiceProvider.php +++ b/Herbert/Framework/Providers/HerbertServiceProvider.php @@ -95,6 +95,16 @@ public function register() 'session', 'Herbert\Framework\Session' ); + + $this->app->instance( + 'notifier', + $this->app->make('Herbert\Framework\Notifier', ['app' => $this->app]) + ); + + $this->app->alias( + 'notifier', + 'Herbert\Framework\Notifier' + ); } /** From 530ffa4b160ad73f0f9bee37ea23325faaf37006 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Thu, 4 Jun 2015 16:53:39 +0100 Subject: [PATCH 22/67] added some stuff for overriding responses --- .../Exceptions/HttpErrorException.php | 26 +++++++++++++++++-- Herbert/Framework/Panel.php | 14 +++++++--- .../Providers/TwigServiceProvider.php | 2 ++ Herbert/Framework/RedirectResponse.php | 2 +- Herbert/Framework/Router.php | 20 ++++++++++++-- bootstrap/helpers.php | 2 +- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/Herbert/Framework/Exceptions/HttpErrorException.php b/Herbert/Framework/Exceptions/HttpErrorException.php index b574643..4bc1a69 100644 --- a/Herbert/Framework/Exceptions/HttpErrorException.php +++ b/Herbert/Framework/Exceptions/HttpErrorException.php @@ -9,17 +9,29 @@ class HttpErrorException extends \Exception { */ protected $status = 500; + /** + * The response. + * + * @var \Herbert\Framework\Response + */ + protected $response = null; + /** * Constructs the HttpErrorException. * * @param integer $status - * @param string $message + * @param string|mixed $message */ public function __construct($status = 500, $message = null) { - parent::__construct($message); + parent::__construct(is_string($message) ? $message : null); $this->status = $status; + + if ( ! is_string($message)) + { + $this->response = $message; + } } /** @@ -32,4 +44,14 @@ public function getStatus() return $this->status; } + /** + * Gets the response. + * + * @return mixed + */ + public function getResponse() + { + return $this->response; + } + } diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 3475fbc..0a2315f 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -255,21 +255,21 @@ protected function call($callable) { echo $response->getBody(); - return; + die; } if (is_null($response) || is_string($response)) { echo $response; - return; + die; } if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable) { echo (new JsonResponse($response))->getBody(); - return; + die; } throw new Exception('Unknown response type!'); @@ -384,6 +384,14 @@ protected function handler($panel) try { $this->call($callable); } catch (HttpErrorException $e) { + if ($e->getStatus() === 301 || $e->getStatus() === 302) + { + $this->call(function () use (&$e) + { + return $e->getResponse(); + }); + } + global $wp_query; $wp_query->set_404(); diff --git a/Herbert/Framework/Providers/TwigServiceProvider.php b/Herbert/Framework/Providers/TwigServiceProvider.php index 80f22bc..49f996d 100644 --- a/Herbert/Framework/Providers/TwigServiceProvider.php +++ b/Herbert/Framework/Providers/TwigServiceProvider.php @@ -86,6 +86,8 @@ public function constructTwig() $twig->addGlobal($key, $value); } + $twig->addGlobal('errors', session()->getFlashBag()->get('__validation_errors', [])); + foreach ((array) $this->app['twig.functions'] as $function) { $twig->addFunction(new Twig_SimpleFunction($function, $function)); diff --git a/Herbert/Framework/RedirectResponse.php b/Herbert/Framework/RedirectResponse.php index 4be38af..8ce9829 100644 --- a/Herbert/Framework/RedirectResponse.php +++ b/Herbert/Framework/RedirectResponse.php @@ -53,7 +53,7 @@ protected function updateBody() -', htmlspecialchars($this->target, ENT_QUOTES, 'UTF-8')); +', str_replace('"', '\\"', $this->target)); } /** diff --git a/Herbert/Framework/Router.php b/Herbert/Framework/Router.php index 6b1c3a5..bb43ed3 100644 --- a/Herbert/Framework/Router.php +++ b/Herbert/Framework/Router.php @@ -241,6 +241,13 @@ public function parseRequest($wp) ) ); } catch (HttpErrorException $e) { + if ($e->getStatus() === 301 || $e->getStatus() === 302) + { + $this->processResponse($e->getResponse()); + + die; + } + global $wp_query; $wp_query->set_404(); @@ -271,12 +278,21 @@ protected function buildRoute($data, $params) * Processes a request. * * @param \Herbert\Framework\Route $route - * @return mixed + * @return void */ protected function processRequest(Route $route) { - $response = $route->handle(); + $this->processResponse($route->handle()); + } + /** + * Processes a response. + * + * @param \Herbert\Framework\Response $response + * @return void + */ + protected function processResponse(Response $response) + { if ($response instanceof RedirectResponse) { $response->flash(); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index d6e298f..12f840d 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -161,7 +161,7 @@ function session_flashed($key = null, $default = []) */ function view($name, $context = []) { - return herbert('Twig_Environment')->render($name, $context); + return response(herbert('Twig_Environment')->render($name, $context)); } } From b2b79df8e342c2a537bbaef3db694ffda3df27a2 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Thu, 4 Jun 2015 16:59:04 +0100 Subject: [PATCH 23/67] disable timestamps on the models --- Herbert/Framework/Models/Comment.php | 7 +++++++ Herbert/Framework/Models/CommentMeta.php | 7 +++++++ Herbert/Framework/Models/Option.php | 7 +++++++ Herbert/Framework/Models/Post.php | 7 +++++++ Herbert/Framework/Models/PostMeta.php | 7 +++++++ Herbert/Framework/Models/Taxonomy.php | 7 +++++++ Herbert/Framework/Models/Term.php | 7 +++++++ 7 files changed, 49 insertions(+) diff --git a/Herbert/Framework/Models/Comment.php b/Herbert/Framework/Models/Comment.php index 3cfa9f3..990c160 100644 --- a/Herbert/Framework/Models/Comment.php +++ b/Herbert/Framework/Models/Comment.php @@ -7,6 +7,13 @@ */ class Comment extends Model { + /** + * Disable timestamps. + * + * @var boolean + */ + public $timestamps = false; + /** * The table associated with the model. * diff --git a/Herbert/Framework/Models/CommentMeta.php b/Herbert/Framework/Models/CommentMeta.php index 3ac0835..3cd4faf 100644 --- a/Herbert/Framework/Models/CommentMeta.php +++ b/Herbert/Framework/Models/CommentMeta.php @@ -7,6 +7,13 @@ */ class CommentMeta extends Model { + /** + * Disable timestamps. + * + * @var boolean + */ + public $timestamps = false; + /** * The table associated with the model. * diff --git a/Herbert/Framework/Models/Option.php b/Herbert/Framework/Models/Option.php index 4a1ba65..628c9ae 100644 --- a/Herbert/Framework/Models/Option.php +++ b/Herbert/Framework/Models/Option.php @@ -7,6 +7,13 @@ */ class Option extends Model { + /** + * Disable timestamps. + * + * @var boolean + */ + public $timestamps = false; + /** * The table associated with the model. * diff --git a/Herbert/Framework/Models/Post.php b/Herbert/Framework/Models/Post.php index 59dcf3a..ebc21fa 100644 --- a/Herbert/Framework/Models/Post.php +++ b/Herbert/Framework/Models/Post.php @@ -7,6 +7,13 @@ */ class Post extends Model { + /** + * Disable timestamps. + * + * @var boolean + */ + public $timestamps = false; + /** * The table associated with the model. * diff --git a/Herbert/Framework/Models/PostMeta.php b/Herbert/Framework/Models/PostMeta.php index d63afa7..a4380c1 100644 --- a/Herbert/Framework/Models/PostMeta.php +++ b/Herbert/Framework/Models/PostMeta.php @@ -7,6 +7,13 @@ */ class PostMeta extends Model { + /** + * Disable timestamps. + * + * @var boolean + */ + public $timestamps = false; + /** * The table associated with the model. * diff --git a/Herbert/Framework/Models/Taxonomy.php b/Herbert/Framework/Models/Taxonomy.php index fc621d9..109d2ef 100644 --- a/Herbert/Framework/Models/Taxonomy.php +++ b/Herbert/Framework/Models/Taxonomy.php @@ -7,6 +7,13 @@ */ class Taxonomy extends Model { + /** + * Disable timestamps. + * + * @var boolean + */ + public $timestamps = false; + /** * The table associated with the model. * diff --git a/Herbert/Framework/Models/Term.php b/Herbert/Framework/Models/Term.php index b3ea6e6..8c69039 100644 --- a/Herbert/Framework/Models/Term.php +++ b/Herbert/Framework/Models/Term.php @@ -7,6 +7,13 @@ */ class Term extends Model { + /** + * Disable timestamps. + * + * @var boolean + */ + public $timestamps = false; + /** * The table associated with the model. * From 0d7a43ecd8784c867f30a34d39a801966cc9fe21 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 11:42:19 +0100 Subject: [PATCH 24/67] provide apis to the views --- Herbert/Framework/Application.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index e56e1f5..8f39157 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -98,6 +98,13 @@ class Application extends \Illuminate\Container\Container implements \Illuminate */ protected $matched = []; + /** + * The plugin apis. + * + * @var array + */ + protected $apis = []; + /** * The plugin configurations. * @@ -443,6 +450,7 @@ protected function loadPluginAPIs($requires = []) { global $$name; $api = $$name = new API($this); + $this->apis[] = [$name, $api]; require "$require"; } @@ -1131,6 +1139,13 @@ protected function buildViewGlobals() $globals = array_merge($globals, $val); } + foreach ($this->apis as $api) + { + list($name, $instance) = $api; + + $globals[$name] = $instance; + } + $this->builtViewGlobals = $globals; } From 13a6d109613a0480bbe751237f3af2cdbb2445c7 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 14:38:06 +0100 Subject: [PATCH 25/67] allow for method.uses --- Herbert/Framework/Panel.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 0a2315f..3ae7db2 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -370,11 +370,9 @@ protected function handler($panel) $callable = array_get($panel, $method, $callable); - if ($action = strtolower($this->http->get('action'))) - { - $callable = array_get($panel, $action, $callable); - $callable = array_get($panel, "{$method}.{$action}", $callable); - } + $action = strtolower($this->http->get('action', 'uses')); + $callable = array_get($panel, $action, $callable); + $callable = array_get($panel, "{$method}.{$action}", $callable); if (is_array($callable)) { From 2dd64f46c975cc35419bb7a68fee80c22712cadb Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 15:31:18 +0100 Subject: [PATCH 26/67] added dates to post/comment and fixed a routing bug in panel.php --- Herbert/Framework/Models/Comment.php | 50 ++++++++++++++++++++---- Herbert/Framework/Models/Post.php | 58 ++++++++++++++++++++++++---- Herbert/Framework/Panel.php | 10 +++-- 3 files changed, 101 insertions(+), 17 deletions(-) diff --git a/Herbert/Framework/Models/Comment.php b/Herbert/Framework/Models/Comment.php index 990c160..1a54ce7 100644 --- a/Herbert/Framework/Models/Comment.php +++ b/Herbert/Framework/Models/Comment.php @@ -7,13 +7,6 @@ */ class Comment extends Model { - /** - * Disable timestamps. - * - * @var boolean - */ - public $timestamps = false; - /** * The table associated with the model. * @@ -28,6 +21,20 @@ class Comment extends Model { */ protected $primaryKey = 'comment_ID'; + /** + * The name of the "created at" column. + * + * @var string + */ + const CREATED_AT = 'comment_date'; + + /** + * The name of the "updated at" column. + * + * @var string + */ + const UPDATED_AT = null; + /** * The attributes that are mass assignable. * @@ -70,4 +77,33 @@ public function meta() return $this->hasMany(__NAMESPACE__ . '\CommentMeta', 'comment_id'); } + /** + * Set the value of the "created at" attribute. + * + * @param mixed $value + * @return void + */ + public function setCreatedAt($value) + { + $this->{static::CREATED_AT} = $value; + + if ( ! $value instanceof Carbon) + { + $value = new Carbon($value); + } + + $this->{static::CREATED_AT . '_gmt'} = $value->timezone('GMT'); + } + + /** + * Set the value of the "updated at" attribute. + * + * @param mixed $value + * @return void + */ + public function setUpdatedAt($value) + { + // + } + } diff --git a/Herbert/Framework/Models/Post.php b/Herbert/Framework/Models/Post.php index ebc21fa..67882b0 100644 --- a/Herbert/Framework/Models/Post.php +++ b/Herbert/Framework/Models/Post.php @@ -1,5 +1,6 @@ where('post_type', $type); } + /** + * Set the value of the "created at" attribute. + * + * @param mixed $value + * @return void + */ + public function setCreatedAt($value) + { + $this->{static::CREATED_AT} = $value; + + if ( ! $value instanceof Carbon) + { + $value = new Carbon($value); + } + + $this->{static::CREATED_AT . '_gmt'} = $value->timezone('GMT'); + } + + /** + * Set the value of the "updated at" attribute. + * + * @param mixed $value + * @return void + */ + public function setUpdatedAt($value) + { + $this->{static::UPDATED_AT} = $value; + + if ( ! $value instanceof Carbon) + { + $value = new Carbon($value); + } + + $this->{static::UPDATED_AT . '_gmt'} = $value->timezone('GMT'); + } + } diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 3ae7db2..4bb8871 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -370,9 +370,13 @@ protected function handler($panel) $callable = array_get($panel, $method, $callable); - $action = strtolower($this->http->get('action', 'uses')); - $callable = array_get($panel, $action, $callable); - $callable = array_get($panel, "{$method}.{$action}", $callable); + if ($callable === $panel['uses']) + { + $action = strtolower($this->http->get('action', 'uses')); + + $callable = array_get($panel, $action, $callable); + $callable = array_get($panel, "{$method}.{$action}", $callable); + } if (is_array($callable)) { From a6e2db731853940cea489cad0023462945a1196b Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 16:10:53 +0100 Subject: [PATCH 27/67] added soft deletes to Post --- Herbert/Framework/Models/Post.php | 10 ++ .../Models/SoftDeletes/SoftDeletes.php | 43 +++++++ .../Models/SoftDeletes/SoftDeletingScope.php | 115 ++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 Herbert/Framework/Models/SoftDeletes/SoftDeletes.php create mode 100644 Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php diff --git a/Herbert/Framework/Models/Post.php b/Herbert/Framework/Models/Post.php index 67882b0..9f9857c 100644 --- a/Herbert/Framework/Models/Post.php +++ b/Herbert/Framework/Models/Post.php @@ -2,12 +2,15 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +use Herbert\Framework\Models\SoftDeletes\SoftDeletes; /** * @see http://getherbert.com */ class Post extends Model { + use SoftDeletes; + /** * The table associated with the model. * @@ -36,6 +39,13 @@ class Post extends Model { */ const UPDATED_AT = 'post_modified'; + /** + * The name of the "deleted at" column. + * + * @var string + */ + const DELETED_AT = 'post_status'; + /** * The attributes that are mass assignable. * diff --git a/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php b/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php new file mode 100644 index 0000000..fb90872 --- /dev/null +++ b/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php @@ -0,0 +1,43 @@ +newQueryWithoutScope(new SoftDeletingScope); + } + + /** + * Get a new query builder that only includes soft deletes. + * + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public static function onlyTrashed() + { + $instance = new static; + + $column = $instance->getQualifiedDeletedAtColumn(); + + return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column); + } + +} diff --git a/Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php b/Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php new file mode 100644 index 0000000..8fcf08a --- /dev/null +++ b/Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php @@ -0,0 +1,115 @@ +where($model->getQualifiedDeletedAtColumn(), '!=', 'trash'); + + $this->extend($builder); + } + + /** + * Remove the scope from the given Eloquent query builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @param \Illuminate\Database\Eloquent\Model $model + * @return void + */ + public function remove(Builder $builder, Model $model) + { + $column = $model->getQualifiedDeletedAtColumn(); + + $query = $builder->getQuery(); + + $query->wheres = collect($query->wheres)->reject(function ($where) use ($column) { + return $this->isSoftDeleteConstraint($where, $column); + })->values()->all(); + + $bindings = $query->getRawBindings(); + + foreach ($bindings['where'] as $k => $v) + { + if ($v !== 'trash') + { + continue; + } + + unset($bindings['where'][$k]); + + break; + } + + $query->setBindings($bindings['where']); + } + + /** + * Extend the query builder with the needed functions. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + public function extend(Builder $builder) + { + foreach ($this->extensions as $extension) { + $this->{"add{$extension}"}($builder); + } + + $builder->onDelete(function (Builder $builder) { + $column = $this->getDeletedAtColumn($builder); + + return $builder->update([ + $column => 'trash', + ]); + }); + } + + /** + * Add the only-trashed extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addOnlyTrashed(Builder $builder) + { + $builder->macro('onlyTrashed', function (Builder $builder) { + $model = $builder->getModel(); + + $this->remove($builder, $model); + + $builder->getQuery()->where($model->getQualifiedDeletedAtColumn(), 'trash'); + + return $builder; + }); + } + + /** + * Determine if the given where clause is a soft delete constraint. + * + * @param array $where + * @param string $column + * @return bool + */ + protected function isSoftDeleteConstraint(array $where, $column) + { + return $where === [ + 'type' => 'Basic', + 'column' => $column, + 'operator' => '!=', + 'value' => 'trash', + 'boolean' => 'and' + ]; + } + +} From 2e04b00e9172bbd4eafb3d0133d6960ce47f63c2 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 16:15:19 +0100 Subject: [PATCH 28/67] fixing a panel bug I created in my last panel commit --- Herbert/Framework/Panel.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 4bb8871..d1c8268 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -365,22 +365,25 @@ protected function namespaceAs($as) */ protected function handler($panel) { - $callable = $panel['uses']; + $callable = $uses = $panel['uses']; $method = strtolower($this->http->method()); + $action = strtolower($this->http->get('action', 'uses')); $callable = array_get($panel, $method, $callable); - if ($callable === $panel['uses']) + if ($callable === $uses || is_array($callable)) { - $action = strtolower($this->http->get('action', 'uses')); - $callable = array_get($panel, $action, $callable); + } + + if ($callable === $uses || is_array($callable)) + { $callable = array_get($panel, "{$method}.{$action}", $callable); } if (is_array($callable)) { - $callable = $panel['uses']; + $callable = $uses; } try { From 314ddb142450f85aae7d5280b33adc39bf92404e Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 16:45:31 +0100 Subject: [PATCH 29/67] fixed soft delete's delete() and restore() --- .../Models/SoftDeletes/SoftDeletes.php | 54 ++++++++++++++++++- .../Models/SoftDeletes/SoftDeletingScope.php | 15 ++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php b/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php index fb90872..76252b2 100644 --- a/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php +++ b/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php @@ -16,6 +16,58 @@ public static function bootSoftDeletes() static::addGlobalScope(new SoftDeletingScope); } + /** + * Perform the actual delete query on this model instance. + * + * @return void + */ + protected function runSoftDelete() + { + $query = $this->newQuery()->where($this->getKeyName(), $this->getKey()); + + $this->{$this->getDeletedAtColumn()} = 'trash'; + + $query->update([$this->getDeletedAtColumn() => 'trash']); + } + + /** + * Restore a soft-deleted model instance. + * + * @return bool|null + */ + public function restore() + { + // If the restoring event does not return false, we will proceed with this + // restore operation. Otherwise, we bail out so the developer will stop + // the restore totally. We will clear the deleted timestamp and save. + if ($this->fireModelEvent('restoring') === false) { + return false; + } + + $this->{$this->getDeletedAtColumn()} = 'publish'; + + // Once we have saved the model, we will fire the "restored" event so this + // developer will do anything they need to after a restore operation is + // totally finished. Then we will return the result of the save call. + $this->exists = true; + + $result = $this->save(); + + $this->fireModelEvent('restored', false); + + return $result; + } + + /** + * Determine if the model instance has been soft-deleted. + * + * @return bool + */ + public function trashed() + { + return $this->{$this->getDeletedAtColumn()} === 'trash'; + } + /** * Get a new query builder that includes soft deletes. * @@ -37,7 +89,7 @@ public static function onlyTrashed() $column = $instance->getQualifiedDeletedAtColumn(); - return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column); + return $instance->newQueryWithoutScope(new SoftDeletingScope)->where($column, '!=', 'trash'); } } diff --git a/Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php b/Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php index 8fcf08a..a9a89bc 100644 --- a/Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php +++ b/Herbert/Framework/Models/SoftDeletes/SoftDeletingScope.php @@ -75,6 +75,21 @@ public function extend(Builder $builder) }); } + /** + * Add the restore extension to the builder. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @return void + */ + protected function addRestore(Builder $builder) + { + $builder->macro('restore', function (Builder $builder) { + $builder->withTrashed(); + + return $builder->update([$builder->getModel()->getDeletedAtColumn() => 'publish']); + }); + } + /** * Add the only-trashed extension to the builder. * From 37c4db902380bf520e02ddadbb0574f13626ea13 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 17:01:45 +0100 Subject: [PATCH 30/67] bump version --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 8f39157..4b6d633 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.6'; + const VERSION = '0.9.7'; /** * The application's version. From 09a3187fd4b529839042b53669e698f6639cc2fa Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 5 Jun 2015 17:04:41 +0100 Subject: [PATCH 31/67] Revert "bump version" This reverts commit 37c4db902380bf520e02ddadbb0574f13626ea13. --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 4b6d633..8f39157 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.7'; + const VERSION = '0.9.6'; /** * The application's version. From 962ec1a687b9a5b0ce1329efa5aa0523267935ab Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Mon, 8 Jun 2015 11:02:51 +0100 Subject: [PATCH 32/67] provided session and session_flashed to twig --- Herbert/Framework/Providers/TwigServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/TwigServiceProvider.php b/Herbert/Framework/Providers/TwigServiceProvider.php index 80f22bc..d4d3e1e 100644 --- a/Herbert/Framework/Providers/TwigServiceProvider.php +++ b/Herbert/Framework/Providers/TwigServiceProvider.php @@ -52,7 +52,9 @@ public function register() 'content_directory', 'plugin_directory', 'panel_url', - 'route_url' + 'route_url', + 'session', + 'session_flashed' ]; }); From 23a61e48030143b1ef37644ec892d07dec713fd5 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Mon, 8 Jun 2015 11:55:46 +0100 Subject: [PATCH 33/67] fix for Panel, accidentally dying when it shouldn't --- Herbert/Framework/Panel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index d1c8268..ce86543 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -255,21 +255,21 @@ protected function call($callable) { echo $response->getBody(); - die; + return; } if (is_null($response) || is_string($response)) { echo $response; - die; + return; } if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable) { echo (new JsonResponse($response))->getBody(); - die; + return; } throw new Exception('Unknown response type!'); From bd630b2bdab54837c01100420f85765f69551916 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Mon, 8 Jun 2015 12:50:12 +0100 Subject: [PATCH 34/67] add a skip for non-GET Panel methods --- Herbert/Framework/Panel.php | 57 +++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index ce86543..e7a5350 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -54,8 +54,17 @@ public function __construct(Application $app, Http $http) $this->app = $app; $this->http = $http; - // add_action('init', [$this, 'bootRoutes']); + if ( ! is_admin()) + { + return; + } + add_action('admin_menu', [$this, 'boot']); + + if ($http->method() !== 'GET') + { + add_action('init', [$this, 'bootEarly']); + } } /** @@ -83,6 +92,26 @@ public function boot() } } + /** + * Boots early. + * + * @return void + */ + public function bootEarly() + { + if (($slug = $this->http->get('page')) === null) + { + return; + } + + if (($panel = $this->getPanel($slug, true)) === null) + { + return; + } + + $this->handler($panel, true); + } + /** * Adds a panel. * @@ -253,6 +282,13 @@ protected function call($callable) if ($response instanceof Response) { + status_header($response->getStatusCode()); + + foreach ($response->getHeaders() as $key => $value) + { + @header($key . ': ' . $value); + } + echo $response->getBody(); return; @@ -278,14 +314,17 @@ protected function call($callable) /** * Gets a panel. * - * @param string $name + * @param string $name + * @param boolean $slug * @return array */ - protected function getPanel($name) + protected function getPanel($name, $slug = false) { + $slug = $slug ? 'slug' : 'as'; + foreach ($this->panels as $panel) { - if (array_get($panel, 'as') !== $name) + if (array_get($panel, $slug) !== $name) { continue; } @@ -360,10 +399,11 @@ protected function namespaceAs($as) /** * Return the correct callable based on action * - * @param $panel + * @param array $panel + * @param boolean $strict * @return void */ - protected function handler($panel) + protected function handler($panel, $strict = false) { $callable = $uses = $panel['uses']; $method = strtolower($this->http->method()); @@ -386,6 +426,11 @@ protected function handler($panel) $callable = $uses; } + if ($strict && $uses === $callable) + { + return; + } + try { $this->call($callable); } catch (HttpErrorException $e) { From e4226d9fb5d819c841a39de4043494e9eff1f93a Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Mon, 8 Jun 2015 17:24:08 +0100 Subject: [PATCH 35/67] fixed missing use statement --- Herbert/Framework/Panel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index e7a5350..2d7d341 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -1,5 +1,6 @@ Date: Tue, 9 Jun 2015 10:22:12 +0100 Subject: [PATCH 36/67] fixed softdeletes scopes --- Herbert/Framework/Models/SoftDeletes/SoftDeletes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php b/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php index 76252b2..b9676fd 100644 --- a/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php +++ b/Herbert/Framework/Models/SoftDeletes/SoftDeletes.php @@ -75,7 +75,7 @@ public function trashed() */ public static function withTrashed() { - return (new static)->newQueryWithoutScope(new SoftDeletingScope); + return (new static)->newQueryWithoutScope(new SoftDeletingScope)->withTrashed(); } /** @@ -89,7 +89,7 @@ public static function onlyTrashed() $column = $instance->getQualifiedDeletedAtColumn(); - return $instance->newQueryWithoutScope(new SoftDeletingScope)->where($column, '!=', 'trash'); + return $instance->newQueryWithoutScope(new SoftDeletingScope)->onlyTrashed(); } } From d1a481535cfbb961d33f0a6c9bb306d5a2c6227c Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Tue, 9 Jun 2015 10:43:21 +0100 Subject: [PATCH 37/67] bind to new L5 contract --- Herbert/Framework/Application.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 8f39157..27cc973 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -153,11 +153,11 @@ public function __construct() /** * Added to satisfy interface * - * @return null + * @return string */ public function basePath() { - return; + return content_directory() . '/herbert-cache'; } /** @@ -1254,4 +1254,24 @@ public static function getInstance() return static::$instance; } + /** + * Get the path to the cached "compiled.php" file. + * + * @return string + */ + public function getCachedCompilePath() + { + return $this->basePath() . '/vendor/compiled.php'; + } + + /** + * Get the path to the cached services.json file. + * + * @return string + */ + public function getCachedServicesPath() + { + return $this->basePath() . '/vendor/services.json'; + } + } From f0929486d5b0fdaf8a9a1d8cb1ed137b956c5dff Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Tue, 9 Jun 2015 11:14:15 +0100 Subject: [PATCH 38/67] fixed a panel bug with non-GET requests --- Herbert/Framework/Panel.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 2d7d341..ae83d5a 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -110,7 +110,12 @@ public function bootEarly() return; } - $this->handler($panel, true); + if ( ! $this->handler($panel, true)) + { + return; + } + + die; } /** @@ -429,7 +434,7 @@ protected function handler($panel, $strict = false) if ($strict && $uses === $callable) { - return; + return false; } try { @@ -455,6 +460,8 @@ protected function handler($panel, $strict = false) do_action('admin_notices'); } + + return true; } } From e6ea3f9d05ec5e6de2c31409517d1266989e49b1 Mon Sep 17 00:00:00 2001 From: "Connor S. Parks" Date: Tue, 9 Jun 2015 14:22:25 +0100 Subject: [PATCH 39/67] Revert to L5.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ab2e78a..8ce4feb 100644 --- a/composer.json +++ b/composer.json @@ -4,10 +4,10 @@ "license": "MIT", "require": { "twig/twig": "~1.16", - "illuminate/database": "~5.1", + "illuminate/database": "~5.0", "vierbergenlars/php-semver": "~3.0", "symfony/var-dumper": "~3.0", - "illuminate/http": "~5.1" + "illuminate/http": "~5.0" }, "autoload": { "psr-4": { From 98b4926883811092f5760ad076524b2b3c686f87 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Tue, 9 Jun 2015 14:32:23 +0100 Subject: [PATCH 40/67] allow method override in query string --- Herbert/Framework/Panel.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index ae83d5a..e2525ce 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -11,6 +11,17 @@ */ class Panel { + /** + * @var array + */ + protected static $methods = [ + 'GET', + 'POST', + 'PUT', + 'PATCH', + 'DELETE' + ]; + /** * @var array */ @@ -62,6 +73,15 @@ public function __construct(Application $app, Http $http) add_action('admin_menu', [$this, 'boot']); + $http->setMethod($http->get('_method'), $old = $http->method()); + + if ( ! in_array($http->method(), self::$methods)) + { + $http->setMethod($old); + } + + dd($http->method()); + if ($http->method() !== 'GET') { add_action('init', [$this, 'bootEarly']); From d20abf6ec06207a2a7c32b3d85cc9421758a7540 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Tue, 9 Jun 2015 14:33:01 +0100 Subject: [PATCH 41/67] removed debug --- Herbert/Framework/Panel.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index e2525ce..45a1a17 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -80,8 +80,6 @@ public function __construct(Application $app, Http $http) $http->setMethod($old); } - dd($http->method()); - if ($http->method() !== 'GET') { add_action('init', [$this, 'bootEarly']); From 64d2cf8904d254743009136ab3067d3ff2cbf644 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Tue, 9 Jun 2015 17:26:33 +0100 Subject: [PATCH 42/67] Route Exception fix --- Herbert/Framework/Router.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Herbert/Framework/Router.php b/Herbert/Framework/Router.php index bb43ed3..5b41a07 100644 --- a/Herbert/Framework/Router.php +++ b/Herbert/Framework/Router.php @@ -248,15 +248,25 @@ public function parseRequest($wp) die; } - global $wp_query; - $wp_query->set_404(); + if ($e->getStatus() === 404) + { + global $wp_query; + $wp_query->set_404(); + } status_header($e->getStatus()); define('HERBERT_HTTP_ERROR_CODE', $e->getStatus()); define('HERBERT_HTTP_ERROR_MESSAGE', $e->getMessage()); - @include get_404_template(); + if ($e->getStatus() === 404) + { + @include get_404_template(); + } + else + { + echo $e->getMessage(); + } } die; From 5b16bc3cd666f18378f2f881113d5a14264dc796 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Wed, 10 Jun 2015 10:48:40 +0100 Subject: [PATCH 43/67] bump version number --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 27cc973..25dc236 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.6'; + const VERSION = '0.9.7'; /** * The application's version. From 52b38a8197d5dbca007ff632d24ed5ae60983ed1 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Wed, 10 Jun 2015 18:03:32 +0100 Subject: [PATCH 44/67] Typo on relationship --- Herbert/Framework/Models/Comment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Models/Comment.php b/Herbert/Framework/Models/Comment.php index 1a54ce7..4e7364f 100644 --- a/Herbert/Framework/Models/Comment.php +++ b/Herbert/Framework/Models/Comment.php @@ -64,7 +64,7 @@ class Comment extends Model { */ public function post() { - return $this->belongsTo(__NAMESPACE__ . '/Post', 'comment_post_ID'); + return $this->belongsTo(__NAMESPACE__ . '\Post', 'comment_post_ID'); } /** From 00eecd6e044f80c12f7a35355ab2c0e069923287 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Thu, 11 Jun 2015 17:13:10 +0100 Subject: [PATCH 45/67] bump version number --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 25dc236..8098abe 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.7'; + const VERSION = '0.9.8'; /** * The application's version. From 3a49cb81a1c2722c345f9d475642dd8030f3def3 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Tue, 16 Jun 2015 15:33:09 +0100 Subject: [PATCH 46/67] added errors() helper function --- .../Providers/HerbertServiceProvider.php | 10 +++++++++ .../Providers/TwigServiceProvider.php | 2 +- bootstrap/helpers.php | 22 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/HerbertServiceProvider.php b/Herbert/Framework/Providers/HerbertServiceProvider.php index cd07dc2..3d81931 100644 --- a/Herbert/Framework/Providers/HerbertServiceProvider.php +++ b/Herbert/Framework/Providers/HerbertServiceProvider.php @@ -105,6 +105,16 @@ public function register() 'notifier', 'Herbert\Framework\Notifier' ); + + $this->app->singleton( + 'errors', + function () + { + return session_flashed('__validation_errors', []); + } + ); + + $_GLOBALS['errors'] = $this->app['errors']; } /** diff --git a/Herbert/Framework/Providers/TwigServiceProvider.php b/Herbert/Framework/Providers/TwigServiceProvider.php index 759b0a0..80753d7 100644 --- a/Herbert/Framework/Providers/TwigServiceProvider.php +++ b/Herbert/Framework/Providers/TwigServiceProvider.php @@ -88,7 +88,7 @@ public function constructTwig() $twig->addGlobal($key, $value); } - $twig->addGlobal('errors', session()->getFlashBag()->get('__validation_errors', [])); + $twig->addGlobal('errors', $this->app['errors']); foreach ((array) $this->app['twig.functions'] as $function) { diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 12f840d..2ea9328 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -110,6 +110,28 @@ function herbert($binding = null) } } +if ( ! function_exists('errors')) +{ + /** + * Get the errors. + * + * @param string key + * @return array + */ + function errors($key = null) + { + $errors = herbert('errors'); + $errors = isset($errors[0]) ? $errors[0] : $errors; + + if (!$key) + { + return $errors; + } + + return array_get($errors, $key); + } +} + if ( ! function_exists('session')) { /** From 5fec3cb1ee131f215879bd3b361c3d21ef5b069c Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Tue, 16 Jun 2015 15:33:24 +0100 Subject: [PATCH 47/67] provided errors helper to twig --- Herbert/Framework/Providers/TwigServiceProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/TwigServiceProvider.php b/Herbert/Framework/Providers/TwigServiceProvider.php index 80753d7..beb4afb 100644 --- a/Herbert/Framework/Providers/TwigServiceProvider.php +++ b/Herbert/Framework/Providers/TwigServiceProvider.php @@ -54,7 +54,8 @@ public function register() 'panel_url', 'route_url', 'session', - 'session_flashed' + 'session_flashed', + 'errors' ]; }); From d856229d2ba7c3d9b9b3b0fc6bfb92b2fcd1094f Mon Sep 17 00:00:00 2001 From: "Connor S. Parks" Date: Fri, 19 Jun 2015 15:43:39 +0100 Subject: [PATCH 48/67] Pull in the plugin's plugin.php --- bootstrap/autoload.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 4b7e308..ae2859d 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -84,6 +84,9 @@ } $herbert->pluginMatched($root); + + @require_once $root.'/plugin.php'; + $herbert->loadPlugin($config); } From ab46f4016e786609b3543c72ee0207c288656386 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Fri, 19 Jun 2015 16:08:24 +0100 Subject: [PATCH 49/67] Version increase --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 8098abe..5ef7098 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.8'; + const VERSION = '0.9.9'; /** * The application's version. From f3f30079193705661efbb606f0f13514052bdd42 Mon Sep 17 00:00:00 2001 From: Jon McPartland Date: Thu, 25 Jun 2015 13:49:45 +0100 Subject: [PATCH 50/67] support position param for menu pages --- Herbert/Framework/Panel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index 45a1a17..e735684 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -209,7 +209,8 @@ protected function addPanel($panel) 'manage_options', $panel['slug'], $this->makeCallable($panel), - isset($panel['icon']) ? $this->fetchIcon($panel['icon']) : '' + isset($panel['icon']) ? $this->fetchIcon($panel['icon']) : '', + isset($panel['order']) ? $panel['order'] : null ); if (isset($panel['rename']) && !empty($panel['rename'])) From 8b4f721a8912a1059f101c062ad10240aeaf79f2 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Tue, 30 Jun 2015 14:34:13 +0100 Subject: [PATCH 51/67] Fixes #9 @twoSeats @brucevdkooij --- Herbert/Framework/Providers/HerbertServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/HerbertServiceProvider.php b/Herbert/Framework/Providers/HerbertServiceProvider.php index 3d81931..674ae2a 100644 --- a/Herbert/Framework/Providers/HerbertServiceProvider.php +++ b/Herbert/Framework/Providers/HerbertServiceProvider.php @@ -135,7 +135,7 @@ protected function registerEloquent() 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => DB_CHARSET, - 'collation' => 'utf8_unicode_ci', + 'collation' => DB_COLLATE, 'prefix' => $wpdb->prefix ]); From 0749fa57493da4eb3bf985c6914c2a1eec9342b6 Mon Sep 17 00:00:00 2001 From: Connor Parks Date: Fri, 10 Jul 2015 11:40:05 +0100 Subject: [PATCH 52/67] fixed an enqueue bug and a panel rendering bug + bumped the version up to 0.9.10 + made the enqueue panel matcher much better --- Herbert/Framework/Application.php | 2 +- Herbert/Framework/Enqueue.php | 33 +++++++++++-------------------- Herbert/Framework/Panel.php | 16 ++++++++++++--- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 5ef7098..5f52e9c 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.9'; + const VERSION = '0.9.10'; /** * The application's version. diff --git a/Herbert/Framework/Enqueue.php b/Herbert/Framework/Enqueue.php index 2fbaf8c..4602740 100644 --- a/Herbert/Framework/Enqueue.php +++ b/Herbert/Framework/Enqueue.php @@ -183,32 +183,23 @@ public function filterHook($attrs, $filterWith) public function filterPanel($attrs, $filterWith) { $panels = $this->app['panel']->getPanels(); - $http = $this->app['http']; + $page = $this->app['http']->get('page', false); - if ($filterWith[0] === '*') { - if (!$http->has('page')) - { - return false; - } - - foreach ($panels as $panel) - { - if ($panel['slug'] === $http->get('page')) - { - return true; - } - } + if (!$page && function_exists('get_current_screen')) + { + $page = object_get(get_current_screen(), 'id', $page); } - else + + foreach ($filterWith as $filter) { - foreach ($filterWith as $filter) + $filtered = array_filter($panels, function ($panel) use ($page, $filter) { + return $page === $panel['slug'] && str_is($filter, $panel['slug']); + }); + + if (count($filtered) > 0) { - if ($panels[$filter]['slug'] === $http->get('page')) - { - return true; - } + return true; } - } return false; diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index e735684..d7102df 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -360,6 +360,16 @@ protected function getPanel($name, $slug = false) return null; } + /** + * Gets the panels. + * + * @return array + */ + public function getPanels() + { + return array_values($this->panels); + } + /** * Get the URL to a panel. * @@ -434,16 +444,16 @@ protected function handler($panel, $strict = false) $method = strtolower($this->http->method()); $action = strtolower($this->http->get('action', 'uses')); - $callable = array_get($panel, $method, $callable); + $callable = array_get($panel, $method, false) ?: $callable; if ($callable === $uses || is_array($callable)) { - $callable = array_get($panel, $action, $callable); + $callable = array_get($panel, $action, false) ?: $callable; } if ($callable === $uses || is_array($callable)) { - $callable = array_get($panel, "{$method}.{$action}", $callable); + $callable = array_get($panel, "{$method}.{$action}", false) ?: $callable; } if (is_array($callable)) From 8730b77e6466655eb512620d7ed595fa7a613429 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Mon, 27 Jul 2015 11:57:41 +0100 Subject: [PATCH 53/67] Set fallback for collation --- Herbert/Framework/Providers/HerbertServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/HerbertServiceProvider.php b/Herbert/Framework/Providers/HerbertServiceProvider.php index 674ae2a..37e004e 100644 --- a/Herbert/Framework/Providers/HerbertServiceProvider.php +++ b/Herbert/Framework/Providers/HerbertServiceProvider.php @@ -135,7 +135,7 @@ protected function registerEloquent() 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => DB_CHARSET, - 'collation' => DB_COLLATE, + 'collation' => DB_COLLATE ?: 'utf8_general_ci', 'prefix' => $wpdb->prefix ]); From de17b91acb63b9868e3641069590b401dae9a452 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Mon, 27 Jul 2015 12:20:23 +0100 Subject: [PATCH 54/67] Make shortcodes handle Response object --- Herbert/Framework/Shortcode.php | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Herbert/Framework/Shortcode.php b/Herbert/Framework/Shortcode.php index 4f69f21..5909135 100644 --- a/Herbert/Framework/Shortcode.php +++ b/Herbert/Framework/Shortcode.php @@ -60,13 +60,48 @@ public function add($name, $callable, $arguments = []) } } - return $this->app->call( + $response = $this->app->call( $callable, array_merge([ '_attributes' => $attributes, '_content' => $content ], $attributes) ); + + if ($response instanceof RedirectResponse) + { + $response->flash(); + } + + if ($response instanceof Response) + { + status_header($response->getStatusCode()); + + foreach ($response->getHeaders() as $key => $value) + { + @header($key . ': ' . $value); + } + + echo $response->getBody(); + + return; + } + + if (is_null($response) || is_string($response)) + { + echo $response; + + return; + } + + if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable) + { + echo (new JsonResponse($response))->getBody(); + + return; + } + + throw new Exception('Unknown response type!'); }); } From 1b5316820c242512aff2849e25503bbae43adac7 Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Tue, 28 Jul 2015 19:14:29 +0100 Subject: [PATCH 55/67] Return shortcode instead of echo. --- Herbert/Framework/Shortcode.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Herbert/Framework/Shortcode.php b/Herbert/Framework/Shortcode.php index 5909135..4e99072 100644 --- a/Herbert/Framework/Shortcode.php +++ b/Herbert/Framework/Shortcode.php @@ -82,23 +82,17 @@ public function add($name, $callable, $arguments = []) @header($key . ': ' . $value); } - echo $response->getBody(); - - return; + return $response->getBody(); } if (is_null($response) || is_string($response)) { - echo $response; - - return; + return $response; } if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable) { - echo (new JsonResponse($response))->getBody(); - - return; + return (new JsonResponse($response))->getBody(); } throw new Exception('Unknown response type!'); From c68ef048c15b376ba7c652cec3915d3b9bfa0edb Mon Sep 17 00:00:00 2001 From: Jason Agnew Date: Tue, 28 Jul 2015 19:15:01 +0100 Subject: [PATCH 56/67] Bump version --- Herbert/Framework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index 5f52e9c..ee7c3e1 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -14,7 +14,7 @@ class Application extends \Illuminate\Container\Container implements \Illuminate /** * The application's version. */ - const VERSION = '0.9.10'; + const VERSION = '0.9.13'; /** * The application's version. From b2e838f45193f6ab300bd1c480cd030e3870048c Mon Sep 17 00:00:00 2001 From: mn-martin Date: Wed, 4 Nov 2015 11:24:51 +0100 Subject: [PATCH 57/67] Fix: open_basedir restriction Plugin activation results on some setups in following error: Warning: is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/xxx/:/tmp) in /xxx/vendor/twig/twig/lib/Twig/Loader/Filesystem.php on line 93 This can be easily fixed applying this simple change. --- Herbert/Framework/Providers/TwigServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/TwigServiceProvider.php b/Herbert/Framework/Providers/TwigServiceProvider.php index beb4afb..cce2573 100644 --- a/Herbert/Framework/Providers/TwigServiceProvider.php +++ b/Herbert/Framework/Providers/TwigServiceProvider.php @@ -20,7 +20,7 @@ public function register() { $this->app->singleton('twig.loader', function () { - $loader = new Twig_Loader_Filesystem('/'); + $loader = new Twig_Loader_Filesystem(); foreach ($this->app->getPlugins() as $plugin) { From 0d99e376e1c26aa097157560f8ea118a26751406 Mon Sep 17 00:00:00 2001 From: foksisko Date: Sat, 12 Dec 2015 06:39:24 +0000 Subject: [PATCH 58/67] Throw fatal error when the parameter $callable in $shortcode->add() is a closure https://github.com/getherbert/herbert/issues/65 --- Herbert/Framework/Shortcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Shortcode.php b/Herbert/Framework/Shortcode.php index 4e99072..25b65b4 100644 --- a/Herbert/Framework/Shortcode.php +++ b/Herbert/Framework/Shortcode.php @@ -41,7 +41,7 @@ public function add($name, $callable, $arguments = []) $attributes = $this->renameArguments($arguments, $attributes); } - if (strpos($callable, '::') !== false) + if (is_string($callable) && strpos($callable, '::') !== false) { list($api, $method) = explode('::', $callable); From 11530233af6e6cdee71b9279ec7bf5a629da8da3 Mon Sep 17 00:00:00 2001 From: Tor Morten Jensen Date: Mon, 22 Feb 2016 13:34:18 +0100 Subject: [PATCH 59/67] Adds support for script localization Adds support for WordPress' script localization feature. --- Herbert/Framework/Enqueue.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Herbert/Framework/Enqueue.php b/Herbert/Framework/Enqueue.php index 4602740..160a960 100644 --- a/Herbert/Framework/Enqueue.php +++ b/Herbert/Framework/Enqueue.php @@ -73,6 +73,10 @@ public function buildInclude($attrs, $footer) else { wp_enqueue_script($attrs['as'], $attrs['src'], [], false, $footer); + + if(isset($attrs['localize'])) { + wp_localize_script( $attrs['as'], $attrs['as'], $attrs['localize'] ); + } } } From 8b6b192174b7f34d96bb4b666ffb27db0ee27641 Mon Sep 17 00:00:00 2001 From: shankarbala33 Date: Wed, 20 Apr 2016 18:04:31 +0530 Subject: [PATCH 60/67] To Set COLLATE as Wordpress Default Collate TO Set Default Collate to Avoid PDO Exceptions --- Herbert/Framework/Providers/HerbertServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Providers/HerbertServiceProvider.php b/Herbert/Framework/Providers/HerbertServiceProvider.php index 37e004e..6bb5826 100644 --- a/Herbert/Framework/Providers/HerbertServiceProvider.php +++ b/Herbert/Framework/Providers/HerbertServiceProvider.php @@ -135,7 +135,7 @@ protected function registerEloquent() 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => DB_CHARSET, - 'collation' => DB_COLLATE ?: 'utf8_general_ci', + 'collation' => DB_COLLATE ?: $wpdb->collate, 'prefix' => $wpdb->prefix ]); From 6624d09bf86895434d217af50a976b6eb819ddd9 Mon Sep 17 00:00:00 2001 From: Tom Holland Date: Mon, 25 Apr 2016 18:25:36 -0700 Subject: [PATCH 61/67] Router argument issue I don't generate any routes with herbert. I noticed that my nginx error log was getting flooded with errors about foreach not having a valid argument. So I added a check to make sure that there is in fact an array of routes to add before trying to iterate it! No more log spam. --- Herbert/Framework/Router.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Herbert/Framework/Router.php b/Herbert/Framework/Router.php index 5b41a07..0af15af 100644 --- a/Herbert/Framework/Router.php +++ b/Herbert/Framework/Router.php @@ -94,11 +94,15 @@ public function __construct(Application $app, Http $http) public function boot() { add_rewrite_tag('%herbert_route%', '(.+)'); - - foreach ($this->routes[$this->http->method()] as $id => $route) + + if(is_array($this->routes[$this->http->method()])) { - $this->addRoute($route, $id, $this->http->method()); + foreach ($this->routes[$this->http->method()] as $id => $route) + { + $this->addRoute($route, $id, $this->http->method()); + } } + } /** From 5632ef2fb9dca11cc85bb5d9e8ae8233afa920f6 Mon Sep 17 00:00:00 2001 From: gocsp Date: Wed, 25 May 2016 09:05:26 +0200 Subject: [PATCH 62/67] Add capabilities as argument for panels --- Herbert/Framework/Panel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Herbert/Framework/Panel.php b/Herbert/Framework/Panel.php index d7102df..c23d43b 100644 --- a/Herbert/Framework/Panel.php +++ b/Herbert/Framework/Panel.php @@ -206,7 +206,7 @@ protected function addPanel($panel) add_menu_page( $panel['title'], $panel['title'], - 'manage_options', + isset($panel['capability']) && $panel['capability'] ? $panel['capability'] : 'manage_options', $panel['slug'], $this->makeCallable($panel), isset($panel['icon']) ? $this->fetchIcon($panel['icon']) : '', @@ -246,7 +246,7 @@ protected function addSubPanel($panel) $panel['parent'], $panel['title'], $panel['title'], - 'manage_options', + isset($panel['capability']) && $panel['capability'] ? $panel['capability'] : 'manage_options', $panel['slug'], isset($panel['rename']) && $panel['rename'] ? null : $this->makeCallable($panel) ); From 4c0be93f28e3cb813f2c30a576a17e655678594a Mon Sep 17 00:00:00 2001 From: Georgios Panayi Date: Fri, 16 Dec 2016 08:50:07 +0200 Subject: [PATCH 63/67] Fixed filtering enqueue by post type (#38) * Fixed filtering enqueue by post type Method was always returning true so filtering wasn't working * Removed ternary operator --- Herbert/Framework/Enqueue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Herbert/Framework/Enqueue.php b/Herbert/Framework/Enqueue.php index 160a960..c0cf67a 100644 --- a/Herbert/Framework/Enqueue.php +++ b/Herbert/Framework/Enqueue.php @@ -327,7 +327,7 @@ public function filterSearch($attrs, $filterWith) */ public function filterPostType($attrs, $filterWith) { - return array_search(get_post_type(), $filterWith) !== null; + return array_search(get_post_type(), $filterWith) !== FALSE; } } From c72019274d7476d3c92b7cab5a0748b898c53a5d Mon Sep 17 00:00:00 2001 From: Alexis Vargas Date: Thu, 29 Jun 2017 17:22:51 -0500 Subject: [PATCH 64/67] MODIFIED. change the name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8ce4feb..a810155 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "getherbert/herbert", + "name": "lexisvar/herbert", "description": "Herbert", "license": "MIT", "require": { From b0bd7da235f84f71b5dec2395b619a828bbda4f0 Mon Sep 17 00:00:00 2001 From: Alexis Vargas Date: Thu, 29 Jun 2017 17:26:13 -0500 Subject: [PATCH 65/67] MODIFIED. Is necesary for can activate the plugin --- Herbert/Framework/Application.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Herbert/Framework/Application.php b/Herbert/Framework/Application.php index ee7c3e1..9f9ae25 100644 --- a/Herbert/Framework/Application.php +++ b/Herbert/Framework/Application.php @@ -11,6 +11,14 @@ */ class Application extends \Illuminate\Container\Container implements \Illuminate\Contracts\Foundation\Application { + public function getCachedPackagesPath() + { + + } + public function runningInConsole() + { + + } /** * The application's version. */ From 5b46fc87a19a171d5b2aa213e1539fea2d80ca9e Mon Sep 17 00:00:00 2001 From: Alexis Vargas Date: Thu, 29 Jun 2017 18:08:10 -0500 Subject: [PATCH 66/67] Update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a810155..7127862 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "lexisvar/herbert", + "name": "lexisvar/framework", "description": "Herbert", "license": "MIT", "require": { From 7aded5484cacd192ba635ac7b857bea801377db9 Mon Sep 17 00:00:00 2001 From: Alexis Vargas Date: Thu, 29 Jun 2017 20:40:51 -0500 Subject: [PATCH 67/67] MODIFIED. TEST --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7127862..274ddd8 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ }, "autoload": { "psr-4": { - "Herbert\\Framework\\": "Herbert/Framework/" + "Herbert\\Framework\\": "Lexisvar/Framework/" } }, "config": {