Table of Contents
处理是否显示关注
Home CMS Tutorial Discuz How discuz develops attention function

How discuz develops attention function

May 07, 2020 pm 12:08 PM
discuz

Functions implemented in this article:

1. Follow and unfollow users

2. Determine the following relationship with the user

Achieve effect

After clicking to follow, it will be displayed as followed, and after unfollowing, it will be displayed as following

How discuz develops attention function

How discuz develops attention function

##Implementation plan


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


Open the file home.php file In line 29, you can see that in_array was used to make a judgment, focusing on the two modules space and spacecp

Let’s first recognize two words: space (space) and spacecp (translated as space program)

How discuz develops attention function

Then we need to open the original default template of discuz (this is when you build a discuz application yourself without any modified code), then post a topic and click on a user image at will. View the address information in the address bar.

I found that I entered the space module

How discuz develops attention function

Then according to the address bar we can find

source/include/space/space_profile.php this 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 the

spacecp module. In this directory, we found the follow file. The English translation of follow means 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

How discuz develops attention function

Open File

source/include/spacecp/spacecp_follow.php. There are two values ​​at the beginning of the file, one add and one del. 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

How discuz develops attention function

we find a value in

add follow_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 that source/include/spacecp/spacecp_follow.php is the file that implements following

How discuz develops attention function

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=2
Copy after login

As for why the request address can be determined, we will introduce it later. , the focus of this article is to focus on the function

How discuz develops attention function

Then we write the following code in the template, which is the style that focuses on it

          
Copy after login

How discuz develops attention function

Click to follow. At this time, our attention is ready. Then the same goes for unfollowing!

How discuz develops attention function

Next we search in the database dictionary based on the keyword follow and find that there will be a user follow relationship table

How discuz develops attention function

打开数据库查到pre_home_follow 这个表,就会发现有一条数据就是关注者跟被关注者。

How discuz develops attention function

在上文中我们实现了关注与取消关注,但是当我们关注了用户后,是不是需要显示已关注 或者 关注ta的字样

处理是否显示关注

我们打开数据库字典搜索pre_common_member_count 用户统计表

在这个表里边我们发现有收听数量和听众数量。那么对应的就是关注数量和粉丝数量

How discuz develops attention function

然后打开文件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'];
}
Copy after login

在template/default/touch/home/space_profile.htm模板里边进行判断

Copy after login

测试

没有关注时显示关注ta

How discuz develops attention function

关注之后显示以关注

How discuz develops attention function

总结

关于本文的实现关注功能。在网上的资料不是很多,但是我们也可以自己去研究实现。后期会一直推送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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Discuz background login problem solution revealed Discuz background login problem solution revealed Mar 03, 2024 am 08:57 AM

The solution to the Discuz background login problem is revealed. Specific code examples are needed. With the rapid development of the Internet, website construction has become more and more common, and Discuz, as a commonly used forum website building system, has been favored by many webmasters. However, precisely because of its powerful functions, sometimes we encounter some problems when using Discuz, such as background login problems. Today, we will reveal the solution to the Discuz background login problem and provide specific code examples. We hope to help those in need.

Detailed explanation of Discuz registration process: allowing you to easily modify personal information Detailed explanation of Discuz registration process: allowing you to easily modify personal information Mar 13, 2024 pm 12:21 PM

"Detailed Explanation of Discuz Registration Process: Allowing you to easily modify personal information, specific code examples are required" Discuz is a powerful community forum program that is widely used in various websites. It provides a wealth of user registration and personal information modification. functions and interfaces. This article will introduce you to Discuz's registration process in detail and provide specific code examples to help you easily customize and modify your personal information. 1. User registration process In Discuz, user registration is one of the important functions of the site. The smoothness of the registration process and

A must-have for Discuz users! Comprehensive analysis of renaming props! A must-have for Discuz users! Comprehensive analysis of renaming props! Mar 12, 2024 pm 10:15 PM

A must-have for Discuz users! Comprehensive analysis of renaming props! In the Discuz forum, the name change function has always received much attention and demand from users. For some users who need to change their name, name change props can easily modify the user name, and this is also an interesting way of interaction. Let’s take an in-depth look at the renaming props in Discuz, including how to obtain them, how to use them, and solutions to some common problems. 1. Obtain name-changing props in Discuz. Name-changing props are usually purchased through points or the administrator

What is Discuz? Definition and function introduction of Discuz What is Discuz? Definition and function introduction of Discuz Mar 03, 2024 am 10:33 AM

"Exploring Discuz: Definition, Functions and Code Examples" With the rapid development of the Internet, community forums have become an important platform for people to obtain information and exchange opinions. Among the many community forum systems, Discuz, as a well-known open source forum software in China, is favored by the majority of website developers and administrators. So, what is Discuz? What functions does it have, and how can it help our website? This article will introduce Discuz in detail and attach specific code examples to help readers learn more about it.

What should I do if I encounter an incorrect Discuz password? Quick solution sharing! What should I do if I encounter an incorrect Discuz password? Quick solution sharing! Mar 03, 2024 am 09:33 AM

What should I do if I encounter an incorrect Discuz password? Quick solution sharing! Discuz! It is a very popular forum program that provides users with a platform for convenient communication. Using Discuz! When accessing a forum, sometimes you may encounter an incorrect password, which may cause users to be unable to log in and use the forum normally. Well, meet Discuz! When the password is wrong, how should we quickly solve the problem? Some solutions will be shared below, with specific code examples provided for reference. 1. Check whether the password

Solve the problem that Discuz WeChat sharing cannot be displayed Solve the problem that Discuz WeChat sharing cannot be displayed Mar 09, 2024 pm 03:39 PM

Title: To solve the problem that Discuz WeChat shares cannot be displayed, specific code examples are needed. With the development of the mobile Internet, WeChat has become an indispensable part of people's daily lives. In website development, in order to improve user experience and expand website exposure, many websites will integrate WeChat sharing functions, allowing users to easily share website content to Moments or WeChat groups. However, sometimes when using open source forum systems such as Discuz, you will encounter the problem that WeChat shares cannot be displayed, which brings certain difficulties to the user experience.

Discuz Editor: Powerful web page editing tool Discuz Editor: Powerful web page editing tool Mar 09, 2024 pm 06:06 PM

Discuz Editor: A powerful web page editing tool that requires specific code examples. With the development of the Internet, website construction and content editing have become more and more important. As a common web page editing tool, Discuz editor plays an important role in website construction. It not only provides a wealth of functions and tools, but also helps users edit and publish content more conveniently. In this article, we will introduce the features and usage of the Discuz editor, and provide some specific code examples to help readers better understand and use

Discuz background account login exception, how to deal with it? Discuz background account login exception, how to deal with it? Mar 09, 2024 pm 05:51 PM

Title: Discuz background account login exception, how to deal with it? When you use the backend management of the Discuz forum system, you may sometimes encounter abnormal account login. This could be due to a variety of reasons, including a wrong password, account being blocked, network connection issues, etc. When encountering this situation, we need to solve the problem through simple troubleshooting and processing. Check whether the account number and password are correct: First, confirm whether the account number and password you entered are correct. When logging in, make sure the capitalization is correct and the password is

See all articles