-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extension.php
92 lines (74 loc) · 1.85 KB
/
Extension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
// Google+ extension for Bolt
namespace Bolt\Extension\DanielKulbe\PHPinfo;
use Bolt\Application;
use Bolt\BaseExtension;
class Extension extends BaseExtension
{
/**
* Extension name
*
* @var string
*/
const NAME = 'PHP Info';
/**
* Cache identifer
* @var string
*/
private $cachekey;
/**
* Cache duration
* @var integer
*/
private $cachetime;#
/**
* Add Twig settings in 'frontend' environment
*
* @return void
*/
public function initialize()
{
$this->cachekey = 'phpinfo';
$this->cachetime = intval($this->app['config']->get('general/caching/duration', 10)) *60;
$this->addTwigFunction('phpinfo', 'phpInfo');
}
/**
* Get the extension's human readable name
*
* @return string
*/
public function getName()
{
return Extension::NAME;
}
/**
* Make phpinfo() Twig function save for record fields, when `allowtwig` is set to `true`.
*
* @return boolean Safe to use with html fields
*/
public function isSafe()
{
return true;
}
/**
* Set the defaults for configuration parameters
*
* @return array
*/
public function phpInfo()
{
$phpinfo = null;
if ($this->app['cache']->contains($this->cachekey)) {
$phpinfo = base64_decode($this->app['cache']->fetch($this->cachekey));
} else {
ob_start();
phpinfo();
$info = ob_get_clean();
$start = stripos($info, "<body");
$end = stripos($info, "</body");
$phpinfo = substr($info,$start,$end-$start);
$this->app['cache']->save($this->cachekey, base64_encode($phpinfo), $this->cachetime);
}
return new \Twig_Markup($phpinfo, 'UTF-8');
}
}