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.
|