RSS 联合供稿使用 <feed refresh-interval="1800">http://rss./rss/cnn_topstories.rss</feed> 获取这些更新联合供稿的协议为 Atom 1.0、Atom 0.3、RSS 2.0 或 RSS 1.0。标准联合供稿通常都会正常运行。 使用联合供稿更新按钮图标/工具提示要通过联合供稿更新工具栏上的图标或工具提示说明,您需要将特定工具栏扩展件添加到使用名称空间的 RSS 或 ATOM。下面是从联合供稿中提取的心情圈圈按钮的示例: <?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>
注意,它指定 如果在实际的服务器上安装了它,联合供稿输出则如下所示: <?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 AAAAAQAAAAAAAAAAAAAAESZIXl4zdJvAXbHS8m3C3f9LnrrLFUtsmwILEX4AAABzAAAAYQAAAEcA AAAqAAAAEwAAAAcAAAACAAAAACs9RTNOjrDtW6nS/53u/f+n/P//hej//2bP/P9Fq93wHGaNrxEv O4kAAAB6AAAAX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Hkv9lk5v/Y4eNtlBfaEgAAAAWAAAACQAAAAIA AAAAAAMAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAMAA AADgAAAA8AEAAA== </gtb:icon> </feed> 以上示例是 Atom 1.0 联合供稿,包含的 Google 自定义按钮名称空间指定为: xmlns:gtb=‘http://toolbar.google.com/custombuttons/‘ 要覆盖随按钮出现的工具提示,请指定: <gtb:description> new-description </gtb:description> 要覆盖随按钮出现的图标,请指定: <gtb:icon> icon-base64-code </gtb:icon> 控制这种复杂的“心情”分析系统的 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>"; ?> 图标应该和脚本位于同一文件夹中。 使用联合供稿更新按钮和下拉菜单图标您还可以将自定义服务器图标添加到联合供稿下拉菜单上的单个项目上。下面是天气按钮示例,它具有包含下拉菜单(默认值)的联合供稿,但是还可以指定
<?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>
下面是天气联合供稿外观的示例,在下拉菜单中各个菜单项目旁边都有自定义图标(为简洁起见,大多数图标已经删除 base64 编码的资料)。基于以上示例,它可见于: <?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 代码使用天气预报回复格式。 <?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/ 名称空间和说明或者 RSS 1.0、RSS 2.0、Atom 1.0 及 Atom 0.3 联合供稿中的图标标记用于工具栏联合供稿。 |
|