Whitespace/code cleanup

* add limits and no_count_rows to optimize queries
* add some missing output escaping
* change some spaces to tabs, some remain
* add coding standards spacing to JS as well
* cast post id as (int) to avoid XSS vector