[SUCS Devel] [Git][sucssite/sucs-site][sucs-site] 3 commits: Fix motd generation

Imran Hussain imranh at sucs.org
Thu Jan 24 12:02:39 GMT 2019


Imran Hussain pushed to branch sucs-site at sucssite / sucs-site


Commits:
4f5034e7 by Imran Hussain at 2019-01-24T11:53:21Z
Fix motd generation

- - - - -
51e49732 by Imran Hussain at 2019-01-24T11:58:25Z
Merge branch 'master' into 'beta'

Fix motd generation

See merge request sucssite/sucs-site!101
- - - - -
52425b80 by Imran Hussain at 2019-01-24T12:02:35Z
Merge branch 'beta' into 'sucs-site'

Beta to live!

See merge request sucssite/sucs-site!102
- - - - -


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/compare/61bf50a5f9b14716391851004119e2c0979c47ad...52425b803ba0bfb4335317a891c570237f0bdd8f

-- 
View it on GitLab: https://projects.sucs.org/sucssite/sucs-site/compare/61bf50a5f9b14716391851004119e2c0979c47ad...52425b803ba0bfb4335317a891c570237f0bdd8f
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/da0a6f97/attachment-0001.html>


More information about the Devel mailing list