Added a phpinfo page under configuration

This commit is contained in:
Andy Miller
2015-08-11 18:30:27 -06:00
parent f4aa929372
commit 61f1908750
13 changed files with 191 additions and 28 deletions

View File

@@ -1,16 +1,16 @@
<?php
namespace Grav\Plugin;
use Grav\Common\Data;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\User\User;
use Grav\Common\GPM\GPM;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Plugins;
use Grav\Common\Themes;
use Grav\Common\Uri;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Page;
use Grav\Common\Data;
use Grav\Common\GPM\GPM;
use Grav\Common\User\User;
use RocketTheme\Toolbox\File\File;
use RocketTheme\Toolbox\File\JsonFile;
use RocketTheme\Toolbox\File\LogFile;
@@ -120,12 +120,14 @@ class Admin
* Fetch and delete messages from the session queue.
*
* @param string $type
*
* @return array
*/
public function messages($type = null)
{
/** @var Message $messages */
$messages = $this->grav['messages'];
return $messages->fetch($type);
}
@@ -133,6 +135,7 @@ class Admin
* Authenticate user.
*
* @param array $form Form fields.
*
* @return bool
*/
public function authenticate($form)
@@ -168,16 +171,18 @@ class Admin
/**
* Checks user authorisation to the action.
*
* @param string $action
* @param string $action
*
* @return bool
*/
public function authorise($action = 'admin.login')
{
$action = (array) $action;
$action = (array)$action;
foreach ($action as $a) {
if ($this->user->authorise($a))
if ($this->user->authorise($a)) {
return true;
}
}
return false;
@@ -187,6 +192,7 @@ class Admin
* Returns edited page.
*
* @param bool $route
*
* @return Page
*/
public function page($route = false)
@@ -208,6 +214,7 @@ class Admin
* Returns blueprints for the given type.
*
* @param string $type
*
* @return Data\Blueprint
*/
public function blueprints($type)
@@ -215,6 +222,7 @@ class Admin
if ($this->blueprints === null) {
$this->blueprints = new Data\Blueprints($this->grav['locator']->findResource('blueprints://'));
}
return $this->blueprints->get($type);
}
@@ -222,7 +230,8 @@ class Admin
* Gets configuration data.
*
* @param string $type
* @param array $post
* @param array $post
*
* @return Data\Data|null
* @throws \RuntimeException
*/
@@ -320,6 +329,7 @@ class Admin
* Converts dot notation to array notation.
*
* @param string $name
*
* @return string
*/
public function field($name)
@@ -338,6 +348,7 @@ class Admin
{
/** @var Pages $pages */
$pages = $this->grav['pages'];
return $pages->routes();
}
@@ -349,7 +360,11 @@ class Admin
public function plugins($local = true)
{
$gpm = $this->gpm();
return $local ? $gpm->getInstalledPlugins() : $gpm->getRepositoryPlugins()->filter(function ($package, $slug) use ($gpm) {
return $local ? $gpm->getInstalledPlugins() : $gpm->getRepositoryPlugins()->filter(function (
$package,
$slug
) use ($gpm) {
return !$gpm->isPluginInstalled($slug);
});
}
@@ -362,7 +377,11 @@ class Admin
public function themes($local = true)
{
$gpm = $this->gpm();
return $local ? $gpm->getInstalledThemes() : $gpm->getRepositoryThemes()->filter(function ($package, $slug) use ($gpm) {
return $local ? $gpm->getInstalledThemes() : $gpm->getRepositoryThemes()->filter(function ($package, $slug) use
(
$gpm
) {
return !$gpm->isThemeInstalled($slug);
});
}
@@ -381,6 +400,7 @@ class Admin
$this->logs = array_reverse($content);
}
return $this->logs;
}
@@ -389,6 +409,7 @@ class Admin
* that have been modified
*
* @param integer $count number of pages to pull back
*
* @return array
*/
public function latestPages($count = 10)
@@ -401,7 +422,7 @@ class Admin
foreach ($pages->routes() as $url => $path) {
$page = $pages->dispatch($url);
if ($page && $page->routable()) {
$latest[$page->route()] = ['modified'=>$page->modified(), 'page'=>$page];
$latest[$page->route()] = ['modified' => $page->modified(), 'page' => $page];
}
}
@@ -410,6 +431,7 @@ class Admin
if ($a['modified'] == $b['modified']) {
return 0;
}
return ($a['modified'] > $b['modified']) ? -1 : 1;
});
@@ -447,8 +469,8 @@ class Admin
$content = $file->content();
if (empty($content)) {
return [
'days' => '&infin;',
'chart_fill' => 100,
'days' => '&infin;',
'chart_fill' => 100,
'chart_empty' => 0
];
}
@@ -461,8 +483,8 @@ class Admin
$chart_fill = $days > 30 ? 100 : round($days / 30 * 100);
return [
'days' => $days,
'chart_fill' => $chart_fill,
'days' => $days,
'chart_fill' => $chart_fill,
'chart_empty' => 100 - $chart_fill
];
}
@@ -471,6 +493,7 @@ class Admin
* Returns the page creating it if it does not exist.
*
* @param $path
*
* @return Page
*/
protected function getPage($path)
@@ -488,7 +511,7 @@ class Admin
$slug = basename($path);
if ($slug == '') {
return null;
return null;
}
$ppath = dirname($path);
@@ -499,7 +522,7 @@ class Admin
// Create page.
$page = new Page;
$page->parent($parent);
$page->filePath($parent->path().'/'.$slug.'/'.$page->name());
$page->filePath($parent->path() . '/' . $slug . '/' . $page->name());
// Add routing information.
$pages->addPage($page, $path);
@@ -511,7 +534,7 @@ class Admin
if (isset($this->session->{$page->route()})) {
// Found the type and header from the session.
$data = $this->session->{$page->route()};
$visible = isset($data['visible']) && $data['visible'] != '' ? (bool) $data['visible'] : $this->guessVisibility($page);
$visible = isset($data['visible']) && $data['visible'] != '' ? (bool)$data['visible'] : $this->guessVisibility($page);
$header = ['title' => $data['title'], 'visible' => $visible];
@@ -522,11 +545,12 @@ class Admin
$name = $page->modular() ? str_replace('modular/', '', $data['type']) : $data['type'];
$page->name($name . '.md');
$page->header($header);
$page->frontmatter(Yaml::dump((array) $page->header()));
$page->frontmatter(Yaml::dump((array)$page->header()));
} else {
// Find out the type by looking at the parent.
$type = $parent->childType() ? $parent->childType() : $parent->blueprints()->get('child_type', 'default');
$page->name($type.CONTENT_EXT);
$type = $parent->childType() ? $parent->childType() : $parent->blueprints()->get('child_type',
'default');
$page->name($type . CONTENT_EXT);
$page->header();
}
$page->modularTwig($slug[0] == '_');
@@ -550,6 +574,7 @@ class Admin
return true;
}
}
return false;
}
@@ -567,6 +592,7 @@ class Admin
* Determine if the plugin or theme info passed is from Team Grav
*
* @param object $info Plugin or Theme info object
*
* @return bool
*/
public function isTeamGrav($info)
@@ -577,4 +603,14 @@ class Admin
return false;
}
}
function phpinfo() {
ob_start();
phpinfo();
$pinfo = ob_get_contents();
ob_end_clean();
$pinfo = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1',$pinfo);
return $pinfo;
}
}

