[EventCalendar] Ignore post_date when start set (corrected)

Dr. Peter Troxler peter.troxler at gmx.net
Thu Jul 19 08:15:26 UTC 2007


you'll obviously want to remove that "testing" bit in the sql UPDATE  
statement, sorry for the mess ... amended version below /pt

On 19-jul-2007, at 10:10, Dr. Peter Troxler wrote:

> On 19-jul-2007, at 8:45, Dr. Peter Troxler wrote:
>
>> Jake
>>
>> in your case it would probably be easiest to modify the plugin so  
>> it actually stores your start date also as the post date in your  
>> database ... might be most easily done with an additional plugin  
>> so you can still upgrade EC ;-)
>>
>> / pt
>>
>
>
> e.g. like that ... no guarantee ... it might well break your  
> complete wp installation or accelerate global warning
>
<?php
/*
Plugin Name: ec3_StartDateIsPostDate.php
Plugin URI: http://www.klapt.net/
Description: When activated, saves the post with post_date set to  
ec3_start_date if post is in event category
Version: 0.1
Author: Peter Troxler
Author URI: http://www.petertroxler.org
*/


// keep assholes out
	global $wp_version;
	if (!isset($wp_version)) die('Cheatin\', uh!?');
	
/*  Copyright 2007  Peter Troxler  (email: peter.troxler at gmail.com)

     This program is free software; you can redistribute it and/or  
modify
     it under the terms of the GNU General Public License as  
published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   
02111-1307  USA



     Purpose and intention -- What we do (readme)

     Jake said: Now I know exactly what I want... in ALL cases I'd  
like the post queries
	to ignore the post_date whenever the start is set.  In other words,  
if the post is
	an event I want to use the event dates exclusively but if the post  
is a regular post
	then I want to use the post's timestamp.
	I said: in your case it would probably be easiest to modify the  
plugin so it actually
	stores your start date also as the post date in your database ...  
might be most easily
	done with an additional plugin so you can still upgrade EC ;-)
	
	How I'd go about it:
	(1)
	-- find a filter hook "before save"
	-- replace the POST data accordingly
	-- save
	or:
	(2)
	-- find an action hook "just after save"
	-- replace data in the DB accordingly
	(3)
	Writing this I wonder: could it be done while retrieving data thus  
making it easy to revert?
	This is probably not feasible since this would have to be "post SQL  
query" so we would need
	to "fix" the SQL query ...
	
	so option 3 is not an option
	option 1: I don't see a database write hook that would get applied  
to the post date
	
	remains option 2
*/


// the function that does it
	function ec3PDISD($post_ID) {
			
		global $wpdb, $_POST;
		$pre = $wpdb->prefix;
		
		// for lazyness let's just assume that we *do have all the $_POST  
data, i.e. also the ec3_start__
		// and that the post has already been saved ...
		// which from testing I no reasonable doubt that this actually is  
the case
		// so we just update the post_date in the wp_posts table
		
		// get the data from the $_POST (this comes from ec3, admin.php,  
lines ca. 195ff)
		
		// Find all of our parameters
	    $sched_entries=array();
	    $fields =array('start','end','allday','rpt');
	    foreach($_POST as $k => $v) {
			if(preg_match('/^ec3_(action|'.implode('|',$fields).')_(_?)([0-9]+) 
$/',$k,$match)) {
				$sid=intval($match[3]);
				if(!isset( $sched_entries[$sid] ))
					$sched_entries[ $sid ]=array('allday' => 0);
				$sched_entries[ $sid ][ $match[1] ] = $v;
			}
	    }

	    foreach($sched_entries as $sid => $vals)
	    {
	    	// Bail out if the input data looks suspect.
	    	if(!array_key_exists('action',$vals) || count($vals)<3)
	        	continue;
	    	// Save the value of 'action' and remove it. Leave just the  
column vals.
	    	$action=$vals['action'];
	    	unset($vals['action']);
	    	// If the action is create or update, we just use the first  
start date, whatever
	    	if( ! ($action=='delete' && $sid>0)) {
				$ec3PDISD = $vals['start'];
				continue;
			}
	    }

		// update the post
		
		$sql = "UPDATE " . $pre . "posts
					SET post_date = \"" . $ec3PDISD . "\"
					WHERE ID = \"" . $post_ID . "\"
					";
		$wpdb->query($sql);

		// that's it.
		
	}


// hook in
	add_action('save_post', 'ec3PDISD');

?>
>
> _______________________________________________
> Blog: http://wpcal.firetree.net/
> EventCalendar at firetree.net mailing list
> Unsubscribe: http://penguin.firetree.net/eventcalendar




More information about the EventCalendar mailing list