Make CSS inline in HTML mails
[bdrem.git] / src / bdrem / Renderer / Html.php
index 637a8389d1599bfb23b68f8670589284641cbdd5..10059ab80b723453d69a5b137389307ac608f92a 100644 (file)
 <?php
+/**
+ * Part of bdrem
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Bdrem
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/bdrem.htm
+ */
 namespace bdrem;
 
+/**
+ * HTML page renderer. Renders a full HTML page.
+ *
+ * @category  Tools
+ * @package   Bdrem
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version   Release: @package_version@
+ * @link      http://cweiske.de/bdrem.htm
+ */
 class Renderer_Html extends Renderer
 {
+    /**
+     * HTTP content type
+     * @var string
+     */
     protected $httpContentType = 'application/xhtml+xml; charset=utf-8';
 
+    /**
+     * Send out HTTP headers when nothing shall be outputted.
+     *
+     * @return void
+     */
     public function handleStopOnEmpty()
     {
         header('HTTP/1.0 204 No Content');
     }
 
+    /**
+     * Generate a HTML page with the given events.
+     *
+     * @param array $arEvents Events to display on the HTML page
+     *
+     * @return string HTML code
+     *
+     * @see Renderer_HtmlTable
+     */
     public function render($arEvents)
     {
+        $links = '';
+        if (isset($_SERVER['HTTP_HOST'])) {
+            if (!isset($_SERVER['REQUEST_SCHEME'])) {
+                $_SERVER['REQUEST_SCHEME'] = 'http';
+            }
+            $links = '  <link rel="alternate" type="text/calendar" href="'
+                . $_SERVER['REQUEST_SCHEME'] . '://'
+                . $_SERVER['HTTP_HOST']
+                . preg_replace('#\?.+$#', '', $_SERVER['REQUEST_URI'])
+                . '?renderer=ical'
+                . '"/>'
+                . "\n";
+            $links .= '  <link rel="alternate" type="text/plain" href="'
+                . $_SERVER['REQUEST_SCHEME'] . '://'
+                . $_SERVER['HTTP_HOST']
+                . preg_replace('#\?.+$#', '', $_SERVER['REQUEST_URI'])
+                . '?renderer=console'
+                . '"/>'
+                . "\n";
+        }
+
         $tr = new Renderer_HtmlTable();
         $table = $tr->render($arEvents);
+        $css = static::getCss();
         $s = <<<HTM
 <?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
   <title>bdrem</title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-  <style type="text/css">
+$links  <style type="text/css">$css</style>
+ </head>
+ <body>
+$table
+ </body>
+</html>
+HTM;
+        return $s;
+    }
+
+    /**
+     * Get the CSS for the HTML table
+     */
+    public static function getCss()
+    {
+        return <<<CSS
 table {
     border: 1px solid black;
     border-collapse: collapse;
@@ -87,14 +166,7 @@ tr.d2 td.icon:before {
 tr.d3 td.icon:before {
     content: "\342\227\224"
 }
-  </style>
- </head>
- <body>
-$table
- </body>
-</html>
-HTM;
-        return $s;
+CSS;
     }
 }
 ?>