Of course. Let's break down archives_do.php from the DedeCMS (织梦内容管理系统) framework.

This is a classic and essential file in DedeCMS, responsible for handling the backend actions related to content archives, which primarily means editing and saving articles.
Core Purpose
The primary function of archives_do.php is to act as a controller for the "Article Editor" page (archives_add.php). When an admin user clicks "Save" or "Submit" in the article backend, this file receives the form data, processes it, validates it, and then saves it to the database.
It handles several key actions, most notably:
- Saving a new article (as a draft or for immediate publishing).
- Updating an existing article.
- Moving an article to another channel (e.g., from "Article" to "Download").
- Copying an article.
- Deleting an article.
How It Works: The Request Flow
- User Action: An admin user is on
archives_add.php(the article editor page). They fill in the title, content, select a category, etc., and click the "Save" button. - Form Submission: The form data (title, body, author, etc.) is sent via a
POSTrequest toarchives_do.php. The request also includes hidden fields likedopost(which specifies the action, e.g.,save) andaid(the article ID if it's an edit). archives_do.phpExecution:- The file first checks for user login status and permissions. If the user is not logged in or lacks the rights, it will block the action.
- It reads the
dopostvariable to determine which specific operation to perform (e.g.,save,edit,move). - Based on the operation, it calls the appropriate functions or includes the necessary logic.
- Data Processing:
- It processes the form data. This includes things like handling special tags, filtering content, and preparing it for database insertion.
- It interacts with the core DedeCMS classes to handle the database interaction.
- Database Update:
- It executes SQL queries to insert a new record into the
dede_archivestable (for the main article info) and thedede_addonarticletable (for the extended article content, like the body text). - It updates related tables, such as
dede_arctype(to update category counts) anddede_arctiny(for a lightweight article listing).
- It executes SQL queries to insert a new record into the
- Response: After a successful save, it redirects the user back to a relevant page, often the article list or the editor for the newly created/updated article, usually with a success message.
Key Variables and Parameters
When archives_do.php is called, it relies on several key parameters sent via the POST request:

dopost: The most important parameter. It defines the action.save: Save a new article.edit: Save an existing article (update).makehtml: (Less common now) Generate an HTML file for the article.move: Move the article to another channel.copy: Copy the article.delete: Delete the article.
aid: The Article ID. This is crucial for identifying which article to update, move, or delete. It's not needed for a new article (save).typeid: The Category ID. This determines where the article belongs.,body,description, etc.: The actual content of the article submitted from the form.arcrank: An integer representing the article's status (e.g., -1 for draft, 0 for published, 1 for pending review).
Code Structure (Simplified)
The code structure of archives_do.php is typically a large switch statement that branches based on the dopost value.
<?php
require_once(dirname(__FILE__)."/config.php");
// Check login and permissions
CheckPurview('a_New,a_AccEdit,a_MyEdit');
// Get the action from the form
$dopost = isset($dopost) ? trim($dopost) : '';
// Main switch statement to handle different actions
switch($dopost)
{
case 'save':
// Logic for saving a NEW article
// 1. Validate input
// 2. Set default values (like arcrank, senddate)
// 3. Call functions to insert data into `dede_archives` and `dede_addonarticle`
// 4. Update category counts
// 5. Redirect with success message
break;
case 'edit':
// Logic for EDITING an existing article
// 1. Check if 'aid' is provided
// 2. Get existing article data
// 3. Update the data in `dede_archives` and `dede_addonarticle`
// 4. Update category counts if category changed
// 5. Redirect with success message
break;
case 'move':
// Logic for MOVING an article to another channel
// 1. Check new channel and category IDs
// 2. Update the article's typeid and channel in the database
// 3. Redirect
break;
case 'delete':
// Logic for DELETING an article
// 1. Get the article ID
// 2. Call a function (like `DelArc()`) to delete the article from all related tables
// 3. Redirect
break;
// ... other cases like 'copy', 'makehtml'
default:
// If no valid dopost is provided, do nothing or show an error.
break;
}
?>
Importance in the DedeCMS Ecosystem
- Central Hub for Content Management: It's the backbone of the content creation workflow in the DedeCMS admin panel. Without it, admins could not create or modify articles.
- Data Integrity: It enforces rules and ensures that data is saved in the correct format to the correct database tables, maintaining the integrity of the content system.
- Integration Point: It integrates with other DedeCMS systems, such as:
- The Model Class (
/include/archives.class.php): This class contains the core functions for adding, editing, and deleting articles (e.g.,SendHTML(),SetArchives(),UpDateArt()) thatarchives_do.phpcalls. - The Channel System: It respects the rules of different content channels (Articles, Downloads, Images, etc.).
- The Template System: It ensures that articles saved can be correctly displayed by the front-end templates.
- The Model Class (
Modern Context (DedeCMS 5.7 & V57)
While the principles remain the same, in newer versions of DedeCMS, the architecture has evolved. The core logic has been refactored into more object-oriented classes, and the file handling might be slightly different. However, archives_do.php still serves the same fundamental purpose and is a critical file for anyone looking to understand or customize the DedeCMS backend.

