ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPlainTextHandler.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
16
18{
19 const KEY_SPACE = 25;
20
26 public function handle()
27 {
28 header("Content-Type: text/plain");
29 echo "<pre>\n";
30 echo $this->content();
31 echo "</pre>\n";
32 }
33
39 protected function content()
40 {
41 return $this->pageHeader()
42 . $this->exceptionContent()
43 . $this->tablesContent()
44 ;
45 }
46
52 protected function pageHeader()
53 {
54 return "";
55 }
56
62 protected function exceptionContent()
63 {
64 return Formatter::formatExceptionPlain($this->getInspector());
65 }
66
72 protected function tablesContent()
73 {
74 $ret = "";
75 foreach ($this->tables() as $title => $content) {
76 $ret .= "\n\n-- $title --\n\n";
77 if (count($content) > 0) {
78 foreach ($content as $key => $value) {
79 $key = str_pad($key, self::KEY_SPACE);
80
81 // indent multiline values, first print_r, split in lines,
82 // indent all but first line, then implode again.
83 $first = true;
84 $indentation = str_pad("", self::KEY_SPACE);
85 $value = implode("\n", array_map(function ($line) use (&$first, $indentation) {
86 if ($first) {
87 $first = false;
88 return $line;
89 }
90 return $indentation . $line;
91 }, explode("\n", print_r($value, true))));
92
93 $ret .= "$key: $value\n";
94 }
95 } else {
96 $ret .= "empty\n";
97 }
98 }
99 return $ret;
100 }
101
107 protected function tables()
108 {
109 $post = $_POST;
111
112 $post = $this->hidePassword($post);
114
115 return array( "GET Data" => $_GET
116 , "POST Data" => $post
117 , "Files" => $_FILES
118 , "Cookies" => $_COOKIE
119 , "Session" => isset($_SESSION) ? $_SESSION : array()
120 , "Server/Request Data" => $server
121 , "Environment Variables" => $_ENV
122 );
123 }
124
132 private function hidePassword(array $post)
133 {
134 if (isset($post["password"])) {
135 $post["password"] = "REMOVED FOR SECURITY";
136 }
137
138 return $post;
139 }
140
148 private function shortenPHPSessionId(array $server)
149 {
150 $cookie_content = $server["HTTP_COOKIE"];
151 $cookie_content = explode(";", $cookie_content);
152
153 foreach ($cookie_content as $key => $content) {
154 $content_array = explode("=", $content);
155 if (trim($content_array[0]) == session_name()) {
156 $content_array[1] = substr($content_array[1], 0, 5) . " (SHORTENED FOR SECURITY)";
157 $cookie_content[$key] = implode("=", $content_array);
158 }
159 }
160
161 $server["HTTP_COOKIE"] = implode(";", $cookie_content);
162
163 return $server;
164 }
165}
$_COOKIE['client_id']
Definition: server.php:9
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Abstract implementation of a Handler.
Definition: Handler.php:16
pageHeader()
Get the header for the page.
tablesContent()
Get the header for the page.
hidePassword(array $post)
Replace passwort from post array with security message.
exceptionContent()
Get a short info about the exception.
handle()
Last missing method from HandlerInterface.
shortenPHPSessionId(array $server)
Shorts the php session id.
tables()
Get the tables that should be rendered.
content()
Assemble the output for this handler.
$key
Definition: croninfo.php:18
$server
Definition: getUserInfo.php:12
$ret
Definition: parser.php:6
$post
Definition: post.php:34
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']