昨日知った事。
var Foo = [1,2,3,];
ケツの,がFirefoxだとOK。IEだとエラー。
'onCompl<strong>a</strong>te' : function(request) {
オンコンプレイト で小2時間はまる。
世の中に対して憎しみが芽生えた。
付録 A. PHP 4 用の PHPUnitPHP 4 用の PHPUnit には、TextUI テストランナーがありません。 PHP 4 用の PHPUnit でテストを実行する際の一般的な方法は、 テストスイートを書いた後で、それを 例 A.2 のように手動で実行することです。
高木さんの涙が出る程ありがたい翻訳マニュアル。
ところで、
「PHP4用のPHPUnitにはTextUIテストランナーがありません。」
この事実、以前辿り着くのが結構大変だった覚えがあります。ありそうなんでドキュメントやソースをかなり漁っちゃうんですよね。 車輪の再開発の嫌い過ぎも瞬発力が無くなっちゃいますね。
ブックマークのRSSでエントリのrdf:aboutやlink要素ってブックマーク先のURIになってるけどこれっていいのかな?(del.icio.usもはてブも) ブックマークサービス上の1ページ(こういうページ)は1個のエントリとはみなさないってこと? フィードをキャッシュしようと思った時、これがエントリのユニークなIDになるかと思ったんだけど頭にフィード自体のURI付けないと駄目か。うzzzzz
faviconのエントリではてブもらったので調べてみました。
WWW::Blog::Metadata::Icon – Extract icon (FOAF photo, favicon) from weblog – search.cpan.orgDESCRIPTION
WWW::Blog::Metadata::Icon is a plugin for WWW::Blog::Metadata that attempts to extract photos/icons for a weblog author. It looks in three places:
1. a FOAF file, from either an img or depiction element. 2. a shortcut icon in a tag in the document. 3. a HEAD check on $uri/favicon.ico.
Ben TrottのWWW::Blog::Metadata::Iconってmoduleで取れるそうです。
sub on_got_tag {
my $class = shift;
my($meta, $tag, $attr, $base_uri) = @_;
if ($tag eq 'link' && $attr->{rel}) {
my %rel = map { $_ => 1 } split /\s+/, lc $attr->{rel};
if ($rel{icon}) {
$meta->favicon_uri(URI->new_abs($attr->{href}, $base_uri))->as_string;
}
}
}
sub on_finished {
my $class = shift;
my($meta) = @_;
$meta->icon_uri($meta->foaf_icon_uri || $meta->favicon_uri);
}
おお、すげー参考になる。foafのiconも見るとこがビリッとしてんなー。 これのPHP4版無いのかな。
個別の記事のページにずっとjsのエラーが出てたのを直しました。 コメント時に名前とかがCookieに保存されないのはこれかよ。 (Sleipnirだとjsエラー時に「デバッガを起動しますか?」みたいなポップアップが出るそうでかなりウザいそうです)
よく見たらMTが使うSite JavaScript(mt-site.js)が元々存在しなかった。 いつのバージョンからあったのかわからないが今さら気づいたので本家からテンプレ持ってきたら動きました。よかった。
3.2x Default TemplatesIndex templates
OKWebでの質問返ってこなかった…。
………よしッ!!!(リアクション間違い)
宣言通りしようがなくJavascriptのParser自分で書いた。
本当に泥臭いから覚悟しろ!
使い方:
<html>
<head>
<script src="scripts/ObjTree.js" type="text/javascript"></script>
<script src="scripts/prototype.js" type="text/javascript"></script>
<script src="scripts/feed.js" type="text/javascript"></script>
<script language="javascript">
var url = 'http://d.hatena.ne.jp/m-komagata/rss'; // RSS1.0
//var url = 'http://d.hatena.ne.jp/m-komagata/rss2'; // RSS2.0
//var url = 'http://p0t.jp/mt/atom.xml'; // Atom0.3
//var url = 'http://komagata.blogspot.com/atom.xml'; // Atom0.3
url = 'proxy.php?uri=' + url;
new Ajax.Request(url, {
onComplete : function(req) {
var feed = new Feed(req.responseText);
feed.parse();
var list = '';
feed.getItems().each(function(item) {
list += '<h2>' + item.title + '</h2>';
list += '<p>' + item.link + '</p>';
list += '<p>' + item.description + '</p>';
list += '<p>' + item.date + '</p>';
});
Element.update('list', list);
}
});
</script>
</head>
<body>
<div id="list" ></div>
</body>
</html>
パーサー:
var Feed = Class.create();
Feed.prototype = {
initialize : function(data) {
this.data = data
},
parse : function() {
var xotree = new XML.ObjTree();
var tree = xotree.parseXML(this.data);
this.data = tree;
var kind = this.getKind();
eval('this.parser = new ' + kind);
this.parser.data = this.data;
this.parser.kind = kind;
},
getKind : function() {
var kind;
if (this.data['rdf:RDF'] &&
this.data['rdf:RDF']['-xmlns'] == 'http://purl.org/rss/1.0/') {
kind = 'RSS10';
} else if (this.data['rss'] && this.data['rss']['-version'] == '2.0') {
kind = 'RSS20';
} else if (this.data['feed'] && this.data['feed']['-version'] == '0.3') {
kind = 'Atom03';
} else {
kind = 'UnknownFeed';
}
return kind;
},
getTitle : function() {
return this.parser.getTitle();
},
getLink : function() {
return this.parser.getLink();
},
getItems : function() {
return this.parser.getItems();
},
getJSON : function() {
return {
title : this.getTitle(),
link : this.getLink(),
items : this.getItems()
};
}
};
var RSS10 = Class.create();
RSS10.prototype = {
initialize : function() {},
getTitle : function() {
return this.data['rdf:RDF'].channel.title;
},
getLink : function() {
return this.data['rdf:RDF'].channel.link;
},
getItems : function() {
var items = this.data['rdf:RDF'].item;
var res = [];
items.each(function(item) {
item['date'] = item['date'] || item['dc:date'];
res.push(item);
});
return res;
}
};
var RSS20 = Class.create();
RSS20.prototype = {
initialize : function() {},
getTitle : function() {
return this.data['rss'].channel.title;
},
getLink : function() {
return this.data['rss'].channel.link;
},
getItems : function() {
var items = this.data['rss'].channel.item;
var res = [];
items.each(function(item) {
item['date'] = item['date'] || item['dc:date'] || item['pubDate'];
res.push(item);
});
return res;
}
};
var Atom03 = Class.create();
Atom03.prototype = {
initialize : function() {},
getTitle : function() {
var title = this.data['feed'].title;
if (typeof(title) == 'string') {
return title;
} else {
return title['#text'];
}
},
getLink : function() {
var link = this.data['feed'].link;
var res = '';
if (!link['-href']) {
link.each(function(ln) {
if (ln['-rel'] == 'alternate') {
res = ln['-href'];
}
});
} else {
res = this.data['feed'].link['-href'];
}
return res;
},
getItems : function() {
var items = this.data['feed'].entry;
var res = [];
items.each(function(item) {
var title = item['title'] = item.title;
if (typeof(title) == 'string') {
item['title'] = title;
} else {
item['title'] = title['#text'];
}
item['date'] = item['date'] || item['dc:date'] || item['created'];
if (typeof(item.link['-href']) != 'string') {
item.link.each(function(ln) {
if (ln['-rel'] == 'alternate') {
item['link'] = ln['-href'];
}
});
} else {
item['link'] = item.link['-href'] || '';
}
if (typeof(item.content['#cdata-section']) == 'string') {
item['description'] = item.content['#cdata-section'];
} else {
item['description'] = item.content.div['#text'];
}
res.push(item);
});
return res;
}
};
proxy.phpのソース:
<?php
require_once 'PHP/Compat/Function/file_get_contents.php';
echo @file_get_contents($_GET['uri']);
?>
結果:
相当泥臭い。大体のフィード読めてるけどいくつか取れないのも。あとでちゃんとRSS/Atomの仕様読んでちゃんとした方法で対応したい。本題のfavicon取る機能はまだ…。
XMLをJSONに変換してくれるXML.ObjTreeが必須。
最近、家の回りに質の悪い連中をちょくちょく見かける。
冬にはまったく見なかったのに、最近は頻繁に目に付いて嫌でも奴らの勢力の強さを感じます。
家の前で見掛けた時、おれがカッと睨み付けてやっても連中は、「ん?なにか?」ってなもんです。
昨日も玄関前でBabyG(*)を見た。このままでは室内に出現するのも時間の問題…。
(*子供のG)
寝苦しい夜が続いていますがいかがお過ごしでしょうか。世間から大体1年ぐらい遅れてJavascriptを書きはじめたkomagataです。
前置きはさておき、ぶっちゃけたこと聞いていいでしょうか?
「varって何?」
「付けたときと付けないときどう違うの?」
それでは宜しくお願い申し上げます。あ、わかった、myみたいなもんか。