select c.* from content c
join content_share cs on cs.content_id = c.id
where cs.user_id = 0 or cs.user_id = ? /* anyone or me */
union
select c.* from content c
join content_share cs on cs.content_id = c.id
join user_friend uf on c.user_id = uf.user_id
where cs.user_id = -1 /* friends */
and uf.friend_user_id = ?