[EventCalendar] making display functions pluggable

Jeremy Clarke jer at simianuprising.com
Thu Jan 29 16:25:09 UTC 2009


hey guys, I love the plugin, its definitely the best thing of its kind around.

I was wondering what you thought of the idea of making the
display-specific functions (like ec3_get_schedule) pluggable similar
to how wp handles functions like get_avatar and authentication. It
would be pretty easy to accomplish, you just need to add existence
checks around the function definitions:

 if (!function_exists('ec3_get_schedule')) :
  function ec3_get_schedule($vars) {
    ...
 } // ec3_get_schedule()

 endif; // function_exists('ec3_get_schedule')

It would let people extend the plugin to their taste (I set mine up to
show a little daily calendar style thing on posts instead of the
current display) without having to change anything in teh core file,
which is obviously valuable for upgrade reasons.

Thoughts on this? I'd love it personally.

I also attatched a txt file of my version of the ec3_get_schedule()
function in case you want to consider it as a core change to the
plugin :)

Thanks for the great plugin!


-- 
Jeremy Clarke
Code and Design | globalvoicesonline.org
-------------- next part --------------
function ec3_get_schedule(
  $format_single =EC3_DEFAULT_FORMAT_SINGLE,
  $format_range  =EC3_DEFAULT_FORMAT_RANGE,
  $format_wrapper=EC3_DEFAULT_FORMAT_WRAPPER
)
{
  global $ec3,$post;
	$format_wrapper = "\n\t".'<div class="ec3_schedule">%s'."\t".'</div>'."\n";
	$format_range = '%1$s' . '%3$s'.'%2$s';
	$format_single = '%s';
  // Should have been set by ec3_filter_the_posts()
  if(!$post || !$post->ec3_schedule)
      return '';
  $result='';
  $date_format=get_settings('date_format');
  $time_format=get_settings('time_format');
  $time_format= "g a";
  $current=false;
  foreach($post->ec3_schedule as $s)
  {
    //$date_start=mysql2date($date_format,$s->start);
 //   $date_end  =mysql2date($date_format,$s->end);
    $time_start= "\t\t".'<div class="eventtime">'.mysql2date($time_format,$s->start).'</div>'."\n";
    $time_end  ="\t\t".'<div class="eventtime">'.mysql2date($time_format,$s->end).'</div>'."\n";
    
     	$date_end.= "\n\t\t".'<div class="eventmonth">'.mysql2date('M',$s->end).'</div>'."\n";
      	$date_end.= "\t\t".'<div class="eventday">'.mysql2date('d',$s->end).'</div>'."\n";
      	$date_end.= "\t\t".'<div class="eventyear">'.mysql2date('Y',$s->end).'</div>'."\n";
      	$date_start.= "\n\t\t".'<div class="eventmonth">'.mysql2date('M',$s->start).'</div>'."\n";
      	$date_start.= "\t\t".'<div class="eventday">'.mysql2date('d',$s->start).'</div>'."\n";
      	$date_start.= "\t\t".'<div class="eventyear">'.mysql2date('Y',$s->start).'</div>'."\n";


    if($s->allday)
    {
      if($date_start!=$date_end)
      {
        $result.=sprintf($format_range,$date_start,$date_end,__('to','ec3'));
      }
      elseif($date_start!=$current)
      {
        $current=$date_start;
        $result.=sprintf($format_single,$date_start);
      }
    }
    else
    {
      if($date_start!=$date_end)
      {
        $current=$date_start;
        $result.=sprintf($format_range, "$date_start $time_start","$date_end $time_end",__(' to <br /> ','ec3'));
      }
      else
      {
        if($date_start!=$current)
        {
          $current=$date_start;
          $result.=sprintf($format_single,$date_start);
        }
        if($time_start==$time_end)
          $result.=sprintf($format_single,$time_start);
        else
          $result.=sprintf($format_range,$time_start,$time_end,__(' to <br />','ec3'));
      }
    }
  }
  return sprintf($format_wrapper,$result);
}


More information about the EventCalendar mailing list