| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | <?php | 
					
						
							|  |  |  | namespace Grav\Plugin; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  | use Composer\Autoload\ClassLoader; | 
					
						
							|  |  |  | use Grav\Common\Cache; | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | use Grav\Common\Data\Data; | 
					
						
							| 
									
										
										
										
											2019-02-07 08:30:32 +02:00
										 |  |  | use Grav\Common\Debugger; | 
					
						
							| 
									
										
										
										
											2015-12-10 12:07:36 +01:00
										 |  |  | use Grav\Common\File\CompiledYamlFile; | 
					
						
							| 
									
										
										
										
											2014-10-07 17:01:40 -07:00
										 |  |  | use Grav\Common\Grav; | 
					
						
							| 
									
										
										
										
											2019-01-31 18:39:38 -07:00
										 |  |  | use Grav\Common\Helpers\LogViewer; | 
					
						
							| 
									
										
										
										
											2015-12-10 13:22:23 -07:00
										 |  |  | use Grav\Common\Inflector; | 
					
						
							| 
									
										
										
										
											2015-10-22 15:53:42 -06:00
										 |  |  | use Grav\Common\Language\Language; | 
					
						
							| 
									
										
										
										
											2019-03-05 15:46:55 +02:00
										 |  |  | use Grav\Common\Page\Interfaces\PageInterface; | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  | use Grav\Common\Page\Page; | 
					
						
							|  |  |  | use Grav\Common\Page\Pages; | 
					
						
							| 
									
										
										
										
											2014-10-07 17:01:40 -07:00
										 |  |  | use Grav\Common\Plugin; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | use Grav\Common\Plugins; | 
					
						
							| 
									
										
										
										
											2019-06-18 12:08:57 +03:00
										 |  |  | use Grav\Common\Processors\Events\RequestHandlerEvent; | 
					
						
							| 
									
										
										
										
											2018-12-05 08:20:38 +02:00
										 |  |  | use Grav\Common\Session; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | use Grav\Common\Twig\Twig; | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  | use Grav\Common\Uri; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | use Grav\Common\User\Interfaces\UserInterface; | 
					
						
							| 
									
										
										
										
											2016-11-07 09:54:10 -07:00
										 |  |  | use Grav\Common\Utils; | 
					
						
							| 
									
										
										
										
											2020-05-08 17:50:03 -06:00
										 |  |  | use Grav\Common\Yaml; | 
					
						
							| 
									
										
										
										
											2020-01-21 09:46:42 +02:00
										 |  |  | use Grav\Events\PermissionsRegisterEvent; | 
					
						
							| 
									
										
										
										
											2020-01-10 20:28:30 +02:00
										 |  |  | use Grav\Framework\Acl\PermissionsReader; | 
					
						
							| 
									
										
										
										
											2019-06-03 13:17:16 +03:00
										 |  |  | use Grav\Framework\Psr7\Response; | 
					
						
							| 
									
										
										
										
											2019-02-07 08:30:32 +02:00
										 |  |  | use Grav\Framework\Session\Exceptions\SessionException; | 
					
						
							| 
									
										
										
										
											2016-11-07 09:54:10 -07:00
										 |  |  | use Grav\Plugin\Admin\Admin; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | use Grav\Plugin\Admin\AdminFormFactory; | 
					
						
							| 
									
										
										
										
											2016-11-07 09:54:10 -07:00
										 |  |  | use Grav\Plugin\Admin\Popularity; | 
					
						
							| 
									
										
										
										
											2019-06-18 12:08:57 +03:00
										 |  |  | use Grav\Plugin\Admin\Router; | 
					
						
							| 
									
										
										
										
											2016-11-07 09:54:10 -07:00
										 |  |  | use Grav\Plugin\Admin\Themes; | 
					
						
							|  |  |  | use Grav\Plugin\Admin\AdminController; | 
					
						
							| 
									
										
										
										
											2018-05-10 10:14:18 +03:00
										 |  |  | use Grav\Plugin\Admin\Twig\AdminTwigExtension; | 
					
						
							| 
									
										
										
										
											2020-04-20 09:57:44 -06:00
										 |  |  | use Grav\Plugin\Admin\WhiteLabel; | 
					
						
							| 
									
										
										
										
											2018-05-10 20:04:14 +03:00
										 |  |  | use Grav\Plugin\Form\Form; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | use Grav\Plugin\Form\Forms; | 
					
						
							| 
									
										
										
										
											2017-08-31 12:46:51 -06:00
										 |  |  | use Grav\Plugin\Login\Login; | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  | use Pimple\Container; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | use Psr\Http\Message\ResponseInterface; | 
					
						
							| 
									
										
										
										
											2015-05-20 17:19:12 +02:00
										 |  |  | use RocketTheme\Toolbox\Event\Event; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Class AdminPlugin | 
					
						
							|  |  |  |  * @package Grav\Plugin\Admin | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | class AdminPlugin extends Plugin | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-22 10:42:38 +02:00
										 |  |  |     public $features = [ | 
					
						
							|  |  |  |         'blueprints' => 1000, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var bool */ | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     protected $active = false; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var string */ | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     protected $template; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var  string */ | 
					
						
							| 
									
										
										
										
											2014-09-03 22:22:03 -06:00
										 |  |  |     protected $theme; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var string */ | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     protected $route; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var string */ | 
					
						
							| 
									
										
										
										
											2016-09-27 18:21:11 +03:00
										 |  |  |     protected $admin_route; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var Uri */ | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     protected $uri; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var Admin */ | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     protected $admin; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var Session */ | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |     protected $session; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var Popularity */ | 
					
						
							| 
									
										
										
										
											2014-09-08 18:32:13 -06:00
										 |  |  |     protected $popularity; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var string */ | 
					
						
							| 
									
										
										
										
											2014-10-01 22:28:16 +03:00
										 |  |  |     protected $base; | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** @var string */ | 
					
						
							| 
									
										
										
										
											2016-04-26 12:57:29 -06:00
										 |  |  |     protected $version; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-09-23 12:45:26 -07:00
										 |  |  |     public static function getSubscribedEvents() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-09-25 17:10:54 -06:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             'onPluginsInitialized' => [ | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |                 ['autoload', 100001], | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |                 ['setup', 100000], | 
					
						
							|  |  |  |                 ['onPluginsInitialized', 1001] | 
					
						
							| 
									
										
										
										
											2020-11-26 15:55:02 +02:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2019-06-18 12:08:57 +03:00
										 |  |  |             'onRequestHandlerInit' => [ | 
					
						
							|  |  |  |                 ['onRequestHandlerInit', 100000] | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             'onFormRegisterTypes'  => ['onFormRegisterTypes', 0], | 
					
						
							| 
									
										
										
										
											2017-09-25 17:10:54 -06:00
										 |  |  |             'onPageInitialized'    => ['onPageInitialized', 0], | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |             'onShutdown'           => ['onShutdown', 1000], | 
					
						
							| 
									
										
										
										
											2020-01-21 09:46:42 +02:00
										 |  |  |             PermissionsRegisterEvent::class => ['onRegisterPermissions', 1000], | 
					
						
							| 
									
										
										
										
											2017-09-25 17:10:54 -06:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2015-12-10 12:07:36 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get list of form field types specified in this plugin. Only special types needs to be listed. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getFormFieldTypes() | 
					
						
							| 
									
										
										
										
											2017-06-02 16:28:52 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             'column'   => [ | 
					
						
							|  |  |  |                 'input@' => false | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'columns'  => [ | 
					
						
							|  |  |  |                 'input@' => false | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'fieldset' => [ | 
					
						
							|  |  |  |                 'input@' => false | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'section'  => [ | 
					
						
							|  |  |  |                 'input@' => false | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'list'     => [ | 
					
						
							|  |  |  |                 'array' => true | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'file'     => [ | 
					
						
							| 
									
										
										
										
											2021-03-17 19:12:18 +02:00
										 |  |  |                 'array' => true, | 
					
						
							|  |  |  |                 'media_field' => true, | 
					
						
							|  |  |  |                 'validate' => [ | 
					
						
							|  |  |  |                     'type' => 'ignore' | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'pagemedia' => [ | 
					
						
							|  |  |  |                 'array' => true, | 
					
						
							|  |  |  |                 'media_field' => true, | 
					
						
							|  |  |  |                 'validate' => [ | 
					
						
							|  |  |  |                     'type' => 'ignore' | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'filepicker' => [ | 
					
						
							|  |  |  |                 'media_picker_field' => true | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |             'pagemediaselect' => [ | 
					
						
							|  |  |  |                 'media_picker_field' => true | 
					
						
							| 
									
										
										
										
											2020-01-24 22:12:30 +02:00
										 |  |  |             ], | 
					
						
							|  |  |  |             'permissions' => [ | 
					
						
							|  |  |  |                 'ignore_empty' => true, | 
					
						
							|  |  |  |                 'validate' => [ | 
					
						
							|  |  |  |                     'type' => 'array' | 
					
						
							|  |  |  |                 ], | 
					
						
							|  |  |  |                 'filter' => [ | 
					
						
							|  |  |  |                     'type' => 'flatten_array', | 
					
						
							|  |  |  |                     'value_type' => 'bool', | 
					
						
							|  |  |  |                 ] | 
					
						
							| 
									
										
										
										
											2020-01-28 22:24:29 +02:00
										 |  |  |             ], | 
					
						
							|  |  |  |             'acl_picker' => [ | 
					
						
							|  |  |  |                 'ignore_empty' => true, | 
					
						
							|  |  |  |                 'validate' => [ | 
					
						
							|  |  |  |                     'type' => 'array' | 
					
						
							|  |  |  |                 ], | 
					
						
							|  |  |  |                 'filter' => [ | 
					
						
							|  |  |  |                     'type' => 'array', | 
					
						
							|  |  |  |                     'key_type' => 'string', | 
					
						
							|  |  |  |                     'value_type' => 'bool', | 
					
						
							|  |  |  |                 ] | 
					
						
							| 
									
										
										
										
											2020-12-23 20:23:55 +02:00
										 |  |  |             ], | 
					
						
							|  |  |  |             'taxonomy' => [ | 
					
						
							|  |  |  |                 'multiple' => true, | 
					
						
							|  |  |  |                 'validate' => [ | 
					
						
							|  |  |  |                     'type' => 'array' | 
					
						
							|  |  |  |                 ] | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |             ] | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2017-06-02 16:28:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * [onPluginsInitialized:100000] Composer autoload. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return ClassLoader | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     public function autoload(): ClassLoader | 
					
						
							| 
									
										
										
										
											2019-03-20 12:52:16 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         return require __DIR__ . '/vendor/autoload.php'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param Event $event | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function onFormRegisterTypes(Event $event): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** @var Forms $forms */ | 
					
						
							|  |  |  |         $forms = $event['forms']; | 
					
						
							|  |  |  |         $forms->registerType('admin', new AdminFormFactory()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * [onPluginsInitialized:100000] | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  |      * If the admin path matches, initialize the Login plugin configuration and set the admin | 
					
						
							|  |  |  |      * as active. | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function setup() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // Only enable admin if it has a route.
 | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  |         $route = $this->config->get('plugins.admin.route'); | 
					
						
							|  |  |  |         if (!$route) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         /** @var Uri uri */ | 
					
						
							|  |  |  |         $this->uri = $this->grav['uri']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-10 13:22:23 -07:00
										 |  |  |         $this->base = '/' . trim($route, '/'); | 
					
						
							| 
									
										
										
										
											2016-09-27 18:21:11 +03:00
										 |  |  |         $this->admin_route = rtrim($this->grav['pages']->base(), '/') . $this->base; | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $inAdmin = $this->isAdminPath(); | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // If no users found, go to register.
 | 
					
						
							|  |  |  |         if (!$inAdmin && !Admin::doAnyUsersExist()) { | 
					
						
							|  |  |  |             $this->grav->redirect($this->admin_route); | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // Only setup admin if we're inside the admin path.
 | 
					
						
							|  |  |  |         if ($inAdmin) { | 
					
						
							|  |  |  |             $this->setupAdmin(); | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-10 12:07:36 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * [onPluginsInitialized:1001] | 
					
						
							| 
									
										
										
										
											2015-12-10 12:07:36 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * If the admin plugin is set as active, initialize the admin | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2015-12-10 12:07:36 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     public function onPluginsInitialized() | 
					
						
							| 
									
										
										
										
											2015-12-10 12:07:36 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         // Only activate admin if we're inside the admin path.
 | 
					
						
							|  |  |  |         if ($this->active) { | 
					
						
							|  |  |  |             $this->initializeAdmin(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // Always initialize popularity.
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         $this->popularity = new Popularity(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-18 12:08:57 +03:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * [onRequestHandlerInit:100000] | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param RequestHandlerEvent $event | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2019-06-18 12:08:57 +03:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function onRequestHandlerInit(RequestHandlerEvent $event) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-26 19:19:25 +02:00
										 |  |  |         // Store this version.
 | 
					
						
							|  |  |  |         $this->version = $this->getBlueprint()->get('version'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-18 12:08:57 +03:00
										 |  |  |         $route = $event->getRoute(); | 
					
						
							|  |  |  |         $base = $route->getRoute(0, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($base === $this->base) { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             /** @var Debugger $debugger */ | 
					
						
							|  |  |  |             $debugger = $this->grav['debugger']; | 
					
						
							|  |  |  |             $debugger->addMessage('Admin v' . $this->version); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $event->addMiddleware('admin_router', new Router($this->grav, $this->admin)); | 
					
						
							| 
									
										
										
										
											2019-06-18 12:08:57 +03:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param Event $event | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function onAdminControllerInit(Event $event): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $eventController = $event['controller']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Blacklist login related views.
 | 
					
						
							|  |  |  |         $loginViews = ['login', 'forgot', 'register', 'reset']; | 
					
						
							|  |  |  |         $eventController->blacklist_views = array_merge($eventController->blacklist_views, $loginViews); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Force compile during save if admin plugin save | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Event $event | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function onAdminSave(Event $event) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $obj = $event['object']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         if ($obj instanceof Data | 
					
						
							|  |  |  |             && ($blueprint = $obj->blueprints()) && $blueprint && $blueprint->getFilename() === 'admin/blueprints') { | 
					
						
							| 
									
										
										
										
											2020-04-20 13:08:23 -06:00
										 |  |  |             [$status, $msg] = $this->grav['admin-whitelabel']->compilePresetScss($obj); | 
					
						
							| 
									
										
										
										
											2020-04-19 18:31:11 -06:00
										 |  |  |             if (!$status) { | 
					
						
							|  |  |  |                 $this->grav['messages']->add($msg, 'error'); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * [onPageInitialized:0] | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function onPageInitialized() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $template = $this->uri->param('tmpl'); | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         if ($template) { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             /** @var PageInterface $page */ | 
					
						
							|  |  |  |             $page = $this->grav['page']; | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |             $page->template($template); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-10 12:07:36 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-07 17:01:40 -07:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * [onShutdown:1000] | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Handles the shutdown | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     public function onShutdown() | 
					
						
							| 
									
										
										
										
											2014-09-09 06:10:31 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ($this->active) { | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |             //only activate when Admin is active
 | 
					
						
							|  |  |  |             if ($this->admin->shouldLoadAdditionalFilesInBackground()) { | 
					
						
							|  |  |  |                 $this->admin->loadAdditionalFilesInBackground(); | 
					
						
							| 
									
										
										
										
											2016-04-07 16:17:19 -06:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         } elseif ($this->popularity && $this->config->get('plugins.admin.popularity.enabled')) { | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |             //if popularity is enabled, track non-admin hits
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             $this->popularity->trackHit(); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-09 14:03:01 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * [onAdminDashboard:0] | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function onAdminDashboard() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-24 21:39:17 -06:00
										 |  |  |         $lang = $this->grav['language']; | 
					
						
							|  |  |  |         $this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [ | 
					
						
							|  |  |  |             'name' => $lang->translate('PLUGIN_ADMIN.MAINTENANCE'), | 
					
						
							|  |  |  |             'template' => 'dashboard-maintenance', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [ | 
					
						
							| 
									
										
										
										
											2020-11-20 16:13:27 -08:00
										 |  |  |             'name' => $lang->translate('PLUGIN_ADMIN.VIEWS_STATISTICS'), | 
					
						
							| 
									
										
										
										
											2019-10-24 21:39:17 -06:00
										 |  |  |             'template' => 'dashboard-statistics', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [ | 
					
						
							|  |  |  |             'name' => $lang->translate('PLUGIN_ADMIN.NOTIFICATIONS'), | 
					
						
							|  |  |  |             'template' => 'dashboard-notifications', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $this->grav['twig']->plugins_hooked_dashboard_widgets_top[] = [ | 
					
						
							|  |  |  |             'name' => $lang->translate('PLUGIN_ADMIN.NEWS_FEED'), | 
					
						
							|  |  |  |             'template' => 'dashboard-feed', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $this->grav['twig']->plugins_hooked_dashboard_widgets_main[] = [ | 
					
						
							|  |  |  |             'name' => $lang->translate('PLUGIN_ADMIN.LATEST_PAGE_UPDATES'), | 
					
						
							|  |  |  |             'template' => 'dashboard-pages', | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * [onAdminTools:0] | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Provide the tools for the Tools page, currently only direct install | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function onAdminTools(Event $event) | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         $event['tools'] = array_merge($event['tools'], [ | 
					
						
							| 
									
										
										
										
											2021-02-23 21:05:20 +02:00
										 |  |  |             'backups'        => [['admin.maintenance', 'admin.super'], 'PLUGIN_ADMIN.BACKUPS'], | 
					
						
							|  |  |  |             'scheduler'      => [['admin.super'], 'PLUGIN_ADMIN.SCHEDULER'], | 
					
						
							|  |  |  |             'logs'           => [['admin.super'], 'PLUGIN_ADMIN.LOGS'], | 
					
						
							|  |  |  |             'reports'        => [['admin.super'], 'PLUGIN_ADMIN.REPORTS'], | 
					
						
							|  |  |  |             'direct-install' => [['admin.super'], 'PLUGIN_ADMIN.DIRECT_INSTALL'], | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2015-10-19 11:46:51 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Sets longer path to the home page allowing us to have list of pages when we enter to pages section. | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |     public function onPagesInitialized() | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-07-13 15:43:15 -06:00
										 |  |  |         $config = $this->config; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Force SSL with redirect if required
 | 
					
						
							|  |  |  |         if ($config->get('system.force_ssl')) { | 
					
						
							| 
									
										
										
										
											2021-03-23 10:36:05 +02:00
										 |  |  |             if (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) !== 'on') { | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  |                 Admin::DEBUG && Admin::addDebugMessage('Admin SSL forced on, redirect'); | 
					
						
							| 
									
										
										
										
											2018-07-13 15:43:15 -06:00
										 |  |  |                 $url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | 
					
						
							|  |  |  |                 $this->grav->redirect($url); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-21 17:17:08 -06:00
										 |  |  |         $this->session = $this->grav['session']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // set session variable if it's passed via the url
 | 
					
						
							| 
									
										
										
										
											2021-03-31 12:16:40 +03:00
										 |  |  |         if (!$this->session->user->authorize('admin.super') || $this->uri->param('mode') === 'normal') { | 
					
						
							| 
									
										
										
										
											2014-09-21 17:17:08 -06:00
										 |  |  |             $this->session->expert = false; | 
					
						
							| 
									
										
										
										
											2021-03-31 12:16:40 +03:00
										 |  |  |         } elseif ($this->uri->param('mode') === 'expert') { | 
					
						
							|  |  |  |             $this->session->expert = true; | 
					
						
							| 
									
										
										
										
											2018-12-05 08:20:38 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             // set the default if not set before
 | 
					
						
							|  |  |  |             $this->session->expert = $this->session->expert ?? false; | 
					
						
							| 
									
										
										
										
											2014-09-21 17:17:08 -06:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // make sure page is not frozen!
 | 
					
						
							|  |  |  |         unset($this->grav['page']); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // Call the controller if it has been set.
 | 
					
						
							|  |  |  |         $adminParams = $this->admin->request->getAttribute('admin'); | 
					
						
							|  |  |  |         $page = null; | 
					
						
							|  |  |  |         if (isset($adminParams['controller'])) { | 
					
						
							|  |  |  |             $controllerParams = $adminParams['controller']; | 
					
						
							|  |  |  |             $class = $controllerParams['class']; | 
					
						
							|  |  |  |             if (!class_exists($class)) { | 
					
						
							|  |  |  |                 throw new \RuntimeException(sprintf('Admin controller %s does not exist', $class)); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             /** @var \Grav\Plugin\Admin\Controllers\AdminController $controller */ | 
					
						
							|  |  |  |             $controller = new $class($this->grav); | 
					
						
							|  |  |  |             $method = $controllerParams['method']; | 
					
						
							|  |  |  |             $params = $controllerParams['params'] ?? []; | 
					
						
							| 
									
										
										
										
											2019-06-03 13:17:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             if (!is_callable([$controller, $method])) { | 
					
						
							|  |  |  |                 throw new \RuntimeException(sprintf('Admin controller method %s() does not exist', $method)); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             /** @var ResponseInterface $response */ | 
					
						
							|  |  |  |             $response = $controller->{$method}(...$params); | 
					
						
							|  |  |  |             if ($response->getStatusCode() !== 418) { | 
					
						
							|  |  |  |                 $this->grav->close($response); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             $page = $controller->getPage(); | 
					
						
							|  |  |  |             if (!$page) { | 
					
						
							|  |  |  |                 throw new \RuntimeException('Not Found', 404); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-09 21:37:34 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             $this->grav['page'] = $page; | 
					
						
							|  |  |  |             $this->admin->form = $controller->getActiveForm(); | 
					
						
							| 
									
										
										
										
											2021-03-30 18:51:07 +03:00
										 |  |  |             $legacyController = false; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-03-30 18:51:07 +03:00
										 |  |  |             $legacyController = true; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-14 13:46:59 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // Replace page service with admin.
 | 
					
						
							|  |  |  |         if (empty($this->grav['page'])) { | 
					
						
							|  |  |  |             /** @var UserInterface $user */ | 
					
						
							|  |  |  |             $user = $this->grav['user']; | 
					
						
							| 
									
										
										
										
											2017-03-08 15:36:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             $this->grav['page'] = function () use ($user) { | 
					
						
							|  |  |  |                 $page = new Page(); | 
					
						
							| 
									
										
										
										
											2018-08-29 15:22:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                 // Plugins may not have the correct Cache-Control header set, force no-store for the proxies.
 | 
					
						
							|  |  |  |                 $page->expires(0); | 
					
						
							| 
									
										
										
										
											2018-08-29 15:22:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                 if ($user->authorize('admin.login')) { | 
					
						
							|  |  |  |                     $event = new Event(['page' => $page]); | 
					
						
							|  |  |  |                     $event = $this->grav->fireEvent('onAdminPage', $event); | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                     /** @var PageInterface $page */ | 
					
						
							|  |  |  |                     $page = $event['page']; | 
					
						
							|  |  |  |                     if ($page->slug()) { | 
					
						
							|  |  |  |                         Admin::DEBUG && Admin::addDebugMessage('Admin page: from event'); | 
					
						
							|  |  |  |                         return $page; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2018-03-18 21:18:52 -06:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                 // Look in the pages provided by the Admin plugin itself
 | 
					
						
							|  |  |  |                 if (file_exists(__DIR__ . "/pages/admin/{$this->template}.md")) { | 
					
						
							|  |  |  |                     Admin::DEBUG && Admin::addDebugMessage("Admin page: {$this->template}"); | 
					
						
							| 
									
										
										
										
											2016-03-11 16:51:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                     $page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$this->template}.md")); | 
					
						
							|  |  |  |                     $page->slug(basename($this->template)); | 
					
						
							| 
									
										
										
										
											2015-09-07 11:49:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 21:30:33 +01:00
										 |  |  |                     return $page; | 
					
						
							| 
									
										
										
										
											2018-03-18 21:18:52 -06:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                 /** @var UniformResourceLocator $locator */ | 
					
						
							|  |  |  |                 $locator = $this->grav['locator']; | 
					
						
							| 
									
										
										
										
											2015-10-26 21:30:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                 // If not provided by Admin, lookup pages added by other plugins
 | 
					
						
							|  |  |  |                 /** @var Plugins $plugins */ | 
					
						
							|  |  |  |                 $plugins = $this->grav['plugins']; | 
					
						
							|  |  |  |                 foreach ($plugins as $plugin) { | 
					
						
							|  |  |  |                     if ($this->config->get("plugins.{$plugin->name}.enabled") !== true) { | 
					
						
							|  |  |  |                         continue; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                     $path = $locator->findResource("plugins://{$plugin->name}/admin/pages/{$this->template}.md"); | 
					
						
							|  |  |  |                     if ($path) { | 
					
						
							|  |  |  |                         Admin::DEBUG && Admin::addDebugMessage("Admin page: plugin {$plugin->name}/{$this->template}"); | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                         $page->init(new \SplFileInfo($path)); | 
					
						
							|  |  |  |                         $page->slug(basename($this->template)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         return $page; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2015-09-07 11:49:41 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2016-01-21 09:46:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                 return null; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-11-25 15:43:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->grav['page'])) { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             if ($user->authenticated) { | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  |                 Admin::DEBUG && Admin::addDebugMessage('Admin page: fire onPageNotFound event'); | 
					
						
							| 
									
										
										
										
											2019-02-28 22:33:26 +02:00
										 |  |  |                 $event = new Event(['page' => null]); | 
					
						
							|  |  |  |                 $event->page = null; | 
					
						
							|  |  |  |                 $event = $this->grav->fireEvent('onPageNotFound', $event); | 
					
						
							| 
									
										
										
										
											2019-03-05 15:46:55 +02:00
										 |  |  |                 /** @var PageInterface $page */ | 
					
						
							| 
									
										
										
										
											2018-12-10 20:18:30 +02:00
										 |  |  |                 $page = $event->page; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (!$page || !$page->routable()) { | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  |                     Admin::DEBUG && Admin::addDebugMessage('Admin page: 404 Not Found'); | 
					
						
							| 
									
										
										
										
											2018-12-10 20:18:30 +02:00
										 |  |  |                     $error_file = $this->grav['locator']->findResource('plugins://admin/pages/admin/error.md'); | 
					
						
							| 
									
										
										
										
											2019-03-05 15:46:55 +02:00
										 |  |  |                     $page = new Page(); | 
					
						
							| 
									
										
										
										
											2018-12-10 20:18:30 +02:00
										 |  |  |                     $page->init(new \SplFileInfo($error_file)); | 
					
						
							|  |  |  |                     $page->slug(basename($this->route)); | 
					
						
							|  |  |  |                     $page->routable(true); | 
					
						
							| 
									
										
										
										
											2016-04-21 15:08:37 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-12-10 20:18:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 unset($this->grav['page']); | 
					
						
							|  |  |  |                 $this->grav['page'] = $page; | 
					
						
							| 
									
										
										
										
											2016-04-21 15:10:02 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  |                 Admin::DEBUG && Admin::addDebugMessage('Admin page: login'); | 
					
						
							| 
									
										
										
										
											2018-09-30 12:19:16 +03:00
										 |  |  |                 // Not Found and not logged in: Display login page.
 | 
					
						
							|  |  |  |                 $login_file = $this->grav['locator']->findResource('plugins://admin/pages/admin/login.md'); | 
					
						
							|  |  |  |                 $page = new Page(); | 
					
						
							|  |  |  |                 $page->init(new \SplFileInfo($login_file)); | 
					
						
							|  |  |  |                 $page->slug(basename($this->route)); | 
					
						
							|  |  |  |                 unset($this->grav['page']); | 
					
						
							|  |  |  |                 $this->grav['page'] = $page; | 
					
						
							| 
									
										
										
										
											2015-11-25 15:43:26 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-03 14:58:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-30 18:51:07 +03:00
										 |  |  |         if ($legacyController) { | 
					
						
							|  |  |  |             // Handle tasks.
 | 
					
						
							|  |  |  |             $this->admin->task = $task = $this->grav['task'] ?? $this->grav['action']; | 
					
						
							|  |  |  |             if ($task) { | 
					
						
							|  |  |  |                 Admin::DEBUG && Admin::addDebugMessage("Admin task: {$task}"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // Make local copy of POST.
 | 
					
						
							|  |  |  |                 $post = $this->grav['uri']->post(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $this->initializeController($task, $post); | 
					
						
							|  |  |  |             } elseif ($this->template === 'logs' && $this->route) { | 
					
						
							|  |  |  |                 // Display RAW error message.
 | 
					
						
							|  |  |  |                 $response = new Response(200, [], $this->admin->logEntry()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $this->grav->close($response); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-03 14:58:11 -07:00
										 |  |  |         // Explicitly set a timestamp on assets
 | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  |         $this->grav['assets']->setTimestamp(substr(md5(GRAV_VERSION . $this->grav['config']->checksum()), 0, 10)); | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 17:17:04 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Handles initializing the assets | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2016-01-10 17:17:04 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-12-03 14:47:34 -07:00
										 |  |  |     public function onAssetsInitialized() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Disable Asset pipelining
 | 
					
						
							|  |  |  |         $assets = $this->grav['assets']; | 
					
						
							| 
									
										
										
										
											2016-03-03 14:58:11 -07:00
										 |  |  |         $assets->setJsPipeline(false); | 
					
						
							|  |  |  |         $assets->setCssPipeline(false); | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-19 18:14:12 -06:00
										 |  |  |         // Compile a missing preset.css file
 | 
					
						
							| 
									
										
										
										
											2020-04-19 23:52:23 -06:00
										 |  |  |         $preset_css = 'asset://admin-preset.css'; | 
					
						
							| 
									
										
										
										
											2020-04-19 18:14:12 -06:00
										 |  |  |         $preset_path = $this->grav['locator']->findResource($preset_css); | 
					
						
							|  |  |  |         if (!$preset_path) { | 
					
						
							| 
									
										
										
										
											2020-04-20 13:08:23 -06:00
										 |  |  |             $this->grav['admin-whitelabel']->compilePresetScss($this->config->get('plugins.admin.whitelabel')); | 
					
						
							| 
									
										
										
										
											2020-04-19 18:14:12 -06:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 14:47:34 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Add twig paths to plugin templates. | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |     public function onTwigTemplatePaths() | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-20 17:19:12 +02:00
										 |  |  |         $twig_paths = []; | 
					
						
							|  |  |  |         $this->grav->fireEvent('onAdminTwigTemplatePaths', new Event(['paths' => &$twig_paths])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $twig_paths[] = __DIR__ . '/themes/' . $this->theme . '/templates'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->grav['twig']->twig_paths = $twig_paths; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Set all twig variables for generating output. | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |     public function onTwigSiteVariables() | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         /** @var Twig $twig */ | 
					
						
							| 
									
										
										
										
											2014-08-29 11:27:53 +03:00
										 |  |  |         $twig = $this->grav['twig']; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         /** @var PageInterface $page */ | 
					
						
							| 
									
										
										
										
											2017-04-13 14:50:27 -06:00
										 |  |  |         $page = $this->grav['page']; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $twig->twig_vars['location'] = $this->template; | 
					
						
							| 
									
										
										
										
											2020-01-16 19:16:56 +02:00
										 |  |  |         $twig->twig_vars['nav_route'] = trim($this->template . '/' . $this->route, '/') . '/'; | 
					
						
							| 
									
										
										
										
											2015-12-10 18:17:09 +01:00
										 |  |  |         $twig->twig_vars['base_url_relative_frontend'] = $twig->twig_vars['base_url_relative'] ?: '/'; | 
					
						
							| 
									
										
										
										
											2016-09-27 18:21:11 +03:00
										 |  |  |         $twig->twig_vars['admin_route'] = trim($this->admin_route, '/'); | 
					
						
							| 
									
										
										
										
											2019-02-11 14:33:48 -07:00
										 |  |  |         $twig->twig_vars['template_route'] = $this->template; | 
					
						
							| 
									
										
										
										
											2018-05-23 22:33:08 +03:00
										 |  |  |         $twig->twig_vars['current_route'] = '/' . $twig->twig_vars['admin_route'] . '/' . $this->template . '/' . $this->route; | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  |         $twig->twig_vars['base_url_relative'] = $twig->twig_vars['base_url_simple'] . '/' . $twig->twig_vars['admin_route']; | 
					
						
							| 
									
										
										
										
											2018-05-23 09:11:30 +03:00
										 |  |  |         $twig->twig_vars['current_url'] = rtrim($twig->twig_vars['base_url_relative'] . '/' . $this->template . '/' . $this->route, '/'); | 
					
						
							| 
									
										
										
										
											2016-07-15 17:39:13 +02:00
										 |  |  |         $theme_url = '/' . ltrim($this->grav['locator']->findResource('plugin://admin/themes/' . $this->theme, | 
					
						
							|  |  |  |             false), '/'); | 
					
						
							|  |  |  |         $twig->twig_vars['theme_url'] = $theme_url; | 
					
						
							| 
									
										
										
										
											2014-08-29 11:59:43 +03:00
										 |  |  |         $twig->twig_vars['base_url'] = $twig->twig_vars['base_url_relative']; | 
					
						
							| 
									
										
										
										
											2015-08-21 15:33:04 -06:00
										 |  |  |         $twig->twig_vars['base_path'] = GRAV_ROOT; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         $twig->twig_vars['admin'] = $this->admin; | 
					
						
							| 
									
										
										
										
											2020-01-30 12:32:10 +02:00
										 |  |  |         $twig->twig_vars['user'] = $this->admin->user; | 
					
						
							| 
									
										
										
										
											2016-04-26 12:57:29 -06:00
										 |  |  |         $twig->twig_vars['admin_version'] = $this->version; | 
					
						
							| 
									
										
										
										
											2019-01-31 18:39:38 -07:00
										 |  |  |         $twig->twig_vars['logviewer'] = new LogViewer(); | 
					
						
							| 
									
										
										
										
											2019-03-12 06:51:53 -06:00
										 |  |  |         $twig->twig_vars['form_max_filesize'] = Utils::getUploadLimit() / 1024 / 1024; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 09:57:44 -06:00
										 |  |  |         // Start white label functionality
 | 
					
						
							|  |  |  |         $twig->twig_vars['whitelabel_presets'] = $this->getPresets(); | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 09:57:44 -06:00
										 |  |  |         $custom_logo = $this->config->get('plugins.admin.whitelabel.logo_custom', false); | 
					
						
							|  |  |  |         $custom_login_logo = $this->config->get('plugins.admin.whitelabel.logo_login', false); | 
					
						
							|  |  |  |         $custom_footer = $this->config->get('plugins.admin.whitelabel.custom_footer', false); | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($custom_logo && is_array($custom_logo)) { | 
					
						
							|  |  |  |             $custom_logo = array_keys($custom_logo); | 
					
						
							|  |  |  |             $path = array_shift($custom_logo); | 
					
						
							|  |  |  |             $twig->twig_vars['custom_admin_logo'] = $path; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($custom_login_logo && is_array($custom_login_logo)) { | 
					
						
							|  |  |  |             $custom_login_logo = array_keys($custom_login_logo); | 
					
						
							|  |  |  |             $path = array_shift($custom_login_logo); | 
					
						
							|  |  |  |             $twig->twig_vars['custom_login_logo'] = $path; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($custom_footer) { | 
					
						
							|  |  |  |             $footer = Utils::processMarkdown($custom_footer); | 
					
						
							|  |  |  |             $twig->twig_vars['custom_admin_footer'] = $footer; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 09:57:44 -06:00
										 |  |  |         $custom_css = $this->config->get('plugins.admin.whitelabel.custom_css', false); | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($custom_css) { | 
					
						
							|  |  |  |             $this->grav['assets']->addInlineCss($custom_css); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-04-20 09:57:44 -06:00
										 |  |  |         // End white label functionality
 | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 19:09:06 +03:00
										 |  |  |         $fa_icons_file = CompiledYamlFile::instance($this->grav['locator']->findResource('plugin://admin/themes/grav/templates/forms/fields/iconpicker/icons' . YAML_EXT)); | 
					
						
							| 
									
										
										
										
											2017-07-14 17:42:20 +02:00
										 |  |  |         $fa_icons = $fa_icons_file->content(); | 
					
						
							|  |  |  |         $fa_icons = array_map(function ($icon) { | 
					
						
							|  |  |  |             //only pick used values
 | 
					
						
							|  |  |  |             return ['id' => $icon['id'], 'unicode' => $icon['unicode']]; | 
					
						
							|  |  |  |         }, $fa_icons['icons']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $twig->twig_vars['fa_icons'] = $fa_icons; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 14:50:27 -06:00
										 |  |  |         // add form if it exists in the page
 | 
					
						
							|  |  |  |         $header = $page->header(); | 
					
						
							| 
									
										
										
										
											2018-05-10 20:04:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $forms = []; | 
					
						
							|  |  |  |         if (isset($header->forms)) foreach ($header->forms as $key => $form) { | 
					
						
							|  |  |  |             $forms[$key] = new Form($page, null, $form); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $twig->twig_vars['forms'] = $forms; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // preserve form validation
 | 
					
						
							| 
									
										
										
										
											2021-04-07 14:14:04 +03:00
										 |  |  |         if ($this->admin->form) { | 
					
						
							|  |  |  |             $twig->twig_vars['form'] = $this->admin->form; | 
					
						
							|  |  |  |         } elseif (!isset($twig->twig_vars['form'])) { | 
					
						
							|  |  |  |             if (isset($header->form)) { | 
					
						
							| 
									
										
										
										
											2017-07-26 02:54:58 +02:00
										 |  |  |                 $twig->twig_vars['form'] = new Form($page); | 
					
						
							| 
									
										
										
										
											2018-05-10 20:04:14 +03:00
										 |  |  |             } elseif (isset($header->forms)) { | 
					
						
							|  |  |  |                 $twig->twig_vars['form'] = new Form($page, null, reset($header->forms)); | 
					
						
							| 
									
										
										
										
											2017-07-26 02:54:58 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-04-13 14:50:27 -06:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |         // Gather all nav items
 | 
					
						
							|  |  |  |         $this->grav['twig']->plugins_hooked_nav = []; | 
					
						
							| 
									
										
										
										
											2015-10-26 21:30:33 +01:00
										 |  |  |         $this->grav->fireEvent('onAdminMenu'); | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |         uasort($this->grav['twig']->plugins_hooked_nav, function ($a, $b) { | 
					
						
							|  |  |  |             $ac = $a['priority'] ?? 0; | 
					
						
							|  |  |  |             $bc = $b['priority'] ?? 0; | 
					
						
							| 
									
										
										
										
											2020-01-16 19:16:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             return $bc <=> $ac; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-10-26 21:30:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 21:39:17 -06:00
										 |  |  |         // Gather Plugin-hooked dashboard items
 | 
					
						
							|  |  |  |         $this->grav->fireEvent('onAdminDashboard'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |         switch ($this->template) { | 
					
						
							| 
									
										
										
										
											2014-09-08 18:32:13 -06:00
										 |  |  |             case 'dashboard': | 
					
						
							|  |  |  |                 $twig->twig_vars['popularity'] = $this->popularity; | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-01 16:08:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $flashData = $this->grav['session']->getFlashCookieObject(Admin::TMP_COOKIE_NAME); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($flashData->message)) { | 
					
						
							|  |  |  |             $this->grav['messages']->add($flashData->message, $flashData->status); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-03 22:22:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Add images to twig template paths to allow inclusion of SVG files | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     public function onTwigLoader() | 
					
						
							| 
									
										
										
										
											2014-09-06 16:59:58 -06:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         /** @var Twig $twig */ | 
					
						
							|  |  |  |         $twig = $this->grav['twig']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** @var UniformResourceLocator $locator */ | 
					
						
							|  |  |  |         $locator = Grav::instance()['locator']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $theme_paths = $locator->findResources('plugins://admin/themes/' . $this->theme . '/images'); | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         foreach($theme_paths as $images_path) { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |             $twig->addPath($images_path, 'admin-images'); | 
					
						
							| 
									
										
										
										
											2014-09-06 16:59:58 -06:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 14:21:59 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * Add the Admin Twig Extensions | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2016-02-29 14:21:59 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     public function onTwigExtensions() | 
					
						
							| 
									
										
										
										
											2016-02-29 14:21:59 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         /** @var Twig $twig */ | 
					
						
							|  |  |  |         $twig = $this->grav['twig']; | 
					
						
							|  |  |  |         $twig->twig->addExtension(new AdminTwigExtension); | 
					
						
							| 
									
										
										
										
											2016-02-29 14:21:59 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param Event $event | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     public function onAdminAfterSave(Event $event) | 
					
						
							| 
									
										
										
										
											2014-09-03 22:22:03 -06:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         // Special case to redirect after changing the admin route to avoid 'breaking'
 | 
					
						
							|  |  |  |         $obj = $event['object']; | 
					
						
							| 
									
										
										
										
											2014-09-03 22:22:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         if (null !== $obj && method_exists($obj, 'blueprints')) { | 
					
						
							|  |  |  |             $blueprint = $obj->blueprints()->getFilename(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($blueprint === 'admin/blueprints' && isset($obj->route) && $this->admin_route !== $obj->route) { | 
					
						
							|  |  |  |                 $redirect = preg_replace('/^' . str_replace('/','\/',$this->admin_route) . '/',$obj->route,$this->uri->path()); | 
					
						
							|  |  |  |                 $this->grav->redirect($redirect); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Convert some types where we want to process out of the standard config path | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Event $e | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function onAdminData(Event $e) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $type = $e['type'] ?? null; | 
					
						
							|  |  |  |         switch ($type) { | 
					
						
							| 
									
										
										
										
											2019-08-28 08:59:58 +03:00
										 |  |  |             case 'config': | 
					
						
							| 
									
										
										
										
											2020-02-03 13:21:19 +02:00
										 |  |  |                 $e['type'] = $this->admin->authorize(['admin.configuration.system', 'admin.super']) ? 'config/system' : 'config/site'; | 
					
						
							| 
									
										
										
										
											2019-08-28 08:59:58 +03:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |             case 'tools/scheduler': | 
					
						
							|  |  |  |                 $e['type'] = 'config/scheduler'; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2019-08-28 08:59:58 +03:00
										 |  |  |             case 'tools': | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |             case 'tools/backups': | 
					
						
							|  |  |  |                 $e['type'] = 'config/backups'; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     public function onOutputGenerated() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Clear flash objects for previously uploaded files whenever the user switches page or reloads
 | 
					
						
							|  |  |  |         // ignoring any JSON / extension call
 | 
					
						
							|  |  |  |         if ($this->admin->task !== 'save' && empty($this->uri->extension())) { | 
					
						
							|  |  |  |             // Discard any previously uploaded files session and remove all uploaded files.
 | 
					
						
							|  |  |  |             if ($flash = $this->session->getFlashObject('files-upload')) { | 
					
						
							|  |  |  |                 $flash = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($flash)); | 
					
						
							|  |  |  |                 foreach ($flash as $key => $value) { | 
					
						
							|  |  |  |                     if ($key !== 'tmp_name') { | 
					
						
							|  |  |  |                         continue; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     @unlink($value); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 20:28:30 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Initial stab at registering permissions (WIP) | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-01-21 09:46:42 +02:00
										 |  |  |      * @param PermissionsRegisterEvent $event | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2020-01-10 20:28:30 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-01-21 09:46:42 +02:00
										 |  |  |     public function onRegisterPermissions(PermissionsRegisterEvent $event): void | 
					
						
							| 
									
										
										
										
											2020-01-10 20:28:30 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $actions = PermissionsReader::fromYaml("plugin://{$this->name}/permissions.yaml"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $permissions = $event->permissions; | 
					
						
							|  |  |  |         $permissions->addActions($actions); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |     public function onAdminMenu() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         /** @var Twig $twig */ | 
					
						
							|  |  |  |         $twig = $this->grav['twig']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |         // Dashboard
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $twig->plugins_hooked_nav['PLUGIN_ADMIN.DASHBOARD'] = [ | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             'route' => 'dashboard', | 
					
						
							|  |  |  |             'icon' => 'fa-th', | 
					
						
							|  |  |  |             'authorize' => ['admin.login', 'admin.super'], | 
					
						
							|  |  |  |             'priority' => 10 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Configuration
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $twig->plugins_hooked_nav['PLUGIN_ADMIN.CONFIGURATION'] = [ | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             'route' => 'config', | 
					
						
							|  |  |  |             'icon' => 'fa-wrench', | 
					
						
							| 
									
										
										
										
											2020-02-03 13:21:19 +02:00
										 |  |  |             'authorize' => [ | 
					
						
							|  |  |  |                 'admin.configuration.system', | 
					
						
							|  |  |  |                 'admin.configuration.site', | 
					
						
							| 
									
										
										
										
											2021-02-10 15:26:02 +02:00
										 |  |  |                 'admin.configuration.media', | 
					
						
							|  |  |  |                 'admin.configuration.security', | 
					
						
							|  |  |  |                 'admin.configuration.info', | 
					
						
							| 
									
										
										
										
											2020-02-03 13:21:19 +02:00
										 |  |  |                 'admin.super'], | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             'priority' => 9 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Pages
 | 
					
						
							|  |  |  |         $count = new Container(['count' => function () { return $this->admin->pagesCount(); }]); | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $twig->plugins_hooked_nav['PLUGIN_ADMIN.PAGES'] = [ | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             'route' => 'pages', | 
					
						
							|  |  |  |             'icon' => 'fa-file-text-o', | 
					
						
							|  |  |  |             'authorize' => ['admin.pages', 'admin.super'], | 
					
						
							|  |  |  |             'badge' => $count, | 
					
						
							|  |  |  |             'priority' => 5 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Plugins
 | 
					
						
							|  |  |  |         $count = new Container(['updates' => 0, 'count' => function () { return count($this->admin->plugins()); }]); | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $twig->plugins_hooked_nav['PLUGIN_ADMIN.PLUGINS'] = [ | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             'route' => 'plugins', | 
					
						
							|  |  |  |             'icon' => 'fa-plug', | 
					
						
							|  |  |  |             'authorize' => ['admin.plugins', 'admin.super'], | 
					
						
							|  |  |  |             'badge' => $count, | 
					
						
							|  |  |  |             'priority' => -8 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Themes
 | 
					
						
							|  |  |  |         $count = new Container(['updates' => 0, 'count' => function () { return count($this->admin->themes()); }]); | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $twig->plugins_hooked_nav['PLUGIN_ADMIN.THEMES'] = [ | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             'route' => 'themes', | 
					
						
							|  |  |  |             'icon' => 'fa-tint', | 
					
						
							|  |  |  |             'authorize' => ['admin.themes', 'admin.super'], | 
					
						
							|  |  |  |             'badge' => $count, | 
					
						
							|  |  |  |             'priority' => -9 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Tools
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $twig->plugins_hooked_nav['PLUGIN_ADMIN.TOOLS'] = [ | 
					
						
							| 
									
										
										
										
											2019-08-27 10:43:16 +03:00
										 |  |  |             'route' => 'tools', | 
					
						
							|  |  |  |             'icon' => 'fa-briefcase', | 
					
						
							|  |  |  |             'authorize' => $this->admin::toolsPermissions(), | 
					
						
							|  |  |  |             'priority' => -10 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Check if the current route is under the admin path | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isAdminPath() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $route = $this->uri->route(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $route === $this->base || 0 === strpos($route, $this->base . '/'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |      * Helper function to replace Pages::Types() and to provide an event to manipulate the data | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |      * Dispatches 'onAdminPageTypes' event with 'types' data member which is a reference to the data | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param bool $keysOnly | 
					
						
							|  |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |     public static function pagesTypes(bool $keysOnly = false) | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $types = Pages::types(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // First filter by configuration
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $hideTypes = (array)Grav::instance()['config']->get('plugins.admin.hide_page_types'); | 
					
						
							|  |  |  |         foreach ($hideTypes as $hide) { | 
					
						
							| 
									
										
										
										
											2020-11-21 15:15:55 -08:00
										 |  |  |             if (isset($types[$hide])) { | 
					
						
							|  |  |  |                 unset($types[$hide]); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 foreach ($types as $key => $type) { | 
					
						
							|  |  |  |                     $match = preg_match('#' . $hide . '#i', $key); | 
					
						
							|  |  |  |                     if ($match) { | 
					
						
							|  |  |  |                         unset($types[$key]); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Allow manipulating of the data by event
 | 
					
						
							|  |  |  |         $e = new Event(['types' => &$types]); | 
					
						
							|  |  |  |         Grav::instance()->fireEvent('onAdminPageTypes', $e); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |         return $keysOnly ? array_keys($types) : $types; | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |      * Helper function to replace Pages::modularTypes() and to provide an event to manipulate the data | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |      * Dispatches 'onAdminModularPageTypes' event with 'types' data member which is a reference to the data | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param bool $keysOnly | 
					
						
							|  |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |     public static function pagesModularTypes(bool $keysOnly = false) | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $types = Pages::modularTypes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // First filter by configuration
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $hideTypes = (array)Grav::instance()['config']->get('plugins.admin.hide_modular_page_types'); | 
					
						
							|  |  |  |         foreach ($hideTypes as $hide) { | 
					
						
							| 
									
										
										
										
											2020-11-21 15:15:55 -08:00
										 |  |  |             if (isset($types[$hide])) { | 
					
						
							|  |  |  |                 unset($types[$hide]); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 foreach ($types as $key => $type) { | 
					
						
							|  |  |  |                     $match = preg_match('#' . $hide . '#i', $key); | 
					
						
							|  |  |  |                     if ($match) { | 
					
						
							|  |  |  |                         unset($types[$key]); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Allow manipulating of the data by event
 | 
					
						
							|  |  |  |         $e = new Event(['types' => &$types]); | 
					
						
							|  |  |  |         Grav::instance()->fireEvent('onAdminModularPageTypes', $e); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-25 13:58:36 +02:00
										 |  |  |         return $keysOnly ? array_keys($types) : $types; | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Validate a value. Currently validates | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * - 'user' for username format and username availability. | 
					
						
							|  |  |  |      * - 'password1' for password format | 
					
						
							|  |  |  |      * - 'password2' for equality to password1 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $type  The field type | 
					
						
							|  |  |  |      * @param string $value The field value | 
					
						
							|  |  |  |      * @param string $extra Any extra value required | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function validate($type, $value, $extra = '') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** @var Login $login */ | 
					
						
							|  |  |  |         $login = $this->grav['login']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $login->validateField($type, $value, $extra); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param string $task | 
					
						
							|  |  |  |      * @param array|null $post | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function initializeController($task, $post = null): void | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-02-10 22:19:39 +02:00
										 |  |  |         Admin::DEBUG && Admin::addDebugMessage('Admin controller: execute'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |         $controller = new AdminController(); | 
					
						
							|  |  |  |         $controller->initialize($this->grav, $this->template, $task, $this->route, $post); | 
					
						
							|  |  |  |         $controller->execute(); | 
					
						
							|  |  |  |         $controller->redirect(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function setupAdmin() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Set cache based on admin_cache option.
 | 
					
						
							|  |  |  |         /** @var Cache $cache */ | 
					
						
							|  |  |  |         $cache = $this->grav['cache']; | 
					
						
							|  |  |  |         $cache->setEnabled($this->config->get('plugins.admin.cache_enabled')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** @var Pages $pages */ | 
					
						
							|  |  |  |         $pages = $this->grav['pages']; | 
					
						
							|  |  |  |         // Disable frontend pages in admin.
 | 
					
						
							|  |  |  |         $pages->disablePages(); | 
					
						
							|  |  |  |         // Force file hash checks to fix caching on moved and deleted pages.
 | 
					
						
							|  |  |  |         $pages->setCheckMethod('hash'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** @var Session $session */ | 
					
						
							|  |  |  |         $session = $this->grav['session']; | 
					
						
							|  |  |  |         // Make sure that the session has been initialized.
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $session->init(); | 
					
						
							|  |  |  |         } catch (SessionException $e) { | 
					
						
							|  |  |  |             $session->init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $message = 'Session corruption detected, restarting session...'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             /** @var Debugger $debugger */ | 
					
						
							|  |  |  |             $debugger = $this->grav['debugger']; | 
					
						
							|  |  |  |             $debugger->addMessage($message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->grav['messages']->add($message, 'error'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->active = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Initialize the admin. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2019-02-01 10:27:48 +02:00
										 |  |  |      * @throws \RuntimeException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function initializeAdmin() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-07-27 12:56:16 -06:00
										 |  |  |         // Check for required plugins
 | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  |         if (!$this->grav['config']->get('plugins.login.enabled') || !$this->grav['config']->get('plugins.form.enabled') || !$this->grav['config']->get('plugins.email.enabled')) { | 
					
						
							| 
									
										
										
										
											2015-07-27 12:56:16 -06:00
										 |  |  |             throw new \RuntimeException('One of the required plugins is missing or not enabled'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         /** @var Cache $cache */ | 
					
						
							|  |  |  |         $cache = $this->grav['cache']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Have a unique Admin-only Cache key
 | 
					
						
							|  |  |  |         $cache_key = $cache->getKey(); | 
					
						
							|  |  |  |         $cache->setKey($cache_key . '$'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** @var Session $session */ | 
					
						
							|  |  |  |         $session = $this->grav['session']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-20 11:02:52 -07:00
										 |  |  |         /** @var Language $language */ | 
					
						
							|  |  |  |         $language = $this->grav['language']; | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /** @var UniformResourceLocator $locator */ | 
					
						
							|  |  |  |         $locator = $this->grav['locator']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Turn on Twig autoescaping
 | 
					
						
							|  |  |  |         if ($this->uri->param('task') !== 'processmarkdown') { | 
					
						
							|  |  |  |             $this->grav['twig']->setAutoescape(true); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Initialize Admin Language if needed
 | 
					
						
							|  |  |  |         if ($language->enabled() && empty($session->admin_lang)) { | 
					
						
							|  |  |  |             $session->admin_lang = $language->getLanguage(); | 
					
						
							| 
									
										
										
										
											2015-11-20 11:02:52 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-09 07:57:53 +03:00
										 |  |  |         // Decide admin template and route.
 | 
					
						
							|  |  |  |         $path = trim(substr($this->uri->route(), strlen($this->base)), '/'); | 
					
						
							| 
									
										
										
										
											2015-12-10 11:02:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->template)) { | 
					
						
							|  |  |  |             $this->template = 'dashboard'; | 
					
						
							| 
									
										
										
										
											2015-12-04 11:58:28 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-10 13:22:23 -07:00
										 |  |  |         // Can't access path directly...
 | 
					
						
							| 
									
										
										
										
											2018-05-10 10:14:18 +03:00
										 |  |  |         if ($path && $path !== 'register') { | 
					
						
							| 
									
										
										
										
											2014-09-09 07:57:53 +03:00
										 |  |  |             $array = explode('/', $path, 2); | 
					
						
							|  |  |  |             $this->template = array_shift($array); | 
					
						
							|  |  |  |             $this->route = array_shift($array); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-09-03 22:22:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 12:25:20 +02:00
										 |  |  |         // Initialize admin class (also registers it to Grav services).
 | 
					
						
							| 
									
										
										
										
											2016-09-27 18:21:11 +03:00
										 |  |  |         $this->admin = new Admin($this->grav, $this->admin_route, $this->template, $this->route); | 
					
						
							| 
									
										
										
										
											2014-09-06 16:59:58 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         // Get theme for admin
 | 
					
						
							|  |  |  |         $this->theme = $this->config->get('plugins.admin.theme', 'grav'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Replace themes service with admin.
 | 
					
						
							|  |  |  |         $this->grav['themes'] = function () { | 
					
						
							|  |  |  |             return new Themes($this->grav); | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Initialize white label functionality
 | 
					
						
							|  |  |  |         $this->grav['admin-whitelabel'] = new WhiteLabel(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // These events are needed for login.
 | 
					
						
							|  |  |  |         $this->enable([ | 
					
						
							|  |  |  |             'onTwigExtensions'           => ['onTwigExtensions', 1000], | 
					
						
							|  |  |  |             'onPagesInitialized'         => ['onPagesInitialized', 1000], | 
					
						
							|  |  |  |             'onTwigLoader'               => ['onTwigLoader', 1000], | 
					
						
							|  |  |  |             'onTwigTemplatePaths'        => ['onTwigTemplatePaths', 1000], | 
					
						
							|  |  |  |             'onTwigSiteVariables'        => ['onTwigSiteVariables', 1000], | 
					
						
							|  |  |  |             'onAssetsInitialized'        => ['onAssetsInitialized', 1000], | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Do not do more if user isn't logged in.
 | 
					
						
							|  |  |  |         if (!$this->admin->user->authorize('admin.login')) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // These events are not needed during login.
 | 
					
						
							|  |  |  |         $this->enable([ | 
					
						
							|  |  |  |             'onAdminControllerInit'     => ['onAdminControllerInit', 1001], | 
					
						
							|  |  |  |             'onAdminDashboard'          => ['onAdminDashboard', 0], | 
					
						
							|  |  |  |             'onAdminMenu'               => ['onAdminMenu', 1000], | 
					
						
							|  |  |  |             'onAdminTools'              => ['onAdminTools', 0], | 
					
						
							|  |  |  |             'onAdminSave'               => ['onAdminSave', 0], | 
					
						
							|  |  |  |             'onAdminAfterSave'          => ['onAdminAfterSave', 0], | 
					
						
							|  |  |  |             'onAdminData'               => ['onAdminData', 0], | 
					
						
							|  |  |  |             'onOutputGenerated'         => ['onOutputGenerated', 0], | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-02 16:22:20 +02:00
										 |  |  |         // Double check we have system.yaml, site.yaml etc
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         $config_path = $locator->findResource('user://config'); | 
					
						
							| 
									
										
										
										
											2018-12-05 08:20:38 +02:00
										 |  |  |         foreach ($this->admin::configurations() as $config_file) { | 
					
						
							| 
									
										
										
										
											2021-02-18 15:38:49 +02:00
										 |  |  |             if ($config_file === 'info') { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-02-11 16:14:43 +01:00
										 |  |  |             $config_file = "{$config_path}/{$config_file}.yaml"; | 
					
						
							|  |  |  |             if (!file_exists($config_file)) { | 
					
						
							|  |  |  |                 touch($config_file); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 18:49:11 +02:00
										 |  |  |         $assets = $this->grav['assets']; | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  |         $translations = 'this.GravAdmin = this.GravAdmin || {}; if (!this.GravAdmin.translations) this.GravAdmin.translations = {}; ' . PHP_EOL . 'this.GravAdmin.translations.PLUGIN_ADMIN = {'; | 
					
						
							| 
									
										
										
										
											2015-08-24 18:49:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-29 21:51:07 -07:00
										 |  |  |         // Enable language translations
 | 
					
						
							|  |  |  |         $translations_actual_state = $this->config->get('system.languages.translations'); | 
					
						
							|  |  |  |         $this->config->set('system.languages.translations', true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  |         $strings = [ | 
					
						
							|  |  |  |             'EVERYTHING_UP_TO_DATE', | 
					
						
							| 
									
										
										
										
											2015-08-24 18:49:11 +02:00
										 |  |  |             'UPDATES_ARE_AVAILABLE', | 
					
						
							|  |  |  |             'IS_AVAILABLE_FOR_UPDATE', | 
					
						
							|  |  |  |             'AND', | 
					
						
							|  |  |  |             'IS_NOW_AVAILABLE', | 
					
						
							|  |  |  |             'CURRENT', | 
					
						
							|  |  |  |             'UPDATE_GRAV_NOW', | 
					
						
							|  |  |  |             'TASK_COMPLETED', | 
					
						
							|  |  |  |             'UPDATE', | 
					
						
							|  |  |  |             'UPDATING_PLEASE_WAIT', | 
					
						
							|  |  |  |             'GRAV_SYMBOLICALLY_LINKED', | 
					
						
							|  |  |  |             'OF_YOUR', | 
					
						
							|  |  |  |             'OF_THIS', | 
					
						
							|  |  |  |             'HAVE_AN_UPDATE_AVAILABLE', | 
					
						
							|  |  |  |             'UPDATE_AVAILABLE', | 
					
						
							| 
									
										
										
										
											2015-08-28 17:31:45 +02:00
										 |  |  |             'UPDATES_AVAILABLE', | 
					
						
							|  |  |  |             'FULLY_UPDATED', | 
					
						
							| 
									
										
										
										
											2015-10-21 19:54:10 +02:00
										 |  |  |             'DAYS', | 
					
						
							|  |  |  |             'PAGE_MODES', | 
					
						
							|  |  |  |             'PAGE_TYPES', | 
					
						
							| 
									
										
										
										
											2016-02-01 11:27:34 -08:00
										 |  |  |             'ACCESS_LEVELS', | 
					
						
							| 
									
										
										
										
											2016-02-01 16:34:50 -08:00
										 |  |  |             'NOTHING_TO_SAVE', | 
					
						
							|  |  |  |             'FILE_UNSUPPORTED', | 
					
						
							|  |  |  |             'FILE_ERROR_ADD', | 
					
						
							| 
									
										
										
										
											2016-05-03 11:10:54 +02:00
										 |  |  |             'FILE_ERROR_UPLOAD', | 
					
						
							|  |  |  |             'DROP_FILES_HERE_TO_UPLOAD', | 
					
						
							|  |  |  |             'DELETE', | 
					
						
							| 
									
										
										
										
											2018-03-09 21:06:00 -06:00
										 |  |  |             'UNSET', | 
					
						
							| 
									
										
										
										
											2016-05-04 14:57:40 +02:00
										 |  |  |             'INSERT', | 
					
						
							| 
									
										
										
										
											2017-06-21 17:55:33 -07:00
										 |  |  |             'METADATA', | 
					
						
							| 
									
										
										
										
											2017-03-08 17:05:08 -08:00
										 |  |  |             'VIEW', | 
					
						
							| 
									
										
										
										
											2016-05-04 14:57:40 +02:00
										 |  |  |             'UNDO', | 
					
						
							|  |  |  |             'REDO', | 
					
						
							|  |  |  |             'HEADERS', | 
					
						
							|  |  |  |             'BOLD', | 
					
						
							|  |  |  |             'ITALIC', | 
					
						
							|  |  |  |             'STRIKETHROUGH', | 
					
						
							|  |  |  |             'SUMMARY_DELIMITER', | 
					
						
							|  |  |  |             'LINK', | 
					
						
							|  |  |  |             'IMAGE', | 
					
						
							|  |  |  |             'BLOCKQUOTE', | 
					
						
							|  |  |  |             'UNORDERED_LIST', | 
					
						
							|  |  |  |             'ORDERED_LIST', | 
					
						
							|  |  |  |             'EDITOR', | 
					
						
							|  |  |  |             'PREVIEW', | 
					
						
							| 
									
										
										
										
											2016-05-06 18:17:26 +02:00
										 |  |  |             'FULLSCREEN', | 
					
						
							| 
									
										
										
										
											2019-11-20 09:51:58 +02:00
										 |  |  |             'MODULE', | 
					
						
							|  |  |  |             'NON_MODULE', | 
					
						
							| 
									
										
										
										
											2016-05-06 18:17:26 +02:00
										 |  |  |             'VISIBLE', | 
					
						
							|  |  |  |             'NON_VISIBLE', | 
					
						
							|  |  |  |             'ROUTABLE', | 
					
						
							|  |  |  |             'NON_ROUTABLE', | 
					
						
							|  |  |  |             'PUBLISHED', | 
					
						
							| 
									
										
										
										
											2016-06-10 15:10:24 +02:00
										 |  |  |             'NON_PUBLISHED', | 
					
						
							|  |  |  |             'PLUGINS', | 
					
						
							|  |  |  |             'THEMES', | 
					
						
							|  |  |  |             'ALL', | 
					
						
							|  |  |  |             'FROM', | 
					
						
							| 
									
										
										
										
											2016-08-29 11:12:09 -07:00
										 |  |  |             'TO', | 
					
						
							|  |  |  |             'DROPZONE_CANCEL_UPLOAD', | 
					
						
							|  |  |  |             'DROPZONE_CANCEL_UPLOAD_CONFIRMATION', | 
					
						
							|  |  |  |             'DROPZONE_DEFAULT_MESSAGE', | 
					
						
							|  |  |  |             'DROPZONE_FALLBACK_MESSAGE', | 
					
						
							|  |  |  |             'DROPZONE_FALLBACK_TEXT', | 
					
						
							|  |  |  |             'DROPZONE_FILE_TOO_BIG', | 
					
						
							|  |  |  |             'DROPZONE_INVALID_FILE_TYPE', | 
					
						
							|  |  |  |             'DROPZONE_MAX_FILES_EXCEEDED', | 
					
						
							|  |  |  |             'DROPZONE_REMOVE_FILE', | 
					
						
							|  |  |  |             'DROPZONE_RESPONSE_ERROR' | 
					
						
							| 
									
										
										
										
											2015-10-21 19:54:10 +02:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2015-08-24 18:49:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 18:55:52 +02:00
										 |  |  |         foreach ($strings as $string) { | 
					
						
							| 
									
										
										
										
											2016-02-01 11:27:34 -08:00
										 |  |  |             $separator = (end($strings) === $string) ? '' : ','; | 
					
						
							| 
									
										
										
										
											2018-12-05 08:20:38 +02:00
										 |  |  |             $translations .= '"' . $string . '": "' . htmlspecialchars($this->admin::translate('PLUGIN_ADMIN.' . $string)) . '"' . $separator; | 
					
						
							| 
									
										
										
										
											2015-08-24 18:49:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-01 11:27:34 -08:00
										 |  |  |         $translations .= '};'; | 
					
						
							| 
									
										
										
										
											2018-03-25 22:20:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $translations .= 'this.GravAdmin.translations.PLUGIN_FORM = {'; | 
					
						
							|  |  |  |         $strings = ['RESOLUTION_MIN', 'RESOLUTION_MAX']; | 
					
						
							|  |  |  |         foreach ($strings as $string) { | 
					
						
							|  |  |  |             $separator = (end($strings) === $string) ? '' : ','; | 
					
						
							| 
									
										
										
										
											2018-12-05 08:20:38 +02:00
										 |  |  |             $translations .= '"' . $string . '": "' . $this->admin::translate('PLUGIN_FORM.' . $string) . '"' . $separator; | 
					
						
							| 
									
										
										
										
											2018-03-25 22:20:05 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |         $translations .= '};'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 12:24:48 -06:00
										 |  |  |         $translations .= 'this.GravAdmin.translations.GRAV_CORE = {'; | 
					
						
							|  |  |  |         $strings = [ | 
					
						
							|  |  |  |             'NICETIME.SECOND', | 
					
						
							|  |  |  |             'NICETIME.MINUTE', | 
					
						
							|  |  |  |             'NICETIME.HOUR', | 
					
						
							|  |  |  |             'NICETIME.DAY', | 
					
						
							|  |  |  |             'NICETIME.WEEK', | 
					
						
							|  |  |  |             'NICETIME.MONTH', | 
					
						
							|  |  |  |             'NICETIME.YEAR', | 
					
						
							|  |  |  |             'CRON.EVERY', | 
					
						
							|  |  |  |             'CRON.EVERY_HOUR', | 
					
						
							|  |  |  |             'CRON.EVERY_MINUTE', | 
					
						
							|  |  |  |             'CRON.EVERY_DAY_OF_WEEK', | 
					
						
							|  |  |  |             'CRON.EVERY_DAY_OF_MONTH', | 
					
						
							|  |  |  |             'CRON.EVERY_MONTH', | 
					
						
							|  |  |  |             'CRON.TEXT_PERIOD', | 
					
						
							|  |  |  |             'CRON.TEXT_MINS', | 
					
						
							|  |  |  |             'CRON.TEXT_TIME', | 
					
						
							|  |  |  |             'CRON.TEXT_DOW', | 
					
						
							|  |  |  |             'CRON.TEXT_MONTH', | 
					
						
							|  |  |  |             'CRON.TEXT_DOM', | 
					
						
							|  |  |  |             'CRON.ERROR1', | 
					
						
							|  |  |  |             'CRON.ERROR2', | 
					
						
							|  |  |  |             'CRON.ERROR3', | 
					
						
							| 
									
										
										
										
											2018-10-24 14:46:24 -06:00
										 |  |  |             'CRON.ERROR4', | 
					
						
							|  |  |  |             'MONTHS_OF_THE_YEAR', | 
					
						
							|  |  |  |             'DAYS_OF_THE_WEEK' | 
					
						
							| 
									
										
										
										
											2018-09-06 12:24:48 -06:00
										 |  |  |         ]; | 
					
						
							|  |  |  |         foreach ($strings as $string) { | 
					
						
							|  |  |  |             $separator = (end($strings) === $string) ? '' : ','; | 
					
						
							| 
									
										
										
										
											2018-12-05 08:20:38 +02:00
										 |  |  |             $translations .= '"' . $string . '": ' . json_encode($this->admin::translate('GRAV.'.$string)) . $separator; | 
					
						
							| 
									
										
										
										
											2018-09-06 12:24:48 -06:00
										 |  |  |         } | 
					
						
							|  |  |  |         $translations .= '};'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-29 21:51:07 -07:00
										 |  |  |         // set the actual translations state back
 | 
					
						
							|  |  |  |         $this->config->set('system.languages.translations', $translations_actual_state); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 18:49:11 +02:00
										 |  |  |         $assets->addInlineJs($translations); | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Fire even to register permissions from other plugins
 | 
					
						
							|  |  |  |         $this->grav->fireEvent('onAdminRegisterPermissions', new Event(['admin' => $this->admin])); | 
					
						
							| 
									
										
										
										
											2014-09-03 22:22:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-05-08 17:50:03 -06:00
										 |  |  |     public static function themeOptions() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         static $options; | 
					
						
							| 
									
										
										
										
											2020-05-08 17:50:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |         if (null === $options) { | 
					
						
							|  |  |  |             $options = []; | 
					
						
							| 
									
										
										
										
											2020-05-08 17:50:03 -06:00
										 |  |  |             $theme_files = glob(__dir__ . '/themes/grav/css/codemirror/themes/*.css'); | 
					
						
							|  |  |  |             foreach ($theme_files as $theme_file) { | 
					
						
							|  |  |  |                 $theme = basename(basename($theme_file, '.css')); | 
					
						
							|  |  |  |                 $options[$theme] = Inflector::titleize($theme); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $options; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |     public function getPresets() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-04-19 16:38:13 -06:00
										 |  |  |         $filename = $this->grav['locator']->findResource('plugin://admin/presets.yaml', false); | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $file     = CompiledYamlFile::instance($filename); | 
					
						
							|  |  |  |         $presets     = (array)$file->content(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 17:50:03 -06:00
										 |  |  |         $custom_presets = $this->config->get('plugins.admin.whitelabel.custom_presets'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($custom_presets)) { | 
					
						
							|  |  |  |             $custom_presets = Yaml::parse($custom_presets); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (is_array($custom_presets)) { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                 if (isset($custom_presets['name'], $custom_presets['colors'], $custom_presets['accents'])) { | 
					
						
							| 
									
										
										
										
											2020-05-08 17:50:03 -06:00
										 |  |  |                     $preset = [Inflector::hyphenize($custom_presets['name']) => $custom_presets]; | 
					
						
							|  |  |  |                     $presets = $preset + $presets; | 
					
						
							|  |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2020-05-09 14:21:46 -06:00
										 |  |  |                     foreach ($custom_presets as $value) { | 
					
						
							| 
									
										
										
										
											2021-03-26 14:39:37 +02:00
										 |  |  |                         if (isset($value['name'], $value['colors'], $value['accents'])) { | 
					
						
							| 
									
										
										
										
											2020-05-09 14:21:46 -06:00
										 |  |  |                             $preset = [Inflector::hyphenize($value['name']) => $value]; | 
					
						
							|  |  |  |                             $presets = $preset + $presets; | 
					
						
							| 
									
										
										
										
											2020-05-09 14:21:03 -06:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2020-05-08 17:50:03 -06:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |         return $presets; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-05 13:06:38 -07:00
										 |  |  | } |