dede archives_do.php有何作用与风险?

99ANYc3cd6
预计阅读时长 24 分钟
位置: 首页 DEDE建站 正文

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

dede archives_do.php
(图片来源网络,侵删)

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

  1. 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.
  2. Form Submission: The form data (title, body, author, etc.) is sent via a POST request to archives_do.php. The request also includes hidden fields like dopost (which specifies the action, e.g., save) and aid (the article ID if it's an edit).
  3. archives_do.php Execution:
    • 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 dopost variable 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.
  4. 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.
  5. Database Update:
    • It executes SQL queries to insert a new record into the dede_archives table (for the main article info) and the dede_addonarticle table (for the extended article content, like the body text).
    • It updates related tables, such as dede_arctype (to update category counts) and dede_arctiny (for a lightweight article listing).
  6. 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:

dede archives_do.php
(图片来源网络,侵删)
  • 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()) that archives_do.php calls.
    • 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.

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.

dede archives_do.php
(图片来源网络,侵删)
-- 展开阅读全文 --
头像
织梦dede模板自带地图如何优化?
« 上一篇 2025-12-01
HTML5织梦后台模板是否适配高端需求?
下一篇 » 2025-12-01
取消
微信二维码
支付宝二维码

目录[+]