Pay tribute to the old open-source social platform ThinkSNS with technical analysis

Source: Internet
Author: User
Pay tribute to the old open-source social platform ThinkSNS with technical analysis

As an IT otaku, I started my SNS social networking from high school. The scenes of the year 78 s were used on SNS social networking, with smiles, sweat, and sadness. When I go out for lighting, I will take a few photos and share them with SNS for social networking. if I encounter behavior detrimental to society, I will break my SNS social networking exposure. if I feel a little emotional, I will send it to SNS for social networking. Gradually, I get used to looking for cool-looking smiles from SNS, and getting the style of literature and art from SNS, learn industry trends and new knowledge from SNS social networking of IT Daniel. Among the many SNS, the open-source SNS that I first came into contact with were ThinkSNS developed based on web2.0.

Through some web searches, it is found that ThinkSNS has little professional technical information on websites such as Zhihu. many programmers cannot retrieve ThinkSNS technical documents. Therefore, I wrote this article about ThinkSNS and shared it with many entrepreneurs who like ThinkSNS. It also provides developers with their own technical insights.

1. what is TS?

First of all, let's get familiar with what TS is. TS is the abbreviation of "ThinkSNS". people who love TS programs are called TSer. TS is an open-source program. The code hosting platform is GitHub. all the details are updated in transparency.

Users can go to the official website (Http://www.thinksns.comAnd the official Demo community (Demo site http://demo.thinksns.com) and GitHub repository (https://github.com/medz/ThinkSNS-4) get the latest TS development news ~ Of course, if you are interested, you can also send the Pull requesTS (PR for short) code to TS developers. after obtaining the code, if the code meets the open source requirements, it will be merged into the TS version, if a common user encounters a problem, you can submit Issues on the demo site or Github, and the developers will reply in a unified manner.

TS requires a relatively low PHP version, and the basic industry has entered the php5.5 or php5.6 stage ~ However, considering most of the niche virtual hosts in China and many people who do not know the relevant professional knowledge, TS has lowered the php version to php5.3.12 ~ Of course, some people think that the minor version is 12, which is the first stable version of php5.3 ~ That is, versions earlier than this minor version are not stable, so it is not recommended for installation.

II,LaravelFrameworkEloquent ORMAndTP framework

During the development in 2016, TS made significant underlying architecture changes. As we all know, the underlying layer of TS is modified based on the ThinkPHP framework. one of the main reasons that users cannot directly upgrade TS with ThinkPHP is that the TP framework is not fully compliant with the MIT open source protocol. Of course, for developers, the technical architecture of the TP framework is not advanced enough and too abstract. Therefore, TS uses the Eloquent ORM of the Laravel framework during data exchange.

What are the advantages of Eloquent ORM? This ORM processes data similar to Node. javaScript Data processing means that everything is an object, and the efficiency of ORM in processing data relations is not inferior to doctrine, which is also the reason for TS's choice. Of course, it is more important to prepare for a more advanced architecture in the future. TS will be developed in an extended way and implement architecture data exchange for the entire TS program.

The introduction of the new ORM allows TS to consider the running of the php7 platform, but php7 has completely deleted the MySQL connection mode, only PDO and MySQLi. If you want to run in the PHP 7 environment, you must modify the DB class again. However, considering the compatibility issue, the SQL statement is still generated by the model in the old application, then, submit the SQL statement to PDO for execution. The newly developed applications and functions use the new ORM for data development.

III,TS technical advantages and expansion

In addition to introducing new ORM, TS has many technical advantages, such as basic classes that are easier to understand and integrate. These base classes are encapsulated based on third-party libraries to make the attributes set in TS module development more standard and easier to get started with development. Because, if inheritance and so on are all third-party classes integrated by developers, this is almost impossible according to national conditions. On the basis of this, developers only need to look at the base class and know what they need to do after integration, without learning third-party classes.

In the new TS expansion (currently an application), the original static resources directly reference the resources under the application. in the new architecture, all TS applications are moved to a public cache directory to facilitate external calls. This design aims to make TS more secure. In this way, the user can obtain the nested static resources in the application without exposing the code. the webmaster or developer can more securely keep the non-public code in the upper layer of the exposed directory to hide it.

What are the specific features of TS? This problem is basically true to the wise. In addition to core social networking functions, TS is a combination of micro bars, channels, information, activities, and shopping malls. at the same time, there are also many TS cooperation products with different industry attributes,

Image 4.png (77.37 KB, Downloads: 0)

Download attachment

Upload

4. chat and wind are the core of social networking

TS has a self-developed native instant chat system. We know that chat and wind are the core of social networking. In PC, TS uses JS polling to receive messages and perform other operations. on mobile terminals, TS uses the advanced technology-Socket technology to ensure that user records are not lost, the P2P point-to-point transmission is avoided. a program is pushed to the server by a client. the server forwards messages to another client, and the probability in the database reaches the goal of multiple terminals at the same time.

V,Basic technical points in TS

The analysis is not dry. Next, let's talk about the basic technical points in TS. In TS, all applications have a configuration file. The current application directory is apps/. Therefore, the configuration file is "apps // manage. json". The following is the demo code:

Image 2.png (7.86 KB, Downloads: 0)

Download attachment

Upload

We can see that this is a relatively new application configuration. in old applications, you only need to configure the "resource" item. after this item is configured, static resources will be cached under "storage/app, if you have configured the developer mode, each access will be moved here. Therefore, the storage/app directory is a public exposed directory.

To achieve this, you have to propose a new application installation class. the namespace is TS \ Helper \ AppInstall-some column processing (static resource cache currently) is performed on the new application mechanism ), the application runner is also located in the namespace. you only need to input the App Name, Controller Name, Action Name, the runner finds the application registration namespace in Composer to run the required controller code.

