|
RSS 聯(lián)合供稿使用 <feed refresh-interval="1800">http://rss./rss/cnn_topstories.rss</feed> 獲取這些更新聯(lián)合供稿的協(xié)議為 Atom 1.0、Atom 0.3、RSS 2.0 或 RSS 1.0。標(biāo)準(zhǔn)聯(lián)合供稿通常都會(huì)正常運(yùn)行。 使用聯(lián)合供稿更新按鈕圖標(biāo)/工具提示要通過(guò)聯(lián)合供稿更新工具欄上的圖標(biāo)或工具提示說(shuō)明,您需要將特定工具欄擴(kuò)展件添加到使用名稱(chēng)空間的 RSS 或 ATOM。下面是從聯(lián)合供稿中提取的心情圈圈按鈕的示例: <?xml version="1.0" encoding="utf-8"?>
<custombuttons xmlns="http://toolbar.google.com/custombuttons/">
<button>
<title>Mood ring</title>
<description>Your virtual mood ring</description>
<site>http://www.google.com/search?q=mood+ring</site>
<feed menu="false" refresh-interval="900">
http://www./custombuttons/samples/feeds/mood</feed>
</button>
</custombuttons>
注意,它指定 如果在實(shí)際的服務(wù)器上安裝了它,聯(lián)合供稿輸出則如下所示: <?xml version=‘1.0‘?> <feed xmlns=‘http://www./2005/Atom‘ xmlns:gtb=‘http://toolbar.google.com/custombuttons/‘> <id>http://www./custombuttons/samples/feeds/mood</id> <title>Mood</title> <link href=‘http://www.google.com/search?q=+ring‘ /> <link rel=‘self‘ href=‘http://www./custombuttons/samples/feeds/mood‘ /> <gtb:description>Bluegreen: Inner emotions charged, somewhat relaxed</gtb:description> <gtb:icon mode="base64" type="image/x-icon"> AAAAAAMAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAMAA AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAA AAAAAAAAAAAGAAAAHAAAAEAAAABhAAAAcwAAAHQAAABpAAAAVQAAAD4AAAApAAAAGAAAAAoAAAAD AAAAAQAAAAAAAAAAAAAAESZIXl4zdJvAXbHS8m3C3f9LnrrLFU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AKSvb9YSoWa+WyagP+wv2X/4NRO/+ngfv/m4Zf/rLeB+lpubIkAAAAlAAAADgAAAAMAAAAA AAAAAAAAAAAAAAAAAAAAAoqvuDxkkp2gYo+c51mHkv9lk5v/Y4eNtlBfaEgAAAAWAAAACQAAAAIA AAAAAAMAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAMAA AADgAAAA8AEAAA== </gtb:icon> </feed> 以上示例是 Atom 1.0 聯(lián)合供稿,包含的 Google 自定義按鈕名稱(chēng)空間指定為: xmlns:gtb=‘http://toolbar.google.com/custombuttons/‘ 要覆蓋隨按鈕出現(xiàn)的工具提示,請(qǐng)指定: <gtb:description> new-description </gtb:description> 要覆蓋隨按鈕出現(xiàn)的圖標(biāo),請(qǐng)指定: <gtb:icon> icon-base64-code </gtb:icon> 控制這種復(fù)雜的“心情”分析系統(tǒng)的 PHP 腳本如下所示: <?php
header(‘Content-type: text/xml‘);
switch(rand(1, 7)) {
case 1:
$icon = "amber.ico";
$desc = "Amber:\nNervous, on edge, uncertain";
break;
case 2:
$icon = "black.ico";
$desc = "Black:\nTense, stressed, working too hard";
break;
case 3:
$icon = "blue.ico";
$desc = "Blue:\nComfortable, breeze, at rest, loveable";
break;
case 4:
$icon = "bluegreen.ico";
$desc = "Bluegreen:\nHeightened inner emotional state, moderately relaxed";
break;
case 5:
$icon = "gray.ico";
$desc = "Gray:\nAnxious, ill at ease, strained";
break;
case 6:
$icon = "green.ico";
$desc = "Green:\nSteady, stable, no emotional turmoil";
brea;
case 7:
$icon = "purple.ico";
$desc = "Dark Blue:\nImpassioned, delighted, whiff of romance";
break;
}
$icon = base64_encode(file_get_contents($icon));
echo "<?xml version=‘1.0‘?>";
echo "\n<feed xmlns=‘http://www./2005/Atom‘ xmlns:gtb=‘http://toolbar.google.com/custombuttons/‘>";
echo "\n<id>http://www./custombuttons/samples/feeds/mood</id>";
echo "\n<title>Mood</title>";
echo "\n<link href=‘http://www.google.com/search?q=$mood+ring‘ />";
echo "\n<link rel=‘self‘ href=‘http://www./custombuttons/samples/feeds/mood‘ />";
echo "\n<gtb:description>$desc</gtb:description>";
echo "\n<gtb:icon mode=‘base64‘ type=‘image/x-icon‘>$icon</gtb:icon>";
echo "\n</feed>";
?>
圖標(biāo)應(yīng)該和腳本位于同一文件夾中。 使用聯(lián)合供稿更新按鈕和下拉菜單圖標(biāo)您還可以將自定義服務(wù)器圖標(biāo)添加到聯(lián)合供稿下拉菜單上的單個(gè)項(xiàng)目上。下面是天氣按鈕示例,它具有包含下拉菜單(默認(rèn)值)的聯(lián)合供稿,但是還可以指定
<?xml version="1.0" encoding="utf-8"?>
<custombuttons xmlns="http://toolbar.google.com/custombuttons/">
<button>
<title>Weather 94043</title>
<description>Weather updates for Mountain View, CA</description>
<site>http://www.google.com/search?q=weather+94043&num=1</site>
<feed refresh-interval="3600" refresh-menuitem="false">
http://www./custombuttons/samples/feeds/weather?zip=94043</feed>
</button>
</custombuttons>
下面是天氣聯(lián)合供稿外觀的示例,在下拉菜單中各個(gè)菜單項(xiàng)目旁邊都有自定義圖標(biāo)(為簡(jiǎn)潔起見(jiàn),大多數(shù)圖標(biāo)已經(jīng)刪除 base64 編碼的資料)?;谝陨鲜纠?,它可見(jiàn)于: <?xml version=‘1.0‘?> <feed xmlns=‘http://www./2005/Atom‘ xmlns:gtb=‘http://toolbar.google.com/custombuttons/‘> <id>http://www./custombuttons/samples/feeds/weather</id> <title>Weather Mountain View, CA</title> <link href=‘http://www.google.com/search?q=weather+94043/‘ /> <link rel=‘self‘ href=‘http://www./custombuttons/samples/feeds/weather‘ /> <gtb:description>Mountain View, CA 63F Mostly Cloudy Humidity: 48% Wind: NW at 8 mph</gtb:description> <gtb:icon mode=‘base64‘ type=‘image/x-icon‘> R0lGODlhKAAoANUAAEuc/Pz8/Fik/Ii00k9daZGPivLy8tbW1k2R0uvr6wZj3HSq0f/QMMfHx7a2 tj2F0fu0EePj4yx81neUp4J/eKanphJq3IJtOGB3iI3C5BFt5B5XnWis7H2346jO5/6+IWKo8923 ... and so on... </gtb:icon> <entry> <title>Today: Mostly Cloudy 65 | 50</title> <link href=‘http://www.google.com/search?q=weather+94043/‘ /> <id>http://www./custombuttons/samples/feeds/weather/0</id> <gtb:icon mode=‘base64‘ type=‘image/x-icon‘> R0lGODlhKAAoANUAAEuc/Pz8/Fik/Ii00k9daZGPivLy8tbW1k2R0uvr6wZj3HSq0f/QMMfHx7a2 tj2F0fu0EePj4yx81neUp4J/eKanphJq3IJtOGB3iI3C5BFt5B5XnWis7H2346jO5/6+IWKo8923 ... and so on... </entry> <entry> <title>Thu: 66 | 51</title> <link href=‘http://www.google.com/search?q=weather+94043/‘ /> <id>http://www./custombuttons/samples/feeds/weather/1</id> <gtb:icon mode=‘base64‘ type=‘image/x-icon‘> R0lGODlhKAAoAPcAAAAAAP///4WOwPT1+tDT3unr8sHG1ff5/6Wy0mZ8rGqAr3mJrJakxa+zvHSK tcDBw1R2slBql110njBXjztmqS9OfjtekTZWhGeJuoqctklLTgJYyQJQtQ9hzhRr3BZlzBVRoS1S ... and so on... </gtb:icon> </entry> <entry> <title>Fri: 67 | 51</title> <link href=‘http://www.google.com/search?q=weather+94043/‘ /> <id>http://www./custombuttons/samples/feeds/weather/2</id> <gtb:icon mode=‘base64‘ type=‘image/x-icon‘> R0lGODlhKAAoANUAAObm52ms7k2Q0Uuc/Fmk+v2zDoS01HOp0avP5tvb26CPXQZj3DqG14yLh05Y Yf/IKv/VN3mCiMPDw6SkpCt82GhxePz8/JG+2pd5NRZu3hBq3fb29rCAFrm5uSN549OWE4WltqHI ... and so on... </gtb:icon> </entry> <entry> <title>Sat: 67 | 50</title> <link href=‘http://www.google.com/search?q=weather+94043/‘ /> <id>http://www./custombuttons/samples/feeds/weather/3</id> <gtb:icon mode=‘base64‘ type=‘image/x-icon‘> R0lGODlhKAAoANUAAObm52ms7k2Q0Uuc/Fmk+v2zDoS01HOp0avP5tvb26CPXQZj3DqG14yLh05Y Yf/IKv/VN3mCiMPDw6SkpCt82GhxePz8/JG+2pd5NRZu3hBq3fb29rCAFrm5uSN549OWE4WltqHI ... and so on... </gtb:icon> </entry> </feed> 為此,PHP 代碼使用天氣預(yù)報(bào)回復(fù)格式。 <?php
// Script to convert Google xml weather interface to custom buttons AtomFeed 1.0
// Sample input at http://www.google.com/ig/api?weather=94043
// To see sample output, run this script with ?zip=94043
$zip = $_GET[‘zip‘];
header(‘Content-type: text/xml‘);
// http://www.google.com/ig/api?weather=94043
$dom= domxml_open_file("http://www.google.com/ig/api?weather=$zip");
$xpath = xpath_new_context($dom);
// $params = $dom->documentElement->firstChild->getElementsByTagName(‘param‘);
$temp = $xpath->xpath_eval(‘//city/@data‘);
$city = $temp->nodeset[0]->value;
$icons = $xpath->xpath_eval(‘//current_conditions/icon/@data‘);
$icon_url = $icons->nodeset[0]->value;
$icon = base64_encode(file_get_contents("http://www.google.com$icon_url"));
$conditions = $xpath->xpath_eval(‘//current_conditions/condition/@data‘);
$condition = $conditions->nodeset[0]->value;
$temp = $xpath->xpath_eval(‘//current_conditions/temp_f/@data‘);
$tempf = $temp->nodeset[0]->value;
$temp = $xpath->xpath_eval(‘//current_conditions/humidity/@data‘);
$humidity = $temp->nodeset[0]->value;
$temp = $xpath->xpath_eval(‘//current_conditions/wind_condition/@data‘);
$wind = $temp->nodeset[0]->value;
echo "<?xml version=‘1.0‘?>";
echo "\n<feed xmlns=‘http://www./2005/Atom‘ ";
echo "xmlns:gtb=‘http://toolbar.google.com/custombuttons/‘>";
echo "\n<id>http://www./custombuttons/samples/feeds/weather</id>";
echo "\n<title>Weather $city</title>";
echo "\n<link href=‘http://www.google.com/search?q=weather+$zip/‘ />";
echo "\n<link rel=‘self‘ href=‘http://www./custombuttons/";
echo "samples/feeds/weather‘ />";
echo "\n<gtb:description>$city\n$tempfF $condition\n$humidity\n$wind";
echo "</gtb:description>";
echo "\n<gtb:icon mode=‘base64‘ type=‘image/x-icon‘>$icon</gtb:icon>";
$days = $xpath->xpath_eval(‘//forecast_conditions/day_of_week/@data‘);
$conditions = $xpath->xpath_eval(‘//forecast_conditions/condition/@data‘);
$icons = $xpath->xpath_eval(‘//forecast_conditions/icon/@data‘);
$highs = $xpath->xpath_eval(‘//forecast_conditions/high/@data‘);
$lows = $xpath->xpath_eval(‘//forecast_conditions/low/@data‘);
for ($i = 0; $i < count($conditions->nodeset); $i++) {
$day_of_week = $days->nodeset[$i]->value;
$condition = $conditions->nodeset[$i]->value;
$high = $highs->nodeset[$i]->value;
$low = $lows->nodeset[$i]->value;
echo "\n<entry>";
echo "\n<title>$day_of_week: $condition $high | $low</title>";
echo "\n<link href=‘http://www.google.com/search?q=weather+$zip/‘ />";
echo "\n<id>http://www./custombuttons/samples/feeds/weather/$i</id>";
$icon_url = $icons->nodeset[$i]->value;
$icon = base64_encode(file_get_contents("http://www.google.com$icon_url"));
echo "\n<gtb:icon mode=‘base64‘ type=‘image/x-icon‘>$icon</gtb:icon>";
echo "\n</entry>";
}
echo "\n</feed>";
?>
您還可以使用相同的 http://toolbar.google.com/custombuttons/ 名稱(chēng)空間和說(shuō)明或者 RSS 1.0、RSS 2.0、Atom 1.0 及 Atom 0.3 聯(lián)合供稿中的圖標(biāo)標(biāo)記用于工具欄聯(lián)合供稿。 |
|
|
來(lái)自: 勇生 > 《電網(wǎng)》