Refactored code and stopped unauthorized users from seeing posts directly.

Refactored code to make it simpler and renamed functions to make sense.

Added restrictions on view of posts if they are viewed directly. Still
need to restrict viewing of posts on the main screens and search etc.