2014-08-05 13:06:38 -07:00
|
|
|
<?php
|
|
|
|
|
namespace Grav\Plugin;
|
|
|
|
|
|
2014-10-07 17:01:40 -07:00
|
|
|
use Grav\Common\GPM\GPM;
|
|
|
|
|
use Grav\Common\Grav;
|
2015-10-22 15:53:42 -06:00
|
|
|
use Grav\Common\Language\Language;
|
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;
|
2014-08-29 11:27:53 +03:00
|
|
|
use Grav\Common\Uri;
|
2014-10-01 22:28:16 +03:00
|
|
|
use RocketTheme\Toolbox\File\File;
|
2015-05-20 17:19:12 +02:00
|
|
|
use RocketTheme\Toolbox\Event\Event;
|
2014-10-01 22:28:16 +03:00
|
|
|
use RocketTheme\Toolbox\Session\Session;
|
2014-08-05 13:06:38 -07:00
|
|
|
|
|
|
|
|
class AdminPlugin extends Plugin
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected $active = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $template;
|
|
|
|
|
|
2014-09-03 22:22:03 -06:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $theme;
|
|
|
|
|
|
2014-08-05 13:06:38 -07:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $route;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Uri
|
|
|
|
|
*/
|
|
|
|
|
protected $uri;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Admin
|
|
|
|
|
*/
|
|
|
|
|
protected $admin;
|
|
|
|
|
|
2014-10-01 22:28:16 +03:00
|
|
|
/**
|
|
|
|
|
* @var Session
|
|
|
|
|
*/
|
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Popularity
|
|
|
|
|
*/
|
2014-09-08 18:32:13 -06:00
|
|
|
protected $popularity;
|
|
|
|
|
|
2014-10-01 22:28:16 +03:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $base;
|
|
|
|
|
|
2014-08-29 11:27:53 +03:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2014-09-23 12:45:26 -07:00
|
|
|
public static function getSubscribedEvents()
|
|
|
|
|
{
|
2014-08-29 11:27:53 +03:00
|
|
|
return [
|
2014-09-09 07:57:53 +03:00
|
|
|
'onPluginsInitialized' => [['login', 100000], ['onPluginsInitialized', 1000]],
|
2014-10-07 17:01:40 -07:00
|
|
|
'onShutdown' => ['onShutdown', 1000]
|
2014-08-29 11:27:53 +03:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-05 13:06:38 -07:00
|
|
|
/**
|
2015-07-30 12:20:25 +02:00
|
|
|
* If the admin path matches, initialize the Login plugin configuration and set the admin
|
|
|
|
|
* as active.
|
2014-08-05 13:06:38 -07:00
|
|
|
*/
|
2014-09-09 06:10:31 +03:00
|
|
|
public function login()
|
2014-08-05 13:06:38 -07:00
|
|
|
{
|
2014-12-29 11:31:10 -07:00
|
|
|
// Check for Pro version is enabled
|
|
|
|
|
if ($this->config->get('plugins.admin-pro.enabled')) {
|
|
|
|
|
$this->active = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-05 13:06:38 -07:00
|
|
|
|
|
|
|
|
$route = $this->config->get('plugins.admin.route');
|
|
|
|
|
if (!$route) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-29 11:31:10 -07:00
|
|
|
$this->grav['debugger']->addMessage("Admin Basic");
|
|
|
|
|
|
2014-09-09 06:10:31 +03:00
|
|
|
$this->base = '/' . trim($route, '/');
|
2014-08-29 11:27:53 +03:00
|
|
|
$this->uri = $this->grav['uri'];
|
2014-08-05 13:06:38 -07:00
|
|
|
|
|
|
|
|
// Only activate admin if we're inside the admin path.
|
2015-08-11 11:07:24 +02:00
|
|
|
if ($this->uri->route() == $this->base ||
|
|
|
|
|
substr($this->uri->route(), 0, strlen($this->base) + 1) == $this->base . '/') {
|
2014-09-09 06:10:31 +03:00
|
|
|
$this->active = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 17:01:40 -07:00
|
|
|
/**
|
2015-07-30 12:20:25 +02:00
|
|
|
* If the admin plugin is set as active, initialize the admin
|
2014-09-09 06:10:31 +03:00
|
|
|
*/
|
|
|
|
|
public function onPluginsInitialized()
|
|
|
|
|
{
|
|
|
|
|
// Only activate admin if we're inside the admin path.
|
|
|
|
|
if ($this->active) {
|
2014-09-09 07:57:53 +03:00
|
|
|
$this->initializeAdmin();
|
2014-09-09 14:03:01 -06:00
|
|
|
|
2015-10-24 18:25:15 +02:00
|
|
|
// Disable Asset pipelining
|
|
|
|
|
$this->config->set('system.assets.css_pipeline', false);
|
|
|
|
|
$this->config->set('system.assets.js_pipeline', false);
|
2015-11-25 18:31:25 +01:00
|
|
|
|
|
|
|
|
// Replace themes service with admin.
|
|
|
|
|
$this->grav['themes'] = function ($c) {
|
|
|
|
|
require_once __DIR__ . '/classes/themes.php';
|
|
|
|
|
return new Themes($this->grav);
|
|
|
|
|
};
|
2015-10-24 18:25:15 +02:00
|
|
|
}
|
2015-10-22 14:47:47 -06:00
|
|
|
|
2014-09-09 14:03:01 -06:00
|
|
|
// We need popularity no matter what
|
|
|
|
|
require_once __DIR__ . '/classes/popularity.php';
|
|
|
|
|
$this->popularity = new Popularity();
|
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.
|
|
|
|
|
*/
|
2014-08-29 11:27:53 +03:00
|
|
|
public function onPagesInitialized()
|
2014-08-05 13:06:38 -07:00
|
|
|
{
|
2014-09-21 17:17:08 -06:00
|
|
|
$this->session = $this->grav['session'];
|
|
|
|
|
|
2014-08-05 13:06:38 -07:00
|
|
|
// Set original route for the home page.
|
|
|
|
|
$home = '/' . trim($this->config->get('system.home.alias'), '/');
|
|
|
|
|
|
2014-10-06 19:03:57 -06:00
|
|
|
// set the default if not set before
|
2015-01-11 00:47:27 +01:00
|
|
|
$this->session->expert = $this->session->expert ?: false;
|
2014-10-06 19:03:57 -06:00
|
|
|
|
2014-09-21 17:17:08 -06:00
|
|
|
// set session variable if it's passed via the url
|
|
|
|
|
if ($this->uri->param('mode') == 'expert') {
|
|
|
|
|
$this->session->expert = true;
|
|
|
|
|
} elseif ($this->uri->param('mode') == 'normal') {
|
|
|
|
|
$this->session->expert = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 17:03:44 -06:00
|
|
|
// check for existence of a user account
|
|
|
|
|
$account_dir = $file_path = $this->grav['locator']->findResource('account://');
|
|
|
|
|
$user_check = (array) glob($account_dir . '/*.yaml');
|
|
|
|
|
if (!count($user_check) > 0) {
|
|
|
|
|
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.NO_USER_ACCOUNTS'), 'info');
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-05 13:06:38 -07:00
|
|
|
/** @var Pages $pages */
|
2014-08-29 11:27:53 +03:00
|
|
|
$pages = $this->grav['pages'];
|
2014-09-05 22:27:30 -06:00
|
|
|
|
|
|
|
|
$this->grav['admin']->routes = $pages->routes();
|
|
|
|
|
|
2015-01-11 00:47:27 +01:00
|
|
|
// Remove default route from routes.
|
2015-01-11 18:33:45 +01:00
|
|
|
if (isset($this->grav['admin']->routes['/'])) {
|
|
|
|
|
unset($this->grav['admin']->routes['/']);
|
2015-01-11 00:47:27 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-07 12:05:34 +02:00
|
|
|
$page = $pages->dispatch('/', true);
|
|
|
|
|
|
|
|
|
|
// If page is null, the default page does not exist, and we cannot route to it
|
|
|
|
|
if ($page) {
|
|
|
|
|
$page->route($home);
|
|
|
|
|
}
|
2014-08-05 13:06:38 -07:00
|
|
|
|
|
|
|
|
// Make local copy of POST.
|
|
|
|
|
$post = !empty($_POST) ? $_POST : array();
|
|
|
|
|
|
|
|
|
|
// Handle tasks.
|
2014-09-22 15:49:53 -06:00
|
|
|
$this->admin->task = $task = !empty($post['task']) ? $post['task'] : $this->uri->param('task');
|
2014-08-05 13:06:38 -07:00
|
|
|
if ($task) {
|
|
|
|
|
require_once __DIR__ . '/classes/controller.php';
|
2014-08-29 11:27:53 +03:00
|
|
|
$controller = new AdminController($this->grav, $this->template, $task, $this->route, $post);
|
2014-09-17 11:54:57 +03:00
|
|
|
$controller->execute();
|
2014-08-05 13:06:38 -07:00
|
|
|
$controller->redirect();
|
|
|
|
|
} elseif ($this->template == 'logs' && $this->route) {
|
|
|
|
|
// Display RAW error message.
|
|
|
|
|
echo $this->admin->logEntry();
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-09 06:10:31 +03:00
|
|
|
$self = $this;
|
2014-08-05 13:06:38 -07:00
|
|
|
|
2014-09-09 06:10:31 +03:00
|
|
|
// Replace page service with admin.
|
2014-09-23 12:45:26 -07:00
|
|
|
$this->grav['page'] = function () use ($self) {
|
2014-09-09 06:10:31 +03:00
|
|
|
$page = new Page;
|
2015-09-07 11:49:41 +02:00
|
|
|
|
|
|
|
|
if (file_exists(__DIR__ . "/pages/admin/{$self->template}.md")) {
|
|
|
|
|
$page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md"));
|
|
|
|
|
$page->slug(basename($self->template));
|
|
|
|
|
return $page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the page cannot be found, try looking in plugins.
|
|
|
|
|
// Allows pages added by plugins in admin
|
|
|
|
|
$plugins = Grav::instance()['config']->get('plugins', []);
|
|
|
|
|
|
|
|
|
|
foreach($plugins as $plugin => $data) {
|
2015-10-29 19:15:51 +01:00
|
|
|
$path = $this->grav['locator']->findResource(
|
|
|
|
|
"user://plugins/{$plugin}/admin/pages/{$self->template}.md");
|
2015-10-26 21:30:33 +01:00
|
|
|
|
|
|
|
|
if (file_exists($path)) {
|
|
|
|
|
$page->init(new \SplFileInfo($path));
|
|
|
|
|
$page->slug(basename($self->template));
|
|
|
|
|
return $page;
|
|
|
|
|
}
|
2015-09-07 11:49:41 +02:00
|
|
|
}
|
2014-09-09 06:10:31 +03:00
|
|
|
};
|
2015-11-25 15:43:26 -07:00
|
|
|
|
|
|
|
|
if (empty($this->grav['page'])) {
|
|
|
|
|
$event = $this->grav->fireEvent('onPageNotFound');
|
|
|
|
|
|
|
|
|
|
if (isset($event->page)) {
|
|
|
|
|
unset($this->grav['page']);
|
|
|
|
|
$this->grav['page'] = $event->page;
|
|
|
|
|
} else {
|
|
|
|
|
throw new \RuntimeException('Page Not Found', 404);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-05 13:06:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add twig paths to plugin templates.
|
|
|
|
|
*/
|
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;
|
2015-02-28 13:41:47 -07:00
|
|
|
|
2014-08-05 13:06:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set all twig variables for generating output.
|
|
|
|
|
*/
|
2014-08-29 11:27:53 +03:00
|
|
|
public function onTwigSiteVariables()
|
2014-08-05 13:06:38 -07:00
|
|
|
{
|
2014-08-29 11:27:53 +03:00
|
|
|
$twig = $this->grav['twig'];
|
2014-08-05 13:06:38 -07:00
|
|
|
|
2014-09-22 15:49:53 -06:00
|
|
|
// Dynamic type support
|
|
|
|
|
$format = $this->uri->extension();
|
|
|
|
|
$ext = '.' . ($format ? $format : 'html') . TWIG_EXT;
|
|
|
|
|
|
2014-08-05 13:06:38 -07:00
|
|
|
$twig->twig_vars['location'] = $this->template;
|
2015-08-25 17:20:07 +02:00
|
|
|
$twig->twig_vars['base_url_relative_frontend'] = $twig->twig_vars['base_url_relative'] ?: '/';
|
2015-08-19 14:58:18 -06:00
|
|
|
$twig->twig_vars['admin_route'] = trim($this->config->get('plugins.admin.route'), '/');
|
2015-10-24 13:14:00 -06:00
|
|
|
$twig->twig_vars['base_url_relative'] =
|
|
|
|
|
$twig->twig_vars['base_url_simple'] . '/' . $twig->twig_vars['admin_route'];
|
2015-02-28 13:41:47 -07:00
|
|
|
$twig->twig_vars['theme_url'] = '/user/plugins/admin/themes/' . $this->theme;
|
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;
|
|
|
|
|
|
2015-09-07 11:48:42 +02:00
|
|
|
// Gather Plugin-hooked nav items
|
2015-10-26 21:30:33 +01:00
|
|
|
$this->grav->fireEvent('onAdminMenu');
|
|
|
|
|
|
|
|
|
|
// DEPRECATED
|
2015-09-07 11:48:42 +02:00
|
|
|
$this->grav->fireEvent('onAdminTemplateNavPluginHook');
|
|
|
|
|
|
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;
|
|
|
|
|
break;
|
2014-08-05 13:06:38 -07:00
|
|
|
case 'pages':
|
2015-08-07 12:05:34 +02:00
|
|
|
$page = $this->admin->page(true);
|
|
|
|
|
if ($page != null) {
|
|
|
|
|
$twig->twig_vars['file'] = File::instance($page->filePath());
|
|
|
|
|
$twig->twig_vars['media_types'] = str_replace('defaults,', '',
|
|
|
|
|
implode(',.', array_keys($this->config->get('media'))));
|
|
|
|
|
|
|
|
|
|
}
|
2014-08-05 13:06:38 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-03 22:22:03 -06:00
|
|
|
|
2014-09-06 16:59:58 -06:00
|
|
|
public function onShutdown()
|
|
|
|
|
{
|
2014-09-09 14:03:01 -06:00
|
|
|
// Just so we know that we're in this debug mode
|
2014-09-06 18:13:04 -06:00
|
|
|
if ($this->config->get('plugins.admin.popularity.enabled')) {
|
2014-09-08 18:32:13 -06:00
|
|
|
|
|
|
|
|
// Only track non-admin
|
|
|
|
|
if (!$this->active) {
|
|
|
|
|
$this->popularity->trackHit();
|
2014-09-06 16:59:58 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 12:20:25 +02:00
|
|
|
/**
|
|
|
|
|
* Handles getting GPM updates
|
|
|
|
|
*/
|
2014-10-07 17:01:40 -07:00
|
|
|
public function onTaskGPM()
|
|
|
|
|
{
|
|
|
|
|
$action = $_POST['action']; // getUpdatable | getUpdatablePlugins | getUpdatableThemes | gravUpdates
|
2015-08-07 14:08:12 -07:00
|
|
|
$flush = isset($_POST['flush']) && $_POST['flush'] == true ? true : false;
|
2014-10-07 17:01:40 -07:00
|
|
|
|
|
|
|
|
if (isset($this->grav['session'])) {
|
|
|
|
|
$this->grav['session']->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2015-08-07 14:08:12 -07:00
|
|
|
$gpm = new GPM($flush);
|
2014-10-07 17:01:40 -07:00
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
|
case 'getUpdates':
|
|
|
|
|
$resources_updates = $gpm->getUpdatable();
|
2015-11-01 12:05:07 +01:00
|
|
|
if ($gpm->grav != null) {
|
|
|
|
|
$grav_updates = [
|
|
|
|
|
"isUpdatable" => $gpm->grav->isUpdatable(),
|
|
|
|
|
"assets" => $gpm->grav->getAssets(),
|
|
|
|
|
"version" => GRAV_VERSION,
|
|
|
|
|
"available" => $gpm->grav->getVersion(),
|
|
|
|
|
"date" => $gpm->grav->getDate(),
|
|
|
|
|
"isSymlink" => $gpm->grav->isSymlink()
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
echo json_encode([
|
|
|
|
|
"status" => "success",
|
|
|
|
|
"payload" => ["resources" => $resources_updates, "grav" => $grav_updates, "installed" => $gpm->countInstalled(), 'flushed' => $flush]
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
echo json_encode(["status" => "error", "message" => "Cannot connect to the GPM"]);
|
|
|
|
|
}
|
2014-10-07 17:01:40 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
2015-05-11 16:37:43 +02:00
|
|
|
echo json_encode(["status" => "error", "message" => $e->getMessage()]);
|
2014-10-07 17:01:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 12:20:25 +02:00
|
|
|
/**
|
|
|
|
|
* Initialize the admin.
|
|
|
|
|
*
|
|
|
|
|
* @throws \RuntimeException
|
|
|
|
|
*/
|
2014-09-03 22:22:03 -06:00
|
|
|
protected function initializeAdmin()
|
|
|
|
|
{
|
2014-09-09 07:57:53 +03:00
|
|
|
$this->enable([
|
2015-08-13 20:26:50 +02:00
|
|
|
'onTwigExtensions' => ['onTwigExtensions', 1000],
|
2014-10-07 17:01:40 -07:00
|
|
|
'onPagesInitialized' => ['onPagesInitialized', 1000],
|
2014-09-09 07:57:53 +03:00
|
|
|
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 1000],
|
2014-10-07 17:01:40 -07:00
|
|
|
'onTwigSiteVariables' => ['onTwigSiteVariables', 1000],
|
|
|
|
|
'onTask.GPM' => ['onTaskGPM', 0]
|
2014-09-09 07:57:53 +03:00
|
|
|
]);
|
2014-09-03 22:22:03 -06:00
|
|
|
|
2015-07-27 12:56:16 -06:00
|
|
|
// Check for required plugins
|
|
|
|
|
if (!$this->grav['config']->get('plugins.login.enabled') ||
|
|
|
|
|
!$this->grav['config']->get('plugins.form.enabled') ||
|
|
|
|
|
!$this->grav['config']->get('plugins.email.enabled')) {
|
|
|
|
|
throw new \RuntimeException('One of the required plugins is missing or not enabled');
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 15:52:34 -06:00
|
|
|
// Double check we have system.yaml and site.yaml
|
|
|
|
|
$config_files[] = $this->grav['locator']->findResource('user://config') . '/system.yaml';
|
|
|
|
|
$config_files[] = $this->grav['locator']->findResource('user://config') . '/site.yaml';
|
|
|
|
|
foreach ($config_files as $config_file) {
|
|
|
|
|
if (!file_exists($config_file)) {
|
|
|
|
|
touch($config_file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-20 11:02:52 -07:00
|
|
|
// Initialize Admin Language if needed
|
|
|
|
|
/** @var Language $language */
|
|
|
|
|
$language = $this->grav['language'];
|
|
|
|
|
if ($language->enabled() && empty($this->grav['session']->admin_lang)) {
|
|
|
|
|
$this->grav['session']->admin_lang = $language->getLanguage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-09 07:57:53 +03:00
|
|
|
// Decide admin template and route.
|
|
|
|
|
$path = trim(substr($this->uri->route(), strlen($this->base)), '/');
|
|
|
|
|
$this->template = 'dashboard';
|
2014-09-03 22:22:03 -06:00
|
|
|
|
2014-09-09 07:57:53 +03:00
|
|
|
if ($path) {
|
|
|
|
|
$array = explode('/', $path, 2);
|
|
|
|
|
$this->template = array_shift($array);
|
|
|
|
|
$this->route = array_shift($array);
|
|
|
|
|
}
|
2014-09-03 22:22:03 -06:00
|
|
|
|
2014-09-09 07:57:53 +03:00
|
|
|
// Initialize admin class.
|
|
|
|
|
require_once __DIR__ . '/classes/admin.php';
|
|
|
|
|
$this->admin = new Admin($this->grav, $this->base, $this->template, $this->route);
|
2014-09-06 16:59:58 -06:00
|
|
|
|
2014-09-09 07:57:53 +03:00
|
|
|
// And store the class into DI container.
|
|
|
|
|
$this->grav['admin'] = $this->admin;
|
2015-02-28 13:41:47 -07:00
|
|
|
|
|
|
|
|
// Get theme for admin
|
|
|
|
|
$this->theme = $this->config->get('plugins.admin.theme', 'grav');
|
2015-08-24 18:49:11 +02:00
|
|
|
|
|
|
|
|
$assets = $this->grav['assets'];
|
|
|
|
|
$translations = 'if (!window.translations) window.translations = {}; ' . PHP_EOL . 'window.translations.PLUGIN_ADMIN = {};' . PHP_EOL;
|
|
|
|
|
|
|
|
|
|
$strings = ['EVERYTHING_UP_TO_DATE',
|
|
|
|
|
'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-08-24 18:49:11 +02:00
|
|
|
'DAYS'];
|
|
|
|
|
|
|
|
|
|
foreach($strings as $string) {
|
|
|
|
|
$translations .= 'translations.PLUGIN_ADMIN.' . $string .' = "' . $this->admin->translate('PLUGIN_ADMIN.' . $string) . '"; ' . PHP_EOL;;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$assets->addInlineJs($translations);
|
2014-09-03 22:22:03 -06:00
|
|
|
}
|
2015-08-13 20:26:50 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add Twig Extensions
|
|
|
|
|
*/
|
|
|
|
|
public function onTwigExtensions()
|
|
|
|
|
{
|
|
|
|
|
require_once(__DIR__.'/twig/AdminTwigExtension.php');
|
|
|
|
|
$this->grav['twig']->twig->addExtension(new AdminTwigExtension());
|
|
|
|
|
}
|
2014-08-05 13:06:38 -07:00
|
|
|
}
|