在线饲料不起作用

时间:2015-11-11 10:02:28

标签: wordpress calendar woocommerce icalendar

我正在研究一个显示我的woocommerce预订的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 (&euro;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 (&euro;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; ?>

2 个答案:

答案 0 :(得分:0)

你的编辑器没有以 CRLF 结束一行,而是一个简单的 LF

将此代码<?php echo "\r\n" ?>添加到脚本中的每个缓冲行。

这样做:

BEGIN:VCALENDAR<?php echo "\r\n" ?>
VERSION:2.0<?php echo "\r\n" ?>

答案 1 :(得分:0)

我发现这样做更容易,而不必担心每行的换行符:

str_replace(["\r\n", "\r", "\n"], "\r\n", $output); //fix linebreaks