[SUCS Devel] [Git][sucssite/sucs-site][master] Fix motd generation
Imran Hussain
imranh at sucs.org
Thu Jan 24 11:53:50 GMT 2019
Imran Hussain pushed to branch master at sucssite / sucs-site
Commits:
4f5034e7 by Imran Hussain at 2019-01-24T11:53:21Z
Fix motd generation
- - - - -
1 changed file:
- components/motd.php
Changes:
=====================================
components/motd.php
=====================================
@@ -3,16 +3,21 @@ $motd_file = "/etc/motd";
function decode_entities($text, $quote_style = ENT_COMPAT)
{
- if (function_exists('html_entity_decode')) {
- $text = html_entity_decode($text, $quote_style, 'ISO-8859-1'); // NOTE: UTF-8 does not work!
- } else {
- $trans_tbl = get_html_translation_table(HTML_ENTITIES, $quote_style);
- $trans_tbl = array_flip($trans_tbl);
- $text = strtr($text, $trans_tbl);
- }
- $text = preg_replace('~&ndash\;~i', '-', $text);
- $text = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $text);
- $text = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $text);
+ $text = html_entity_decode($text, $quote_style, 'ISO-8859-1'); // NOTE: UTF-8 does not work!
+ $text = preg_replace_callback('~&#x([0-9a-f]+);~i',
+ function ($matches) {
+ foreach ($matches as $match) {
+ return chr(hexdec($match));
+ }
+ },
+ $text);
+ $text = preg_replace_callback('~&#([0-9]+);~',
+ function ($matches) {
+ foreach ($matches as $match) {
+ return chr($match);
+ }
+ },
+ $text);
return $text;
}
@@ -52,7 +57,12 @@ for ($i = count($news) - 1; $i > -1; $i--) {
$body = str_replace("…", "...", $body);
$body = str_replace("'", "'", $body);
// remove hyperlinks, collect to display later
- $body = preg_replace(":<a href=['\"](.+?)['\"].*?>(.*?)</a>:e", "'\\2['.linkcounter('\\1').']'", $body);
+ $body = preg_replace_callback(":<a href=['\"](.+?)['\"].*?>(.*?)</a>:",
+ function ($matches) {
+ $i = linkcounter($matches[1]);
+ return $matches[0]."[".$i."]";
+ },
+ $body);
$body = strip_tags($body);
$body = decode_entities($body);
$body = wordwrap($body, 75, "\n ", 1);
@@ -76,9 +86,11 @@ for ($i = count($news) - 1; $i > -1; $i--) {
}
$motd .= "---------------------------- [ http://sucs.org/ ] -----------------------------\n";
+//print($motd);
+
//if (time()-filemtime($motd_file) < 86000 && $poemmode == 1) { //86000 to allow a little slack depending on when cron runs
// print "MOTD too recent to replace with a poem!\n";
//} else {
file_put_contents($motd_file, $motd);
//}
-?>
+?>
\ No newline at end of file
View it on GitLab: https://projects.sucs.org/sucssite/sucs-site/commit/4f5034e7edf8614dd8ab69c88fc5daea72afa53e
--
View it on GitLab: https://projects.sucs.org/sucssite/sucs-site/commit/4f5034e7edf8614dd8ab69c88fc5daea72afa53e
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20190124/4d7296c7/attachment-0001.html>
More information about the Devel
mailing list