We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25106
    • 6 Posts
    It’s exactly what I’m looking for tuatara ! Could you send me this plugin ?
      • 6726
      • 7,075 Posts
      Better yet, share it with the community wink
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 30765
        • 66 Posts
        Quote from: ripper at Dec 05, 2007, 05:12 PM

        It’s exactly what I’m looking for tuatara ! Could you send me this plugin ?

        This is it below (I had published it before but I think that was in the commercial support forum). I’d put it on the repository, but I’m not a million percent convinced it handles all time zones correctly ... although it works fine for me, 19 zones from the web server. Also there are a couple of pages that should not have pub_date set, and I’m not certain yet which ones I need to work around. I know the home page can’t have a pub_date; presume others like the error page are the same.

        If anyone has any knowledge about the above, I’ll put it on the repository ... perhaps a future version of MODx will make it unnecessary. It’s amazing to me that I can add this kind of core functionality in a simple plugin without hacking at the MODx core at all. Bravo to the MODx devs!

        (And don’t forget to check the OnDocFormSave and OnDocPublished events in the plugin config.)

        [Edit: just to be clear: with this plugin installed, you should be able to use pub_date in your ditto calls. Obviously it won’t have any effect on already-published articles.]


        Cheers
        Matt

        Plugin: Correct Dates
        Makes sure pub_date and publishedon are correct

        /*
         * CorrectDates
         * When a document is published or set to be published,
         * always populate publishedon and pub_date variables correctly
         *
         * Configuration:
         * check the OnDocFormSave and OnDocPublished events
         *
         * Version 0.1, October 2007
         *
         * Version 0.1.1, November 2007
         * Does nothing if page is start page (which can't have publish dates)
         *
         */
        
        function normaliseDates($docid) {
        	global $modx;
        	$dates = $modx->getPageInfo($docid, 0, 'publishedon,pub_date');
        	$pub_date = $dates['pub_date'];
        	$publishedon = $dates['publishedon'];
        	$dbtable = $modx->getFullTableName('site_content');
        	if($publishedon && !$pub_date) {
        		// set pub_date to the same as publishedon
        		$modx->db->update('pub_date=' . $publishedon, $dbtable, 'id=' . $docid);
        	} elseif ($pub_date && !$publishedon) {
        		// set publishedon to now
        		$modx->db->update('publishedon=' . time(), $dbtable, 'id=' . $docid);		
        	}
        }
        
        $e = &$modx->Event;
        switch($e->name) {
        	case 'OnDocFormSave':
        		if ($id != $modx->config['site_start']) normaliseDates($id);
        		break;
        	case 'OnDocPublished':
        		if ($id != $modx->config['site_start']) normaliseDates($docid);
        		break;
        }
        

          • 6726
          • 7,075 Posts
          Great !
          Thanks for sharing I’ll try it out and report smiley
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 25106
            • 6 Posts
            Works perfect for me Thanks tuatara! Great job!