several fixes to the code - most were uncovered in PHP 5.4.x STRICT mode

See the commit messages for what was observed and fixed in each commit.

All these were needed to have kisscms render the site.

OT/aside: the 'require.js loaded too late' problem is filed in a separate issue as you might be quicker at fixing that bugger than me as I'd have to dig through the PHP DOM editing code AFAICT.