Home>Article>CMS Tutorial> How discuz develops attention function
Functions implemented in this article:
1. Follow and unfollow users
2. Determine the following relationship with the user
After clicking to follow, it will be displayed as followed, and after unfollowing, it will be displayed as following
source/include/space/space_profile.phpthis file. But in this file, I can't find any code related to attention.
But this file contains all the required data about user space. For example, the number of users' fans, the number of user topics, the number of users' followers, and the number of users' friends. These values are stored in the $space variable and the interface is used directly in the template. For these fields, you can directly search for keywords in the database dictionary So we are taking a look at thespacecpmodule. In this directory, we found the follow file. The English translation offollowmeans following.
When learning other people’s projects, we first need to read the documentation, and secondly we need to guess its meaning based on the directory structure and file name Open Filesource/include/spacecp/spacecp_follow.php. There are two values at the beginning of the file, oneaddand onedel. Then use the op variable to receive it. According to this op variable, we can know that adding a follow is add. When canceling the follow, the del method
we find a value inaddfollow_not_follow_selfMy understanding of this is that you cannot pay attention to yourself. You can search for this value in language to confirm. It has been proven here thatsource/include/spacecp/spacecp_follow.phpis the file that implements following
The next step is how to make a request Woolen cloth!
According to the four $_GET values pointed to by the arrows below, the request address we can determine is
home.php?mod=spacecp&ac=follow&op=add&hash={FORMHASH}&fuid={$space[uid]}&mobile=2As for why the request address can be determined, we will introduce it later. , the focus of this article is to focus on the function
Then we write the following code in the template, which is the style that focuses on it
关注taClick to follow. At this time, our attention is ready. Then the same goes for unfollowing! Next we search in the database dictionary based on the keyword follow and find that there will be a user follow relationship table
打开数据库查到pre_home_follow这个表,就会发现有一条数据就是关注者跟被关注者。
在上文中我们实现了关注与取消关注,但是当我们关注了用户后,是不是需要显示已关注 或者 关注ta的字样
我们打开数据库字典搜索pre_common_member_count 用户统计表。
在这个表里边我们发现有收听数量和听众数量。那么对应的就是关注数量和粉丝数量
然后打开文件source/include/space/space_profile.php加上代码
# 判断是否关注 $follow_data = DB::fetch_all("select * from pre_home_follow where uid = '$_G[uid]' and followuid = '$space[uid]' limit 1"); if(!empty($follow_data)){ $space['is_follow'] = $follow_data[0]['mutual']; }
在template/default/touch/home/space_profile.htm模板里边进行判断
没有关注时显示关注ta
关注之后显示以关注
关于本文的实现关注功能。在网上的资料不是很多,但是我们也可以自己去研究实现。后期会一直推送discuz的文章。有任何问题,评论区见。
The above is the detailed content of How discuz develops attention function. For more information, please follow other related articles on the PHP Chinese website!