<?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/"
	>

<channel>
	<title>almondlab. &#187; PHP</title>
	<atom:link href="http://www.almondlab.jp/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.almondlab.jp</link>
	<description>Web Design, Graphic Design, FLASH, CMS</description>
	<lastBuildDate>Sat, 28 Jan 2012 15:25:03 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CakePHP 2.0でユーザーのアクセス権限をチェック。</title>
		<link>http://www.almondlab.jp/labs/925</link>
		<comments>http://www.almondlab.jp/labs/925#comments</comments>
		<pubDate>Sat, 08 Oct 2011 08:57:10 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=925</guid>
		<description><![CDATA[CakePHP 2.0 RC3でACLを設定した後に、各コントローラーでアクセス権限をチェックするためのコードメモです。]]></description>
			<content:encoded><![CDATA[<p>CakePHP 2.0 RC3でブログのサンプル、ACLを設定した後に、各コントローラーでアクセス権限をViewのテンプレートファイル内（View/Posts/index.ctpなど）でチェックするためのコードメモです。</p>
<div class="space"></div>
<p>ブログのサンプル、ACLについてはCakePHPマニュアルページの中にあるチュートリアルを参考に設定してみました。（ACLチュートリアルの説明は難解ですね。かなり苦戦しました・・・。）<br />
<span class="link"><a href="http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html" onclick="window.open(this.href); return false;">CakePHPブログチュートリアル（英語）</a></span><br />
<span class="link"><a href="http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html" onclick="window.open(this.href); return false;">ACL を制御するシンプルなアプリケーション（英語）</a></span></p>
<div class="space"></div>
<p>チュートリアルで作成したブログのコントローラ「PostsController.php」のbeforeFilter()の中に下記のコードを記述することで、閲覧しているユーザーのアクセス権限をチェックし、「create」「read」「update」「delete」の各アクションの権限の有無を配列にして、Viewへ渡すデータにセットするようにしています。</p>
<div class="space"></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> beforeFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$acl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'create'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'read'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'update'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'delete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$acl</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Acl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'posts'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'acl'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$acl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Viewのテンプレート上では次のように利用できます。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$acl</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'create'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'add'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>ユーザーの権限によって、編集や削除のリンクを、表示／非表示にしたい場合などに使えるかなと思います。<br />
他にもっと良い方法があるかもしれませんが・・・。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/925/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal 7でメニューをカスタムに表示する際のメモ。</title>
		<link>http://www.almondlab.jp/notes/908</link>
		<comments>http://www.almondlab.jp/notes/908#comments</comments>
		<pubDate>Wed, 07 Sep 2011 13:29:42 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Drupal7]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=908</guid>
		<description><![CDATA[Drupal 7の管理画面で作成したメニューをテーマのテンプレート内に追加することでカスタムに表示ができます。]]></description>
			<content:encoded><![CDATA[<p>通常、管理画面で作成したメニューはブロックを使うことで割り当てられた場所に配置ができますが、テンプレート内に直接追加することもできます。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">print</span> theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'links'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'links'</span> <span style="color: #339933;">=&gt;</span> menu_navigation_links<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'menu-custom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'attributes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'custom'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>上記では「menu-custom」という名前で作成したメニューを、テンプレートファイル「page.tpl.php」に追加することで、カスタムに表示することができます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/908/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHPで「home.ctp」のレイアウトを変更。</title>
		<link>http://www.almondlab.jp/notes/873</link>
		<comments>http://www.almondlab.jp/notes/873#comments</comments>
		<pubDate>Wed, 25 May 2011 04:50:37 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=873</guid>
		<description><![CDATA[CakePHPで「home.ctp（トップページ）」のレイアウトを変更する方法です。]]></description>
			<content:encoded><![CDATA[<p>CakePHPでトップページの表示を変更するには「app/views/pages/home.ctp」を書き換えることで可能です。<br />
この場合レイアウトは、自動的に「app/views/layouts/default.ctp」を利用します。</p>
<div class="space"></div>
<p>通常レイアウトの変更には、コントローラーのアクションに「$this->layout = &#8216;default&#8217;;」といった感じで、任意に変更ができるのですが、もともとコントローラーを作成しないトップページの場合では、簡単にレイアウトの変更ができません。</p>
<div class="space"></div>
<p>そのための解決方法として、トップページの表示を担うコントローラーをCakePHPコアのライブラリからコピーして、一部修正することにします。<br />
はじめに、コアに含まれるライブラリ「cake/libs/controller/pages_controller.php」を、「app/controllers」にコピーします。</p>
<div class="space"></div>
<p>「pages_controller.php」内のdisplayアクションは次のようになっています。（バージョン1.3.8）</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> display<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$subpage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$title_for_layout</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$subpage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$title_for_layout</span> <span style="color: #339933;">=</span> Inflector<span style="color: #339933;">::</span><span style="color: #004000;">humanize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">compact</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'subpage'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'title_for_layout'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>このdisplayアクションに、レイアウトを指定する記述を追加することで、トップページ用のレイアウトを変更できます。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>64
65
66
67
68
69
70
71
72
73
74
75
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> display<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//ここから</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'home'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//ここまで</span>
&nbsp;
	<span style="color: #339933;">...</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>上記の例では、ページのパスが「home（トップページ）」の場合に、「home」レイアウトを利用するようにしています。<br />
後は「app/views/layouts」フォルダに、テンプレート「home.ctp」を作成すればレイアウトの変更が可能になります。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/873/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal 7でユーザープロフィールの項目をノード内に出力。</title>
		<link>http://www.almondlab.jp/labs/855</link>
		<comments>http://www.almondlab.jp/labs/855#comments</comments>
		<pubDate>Mon, 23 May 2011 12:15:15 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal7]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=855</guid>
		<description><![CDATA[Drupal 7でユーザープロフィールの項目を、ノードの投稿者情報に関連づけて出力する方法です。]]></description>
			<content:encoded><![CDATA[<p>Drupal 7から標準で実装されたユーザープロフィールの項目を、ノードの投稿者情報に関連づけて出力する方法です。</p>
<div class="space"></div>
<p>一般的にユーザーアカウントの名前には英数字のみで構成されるので、それとは別に日本語での名前を、ユーザープロフィールに「field_name」として追加しています。<br />
<img src="http://www.almondlab.jp/wp-content/uploads/drupal7-user-profile.png" alt="Drupal 7 User Profile" title="Drupal 7 User Profile" width="803" height="430" class="frame space" /><br />
ユーザープロフィールを出力する一番簡単な方法は、ビューを使うことですが、今回はテーマに組み込む方法で出力を行います。</p>
<div class="space"></div>
<p>テーマに変更を加えるのは次の2つです。</p>
<ol>
<li>「template.php」にpreprocess関数を追加</li>
<li>「node.tpl.php」にユーザープロフィール変数の出力コードを追加</li>
</ol>
<div class="space"></div>
<p>テーマフォルダの中に含まれている「template.php」ファイルに、次のようにpreprocess関数を追加します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> THEMENAME_preprocess_node<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT field_name_value  FROM {field_data_field_name} where entity_id= :uid&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':uid'</span> <span style="color: #339933;">=&gt;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchField</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alter_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>関数名の「THEMENAME」の部分は、実際のテーマ名に置き換えます。<br />
ここでは投稿者の「uid」からユーザープロフィール「field_name」を参照して、「node.tpl.php」に渡す変数の配列に値を追加しています。</p>
<div class="space"></div>
<p>次に「node.tpl.php」にて、上記で渡された変数を出力します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$alter_name</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>「node.tpl.php」ファイルを書き換え後は、「パフォーマンス」でキャッシュのクリアをしないと、うまく反映していないかもしれません。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/855/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>整数を指定桁数に合わせて0で埋めるスクリプト。</title>
		<link>http://www.almondlab.jp/notes/781</link>
		<comments>http://www.almondlab.jp/notes/781#comments</comments>
		<pubDate>Sun, 16 Jan 2011 02:51:05 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=781</guid>
		<description><![CDATA[PHP、JavaScript、ActionScriptそれぞれで、整数を指定桁数に合わせて0で埋めるスクリプトのメモです。]]></description>
			<content:encoded><![CDATA[<p>PHP、JavaScript、ActionScriptそれぞれで、整数を指定桁数に合わせて0で埋めるスクリプトのメモです。<br />
いずれの場合も一つ目の引数に対象となる整数、二つ目の引数に桁数を渡しています。<br />
JavaScriptとActionScriptは型指定の有無の違いだけで、同じスクリプトで動作します。</p>
<div class="space"></div>
<h3>PHP</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> convertNum<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1234</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//01234</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> convertNum<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #339933;">,</span> <span style="color: #000088;">$figures</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%0&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$figures</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<div class="space"></div>
<h3>JavaScript</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> convertNum<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1234</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//01234</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> convertNum<span style="color: #009900;">&#40;</span>num<span style="color: #339933;">,</span> figures<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> String<span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> figures<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		str <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">+</span>str<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> str<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div class="space"></div>
<h3>ActionScript</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> result = convertNum<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1234</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//01234</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> convertNum<span style="color: #000000;">&#40;</span>num<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span> figures<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> str<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>num<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>str<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&lt;</span> figures<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		str = <span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">+</span>str<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> str<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/781/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPressのページ機能を活用。</title>
		<link>http://www.almondlab.jp/notes/732</link>
		<comments>http://www.almondlab.jp/notes/732#comments</comments>
		<pubDate>Sun, 19 Dec 2010 10:22:53 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=732</guid>
		<description><![CDATA[WordPressのページ機能で、静的サイトの作成に活用する方法です。]]></description>
			<content:encoded><![CDATA[<p>WordPressには通常の投稿以外に、固定ページを作成するためのページ機能があります。<br />
通常の利用では投稿した記事ページとあまり差がないようですが、テンプレートを切り替えることで、ページ機能の使い道の幅が広がります。</p>
<div class="space"></div>
<p>ページ機能で作成したページすべてに利用するためのテンプレートは「page.php」となりますが、各ページ個別にテンプレートを切り替えるには、ページスラッグを後に続けて「page-one.php」「page-two.php」となります。<br />
<img src="http://www.almondlab.jp/wp-content/uploads/wordpress-page-01.png" alt="WordPress" title="WordPress" width="649" height="279" class="space frame" /><br />
ページ機能テンプレートの本来の使い方は、WordPressの投稿フォームで入力した内容を自由なデザインで表示するためのものですが、WordPressでの入力内容を全く利用せずに、純粋なPHPページを表示するという使い方もあります。<br />
WordPressで用意されているテンプレートタグ「the_title()」「the_content()」を使わないで、直接ページ機能テンプレートに内容を記述していきます。</p>
<div class="space"></div>
<p>例えば全画面フラッシュのページなど、投稿フォームでは作成が難しい場合や、他のプログラム用にXML出力ページに有効です。<br />
もちろんページ機能テンプレート内ではWordPressのテンプレートタグも使えるので、より柔軟な静的サイトの作成に応用できます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/732/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPで西暦を和暦に変換。</title>
		<link>http://www.almondlab.jp/notes/662</link>
		<comments>http://www.almondlab.jp/notes/662#comments</comments>
		<pubDate>Wed, 02 Jun 2010 10:12:57 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=662</guid>
		<description><![CDATA[PHPで西暦を和暦の表記に変換するためのコードです。]]></description>
			<content:encoded><![CDATA[<p>PHPで西暦を和暦の表記に変換するためのコードです。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> convert_japanese_year<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2000</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//「H12」を出力</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> convert_japanese_year<span style="color: #009900;">&#40;</span><span style="color: #000088;">$year</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%04d</span><span style="color: #009933; font-weight: bold;">%02d</span><span style="color: #009933; font-weight: bold;">%02d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">19890108</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//平成元年（1989年1月8日以降）</span>
		<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;H&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$year</span> <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">1988</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">19261225</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//昭和元年（1926年12月25日以降）</span>
		<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;S&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$year</span> <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">1925</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">19120730</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//大正元年（1912年7月30日以降）</span>
		<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;T&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$year</span> <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">1911</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">18680125</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//明治元年（1868年1月25日以降）</span>
		<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;M&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$year</span> <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">1867</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$year</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/662/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHPで祝日表示付きカレンダーの作成。</title>
		<link>http://www.almondlab.jp/labs/598</link>
		<comments>http://www.almondlab.jp/labs/598#comments</comments>
		<pubDate>Sun, 16 May 2010 05:17:51 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=598</guid>
		<description><![CDATA[PHPのPEARライブラリを使って、祝日の表示を加えたカレンダーの作成方法です。]]></description>
			<content:encoded><![CDATA[<p>PHPのPEARライブラリを使って、祝日の表示を加えたカレンダーの作成方法です。<br />
カレンダーの作成には「<a href="http://pear.php.net/package/Calendar/" onclick="window.open(this.href); return false;">Calendar</a>」ライブラリ、祝日の取得には「<a href="http://pear.php.net/package/Date_Holidays_Japan" onclick="window.open(this.href); return false;">Date_Holidays_Japan</a>」ライブラリを利用しています。<br />
<span class="link"><a href="http://www.almondlab.jp/wp-content/uploads/calendar" onclick="window.open(this.href); return false;">サンプルはこちら</a></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Calendar/Month/Weekdays.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Date/Holidays.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$current_year</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$current_month</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$calMonth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Calendar_Month_Weekdays<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_year</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_month</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//第3引数の0は週の最初を日曜に</span>
<span style="color: #000088;">$calMonth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ja</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;data/Date_Holidays_Japan/lang/Japan/ja_JP.xml&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dh</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>Date_Holidays<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Japan&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_year</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ja_JP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTranslationFile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ja</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ja_JP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$holidays</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//祝日の月日をキーに祝日名を配列に格納</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$dh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHolidays</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$holidays</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$value</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%m<span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$current_year</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;年&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$current_month</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;月&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/h2&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;table class=<span style="color: #000099; font-weight: bold;">\&quot;</span>calendar<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;thead&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;th&gt;日&lt;/th&gt;&lt;th&gt;月&lt;/th&gt;&lt;th&gt;火&lt;/th&gt;&lt;th&gt;水&lt;/th&gt;&lt;th&gt;木&lt;/th&gt;&lt;th&gt;金&lt;/th&gt;&lt;th&gt;土&lt;/th&gt;&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/thead&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tbody&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$calMonth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isFirst</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;tr&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%02d</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thisMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%02d</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thisDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #339933;">,</span> <span style="color: #000088;">$holidays</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>holiday<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//祝日のとき</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isFirst</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>sun<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//週の最初（日曜）のとき</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isLast</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td class=<span style="color: #000099; font-weight: bold;">\&quot;</span>sat<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//週の最後（土曜）のとき</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;span class=<span style="color: #000099; font-weight: bold;">\&quot;</span>day<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">thisDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//祝日に該当する月日の場合、祝日名を出力</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #339933;">,</span> <span style="color: #000088;">$holidays</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;span class=<span style="color: #000099; font-weight: bold;">\&quot;</span>holiday<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$holidays</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isLast</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/tbody&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>あらかじめ祝日の月日、名称を配列に格納しておき、カレンダー生成のループの中で、祝日の判定を行っています。</p>
<div class="space"></div>
<p><span class="link"><a href="http://pear.php.net/package/Calendar/" onclick="window.open(this.href); return false;">PEAR Calendar</a></span><br />
<span class="link"><a href="http://pear.php.net/package/Date_Holidays_Japan" onclick="window.open(this.href); return false;">PEAR Date_Holidays_Japan</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/598/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimplepieでRSSを表示する方法。</title>
		<link>http://www.almondlab.jp/notes/573</link>
		<comments>http://www.almondlab.jp/notes/573#comments</comments>
		<pubDate>Sun, 09 May 2010 10:00:48 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=573</guid>
		<description><![CDATA[他のサイトのRSSフィードを、「Simplepie」というクラスライブラリを使い表示する方法です。]]></description>
			<content:encoded><![CDATA[<p>他のサイトのRSSフィードを、「<a href="http://simplepie.org/" onclick="window.open(this.href); return false;">Simplepie</a>」というクラスライブラリを使い表示する方法です。基本的な使い方は次の通りです。最新から5件のタイトル、投稿日、パーマリンクを表示しています。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;simplepie/simplepie.inc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_feed_url</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.almondlab.jp/feed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enable_cache</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handle_content_type</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_items</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_permalink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_title</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(Y年m月d日)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$title</span><span style="color: #339933;">.</span><span style="color: #000088;">$date</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>複数のサイトのRSSフィードを取得したい場合には、「set_feed_url」メソッドで、URLを配列のかたちで渡します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_feed_url</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">&quot;http://www.almondlab.jp/feed&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">&quot;http://www.example.jp/feed&quot;</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>上記ではキャッシュを無効にしていますが、キャッシュを利用する場合には、「$feed->enable_cache(false)」を削除して、代わりに次のように記述します。キャッシュを保存するディレクトリ、保存期間を指定します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_cache_location</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cache/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//保存するディレクトリ</span>
<span style="color: #000088;">$feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_cache_duration</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//単位は秒で指定</span></pre></td></tr></table></div>

<p><span class="link"><a href="http://simplepie.org/" onclick="window.open(this.href); return false;">Simplepie</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/573/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPressで登録ユーザーのみに閲覧を制限する方法。</title>
		<link>http://www.almondlab.jp/notes/565</link>
		<comments>http://www.almondlab.jp/notes/565#comments</comments>
		<pubDate>Wed, 05 May 2010 04:53:33 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=565</guid>
		<description><![CDATA[サイト全体、または一部のページに対して、登録ユーザーのみに閲覧を制限する方法です。]]></description>
			<content:encoded><![CDATA[<p>サイト全体、または一部のページに対して、登録ユーザーのみに閲覧を制限したい場合には、テーマのテンプレートファイル内に、次のコードを追加します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_user_logged_in<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> auth_redirect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>ログインしていない状態で該当するテンプレートのページを開こうとした場合、ログイン画面に移りユーザー名、パスワードの入力を求められます。<br />
そこでログインするともとのページにリダイレクトされ、ページの閲覧が可能になります。<br />
「is_page()」「is_category()」などと組み合わせると、必要なページのみに制限をかけることができます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/565/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupalでプロフィール情報を取り出す時のメモ。</title>
		<link>http://www.almondlab.jp/notes/548</link>
		<comments>http://www.almondlab.jp/notes/548#comments</comments>
		<pubDate>Thu, 22 Apr 2010 11:19:58 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal6]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=548</guid>
		<description><![CDATA[Drupalのプロフィールモジュールで作成したカスタムフィールドを、データベースから直接取り出す時のメモです。]]></description>
			<content:encoded><![CDATA[<p>Drupalのコアに含まれるプロフィールモジュールではユーザに関連するデータ、本名や電話などを追加で作成できます。プロフィールモジュールで作成したカスタムフィールドを、データベースから直接取り出す時のメモです。<br />
この情報をノードタイプのviewsやcontemplateで使いたい時に、下記のように記述して直接データベースから取得しています。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//uidが3で、プロフィールフィールドのIDが1のデータ</span>
<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> db_result<span style="color: #009900;">&#40;</span>db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT value FROM {profile_values} WHERE uid = <span style="color: #009933; font-weight: bold;">%d</span> AND fid = <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>viewsでコンテンツにCCKのユーザ参照がある場合は、リレーションシップにした方が簡単です。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/548/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>正規表現でファイルの拡張子を取り除く方法。</title>
		<link>http://www.almondlab.jp/notes/541</link>
		<comments>http://www.almondlab.jp/notes/541#comments</comments>
		<pubDate>Sun, 28 Mar 2010 04:10:57 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=541</guid>
		<description><![CDATA[PHPの正規表現によるパターンマッチで、ファイル名から拡張子を取り除いた文字列を取り出す方法です。]]></description>
			<content:encoded><![CDATA[<p>PHPの正規表現によるパターンマッチで、ファイル名から拡張子を取り除いた文字列を取り出す方法です。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span>get_filename<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//test</span>
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span>get_filename<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test.test.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//test.test</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> get_filename<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/(.+)(\.[^.]+$)/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$1</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>パターンマッチ内の1つ目のパーレン「(.+)」で、任意の1文字以上の文字列を表します。<br />
2つ目のパーレン「(\.[^.]+$)」で、文末にある、ドット1文字から始まり、ドット以外の1文字以上の文字列を表しています。<br />
「$1」の部分を「$2」とすることで、2つ目のパーレン（上記の場合「.txt」となります）を取り出すことができます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/541/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScriptからPHPの関数を実行。</title>
		<link>http://www.almondlab.jp/labs/380</link>
		<comments>http://www.almondlab.jp/labs/380#comments</comments>
		<pubDate>Sat, 06 Feb 2010 15:00:29 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLASH]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=380</guid>
		<description><![CDATA[WEBページのFLASHから、任意のPHP関数を呼び出す方法です。]]></description>
			<content:encoded><![CDATA[<p>ActionScriptからPHPを実行するには、「URLLoader」を使ってPHPファイルにアクセスすることができます。その際に引数を渡すには「URLVariables」でGET、またはPOSTの変数を渡すことができます。<br />
この方法では、アクセスするPHPファイル全体を実行します。</p>
<div class="space"></div>
<p>PHPファイル内の任意の関数のみを実行するには、ActionScriptからGET、またはPOSTの変数を経由し、PHPの関数名の文字列を変数で渡して、PHP側で文字列を関数名として評価することで任意の関数を実行できます。</p>
<div class="space"></div>
<p>ActionScriptでは、次のように記述します。（ドキュメントクラスに書いています）</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLLoader</span><span style="color: #000066; font-weight: bold;">;</span>	
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequest</span><span style="color: #000066; font-weight: bold;">;</span>	
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequestMethod</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLVariables</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> url_variables<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLVariables</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLVariables</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> url_request<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;functions.php&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//PHPリクエストのPOST変数にPHPの関数名を含める</span>
			url_variables<span style="color: #000066; font-weight: bold;">.</span>function_name = <span style="color: #990000;">&quot;test&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			url_request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">method</span> = <span style="color: #004993;">URLRequestMethod</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">POST</span><span style="color: #000066; font-weight: bold;">;</span>
			url_request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = url_variables<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//PHPを実行（読み込み）</span>
			<span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>url_request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//PHPの実行が完了したとき</span>
			<span style="color: #339966; font-weight: bold;">function</span> onComplete<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">//テキストフィールドを作成して、PHP関数の出力を表示</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> textfield<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>textfield<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				textfield<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>PHPファイル「functions.php」にPOST変数で関数名「function_name」を文字列で渡します。PHPファイルの読み込み（実行）が完了したら「onCimplete」にて、PHPで出力された文字列「event.target.data」を扱えるようになります。</p>
<div class="space"></div>
<p>PHPファイル「functions.php」には、次のように記述します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//POST変数「function_name」の関数が存在したら実行</span>
<span style="color: #000088;">$function</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//文字列を出力（ActionScriptに渡す）</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;function test&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>「$function」にPOST変数の「function_name」を代入して、同名の関数が存在していたら実行します。<br />
PHPから出力された文字列は、そのままActionScriptで受け取ることができます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/380/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SWFを表示しているURLの取得方法。</title>
		<link>http://www.almondlab.jp/notes/368</link>
		<comments>http://www.almondlab.jp/notes/368#comments</comments>
		<pubDate>Sat, 06 Feb 2010 03:16:14 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=368</guid>
		<description><![CDATA[ActionScript内で、SWFを表示しているページのURLを取得する方法です。]]></description>
			<content:encoded><![CDATA[<p>ActionScriptでSWFの置かれているパスではなく、実際に表示されているページのパスを取得するにはJavaScript、またはPHPとの連携で可能になります。</p>
<div class="space-wide"></div>
<h3>Javascriptの場合</h3>
<p>ActionScriptからJavascriptの関数を実行する「ExternalInterface」で行えます。<br />
HTML内に、パスの値を返すJavaScriptの関数を加えます。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> getPath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> location.<span style="color: #660066;">href</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>ActionScriptではJavaScriptの関数を実行して、戻り値を変数に格納します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> path<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">ExternalInterface</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;getPath&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<div class="space-wide"></div>
<h3>PHP（＆FlashVars）の場合</h3>
<p>PHPでActionScriptに値を渡すには、FlashVarsを利用する方法が簡単です。<br />
PHP内のFLASH埋め込みのコード内に、PHPで動的に取得したパス情報を、FlashVars経由でSWFに渡します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;param name=&quot;FlashVars&quot; value=&quot;path=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SERVER_NAME&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;</pre></td></tr></table></div>

<p>ActionScriptではFlashVarsの値を「loaderInfo.parameters」で取り出します。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> param:<span style="color: #0066CC;">Object</span> = loaderInfo.<span style="color: #006600;">parameters</span>;
<span style="color: #000000; font-weight: bold;">var</span> path:<span style="color: #0066CC;">String</span> = param<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;path&quot;</span><span style="color: #66cc66;">&#93;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/368/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPressで記事のXMLを出力。</title>
		<link>http://www.almondlab.jp/notes/284</link>
		<comments>http://www.almondlab.jp/notes/284#comments</comments>
		<pubDate>Sat, 16 Jan 2010 02:39:56 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=284</guid>
		<description><![CDATA[WordPressのページ機能を使って、投稿記事の情報をXMLに書き出す方法です。]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.almondlab.jp/wp-content/uploads/wordpress-page-template.png" alt="テンプレート" title="テンプレート" width="280" height="395" class="right" />WordPressのページ機能を使って、投稿記事の情報をXMLに書き出す方法です。<br />
WordPressのページ機能は、主に固定ページを扱うために用意されていますが、表示テンプレートをコントロールすることで、投稿記事のリストを動的にXMLで出力することもできます。<br />
<br />
ページのテンプレート変更には、使用しているテーマのフォルダにテンプレートファイルを入れることで、ページ編集画面の「属性」から切り替えが可能になります。<br />
<br />
次のコードは最近の記事10件のタイトル、抜粋、リンクをXMLで出力するテンプレートです。</p>
<div class="clear"></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/*Template Name: topics XML*/</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;?xml version=<span style="color: #000099; font-weight: bold;">\&quot;</span>1.0<span style="color: #000099; font-weight: bold;">\&quot;</span> encoding=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;blog_charset&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> ?&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
&lt;topics&gt; 
&nbsp;
&lt;!-- 最近の記事10件をクエリにセット --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;posts_per_page=10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;topic&gt;
&nbsp;
&lt;!-- タイトル、抜粋、リンクを出力 --&gt;
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;
&lt;excerpt&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_excerpt_rss<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/excerpt&gt;
&lt;url&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/url&gt;
&nbsp;
&lt;/topic&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/topics&gt;</pre></td></tr></table></div>

<p>テンプレートの作成で注意する点は、WordPressにテンプレートファイルであることを認識させるために、コードの先頭にコメントで「Template Name」を記述する必要があります。これにより、編集画面で選択が可能になります。テンプレートのファイル名は特に指定はありません。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/*Template Name: topics XML*/</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>WordPressの記事をXMLで出力することで、FLASHコンテンツ内で表示したりなど、他のコンテンツとの連携がやりやすくなります。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/284/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Codaのプラグイン作成。</title>
		<link>http://www.almondlab.jp/labs/78</link>
		<comments>http://www.almondlab.jp/labs/78#comments</comments>
		<pubDate>Mon, 04 Jan 2010 03:39:46 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[Coda]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=78</guid>
		<description><![CDATA[Codaで制作効率をアップさせる、ちょっとしたプラグインの作成方法です。]]></description>
			<content:encoded><![CDATA[<p>Codaで制作効率をアップさせる、ちょっとしたプラグインの作成方法です。<br />
プラグインを作成するには専用のツールが必要になります。Panicサイトの<a href="http://www.panic.com/jp/coda/developer/howto/plugins.php" onclick="window.open(this.href); return false;"> Codaデベロッパゾーン</a>で「Coda Plug-in Creator」が配布されているので、こちらをダウンロードします。サンプルプラグインも同時に配布されていて、初めてプラグインを作成する際に参考になります。</p>
<div class="space"></div>
<p>「Coda Plug-in Creator」を起動すると新規ウィンドウが開かれます。<br />
<img src="http://www.almondlab.jp/wp-content/uploads/coda-plugin-01.png" alt="" title="" width="629" height="551" class="space" /><br />
今回はシンプルに、選択したテキストに対して&lt;p&gt;、&lt;div&gt;などの任意のタグで囲むだけのプラグインを作成します。実は、サンプルプラグインにも同様のものが含まれていて、それをもとに作成しています。<br />
CodaのプラグインのスクリプトそのものはPHP（またはCocoa）で書かれていて、上記のウィンドウではそれらを管理し、プラグインを構成していきます。</p>
<div class="space"></div>
<p>プラグイン編集中のウィンドウです。編集の大まかな流れは以下のようになります。<br />
<img src="http://www.almondlab.jp/wp-content/uploads/coda-plugin-02.png" alt="" title="" width="629" height="551" id="edit" class="space" /></p>
<ol>
<li><a href="#edit"><strong>コマンドの作成</strong></a><br />
プラグイン内のコマンドを作成します。作成したコマンドは左ペインに登録されて、右ペインで編集が可能になります。左ペインの「Shortcut」の箇所をクリックしてショートカットを設定することもできます。</li>
<li><a href="#edit"><strong>スクリプトの作成、または編集</strong></a><br />
作成したコマンドを選択すると、「Script」がアクティブになり、スクリプトを作成することができます。すでに作成されていると編集になります。スクリプトファイルはプラグインファイルに内包されます。</li>
<li><a href="#edit"><strong>入力テキスト</strong></a><br />
入力テキストの扱いを指定します。選択テキストのみ、ドキュメント全体、選択なしなど。</li>
<li><a href="#edit"><strong>出力テキスト</strong></a><br />
スクリプトを実行した後の、出力テキストの扱いを指定します。選択テキストを置き換え、ドキュメント全体を置き換えなど。</li>
<li><a href="#edit"><strong>ポインターの位置</strong></a><br />
スクリプトを実行した後の、テキストポインターの位置を指定したい場合にチェックします。その場合スクリプト内に記述する「$$IP$$」にポインターが移動します。</li>
</ol>
<div class="space"></div>
<p>作成したスクリプトファイルには、このように記述しています。（&lt;p&gt;で囲む場合）</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://stdin'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;'</span><span style="color: #339933;">.</span><span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>プラグインの作成が完了したら、保存して書き出されるプラグインファイルを「Application Support/Coda/Plug-ins」フォルダに入れます。これでメニューの「Plug-ins」から実行可能になります。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/78/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

