<?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.</title>
	<atom:link href="http://www.almondlab.jp/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>Google Mapsで住所、緯度・経度を取得。</title>
		<link>http://www.almondlab.jp/labs/964</link>
		<comments>http://www.almondlab.jp/labs/964#comments</comments>
		<pubDate>Fri, 27 Jan 2012 14:01:28 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=964</guid>
		<description><![CDATA[Google Mapsでマーカーの位置から住所、緯度・経度を取得するコードのメモです。]]></description>
			<content:encoded><![CDATA[<p>Google Maps APIを使って、マーカーの位置から住所、緯度・経度を取得と、住所からマーカーの移動および、緯度・経度の取得するためのコードのメモです。<br />
<span class="link"><a href="http://www.almondlab.jp/wp-content/uploads/google-map-search">サンプルはこちら</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
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Style-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Script-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Google Map Search<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;common/js/jquery-1.7.1.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://maps.google.com/maps/api/js?sensor=false&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;common/js/functions.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
$(function() {
	setMapSearch({
		container: &quot;map&quot;,
		lat: 35.68075,
		lng: 139.76720,
		zoom: 15
	});
});
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;map&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width:500px; height:500px;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
緯度：<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lat&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
経度：<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lng&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
住所：<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;address&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;検索&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

<p>マーカーのドラッグで緯度・経度を書き換えて、ドロップの際に住所を書き換えています。<br />
また住所から検索で、マーカーを移動して、緯度・経度を書き換えています。<br />
JavaScript自体のコードはこちら。</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
58
59
60
61
62
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> setMapSearch<span style="color: #009900;">&#40;</span>params<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> geocoder <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Geocoder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> position <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>params.<span style="color: #660066;">lat</span><span style="color: #339933;">,</span> params.<span style="color: #660066;">lng</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> map_options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		zoom<span style="color: #339933;">:</span> params.<span style="color: #660066;">zoom</span><span style="color: #339933;">,</span>
		center<span style="color: #339933;">:</span> position<span style="color: #339933;">,</span>
		mapTypeId<span style="color: #339933;">:</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MapTypeId</span>.<span style="color: #660066;">ROADMAP</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>params.<span style="color: #660066;">container</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> map_options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		position<span style="color: #339933;">:</span> position<span style="color: #339933;">,</span>
		map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span> 
		draggable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//マーカーのドラッグ時</span>
	google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>marker<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;drag&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		updateLatLng<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">//マーカーのドロップ時</span>
	google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>marker<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;dragend&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> latlng <span style="color: #339933;">=</span> marker.<span style="color: #660066;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		geocoder.<span style="color: #660066;">geocode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>latLng<span style="color: #339933;">:</span>latlng<span style="color: #339933;">,</span> language<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ja&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>results<span style="color: #339933;">,</span> <span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span> <span style="color: #339933;">==</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">GeocoderStatus</span>.<span style="color: #660066;">OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					updateAddress<span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">formatted_address</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	updateLatLng<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	setSearch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//緯度・経度を書き換え</span>
	<span style="color: #003366; font-weight: bold;">function</span> updateLatLng<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> latlng <span style="color: #339933;">=</span> marker.<span style="color: #660066;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#lat&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>latlng.<span style="color: #660066;">lat</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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#lng&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>latlng.<span style="color: #660066;">lng</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: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//住所を書き換え</span>
	<span style="color: #003366; font-weight: bold;">function</span> updateAddress<span style="color: #009900;">&#40;</span>address<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#address&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>address<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//住所から検索して、マップを移動</span>
	<span style="color: #003366; font-weight: bold;">function</span> setSearch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> address <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#address&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			geocoder.<span style="color: #660066;">geocode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;address&quot;</span><span style="color: #339933;">:</span> address<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>results<span style="color: #339933;">,</span> <span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span> <span style="color: #339933;">==</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">GeocoderStatus</span>.<span style="color: #660066;">OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					marker.<span style="color: #660066;">setPosition</span><span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					updateLatLng<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/964/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal 7のおすすめモジュール。</title>
		<link>http://www.almondlab.jp/notes/944</link>
		<comments>http://www.almondlab.jp/notes/944#comments</comments>
		<pubDate>Sat, 03 Dec 2011 05:23:21 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal7]]></category>
		<category><![CDATA[Module]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=944</guid>
		<description><![CDATA[Drupal 7でサイトの構築にあたり、最小限入れておいた方が良いと思うモジュールです。]]></description>
			<content:encoded><![CDATA[<p>Drupalでは非常に多くの寄与されたモジュールが存在しますが、初めはどのモジュールを入れたら良いのか迷ってしまいます。</p>
<div class="space"></div>
<p>Drupal 7になり、それまでモジュールとして提供されいた主要機能、たとえば「CCK」「ImageCache」などが標準で搭載され、新たに追加するモジュールの数がぐっと減りました。<br />
その上で、これだけは最小限入れておいた方が良いと思うモジュールをいくつか挙げます。</p>
<div class="space"></div>
<table class="data">
<tr>
<th width="100"><a href="http://drupal.org/project/views" onclick="window.open(this.href); return false;">Views</a></th>
<td>コンテンツの表示方法を柔軟にコントロールすることができます。<br />
とても多機能で奥の深いモジュールなので、使い方を覚えるまでが大変ですが、Drupalを利用する上で、最大のアドバンテージになり得ます。<br />
具体的な応用例としては、サムネールの一覧表示や、ソート可能なテーブル形式の表示などです。</td>
</tr>
<tr>
<th><a href="http://drupal.org/project/ctools" onclick="window.open(this.href); return false;">Chaos tool suite (ctools)</a></th>
<td>「Views」の利用の際に必須です。管理画面で、モジュールのインターフェイス部分を担っています。</td>
</tr>
<tr>
<th><a href="http://drupal.org/project/ckeditor" onclick="window.open(this.href); return false;">CKEditor</a></th>
<td>WYSWYGエディタです。同様のエディタはいくつか存在しますが、これが一番使いやすい印象です。<br />
CKEditorを利用するには、モジュールの他に、「<a href="http://ckeditor.com/download" onclick="window.open(this.href); return false;">CKEditor</a>」本体も組み込む必要があります。<br />
「sites/all/modules/ckeditor/ckeditor」のディレクトリの中に本体の「ckeditor」フォルダを入れます。（「ckeditor」フォルダが3つ入れ子になります）</td>
</tr>
<tr>
<th><a href="http://drupal.org/project/insert" onclick="window.open(this.href); return false;">Insert</a></th>
<td>コンテンツの作成で、画像のアップロードは標準の「Image」で行えますが、その画像を本文内に挿入するには、「Insert」が便利です。<br />
アップロードした画像の横にボタンが追加され、テキストエリアのカーソルのある位置に画像を挿入してくれます。また画像スタイル（medium、largeなど）にも対応しています。<br />
CKEditorと組み合わせることで威力を発揮します。</td>
</tr>
<tr>
<th><a href="http://drupal.org/project/pathauto" onclick="window.open(this.href); return false;">Pathauto</a></th>
<td>DrupalではURLエイリアスという機能でURLを置き換えることができます。通常「node/1」「node/2」といったデフォルトのURLを「blog/1」「article/2011/12/2」といった具合に、コンテンツと関連性のあるURLに置き換えられます。<br />
「Pathauto」では自分で設定したルールに基づいて、自動でURLエイリアスを作成することができます。</td>
</tr>
<tr>
<th><a href="http://drupal.org/project/token" onclick="window.open(this.href); return false;">Token</a></th>
<td>「pathauto」の利用の際に必須です。サイト内で扱っている動的なパラメータを利用するためのモジュールです。<br />
たとえば投稿者名を、[node:author]と入力することで、実際の名前を表示することができます。<br />
ただし利用できる場所は限られてはいます。</td>
</tr>
<tr>
<th><a href="http://drupal.org/project/backup_migrate" onclick="window.open(this.href); return false;">Backup and Migrate</a></th>
<td>データベースのバックアップとリストアができます。<br />
公開しているサイトのバックアップはもちろんですが、サイトの制作時に、開発環境のサーバから本サーバへ移すときにも便利です。</td>
</tr>
<tr>
<th><a href="http://drupal.org/project/webform" onclick="window.open(this.href); return false;">Webform</a></th>
<td>お問い合わせなどのフォームを簡単に作成することができます。<br />
フォームの項目も簡単に追加できるので、複雑なアンケートフォームの作成にも便利です。<br />
エクセルでの管理用にCSVダウンロードもできます。</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/944/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SnippetsのExpand Triggerが便利。</title>
		<link>http://www.almondlab.jp/notes/932</link>
		<comments>http://www.almondlab.jp/notes/932#comments</comments>
		<pubDate>Fri, 02 Dec 2011 06:55:05 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=932</guid>
		<description><![CDATA[Snippets 1.3より追加された入力補完をしてくれる機能、Expand Triggerがコーディングに便利です。]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.snippetsapp.com/" onclick="window.open(this.href); return false;">Snippets</a>はコーディングの際によく使うコードの部品を効率よく管理してくれるツールですが、バージョン1.3から省略された文字をタイプすることで、テキストエディッタへダイレクトに入力することができるようになりました。<br />
<img src="http://www.almondlab.jp/wp-content/uploads/snippets-trigger.png" alt="Snippets" title="Snippets" width="962" height="589" class="space" /></p>
<p>同様の機能は、<a href="http://www.smilesoftware.com/TextExpander/" onclick="window.open(this.href); return false;">TextExpander</a>といったアプリケーションで実現していましたが、コーディング用アプリケーションというわけではないので、シンタックスのカラーリングができなかったり、コードの管理には不向きです。</p>
<div class="space"></div>
<p>Snippetsでこの機能をサポートしてくれたおかげで、TextExpanderに登録していたコードもSnippets内で一つにまとめることができます。<br />
ただ現在のところ、シンプルな機能のみなので、入力完了の際に効果音がなかったり、カーソルの位置を指定できなかったり、TextExpanderと比較すると不便なところもあります。</p>
<div class="space"></div>
<p>でも、これまでもSnippetsは着実に機能追加を続けているので、今後に期待がもてそうです。差し当たり、iCloudでの同期を実現してくれると非常にありがたいです。</p>
<div class="space"></div>
<p><span class="link"><a href="http://www.snippetsapp.com/" onclick="window.open(this.href); return false;">Snippets (Lucky Ants)</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/932/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Espresso 2.0</title>
		<link>http://www.almondlab.jp/notes/918</link>
		<comments>http://www.almondlab.jp/notes/918#comments</comments>
		<pubDate>Fri, 30 Sep 2011 02:43:42 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=918</guid>
		<description><![CDATA[Espressoのメジャーアップグレードとなるバージョン2.0が登場しました。]]></description>
			<content:encoded><![CDATA[<p>Espressoのメジャーアップグレードとなるバージョン2.0が登場しました。<br />
今回のバージョンアップでの大きな特長は、CSSEditが統合されたことでしょうか。CSSの編集がグラフィカルになり、より快適になっています。<br />
（それにより、CSSEditの販売・開発は終了してしまったようですが・・・）</p>
<div class="space"></div>
<p>インターフェースは前バージョンからそれほど変わっていないようですが、OS X Lionになった今でも非常に美しく感じます。<br />
競合製品であるCodaと、どちらを使うか悩むところではありますが、ビジュアルブルでリッチにコーディングをしたいならEspressoを、効率を重視するならCodaと、その時々で使い分けるのもよいかもしれません。</p>
<div class="space"></div>
<p>価格は新規購入の場合$79、アップグレードは2009年4月10日以降の購入者は無料で、それ以前の購入者は$29となっています。</p>
<div class="space"></div>
<p><span class="link"><a href="http://macrabbit.com/" onclick="window.open(this.href); return false;">MacRabbit</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/918/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMware Fusion 4にアップグレード。</title>
		<link>http://www.almondlab.jp/notes/914</link>
		<comments>http://www.almondlab.jp/notes/914#comments</comments>
		<pubDate>Tue, 20 Sep 2011 10:29:21 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=914</guid>
		<description><![CDATA[仮想化ソフトウェアVMware Fusionをアップグレードしました。]]></description>
			<content:encoded><![CDATA[<p>先日、新バージョンとなる<a href="http://www.vmware.com/products/fusion/" onclick="window.open(this.href); return false;">VMware Fusion 4</a>が登場したので、早速アップグレード。<br />
大きな特長としては、Lion環境への最適化、パフォーマンスの向上、あとLionを仮想マシンとして実行できるようになりました。</p>
<div class="space"></div>
<p>しばらく使ってみた感じでは、Lion環境に合わせたUIの改良は、なかなか好印象です。パフォーマンスに関しては、仮想マシン上では重い処理を実行しないので、正直前バージョンからの違いは分かりませんでした。<br />
気になる点としては、Fusion自体の起動速度が遅くなってしまったような感じがします。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/914/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>OS X Lionをインストール。</title>
		<link>http://www.almondlab.jp/notes/903</link>
		<comments>http://www.almondlab.jp/notes/903#comments</comments>
		<pubDate>Thu, 21 Jul 2011 01:49:30 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=903</guid>
		<description><![CDATA[昨日発売されたOS X Lionを、iMacにインストールしました。]]></description>
			<content:encoded><![CDATA[<p>昨日発売されたOS X Lionを、メインマシンとして使っているiMac（Early 2008）にインストールしました。<br />
本当はサプのノートにインストールしたかったんですが、初期のMacBook（Early 2006）でCPUが対象外でした・・・。</p>
<div class="space"></div>
<p>インストールは既存のSnow Leopardを上書きするかたちで、ガイドに従って行いました。所要時間はおよそ40分でした。<br />
一番心配していた普段使っているアプリケーションとの互換性ですが、今のところ特に問題はありません。「Coda」「ForkLift」「Path Finder」「QuicKeys」「LaunchBar」など、正常に動いています。（僅かに表示がおかしかったりしますが）</p>
<div class="space"></div>
<p>OSのメジャーアップグレードで、これほどスムーズに移行できるのは、よくよく考えてみるとすごいことですよね。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/903/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupalの管理画面にアクセスできない場合の対処法。</title>
		<link>http://www.almondlab.jp/notes/899</link>
		<comments>http://www.almondlab.jp/notes/899#comments</comments>
		<pubDate>Wed, 22 Jun 2011 07:39:13 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=899</guid>
		<description><![CDATA[Drupalの管理画面へアクセスの際に「Warning: MySQL server has gone away query: INSERT INTO watchdog...」というエラーが表示してアクセスできない場合の対処法です。]]></description>
			<content:encoded><![CDATA[<p>Drupalの管理画面へアクセスの際に、下記のようなエラーが表示されてアクセスできない場合があります。</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;">Warning<span style="color: #339933;">:</span> <span style="color: #990000;">MySQL</span> server has gone away query<span style="color: #339933;">:</span> INSERT INTO watchdog<span style="color: #339933;">...</span></pre></td></tr></table></div>

<p>症状はMySQLへのアクセスに問題を生じているのですが、具体的にはモジュール等のアップデートのチェックで、MySQLがビジーになってしまっているようです。</p>
<div class="space"></div>
<p>暫定的な解決方法としてモジュールの管理ページ（admin/build/modules）にアクセスして、（画面にエラーは表示されたままですが）コアモジュールの「Update status」をオフにすることで、とりあえずエラーの表示はなくなります。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/899/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScriptで透過ビットマップのロールオーバーを判定。</title>
		<link>http://www.almondlab.jp/labs/890</link>
		<comments>http://www.almondlab.jp/labs/890#comments</comments>
		<pubDate>Wed, 15 Jun 2011 05:54:11 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLASH]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=890</guid>
		<description><![CDATA[マウスのロールオーバー時に、ビットマップの透過ではない部分でのみ判定をする方法です。]]></description>
			<content:encoded><![CDATA[<p>マウスのロールオーバー時に、ビットマップの透過ではない部分でのみ判定をする方法です。<br />
通常ビットマップのマウス判定には矩形エリア全体が対象になるので、透明PNGの透明部分でも判定されてしまいます。<br />
それを回避する方法として、マウスのイベントリスナーを使うのではなく、マウス座標上にあるビットマップのピクセル色が透明かどうかを測定して、判定をするようにしています。<br />
<span class="link"><a href="http://www.almondlab.jp/wp-content/uploads/bitmap-rollover">サンプルはこちら</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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</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.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Bitmap</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">BitmapData</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PixelSnapping</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<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.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</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> <span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</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;">//ライブラリ内の「Cloud」ビットマップクラス（透過PNG）インスタンスを作成</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> bitmap_data<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Cloud<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> bitmap<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>bitmap_data<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">PixelSnapping</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NEVER</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><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;">addChild</span><span style="color: #000000;">&#40;</span>bitmap<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><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			setBitmapRollOverOut<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">,</span> bitmap_data<span style="color: #000066; font-weight: bold;">,</span> targetOverTest<span style="color: #000066; font-weight: bold;">,</span> targetOutTest<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">//ロールオーバー時</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> targetOverTest<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:*</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>
			<span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><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;">alpha</span> = <span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">//ロールアウト時</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> targetOutTest<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:*</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>
			<span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">false</span><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;">alpha</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">//引数にロールオーバー時、ロールアウト時の関数を渡します</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> setBitmapRollOverOut<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">,</span> bitmap_data<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span><span style="color: #000066; font-weight: bold;">,</span> rolloverFunction<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Function</span><span style="color: #000066; font-weight: bold;">,</span> rolloutFunction<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Function</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>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">color</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span><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;">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;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> targetOverEnter<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #339966; font-weight: bold;">function</span> targetOverEnter<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;">//マウス位置のビットマップの（アルファ値を含む）ピクセル色を測定</span>
				<span style="color: #004993;">color</span> = bitmap_data<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getPixel32</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseX</span><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;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">//ビットマップが透明でなければロールオーバー関数を実行</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
					<span style="color: #009900; font-style: italic;">//ロールオーバー関数の実行を一度だけにするため、一旦エンターフレームを解除します</span>
					<span style="color: #009900; font-style: italic;">//同時にロールアウトのエンターフレームを再開します</span>
					<span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</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;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> targetOverEnter<span style="color: #000000;">&#41;</span><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;">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;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> targetOutEnter<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					rolloverFunction<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #339966; font-weight: bold;">function</span> targetOutEnter<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;">//マウス位置のビットマップの（アルファ値を含む）ピクセル色を測定</span>
				<span style="color: #004993;">color</span> = bitmap_data<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getPixel32</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseX</span><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;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">//ビットマップが透明だったらロールアウト関数を実行</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
					<span style="color: #009900; font-style: italic;">//ロールアウト関数の実行を一度だけにするため、一旦エンターフレームを解除します</span>
					<span style="color: #009900; font-style: italic;">//同時にロールオーバーのエンターフレームを再開します</span>
					<span style="color: #004993;">target</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;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> targetOverEnter<span style="color: #000000;">&#41;</span><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;">removeEventListener</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;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> targetOutEnter<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					rolloutFunction<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</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>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/890/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QuicKeysでアプリケーションの表示＆非表示アクションを作成。</title>
		<link>http://www.almondlab.jp/notes/883</link>
		<comments>http://www.almondlab.jp/notes/883#comments</comments>
		<pubDate>Thu, 26 May 2011 00:41:14 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=883</guid>
		<description><![CDATA[QuicKeysを使って、アプリケーションの表示＆非表示のトグルアクションを作成。]]></description>
			<content:encoded><![CDATA[<p>QuicKeysは、Mac上でのいくつかの処理をまとめ一つのアクションに登録して、作業を自動化することができるユーティリティです。<br />
またMacでの状態をある程度チェックできるので、状況に応じて処理を振り分け、簡単なシーケンスのアクションも作成できます。</p>
<div class="space"></div>
<p>次の例は、Safariのアクティブ、非アクティブの状態をチェックして、表示、または非表示にするアクションです。<br />
<img src="http://www.almondlab.jp/wp-content/uploads/quickeys-toggle.png" alt="QuicKeys" width="585" height="1341" class="frame space" /><br />
上記のような小さなアクションでも、自分に合わせてたくさん作っておくと、Macの操作性はぐっと良くなるのでおすすめです。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/883/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とWordPressについて。</title>
		<link>http://www.almondlab.jp/notes/868</link>
		<comments>http://www.almondlab.jp/notes/868#comments</comments>
		<pubDate>Tue, 24 May 2011 06:42:43 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=868</guid>
		<description><![CDATA[2つのCMS、DrupalとWordpressをこれまで利用しての雑感です。]]></description>
			<content:encoded><![CDATA[<p>現在人気の高い2つのCMS、DrupalとWordpressですが、同じくCMSという括りではあるものの、実際には両者でかなり性格の異なっているように思います。<br />
大きく分けると、サイトの構築、更新作業において、Drupalは複雑なサイト、Wordpressはシンプルなサイトに向いているようです。</p>
<div class="space"></div>
<p>どちらのCMSも長く利用していますが、それぞれに得意なところ、不得意なところがあるので、構築するサイトの構成によって使い分けるようにしています。<br />
これまで2つのCMSを自分が使ってきた中で、それぞれ次のような特徴があると思います。</p>
<div class="space"></div>
<div class="separate"></div>
<div class="space"></div>
<p><img src="http://www.almondlab.jp/wp-content/uploads/drupal-wordpress-01.png" alt="Drupal" title="Drupal" width="64" height="64" class="right" />Drupalで最も優れているところは、コンテンツの柔軟性にあります。<br />
通常のブログタイプのCMSでは、一つ記事にタイトル、本文のみの構成ですが、Drupalでは様々なタイプの追加フィールドを任意で設けることができます。なので、例えば不動産サイトのような複雑な情報サイトでも、比較的容易に構築することが可能です。</p>
<div class="space"></div>
<p>もう一つ大きな特長として、ユーザー権限の管理があります。<br />
複数の階層によるユーザーグループの権限を作成でき、ユーザー毎に、きめ細かくサイト内ページの閲覧権限などを設定できます。会員制サイトなどの構築には威力を発揮します。</p>
<div class="space"></div>
<p>逆にマイナスと感じるところは、やはり学習の難しさにあると思います。<br />
初めてインストールした直後では最小構成の機能しか使えない状態なので、ブログとして利用する場合でも、画像の挿入さえままならない状況です。<br />
いくつかのモジュールを組み合わせれば、基本的なブログとして利用できるようになりますが、初めて利用した際には、かなりハードルが高いように思います。<br />
さらにサイト構築となると、テーマ作成も必要になりますが、これがまた簡単ではありません。<br />
Drupalのルールに基づいてテンプレートファイルなどを作成していきますが、理解するにはそれなりの時間がかかってしまいます。<br />
ただ一度覚えてしまうと、とても理にかなったルールなので、開発も楽しく？なります。</p>
<div class="space"></div>
<div class="separate"></div>
<div class="space"></div>
<p><img src="http://www.almondlab.jp/wp-content/uploads/drupal-wordpress-02.png" alt="Wordpress" title="Wordpress" width="64" height="64" class="right" />WordPressはブログタイプのCMSで、固定ページ機能を組み合わせることで、大抵のWebサイトの構築には十分な能力を持っています。</p>
<div class="space"></div>
<p>またブログをベースにしていることもあり、シンプルな管理画面に加え標準でのWYSWYSエディタが搭載されていて、とても親しみやすい印象を受けます。<br />
テーマを含むサイトの開発においても、HTMLの知識と、Wordpressの出力を担うテンプレートタグをおおまかに理解していれば、独自のサイト構築も難しくはありません。</p>
<div class="space"></div>
<p>WordPressにとってもマイナス部分は、これは良いところでもありますが、あくまでブログベースのサイトしか作れないことです。<br />
基本的にタイトル、本文の構成なので、イレギュラーなコンテンツの作成ができません。<br />
カスタムフィールドを使う方法もありますが、更新作業の際にパソコンに詳しい人だったら問題ありませんが、そうでない人にとっては、かなりストレスが溜まるように思います。</p>
<div class="space"></div>
<div class="separate"></div>
<div class="space"></div>
<p>2つのCMSを比較すると、自分の中では上記のような特徴が挙げられますが、あくまで性格の異なるもととしてとらえています。<br />
例えるなら、自動車とバイクのような違いがあるように思います。</p>
<div class="space"></div>
<p>サイトの構築では、いろいろなケースがあるので、どのように構築するかは毎回悩みます。<br />
ただ一つのCMSのみで構築を考えるより、CMS利用の有無も含めて、複数のCMSを使い分けていくことがベストのようです。ケースによってはJoomla!やMoodleが向いている場合もあります。<br />
とりわけ、DrupalとWordpressは開発も盛んで将来性が高いので、時間をかけて学習するだけの価値はあるように思います。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/868/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>Drupal 7のスクラッチテーマ作成。</title>
		<link>http://www.almondlab.jp/labs/848</link>
		<comments>http://www.almondlab.jp/labs/848#comments</comments>
		<pubDate>Sat, 21 May 2011 08:44:42 +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[Theme]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=848</guid>
		<description><![CDATA[Drupal 7でサイト構築にあたり、基盤となるスクラッチテーマを作成しました。]]></description>
			<content:encoded><![CDATA[<p>Drupal 7正式版が登場して5ヶ月あまり経ちますが、そろそろ主要モジュールも整ってきたので、Drupal 6からDrupal 7へ移行を進めています。<br />
Drupal 7でサイトを構築するにあたり重要となるテーマ作成ですが、基本的な構成のみをまとめたスクラッチテーマを作成してみました。<br />
<span class="link"><a href="http://drupal7.almondlab.jp" onclick="window.open(this.href); return false;">Drupal 7のスクラッチテーマ</a></span></p>
<div class="space"></div>
<p>drupal 7ではテーマを継承してサブテーマを作ることができるので、上記の基本構成以外はサブテーマにて装飾を加えていくことで、効率的なサイト構築が可能です。</p>
<div class="space"></div>
<p>テーマ制作の流れは、おおむねDrupal 6の場合と変わっていないように感じました。<br />
ただしテンプレートファイル内で利用するメソッド、パラメータには変更があったので、Drupal 6のテーマをDrupal 7用に書き換えるのは、少し大変かもしれません。</p>
<div class="space"></div>
<p>またDrupalオフィシャルサイトでは、テーマ作成のためドキュメントが充実しているので、とても参考になりました。<br />
<span class="link"><a href="http://drupal.org/theme-guide/6-7" onclick="window.open(this.href); return false;">Theming Drupal 6 and 7 | drupal.org</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/848/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScriptで方向キー操作のメモ。</title>
		<link>http://www.almondlab.jp/notes/845</link>
		<comments>http://www.almondlab.jp/notes/845#comments</comments>
		<pubDate>Sun, 15 May 2011 06:24:16 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=845</guid>
		<description><![CDATA[ActionScriptで方向キーが押された時のイベントのメモです。]]></description>
			<content:encoded><![CDATA[<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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><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;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">stage</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;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> onKeyPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> onKeyPress<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</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>
	<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">38</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//up</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//down</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//left</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//right</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>ステージにイベントリスナーをかけて、方向キーが押された時に関数を実行します。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/845/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQueryでアンカーポイントまでスクロール。</title>
		<link>http://www.almondlab.jp/labs/839</link>
		<comments>http://www.almondlab.jp/labs/839#comments</comments>
		<pubDate>Fri, 01 Apr 2011 13:26:33 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=839</guid>
		<description><![CDATA[jQueryでページ内のアンカーポイントまでスムーズにスクロールするスクリプトです。]]></description>
			<content:encoded><![CDATA[<p>jQueryでページ内のアンカーポイントまでスムーズにスクロールするスクリプトです。<br />
スクロールのイージングには「<a href="http://gsgd.co.uk/sandbox/jquery/easing/">jquery.easing.1.3.js</a>」を利用しています。<br />
<span class="link"><a href="http://www.almondlab.jp/wp-content/uploads/scroll-to-ancor">サンプルはこちら</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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> scrollToAnchor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[href*=#]&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> target <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">hash</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>offset <span style="color: #339933;">&gt;</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</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>
			offset <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;html, body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>scrollTop<span style="color: #339933;">:</span>offset<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>duration<span style="color: #339933;">:</span><span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span> easing<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;easeOutQuart&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>&lt;a&gt;タグのリンクからハッシュ（#の部分）のみを抽出して、ページ先頭からの高さを調べています。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/labs/839/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScriptでXMLを操作するときのメモ。</title>
		<link>http://www.almondlab.jp/notes/833</link>
		<comments>http://www.almondlab.jp/notes/833#comments</comments>
		<pubDate>Tue, 29 Mar 2011 07:35:38 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLASH]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=833</guid>
		<description><![CDATA[ActionScriotでXMLを操作する際に、よく使うメソッドのメモです。]]></description>
			<content:encoded><![CDATA[<p>ActionScriotでXMLを操作する際に、よく使うメソッドのメモです。</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> =
<span style="color: #000066; font-weight: bold;">&lt;</span>root<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>item id=<span style="color: #990000;">&quot;1&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>test1<span style="color: #000066; font-weight: bold;">&lt;/</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>url<span style="color: #000066; font-weight: bold;">&gt;</span>www<span style="color: #000066; font-weight: bold;">.</span>example1<span style="color: #000066; font-weight: bold;">.</span>com<span style="color: #000066; font-weight: bold;">&lt;/</span>url<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>item<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>item id=<span style="color: #990000;">&quot;2&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>test2<span style="color: #000066; font-weight: bold;">&lt;/</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>url<span style="color: #000066; font-weight: bold;">&gt;</span>www<span style="color: #000066; font-weight: bold;">.</span>example2<span style="color: #000066; font-weight: bold;">.</span>com<span style="color: #000066; font-weight: bold;">&lt;/</span>url<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>item<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>item id=<span style="color: #990000;">&quot;3&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>test3<span style="color: #000066; font-weight: bold;">&lt;/</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>item<span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>root<span style="color: #000066; font-weight: bold;">&gt;;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//一つ目（0番目）の「item」ノード内の「name」ノードの内容を取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span>
<span style="color: #009900; font-style: italic;">//test1</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//二つ目の「item」ノードの「id」属性を取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">child</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;item&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>@id<span style="color: #000000;">&#41;</span>
<span style="color: #009900; font-style: italic;">//2</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//「item」ノードの数を取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//3</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//「item」ノード内の「url」ノードの数を取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">..</span><span style="color: #004993;">url</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//2</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//一つ目（0番目）の「item」ノードの二つ目（1番目）のノード名を取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">child</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//url</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//「item」ノード内の「name」ノードの内容が「test1」の「url」ノードの内容を取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span> == <span style="color: #990000;">&quot;test1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//www.example1.com</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//「item」ノード内の「id」属性が「2」の「url」ノードの内容を取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000066; font-weight: bold;">.</span><span style="color: #000000;">&#40;</span>@id == <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span><span style="color: #000000;">&#41;</span>
<span style="color: #009900; font-style: italic;">//www.example2.com</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//三つ目（2番目）の「item」ノードに「url」ノードの有無をブール値で取得</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000066; font-weight: bold;">.</span>item<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">hasOwnProperty</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;url&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//false</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/833/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ブログのRSSから広告をカットする方法。</title>
		<link>http://www.almondlab.jp/notes/825</link>
		<comments>http://www.almondlab.jp/notes/825#comments</comments>
		<pubDate>Sat, 26 Mar 2011 05:21:04 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=825</guid>
		<description><![CDATA[アメーバなど無料ブログのRSSフィードから、「PR」広告をカットする方法です。]]></description>
			<content:encoded><![CDATA[<p>アメーバなど無料ブログのRSSフィードをWebサイトで掲載したい場合、よく「PR」の広告文が含まれてしまいます。<br />
この広告をカットして掲載するには「<a href="http://pipes.yahoo.com/pipes/" onclick="window.open(this.href); return false;">Yahoo! Pipes</a>」を使うと簡単に行えます。</p>
<div class="space"></div>
<p>Yahoo! Pipiesのトップページ右上にある検索フィールドから、例えば「ameba」と入力して検索すると、アメーバブログの広告をカットするための項目がたくさん表示されます。<br />
このうちどれか一つを選んで、表示される「RSS」フォームにブログのRSSアドレスを入力し「Run Pipe」ボタンを押します。<br />
しばらくすると、PipeされたRSS項目が「Get as RSS」として表示されます。<br />
このリンクをWebサイトで登録すれば、広告をカットされたRSSが表示できます。</p>
<div class="space"></div>
<p><span class="link"><a href="http://pipes.yahoo.com/pipes/" onclick="window.open(this.href); return false;">Yahoo! Pipes</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/825/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CKEditorのスマイリー画像を追加する方法。</title>
		<link>http://www.almondlab.jp/notes/817</link>
		<comments>http://www.almondlab.jp/notes/817#comments</comments>
		<pubDate>Sun, 20 Mar 2011 14:32:25 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=817</guid>
		<description><![CDATA[CKEditorに搭載されているスマイリーアイコン画像を、カスタムで追加するための方法です。]]></description>
			<content:encoded><![CDATA[<p>ブログやCMSなどでWYSIWYGエディタはよく利用されていますが、オープンソースのCMSであるdrupalでも、モジュールとしてCKEditorを利用することができます。drupalにはいくつかのWYSIWYGエディタをモジュールとして利用できますが、自分的にはCKEditorが一番でしっくりきます。</p>
<div class="space"></div>
<p>CKEditorには機能の一部として、スマイリーアイコン画像を本文中に使うことができますが、標準のアイコンは種類が少なく、絵柄も日本向けではないので、あまり実用性はないように思います。</p>
<div class="space"></div>
<p>このスマイリーアイコンをカスタムで追加するには、下記のようにアイコン画像ファイルを指定のフォルダに追加し、ソースコードに画像のファイル名を記述することで、アイコン画像を追加することができます。</p>
<div class="space"></div>
<p>追加するアイコンの画像ファイルは、下記のフォルダに格納します。<br />
<strong>ckeditor/plugins/smiley/images</strong></p>
<div class="space"></div>
<p>追加した画像ファイルをCKEditorに登録するために、次の2カ所に記述をします。いずれも配列として続けて追加します。<br />
<strong>ckeditor/_source/plugins/smiley/plugin.js</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>50
51
52
53
54
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">CKEDITOR.<span style="color: #660066;">config</span>.<span style="color: #660066;">smiley_images</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
	<span style="color: #3366CC;">'regular_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'sad_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'wink_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'teeth_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'confused_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'tounge_smile.gif'</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'embaressed_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'omg_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'whatchutalkingabout_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'angry_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'angel_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'shades_smile.gif'</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'devil_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'cry_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'lightbulb.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'thumbs_down.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'thumbs_up.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'heart.gif'</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'broken_heart.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'kiss.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'envelope.gif'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>ckeditor/ckeditor.js</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>68
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">i.<span style="color: #660066;">smiley_images</span><span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'regular_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'sad_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'wink_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'teeth_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'confused_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'tounge_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'embaressed_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'omg_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'whatchutalkingabout_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'angry_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'angel_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'shades_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'devil_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'cry_smile.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'lightbulb.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'thumbs_down.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'thumbs_up.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'heart.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'broken_heart.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'kiss.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'envelope.gif'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'test.gif'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>以上でCKEditorのスマイリーアイコンに、カスタムの画像を追加することができます。</p>
<div class="space"></div>
<p>また必須ではないですが、画像のalt属性、title属性として利用するための、説明文も追加することもできます。<br />
<strong>ckeditor/_source/plugins/smiley/plugin.js</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>80
81
82
83
84
85
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">CKEDITOR.<span style="color: #660066;">config</span>.<span style="color: #660066;">smiley_descriptions</span> <span style="color: #339933;">=</span>
	<span style="color: #009900;">&#91;</span>
		<span style="color: #3366CC;">'smiley'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'sad'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'wink'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'laugh'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'frown'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'cheeky'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'blush'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'surprise'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'indecision'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'angry'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'angle'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'cool'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'devil'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'crying'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'enlightened'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'no'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'yes'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'heart'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'broken heart'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'kiss'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'mail'</span>
	<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>ckeditor/ckeditor.js</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>68
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">i.<span style="color: #660066;">smiley_descriptions</span><span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'smiley'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'sad'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'wink'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'laugh'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'frown'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'cheeky'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'blush'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'surprise'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'indecision'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'angry'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'angle'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'cool'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'devil'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'crying'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'enlightened'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'no'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'yes'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'heart'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'broken heart'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'kiss'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'mail'</span><span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>先に追加した画像ファイル名の配列と同じ順番で、説明文を追加します。</p>
<div class="space"></div>
<p><span class="link"><a href="http://ckeditor.com/" onclick="window.open(this.href); return false;">CKEditor</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/817/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

