Dedecms source code analysis (1)

Source: Internet
Author: User

 

I have been busy with other things for a while, and I don't have much time to spend. I am stuck with this topic. Now, I am going to talk about dedecms's entry code.

Open index. php to see what it is. Open index. php In the root directory
Well, what comes to the eye is an if statement.
Check whether/data/common. Inc. php exists. If not, go to the installation page.

Let's go to/data/To see this directory and common. Inc. php.
Open/data/, which contains many directories and files, including temporary directories for upload, template cache, and compressed temporary directories, cache files of system configuration information stored in various databases and other things are messy ~
Okay, let's open common. Inc. php. Oh, it turns out that the database connection variables are saved. To put it bluntly, dedecms's database connection configuration file is probably generated after the system is installed. So/index. php will check whether it exists.

We will return to the/homepage, that is, the static homepage of dedecms (Remember, the front-end page of dedecms is the static page generated by the system ).

Think about what we will study next? Yes, that is, when the GET request "upcache" exists, the code of the homepage cache is updated. The Code is as follows:
Require_once (dirname (_ file _). "/include/common. Inc. php ");
Require_once dedeinc. "/arc. partview. Class. php ";
$ Globals ['_ arclistenv'] = 'index ';
$ ROW = $ dsql-> getone ("select * from '#@__ homepageset '");
$ Row ['templet'] = mftemplet ($ row ['templet']);
$ Pv = new partview ();
$ PV-> settemplet ($ pai_basedir. $ pai_templets_dir. "/". $ row ['templet']);
$ PV-> savetohtml (dirname (_ file _). '/index.html ');
Include (dirname (_ file _). '/index.html ');
Exit ();

First, load/include/common. Inc. php. It is estimated that some common functions and files that load other system functions and classes.
Next, dedeinc is loaded. "/arc. partview. class. PHP ", pay attention to the constant dedeinc. We know that after the preliminary observation of the dedecms directory structure, arc. partview. class. PHP is in the/include directory, while loading/include/Common. inc. PHP does not use the constant dedeinc, which indicates that common. inc. the dedeinc constant is defined in PHP, so it can be used later. inc. the general role of PHP is the basic part of system operation, all of which are covered here. We are not in a rush to go to common. Inc. php and continue to read the updated cache code of index. php.
Third, set a global variable: $ globals ['_ arclistenv'] = 'index ';
Row 4: obtain all records of a table '##__ homepageset'. Of course, if you look at the database, there is no table "#@__ homepageset" in it, we will judge, it is the database operation-related function that replaces the First Half of the table name with the table name prefix. This does not matter. It is important to use this sentence, after obtaining the relevant configuration information on the homepage, we open the dede_homepageset table in the database. If it is dizzy, there will be a record and two fields. I have basically guessed that one is the homepage Template Name, one is the location of the generated static file.
Back to continue analyzing the previous Code
$ Row ['templet'] = mftemplet ($ row ['templet']);
The mftemplet function seems to have converted $ row ['templet. Write down the mftemplet function to be mined later.
Next, we have a new partview class. Looking at this name, we can see the role of loading arc. partview. Class. php.
As for the role of this partview class, let's continue to look at the code. After reading the following two lines, I think everyone should understand it.
$ PV-> settemplet ($ pai_basedir. $ pai_templets_dir. "/". $ row ['templet']);
$ PV-> savetohtml (dirname (_ file _). '/index.html ');
Create a view object (the partview class instance is called a view object), set a template, and write the last generated page to the specified position through the savetohtml method.
After the home page is generated, the generated static file is displayed in the form of include, and the page resolution is terminated by exit.

Now, the/index. php analysis is complete.
It first uses/data/common. Inc. php to determine whether dedecms is installed or whether database configuration information is defined, so as to lay the foundation for subsequent operations.
Then determine whether a GET request "upcache" exists. If yes, load/include/Common. inc. PHP initializes the system, calls the partview class method to generate a static homepage file, and displays it.

In this case, dedecms does not have many secrets ~

However, this article also leaves several questions:
1) load/include/common. Inc. php. What does it do?
2) What is/include/arc. partview. Class. php?/include/What are there many files starting with arc?
3) What operations does the mftemplet function perform on the template file path string?
4) What are the secrets of partview related parties' methods?

With these questions, we will end this article and the subsequent articles will unveil these puzzles one by one.

-End-

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.