Fixes custom SQL query rewriting in PodsData->build()

This fixes the handling of the `sql` parameter in `PodsData->build()`.

A quick overview of the fixes:
* The `sql` parameter was prematurely rejected, rendering most of the rewriting logic unused. This was caused by an incorrect check.
* Instead of treating the custom query as a 'special case', the default query is now the special case. When `sql` is null, a [default custom query](https://github.com/MattiasBuelens/pods/blob/cb9aaa96ea7462b124844282a2c5941edf635fd2/classes/PodsData.php#L1067) is used containing the default placements for all query parts.
* The `$this->total_sql` is now produced during the rewriting. It only differs from `$sql` in the `SELECT` and `LIMIT` clauses, so the handling of those two is postponed until the end of the process.
 * `$sql` receives the actual `$params->select` and `LIMIT`.
 * `$this->total_sql` receives `COUNT(*)` without a `LIMIT`.
* Since the rewriting logic was never actually used, it had a few bugs:
 * `$params->sql` instead of `$this->sql` has to be the source of the rewriting process.
 * The `/g` flag in `preg_replace` is unnecessary and deprecated.
 * A copy-paste typo caused `$params->having` being inserted in the `ORDER BY` clause.

This is a rewrite of #922 for the new 2.3 code base. The diffs are much better now as well! :wink: