8月
28
2009
0

[SEO][メモ]google,Yahoo,bing(msn)のサイトマップ登録先
このエントリをはてなブックマークに追加このエントリをdel.icio.usに追加このエントリをLivedoor Clipに追加このエントリをYahoo!ブックマークに追加このエントリをFC2ブックマークに追加このエントリをNifty Clipに追加このエントリをPOOKMARK. Airlinesに追加このエントリをBuzzurl(バザール)に追加このエントリをChoixに追加このエントリをnewsingに追加

新しいサイトを立ち上げたのですが、旧msn(現bing?)のサイトマップの登録先がわからなくて探しました^^;
主要検索サイトのsitemap.xmlの登録先をメモしておきます。

2009-08-28時点
Google
yahoo
msn(bing)

参考にさせていただいたのはこちらのサイト
XML サイトマップファイル(sitemap.xml)の作成方法 (SEO対策) | ネットビジネス支援 情報サイト
他にもSEO関連の記事がとても充実していて勉強になります。
フィード登録して、後でじっくり読もうっと!

Written by suzukenn in: メモ | タグ: ,
8月
26
2009
0

[PHP][メモ]class.upload.phpに関するメモ(docs)
このエントリをはてなブックマークに追加このエントリをdel.icio.usに追加このエントリをLivedoor Clipに追加このエントリをYahoo!ブックマークに追加このエントリをFC2ブックマークに追加このエントリをNifty Clipに追加このエントリをPOOKMARK. Airlinesに追加このエントリをBuzzurl(バザール)に追加このエントリをChoixに追加このエントリをnewsingに追加

画像アップロードライブラリのclass.upload.phpのドキュメントを抜粋して(機械)翻訳しました。
英語が読める方は以下のリンクをご利用ください。

docs
faq

下記はご参考程度にどうぞ。
間違いもたくさんあると思いますので、ご指摘大歓迎です。
コメントでもスカイプでもTwitterでも何でも結構ですので突っ込んでいただけると助かります。

パラメータ

ファイル名の設定

file_new_name_body replaces the name body (default: ”)
$handle->file_new_name_body = 'new name';

設定済みファイル名の後ろに文字列を追加?

file_name_body_add appends to the name body (default: ”)
$handle->file_name_body_add = '_uploaded';

設定済みファイル名の前に文字列を追加

file_name_body_pre prepends to the name body (default: ”)
$handle->file_name_body_pre = ‘thumb_’;

デフォルトで出力するファイルの拡張子を変更する

file_new_name_ext replaces the file extension (default: ”)
$handle->file_new_name_ext = 'txt';

ファイル名のスペースを_(アンダーバー)に変更する?

file_safe_name formats the filename (spaces changed to _) (default: true)
$handle->file_safe_name = true;

出力先に同名のファイルがある場合に上書きする

file_overwrite sets behaviour if file already exists (default: false)
$handle->file_overwrite = true;

出力先に同名のファイルがある場合、自動的に名前を変更する

file_auto_rename automatically renames file if it already exists (default: true)
$handle->file_auto_rename = true;

出力先ディレクトリが存在し無い場合、自動的に作成する

auto_create_dir automatically creates destination directory if missing (default: true)
$handle->auto_create_dir = true;

出力先に書き込み権限が無い場合、書き込み権限をセット(chmod)を試みる?

dir_auto_chmod automatically attempts to chmod the destination directory if not writeable (default: true)
$handle->dir_auto_chmod = true;

dir_auto_chmodで出力先の書き込み権限セット(chmod)するときの権限?

dir_chmod chmod used when creating directory or if directory not writeable (default: 0777)
$handle->dir_chmod = 0777;

最大アップロードサイズ

file_max_size sets maximum upload size (default: upload_max_filesize from php.ini)
$handle->file_max_size = '1024'; // 1KB

後述のallowedしたMIMEタイプリストに対するチェック

mime_check sets if the class check the MIME against the allowed list (default: true)
$handle->mime_check = true;

???

mime_fileinfo activates MIME detection with Fileinfo PECL extension if true (or a string to set the path to the magic database file); false to deactivate (default: true)
$handle->mime_fileinfo = '/usr/share/file/magic';

???

mime_file activates MIME detection with UNIX file() command if true; false to deactivate (default: true)
$handle->mime_file = false;

???

mime_magic activates MIME detection with mime_magic (mime_content_type()) if true; false to deactivate (default: true)
$handle->mime_magic = false;

???

mime_getimagesize activates MIME detection with getimagesize() if true; false to deactivate (default: true)
$handle->mime_getimagesize = false;

???

no_script sets if the class turns scripts into text files (default: true)
$handle->no_script = false;

アップロードを許可するMIMEタイプの設定(*でワイルドカード指定可能)

allowed array of allowed mime-types. wildcard accepted, as in image/* (default: check Init)
$handle->allowed = array('application/pdf','application/msword', 'image/*')

アップロードを禁止するMIMEタイプの設定(*でワイルドカード指定可能)

forbidden array of forbidden mime-types. wildcard accepted, as in image/* (default: check Init)
$handle->forbidden = array('application/*');

出力する画像のタイプ(png,jpeg,gif,bmp,default)を指定する

image_convert if set, image will be converted (possible values : ”|’png’|'jpeg’|'gif’|'bmp’; default: ”)
$handle->image_convert = 'jpg';

??指定した色を透明化する?

image_background_color if set, will forcibly fill transparent areas with the color, in hexadecimal (default: null)
$handle->image_background_color = '#FF00FF';

???

image_default_color fallback color background color for non alpha-transparent output formats, such as JPEG or BMP, in hexadecimal (default: #FFFFFF)
$handle->image_default_color = '#FF00FF';

jpeg画像の品質

jpeg_quality sets the compression quality for JPEG images (default: 85)
$handle->jpeg_quality = 50;

jpeg画像のファイルサイズ指定

jpeg_size if set to a size in bytes, will approximate jpeg_quality so the output image fits within the size (default: null)
$handle->jpeg_size = 3072;

アップロードを制限する指定

以下の8項目のパラメータはアップロードを制限するのに利用できます。

画像の最大幅を制限

image_max_width if set to a dimension in pixels, the upload will be invalid if the image width is greater (default: null)
$handle->image_max_width = 200;

画像の最大高を制限

image_max_height if set to a dimension in pixels, the upload will be invalid if the image height is greater (default: null)
$handle->image_max_height = 100;

画像の最大総ピクセル数を制限?

image_max_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is greater (default: null)
$handle->image_max_pixels = 50000;

画像の最大アスペクト比(縦横比)を制限*1

image_max_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is greater (default: null)
$handle->image_max_ratio = 1.5;

画像の最小幅を制限

image_min_width if set to a dimension in pixels, the upload will be invalid if the image width is lower (default: null)
$handle->image_min_width = 100;

画像の最小高を制限

image_min_height if set to a dimension in pixels, the upload will be invalid if the image height is lower (default: null)
$handle->image_min_height = 500;

画像の最小ピクセル数を制限

image_min_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is lower (default: null)
$handle->image_min_pixels = 20000;

画像の最小アスペクト比(縦横比)を制限

image_min_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is lower (default: null)
$handle->image_min_ratio = 0.5;

画像のサイズ変更

画像のサイズを変更するか

image_resize determines is an image will be resized (default: false)
$handle->image_resize = true;

サイズ変更後の画像幅

image_x destination image width (default: 150)
$handle->image_x = 100

サイズ変更後の画像高

image_y destination image height (default: 150)
$handle->image_y = 200;

画像のアスペクト比(縦横比)を維持する?

image_ratio if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes if true (default: false)
$handle->image_ratio = true;

image_xとimage_yを優先してサイズ変更しあまった部分をトリミングする???

image_ratio_crop if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes, and cropping excedent to fill the space. setting can also be a string, with one or more from ‘TBLR’, indicating which side of the image will be kept while cropping (default: false)
$handle->image_ratio_crop = true;

???

image_ratio_fill if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes, fitting the image in the space and coloring the remaining space. setting can also be a string, with one or more from ‘TBLR’, indicating which side of the space the image will be in (default: false)
$handle->image_ratio_fill = true;

???

image_ratio_no_zoom_out same as image_ratio, but won’t resize if the source image is bigger than image_x x image_y (default: false)
$handle->image_ratio_no_zoom_out = true;

???

image_ratio_x if true, resize image, calculating image_x from image_y and conserving the original sizes ratio (default: false)
$handle->image_ratio_x = true;

???

image_ratio_y if true, resize image, calculating image_y from image_x and conserving the original sizes ratio (default: false)
$handle->image_ratio_y = true;

???

image_ratio_pixels if set to a long integer, resize image, calculating image_y and image_x to match a the number of pixels (default: false)
$handle->image_ratio_pixels = 25000;

画像の装飾など?

情熱が潰えたので割愛。

TIPS

ローカルファイルを処理する場合は、第1引数にローカルファイルのパス指定してインスタンスを作る。

$upload = new upload('/home/user/myfile.jpg');

言語をセットするには、第2引数に言語コードを指定してインスタンスを作る。

$handle = new upload($_FILES['image_field'], 'fr_FR');
$handle = new upload('/home/user/myfile.jpg', 'fr_FR');

言語ファイルには「class.upload.xx_XX.php」というファイルが含まれており、このファイルを編集することで簡単に自作できる。

アップロードファイルを直接表示するには

$handle = new upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mim
echo $handle->Process();
die();

アップロードしたファイルの保存名を取得

$handle->file_dst_name;

ダウンロードを強制するには、

$handle = new upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mime);
header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
echo $handle->Process();
die();

デバッグ

以下のコードでログを表示可能
echo $foo->log;

※後日CakePHPでclass.upload.phpを使うメモを書こうと思っていたりいなかったり。

  1. こんな設定もあるのか! []
Written by suzukenn in: メモ,リファレンス | タグ: ,
8月
10
2009
0

[CakePHP]Cakeで初めてSSLを使ったメモ
このエントリをはてなブックマークに追加このエントリをdel.icio.usに追加このエントリをLivedoor Clipに追加このエントリをYahoo!ブックマークに追加このエントリをFC2ブックマークに追加このエントリをNifty Clipに追加このエントリをPOOKMARK. Airlinesに追加このエントリをBuzzurl(バザール)に追加このエントリをChoixに追加このエントリをnewsingに追加

明後日リリースするecサイトのプロジェクトで、CakePHPwithSSLを初めて経験したのでメモ。

注文フロー(カート内と呼称)や、問い合わせフォーム、マイページなど、個人情報に関する入力フォームのあるactionはhttps(SSL)のアクセスとする。

事前準備

特定のコントローラ、アクションに対してSSLアクセス必須の定義をするために、
/app/app_controller.phpでSecurityコンポーネントを追加

そのアクセスがSSLかどうかを判定するisSSLを使うために、
/app/app_controller.phpでRequestHandlerコンポーネントを追加

/app/app_controller.phpに_sslFailメソッドを追加
参考:CakePHPクッキング – 投稿の詳細: 特定のURLのみSSL接続を必須にする方法

http://cakephp.blog16.jp/index.php/2008/08/08/p50

	// SSL呼出エラー処理
	function _sslFail($err) {

		if ($err === 'secure') {
			// リダイレクト先は$this->paramsからとってるけど、別のパラメータから取得した方がいいのかな?キャメライズされないのでいつもここからとってるんですが^^;
			$this->redirect("https://".BASE_URL."/".$this->params['controller']."/".$this->params['action']);
			exit;
		}

	}

各コントローラのbeforeFIlterで必要に応じてSecurity::requireSecure();とコールバックをセット*1

		$this->Security->blackHoleCallback = '_sslFail';
		$this->Security->requireSecure("index", "preview", "demo", "demo_preview");

http⇒https

各コントローラでblackHoleCallback = _sslFailをセットしてるので、_sslFailメソッドでhttpsのurlにリダイレクトしてます。

https⇒http

各コントローラのbeforeFilterでセットしているSecurity::requireSecureを利用して、requreSecureをセットしていないコントローラでSSLアクセスならばhttpにリダイレクトとい処理を書いています。*2

		// Security::requireSecureをセットしていない"コントローラ"でhttpに戻す(actionを指定しているコントローラでは走らない)
		if (empty($this->Security->requireSecure)) {
			// チェックしたらこの処理じゃSSLページからpages/...を開けなくなってしまう...orzので取り急ぎpagesを回避
			<del datetime="2009-08-10T08:26:31+00:00">if ($this->RequestHandler->isSSL()) {</del>
			if ($this->RequestHandler->isSSL() && $this->params['controller'] !== "pages") {
				$this->redirect("http://".BASE_URL."/".$this->params['controller']."/".$this->params['action']);
			}
		}

Security::requireSecureが!emptyの場合に、array_searchを使えばaction単位で制御できると思いますが、僕の場合はほとんどコントローラ単位の制御なので割愛しました。なんとなくやりすぎかなぁとも思うし。

あと、今追い込みでテストしてますが、もしかしたら支障が出るようなこともあるかも。
例えば、通常ページからSSLのページにポストするとリダイレクトによって$this->dataが飛んじゃうんじゃないか?とか、試してませんしそれなら、その前からSSLアクセスしろよということになりますのであまりないと思いますけど。

ちなみに僕の場合はそれがいいのかどうかはわかりませんが、POSTはすべて元のアクションに返して、if ($this->params['form']['submitのname']) {}で処理、その後次画面にリダイレクトするようにカートを作っているので上記のようなことはありません。
↑こういうのもCakePHPのセオリーから外れた方法なんでしょうかね?CakePHPは素晴らしい先人の方々が作ったソースがいくらでも読み放題なんだから、そこから学べばいいんでしょうが、今の今まで読まずに我流でやってきちゃいました。
正直、CakePHPの規約もあまり守らず好き勝手やってるし、だからというのもあるのですがコンソール?とか、テストもほとんど使ったことが無いんですよね?。
知らないって罪ですよね。ものすごく遠回りしていることがたくさんあるんだろうけど、忙しいからと学ぶことを後回しにしてしまう。
僕にもう少し、余裕が出てきたらCakePHPに関して積極的に活動されている憧れの皆さんの輪の中に、僕も入ってみたいと思っています。 *3

  1. SSLアクセスが必要の無いコントローラなら書かなくてOK []
  2. もっといい方法があると思いますがこんな方法で良いわけありませんが、僕のできる範囲、思いつく範囲ではこれが最善限界…^^;。更によい方法がお分かりになる方教えてくださいm_ _m []
  3. この忙しい最中何を書いてるんだ俺は。。。orz []
Written by suzukenn in: メモ | タグ:

| I have been indebted to Aeros Theme. | Background image owner is NASA.