开发者

What is the best approach for storing YouTube content appended to user contributed content?

So I'm trying to implement similar functionality to Facebook where I am including information from YouTube should a users post contain a li开发者_开发知识库nk, and when clicked it embeds the video.

I've accomplished it thus far, I'm just wondering how Facebook stores this information.

To me there are two options:

1) Have the post saved as normal (it is just plain text), and if the post contains a youtube link, append it on the fly in JavaScript whenever that content is viewed. However I know that when you post a link, Facebook gives you the option to change the title, description etc. Which leads me to..

2) Generate the HTML that would be otherwise appended when viewed and store it alongside the post at the database-insert level.

If so, doesnt that add a significant amount of information per post? What happens if you want to change the formatting of all youtube content within posts on your site later on? Each will be stored individually and seems like it would be a pain.

What is the best way to manage & engineer this sort of functionality?

Cheers,


I'd store the information itself in the database, but not as HTML. Generate the HTML on the fly but store the data in a separate place. If you don't want to add too many extra database fields consider storing the information in some serialized form (like serialize() in PHP).

Anyway I would always keep information separated and never store auto-generated HTML unless it's some sort of cache that can be re-generated.


If you want the user to include his video within his text, store the link in HTML within that user's intervention, and output it as is from the database on the page. Then your users can edit their posts to decide whether to place the video before, after, in the middle or not at all, and can change the details in HTML.

If you are showing the video in some standard way, then store the video link along with the post in a separate database column, and generate the HTML on the fly. You can have data in columns for size, colour etc..., but the flexibility will always be limited to what you decide to store: if there is a database coloumn for colour then you are letting the user choose the colour, otherwise... not.

So, the most flexible is to let your users type HTML. If you think they aren't up to it, or you want to limit their choices of what they can format, you could use a java(script) rich text editor of the type that you have in stackoverflow, wikipedia etc., with possibilities to edit text in certain chosen ways via buttons. You could also store the post in XML, say in a chosen subset of HTML5 (anything that is valid in a certain container...), and transform it at presentation time.


to me this sounds like a problem that was taken too far. if you implement ckeditor in your post form, it should resolve the problem ( if i understood it right ), since in ckeditor you can embed an swf/flv, and the output will be html.

that gives the editor the power to decide exactly where he want the video ( since he can add the link wherever he wants in the form ).

since the flv/swf come with its meta data from youtube, you dont need to save that data, just the link to the video.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