<?php
echo "<div class=\"quote_container\">\n";
$safe_m_link = $m_link ?? '';
$quote_link = str_replace('index.php?m=', 'miters/', $safe_m_link);
$quote_link = $quote_link . '.txt';
if (file_exists($quote_link)) {
$quote_arc = file($quote_link, FILE_IGNORE_NEW_LINES);
$quote_data = $quote_arc[0] ?? '';
$quote_link = $quote_arc[1] ?? '';
$quote_img = $quote_arc[2] ?? '';
$quote_keys = $quote_arc[3] ?? '';
$quote_odate = $quote_arc[4] ?? '';
$quote_gdate = $quote_arc[5] ?? '';
$quote_udate = $quote_arc[6] ?? '';
$quote = htmlspecialchars($quote_data, ENT_QUOTES, 'UTF-8');
$quote = str_replace(''', '\'', $quote); // dumb solution
$quote = str_replace(['<br>', '<br />'], '<br>', $quote);
$quote = preg_replace('/(?<!\w)#([0-9a-zA-Z]+)/m', '<a href="index.php?q=$1">#$1</a>', $quote);
$quote = preg_replace('#\[b\](.*?)\[/b\]#', '<b>$1</b>', $quote);
$quote = preg_replace('#\[i\](.*?)\[/i\]#', '<i>$1</i>', $quote);
$quote = preg_replace('#\[u\](.*?)\[/u\]#', '<u>$1</u>', $quote);
$quote = preg_replace('#\[s\](.*?)\[/s\]#', '<s>$1</s>', $quote);
$quote = preg_replace('#\[img\](.*?)\[/img\]#', '<a href="$1" target="_blank"><img src="$1"></a>', $quote);
$quote = preg_replace('#\[url\](.*?)\[/url\]#', '<a href="$1" target="_blank">$1</a>', $quote);
$quote = str_replace('[hr]', '<hr />', $quote);
if (substr($quote, 0, 4) === '>') {
$quote = preg_replace('/>([^<]*)/m', '<span class="green_text">>$1</span>', $quote, 1);
}
$quote = preg_replace('/<br \/>>([^<]*)/m', '<br><span class="green_text">>$1</span>', $quote);
$quote_url_scheme = parse_url($safe_m_link, PHP_URL_SCHEME);
$quote_url_host = parse_url($safe_m_link, PHP_URL_HOST);
$quote_user_file = $quote_url_scheme . '://' . $quote_url_host . '/user/user.xml';
$quote_user_username = '';
if (file_exists($quote_user_file)) {
$quote_user_get = simplexml_load_file($quote_user_file);
if ($quote_user_get !== false) {
$quote_user_array = $quote_user_get->xpath("/miter/user[@id='probe']");
if (!empty($quote_user_array)) {
$quote_user_username = (string)$quote_user_array[0]->name;
}
}
}
$safe_username = htmlspecialchars($quote_user_username, ENT_QUOTES, 'UTF-8');
echo "<span class=\"name\">{$safe_username} ";
$q_start = new DateTime('now');
$q_end = new DateTime($quote_gdate);
$q_dif = $q_start->diff($q_end);
if ($q_dif->days < 1) {
$q_since = ($q_dif->h < 1) ? $q_dif->i . "m" : $q_dif->h . "h";
} else {
if ($q_dif->days > 365) {
$q_y = floor($q_dif->days / 365);
$q_y_d = $q_dif->days % 365;
$q_since = $q_y . 'y ' . $q_y_d . 'd';
} else {
$q_since = $q_dif->days . 'd';
}
}
echo "· {$q_since}</span><br>\n";
echo "<div class=\"space_name\"></div>\n";
echo "<span class=\"miter_text\">{$quote}</span><br>\n";
echo "<div class=\"date_table-div\">\n";
$safe_link = htmlspecialchars($safe_m_link, ENT_QUOTES, 'UTF-8');
$safe_odate = htmlspecialchars($quote_odate, ENT_QUOTES, 'UTF-8');
echo "<a href=\"{$safe_link}\" target=\"_blank\" class=\"permalink\">{$safe_odate}";
if ($quote_udate > $quote_gdate) {
echo " ±";
}
echo "</a>\n";
echo "</div>\n";
} else {
echo "<span class=\"grey\">miter no longer exists</span>\n";
}
echo "</div>\n";
?>