[EventCalendar] Re: Get Schedule: Can dates be formatted differently?

Dr. Peter Troxler peter.troxler at gmx.net
Thu Jun 28 16:51:33 UTC 2007


Hi Karl & everybody

I played around with eventcalendar (3.1.1.rc1) to add custom  
formatting to the schedule via the admin panel.

Below are the diffs for eventcalendar3.php, template-functions.php,  
options.php and admin.php
po/mo files would be affected by these changes too but I was too lazy  
to do anything about it right now

I've not tested it properly on different platforms (will do mid june  
when I have access to a win machine again) ... it works from my  
integration test install (this is a wp 2.1.3 install) <http:// 
www.scope34.org/test/>,

see it in action e.g. <http://www.scope34.org/test/content/aktuell/ 
kalender/> and <http://www.scope34.org/test/content/aktuell/kalender/? 
ec3_before=today>

it's not tested with the calendar and what it does to it, however

as usual, 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, etc. p.p.

cheers

/ Peter


> Hi there, Great plugin :) Is there a way I can format what is  
> produced from using: In particular I want to format the date  
> display differently (use June instead of Jun) and also when there  
> is an event for just one day I wondered why a ; and not a full stop  
> is added at the end of the date. Here is a link to one such event:  
> http://www.elyonline.co.uk/archives/2007/06/05/mediaeval-baebes- 
> ely/ -- Regards Karl


