[ticket/13163] Fix responsive link lists

Rewrote the entire function, because it was incomprehensible spaghetti and a major resource hog (partly my own fault).

https://tracker.phpbb.com/browse/PHPBB3-13163