2013-08-21 38 views
0

我使用PHP包括(強制性)和simplepie獲取事件標題和開始日期,但它不斷給我8月8日2013年每個事件。我可以看到事件很好。任何想法如何從這抓住'when'標籤? 如果我使用標籤,我會收到錯誤信息。我現在不是專業人士,而是在我的智慧結尾!無法使用simplepie將谷歌事件鏈接到谷歌日曆

 <?php 
    if ($_SERVER['QUERY_STRING']) { 
    parse_str($_SERVER['QUERY_STRING'], $arg); 
    } else { 
    $arg['feed'] = ''; 
    $arg['count'] = ''; 
    $arg['more'] = ''; 
    $arg['nodiv'] = ''; 
    } 

    if (!isset($arg['nodiv'])) $arg['nodiv']='false'; 

    if ($arg['nodiv'] != 'true') { 
?> 





<div id="news_list"> 
<?php 
    } 

    include('simplepie.inc'); 

// Let's create a new SimplePie object 
$feed = new SimplePie(); 

$feed = new SimplePie(); 
    $feed->set_file($file); 
    $feed->enable_cache(false); 

    $feed->init(); 
    $feed->handle_content_type(); 

// This is the feed we'll use 
$feed->set_feed_url('http://www.google.com/calendar/feeds/aufdccetl%40gmail.com/public/full?max-results=2'); 


// Let's turn this off because we're just going to re-sort anyways, and there's no reason to waste CPU doing it twice. 
$feed->enable_order_by_date(false); 

// Initialize the feed so that we can use it. 
$feed->init(); 

// Make sure the content is being served out to the browser properly. 
$feed->handle_content_type(); 

// We'll use this for re-sorting the items based on the new date. 
$temp = array(); 


foreach ($feed->get_items() as $item) { 


    // We want to grab the Google-namespaced <gd:when> tag. 
    $when = $item->get_item_tags('http://schemas.google.com/g/2005', 'when'); 



    // Once we grab the tag, let's grab the startTime attribute 
    $date = $when[0]['attribs']['']['startTime']; 

    // Let's convert it all to UNIX timestamp. This will be used for sorting. 
    $sortDate = SimplePie_Misc::parse_date($date); 

    // Let's format it with date(). This will be the date we display. 
    $gCalDate = date('l, F j, Y', $sortDate); 

    // This is how each item will be displayed. We're adding it to the array we created earlier, and indexing it by the $sortDate. 
    $temp[$sortDate] = '<p> <div class="event_title"><a href=' . $feed->get_permalink(). '>' . $item->get_title() . '</a></div> <div class="event_date"> ' . $gCalDate . '</div> <br/></p>'; 
} 

// Change this to krsort() to display with the furthest event first. 
ksort($temp); 

// Loop through the (now sorted) array, and display what we wanted. 
foreach (array_slice($temp, 0, 3) as $paragraph) { 

    echo $paragraph; 

} 
?> 

這個腳本提取事件標題和日期就好了,它沒有得到事件的公共url。而是向我展示一個空白的日曆。有關如何通過網址獲取公共活動信息的任何想法?

+0

什麼對你是從拉動飼料的網址是什麼?你能否驗證它是否是瀏覽器中的有效提要?如果是這樣,文章的日期是什麼? – Revent

+0

您確定'$ arg ['feed']'提供服務器上存在的有效文件名嗎? – Revent

+0

我有腳本現在工作,只需要顯示3個事件,而不是整個列表,我現在試圖弄清楚這一點 此外,這是一個pvt飼料,我不能在這裏顯示。 – alice

回答

1

要回答關於限制事件/文章的問題,請使用set_item_limit()函數。例如:

$feed->set_item_limit(5); // limit each feed to the top 5 articles/events 
$feed->init(); 

如果你想限制顯示的總數量,使用此:

$max_items_total = 25; // limit the total number of articles displayed to 25 
foreach ($feed->get_items(0, $max_items_total) as $key=>$item) { 
    ... 
} 
+0

感謝您的回答Revent,但我得到了這部分工作。我真的需要獲取每個事件的個人網址。所以,當用戶點擊事件標題時,他將被帶到事件信息。 – alice

+0

不客氣。假設您的Feed項目中包含網址,您應該可以抓取這些網址。如果它在那裏,您還可以獲取供稿網址。 – Revent