在线 ical feed 将不起作用
Online ical feed won't work
我正在为显示我的 woocommerce 预订的 ical feed 工作,但似乎无法让它工作。谁能检查我的代码是否有错误?
我尝试了 http://icalendar.org/validator.html,但出现以下错误:
错误
第 1 行附近未由 CRLF 序列分隔的行
参考:RFC 5545 3.1。内容行
<?php
// - start collecting output -
ob_start();
// - file header -
header('Content-type: text/calendar');
header('Content-Disposition: attachment; filename="ical.ics"');
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//bobbin v0.1//NONSGML iCal Writer//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
<?php
global $wpdb, $woocommerce, $post, $feed;
$orders = $feed->get_bookings();
foreach ($orders as $o):
$order = new WC_Order($o->ID);
$items = $order->get_items();
foreach ($items as $id => $item) {
$length = $item['item_meta']["Aantal uur (€25,00)"][0];
$item['item_meta'] = $wpdb->get_results('SELECT * FROM wp_woocommerce_order_itemmeta WHERE order_item_id='.$id, 'ARRAY_A');
foreach ($item['item_meta'] as $meta) {
$item['item_meta'][$meta['meta_key']] = $meta['meta_value'];
}
if (isset($item['item_meta']['Verhuur datum'])) {
// var_dump($item['item_meta']);
$date = $item['item_meta']['Verhuur datum'];
$start = $item['item_meta']['Booking Time'];
$length = $item['item_meta']["Aantal uur (€25,00)"];
$starttime = date('Ymd\THis', strtotime($date . " " . $start));
$endtime = date('Ymd\THis', strtotime($date . " " . $start) + $length * 3600);
// - content header -
?>
BEGIN:VEVENT
DTSTART:<?php echo $starttime . "\n\r"; ?>
DTEND:<?php echo $endtime . "\n\r"; ?>
DTSTAMP:<?php echo date('Ymd\THis', strtotime($o->post_date)) . "\n\r"; ?>
UID:<?php echo $o->ID; ?>@se-haaglanden.nl
CREATED:<?php echo date('Ymd\THis', strtotime($o->post_date)) . "\n\r"; ?>
DESCRIPTION:<?php echo $o->post_title . "\n\r"; ?>
LAST-MODIFIED:<?php date('Ymd\THis', strtotime($o->post_modified)) . "\n\r"; ?>
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:<?php echo $o->post_title . "\n\r"; ?>
TRANSP:OPAQUE
END:VEVENT
<?php } } endforeach; ?>
END:VCALENDAR
<?php exit; ?>
您的编辑器没有以 CRLF 结束一行,而是一个简单的 LF.
将此代码 <?php echo "\r\n" ?>
添加到脚本中的每个缓冲区行。
这样做:
BEGIN:VCALENDAR<?php echo "\r\n" ?>
VERSION:2.0<?php echo "\r\n" ?>
我发现这样做更容易,而不是担心每行的换行符:
str_replace(["\r\n", "\r", "\n"], "\r\n", $output); //fix linebreaks
我正在为显示我的 woocommerce 预订的 ical feed 工作,但似乎无法让它工作。谁能检查我的代码是否有错误?
我尝试了 http://icalendar.org/validator.html,但出现以下错误:
错误 第 1 行附近未由 CRLF 序列分隔的行 参考:RFC 5545 3.1。内容行
<?php
// - start collecting output -
ob_start();
// - file header -
header('Content-type: text/calendar');
header('Content-Disposition: attachment; filename="ical.ics"');
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//bobbin v0.1//NONSGML iCal Writer//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
<?php
global $wpdb, $woocommerce, $post, $feed;
$orders = $feed->get_bookings();
foreach ($orders as $o):
$order = new WC_Order($o->ID);
$items = $order->get_items();
foreach ($items as $id => $item) {
$length = $item['item_meta']["Aantal uur (€25,00)"][0];
$item['item_meta'] = $wpdb->get_results('SELECT * FROM wp_woocommerce_order_itemmeta WHERE order_item_id='.$id, 'ARRAY_A');
foreach ($item['item_meta'] as $meta) {
$item['item_meta'][$meta['meta_key']] = $meta['meta_value'];
}
if (isset($item['item_meta']['Verhuur datum'])) {
// var_dump($item['item_meta']);
$date = $item['item_meta']['Verhuur datum'];
$start = $item['item_meta']['Booking Time'];
$length = $item['item_meta']["Aantal uur (€25,00)"];
$starttime = date('Ymd\THis', strtotime($date . " " . $start));
$endtime = date('Ymd\THis', strtotime($date . " " . $start) + $length * 3600);
// - content header -
?>
BEGIN:VEVENT
DTSTART:<?php echo $starttime . "\n\r"; ?>
DTEND:<?php echo $endtime . "\n\r"; ?>
DTSTAMP:<?php echo date('Ymd\THis', strtotime($o->post_date)) . "\n\r"; ?>
UID:<?php echo $o->ID; ?>@se-haaglanden.nl
CREATED:<?php echo date('Ymd\THis', strtotime($o->post_date)) . "\n\r"; ?>
DESCRIPTION:<?php echo $o->post_title . "\n\r"; ?>
LAST-MODIFIED:<?php date('Ymd\THis', strtotime($o->post_modified)) . "\n\r"; ?>
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:<?php echo $o->post_title . "\n\r"; ?>
TRANSP:OPAQUE
END:VEVENT
<?php } } endforeach; ?>
END:VCALENDAR
<?php exit; ?>
您的编辑器没有以 CRLF 结束一行,而是一个简单的 LF.
将此代码 <?php echo "\r\n" ?>
添加到脚本中的每个缓冲区行。
这样做:
BEGIN:VCALENDAR<?php echo "\r\n" ?>
VERSION:2.0<?php echo "\r\n" ?>
我发现这样做更容易,而不是担心每行的换行符:
str_replace(["\r\n", "\r", "\n"], "\r\n", $output); //fix linebreaks