Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop the attention function of discuz

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you attention on how to develop discuz. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

This paper implements the function:

1. Follow and unfollow users

two。 Judge the relationship of concern with the user

Realize the effect

Click follow to show that you have followed, and cancel to show ta to follow.

Realization scheme

The entry to user space is the home.php file, so we need to start with the home.php file first.

Opening the 29 lines of the file home.php file, you can see that a judgment was made using in_array, focusing mainly on the two modules space and spacecp.

Let's first know two words: space and spacecp.

Then we need to open the original default template of discuz (this is the code you are building a discuz application without any changes to), then post a theme and click on a user image to view the address information in the address bar.

It is found that the module entered is space.

So we can find the source/include/space/space_profile.php file according to the address bar. But in this file, you can't find any code about concerns.

But this file contains all the required data about user space. For example, the number of user fans, the number of user topics, the number of user followers, the number of user friends. These values are stored in the $space variable, using the interface directly in the template. For these fields, you can search for keywords directly in the database dictionary.

So we took a look at the spacecp module, and in this directory, we found the file follow. The English translation of follow has the meaning of concern.

When learning other people's projects, we first need to look at the documents, and second, we need to guess its meaning according to the directory structure and file name.

Open the file source/include/spacecp/spacecp_follow.php. There are two values at the beginning of the file, one add and one del. Then it is received using the variable op. According to this op variable, you can know that adding attention is the del method when add cancels it.

We found a follow_not_follow_self value in add, which I understand is that I can't pay attention to myself. You can search for this value in language to confirm. It has been proved here that source/include/spacecp/spacecp_follow.php is the file that implements the concern.

The next step is how to make a request!

Based on the four $_ get values pointed to by the arrow below, we can determine the request address as

Home.php?mod=spacecp&ac=follow&op=add&hash= {FORMHASH} & fuid= {$space [uid]} & mobile=2

As to why the request address can be determined, it will be described later. This article focuses on the function.

Then we write the following code in the template, which is to focus on the style of ta

Follow ta

Click follow, and at this time our attention will be done. So it's the same thing to cancel your attention!

Next, we search the database dictionary according to the keyword follow and find that there is a user following the relational table.

Open the database and look up the pre_home_follow table, and you will find that there is a piece of data that is the follower and the follower.

In the above, we have implemented the following and unfollowing, but when we have followed the users, do we need to show the words that have followed or followed ta?

Whether to process whether to show concern

We open the database dictionary to search for pre_common_member_count user statistics.

In this table we find the number of listeners and the number of listeners. Then it corresponds to the number of followers and the number of fans.

Then open the file source/include/space/space_profile.php and add the code

# determine whether to follow $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'];}

Judge in the template/default/touch/home/space_profile.htm template

Have focused on ta testing

Show follow ta when there is no follow

Show after follow to follow

Summary

The realization of this article focuses on the function. There is not a lot of information on the Internet, but we can also study and implement it ourselves. Discuz articles will be pushed at a later stage. If you have any questions, see you in the comments section.

The above is the concern function of how to develop discuz shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report