


Use 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. LaravelFramework
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. TSTechnical 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:
![]()
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/
![]() 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/
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/
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
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:
![]() 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 “App
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.
|

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
