ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
17 class ilPlainTextHandler extends Handler {
18  const KEY_SPACE = 25;
19 
25  public function handle() {
26  header("Content-Type: text/plain");
27  echo "<pre>\n";
28  echo $this->content();
29  echo "</pre>\n";
30  }
31 
37  protected function content() {
38  return $this->pageHeader()
39  .$this->exceptionContent()
40  .$this->tablesContent()
41  ;
42  }
43 
49  protected function pageHeader() {
50  return "";
51  }
52 
58  protected function exceptionContent() {
59  return Formatter::formatExceptionPlain($this->getInspector());
60  }
61 
67  protected function tablesContent() {
68  $ret = "";
69  foreach ($this->tables() as $title => $content) {
70  $ret .= "\n\n-- $title --\n\n";
71  if (count($content) > 0) {
72  foreach ($content as $key => $value) {
73  $key = str_pad($key, self::KEY_SPACE);
74 
75  // indent multiline values, first print_r, split in lines,
76  // indent all but first line, then implode again.
77  $first = true;
78  $indentation = str_pad("", self::KEY_SPACE);
79  $value = implode("\n", array_map(function($line) use (&$first, $indentation) {
80  if ($first) {
81  $first = false;
82  return $line;
83  }
84  return $indentation.$line;
85  }, explode("\n", print_r($value, true))));
86 
87  $ret .= "$key: $value\n";
88  }
89  }
90  else {
91  $ret .= "empty\n";
92  }
93  }
94  return $ret;
95  }
96 
102  protected function tables() {
103  $post = $_POST;
104  $server = $_SERVER;
105 
106  $post = $this->hidePassword($post);
108 
109  return array
110  ( "GET Data" => $_GET
111  , "POST Data" => $post
112  , "Files" => $_FILES
113  , "Cookies" => $_COOKIE
114  , "Session" => isset($_SESSION) ? $_SESSION : array()
115  , "Server/Request Data" => $server
116  , "Environment Variables" => $_ENV
117  );
118  }
119 
127  private function hidePassword(array $post) {
128  if(isset($post["password"])) {
129  $post["password"] = "REMOVED FOR SECURITY";
130  }
131 
132  return $post;
133  }
134 
142  private function shortenPHPSessionId(array $server) {
143  $cookie_content = $server["HTTP_COOKIE"];
144  $cookie_content = explode(";", $cookie_content);
145 
146  foreach ($cookie_content as $key => $content) {
147  $content_array = explode("=", $content);
148  if(trim($content_array[0]) == session_name()) {
149  $content_array[1] = substr($content_array[1], 0, 5)." (SHORTENED FOR SECURITY)";
150  $cookie_content[$key] = implode("=", $content_array);
151  }
152  }
153 
154  $server["HTTP_COOKIE"] = implode(";", $cookie_content);
155 
156  return $server;
157  }
158 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
hidePassword(array $post)
Replace passwort from post array with security message.
$_SESSION["AccountId"]
handle()
Last missing method from HandlerInterface.
$_GET["client_id"]
tablesContent()
Get the header for the page.
shortenPHPSessionId(array $server)
Shorts the php session id.
exceptionContent()
Get a short info about the exception.
tables()
Get the tables that should be rendered.
pageHeader()
Get the header for the page.
Add a drawing to the header
Definition: 04printing.php:69
Create styles array
The data for the language used.
Abstract implementation of a Handler.
Definition: Handler.php:15
$server
$ret
Definition: parser.php:6
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
content()
Assemble the output for this handler.
$_POST["username"]