Changed to proper layout setter.
Fixed tag_subs.tag_query charset.
Couple changes to generate_preview().
 * Now accepts $force_regen option.
 * Calling tempfile_path()  would cause an error.
 * Changed file_exists() for is_file().
Changed purge_tags().
Tag purging was done directly to the database, leaving the tags' history entries orphan.