add links to calendar and plain text on html page
[bdrem.git] / src / bdrem / Renderer / Html.php
1 <?php
2 /**
3  * Part of bdrem
4  *
5  * PHP version 5
6  *
7  * @category  Tools
8  * @package   Bdrem
9  * @author    Christian Weiske <cweiske@cweiske.de>
10  * @copyright 2014 Christian Weiske
11  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12  * @link      http://cweiske.de/bdrem.htm
13  */
14 namespace bdrem;
15
16 /**
17  * HTML page renderer. Renders a full HTML page.
18  *
19  * @category  Tools
20  * @package   Bdrem
21  * @author    Christian Weiske <cweiske@cweiske.de>
22  * @copyright 2014 Christian Weiske
23  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24  * @version   Release: @package_version@
25  * @link      http://cweiske.de/bdrem.htm
26  */
27 class Renderer_Html extends Renderer
28 {
29     /**
30      * HTTP content type
31      * @var string
32      */
33     protected $httpContentType = 'application/xhtml+xml; charset=utf-8';
34
35     /**
36      * Send out HTTP headers when nothing shall be outputted.
37      *
38      * @return void
39      */
40     public function handleStopOnEmpty()
41     {
42         header('HTTP/1.0 204 No Content');
43     }
44
45     /**
46      * Generate a HTML page with the given events.
47      *
48      * @param array $arEvents Events to display on the HTML page
49      *
50      * @return string HTML code
51      *
52      * @see Renderer_HtmlTable
53      */
54     public function render($arEvents)
55     {
56         $links = '';
57         if (isset($_SERVER['HTTP_HOST'])) {
58             $links = '  <link rel="alternate" type="text/calendar" href="'
59                 . $_SERVER['REQUEST_SCHEME'] . '://'
60                 . $_SERVER['HTTP_HOST']
61                 . preg_replace('#\?.+$#', '', $_SERVER['REQUEST_URI'])
62                 . '?renderer=ical'
63                 . '"/>'
64                 . "\n";
65             $links .= '  <link rel="alternate" type="text/plain" href="'
66                 . $_SERVER['REQUEST_SCHEME'] . '://'
67                 . $_SERVER['HTTP_HOST']
68                 . preg_replace('#\?.+$#', '', $_SERVER['REQUEST_URI'])
69                 . '?renderer=console'
70                 . '"/>'
71                 . "\n";
72         }
73
74         $tr = new Renderer_HtmlTable();
75         $table = $tr->render($arEvents);
76         $s = <<<HTM
77 <?xml version="1.0" encoding="utf-8"?>
78 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
79  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
80 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
81  <head>
82   <title>bdrem</title>
83   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
84 $links  <style type="text/css">
85 table {
86     border: 1px solid black;
87     border-collapse: collapse;
88     margin-left: auto;
89     margin-right: auto;
90 }
91 td, th {
92     border: 1px solid grey;
93     border-left: 0px;
94     border-right: 0px;
95     padding: 0.1ex 1ex;
96 }
97
98 tr.prev td {
99     background-color: #C4DDF4;
100 }
101 tr.today td {
102     background-color: #FEDCBA;
103 }
104 tr.next td {
105     background-color: #DEFABC;
106 }
107 tr:hover td {
108     background-color: white;
109 }
110
111 .r {
112     text-align: right;
113 }
114
115 tr td.icon {
116     background-color: white;
117 }
118 tr.prev td.icon {
119     color: #00A;
120 }
121 tr.today td.icon {
122     color: black;
123     background-color: #FEDCBA;
124 }
125 tr.next td.icon {
126     color: #080;
127 }
128
129 tr.d-3 td.icon:before {
130     content: "\342\227\224"
131 }
132 tr.d-2 td.icon:before {
133     content: "\342\227\221"
134 }
135 tr.d-1 td.icon:before {
136     content: "\342\227\225"
137 }
138 tr.d0 td.icon:before {
139     content: "\342\230\205"
140 }
141 tr.d1 td.icon:before {
142     content: "\342\227\225"
143 }
144 tr.d2 td.icon:before {
145     content: "\342\227\221"
146 }
147 tr.d3 td.icon:before {
148     content: "\342\227\224"
149 }
150   </style>
151  </head>
152  <body>
153 $table
154  </body>
155 </html>
156 HTM;
157         return $s;
158     }
159 }
160 ?>