Hongmu Notes
Home Program Notes In Empire CMS' Dynamic Mode, thousands of articles can be scheduled for automated publishing without any manual intervention.
Program Notes Empire cms

In Empire CMS' Dynamic Mode, thousands of articles can be scheduled for automated publishing without any manual intervention.

In Empire CMS' Dynamic Mode, thousands of articles can be scheduled for automated publishing without any manual intervention.

I previously examined the review functionality of Empire CMS; for some unknown reason, when I published an article on Empire CMS with the setting configured as "Not Reviewed," it was automatically reviewed shortly thereafter – simply troublesome!

To avoid wasting too much time, I didn't delve into it carefully!

I need to use the review function again – this is really giving me a headache!

With tens of millions of articles to publish on Trainhead, getting them approved can be quite cumbersome!

So, after doing some research, I adopted a different approach!

I don't need the review feature, yet I can still have my website display the latest articles every day!

Problem Analysis

1. For EmpireCMS templates: when generating tags, set the publication date!

We start by checking the release time: if the release time is earlier than the current time, then invoke the function.

For example, if I set an article's publication date to tomorrow, the tag will not trigger for that article yet; it will only be triggered at the specified time tomorrow!

Additional SQL conditions:newstime <= '.time().'

If you don't want to manually add SQL conditions every time, you can refer to this article: <Empire CMS modifies PHP and directly sets the article calling conditions that are less than the article publishing time (newstime)

ad1a1b7183102738

2. Use PHP to modify the publication dates in the Empire Data Table – to allow all tens of millions of articles to have their publication dates set, I wrote two separate PHP scripts!

The first PHP script is responsible for reading all articles from the entire table and generating the corresponding publication dates.

The second PHP script is responsible for setting the scheduled publication times for articles in the database – up to 100 articles can be updated at a time!

This allows for the efficient setting of time parameters without placing a significant burden on the server.

First PHP code

 隐藏内容:评论后查看
<?php
require('e/class/connect.php');        //引入数据库配置文件和公共函数文件
require('e/class/db_sql.php');        //引入数据库操作文件
$link=db_connect();                //连接MYSQL
$empire=new mysqlquery();        //声明数据库操作类
$sql=$empire->query("select id,title from {$dbtbpre}ecms_news");        //查询新闻表最新10条记录

$num = 10;
$i = 1;
$n = 1;
$s = 1;
$newstime = strtotime("2023-8-21 6:20:30");
while($r=$empire->fetch($sql))        //循环获取查询记录
{
    $br = '';
    $time = $num;
    if($num==1){
        if($s==0){
            $s = 1; 
            $n++;
        }
        $num = 10 + $n;
        $br = "<hr style='color:red'>";
        $s--;
        $newstime+=86400;
    }
    
    echo"{$i}标题:".$r['title']."-----{$time}---{$newstime}---".date("Y-m-d H:i:s",$newstime)."<br>{$br}";
    //  echo"{$i}--".$r['id']."--{$time}|{$br}";
    // echo $sqlUp = "UPDATE `phome_ecms_news` SET `newstime` = '{$newstime}' WHERE `id` = {$r['id']};";
    $array[] = array($r['id'],$newstime);
    $empire->query1($sqlUp);
    $i++;
    $num--;
}

file_put_contents("定时发布.json", json_encode($array));

db_close();                        //关闭MYSQL链接
$empire=null;                        //注消操作类变量
?>

Second PHP code

 隐藏内容:评论后查看
<?
$jsonFile = "定时发布.json";
$array = json_decode(file_get_contents($jsonFile),true);

if(empty($array)){
    die("已发布完成");
}

function getSequentialElements(&$array, $quantity) {
    // 检查数组长度和需求数量
    $arrayLength = count($array);
    if ($arrayLength <= $quantity) {
        $result = $array;
        $array = array_slice($array, $arrayLength);
        return $result; // 数组长度小于或等于需求数量,直接返回整个数组
    }

    // 从原数组中顺序取出指定数量的元素,并将其从原数组中删除
    $result = array_slice($array, 0, $quantity);
    $array = array_slice($array, $quantity);

    return $result;
}

$randomElements = getSequentialElements($array, 100);

require('e/class/connect.php');        //引入数据库配置文件和公共函数文件
require('e/class/db_sql.php');        //引入数据库操作文件
$link=db_connect();                //连接MYSQL
$empire=new mysqlquery();        //声明数据库操作类

$n=1;
foreach($randomElements as $v){
    $sql = "UPDATE `phome_ecms_news` SET `newstime` = '{$v[1]}' WHERE `id` = {$v[0]};";
    if($empire->query($sql)){
        echo "{$n}成功设置定时发布,文章ID:$v[0],发布时间:".date("Y-m-d H:i:s",$v[1])."<br>";
    
        $n++;
    }
}

file_put_contents($jsonFile,json_encode($array));

db_close();                        //关闭MYSQL链接
$empire=null;                        //注消操作类变量
?>