### diff for eventcalendar3.php
--- eventcalendar3.php
+++ eventcalendar3.php
@@ -516,7 +516,7 @@
function ec3_filter_the_content(&$post_content)
{
-  return ec3_get_schedule() . $post_content;
+  return ec3_get_schedule(get_settings 
('ec3_date_format'),get_settings('ec3_time_format'),html_entity_decode 
(get_settings('ec3_format_single')),html_entity_decode(get_settings 
('ec3_format_range')),html_entity_decode(get_settings 
('ec3_format_wrapper')),html_entity_decode(get_settings 
('ec3_date_time_separator'))) . $post_content;
}
@@ -545,7 +545,7 @@
    if($post->ec3_schedule)
    {
-    $schedule=ec3_get_schedule('%s; ',"%1\$s %3\$s %2\$s. ",'[ %s] ');
+    $schedule=ec3_get_schedule('','','%s; ',"%1\$s %3\$s %2\$s.  
",'[ %s] ');
      $text=$schedule.$text;
    }
### eof


### diff for template-functions.php
--- template-functions.php
+++ template-functions.php
@@ -453,17 +453,15 @@
    echo "</ul>\n";
}
-define('EC3_DEFAULT_FORMAT_SINGLE','<tr><td colspan="3">%s</td></tr>');
-define('EC3_DEFAULT_FORMAT_RANGE','<tr><td class="ec3_start">%1$s</td>'
- . '<td class="ec3_to">%3$s</td><td class="ec3_end">%2$s</td></tr>');
-define('EC3_DEFAULT_FORMAT_WRAPPER','<table class="ec3_schedule">%s</ 
table>');
-
/** Formats the schedule for the current post.
   *  Returns the HTML fragment as a string. */
function ec3_get_schedule(
-  $format_single =EC3_DEFAULT_FORMAT_SINGLE,
-  $format_range  =EC3_DEFAULT_FORMAT_RANGE,
-  $format_wrapper=EC3_DEFAULT_FORMAT_WRAPPER
+  $date_format,
+  $time_format,
+  $format_single,
+  $format_range,
+  $format_wrapper,
+  $date_time_separator
)
{
    global $ec3,$post;
@@ -471,8 +469,6 @@
    if(!$post || !$post->ec3_schedule)
        return '';
    $result='';
-  $date_format=get_settings('date_format');
-  $time_format=get_settings('time_format');
    $current=false;
    foreach($post->ec3_schedule as $s)
    {
@@ -499,7 +495,7 @@
        {
          $current=$date_start;
          $result.=sprintf($format_range,
-          "$date_start $time_start","$date_end $time_end",__ 
('to','ec3'));
+          "$date_start$date_time_separator$time_start","$date_end 
$date_time_separator$time_end",__('to','ec3')); // here we would want  
to add $date_time_separator somehow somewhere
        }
        else
        {
@@ -507,6 +503,7 @@
          {
            $current=$date_start;
            $result.=sprintf($format_single,$date_start);
+          $result.=$date_time_separator;
          }
          if($time_start==$time_end)
            $result.=sprintf($format_single,$time_start);
@@ -521,12 +518,15 @@
/** Echos the schedule for the current post. */
function ec3_the_schedule(
-  $format_single =EC3_DEFAULT_FORMAT_SINGLE,
-  $format_range  =EC3_DEFAULT_FORMAT_RANGE,
-  $format_wrapper=EC3_DEFAULT_FORMAT_WRAPPER
+  $date_format,
+  $time_format,
+  $format_single,
+  $format_range,
+  $format_wrapper,
+  $date_time_separator
)
{
-  echo ec3_get_schedule($format_single,$format_range,$format_wrapper);
+  echo ec3_get_schedule($date_format,$time_format,$format_single, 
$format_range,$format_wrapper,$date_time_separator);
}
?>
### eof


### diff for options.php
--- options.php
+++ options.php
@@ -65,6 +65,18 @@
    var $hide_logo;
    /** Display event box within post. DEFAULT=0 */
    var $hide_event_box;
+  /** Format of date in event box within post. DEFAULT is WP setting */
+  var $date_format;
+  /** Format of time in event box within post. DEFAULT is WP setting */
+  var $time_format;
+  /** Format of event with only start time in event box within post.  
DEFAULT='<tr><td colspan="3">%s</td></tr>' */
+  var $format_single;
+  /** Format of event with start/end time in event box within post.  
DEFAULT='<tr><td class="ec3_start">%1$s</td><td class="ec3_to">%3$s</ 
td><td class="ec3_end">%2$s</td></tr>' */
+  var $format_range;
+  /** Format of wrapper of event box within post. DEFAULT='<table  
class="ec3_schedule">%s</table>' */
+  var $format_wrapper;
+  /** String between date and time DEFAULT=";&nbsp;" */
+  var $date_time_separator;
    /** Use advanced post behaviour? DEFAULT=0 */
    var $advanced;
    /** Position navigation links or hide them. DEFAULT=0 */
@@ -99,6 +111,12 @@
      $this->read_day_length();
      $this->read_hide_logo();
      $this->read_hide_event_box();
+    $this->read_date_format();
+    $this->read_time_format();
+    $this->read_format_single();
+    $this->read_format_range();
+    $this->read_format_wrapper();
+    $this->read_date_time_separator();
      $this->read_advanced();
      $this->read_navigation();
      $this->read_disable_popups();
@@ -148,6 +166,42 @@
    {
      $this->hide_event_box=intval(get_settings('ec3_hide_event_box'));
    }
+  function read_date_format()
+  {
+    $this->date_format=(get_settings('ec3_date_format'));
+    if($this->date_format=='')
+        $this->date_format=get_settings('date_format');
+  }
+  function read_time_format()
+  {
+    $this->time_format=(get_settings('ec3_time_format'));
+    if($this->time_format=='')
+        $this->time_format=get_settings('time_format');
+  }
+  function read_format_single()
+  {
+    $this->format_single=(get_settings('ec3_format_single'));
+    if($this->format_single=='')
+        $this->format_single=htmlspecialchars('<tr><td colspan="3">% 
s</td></tr>', ENT_QUOTES);
+  }
+  function read_format_range()
+  {
+    $this->format_range=(get_settings('ec3_format_range'));
+    if($this->format_range=='')
+        $this->format_range=htmlspecialchars('<tr><td  
class="ec3_start">%1$s</td><td class="ec3_to">%3$s</td><td  
class="ec3_end">%2$s</td></tr>', ENT_QUOTES);
+  }
+  function read_format_wrapper()
+  {
+    $this->format_wrapper=(get_settings('ec3_format_wrapper'));
+    if($this->format_wrapper=='')
+        $this->format_wrapper=htmlspecialchars('<table  
class="ec3_schedule">%s</table>', ENT_QUOTES);
+  }
+  function read_date_time_separator()
+  {
+    $this->date_time_separator=(get_settings 
('ec3_date_time_separator'));
+    if($this->date_time_separator=='')
+        $this->date_time_separator=';&nbsp;';
+  }
    function read_advanced()
    {
      $this->advanced=intval(get_settings('ec3_advanced'));
@@ -227,6 +281,54 @@
        $this->read_hide_event_box();
      }
    }
+  function set_date_format($val)
+  {
+    if($this->date_format!=$val)
+    {
+      update_option('ec3_date_format',$val);
+      $this->read_date_format();
+    }
+  }
+  function set_time_format($val)
+  {
+    if($this->time_format!=$val)
+    {
+      update_option('ec3_time_format',$val);
+      $this->read_time_format();
+    }
+  }
+  function set_format_single($val)
+  {
+    if($this->format_single!=$val)
+    {
+      update_option('ec3_format_single',$val);
+      $this->read_format_single();
+    }
+  }
+  function set_format_range($val)
+  {
+    if($this->format_range!=$val)
+    {
+      update_option('ec3_format_range',$val);
+      $this->read_format_range();
+    }
+  }
+  function set_format_wrapper($val)
+  {
+    if($this->format_wrapper!=$val)
+    {
+      update_option('ec3_format_wrapper',$val);
+      $this->read_format_wrapper();
+    }
+  }
+  function set_date_time_separator($val)
+  {
+    if($this->date_time_separator!=$val)
+    {
+      update_option('ec3_date_time_separator',$val);
+      $this->read_date_time_separator();
+    }
+  }
    function set_advanced($val)
    {
      if($this->advanced_setting!=$val)
### eof


### diff for admin.php
--- admin.php
+++ admin.php
@@ -415,6 +415,18 @@
            $ec3->set_hide_logo( intval($_POST['ec3_hide_logo']) );
        if(isset($_POST['ec3_hide_event_box']))
            $ec3->set_hide_event_box( intval($_POST 
['ec3_hide_event_box']) );
+      if(isset($_POST['ec3_date_format']))
+          $ec3->set_date_format(attribute_escape($_POST 
['ec3_date_format']) );
+      if(isset($_POST['ec3_time_format']))
+          $ec3->set_time_format(attribute_escape($_POST 
['ec3_time_format']));
+      if(isset($_POST['ec3_format_single']))
+          $ec3->set_format_single(attribute_escape($_POST 
['ec3_format_single']));
+      if(isset($_POST['ec3_format_range']))
+          $ec3->set_format_range(attribute_escape($_POST 
['ec3_format_range']));
+      if(isset($_POST['ec3_format_wrapper']))
+          $ec3->set_format_wrapper(attribute_escape($_POST 
['ec3_format_wrapper']));
+      if(isset($_POST['ec3_date_time_separator']))
+          $ec3->set_date_time_separator(attribute_escape($_POST 
['ec3_date_time_separator']));
        if(isset($_POST['ec3_advanced']))
            $ec3->set_advanced( intval($_POST['ec3_advanced']) );
        if(isset($_POST['ec3_navigation']))
@@ -462,8 +474,42 @@
           </select>
          </td>
         </tr>
+
+       <tr valign="top">
+        <th width="33%" scope="row"><?php _e('Format schedule within  
posts','ec3'); ?>:</th>
+        <td>
+          <table>
+            <tr valign="top">
+              <th><?php _e('Date','ec3'); ?>:</th>
+			  <td><input type="text" name="ec3_date_format" value="<?php echo  
$ec3->date_format; ?>" /><br />
+			  <em><?php _e('Date format according to php specs, see <a  
href="http://codex.wordpress.org/ 
Formatting_Date_and_Time">documentation on date formatting</ 
a>.','ec3'); ?></em></td>
+            </tr><tr valign="top">
+              <th><?php _e('Time','ec3'); ?>:</th>
+			  <td><input type="text" name="ec3_time_format" value="<?php echo  
$ec3->time_format; ?>" /><br />
+			  <em><?php _e('Time format according to php specs, see <a  
href="http://codex.wordpress.org/ 
Formatting_Date_and_Time">documentation on time formatting</ 
a>.','ec3'); ?></em></td>
+            </tr><tr valign="top">
+              <th><?php _e('Sinlge','ec3'); ?>:</th>
+			  <td><input type="text" size="100" name="ec3_format_single"  
value="<?php echo $ec3->format_single; ?>" /><br />
+			  <em><?php _e('Events that only a start time (no duration) are  
generated using this template. %s is a placeholder for the  
time.','ec3'); ?></em></td>
+            </tr><tr valign="top">
+              <th><?php _e('Range','ec3'); ?>:</th>
+			  <td><input type="text" size="100" name="ec3_format_range"  
value="<?php echo $ec3->format_range; ?>" /><br />
+			  <em><?php _e('Events that have a start and end time are  
generated using this template. %1$s is a placeholder for the start,  
and %2$s is a placeholder for the end time. %3$s is a placeholder for  
the word "to", which may be translated if you are using a localised  
version of EventCalendar.','ec3'); ?></em></td>
+            </tr><tr valign="top">
+              <th><?php _e('Wrapper','ec3'); ?>:</th>
+			  <td><input type="text" size="100" name="ec3_format_wrapper"  
value="<?php echo $ec3->format_wrapper; ?>" /><br />
+			  <em><?php _e('A template for the whole result. The default  
generates a table, but you may prefer to have it generate a div, or  
leave it blank. %s is a placeholder.','ec3'); ?></em></td>
+			</tr>
+            </tr><tr valign="top">
+              <th><?php _e('Date/Time-Separator','ec3'); ?>:</th>
+			  <td><input type="text" size="100"  
name="ec3_date_time_separator" value="<?php echo $ec3- 
 >date_time_separator; ?>" /><br />
+			  <em><?php _e('A separator that is put between date and time,  
e.g. the "; " in June 28, 2007; 10:30 am. You have to enter non- 
breaking spaces with your keyboard combination (alt-space on a Mac),  
&amp;nbsp; will not work.','ec3'); ?></em></td>
+			</tr>
+		  </table>
+        </td>
+       </tr>
-      <tr valign="top">
+       <tr valign="top">
         <th width="33%" scope="row"><?php _e('Show events as blog  
entries','ec3'); ?>:</th>
         <td>
          <select name="ec3_advanced">
### eof




More information about the EventCalendar mailing list