<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>FJORD, LLC（合同会社フィヨルド）</title>
	<atom:link href="http://fjord.jp/feed" rel="self" type="application/rss+xml" />
	<link>http://fjord.jp</link>
	<description>rails php webデザイン webサイト運営 は町田、駒形にお任せください。</description>
	<lastBuildDate>Fri, 03 Sep 2010 07:16:11 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/feed" />
		<item>
		<title>Ham Cutletを英語対応にしました</title>
		<link>http://fjord.jp/love/464.html</link>
		<comments>http://fjord.jp/love/464.html#comments</comments>
		<pubDate>Fri, 03 Sep 2010 07:16:11 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Ham Cutlet]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[information]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=464</guid>
		<description><![CDATA[
HTMLのインデントを綺麗にするだけのサービス、Ham Cutletを英語対応にしました。ブラウザの言語設定で英語が優先になってる人には英語で表示されるようになりました。
HTMLのインデントを病的に気にする外人さんが [...]]]></description>
			<content:encoded><![CDATA[<p class="center"><a href="http://www.flickr.com/photos/komagata/4953058775/" title="Ham Cutlet(en)2 by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4131/4953058775_c26d0e5c06.jpg" width="500" height="344" alt="Ham Cutlet(en)2" /></a></p>
<p>HTMLのインデントを綺麗にするだけのサービス、<a href="http://hamcutlet.fjord.jp/"title="HTMLのインデントを美しく「Ham Cutlet（通称ハムカツ）」" >Ham Cutlet</a>を英語対応にしました。ブラウザの言語設定で英語が優先になってる人には英語で表示されるようになりました。</p>
<p>HTMLのインデントを病的に気にする外人さんがいたらオススメしてください・・・。</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/464.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/464.html" />
	</item>
		<item>
		<title>to do管理のwebアプリ、todo.lyの使いやすさに感動！</title>
		<link>http://fjord.jp/love/440.html</link>
		<comments>http://fjord.jp/love/440.html#comments</comments>
		<pubDate>Sun, 15 Aug 2010 19:09:09 +0000</pubDate>
		<dc:creator>machida</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[ウェブサービス]]></category>
		<category><![CDATA[デザイン]]></category>
		<category><![CDATA[ユーザーインターフェース]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=440</guid>
		<description><![CDATA[長らくブログを書かなかったので、右カラムの新着記事の一覧が@komagataさんのアイコンに占領されるという自体に。
ちょっと先月（2010年7月）はバタバタしてたのですが、お盆も終わったことだし、バタバタしてしまった反 [...]]]></description>
			<content:encoded><![CDATA[<p>長らくブログを書かなかったので、右カラムの新着記事の一覧が<a href="http://twitter.com/komagata"title="" >@komagata</a>さんのアイコンに占領されるという自体に。<br />
ちょっと先月（2010年7月）はバタバタしてたのですが、お盆も終わったことだし、バタバタしてしまった反省もしたし、これからちょくちょくブログを書いていきます。</p>
<p>このバタバタしてたときにとっても役に立ったtodo管理のwebアプリ、<a href="http://todo.ly/"title="todo.ly" >todo.ly</a>。<br />
ものすごく使いやすくて、これを知った瞬間からすっかりヘヴィユーザーになりました。</p>
<p><a href="http://todo.ly/" title="http://todo.ly/"><img src="http://farm5.static.flickr.com/4074/4893888435_f31d0696d5.jpg" width="500" height="298" alt="snapshot.png" /></a></p>
<p><a href="http://todo.ly/" title="http://todo.ly/">http://todo.ly/</a><br />
外国の先端のwebサービスって感じのトップページ。<br />
僕はこの手のデザインに弱くて、ついつい使いたくなってしまいます。</p>
<p>sign upしたらメインのページへ。<br />
すごくシンプルなメインページだけど、実はこのサービス、to do管理ツールの部分は下の画像にある1ページのみでページの遷移は一切ありません。</p>
<p><img src="http://farm5.static.flickr.com/4142/4894595668_a63a45a77f.jpg" width="500" height="222" alt="snapshot.png" /></p>
<h4>todo.lyにあるもの</h4>
<h5>左カラム</h5>
<ul>
<li>Filters（to doの一覧を絞り込む）</li>
<li>Projects（to doのカテゴリーの一覧を表示させる）</li>
<li>Recycle Bin（ゴミ箱）</li>
</ul>
<h5>メインカラム</h5>
<ul>
<li>to doの一覧の表示</li>
<li>to doの新規追加の為の入力ボックス</li>
</ul>
<p>これだけ！<br />
このシンプルさは素敵過ぎ。</p>
<p>なんと言ってもtodo.lyはスピーディーに使えるところが使いたくなるポイント。<br />
これはtodo.ly自体がAjaxでサクサク動くっていうのもあるし、UIもサクサクとタスクを登録できるように出来てる。</p>
<h5>to do登録の手順</h5>
<ol>
<li>まずはこれから登録するto doのカテゴリーを左カラムから選んでクリック。</li>
<li>あとはto doの内容をメインカラムのボックスに入力するだけ。</li>
</ol>
<p>to doを登録する際に考えることは、「to doのカテゴリー」と「to doの内容の文」だけ。<br />
ページが遷移しないからサクサク動いてto doを登録するのに数秒しかかからない。<br />
だからガンガンto do登録が進みます。</p>
<p>to doに期日（Due Date）も登録することができますが、しなくてもOK。必要なときはto do登録ボックスの下の「more」をクリックをすれば期日登録のボックスが表示されますが、「more」をクリックするまでは期日登録ボックスが目に入らないところもサクサク感を感じるポイントですね。</p>
<p>まぁ、上記の機能も動作も使い方も<a href="http://www.rememberthemilk.com/"title="" >remember the milk</a>にあるんだけど、Remember The Milkにはもっと機能があって、todo.lyの方はこれだけ。その分画面にある文字の量も情報も少ないので、Remember The Milkに比べてもっと使うのが簡単そうに見えます。</p>
<p>簡単そうだから特にIT系じゃないパソコンを使う人に勧めやすいです。僕が「使いたい」って思ったのも、やっぱり簡単そうだったから。まずは簡単そうに見えること、そして簡単なこと、これが大事ですね。</p>
<p>付箋にto doを書いてパソコンのモニターに貼ったりだとか、テキストエディタにto doリストを書いて終わったら消していく、なんて作業をやっているのを見たときに教えたくなるようなサービスです。</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/440.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/440.html" />
	</item>
		<item>
		<title>RubyInstallerの絶妙なロゴ</title>
		<link>http://fjord.jp/love/431.html</link>
		<comments>http://fjord.jp/love/431.html#comments</comments>
		<pubDate>Thu, 12 Aug 2010 06:31:47 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[デザイン]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=431</guid>
		<description><![CDATA[RubyInstallerのロゴが凄いです。
RubyInstallerはプログラミング言語のRubyをWindowsに簡単にインストールできるソフトです。
Windowsロゴ

Rubyロゴ

RubyInstalle [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rubyinstaller.org/">RubyInstaller</a>のロゴが凄いです。</p>
<p>RubyInstallerはプログラミング言語のRubyをWindowsに簡単にインストールできるソフトです。</p>
<p>Windowsロゴ</p>
<p><a href="http://www.flickr.com/photos/komagata/4884063423/" title="Supaki電記 Hamazo店:PC速報 by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4078/4884063423_68a97618ee_t.jpg" width="100" height="75" alt="Supaki電記 Hamazo店:PC速報" /></a></p>
<p>Rubyロゴ</p>
<p><a href="http://www.flickr.com/photos/komagata/4884065005/" title="ruby_logo.png by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4122/4884065005_6ef13a75de_t.jpg" width="100" height="100" alt="ruby_logo.png" /></a></p>
<p>RubyInstallerロゴ</p>
<p><a href="http://www.flickr.com/photos/komagata/4884658548/" title="RubyInstaller for Windows by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4074/4884658548_45a41e7daa.jpg" width="317" height="79" alt="RubyInstaller for Windows" /></a></p>
<p>RubyのロゴとWindowsのロゴをうまい具合に組み合わせてあるので、両方を知ってる人なら見ただけでどういうものか分かりそうです。</p>
<p>そもそもRubyInstallerのロゴはデザインコンテストを行って広く募集した中から投票で1位に選ばれた物です。オープンソースのソフトなどはどうしてもプログラマー寄りの物が多く、デザインは後回しになってしまうことが多いですが、一般の方にも使ってもらうにはデザインはとても重要なので、こうした成果物を見ると、こういったコンテストはとても有効だと思いました。</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/431.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/431.html" />
	</item>
		<item>
		<title>デザイナーのための Ruby on Rails + Mac 環境構築ガイド</title>
		<link>http://fjord.jp/love/423.html</link>
		<comments>http://fjord.jp/love/423.html#comments</comments>
		<pubDate>Tue, 10 Aug 2010 06:10:21 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=423</guid>
		<description><![CDATA[つくる社さんの環境構築ガイドを勉強してKEIO Railsのイベントに参加しようとした矢先、@machidaさんがWindowsからMacにSwitchしてしまって、当日何も出来ずに精神的に追い詰められてゲロを吐いてしま [...]]]></description>
			<content:encoded><![CDATA[<p>つくる社さんの環境構築ガイドを勉強してKEIO Railsのイベントに参加しようとした矢先、<a href="http://twitter.com/machida"title="" >@machida</a>さんがWindowsからMacにSwitchしてしまって、当日何も出来ずに精神的に追い詰められてゲロを吐いてしまいそうだというのでMac用のガイドを書いてみます。</p>
<p>全面参考：<a href="http://tsukurusha.com/2010/07/ruby_on_rails_setup_guide_for_designers/">デザイナーのための Ruby on Rails + Windows 環境構築ガイド | つくる社LLC</a></p>
<p>Railsのアプリを作るには下記の物をインストールする必要があります。</p>
<ol>
<li>Xcode + iOS SDK（両方必要無いが、MacPortsを使うのに必要なソフトが一杯付いてくる）</li>
<li>MacPorts（Macのアプリを簡単にインストールするプログラム）</li>
<li>Ruby（プログラミング言語）</li>
<li>RubyGems（Rubyのライブラリを簡単にインストールするプログラム）</li>
<li>SQLite3（データベース。Railsのデフォルトデータベース）</li>
<li>Ruby on Rails（RubyのWebアプリが簡単に作れるフレームワーク）</li>
</ol>
<h4>Xcode + iOS SDKのインストール</h4>
<p>下記から最新版をダウンロードしてインストール。（要デベロッパー登録）</p>
<p><a href="https://developer.apple.com/mac/">https://developer.apple.com/mac/</a></p>
<h4>MacPortsをインストール</h4>
<p>下記から最新版をダウンロードしてインストール。（数字が一番大きくて、SnowLeopard対応で拡張子がdmgのヤツ）<br />
例：MacPorts-1.9.1-10.6-SnowLeopard.dmg</p>
<p><a href="http://distfiles.macports.org/MacPorts/">http://distfiles.macports.org/MacPorts/</a></p>
<h4>Ruby、RubyGems、SQLite3をインストール</h4>
<p>ターミナル.app（別名「黒い画面」）で下記を入力。</p>
<pre>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo port install ruby rb-rubygems sqlite3 rb-sqlite3</div></td></tr></tbody></table></div>
</pre>
<p class="center"><a href="http://www.flickr.com/photos/komagata/4878554162/" title="ターミナル — bash — 80×24 by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4097/4878554162_d3efcaa656.jpg" width="500" height="313" alt="ターミナル — bash — 80×24" /></a></p>
<h4>RubyGemsを最新版にアップデート</h4>
<pre>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo gem update --system</div></td></tr></tbody></table></div>
</pre>
<h4>Ruby on Railsをインストール</h4>
<pre>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo gem install rails</div></td></tr></tbody></table></div>
</pre>
<h4>サンプルアプリを作成してRailsの動作確認</h4>
<pre>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cd (ホームディレクトリに移動)<br />
mkdir rails<br />
cd rails<br />
rails test (test という Rails アプリを作成)<br />
cd test<br />
ruby script/generate scaffold Customer name:string (name というフィールドをひとつだけ持った Customer というモデルをベースにテンプレートの画面を作成)<br />
rake db:migrate (DB にテーブルを作成)<br />
ruby script/server (アプリケーションサーバーを起動)</div></td></tr></tbody></table></div>
</pre>
<p class="center"><a href="http://www.flickr.com/photos/komagata/4878556256/" title="ターミナル — bash — 80×24 by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4102/4878556256_f1cc7c3543.jpg" width="500" height="313" alt="ターミナル — bash — 80×24" /></a></p>
<p>ブラウザより、http://localhost:3000/customers にアクセスし、New customer で新しいレコードを追加したり、そのあと編集・削除などの操作ができれば成功です。</p>
<p class="center"><a href="http://www.flickr.com/photos/komagata/4877941951/" title="Customers: index by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4139/4877941951_a593339207.jpg" width="498" height="261" alt="Customers: index" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/423.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/423.html" />
	</item>
		<item>
		<title>コードDJ第9回 &#8211; Chrome Extensionに挑戦</title>
		<link>http://fjord.jp/love/414.html</link>
		<comments>http://fjord.jp/love/414.html#comments</comments>
		<pubDate>Tue, 27 Jul 2010 07:04:32 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Help me hackers!]]></category>
		<category><![CDATA[コードDJ]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=414</guid>
		<description><![CDATA[毎週火曜日、Help me, hackers!に上がったコードを紹介していくコードDJ 第9回。
「あなだのコードがー　しぬほどスキダカダー！」（＠チャン・ドンゴン）
komagata a.k.a. DJです。
今回紹介 [...]]]></description>
			<content:encoded><![CDATA[<p>毎週火曜日、<a href="http://help-me-hackers.com/"title="Help me, hackers!" >Help me, hackers!</a>に上がったコードを紹介していくコードDJ 第9回。</p>
<p>「あなだのコードがー　しぬほどスキダカダー！」（＠チャン・ドンゴン）</p>
<p>komagata a.k.a. DJです。</p>
<p>今回紹介するのはコレ。</p>
<p><a href="http://help-me-hackers.com/projects/15">Ham Cutlet Chrome Extension &#8211; Help me, hackers!</a></p>
<p>HTMLのインデントを綺麗にする誰得サービス<a href="http://hamcutlet.fjord.jp/"title="HTMLのインデントを美しく「Ham Cutlet（通称ハムカツ）」" >Ham Cutlet</a>のGoogle Chrome Extension。ブラウザの「このページのソースを見る」の代わりにインデントを綺麗にしたソースを表示するボタンをOmniBoxの右に追加するExtensionだ。</p>
<p><a href="http://help-me-hackers.com/mongorian_chop">mongorian_chop</a> a.k.a. 自由人が作ってくれた。ボタンのアイコンは<a href="http://help-me-hackers.com/machida">machida</a> a.k.a. 漫★画太郎。軽いコラボ。</p>
<p class="center"><img src="http://img.skitch.com/20100727-d8mxncfx7jqt6nyxdifxqrkh1g.png" /></p>
<p>コードはココ。</p>
<p><a href="http://github.com/mongorian-chop/hamcutlet-extension">mongorian-chop&#8217;s hamcutlet-extension at master &#8211; GitHub</a></p>
<p>manifest.json</p>
<div class="codecolorer-container javascript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Ham Cutlet Extension&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;version&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;0.1&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Ham Cutletを使用したHTMLソース表示&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;background_page&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;background.html&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;browser_action&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;default_icon&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;icon.png&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;defailt_title&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Ham Cutlet&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;permissions&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;tabs&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>background.html</p>
<div class="codecolorer-container html4strict geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<br />
function openTab(v) {<br />
&nbsp; &nbsp; t = &quot;http://hamcutlet.fjord.jp/?url=&quot; + v;<br />
&nbsp; &nbsp; chrome.tabs.create({url: t});<br />
}<br />
<br />
chrome.browserAction.onClicked.addListener(function(tab) {<br />
&nbsp; getUrl();<br />
});<br />
<br />
function getUrl() {<br />
&nbsp; &nbsp; chrome.tabs.getSelected(null, function(tab) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var url = tab.url;<br />
&nbsp; &nbsp; &nbsp; &nbsp; if(url.match(/^http(s)?/)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; openTab(tab.url);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; });<br />
}<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Chrome Extensionの作り方なんて知らないって？それならDJに任せろ！当然の如くDJも知らないからお前らの代わりに泣きながら覚えてやる！</p>
<p>モダンブラウザ・JS好きなら知らぬものはいない<a href="http://d.hatena.ne.jp/os0x/">id:os0x</a>の連載、<a href="http://gihyo.jp/dev/serial/01/chrome-extensions/0001">続・先取り！ Google Chrome Extensions：第1回　Chrome ExtensionsのAPI#1｜gihyo.jp … 技術評論社</a>で丁寧に説明されてるのでこれでわかりそうだ。</p>
<p>DJが超訳するとこんな感じだ。</p>
<ul>
<li>manifest.jsonの入ったディレクトリを作る</li>
<li>上のバーの右にあるボタンはbrowser_actionという</li>
<li>browser_actionのボタンを押した時の動きはbackground_pageで指定したhtmlに書く</li>
<li>Chromeで.crxパッケージを作れる。（単なるzipなので解凍も出来る）（CUI野郎には<a href="http://github.com/Constellation/crxmake">Constellation&#8217;s crxmake at master &#8211; GitHub</a>というパッケージングコマンドもあるらしい。）</li>
</ul>
<p>作れる気がしてきた！早速コードを見ていこう。</p>
<p>6行目のbrowser_actionでタイトルとアイコンを設定してる。</p>
<p>10行目のpermissionsはクロスドメインでアクセスできるURLを指定するようだが、tabsはなんだろう？</p>
<p>5行目のbackground_pageで実際の動作を書くファイルを指定している。</p>
<p>background.htmlを見ていこう。</p>
<p>10行目のchrome.browserAction.onClicked.addListenerがキモだ。こうやってbrowser_actionをクリックした時の動作を設定するのだろう。</p>
<p>7行目のchrome.tabs.createでURLを指定してタブを開けるらしい。何かグリモンでも思ったけどクロスブラウザ問題が無いとJSってこんなにシンプルに書けるのかという・・・。</p>
<p>URLは以前、「<a href="http://help-me-hackers.com/tasks/63">HTMLのインデントを綺麗にするAPI &#8211; Help me, hackers!</a>」で<a href="http://help-me-hackers.com/kyanny">kyanny</a> a.k.a. 刺身ブーメランが作ってくれたHam Cutlet APIを使って該当ページのソースをインデントを綺麗にした上で取得している。</p>
<p>これは簡単・・・。グリモンやFF拡張もそうだけど、実用的なものが簡単に作れるのがイイ！ECMAScripter的にもクロスブラウザに悩まされず思いっきりJSを書けるのも気持ちがイイ。</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/414.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/414.html" />
	</item>
		<item>
		<title>コードDJ 第8回 &#8211; AutoPagerize_DOMNodeInserted・・・だと・・・？</title>
		<link>http://fjord.jp/love/406.html</link>
		<comments>http://fjord.jp/love/406.html#comments</comments>
		<pubDate>Thu, 22 Jul 2010 14:54:26 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Help me hackers!]]></category>
		<category><![CDATA[コードDJ]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=406</guid>
		<description><![CDATA[毎週火曜日、Help me, hackers!に上がったコードを紹介していくコードDJ 第8回。
「おでのからだはぼどぼどだー！」
komagata a.k.a. DJです。
今週はコレ。
WordPress.orgのプ [...]]]></description>
			<content:encoded><![CDATA[<p>毎週火曜日、<a href="http://help-me-hackers.com/"title="Help me, hackers!" >Help me, hackers!</a>に上がったコードを紹介していくコードDJ 第8回。</p>
<p>「おでのからだはぼどぼどだー！」</p>
<p>komagata a.k.a. DJです。</p>
<p>今週はコレ。</p>
<p><a href="http://help-me-hackers.com/tasks/105">WordPress.orgのプラグイン一覧でダウンロード数に目印をつけて欲しい &#8211; Help me, hackers!</a></p>
<p>登録してくれたのは<a href="http://help-me-hackers.com/monoooki">monoooki</a> a.k.a. 前田製作所。速攻解決してくれたのは<a href="http://help-me-hackers.com/azu_re">azu_re</a> a.k.a. Firefoxの人（DJ主観）。</p>
<p>ソースコード：</p>
<div class="codecolorer-container javascript geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">// ==UserScript==</span><br />
<span style="color: #006600; font-style: italic;">// @name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WordPress.org highlight counter</span><br />
<span style="color: #006600; font-style: italic;">// @namespace &nbsp; &nbsp; &nbsp;http://efcl.info/</span><br />
<span style="color: #006600; font-style: italic;">// @description &nbsp; &nbsp;WordPress.orgのタグ/単語検索のダウンロード数によって色を変える</span><br />
<span style="color: #006600; font-style: italic;">// @include &nbsp; &nbsp; &nbsp; &nbsp;http://wordpress.org/extend/plugins/tags/*</span><br />
<span style="color: #006600; font-style: italic;">// @include &nbsp; &nbsp; &nbsp; &nbsp;http://wordpress.org/extend/plugins/search*</span><br />
<span style="color: #006600; font-style: italic;">// ==/UserScript==</span><br />
<span style="color: #006600; font-style: italic;">/* &nbsp;TEST URL<br />
&nbsp; &nbsp; http://wordpress.org/extend/plugins/search.php?q=word<br />
&nbsp; &nbsp; http://wordpress.org/extend/plugins/tags/widget<br />
*/</span><br />
GM_addStyle<span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;&gt;&lt;!</span><span style="color: #009900;">&#91;</span>CDATA<span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; .<span style="color: #660066;">GM_downloads_count_50000</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; background<span style="color: #339933;">:</span> #cc0000<span style="color: #339933;">;</span> color<span style="color: #339933;">:</span> #fff<span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> 1px 3px<span style="color: #339933;">;</span> <span style="color: #339933;">-</span>moz<span style="color: #339933;">-</span>border<span style="color: #339933;">-</span>radius<span style="color: #339933;">:</span> 3px<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; .<span style="color: #660066;">GM_downloads_count_10000</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; background<span style="color: #339933;">:</span>#ffb0b0<span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> 1px 3px<span style="color: #339933;">;</span> <span style="color: #339933;">-</span>moz<span style="color: #339933;">-</span>border<span style="color: #339933;">-</span>radius<span style="color: #339933;">:</span> 3px<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; .<span style="color: #660066;">GM_downloads_count_5000</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; background<span style="color: #339933;">:</span>#ffd792<span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> 1px 3px<span style="color: #339933;">;</span> <span style="color: #339933;">-</span>moz<span style="color: #339933;">-</span>border<span style="color: #339933;">-</span>radius<span style="color: #339933;">:</span> 3px<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; .<span style="color: #660066;">GM_downloads_count_2000</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; background<span style="color: #339933;">:</span>#f9f49d<span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> 1px 3px<span style="color: #339933;">;</span> <span style="color: #339933;">-</span>moz<span style="color: #339933;">-</span>border<span style="color: #339933;">-</span>radius<span style="color: #339933;">:</span> 3px<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;&lt;/&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> hilightCounter<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> downloadsSpan <span style="color: #339933;">=</span> $X<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'//span[@class=&quot;info-marker&quot;][text()=&quot;Downloads&quot;]'</span> <span style="color: #339933;">,</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>len<span style="color: #339933;">=</span>downloadsSpan.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>len<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> countTextNode <span style="color: #339933;">=</span> downloadsSpan<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nextSibling</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> downloadCount <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>countTextNode.<span style="color: #660066;">textContent</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;g&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">// 数値化</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> parDownload <span style="color: #339933;">=</span> downloadsSpan<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">parentNode</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> span <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downloadCount <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">50000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; span.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;GM_downloads_count_50000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downloadCount <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; span.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;GM_downloads_count_10000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downloadCount <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; span.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;GM_downloads_count_5000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downloadCount <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; span.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;GM_downloads_count_2000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; span.<span style="color: #660066;">textContent</span> <span style="color: #339933;">=</span> countTextNode.<span style="color: #660066;">textContent</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parDownload.<span style="color: #660066;">replaceChild</span><span style="color: #009900;">&#40;</span>span <span style="color: #339933;">,</span> countTextNode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
document.<span style="color: #660066;">body</span>.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'AutoPagerize_DOMNodeInserted'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> node <span style="color: #339933;">=</span> evt.<span style="color: #660066;">target</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//var requestURL = evt.newValue;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//var parentNode = evt.relatedNode;</span><br />
&nbsp; &nbsp; hilightCounter<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
hilightCounter<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #006600; font-style: italic;">// $X on XHTML</span><br />
<span style="color: #006600; font-style: italic;">// @target Freifox3, Chrome3, Safari4, Opera10</span><br />
<span style="color: #006600; font-style: italic;">// @source http://gist.github.com/184276.txt</span><br />
<span style="color: #003366; font-weight: bold;">function</span> $X <span style="color: #009900;">&#40;</span>exp<span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; context <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>context <span style="color: #339933;">=</span> document<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> _document &nbsp;<span style="color: #339933;">=</span> context.<span style="color: #660066;">ownerDocument</span> <span style="color: #339933;">||</span> context<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; documentElement <span style="color: #339933;">=</span> _document.<span style="color: #660066;">documentElement</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; isXHTML <span style="color: #339933;">=</span> documentElement.<span style="color: #660066;">tagName</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'HTML'</span> <span style="color: #339933;">&amp;&amp;</span> _document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">tagName</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'p'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; defaultPrefix <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isXHTML<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultPrefix <span style="color: #339933;">=</span> <span style="color: #3366CC;">'__default__'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exp <span style="color: #339933;">=</span> addDefaultPrefix<span style="color: #009900;">&#40;</span>exp<span style="color: #339933;">,</span> defaultPrefix<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> resolver <span style="color: #009900;">&#40;</span>prefix<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> context.<span style="color: #660066;">lookupNamespaceURI</span><span style="color: #009900;">&#40;</span>prefix <span style="color: #339933;">===</span> defaultPrefix <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">:</span> prefix<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;documentElement.<span style="color: #660066;">namespaceURI</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> _document.<span style="color: #660066;">evaluate</span><span style="color: #009900;">&#40;</span>exp<span style="color: #339933;">,</span> context<span style="color: #339933;">,</span> resolver<span style="color: #339933;">,</span> XPathResult.<span style="color: #660066;">ANY_TYPE</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>result.<span style="color: #660066;">resultType</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">case</span> XPathResult.<span style="color: #660066;">STRING_TYPE</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> result.<span style="color: #660066;">stringValue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">case</span> XPathResult.<span style="color: #660066;">NUMBER_TYPE</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> result.<span style="color: #660066;">numberValue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">case</span> XPathResult.<span style="color: #660066;">BOOLEAN_TYPE</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">return</span> result.<span style="color: #660066;">booleanValue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">case</span> XPathResult.<span style="color: #660066;">UNORDERED_NODE_ITERATOR_TYPE</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// not ensure the order.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> ret <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> i <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> result.<span style="color: #660066;">iterateNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ret.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>このブログを読んでる人達ならそろそろグリモン見慣れてきたんじゃないか？泣きながらソース読んでたDJも慣れてきたよ。</p>
<p>12行目からはxmlリテラルでstyleを追加。でも、先頭の<>ってのはなんだろう？</p>
<p>61行目の$X関数はXPathのためのラッパー。こうして見ると色々な人が色々なXPathユーティリティーを選んでるのがわかる。$X関数は比較的昔からあって有名な方なんじゃないかと思う。</p>
<p>26行目のhilightCounterで注文通り、ダウンロード数別に色を変えるためにclassを割り当ててる。</p>
<p>41行目はびっくり。AutoPagerizeのイベントにひっかけてる。ブログのソースコードのSyntax HilightingとかJSのonloadでやってる場合に、AutoPagerizeの2ページ目からは反映されなくてガッカリ・・・ってことが多かったんだけどこれを使えばイケる！</p>
<p>これはDJ得した気分。</p>
<p>WordPressのプラグインページは見る人が多いからuserscripts.orgにきちんと登録してある点も素敵だ。</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/406.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/406.html" />
	</item>
		<item>
		<title>コードDJ 第7回 &#8211; WordPressの擬似cron機構</title>
		<link>http://fjord.jp/love/401.html</link>
		<comments>http://fjord.jp/love/401.html#comments</comments>
		<pubDate>Tue, 13 Jul 2010 06:59:45 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Help me hackers!]]></category>
		<category><![CDATA[コードDJ]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=401</guid>
		<description><![CDATA[毎週火曜日、Help me, hackers!に上がったコードを紹介していくコードDJ 第7回。
今、流行の２４シーズン１を見ているkomagata a.k.a. DJ（@流行に疎い方）です。
今回紹介するコードはコレ。 [...]]]></description>
			<content:encoded><![CDATA[<p>毎週火曜日、<a href="http://help-me-hackers.com/"title="Help me, hackers!" >Help me, hackers!</a>に上がったコードを紹介していくコードDJ 第7回。</p>
<p>今、流行の２４シーズン１を見ているkomagata a.k.a. DJ（@流行に疎い方）です。</p>
<p>今回紹介するコードはコレ。</p>
<p><a href="http://help-me-hackers.com/tasks/93">任意の期間、ブログが更新されないとメールが飛ぶwordpressのplugin &#8211; Help me, hackers!</a></p>
<p>出題したのは<a href="http://help-me-hackers.com/machida">@machida</a> a.k.a. お米嫌い。議論に対していきなりコードで回答を示したのが<a href="http://help-me-hackers.com/terakuma">@terakuma</a> a.k.a. 法務系PHPer。</p>
<p>コード：</p>
<div class="codecolorer-container php geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">/*<br />
Plugin Name: Remember The WordPress<br />
Plugin URI: http://github.com/e2esoundcom/Remember-The-WordPress<br />
Description: If you forgot write a new post,this plugin send you E-mail.<br />
Version: 0.2<br />
Author: Yuya Terajima<br />
Author URI: http://www.e2esound.com/<br />
*/</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* When Activate Plugin<br />
==================================================================== */</span><br />
<span style="color: #000000; font-weight: bold;">function</span> rtw_activate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$terms</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//default terms</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$unixtime_per_day</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">86400</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Remember the WordPress!!&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Blogの更新が滞っているようです。サイトの更新をお願いします。&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_initialized'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_initialized'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_initialized'</span><span style="color: #339933;">,</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_terms'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_terms'</span><span style="color: #339933;">,</span><span style="color: #000088;">$terms</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$unixtime_per_day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_email'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_email'</span><span style="color: #339933;">,</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_subject'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_subject'</span><span style="color: #339933;">,</span><span style="color: #000088;">$subject</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_message'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_message'</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; wp_schedule_event<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">86400</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'daily'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rtw_cron'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
register_activation_hook<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rtw_activate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> get_latest_post_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT post_date FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">posts</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE post_status = 'publish' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">posts</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;`.`post_date` DESC LIMIT 0,1&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> rtw_sendmail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$subject</span> &nbsp;<span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_subject'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$mailbody</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$to_email</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.php.net/mb_send_mail"><span style="color: #990000;">mb_send_mail</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to_email</span><span style="color: #339933;">,</span><span style="color: #000088;">$subject</span><span style="color: #339933;">,</span><span style="color: #000088;">$mailbody</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> rtw_compare_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$unixtime_per_day</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">86400</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$latest</span> <span style="color: #339933;">=</span> get_latest_post_time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$terms</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_terms'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$latest</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$terms</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rtw_sendmail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_cron'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rtw_compare_time'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* When New Post or Edited Post.<br />
==================================================================== */</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> rtw_new_posted<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_initialized'</span><span style="color: #339933;">,</span><a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_post'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rtw_new_posted'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* When De-Activate Plugin<br />
==================================================================== */</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> rtw_deactivate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; wp_clear_scheduled_hook<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_cron'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_initialized'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_terms'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_subject'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
register_deactivation_hook<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rtw_deactivate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">/* Admin<br />
==================================================================== */</span><br />
<span style="color: #000000; font-weight: bold;">function</span> rtw_add_admin_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; add_options_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Remember The WordPress'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Remember The WP'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'administrator'</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rtw_add_admin_page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rtw_add_admin_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> rtw_add_admin_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'posted'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$posted</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'posted'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$posted</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$unixtime_per_day</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">86400</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$posted</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Validation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[1-3][0-9]|[1-9]/'</span><span style="color: #339933;">,</span><a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'terms'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'terms'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_terms'</span><span style="color: #339933;">,</span><a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'terms'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$unixtime_per_day</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_email'</span><span style="color: #339933;">,</span><a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_subject'</span><span style="color: #339933;">,</span><a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'subject'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_message'</span><span style="color: #339933;">,</span><a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$rtw_error</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$rtw_error</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Admin Page Start</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Updated Message</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$posted</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span> AND <span style="color: #000088;">$rtw_error</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;div class=&quot;updated&quot;&gt;&lt;p&gt;&lt;strong&gt;設定を保存しました&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$posted</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span> AND <span style="color: #000088;">$rtw_error</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;div class=&quot;error&quot;&gt;&lt;p&gt;&lt;strong&gt;アラート発生日数は1-30の間の値を入力して下さい。&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&lt;div class=&quot;wrap&quot;&gt;<br />
&nbsp; &nbsp; &lt;h2&gt;Remember The WordPress Settings&lt;/h2&gt;<br />
&nbsp; &nbsp; &lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'%7E'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'~'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;posted&quot; value=&quot;yes&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;table class=&quot;form-table&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr valign=&quot;top&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th scope=&quot;row&quot;&gt;&lt;label for=&quot;terms&quot;&gt;アラート発生日数&lt;label&gt;&lt;/th&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input name=&quot;terms&quot; type=&quot;text&quot; id=&quot;terms&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_terms'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$unixtime_per_day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;regular-text code&quot; /&gt;&lt;br /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1-30までの数字を入力してください。<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr valign=&quot;top&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th scope=&quot;row&quot;&gt;&lt;label for=&quot;email&quot;&gt;送信先E-mailアドレス&lt;label&gt;&lt;/th&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input name=&quot;email&quot; type=&quot;text&quot; id=&quot;email&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/htmlspecialchars"><span style="color: #990000;">htmlspecialchars</span></a><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;regular-text code&quot; /&gt;&lt;br /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; アラートメールの送信先E-mailアドレスを入力してください。<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr valign=&quot;top&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th scope=&quot;row&quot;&gt;&lt;label for=&quot;terms&quot;&gt;メールタイトル&lt;label&gt;&lt;/th&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input name=&quot;subject&quot; type=&quot;text&quot; id=&quot;subject&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/htmlspecialchars"><span style="color: #990000;">htmlspecialchars</span></a><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_subject'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;regular-text code&quot; /&gt;&lt;br /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 送信メッセージの「タイトル」を入力してください。<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr valign=&quot;top&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th scope=&quot;row&quot;&gt;&lt;label for=&quot;terms&quot;&gt;メール本文&lt;label&gt;&lt;/th&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;textarea name='message' id='message' cols='50' rows='10'&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/htmlspecialchars"><span style="color: #990000;">htmlspecialchars</span></a><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rtw_message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;br /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 送信メッセージの「内容」を入力してください。<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/table&gt;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;p class=&quot;submit&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;submit&quot; name=&quot;Submit&quot; class=&quot;button-primary&quot; value=&quot;変更を保存&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/p&gt;<br />
&nbsp; &nbsp; &lt;/form&gt;<br />
&lt;/div&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>少々長いがへこたれずに頑張ってみていくことにしよう。（自分自身を鼓舞）</p>
<h4>WordPressプラグインの作成方法</h4>
<p>前提としてこれはWordPressプラグインなのでその大まかな作り方を紹介しよう。</p>
<p>まず、単体のphpファイルか、もしくは同名のディレクトリにプラグイン用のファイルを作る。<br />
（例：foo_plugin/foo_plugin.php）</p>
<p>プラグインの各種情報は決まったコメントの書き方があるのでそれにしたがってファイル内先頭に書く。これがWordPressのプラグイン管理画面に出てくる情報になる。</p>
<p>一番単純なプラグインとしては、プラグインを管理画面から有効にすると、プラグインのphpファイルがWordPressにincludeされる。よって適当な関数をプラグイン内で定義しておき、テーマの中で使うといったことが可能だ。（モチロン名前はぶつかる可能性がある。プラグイン名をprefixにした関数を作るか、プラグイン名のクラスに閉じ込めることが推奨されている。）</p>
<p>これでWordPressの関数や変数、DBをプラグイン内からでも使うことが出来る。また、プラグイン用にactionやfilterといったフックをかける事ができる。この辺は公式ドキュメントに全関数リファレンスやプラグイン用のフックの説明がちゃんとあるのでPHPが分かれば理解するのは容易だ。（<a href="http://wpdocs.sourceforge.jp/">Main Page &#8211; WordPress Codex 日本語版</a>）</p>
<h4>擬似cron</h4>
<p>今回のコードを理解する上でもう一つ必要になるのが、wp_schedule_event関数を使った擬似cronの仕組みだ。WordPressにはwp_schedule_event関数でcronのように定期スケジュールを登録することが出来る。こういう処理はcron daemonのように常に起動しているプロセスと連携する必要があり、一見単純なPHPウェブアプリだけでは無理に思えるが、Webからのユーザーリクエストのみをトリガーにcronのようなスケジュール実行を可能にしている。</p>
<p>もちろんWebからのリクエスト頼みなのでアクセスがまったく来なければスケジュールした時間には実行されない擬似的な機能なので厳密な処理には向かない。しかし、一般的なサイトであれば大抵毎分１アクセスぐらいはあるので大体このぐらいの頻度でやって欲しいといった処理なら実用上は問題なさそうだ。</p>
<p>参照：<a href="http://codex.wordpress.org/Function_Reference/wp_schedule_event">Function Reference/wp schedule event « WordPress Codex</a></p>
<p>こんないい加減な仕組み使うなんてありえねー！とヤルタイプからは言われそうだが、phpのsession削除は同様の仕組みで行われている。（アクセスが来なければ永久にセッションファイルは消えない）<br />
根本的なこの仕組の是非は兎も角、PHPの流儀に従った実装方法ではあると言える。</p>
<p>参照：<a href="http://jp2.php.net/manual/ja/session.configuration.php#ini.session.gc_maxlifetime">PHP: 実行時設定 &#8211; Manual</a></p>
<h4>Remenber The WordPress</h4>
<p>まず、38行目でregister_activation_hook関数で自分自身のファイルのrtw_activate関数をactivation_hookに登録している。activationとはプラグイン管理画面でそのプラグインを「有効」にしたときのことだ。データベーステーブルを独自に持つようなプラグインでは大抵この場所でテーブルをCREATEしている。（WordPressはORMを提供していないので、各種プラグインのこの場所にはMySQLに特化したSQLが大抵使用されている。WordPressはプラグインエコシステムがキモであるため、コレのせいで他DBへの対応が非常に難しくなっている。）</p>
<p>rtw_activate関数の中でwp_schedule_eventを使ってdailyで実行されるようにrtw_cronを登録している。</p>
<p>あとは、40行目のget_latest_post_time関数で最終投稿日を取得して、管理画面で設定できる「何日更新が無かったらメールを送るか？」という値と比較してmb_send_mailでメールを送っている。</p>
<p>殆どの行数は管理画面用なので長く見えるし大変そうだが、管理画面からプラグインの設定が出来るというのがWordPressユーザーに非常に訴える箇所なので重要だ。</p>
<p>議論にコードで答えた事。（これが結構貴重なんだが）WordPress流儀に則った実装。管理画面まで手を抜かない所。等々、@terakuma a.k.a. 法務系PHPerは素晴らしい。それに<a href="http://www.rememberthemilk.com/"title="" >Remember The Milk</a>をパクったRemember The WordPressというプラグイン名も素敵だ。</p>
<p>WordPressプラグインで困ったことがあったら@terakuma a.k.a. 法務系PHPerに相談してみたらいいかもしれない！</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/401.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/401.html" />
	</item>
		<item>
		<title>コードDJ 第6回 &#8211; はやい！もうついたのか！</title>
		<link>http://fjord.jp/love/383.html</link>
		<comments>http://fjord.jp/love/383.html#comments</comments>
		<pubDate>Tue, 06 Jul 2010 11:03:05 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Help me hackers!]]></category>
		<category><![CDATA[コードDJ]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=383</guid>
		<description><![CDATA[毎週火曜日、Help me, hackers!に上がったコードを紹介していくコードDJ 第6回。
おい！ワールドカップ見てない癖に適当に話を合わせるのは辞めろ！DJ？モチロン見てたよ。本田のシュートは凄かったよね！・・・ [...]]]></description>
			<content:encoded><![CDATA[<p>毎週火曜日、<a href="http://help-me-hackers.com/"title="Help me, hackers!" >Help me, hackers!</a>に上がったコードを紹介していくコードDJ 第6回。</p>
<p>おい！ワールドカップ見てない癖に適当に話を合わせるのは辞めろ！DJ？モチロン見てたよ。本田のシュートは凄かったよね！・・・くらいやがれ！これが俺のワールドカップに対する知識の全てだ！</p>
<p>komagata a.k.a. DJです。</p>
<p>今回紹介するのはコレ。</p>
<p><a href="http://help-me-hackers.com/tasks/106">無印良品のサイトの表示をデフォルトで「安い順、150件表示」にする &#8211; Help me, hackers!</a></p>
<p>まさに「プログラマーにとって解きたくなるような問題」といったセンスの良い問題を投稿してくれたのは<a href="http://help-me-hackers.com/monoooki">@monoooki</a> a.k.a. <a href="http://maedaseisaku.com/">前田製作所</a>。</p>
<p>そして解決してくれたのはお馴染み<a href="http://help-me-hackers.com/milk1000cc">@milk1000cc</a> a.k.a. 牛乳嫌いプログラマ on Rails。（@milk1000ccはDJのストーキング情報によれば最近<a href="http://ponpon.milk1000.cc/">PONPON</a>というグルーポン情報まとめサイトをRails, Herokuで公開したらしいRails野郎だ。）</p>
<p>二人ともありがとう！</p>
<p>しかし、ちょっと待ってくれ。コイツをどう思う？（＠阿部高和）</p>
<pre>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">% heroku console<br />
&gt;&gt; Task.find(106).created_at<br />
=&gt; Tue, 06 Jul 2010 04:16:07 UTC +00:00<br />
&gt;&gt; Task.find(106).comments.correct.first.created_at<br />
=&gt; Tue, 06 Jul 2010 07:02:54 UTC +00:00</div></td></tr></tbody></table></div>
</pre>
<p>「すごく・・・早いです・・・。」（＠道下正樹）</p>
<p>タスクが登録されてからわずか3時間足らずで解決されている。（＠荒巻）</p>
<p>たしかにDJも「これは解きたくなる問題だな」とは思ってはいたが、あまりにもはやすぐるでしょう？</p>
<p>本題のタスクの内容は、</p>
<p class="center"><a href="http://www.flickr.com/photos/komagata/4767613698/" title="無印良品ネットストア by komagata, on Flickr"><img src="http://farm5.static.flickr.com/4135/4767613698_c82ef8244b.jpg" width="500" height="368" alt="無印良品ネットストア"></a></p>
<p>こんな感じで無印良品ネットストアのデフォルトは「おすすめ順」「50件表示」になってる。それを「安い順」「150件表示」をデフォルトになるようにして欲しいというタスク。</p>
<p>あるある。確かにハードに使ってるサイトでこういうちょっとしたところを俺仕様にしたいことある。</p>
<p>それを通常ならありえない速さできょうきょ参戦（＠ブロントさん）してくれたグリモンコードがコレ。</p>
<p><a href="http://gist.github.com/465095">http://gist.github.com/465095</a><br />
（右上のrawのリンクをクリックでグリモンスクリプトインストール）</p>
<pre lang="javascript">
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">// ==UserScript==<br />
// @name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AutoMujiSort<br />
// @namespace &nbsp; &nbsp; &nbsp;http://www.milk1000.cc/<br />
// @include &nbsp; &nbsp; &nbsp; &nbsp;http://www.muji.net/store/cmdty/section/*<br />
// ==/UserScript==<br />
<br />
(function() {<br />
&nbsp; &nbsp; var OLD_PATTERN = { sort: 4, count: 12 };<br />
&nbsp; &nbsp; var NEW_PATTERN = { sort: 0, count: 150 };<br />
<br />
&nbsp; &nbsp; var $ = function(selector) { return document.querySelector(selector); };<br />
<br />
&nbsp; &nbsp; if ($('select[name=&quot;sort&quot;]') &amp;&amp; $('select[name=&quot;sort&quot;]').value == OLD_PATTERN.sort &amp;&amp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $('select[name=&quot;count&quot;]') &amp;&amp; $('select[name=&quot;count&quot;]').value == OLD_PATTERN.count) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $('select[name=&quot;sort&quot;]').value = NEW_PATTERN.sort;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $('select[name=&quot;count&quot;]').value = NEW_PATTERN.count;<br />
&nbsp; &nbsp; &nbsp; &nbsp; (typeof unsafeWindow != 'undefined' ? unsafeWindow : window).sort();<br />
&nbsp; &nbsp; }<br />
})();</div></td></tr></tbody></table></div>
</pre>
<p>きれいなコード。DJ以前はグリモンのコード「嫌だなぁ、嫌だなぁ、怖いなぁ」（@稲川淳二）なんて思ってたけどこの連載のお陰でむしろ好きになってきた。読み易い。</p>
<p>11行目のquerySelectorを$に割り当てるのはECMAScripterお馴染みパンチライン。最初のvarはconstにしたら速くなるのかも？</p>
<p>17行目のunsafeWindowを見てるのは多分ブラウザによって違うところなんだろう。</p>
<p>DJそろそろ気付いてきたんだが、今、タスクの需要と供給は依頼が少ない状態にある。特にJavascriptのタスクは監視してるイカレタHacker達が飢えた獣のように跳びかかり、瞬時に解決されてしまう。</p>
<p>成果物の公開方法やパッケージング方法、環境作りが楽なグリモン・JavascriptはHacker側にとって非常にやりやすい。そういう事情を踏まえた依頼の仕方もセンスが問われている。</p>
<p>センスを磨くか、金を積むか。そういう仕組みになっているらしい。</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/383.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/383.html" />
	</item>
		<item>
		<title>コードDJ 第5回 – ウォーターマークが消えなければ消せばいいじゃない</title>
		<link>http://fjord.jp/love/380.html</link>
		<comments>http://fjord.jp/love/380.html#comments</comments>
		<pubDate>Tue, 29 Jun 2010 01:26:31 +0000</pubDate>
		<dc:creator>komagata</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[Help me hackers!]]></category>
		<category><![CDATA[コードDJ]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=380</guid>
		<description><![CDATA[毎週火曜日、Help me, hackers!に上がったコードを紹介していくコードDJ 第5回。
TimeMachineで自動バックアップを取っていても結局クリーンインストール後は手でデータを復旧させる昭和の男、koma [...]]]></description>
			<content:encoded><![CDATA[<p>毎週火曜日、<a href="http://help-me-hackers.com/"title="Help me, hackers!" >Help me, hackers!</a>に上がったコードを紹介していくコードDJ 第5回。</p>
<p>TimeMachineで自動バックアップを取っていても結局クリーンインストール後は手でデータを復旧させる昭和の男、komagata a.k.a. DJです。</p>
<p>今回はコレ、<a href="http://help-me-hackers.com/tasks/94">フォームのデフォルトの文字をフォーカスが移ったら消す &#8211; Help me, hackers!</a></p>
<p>コレの経緯はこんな感じだ。</p>
<ol>
<li><a href="http://help-me-hackers.com/F5V">F5V</a> a.k.a. PHPerより<a href="http://hamcutlet.fjord.jp/"title="HTMLのインデントを美しく「Ham Cutlet（通称ハムカツ）」" >Ham Cutlet</a>にTwitter経由で上記の要望が入る。</li>
<li>DJが要望をHelp me, hacekrs!に登録する。</li>
<li><a href="http://help-me-hackers.com/mongorian_chop">mongorian_chop</a> a.k.a. 自由人からjQuery Watermark Pluginの情報を貰う。</li>
<li>USTREAMの開発生放送でDJが上記プラグインでの実装に敗北。</li>
<li>見るに見かねたmongorian_chopが実装してpull request。</li>
</ol>
<p>１００万語の言葉より１つのpull request。コードは偉大だ。</p>
<p>「コード！コード！コード！」</p>
<p>「よし、ならばコードだ。」</p>
<p>今回のキモはココ。</p>
<p><a href="http://github.com/mongorian-chop/hamcutlet/blob/c7cf55da11f2131568deda5b1d4b7a46742943f8/views/index.haml#L39-48">views/index.haml at c7cf55da11f2131568deda5b1d4b7a46742943f8 from mongorian-chop&#8217;s hamcutlet &#8211; GitHub</a></p>
<pre lang="javascript">
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$(document).ready(function(){<br />
&nbsp; &nbsp; $.updnWatermark.attachAll();<br />
&nbsp; &nbsp; $('.updnWatermark &gt; label').click(function(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(this).toggle();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;textarea&quot;).select();<br />
&nbsp; &nbsp; }).blur(function(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(this).toggle();<br />
&nbsp; &nbsp; }); <br />
});</div></td></tr></tbody></table></div>
</pre>
<p>$(document).ready(function(){ &#8230; }) はお馴染み、DOMの構築が終わった瞬間に実行してくれるjQueryの書き方だ。$(function() { &#8230; }) でも同じ。画像の読み込み等を待たない分、onloadより速いのでjQuerystはドンドン使ってこ！</p>
<p>今回、DJが挫折してたのはjQuery Watermark Pluginをtextareaに使った時に、そのWatermarkのテキスト自身をクリックした場合にWatermakが消えないところだ。</p>
<p>mongorian_chopはそこをちゃんと消すコードを書いてくれた。ありがとう！</p>
<p>jQueryだとちょっと面倒に思えた処理もこんなにスマートな見た目で書けるなんて。DJこの連載のおかげで強制的にJS勉強させられてるね！</p>
<p>DJ、今現在もHelp me, hacekers!上で複数のコード野郎共とコラボ中だ。議論する暇があったらコードを送りつけろ！</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/380.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/380.html" />
	</item>
		<item>
		<title>「komagata a.k.a. ラペコの肉番長」への挑戦者求む！</title>
		<link>http://fjord.jp/love/370.html</link>
		<comments>http://fjord.jp/love/370.html#comments</comments>
		<pubDate>Fri, 25 Jun 2010 16:51:35 +0000</pubDate>
		<dc:creator>machida</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[ウェブサービス]]></category>
		<category><![CDATA[肉]]></category>

		<guid isPermaLink="false">http://fjord.jp/?p=370</guid>
		<description><![CDATA[help me, hackers!でも色々参考に（ときにパクったり）させていただいた@func09さんの美味しそう！を共有するサービス「ラペコ」。
美味しいそうな食べ物の写真が並んでて見ていて楽しい、サイトのデザインも可 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://help-me-hackers.com/"title="Help me, hackers!" >help me, hackers!</a>でも色々参考に（ときにパクったり）させていただいた<a href="http://twitter.com/func09"title="func09さんのtwitter" >@func09</a>さんの美味しそう！を共有するサービス「<a href="http://rapeco.jp/"title="美味しそう！を共有する素敵なサービス「ラペコ」" >ラペコ</a>」。</p>
<p>美味しいそうな食べ物の写真が並んでて見ていて楽しい、サイトのデザインも可愛いくて素敵なサイトです。モニターに映るラペコを前に僕らの間は嫉妬の空気がいつも充満。</p>
<p>ラペコにアップした<a href="http://twitter.com/komagata"title="" >@komagata</a>さんの肉の写真がかなり長い間人気のペコフォトランキングで上位に。<br />
@komagataさんが「komagata a.k.a. rapeco」の肉番長の名を欲しいままにしています。</p>
<p><a href="http://www.flickr.com/photos/fjord_llc/4732823565/" title="snapshot.png by 町田 哲平（teppei machida）, on Flickr"><img src="http://farm2.static.flickr.com/1258/4732823565_c21aed5021.jpg" width="500" height="445" alt="snapshot.png" /></a></p>
<p class="center">2010年6月26日現在2位！</p>
<p class="center"><a href="http://rapeco.jp/pecos/5b2mf4rt"><img src="http://farm2.static.flickr.com/1017/4732915869_200bda3c33_m.jpg" width="240" height="139" alt="snapshot.png" /></a></p>
<p class="center"><a href="http://rapeco.jp/pecos/5b2mf4rt">これが肉番長の肉写真</a></p>
<p>ちなみに写真の右側にいるのが僕で、左がアクトインディ社長の<a href="http://twitter.com/lupin13"title="" >@lupin13</a>さんです。ついでに僕の当時の携帯にもその肉の写真が入ってました（<a href="http://rapeco.jp/pecos/wnbafhxs">ココ</a>）。</p>
<p>@func09さんはhelp me, hackers!にあげた<a href="http://hamcutlet.fjord.jp/"title="HTMLのインデントを美しく「Ham Cutlet（通称ハムカツ）」" >ハムカツ</a>改良タスクを見事な方法で解決にしていただいたり、生放送に付き合ってくれたり、本当ナイスガイなプログラマーさん。いつもありがとうございます。</p>
<p>「komagata a.k.a. ラペコの肉番長」への挑戦者求む！</p>
]]></content:encoded>
			<wfw:commentRss>http://fjord.jp/love/370.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://fjord.jp/love/370.html" />
	</item>
	</channel>
</rss>