7
pages/admin/info.md Normal file
View File

@@ -0,0 +1,7 @@
---
title: PHP Info
access:
admin.settings: true
admin.super: true
---

View File

@@ -765,6 +765,20 @@ tr {
-moz-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap; }
tr th {
display: block;
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
flex: 1;
font-weight: bold; }
tr th:first-child {
padding-left: 3rem; }
tr th:last-child {
padding-right: 3rem; }
tr td {
display: block;
-webkit-box-flex: 1;
@@ -2295,4 +2309,26 @@ button.toast-close-button {
color: #a2a2a2;
font-weight: normal; }
#phpinfo img {
display: none; }
#phpinfo table {
margin: 1rem 0 0; }
#phpinfo tr:hover {
background: transparent; }
#phpinfo th {
background: #d9d9d9; }
#phpinfo td {
word-wrap: break-word; }
#phpinfo td h1 {
margin: 0rem -3rem 0rem !important; }
#phpinfo td:first-child {
color: #349886; }
#phpinfo hr {
border-bottom: 0; }
#phpinfo h1 {
font-size: 2.3rem; }
#phpinfo h2 {
font-size: 1.7rem;
margin: 3rem 3rem 0rem !important; }
/*# sourceMappingURL=template.css.map */

File diff suppressed because one or more lines are too long

