From 30e47dacbaf39b237c6e301810dce148bb768154 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 19 Jun 2013 23:55:52 +0200 Subject: [PATCH] first work on rendering --- data/templates/default/mentions-comment.htm | 10 +++ data/templates/default/mentions-link.htm | 7 ++ data/templates/default/mentions.htm | 17 +++++ src/stapibas/Renderer/Html.php | 78 +++++++++++++++++++++ www/render.php | 41 +++++++++++ 5 files changed, 153 insertions(+) create mode 100644 data/templates/default/mentions-comment.htm create mode 100644 data/templates/default/mentions-link.htm create mode 100644 data/templates/default/mentions.htm create mode 100644 src/stapibas/Renderer/Html.php create mode 100644 www/render.php diff --git a/data/templates/default/mentions-comment.htm b/data/templates/default/mentions-comment.htm new file mode 100644 index 0000000..929f144 --- /dev/null +++ b/data/templates/default/mentions-comment.htm @@ -0,0 +1,10 @@ +{% if commentRow.rc_author_image %}Avatar for {{commentRow.rc_author_name}}{% endif %} + +{% if linkRow.rc_author_url %}{% endif %} +{{commentRow.rc_author_name}} +{% if linkRow.rc_author_url %}{% endif %} + +
+ {% if commentRow.rc_title %}

{{commentRow.rc_title}}

{% endif %} + {{commentRow.rl_comment|raw}} +
diff --git a/data/templates/default/mentions-link.htm b/data/templates/default/mentions-link.htm new file mode 100644 index 0000000..7dfad64 --- /dev/null +++ b/data/templates/default/mentions-link.htm @@ -0,0 +1,7 @@ +{{linkRow.rl_title}} +{% if linkRow.rl_author_name %} + by + {% if linkRow.rl_author_url %}{% endif %} + {{linkRow.rl_author_name}} + {% if linkRow.rl_author_url %}{% endif %} +{% endif %} diff --git a/data/templates/default/mentions.htm b/data/templates/default/mentions.htm new file mode 100644 index 0000000..7f57d32 --- /dev/null +++ b/data/templates/default/mentions.htm @@ -0,0 +1,17 @@ +{% if arData.comments %} +

Comments

+ +{% endif %} + +{% if arData.links %} + + +{% endif %} diff --git a/src/stapibas/Renderer/Html.php b/src/stapibas/Renderer/Html.php new file mode 100644 index 0000000..ca26584 --- /dev/null +++ b/src/stapibas/Renderer/Html.php @@ -0,0 +1,78 @@ +deps = $deps; + $this->db = $deps->db; + $this->log = $deps->log; + + \Twig_Autoloader::register(); + $loader = new \Twig_Loader_Filesystem($this->deps->options['template_dir']); + $this->deps->twig = new \Twig_Environment( + $loader, + array( + //'cache' => '/path/to/compilation_cache', + 'debug' => true + ) + ); + } + + public function render($url) + { + $arData = $this->loadData($url); + header('Content-type: text/html'); + $this->renderHtml('mentions', array('arData' => $arData)); + } + + /** + * Fetches all bookmarks, comments and links + */ + protected function loadData($url) + { + $arData = array( + 'bookmarks' => array(), + 'comments' => array(), + 'links' => array(), + ); + + $stmt = $this->db->query( + 'SELECT * FROM pingbacks, rbookmarks' + . ' WHERE p_id = rb_p_id AND p_use = 1' + . ' AND p_target = ' . $this->db->quote($url) + . ' ORDER BY p_time ASC' + ); + $arData['bookmarks'] = $stmt->fetchAll(); + + $stmt = $this->db->query( + 'SELECT * FROM pingbacks, rcomments' + . ' WHERE p_id = rc_p_id AND p_use = 1' + . ' AND p_target = ' . $this->db->quote($url) + . ' ORDER BY p_time ASC' + ); + $arData['comments'] = $stmt->fetchAll(); + + $stmt = $this->db->query( + 'SELECT * FROM pingbacks, rlinks' + . ' WHERE p_id = rl_p_id AND p_use = 1' + . ' AND p_target = ' . $this->db->quote($url) + . ' ORDER BY p_time ASC' + ); + $arData['links'] = $stmt->fetchAll(); + + return $arData; + } + + protected function renderHtml($tplname, $vars = array()) + { + $template = $this->deps->twig->loadTemplate($tplname . '.htm'); + echo $template->render($vars); + } + +} +?> diff --git a/www/render.php b/www/render.php new file mode 100644 index 0000000..e460b42 --- /dev/null +++ b/www/render.php @@ -0,0 +1,41 @@ +db = new PDO($dbdsn, $dbuser, $dbpass); +$deps->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +$deps->options = array( + 'template_dir' => __DIR__ . '/../data/templates/default/' +); + +$r = new Renderer_Html($deps); +echo $r->render($url); +?> -- 2.30.2