Update phing build script to use composer installation only
[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             if (!isset($_SERVER['REQUEST_SCHEME'])) {
59                 $_SERVER['REQUEST_SCHEME'] = 'http';
60             }
61             $links = '  <link rel="alternate" type="text/calendar" href="'
62                 . $_SERVER['REQUEST_SCHEME'] . '://'
63                 . $_SERVER['HTTP_HOST']
64                 . preg_replace('#\?.+$#', '', $_SERVER['REQUEST_URI'])
65                 . '?renderer=ical'
66                 . '"/>'
67                 . "\n";
68             $links .= '  <link rel="alternate" type="text/plain" href="'
69                 . $_SERVER['REQUEST_SCHEME'] . '://'
70                 . $_SERVER['HTTP_HOST']
71                 . preg_replace('#\?.+$#', '', $_SERVER['REQUEST_URI'])
72                 . '?renderer=console'
73                 . '"/>'
74                 . "\n";
75         }
76
77         $tr = new Renderer_HtmlTable();
78         $table = $tr->render($arEvents);
79         $css = static::getCss();
80         $s = <<<HTM
81 <?xml version="1.0" encoding="utf-8"?>
82 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
83  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
84 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
85  <head>
86   <title>bdrem</title>
87   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
88 $links  <style type="text/css">$css</style>
89  </head>
90  <body>
91 $table
92  </body>
93 </html>
94 HTM;
95         return $s;
96     }
97
98     /**
99      * Get the CSS for the HTML table
100      */
101     public static function getCss()
102     {
103         return <<<CSS
104 table {
105     border: 1px solid black;
106     border-collapse: collapse;
107     margin-left: auto;
108     margin-right: auto;
109 }
110 td, th {
111     border: 1px solid grey;
112     border-left: 0px;
113     border-right: 0px;
114     padding: 0.1ex 1ex;
115 }
116
117 tr.prev td {
118     background-color: #C4DDF4;
119 }
120 tr.today td {
121     background-color: #FEDCBA;
122 }
123 tr.next td {
124     background-color: #DEFABC;
125 }
126 tr:hover td {
127     background-color: white;
128 }
129
130 .r {
131     text-align: right;
132 }
133
134 tr td.icon {
135     background-color: white;
136 }
137 tr.prev td.icon {
138     color: #00A;
139 }
140 tr.today td.icon {
141     color: black;
142     background-color: #FEDCBA;
143 }
144 tr.next td.icon {
145     color: #080;
146 }
147
148 tr.d-3 td.icon:before {
149     content: "\342\227\224"
150 }
151 tr.d-2 td.icon:before {
152     content: "\342\227\221"
153 }
154 tr.d-1 td.icon:before {
155     content: "\342\227\225"
156 }
157 tr.d0 td.icon:before {
158     content: "\342\230\205"
159 }
160 tr.d1 td.icon:before {
161     content: "\342\227\225"
162 }
163 tr.d2 td.icon:before {
164     content: "\342\227\221"
165 }
166 tr.d3 td.icon:before {
167     content: "\342\227\224"
168 }
169 CSS;
170     }
171 }
172 ?>