In this article I will try to briefly tell you about building an analogue of Livestreet based on XenForo. The entire social network is a plug-in for XenForo called Social.
An overview of the engine architecture and the
basics of plug- in
descriptions are described in the
FractalizeR articles.
After analyzing the architecture of XenForo, we realized that there are not so many fundamental differences between the forum and blogs. Indeed, the first message of the topic easily turns into an article, and the rest of the messages - into comments. Certain sections of the forum can be turned into blogs.
I will list the main advantages of this solution.
- Built forum.
- Ready system bbkodov and message handling.
- Transformations of articles into topics, and topics into articles by moving to the desired section.
- The plugin code is very compact.
Of course, this approach has its drawbacks.
- For the proper separation of the functional, I had to examine the engine completely.
- Less leeway because articles expand topics.
In general, the idea that any discussion is a topic seemed to us very logical. The separation of topics and articles in the end was not so difficult. Now about the main points of the technical implementation of the plugin.
Blogs
Make the
socialBlogRoot
setting, which defines the parent node for all blogs. Those. All child
socialBlogRoot
forums should be turned into blogs, and the topics of these forums should be articles. Add a
parent_post_id
field to the
xf_post
table for tree comments.
')
Controller
We
XenForo_ControllerPublic_Thread
and
XenForo_ControllerPublic_Forum
. If the current forum is a child of
socialBlogRoot
, make an entry in the registry:
XenForo_Application::set('blogView', 1);
Now, anywhere in the script, we know that we are inside the blog.
View
XenForo_ViewPublic_Thread_View
class:
class Social_ViewPublic_Thread_View extends XFCP_Social_ViewPublic_Thread_View { public function renderHtml() { parent::renderHtml(); // , if (XenForo_Application::isRegistered('blogView')) { $firstPostId = $this->_params['firstPost']['post_id']; $this->_params['firstPost'] = $this->_params['posts'][$firstPostId]; // , unset($this->_params['posts'][$firstPostId]); // $commentTree = Social_ViewPublic_Helper_Comment::buildCommentTree($this->_params['posts']); $this->_params['commentsTemplate'] = Social_ViewPublic_Helper_Comment::createCommentsTemplateObject($this, $commentTree); // $this->_params['posts'] = array($this->_params['firstPost']['post_id'] => $this->_params['firstPost']); } } }
Template
The first post and the rendered comment tree are passed as template parameters. It only remains to insert this tree at the end of the first post, using a template hook called
ad_message_below
in the
message
pattern.
Theme-based comment module
It turns out that themes can be used as a universal way of commenting on any content. Let's show it on the example of photo albums. From the box, photos can be uploaded as attachments to messages, and viewed using the built-in lightbox.
Again, create a
socialAlbumRoot
setting for the root of all albums. For blogs, we made tree comments. Now the message can relate not only to another message, but also to the attachment. To do this, instead of adding a single
parent_post_id
field to the
xf_post
table, add two fields
target_id
and
target_type
. The latter indicates the type of content to which the message belongs (post or attachment).
All albums of one user can now fit into one tree-like theme as follows:
- Album (post: target_id = 0, target_type = post, post_id = 200)
- Photo (attachment: target_id = 200, target_type = post, attachment_id = 1000)
- Comment (post: target_id = 1000, target_type = attachment, post_id = 201)
- Comment (post: target_id = 1000, target_type = attachment, post_id = 202)
- Comment (post: target_id = 1000, target_type = attachment, post_id = 203)
- Photo (attachment: target_id = 200, target_type = post, attachment_id = 1001)
- Comment (post: target_id = 1001, target_type = attachment, post_id = 204)
- Comment (post: target_id = 1001, target_type = attachment, post_id = 205)
- Comment (post: target_id = 1001, target_type = attachment, post_id = 206)
- Album (post: target_id = 0, target_type = post, post_id = 201)
- Photo (attachment: target_id = 201, target_type = post, attachment_id = 1002)
- Comment (post: target_id = 1002, target_type = attachment, post_id = 207)
- Comment (post: target_id = 1002, target_type = attachment, post_id = 208)
- Comment (post: target_id = 1002, target_type = attachment, post_id = 209)
- Photo (attachment: target_id = 201, target_type = post, attachment_id = 1003)
- Comment (post: target_id = 1003, target_type = attachment, post_id = 210)
- Comment (post: target_id = 1003, target_type = attachment, post_id = 211)
- Comment (post: target_id = 1003, target_type = attachment, post_id = 212)
Then you can act like a blog: make an entry in the registry, expand the view and change the template. There is no point in going into technical details.
News (Home)
The news feed has its own controller, look and pattern. Each news item is a processed first post of a topic. Processing consists of automatic cropping, as well as limiting the number of embedded images and videos. The news appears on the main page if the first message of the thread collects more than a specified number of likes. Thanks to this approach, an article, a photo album, a survey or a simple discussion can be news.
Conclusion
XenForo seemed to us one of the most thoughtful and technologically advanced scripts not only among forum engines, but also among CMS. Now I am convinced that based on XenForo, you can make both a large portal and a social network.
The project is developing. The main part of the blog is ready. Plans are photo albums, CMS, online store, wiki, poster. If someone is interested to participate - write. If it is interesting to see the demo, add a link.