View File

@@ -72,6 +72,9 @@
// GPM
@import "template/gpm";
// PHPInfo
@import "template/phpinfo";
// Custom
@import "template/custom";

View File

@@ -0,0 +1,42 @@
#phpinfo {
img { display: none;}
table {
margin: 1rem 0 0;
}
tr {
&:hover {
background: transparent;
}
}
th {
background: #d9d9d9;
}
td {
word-wrap: break-word;
h1 {
margin: 0rem (- $padding-default) 0rem !important;
}
&:first-child {
color: $secondary-accent-bg;
}
}
hr {
border-bottom: 0;
}
h1 {
font-size: 2.3rem;
}
h2 {
font-size: 1.7rem;
margin: 3rem ($padding-default) 0rem !important;
}
}

View File

@@ -20,6 +20,20 @@ tr {
@include display(flex);
@include flex-wrap(wrap);
th {
display: block;
@include flex(1);
font-weight: bold;
&:first-child {
padding-left: $padding-default;
}
&:last-child {
padding-right: $padding-default;
}
}
td {
display: block;
@include flex(1);

View File

@@ -0,0 +1,23 @@
{% extends 'partials/base.html.twig' %}
{% block titlebar %}
<div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> Back</a>
</div>
<h1><i class="fa fa-fw fa-th"></i> Configuration - PHP Info</h1>
{% endblock %}
{% block content_top %}
<ul class="tab-bar">
<li><a href="{{ base_url_relative }}/system">System</a></li>
<li><a href="{{ base_url_relative }}/site">Site</a></li>
<li class="active"><span>Info</span></li>
</ul>
{% endblock %}
{% block content %}
<div id="phpinfo">
{{ admin.phpinfo }}
</div>
{% endblock %}

View File

@@ -20,8 +20,8 @@
<li class="{{ (location == 'dashboard') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}"><i class="fa fa-fw fa-th"></i> Dashboard</a>
</li>
<li class="{{ (location == 'configuration' or location == 'settings') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/configuration"><i class="fa fa-fw fa-wrench"></i> Configuration</a>
<li class="{{ (location == 'system' or location == 'site') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/system"><i class="fa fa-fw fa-wrench"></i> Configuration</a>
</li>
<li class="{{ (location == 'pages') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/pages">

View File

@@ -10,8 +10,9 @@
{% block content_top %}
<ul class="tab-bar">
<li><a href="{{ base_url_relative }}/configuration/">System</a></li>
<li><a href="{{ base_url_relative }}/system">System</a></li>
<li class="active"><span>Site</span></li>
<li><a href="{{ base_url_relative }}/info">Info</a></li>
</ul>
{% endblock %}

View File

@@ -11,7 +11,8 @@
{% block content_top %}
<ul class="tab-bar">
<li class="active"><span>System</span></li>
<li><a href="{{ base_url_relative }}/settings/">Site</a></li>
<li><a href="{{ base_url_relative }}/site">Site</a></li>
<li><a href="{{ base_url_relative }}/info">Info</a></li>
</ul>
{% endblock %}