Dedecms deletes both the scaling chart and article image when deleting an article

Source: Internet
Author: User

Dedecms deletes both the scaling chart and article image when deleting an article
I used gbk to test version 5.6.
Method:

Here, I still put the complete code out of the province, which is hard to understand and attacked by artillery.
Before I paste the code, you must remember to follow what I said. If you fail to follow what I said, or you have problems, don't scold me. I declare that if you follow what I said, if something goes wrong, you can yell at me. I don't pay back, don't talk nonsense, and post code.
First, open "extend. func. php Tutorial "file. then, save the following content in "extend. func. php "file tail, a total of three functions
// Parse the body data to obtain the absolute address of all images

Function getpicstruepath ($ body, $ litpic ){

$ Delfiles = array (); // stores image address data

If (! Empty ($ litpic )){

$ Litpicpath =
Gettruepath ();

$ Litpicpath. =
$ Litpic;

$ Delfiles [] =
$ Litpicpath; // Thumbnail address

         }

Preg_match_all ("/src = [" | '| s] ([^
|/|>] *) {0,} ([^>] *). (gif | jpg | png)/isu ", $ body, $ tmpdata );

$ Picspath =
Array_unique ($ tmpdata [2]); // address of all images in the body

Foreach ($ picspath
$ Tmppath ){

$ Path =
Gettruepath (); // Obtain the absolute path

$ Picpath =
Preg_replace ("/[a-za-z] +: // [^ |/| s] */", '', $ tmppath); // remove the url section

$ Path. = $ picpath;

$ Delfiles [] =
$ Path; // Save the processed data

         }

Return $ delfiles;

}

 

// Obtain the article body data

Function getarcbody ($ aid ){

Global $ dsql;

$ Query = "select
Dede_addonarticle.body from dede_addonarticle where dede_addonarticle.aid =
'$ Aid '";

$ Row =
$ Dsql-> getone ($ query );

If (is_array ($ row ))

Return $ row;

Else

Return false;

}

 

// Write the log file

Function writetodelfiles ($ msg) // logs are recorded through this function when you delete an article.

{

If (empty ($ msg ))
$ Savemsg = "messages not received ";

Else $ savemsg = $ msg;

$ Errorfile =
Dirname (_ file _). '/../data/del_body_file.txt'; // delete the record file

$ Fp = @ fopen ($ errorfile,
'A ');

@ Fwrite ($ fp, "rn {$ savemsg }");

@ Fclose ($ fp );

}

Next, open the "/dede/inc/inc_batchup.php" file.
1: add at the bottom of 33 rows, that is, "$ arcrow = $ dsql-> getone ($ arcquery);" below:
$ Arcbodyrow = getarcbody ($ aid );
2: add it at the bottom of 102, that is, "if (@ is_file ($ filenameh) @ unlink ($ filenameh);" below:
// Parse the resource in the body and delete it

$ Willdelfiles = getpicstruepath ($ arcbodyrow ['body'], $ arcrow ['litpic ']);
$ Nowtime = time ();
$ Executetime = mydate ('Y-m-d h: I: S', $ nowtime); // Obtain the execution time
$ Msg = "rn article title: $ arcrow [title]";
Writetodelfiles ($ msg );
If (! Empty ($ willdelfiles )){
Foreach ($ willdelfiles as $ file ){
If (file_exists ($ file )&&! Is_dir ($ file ))
        {
If (unlink ($ file) $ msg = "rn location: $ filern result: deletion successful! Rn Time: $ executetime ";
Else $ msg = "rn location: $ filern result: deletion failed! Rn Time: $ executetime ";
        }
Else $ msg = "rn location: $ filern result: the file is not saved! Rn Time: $ executetime ";
Writetodelfiles ($ msg );
} // End foreach
} Else {
$ Msg = "rn does not parse the original rnbody data in the body: $ arcbodyrow [body] rn Time: $ executetime ";
Writetodelfiles ($ msg );
}


After all the modifications are completed, the program analyzes the image address in the body and then deletes the file. In the/data/directory, the log file del_body_file.txt is generated.
You can check this file when you delete it.

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.