Cleanup of unused variables

Tracker ID: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30479

The php code is riddled with variables that are not being used. Probably left-overs from old and removed code. Or simply bad programming practises (like initializing the variable when it is always set in later code).

Anyway, this PR removes the bulk of those unused (memory/resource/time-hogging) variables.

Changes this PR brings:
- Removal of unused variables
- Some syntax cleanup
- Some fixes in the tests (to deal with syntax cleanup)

#### Testing instructions
This probably just needs the general system tests to see if it doesn't break anything.