<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
class Replacement
{
public static function getPR($tagChildren, $tagOption, $tag, array $options/*, \XFBbCode\Renderer\AbstractRenderer $renderer*/)
{
$pr_id = $tag;//259851; //TODO: get from a parameter. But which one?
$url = "https://bugs.freebsd.org/bugzilla/";
$bug_data = null;
// if (false) // true if file_get_contents should be used, false if cURL should be used
// {
$context = stream_context_create(array('http' => array('method'=>'GET', 'header'=>'Connection: close\r\n')));
$bug_data = json_decode(file_get_contents("${url}rest/bug/${pr_id}?include_fields=summary,status,component,resolution,creator", false, $context));
// }
// else
// {
// $timeout = 5;
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, "${url}rest/bug/${pr_id}?include_fields=summary,status,component,resolution,creator");
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// $bug_data = json_decode(curl_exec($ch));
// curl_close($ch);
// }
$html = $pr_id;
if ($bug_data !== null)
{
$summary = htmlentities($bug_data->bugs[0]->summary, ENT_QUOTES, "UTF-8");
$status = htmlentities($bug_data->bugs[0]->status, ENT_QUOTES, "UTF-8");
$component = htmlentities($bug_data->bugs[0]->component, ENT_QUOTES, "UTF-8");
$resolution = htmlentities($bug_data->bugs[0]->resolution, ENT_QUOTES, "UTF-8");
$creator = htmlentities($bug_data->bugs[0]->creator, ENT_QUOTES, "UTF-8");
// add link
$html = "<a class=\"pr_popup\" target=\"_blank\" title=\"Problem report\" href=\"${url}show_bug.cgi?id=${pr_id}\">PR: ${summary}</a>";
// add popup (initially hidden)
$html .= "<div class=\"pr_popup\"><ul><li>Status: ${status}</li><li>Component: ${component}</li><li>Resolution: ${resolution}</li><li>Creator: ${creator}</li></ul></div>";
// add CSS TODO: make pretty
$html .= "<style>
div.pr_popup { display: none; border: 1px solid black; background-color: #ffe6e6; padding: 4px; position: absolute; }
div.pr_popup ul { list-style-type: none; margin: 0; padding:0; }
a.pr_popup:hover + div.pr_popup { display: block; }
</style>";
}
return $html;
}
}
// These are dummies, XenForo will pass them to the replacement function
$tagChildren = null;
$tagOption = null;
$tag = null;
$options = array();
$renderer = null;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PR test</title>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<div><?php echo Replacement::getPR($tagChildren, $tagOption, 259851, $options/*, $renderer*/); ?></div>
<div><?php echo Replacement::getPR($tagChildren, $tagOption, 259852, $options/*, $renderer*/); ?></div>
</body>
</html>