Phpcms V9: Set the timed release program code

Source: Internet
Author: User
Tags php file


Phpcms v9 itself does not regularly publish this function, which requires secondary development. You don't need to talk about the benefits of timed release, when we do not have time to update the site, there will be no more broken articles. For example, if we have no time to update the site during the Chinese New Year or holidays, we can write a good article in advance and let it automatically update it, there is such a good time mechanism in wordpress. The following summer blog will talk about how to implement regular publishing of articles in phpcms v9. This is a method seen on the pc Forum, if it feels good, share the code.

1. Modify the api/count. php file and end the code in the PHP statement?> Add the following code:


// Add timed release review function
$ Urlobj = pc_base: load_app_class ('URL', 'Content ');
$ Html = pc_base: load_app_class ('html', 'Content ');
 
$ Modelid = $ modelid? $ Modelid: intval ($ _ GET ['modelid']);
$ Content_db = $ content_db? $ Content_db: pc_base: load_model ('content _ Model ');
$ Content_db-> set_model ($ modelid );
$ Where = 'status = 1 and inputtime <= '. SYS_TIME;
$ R = $ content_db-> count ($ where );
If (! Empty ($ r) {// execute the update operation
$ Ids = $ content_db-> select ($ where, 'id, catid', $ r, '','', 'id ');
Foreach ($ ids AS $ kid => $ v ){
$ Catid = $ v ['catid'];
$ Id = $ kid;
$ R = $ content_db-> get_content ($ catid, $ id );
$ Urls = $ urlobj-> show ($ id, 0, $ catid, $ r ['inputtime'], $ r ['prefix'], $ r, 'ADD ');
If ($ urls ['content _ ishtml ']) $ html-> show ($ urls [1], $ urls ['data'], 0 );
$ Html-> index ();
$ Html-> create_relation_html ($ catid );
        }
$ Content_db-> update (array ('status' => 99), $ where );
        }

In this way, when updating the statistical code, we can publish the articles to be reviewed at a specified time.
2. Add the statistical code in the template on the article page:


<Script language = "JavaScript" src = "{APP_PATH} api. php? Op = count & id = {$ id} & modelid = {$ modelid} "> </script>

This statistical code has been added by default in the default template. Check the code so that when this JS is triggered when the article is browsed, the code added in the first step will be reviewed.

This timed editor thinks it is unreasonable. If no one can access it, it cannot be released on a regular basis. Therefore, we can use the timed task function on the server to implement timed automatic release very accurately.

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.