local initial checkin

This commit is contained in:
Andy Miller
2014-09-03 22:22:03 -06:00
parent bc3753a693
commit 1c83133f82
437 changed files with 7294 additions and 43 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
themes/grav/.sass-cache

107
admin.php
View File

@@ -20,6 +20,11 @@ class AdminPlugin extends Plugin
*/ */
protected $template; protected $template;
/**
* @var string
*/
protected $theme;
/** /**
* @var string * @var string
*/ */
@@ -51,49 +56,16 @@ class AdminPlugin extends Plugin
*/ */
public function onPluginsInitialized() public function onPluginsInitialized()
{ {
$route = $this->config->get('plugins.admin.route');
if (!$route) { // Check for Pro version and disable this plugin if found
return; // if (file_exists(PLUGINS_DIR . 'admin_pro/admin_pro.php')) {
} // $this->enabled = false;
// return;
// }
$this->uri = $this->grav['uri']; // echo "<h1>Admin Free</h1>";
$base = '/' . trim($route, '/');
// Only activate admin if we're inside the admin path. $this->initializeAdmin();
if (substr($this->uri->route(), 0, strlen($base)) == $base) {
$this->enable([
'onPagesInitialized' => ['onPagesInitialized', 1000],
'onPageInitialized' => ['onPageInitialized', 1000],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 1000],
'onTwigSiteVariables' => ['onTwigSiteVariables', 1000]
]);
// Disable system caching.
$this->config->set('system.cache.enabled', false);
// Decide admin template and route.
$path = trim(substr($this->uri->route(), strlen($base)), '/');
$this->template = 'dashboard';
if ($path) {
$array = explode('/', $path, 2);
$this->template = array_shift($array);
$this->route = array_shift($array);
// Set path for new page.
if ($this->uri->param('new')) {
$this->route .= '/new';
}
}
// Initialize admin class.
require_once __DIR__ . '/classes/admin.php';
$this->admin = new Admin($this->grav, $base, $this->template, $this->route);
// And store the class into DI container.
$this->grav['admin'] = $this->admin;
}
} }
/** /**
@@ -119,6 +91,8 @@ class AdminPlugin extends Plugin
$this->template = $this->admin->user ? 'denied' : 'login'; $this->template = $this->admin->user ? 'denied' : 'login';
} }
// Make local copy of POST. // Make local copy of POST.
$post = !empty($_POST) ? $_POST : array(); $post = !empty($_POST) ? $_POST : array();
@@ -152,8 +126,8 @@ class AdminPlugin extends Plugin
*/ */
public function onTwigTemplatePaths() public function onTwigTemplatePaths()
{ {
$twig = $this->grav['twig']; $this->theme = $this->config->get('plugins.admin.theme', 'grav');
$twig->twig_paths = array(__DIR__ . '/theme/templates'); $this->grav['twig']->twig_paths = array(__DIR__ . '/themes/'.$this->theme.'/templates');
} }
/** /**
@@ -162,7 +136,7 @@ class AdminPlugin extends Plugin
public function onTwigSiteVariables() public function onTwigSiteVariables()
{ {
// TODO: use real plugin name instead // TODO: use real plugin name instead
$theme_url = $this->config->get('system.base_url_relative') . '/user/plugins/admin/theme'; $theme_url = $this->config->get('system.base_url_relative') . '/user/plugins/admin/themes/'.$this->theme;
$twig = $this->grav['twig']; $twig = $this->grav['twig'];
$twig->template = $this->template . '.html.twig'; $twig->template = $this->template . '.html.twig';
@@ -182,4 +156,51 @@ class AdminPlugin extends Plugin
break; break;
} }
} }
protected function initializeAdmin()
{
$this->route = $this->config->get('plugins.admin.route');
if (!$this->route) {
return;
}
$this->uri = $this->grav['uri'];
$base = '/' . trim($this->route, '/');
// Only activate admin if we're inside the admin path.
if (substr($this->uri->route(), 0, strlen($base)) == $base) {
$this->enable([
'onPagesInitialized' => ['onPagesInitialized', 1000],
'onPageInitialized' => ['onPageInitialized', 1000],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 1000],
'onTwigSiteVariables' => ['onTwigSiteVariables', 1000]
]);
// Disable system caching.
$this->config->set('system.cache.enabled', false);
// Decide admin template and route.
$path = trim(substr($this->uri->route(), strlen($base)), '/');
$this->template = 'dashboard';
if ($path) {
$array = explode('/', $path, 2);
$this->template = array_shift($array);
$this->route = array_shift($array);
// Set path for new page.
if ($this->uri->param('new')) {
$this->route .= '/new';
}
}
// Initialize admin class.
require_once PLUGINS_DIR . 'admin/classes/admin.php';
$this->admin = new Admin($this->grav, $base, $this->template, $this->route);
// And store the class into DI container.
$this->grav['admin'] = $this->admin;
}
}
} }

View File

@@ -1,2 +1,3 @@
enabled: true enabled: true
route: '/admin' route: '/admin'
theme: grav

View File

Before

Width:  |  Height:  |  Size: 197 KiB

After

Width:  |  Height:  |  Size: 197 KiB

View File

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 104 KiB

View File

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 114 KiB

View File

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 117 KiB

View File

Before

Width:  |  Height:  |  Size: 669 B

After

Width:  |  Height:  |  Size: 669 B

Some files were not shown because too many files have changed in this diff Show More