search
HomeBackend DevelopmentPHP TutorialUse technical analysis to pay tribute to the old open source social platform-ThinkSNS

I am an IT otaku, and I have started my own SNS social journey since high school. The past seven or eight years have been spent on SNS socializing, including smiles, sweat, and sadness. When I go out to get some light, I will take a few photos and share them on SNS. If I encounter behavior that is detrimental to society, I will expose it on SNS. If I have a little emotion in my heart, I will post it on SNS to vent it out. Gradually, I got used to looking for those random jokes from SNS, getting literary and artistic talents from SNS of famous writers, and absorbing industry trends and fresh knowledge from SNS of IT tycoons. Among many SNS social systems, the first open source social SNS I came into contact with was ThinkSNS, which was developed based on web2.0 version.
Through some Internet searches, I found that there is relatively little professional technical information about ThinkSNS on related websites such as Zhihu. Many programmers want to search for some technical documents about ThinkSNS but cannot get it. Therefore, I wrote this article about ThinkSNS technology to share it with many entrepreneurs who like ThinkSNS, and also provide developers with their own technical insights.
                                  What? First, let’s get familiar with what TS is. TS is the abbreviation of “ThinkSNS”. People who like TS programs are called TSers. TS is an open source program, and the code hosting platform is GitHub. All detailed modifications are transparent updates. Users can use the official website (http://www.thinksns.com) and the official demo community (Demo site http://demo.thinksns.com) and GitHub repository (https://github.com/medz /ThinkSNS-4) Get the latest development trends of TS~ Of course, if you are interested, you can also Pull requestTS (PR for short) code to TS developers. After the developers get the code, if it meets the open source requirements, it will be merged into the TS version. , if ordinary users encounter problems, they can submit Issues on the demo site or Github, and they will receive a unified response from the developers. TS has relatively low requirements for PHP version, and basic industries have entered the php5.5 or php5.6 stage~ However, considering that most domestic niche virtual hosts and many people who do not know relevant professional knowledge, so , TS lowered the php version to php5.3.12~ Of course, some people think why the minor version is 12. This version is the first stable version of php5.3~ That is, the versions before this minor version are not stable versions, so it is not Recommended to install and use.
2.
Laravel
Framework
Eloquent ORM and TP Framework TS made relatively large underlying architecture changes during the development process in 2016. As we all know, the bottom layer of TS is modified based on the ThinkPHP framework. One of the main reasons why users cannot directly upgrade TS based on ThinkPHP is that the TP framework does not fully follow the MIT open source protocol. Of course, for developers, the TP framework technical architecture itself also has problems that are not advanced enough and too abstract. Therefore, after comprehensive consideration, TS uses the Eloquent ORM of the Laravel framework for data exchange. What are the advantages of Eloquent ORM? This ORM's data processing is similar to Node.js's data processing, that is, everything is an object, and the ORM's processing efficiency of data relationships is not inferior to doctrine, which is why TS chose it this way. Of course, the more consideration is to prepare for more advanced architectures in the future. TS will gradually adopt an expansion method for development, and perform architectural data exchange on the entire TS program. The introduction of the new ORM has made TS consider running the php7 platform, but php7 has completely deleted the MySQL connection method, leaving only PDO and MySQLi. Then, if you want to run it in the php7 environment, you must re-modify the DB class. However, considering the compatibility issue, currently in the old application, the SQL is still generated by the model, and then the SQL is handed over to PDO for execution. . The newly developed applications and functions are all developed using new ORM data.
3.
TS
Technical advantages and expansion
In addition to introducing a new ORM, TS also has many technical advantages, such as: having a base class that is easier to understand and integrate. These base classes are re-encapsulated on the basis of third-party libraries, making the attributes set in TS module development more standard and making it easier to get started with development. Because, if inheritance and other tasks are done by developers to integrate third-party classes, then according to national conditions, this is almost impossible. On this basis, developers only need to look at the base class to know what they need to do after integration, without having to learn third-party classes.
In the new extension of TS (currently an application), the original static resources directly reference the resources under the application. In the new architecture, TS applications will be uniformly moved to a public cache directory to facilitate external calls. This design is to make TS more secure. In this way, users can obtain the static resources nested in the application without exposing the code, and the webmaster or developer can more safely keep the non-public code in the upper layer of the exposed directory and hide it.
So what specific features does TS have? This issue is basically a matter of opinion. Because TS is all in one, in addition to the core social functions, it also has micro bars, channels, information, activities, shopping malls, etc., as well as many TS cooperation products with different industry attributes, as shown in the picture:
Use technical analysis to pay tribute to the old open source social platform-ThinkSNS
4. Chatting and trend are the core of social interaction
TS has an independently developed native instant chat system. We know that chat and direction are the core of social interaction. On the PC, TS uses JS polling to implement message reception and other operations; on the mobile terminal, TS uses advanced technology - Socket technology. In order to ensure that user records are not lost and avoid P2P point-to-point transmission, the program is run by a client The client pushes the message to the server, and the server forwards the message to another client and stores it in the database, achieving the goal of simultaneous arrival from multiple clients.
5. Basic technical points in TS
Any analysis without some practical information is just a rogue. Next, let’s talk about the basic technical points in TS. In TS, applications have a configuration file. The current application directory is apps/ Therefore, the configuration file is: "apps//manage.json". Here is the demo code:
Use technical analysis to pay tribute to the old open source social platform-ThinkSNS
We can see that this is a relatively new application configuration. In old applications, you only need to configure the "resource" item. After configuring this item, the static resources will be cached to "storage/app/ "Under ", if you configure developer mode, it will be moved here every time you access it. Therefore, the storage/app directory is a publicly exposed directory.
To achieve the above, we have to mention a new application installation class. The namespace is TSHelperAppInstall - some processing has been done on the new application mechanism (currently static resource caching), and the application runner is also located under this namespace. "TSHelperController", a real-time runner, only needs to pass in the App Name, Controller Name, and Action Name. The runner will find the namespace registered by the application through Composer to run the required controller code.
Speaking of which, I have to mention an important technical addition, which is the Composer package management tool. Composer can be said to be the best tool among all language package management tools. It provides standardized integration, upgrade, and uninstallation of third-party packages, as well as AutoLoader tools that comply with PSR-0 and PSR-4 specifications. This eliminates the need for redundant custom automatic loading in TS to find the class files and library files we need. It can be registered directly using Composer. Let’s use the simplest example to illustrate:
It is understood that the TS development team is developing a new Web Application. The important code exists in the apps//src directory. So, how does TS Can you find the directory location of the class customization? Speaking of which, you need to know the namespace specified by the application. The application does not have any requirements for the namespace. The only requirement is the controller. The namespace of the Controller is specified as "App". This specification is convenient for passing the URL. The parameters find the controller of the application. Of course, this is only temporary. In the future, the development of TS will no longer have any technical requirements such as namespaces. You only need to call the router to register the controller, instead of TS actively searching for the controller. , everything used needs to be registered in advance, which complies with advanced technical requirements.
Getting back to the topic, how did TS find the Controller?
In fact, what TS does is very simple. It constructs a class of "App" and then instantiates this class. This class is registered for automatic loading through Composer during application development. of. The standard for this application is PSR-4, so we can put the code in any directory, not just the src directory. This directory is unknown to the TS program, but Composer knows it, so TS only needs to "ask "Composer is available.
The introduction of this new technology not only reduces the heavy development work, but also makes the TS code simpler, because we no longer care about things unrelated to the TS code itself, we only need to focus on the development of our own code part. So the TS code package, excluding third-party libraries, has been reduced from 24MB last year to 21MB now. Why is it still so big? Because TS must take into account the operational requirements of old modules while using new technologies, there is nothing we can do now to re-develop all old modules because there is no need. We can't always say that after giving birth to a child, if the child becomes ugly, just stuff it back and give birth to a new child!
The focus of TS changes is the addition of ORM, so how to use the new data model? Here’s a basic inheritance code:
Use technical analysis to pay tribute to the old open source social platform-ThinkSNS
That’s right, it only takes 20 lines with comments. What’s the difference between that and the previous model inheritance? One difference lies in the change of passed parameters. ORM supports free switching among MySQL, SqlLite, SQL server and other databases. Another difference lies in the change of defined keywords. Once the model is defined, you can frequently operate on the table. Isn't it very simple? In the above table, querying a piece of data whose feed_id is 1 is very simple, Feed::find(1). OK, we have completed the query. Of course, what is returned is an object, not an Array of pure data.
If you want to turn it into the array you want, for example $feed is the data returned by the above query, then you only need $feed->toArray() to do it. If we can know the fields of the table, we can directly read the queried data as object members, such as $feed->feed_id or $feed->cTime, or directly pass this object to foreach. Traverse the attributes. From this, we can see that the new ORM does not need to operate on arrays as before when processing data, but we can keep the traversal unchanged on the previous basis.
Of course, for more specific uses, you can check the official documentation of the Laravel framework and give another example of a relationship in ORM.
public function phone()
{
Return $this->hasOne('Phone');
}
Define such a method in the above method, we associate the Phone model one-to-one, $data = Feed::find(1)->phone, we can get the same value of the phone primary key feed_id and the feed table table object. Isn't it very convenient?
Finally, let’s talk about the controller. A base class called “TSBaseNoneController” is encapsulated in TS. Under your controller, define a controller class called “AppControllerNone” and inherit it. This NoneController object, then when your application accesses a controller that does not exist, it will be redirected to this controller. Therefore, you can use this thing to develop many unexpected methods.
6. ThinkSNS is not only open source, but also a business accelerator
I don’t know if you really understand TS through the introduction of this article, and this is just a rare part of TS, but It cannot be ignored either.
TS has been growing and doing its best to add power and acceleration to entrepreneurs.
Summary: TS has an advanced architecture, the code complies with PSR specifications, is simple to use, and has high compatibility. Entrepreneurs can easily adapt TS to meet their business needs, and developers can get started in a very short time.
Time is the most expensive cost for technicians and entrepreneurs. The hope and purpose of ThinkSNS is to allow entrepreneurs and developers to focus on what they should do.



Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use