--- /dev/null
+{% if commentRow.rc_author_image %}<img src="{{commentRow.rc_author_image}}" alt="Avatar for {{commentRow.rc_author_name}}" style="max-width: 48px; max-height: 48px"/>{% endif %}
+
+{% if linkRow.rc_author_url %}<a href="{{linkRow.rc_author_url}}">{% endif %}
+{{commentRow.rc_author_name}}
+{% if linkRow.rc_author_url %}</a>{% endif %}
+
+<div>
+ {% if commentRow.rc_title %}<h3>{{commentRow.rc_title}}</h3>{% endif %}
+ {{commentRow.rl_comment|raw}}
+</div>
--- /dev/null
+<a href="{{linkRow.rl_source}}">{{linkRow.rl_title}}</a>
+{% if linkRow.rl_author_name %}
+ by
+ {% if linkRow.rl_author_url %}<a href="{{linkRow.rl_author_url}}">{% endif %}
+ {{linkRow.rl_author_name}}
+ {% if linkRow.rl_author_url %}</a>{% endif %}
+{% endif %}
--- /dev/null
+{% if arData.comments %}
+<h3 id="m-comments">Comments</h3>
+<ul class="m-container m-comments">
+ {% for commentRow in arData.comments %}
+ {% include 'mentions-comment.htm' %}
+ {% endfor %}
+</ul>
+{% endif %}
+
+{% if arData.links %}
+<h3 id="m-links">Links to this page</h3>
+<ul class="m-container m-links">
+ {% for linkRow in arData.links %}
+ <li>{% include 'mentions-link.htm' %}</li>
+ {% endfor %}
+</ul>
+{% endif %}
--- /dev/null
+<?php
+namespace stapibas;
+
+class Renderer_Html
+{
+ public $db;
+ public $log;
+
+ public function __construct(Dependencies $deps)
+ {
+ $this->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);
+ }
+
+}
+?>
--- /dev/null
+<?php
+namespace stapibas;
+/**
+ * Render the bookmarks/comments/links for a given URL
+ *
+ * @param string $url URL to get content for
+ */
+header('HTTP/1.0 500 Internal Server Error');
+header('Content-type: text/plain');
+
+require_once __DIR__ . '/../data/config.php';
+require_once 'stapibas/autoloader.php';
+
+if (!isset($_GET['url'])) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "HTTP POST 'url' parameter missing\n";
+ exit(1);
+}
+$url = $_GET['url'];
+if ($url === '') {
+ header('HTTP/1.0 400 Bad Request');
+ echo "'url' parameter is empty\n";
+ exit(1);
+}
+if (filter_var($url, FILTER_VALIDATE_URL) === false) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Invalid URL given\n";
+ exit(1);
+}
+
+
+$deps = new Dependencies();
+$deps->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);
+?>