Lines 86 - 93:
if ($mode == 'window')
It is not possible to ORDER BY with group functions.
Fix: Replace ORDER BY MIN(smiley_order) with ORDER BY smiley_order
you could select MIN(smiley_order) AS min_smiley_order and afterwards ORDER BY min_smiley_order.
But that's not interesting here.
We just want to get those smileys ordered