web/wp-content/plugins/event-calendar/template-functions.php
branchwordpress
changeset 123 561aa6d282f6
parent 109 03b0d1493584
equal deleted inserted replaced
112:fb7cd02b9848 123:561aa6d282f6
    67   return $result;
    67   return $result;
    68 }
    68 }
    69 
    69 
    70 
    70 
    71 /** Echos the event calendar navigation controls. */
    71 /** Echos the event calendar navigation controls. */
       
    72 /* modified by samuel huron 05/01/2010 */
    72 function ec3_get_calendar_nav($date,$num_months)
    73 function ec3_get_calendar_nav($date,$num_months)
    73 {
    74 {
    74   global $ec3;
    75   global $ec3;
    75   echo "<table class='nav'><tbody><tr>\n";
    76   echo "<table class='nav'><tbody><tr>\n";
    76 
    77 
    77   // Previous
    78   // Previous
    78   $prev=$date->prev_month();
    79   $prev=$date->prev_month();
    79   echo "\t<td id='prev'><a id='ec3_prev' href='" . $prev->month_link() . "'"
    80   echo "\t<td id='prev'><a id='ec3_prev' href='" . $prev->month_link() . "'"
    80      . '>&laquo;&nbsp;' . $prev->month_abbrev() . "</a></td>\n";
    81      . '>&laquo;&nbsp;' . $prev->month_abbrev() . "</a></td>\n";
    81 
    82   
    82   echo "\t<td><img id='ec3_spinner' style='display:none' src='" 
    83   // --------------------------------------------------------------------------
    83      . $ec3->myfiles . "/ec_load.gif' alt='spinner' />\n";
    84   // start modified by sam 
       
    85  
       
    86  /*
    84   // iCalendar link.
    87   // iCalendar link.
    85   $webcal=get_option('home') . "/?ec3_ical";
    88   $webcal=get_option('home') . "/?ec3_ical";
    86   // Macintosh always understands webcal:// protocol.
    89   // Macintosh always understands webcal:// protocol.
    87   // It's hard to guess on other platforms, so stick to http://
    90   // It's hard to guess on other platforms, so stick to http://
    88   if(strstr($_SERVER['HTTP_USER_AGENT'],'Mac OS X'))
    91   if(strstr($_SERVER['HTTP_USER_AGENT'],'Mac OS X'))
    89       $webcal=preg_replace('/^http:/','webcal:',$webcal);
    92       $webcal=preg_replace('/^http:/','webcal:',$webcal);
    90   echo "\t    <a id='ec3_publish' href='$webcal'"
    93   echo "\t    <a id='ec3_publish' href='$webcal'"
    91      . " title='" . __('Subscribe to iCalendar.','ec3') ."'>\n"
    94      . " title='" . __('Subscribe to iCalendar.','ec3') ."'>\n"
    92      . "\t     <img src='$ec3->myfiles/publish.gif' alt='iCalendar' />\n"
    95      . "\t     <img src='$ec3->myfiles/publish.gif' alt='iCalendar' />\n"
    93      . "\t    </a>\n";
    96      . "\t    </a>\n";*/
    94   echo "\t</td>\n";
    97   echo "\t</td>\n";
    95 
    98   // -------------------------------------------------------------------------- stop 
       
    99   
       
   100   
    96   // Next
   101   // Next
    97   $next=$date->plus_months($num_months);
   102   $next=$date->plus_months($num_months);
    98   echo "\t<td id='next'><a id='ec3_next' href='" . $next->month_link() . "'"
   103   echo "\t<td id='next'><a id='ec3_next' href='" . $next->month_link() . "'"
    99      . '>' . $next->month_abbrev() . "&nbsp;&raquo;</a></td>\n";
   104      . '>' . $next->month_abbrev() . "&nbsp;&raquo;</a></td>\n";
   100 
   105 
   204   global $ec3;
   209   global $ec3;
   205   //
   210   //
   206   // Table start.
   211   // Table start.
   207   $title=
   212   $title=
   208     sprintf(__('View posts for %1$s %2$s'),$date->month_name(),$date->year_num);
   213     sprintf(__('View posts for %1$s %2$s'),$date->month_name(),$date->year_num);
   209   echo "<table id='" . $date->month_id() . "'>\n<caption>"
   214   echo "<table id='" . $date->month_id() . "' >\n<caption>"
   210     . '<a href="' . $date->month_link() . '" title="' . $title . '">'
   215     . '<a href="' . $date->month_link() . '" title="' . $title . '">'
   211     . $date->month_name() . ' ' . $date->year_num . "</a></caption>\n";
   216     . $date->month_name() . ' ' . $date->year_num . "</a></caption>\n";
   212   echo $thead;
   217   echo $thead;
   213 
   218 
   214   //
   219   //
   271       . ($ec3->hide_logo? " style='display:none'>": ">")
   276       . ($ec3->hide_logo? " style='display:none'>": ">")
   272       . "<span class='ec3_ec'><span>EC</span></span></a></td>";
   277       . "<span class='ec3_ec'><span>EC</span></span></a></td>";
   273   elseif($pad)
   278   elseif($pad)
   274       echo "<td colspan='$pad' class='pad'>&nbsp;</td>";
   279       echo "<td colspan='$pad' class='pad'>&nbsp;</td>";
   275 
   280 
   276   echo "</tr>\n</tbody>\n</table>";
   281   echo "</tr>\n</tbody>\n</table> <!-- LA --> ";
   277 }
   282 }
   278 
   283 
   279 
   284 
   280 /** Template function. Call this from your template to insert the
   285 /** Template function. Call this from your template to insert the
   281  *  Event Calendar. */
   286  *  Event Calendar. */
   318     $next_month=$this_month->next_month();
   323     $next_month=$this_month->next_month();
   319     ec3_get_calendar_month($this_month,$calendar_days,$thead);
   324     ec3_get_calendar_month($this_month,$calendar_days,$thead);
   320     $this_month=$next_month;
   325     $this_month=$next_month;
   321   }
   326   }
   322 
   327 
       
   328   // ------------------------------
       
   329   //modified
       
   330 
       
   331   echo "</div>\n";
       
   332   
   323   // Display navigation panel.
   333   // Display navigation panel.
   324   if(1==$ec3->navigation)
   334   if(1==$ec3->navigation)
   325     ec3_get_calendar_nav(new ec3_Date(),$ec3->num_months);
   335     ec3_get_calendar_nav(new ec3_Date(),$ec3->num_months);
   326 
   336 
   327   echo "</div>\n";
   337   
   328 
       
   329   if(!$ec3->disable_popups)
   338   if(!$ec3->disable_popups)
   330     echo "\t<script type='text/javascript' src='"
   339     echo "\t<script type='text/javascript' src='"
   331     .    $ec3->myfiles . "/popup.js'></script>\n";
   340     .    $ec3->myfiles . "/popup.js'></script>\n";
   332 }
   341 }
   333 
   342 
   336  *  array. */
   345  *  array. */
   337 function ec3_format_str($format,$data)
   346 function ec3_format_str($format,$data)
   338 {
   347 {
   339   foreach($data as $k=>$v)
   348   foreach($data as $k=>$v)
   340       $format=str_replace("%$k%",$v,$format);
   349       $format=str_replace("%$k%",$v,$format);
       
   350 	 echo ("<!-- ".$k."".$v." -->");
   341   return $format;
   351   return $format;
   342 }
   352 }
   343 
   353 
   344 
   354 
   345 define('EC3_DEFAULT_TEMPLATE_EVENT','<a href="%LINK%">%TITLE% (%TIME%)</a>');
   355 define('EC3_DEFAULT_TEMPLATE_EVENT','<a href="%LINK%">%TITLE% (%TIME%)</a>');
   346 define('EC3_DEFAULT_TEMPLATE_DAY',  '%DATE%:');
   356 define('EC3_DEFAULT_TEMPLATE_DAY',  '%DATE% :');
   347 define('EC3_DEFAULT_DATE_FORMAT',   'j F');
   357 define('EC3_DEFAULT_DATE_FORMAT',   'j F');
   348 define('EC3_DEFAULT_TEMPLATE_MONTH','');
   358 define('EC3_DEFAULT_TEMPLATE_MONTH','');
   349 define('EC3_DEFAULT_MONTH_FORMAT',  'F Y');
   359 define('EC3_DEFAULT_MONTH_FORMAT',  'F Y');
   350 
   360 
   351 /** Template function. Call this from your template to insert a list of
   361 /** Template function. Call this from your template to insert a list of
   352  *  forthcoming events. Available template variables are:
   362  *  forthcoming events. Available template variables are:
   353  *   - template_day: %DATE% %SINCE% (only with Time Since plugin)
   363  *   - template_day: %DATE% %SINCE% (only with Time Since plugin)
   354  *   - template_event: %DATE% %TIME% %LINK% %TITLE% %AUTHOR%
   364  *   - template_event: %DATE% %TIME% %LINK% %TITLE% %AUTHOR%
   355  */
   365  */
   356 function ec3_get_events(
   366 
       
   367 // version racine
       
   368  function ec3_get_events(
   357   $limit,
   369   $limit,
   358   $template_event=EC3_DEFAULT_TEMPLATE_EVENT,
   370   $template_event=EC3_DEFAULT_TEMPLATE_EVENT,
   359   $template_day  =EC3_DEFAULT_TEMPLATE_DAY,
   371   $template_day  =EC3_DEFAULT_TEMPLATE_DAY,
   360   $date_format   =EC3_DEFAULT_DATE_FORMAT,
   372   $date_format   =EC3_DEFAULT_DATE_FORMAT,
   361   $template_month=EC3_DEFAULT_TEMPLATE_MONTH,
   373   $template_month=EC3_DEFAULT_TEMPLATE_MONTH,
   403      WHERE p.post_status='publish'
   415      WHERE p.post_status='publish'
   404        AND end>='$ec3->today' $and_before
   416        AND end>='$ec3->today' $and_before
   405      ORDER BY start $limit_numposts"
   417      ORDER BY start $limit_numposts"
   406   );
   418   );
   407 
   419 
       
   420   echo "<ul class='ec3_events'>";
   408   echo "<!-- Generated by Event Calendar v$ec3->version -->\n";
   421   echo "<!-- Generated by Event Calendar v$ec3->version -->\n";
   409   echo "<ul id='accordion'>";
   422   if($calendar_entries)
       
   423   {
       
   424     $time_format=get_option('time_format');
       
   425     $current_month=false;
       
   426     $current_date=false;
       
   427     $data=array();
       
   428     foreach($calendar_entries as $entry)
       
   429     {
       
   430       // To use %SINCE%, you need Dunstan's 'Time Since' plugin.
       
   431       if(function_exists('time_since'))
       
   432           $data['SINCE']=time_since( time(), ec3_to_time($entry->start) );
       
   433 
       
   434       // Month changed?
       
   435       $data['MONTH']=mysql2date($month_format,$entry->start);
       
   436       if((!$current_month || $current_month!=$data['MONTH']) && $template_month)
       
   437       {
       
   438         if($current_date)
       
   439             echo "</ul></li>\n";
       
   440         if($current_month)
       
   441             echo "</ul></li>\n";
       
   442         echo "<li class='ec3_list ec3_list_month'>"
       
   443         .    ec3_format_str($template_month,$data)."\n<ul>\n";
       
   444         $current_month=$data['MONTH'];
       
   445         $current_date=false;
       
   446       }
       
   447 
       
   448       // Date changed?
       
   449       $data['DATE'] =mysql2date($date_format, $entry->start);
       
   450       if((!$current_date || $current_date!=$data['DATE']) && $template_day)
       
   451       {
       
   452         if($current_date)
       
   453             echo "</ul></li>\n";
       
   454         echo "<li class='ec3_list ec3_list_day'>"
       
   455         .    ec3_format_str($template_day,$data)."\n<ul>\n";
       
   456         $current_date=$data['DATE'];
       
   457       }
       
   458 
       
   459       if($entry->allday)
       
   460           $data['TIME']=__('all day','ec3');
       
   461       else
       
   462           $data['TIME']=mysql2date($time_format,$entry->start);
       
   463 
       
   464       $data['TITLE'] =
       
   465         htmlentities(
       
   466           stripslashes(strip_tags($entry->post_title)),
       
   467           ENT_QUOTES,get_option('blog_charset')
       
   468         );
       
   469       $data['LINK']  =get_permalink($entry->id);
       
   470       $data['AUTHOR']=
       
   471         htmlentities($entry->author,ENT_QUOTES,get_option('blog_charset'));
       
   472       echo " <li>".ec3_format_str($template_event,$data)."</li>\n";
       
   473     }
       
   474     if($current_date)
       
   475         echo "</ul></li>\n";
       
   476     if($current_month)
       
   477         echo "</ul></li>\n";
       
   478   }
       
   479   else
       
   480   {
       
   481     echo "<li>".__('No events.','ec3')."</li>\n";
       
   482   }
       
   483   echo "</ul>\n";
       
   484 }
       
   485 
       
   486  
       
   487 // version accordeon by samuel huron 
       
   488 function ec3_get_events_acc(
       
   489   $limit,
       
   490   $template_event=EC3_DEFAULT_TEMPLATE_EVENT,
       
   491   $template_day  =EC3_DEFAULT_TEMPLATE_DAY,
       
   492   $date_format   =EC3_DEFAULT_DATE_FORMAT,
       
   493   $template_month=EC3_DEFAULT_TEMPLATE_MONTH,
       
   494   $month_format  =EC3_DEFAULT_MONTH_FORMAT)
       
   495 {
       
   496   if(!ec3_check_installed(__('Upcoming Events','ec3')))
       
   497     return;
       
   498   global $ec3,$wpdb,$wp_version;
       
   499 
       
   500   // Parse $limit:
       
   501   //  NUMBER      - limits number of posts
       
   502   //  NUMBER days - next NUMBER of days
       
   503   if(empty($limit))
       
   504   {
       
   505     $limit_numposts='LIMIT 5';
       
   506   }
       
   507   elseif(preg_match('/^ *([0-9]+) *d(ays?)?/',$limit,$matches))
       
   508   {
       
   509     $secs=intval($matches[1])*24*3600;
       
   510     $and_before="AND start<='".ec3_strftime('%Y-%m-%d',time()+$secs)."'";
       
   511   }
       
   512   elseif(intval($limit)<1)
       
   513   {
       
   514     $limit_numposts='LIMIT 5';
       
   515   }
       
   516   else
       
   517   {
       
   518     $limit_numposts='LIMIT '.intval($limit);
       
   519   }
       
   520   
       
   521   if(!$date_format)
       
   522       $date_format=get_option('date_format');
       
   523 
       
   524   // Find the upcoming events.
       
   525   $calendar_entries = $wpdb->get_results(
       
   526     "SELECT DISTINCT
       
   527        p.id AS id,
       
   528        post_title,
       
   529        start,
       
   530        u.$ec3->wp_user_nicename AS author,
       
   531        allday
       
   532      FROM $ec3->schedule s
       
   533      LEFT JOIN $wpdb->posts p ON s.post_id=p.id
       
   534      LEFT JOIN $wpdb->users u ON p.post_author = u.id
       
   535      WHERE p.post_status='publish'
       
   536        AND end>='$ec3->today' $and_before
       
   537      ORDER BY start $limit_numposts"
       
   538   );
       
   539 
       
   540   echo "<!-- Generated by Event Calendar v$ec3->version  Modified by samuel huron for acc integration -->\n";
       
   541   echo "<ul id='accordion_nav'>";
   410   // echo "<li id='test'>test</li>";
   542   // echo "<li id='test'>test</li>";
   411 	  if($calendar_entries)
   543 	  if($calendar_entries)
   412 	  {
   544 	  {
   413 		$time_format=get_option('time_format');
   545 		$time_format=get_option('time_format');
   414 		$current_month=false;
   546 		$current_month=false;
   470 	  }
   602 	  }
   471 	  else
   603 	  else
   472 	  {
   604 	  {
   473 		echo "<li>".__('No events.','ec3')."</li>\n";
   605 		echo "<li>".__('No events.','ec3')."</li>\n";
   474 	  }
   606 	  }
       
   607   echo " \n </ul> \n <div class='ui-helper-clearfix'>&nbsp;</div>";
       
   608 }
       
   609 
       
   610 // version pour la home by samuel huron 
       
   611 function ec3_get_events_home(
       
   612   $limit,
       
   613   $template_event=EC3_DEFAULT_TEMPLATE_EVENT,
       
   614   $template_day  =EC3_DEFAULT_TEMPLATE_DAY,
       
   615   $date_format   =EC3_DEFAULT_DATE_FORMAT,
       
   616   $template_month=EC3_DEFAULT_TEMPLATE_MONTH,
       
   617   $month_format  =EC3_DEFAULT_MONTH_FORMAT)
       
   618 {
       
   619   if(!ec3_check_installed(__('Upcoming Events','ec3')))
       
   620     return;
       
   621   global $ec3,$wpdb,$wp_version;
       
   622 
       
   623   // Parse $limit:
       
   624   //  NUMBER      - limits number of posts
       
   625   //  NUMBER days - next NUMBER of days
       
   626   if(empty($limit))
       
   627   {
       
   628     $limit_numposts='LIMIT 5';
       
   629   }
       
   630   elseif(preg_match('/^ *([0-9]+) *d(ays?)?/',$limit,$matches))
       
   631   {
       
   632     $secs=intval($matches[1])*24*3600;
       
   633     $and_before="AND start<='".ec3_strftime('%Y-%m-%d',time()+$secs)."'";
       
   634   }
       
   635   elseif(intval($limit)<1)
       
   636   {
       
   637     $limit_numposts='LIMIT 5';
       
   638   }
       
   639   else
       
   640   {
       
   641     $limit_numposts='LIMIT '.intval($limit);
       
   642   }
       
   643   
       
   644   if(!$date_format)
       
   645       $date_format = get_option('date_format');
       
   646 	  
       
   647 	 // echo("<!-- ".get_option('date_format')." -->");
       
   648 	  
       
   649   // Find the upcoming events.
       
   650   $calendar_entries = $wpdb->get_results(
       
   651     "SELECT DISTINCT
       
   652        p.id AS id,
       
   653        post_title,
       
   654 	   post_content,
       
   655        start,
       
   656        u.$ec3->wp_user_nicename AS author,
       
   657        allday
       
   658      FROM $ec3->schedule s
       
   659      LEFT JOIN $wpdb->posts p ON s.post_id=p.id
       
   660      LEFT JOIN $wpdb->users u ON p.post_author = u.id
       
   661      WHERE p.post_status='publish'
       
   662        AND end>='$ec3->today' $and_before
       
   663      ORDER BY start $limit_numposts"
       
   664   );
       
   665 
       
   666   echo "<!-- Generated by Event Calendar v$ec3->version  Modified by samuel huron for home integration -->\n";
       
   667   echo "<ul>";
       
   668   // echo "<li id='test'>test</li>";
       
   669 	  if($calendar_entries)
       
   670 	  {
       
   671 		$time_format=get_option('time_format');
       
   672 		$current_month=false;
       
   673 		$current_date=false;
       
   674 		$data=array();
       
   675 		foreach($calendar_entries as $entry)
       
   676 		{
       
   677 		  // To use %SINCE%, you need Dunstan's 'Time Since' plugin.
       
   678 		  if(function_exists('time_since'))
       
   679 			  $data['SINCE']=time_since( time(), ec3_to_time($entry->start) );
       
   680 
       
   681 		  // Month changed?
       
   682 		  $data['MONTH']=mysql2date($month_format,$entry->start);
       
   683 		  if((!$current_month || $current_month!=$data['MONTH']) && $template_month)
       
   684 		  {
       
   685 			if($current_date)
       
   686 				echo "</ul></li>\n";
       
   687 			if($current_month)
       
   688 			$id_accordion=str_replace(" ", "_",ec3_format_str($template_month,$data));
       
   689 			$id_accordion=str_replace(":", "",$id_accordion);
       
   690 				echo " </ul></li>\n";
       
   691 			echo "<li id='ec3_list ec3_list_month'> ".ec3_format_str($template_month,$data)." \n<ul id=".$id_accordion.">\n";
       
   692 			echo "<!-- ".$data." -->";
       
   693 			$current_month=$data['MONTH'];
       
   694 			$current_date=false;
       
   695 		  }
       
   696 
       
   697 		  
       
   698 		  // Date changed?
       
   699 		  $data['DATE'] =mysql2date($date_format, $entry->start);
       
   700 		  if((!$current_date || $current_date!=$data['DATE']) && $template_day)
       
   701 		  {
       
   702 			if($current_date)
       
   703 				echo "</ul></li>\n";
       
   704 				$id_accordion=str_replace(" ", "_",ec3_format_str($template_day,$data));
       
   705 				$id_accordion=str_replace(":", "",$id_accordion);
       
   706 				echo "<li > ".ec3_format_str($template_day,$data).$data['YEAR']." \n <ul id=".$id_accordion.">\n";
       
   707 			$current_date=$data['DATE'];
       
   708 		  }
       
   709 
       
   710 		  if($entry->allday)
       
   711 			  $data['TIME']=__('all day','ec3');
       
   712 		  else
       
   713 			  $data['TIME']=mysql2date($time_format,$entry->start);
       
   714 
       
   715 		  $data['TITLE'] =
       
   716 			htmlentities(
       
   717 			  stripslashes(strip_tags($entry->post_title)),
       
   718 			  ENT_QUOTES,get_option('blog_charset')
       
   719 			);
       
   720 		 $data['RESUME'] =
       
   721 			htmlentities(
       
   722 			  stripslashes(strip_tags(substr($entry->post_content,0,400)."[...]")),
       
   723 			  ENT_QUOTES,get_option('blog_charset')
       
   724 			);
       
   725 		  $data['LINK']  =get_permalink($entry->id);
       
   726 		  $data['AUTHOR']=
       
   727 			htmlentities($entry->author,ENT_QUOTES,get_option('blog_charset'));
       
   728 		  //echo " <li>".ec3_format_str($template_event,$data)."</li>\n";
       
   729 		  echo " <a href='".$data['LINK']."' nicetitle='".$data['RESUME']."' >".$data['TITLE']."</a>\n";
       
   730 		}
       
   731 		if($current_date)
       
   732 			echo "</ul></li>\n";
       
   733 		if($current_month)
       
   734 			echo "</ul></li>\n";
       
   735 	  }
       
   736 	  else
       
   737 	  {
       
   738 		echo "<li>".__('No events.','ec3')."</li>\n";
       
   739 	  }
   475   echo " \n </ul> \n";
   740   echo " \n </ul> \n";
   476 }
   741 }
       
   742 
   477 
   743 
   478 define('EC3_DEFAULT_FORMAT_SINGLE','<tr><td colspan="3">%s</td></tr>');
   744 define('EC3_DEFAULT_FORMAT_SINGLE','<tr><td colspan="3">%s</td></tr>');
   479 define('EC3_DEFAULT_FORMAT_RANGE','<tr><td class="ec3_start">%1$s</td>'
   745 define('EC3_DEFAULT_FORMAT_RANGE','<tr><td class="ec3_start">%1$s</td>'
   480  . '<td class="ec3_to">%3$s</td><td class="ec3_end">%2$s</td></tr>');
   746  . '<td class="ec3_to">%3$s</td><td class="ec3_end">%2$s</td></tr>');
   481 define('EC3_DEFAULT_FORMAT_WRAPPER','<table class="ec3_schedule">%s</table>');
   747 define('EC3_DEFAULT_FORMAT_WRAPPER','<table class="ec3_schedule">%s</table>');