Here, we have to mention an important technology, namely the Composer package management tool. Composer can be said to be the best tool for package management tools in all languages, which provides third-party packages for standardized integration, upgrade, uninstallation, and AutoLoader tools that comply with PSR-0 and PSR-4 specifications. This makes it unnecessary for TS to automatically load redundant custom files to find the class files and library files we need. you can directly register them using Composer. Here is a simple example:

It is understood that the TS development team is developing a brand new Web Application. the important code is stored in the apps/src directory, how does TS find the location of the custom directory of the class? Speaking of this, you need to know the namespace specified by the application. the application has no requirements for the namespace. The only requirement is the Controller. the namespace specified by the Controller is "App \", this rule is convenient to find the application controller through URL parameters. of course, this is only temporary. in the future, TS development will not have any technical requirements such as namespaces, you only need to call the vro to register the controller, instead of the TS to actively search for the controller. all the items used must be registered in advance, which meets the advanced technical requirements.

Now, how does TS find the Controller?

In fact, what TS does is very simple. it constructs an "App \\ Class, and then instantiate this class, and this class is registered to automatically loaded through Composer during application development. This application quasi-Query specification is PSR-4, so we can put the code in any directory, not just src Directory, this directory is unknown for TS programs, but Composer knows, so TS only needs to "ask" Composer to get it.

The introduction of this new technology not only reduces the heavy development work, but also makes TS code simpler, because we do not care about things unrelated to TS code, we only need to focus on the development of our own code. Therefore, in addition to third-party libraries, TS code packages have been reduced from 24 MB last year to 21 MB. why is it so large? While using the new technology, TS needs to consider the operation requirements of the old modules. it is powerless to re-develop the old modules because it is not necessary. We can't say that if we have a child and the child is ugly, we should try again!

The focus of TS changes lies in the addition of ORM. how can we use the new data model? Basic inheritance code:

Image 1.png (25.75 KB, Downloads: 0)

Download attachment

Upload

That's right. There are 20 lines of comment. what is the difference between it and the previous model inheritance? One difference lies in passing parameter changes. ORM supports free switching in databases such as MySQL, SqlLite, and SQL server. Another difference lies in the change of the defined keywords. once a model is defined, the table can be operated frequently. is it very easy. In the preceding table, it is very easy to query a data record with feed_id as 1. Feed: find (1 ). OK. the query is complete. Of course, the returned object is not an Array of pure data.

If you want to convert it into the array you want, for example, $ feed is the data returned by the preceding query, you only need $ feed-> toArray () to do this. If we can know the table fields, we can directly read the queried data as an object member, such as $ feed-> feed_id or $ feed-> cTime, you can also directly pass this object to foreach to traverse the attributes. From this we can see that the new ORM does not need to perform array operations on data processing as before, however, we can keep the traversal settings unchanged.

Of course, for more details, you can query the official documentation of the Laravel framework and give an example of the relationship in the ORM.

Public function phone ()

{

Return $ this-> hasOne ('phone ');

}

In the above method, we define this method. we associate the Phone model one to one, $ data = Feed: find (1) -> for phone, we can get the table object with the same value of the phone primary key feed_id and the feed table. Is it convenient?

Finally, let's talk about the controller. in TS, a Base class called "TS \ Base \ NoneController" is encapsulated. under your controller, define a Controller class named "App \ controller \ None" and inherit the NoneController object. Then, when your application accesses a controller that does not exist, it will redirect to this Controller. Therefore, you can use this to expand many unexpected methods.

VI,ThinkSNS are not only open source, but also entrepreneurial accelerators

I don't know whether you have really understood TS through the introduction in this article. this is only rare in TS, but it cannot be ignored.

TS has been growing and does its best to provide dynamic acceleration for entrepreneurs.

Conclusion: the TS architecture is advanced, and the code conforms to the PSR specifications. users are easy to use and have high compatibility. entrepreneurs can easily adapt to TS to meet their own business needs, developers can start in a very short time.

Time is the most expensive for technicians and entrepreneurs. ThinkSNS aims to let entrepreneurs and developers focus on what they should do.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.