The current code for PIDF aggregation produces invalid documents (ie they don't validate) mainly due to the ordering of XML elements in the resulting document. There is also no way to prevent OpenSIPS from automatically generating a PIDF when a PUBLISH with Expires: 0 is received.
The attached patch adds a new modparam to presence_xml 'generate_offline_body' (enabled by default) to control if offline PIDFs should be generated automatically. It also refactors the way PIDFs are aggregated to ensure the order is correct and duplicates are pruned.
Since the patch is quite big, I'll send an email to the -dev mailing list with a detailed explanation of the issues I discovered and how the patch addresses them.
Saúl Ibarra Corretgé