さくらインターネットにOpenPNEをインストール(ImageMagicKの設定)

2月 24, 2011 · Posted in OpenPNE · Comment 

ちょっとメモ。

環境

さくらインターネットマネージドプラン(Atom)
http://www.sakura.ne.jp/managedserver/
OpenPNE2.14.7

設定

config.phpを編集

// ImageMagick の convertコマンドのパス
define('IMGMAGICK_APP', '/usr/local/bin/convert');

PEAR – Text_CAPTCHA

9月 17, 2010 · Posted in PEAR, PEAR::Text_CAPTCHA, PHP · Comment 

Pear::Text_CAPTCHA。PearのCAPTCHA出力用モジュールを使ってみる。

インストール

例によって安定版が存在しないのでアルファ版をインストール

D:\>pear install Text_CAPTCHA
Failed to download pear/Text_CAPTCHA within preferred state “stable”, latest rel
ease is version 0.4.0, stability “alpha”, use “channel://pear.php.net/Text_CAPTC
HA-0.4.0″ to install
install failed

D:\>pear install Text_CAPTCHA-alpha
WARNING: channel “pear.php.net” has updated its protocols, use “pear channel-upd
ate pear.php.net” to update
Did not download optional dependencies: pear/Numbers_Words, pear/Text_Figlet, pe
ar/Image_Text, use –alldeps to download automatically
pear/Text_CAPTCHA can optionally use package “pear/Numbers_Words”
pear/Text_CAPTCHA can optionally use package “pear/Text_Figlet”
pear/Text_CAPTCHA can optionally use package “pear/Image_Text” (recommended vers
ion 0.6.0beta)
downloading Text_CAPTCHA-0.4.0.tgz …
Starting to download Text_CAPTCHA-0.4.0.tgz (14,833 bytes)
…..done: 14,833 bytes
downloading Text_Password-1.1.1.tgz …
Starting to download Text_Password-1.1.1.tgz (4,357 bytes)
…done: 4,357 bytes
install ok: channel://pear.php.net/Text_Password-1.1.1
install ok: channel://pear.php.net/Text_CAPTCHA-0.4.0

D:\>

PEAR::Image_Textもインストール

D:\>pear install Image_Text-beta
WARNING: channel “pear.php.net” has updated its protocols, use “pear channel-upd
ate pear.php.net” to update
downloading Image_Text-0.6.0beta.tgz …
Starting to download Image_Text-0.6.0beta.tgz (60,924 bytes)
……………done: 60,924 bytes
install ok: channel://pear.php.net/Image_Text-0.6.0beta

クイックスタート

サンプルコードの実行

<?php
require_once 'Text/CAPTCHA.php';

// CAPTCHA のオプションを設定します (フォントが存在する必要があります!)
$imageOptions = array(
    'font_size'        => 24,
    'font_path'        => './',
    'font_file'        => 'COUR.TTF',
    'text_color'       => '#DDFF99',
    'lines_color'      => '#CCEEDD',
    'background_color' => '#555555'
);

// CAPTCHA のオプションを設定します
$options = array(
    'width' => 200,
    'height' => 80,
    'output' => 'png',
    'imageOptions' => $imageOptions
);

// 新しい Text_CAPTCHA オブジェクトを Image ドライバで作成します
$c = Text_CAPTCHA::factory('Image');
$retval = $c->init($options);
if (PEAR::isError($retval)) {
    printf('CAPTCHA 作成時にエラー: %s!',
        $retval->getMessage());
    exit;
}

// CAPTCHA のパスフレーズを取得します
$_SESSION['phrase'] = $c->getPhrase();

// CAPTCHA 画像を (PNG 形式で) 取得します
$png = $c->getCAPTCHAAsPNG();
if (PEAR::isError($png)) {
    echo 'CAPTCHA 作成時にエラー!';
    echo $png->getMessage();
    exit;
}
file_put_contents(md5(session_id()) . '.png', $png);
?>

おこられ

フォントがないのが原因ぽい(8行目の「’font_file’=>’COUR.TTF’」)

とりあえず、IPAフォントをダウンロード。(IPAフォント)ipag.ttfをソースコードと同一ディレクトリにおいて、8行目のフォント指定をipag.ttfに修正して再実行・・・画面真っ白。

と思ったら、ソースコードのディレクトリに「’ランダムな文字列.png’」ファイルができてた。

簡単。

PEAR – Calendar

9月 7, 2010 · Posted in PEAR, PEAR::Calendar, PHP · Comment 

PEAR::Calendar。PEARのカレンダーモジュールを使ってみる。

インストール

パッケージのインストール。
安定版が存在しないのでベータ版をダウンロードする。

D:\xampp\php>pear install calendar
Failed to download pear/calendar within preferred state “stable”, latest release
is version 0.5.5, stability “beta”, use “channel://pear.php.net/calendar-0.5.5″
to install
install failed

D:\xampp\php>pear install calendar-beta
WARNING: channel “pear.php.net” has updated its protocols, use “pear channel-upd
ate pear.php.net” to update
Did not download optional dependencies: pear/Date, use –alldeps to download aut
omatically
pear/Calendar can optionally use package “pear/Date”
downloading Calendar-0.5.5.tgz …
Starting to download Calendar-0.5.5.tgz (58,159 bytes)
…………..done: 58,159 bytes
install ok: channel://pear.php.net/Calendar-0.5.5

D:\xampp\php>

サンプルコードの実行

公式ページのサンプルスクリプト(お急ぎの方用 — お湯をかけるだけのように…)を実行してみる

<?php
require_once 'Calendar/Month/Weekdays.php';

$month = new Calendar_Month_Weekdays(date('Y'), date('n'));
$month->build();

echo "<table>\n";

while ($day = $Month->fetch()) {
    if ($day->isFirst()) {
        echo "<tr>\n";
    }

    if ($day->isEmpty()) {
        echo "<td>&nbsp;</td>\n";
    } else {
        echo '<td>'.$day->thisDay()."</td>\n";
    }

    if ($day->isLast()) {
        echo "</tr>\n";
    }
}

echo "</table>\n";
?>

結果

おー、簡単。
実際に使うときは、テンプレートエンジン(Smartyとか)と組み合わせたほうがスッキリする。

年月の取得

require_once 'Calendar/Month/Weekdays.php';

$month = new Calendar_Month_Weekdays(date('Y'), date('n'));
$month->build();

// (略)

print $month->year;
print $month->month;

カレンダーの開始曜日を設定する

$month = new Calendar_Month_Weekdays(date("Y"), date("n"), 0);

コンストラクタに3つめの引数を設定して制御する。0=日曜日,1=月曜日…6=土曜日。なぜか定数はなし。

週間カレンダーの作成・取得

require_once "Calendar/Week.php";

$week = new Calendar_Week(date("Y"), date("n"), date("d") ,0);
$week->build();

while ($day = $week->fetch()) {
	print_r($day->day);
	print "<hr>";
}
?>

結果

何週目か取得(ドキュメント

$week->thisWeek("n_in_month");

次ページへ »