Improvements to widgets.php

* Better defaults
* Improved sercurity
* Removed unnecessary typecasting
* Make sure a 1 or 0 is always saved to the db
Improvements to classes.php

* Improve query building logic
* Improve query sanitization