<meta http-equiv="refresh" content="0;">

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Empire CMS database statement & SQL statement format

Empire CMS database statement & SQL statement format Program Notes Empire cms

Introduction to Imperial CMS extended SQL program writing, basic examples of Imperial CMS database statements & SQL statement formats: Note: The following examples are based on placing PHP files in the system root directory. Example 1: Connect to MYSQL program. (a.php)<?php require('e/class/connect.php'); //Introduce database configuration files and public function files requ…
👁 351
Empire CMS obtains the system COOKIE variable function getcvar()

Empire CMS obtains the system COOKIE variable function getcvar() Program Notes Empire cms

Get the system COOKIE variable function syntax: getcvar($var,$ecms) Description: $var: is the variable name $ecms: 0 is to set the foreground COOKIE variable, 1 is to set the background COOKIE variable. This parameter can be omitted and defaults to 0. Usage example: getcvar('mlusername'), get the user name of the front-end login member getcvar('loginu...
👁 295
Empire CMS smart label call field collection

Empire CMS smart label call field collection Program Notes Empire cms

Collect and classify all fields that support smart tag calls into Empire CMS smart tags: [e:loop={column ID/topic ID, number of items displayed, operation type, only display pictures with titles, additional SQL conditions, display sorting}] Template code content [/e:loop] Calling time: <?=date('m-d',$bqr[newstime])?> <?=dat…
👁 3749

Recommended reading

(Adaptive Mobile Version) Brown Furniture Decoration PBootCMS Website Template – Download Responsive Furniture & Building Materials Website Source Code: 0868

(Adaptive Mobile Version) Brown Furniture Decoration PBootCMS Website Template – Download Responsive Furniture & Building Materials Website Source Code: 0868 Practical Collection pbootcms Template

A responsive PbootCMS website template for brown furniture decoration and building materials businesses, supporting mobile access. The warm, wood-inspired design is ideal for showcasing furniture products, interior design projects, and building materials trade opportunities. It helps furniture and building materials companies promote their brands online and attract both renovation companies and consumers. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.c...
👁 41
(Adaptive Mobile Version) HTML5 Blue Wide-Screen Clean & Eco-Friendly Tech Energy pbootCMS Corporate Website Template – Responsive Blue Group Universal Website Source Code Download: 0201

(Adaptive Mobile Version) HTML5 Blue Wide-Screen Clean & Eco-Friendly Tech Energy pbootCMS Corporate Website Template – Responsive Blue Group Universal Website Source Code Download: 0201 Practical Collection pbootcms Template

This adaptive HTML5 corporate template for mobile devices – featuring a blue wide-screen design with eco-friendly technology and energy-themed themes, powered by PbootCMS – employs a responsive design approach. Its modern, tech-driven aesthetic makes it ideal for companies specializing in sustainable energy solutions or large corporations seeking to showcase their brand identity and business segments. It is an excellent choice for businesses looking to create an international, high-tech branded official website. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: ww...
👁 68
For a MySQL database containing time-based fields, what should be taken into account? What data type is recommended?

For a MySQL database containing time-based fields, what should be taken into account? What data type is recommended? Language Notes mySql

When designing data types for time-based fields, the following aspects should be considered: Precision: Determine the required time precision for storage—e.g., year, month, day, hour, minute, second, millisecond, etc.; Time zone: Account for the time zone used for storage—e.g., store local time or UTC time, etc.; Data length: Ensure that the selected data type has a sufficient length to accommodate the required data. Based on these considerations, the following data types are suitable for storing time-based fields:...
👁 177
Marketing-oriented eco-friendly shell powder ecological coating website template – 1072

Marketing-oriented eco-friendly shell powder ecological coating website template – 1072 Practical Collection Yiyou template

This EyouCMS template is ideal for environmental protection companies specializing in shell powder eco-coatings; its eco-friendly design style effectively showcases shell powder coating products, application results, and project cases. It helps coating enterprises promote green building materials online and attract customers in the home decoration and construction sectors. Template Demo | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | Eyou...
👁 58
Responsive sheet metal equipment manufacturing website template 0373

Responsive sheet metal equipment manufacturing website template 0373 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the sheet metal equipment manufacturing industry, featuring a professional industrial design style that effectively showcases sheet metal equipment products, manufacturing processes, technical specifications, and industrial applications. It enables sheet metal manufacturing enterprises to present their products online and attract industrial customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 40
(Adaptive mobile version) Blue personal technology blog website – PBootCMS template; Responsive wide-screen, professional news blog website source code – Download at 0869

(Adaptive mobile version) Blue personal technology blog website – PBootCMS template; Responsive wide-screen, professional news blog website source code – Download at 0869 Practical Collection pbootcms Template

A blue, responsive website template built with PbootCMS, ideal for technical bloggers to share code, technical articles, and personal insights. It helps technical bloggers build their personal brand and gain industry influence online. Template Demo | Installation Instructions | Website Admin Panel: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: Pbo...
👁 48