Numerous fixes

This PR fixes problems with sending newsletters as well as fixing errors in PHP 5.4+.

I have also added queries to add settings on install and some uninstall logic as they were missing.

There is also a fix for a query conflict when getting settings from within a query.