Check out the available social network frameworks out there. I googled the term and immediately found this promising one:
http://www.anahitapolis.com/
I'm not endorsing it, I know nothing about it; I'm sharing the link only as an example of what you might find and use as a foundation for your project. No sense in re-inventing the wheel.