Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

12/07/2012

jquery.twitter.widget.js をリリースしました

Twitter のウィジェットを仕事で使うことになったんですが、Twitter API が 1.1 になったので、既存のウィジェットを使うと 来年 3 月 5 日以降サポートがされなくなる らしいのです。そこで、本家のウィジェット も新しくできたらしいので見てみたら、カスタマイズしづらいって思ったので、その案件専用のウィジェットを作りました。でもこれを汎用的にしておくと、他の案件でも使えるかもしれないし、これを使って幸せになる人もいるかもしれないので、jQuery プラグインとして作りました。

wings1685/jquery.twitter.widget.js


【使い方】
ダウンロード後(必要であれば解凍後)に生成された「jquery.twitter.widget.min.js」をhtmlに指定します。
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script>
<script type='text/javascript' src='jquery.twitter.widget.min.js'></script>
また、生成された「twitter.php」をどこかのディレクトリにアップロードします。ここではサンプルとして、「/api/」にアップします。


【機能詳細】
「$(selector).twitterWidget()」でターゲットとするTwitterユーザのツイートを取得し、表示します。表示する内容やツイートを表示する速さなどはプロパティを設定することで変えられます。

プロパティ一覧
  • screen_name:対象とするTwitterアカウント名
  • count:最大表示件数(最大200件)
  • speed:ツイートを表示していくスピード(秒)
  • exclude_replies:リプライのツイートを表示するかどうか(「true」で排除、「false」で表示)
  • include_rts:リツイートを表示するかどうか(trueで表示、falseで排除)
  • dateformat:日付のフォーマット(「Y年M月D日 h時m分s秒」など)
  • path:「twitter.php」までのパス(「./api/」など)
  • src:表示する部分のソース
  • src.header:ヘッダ部分
  • src.body:本体部分
  • src.footer:フッタ部分
  • src.reply:リプライ部分
  • src.retweet:リツイート部分
  • src.favorite:お気に入り部分

src内で指定できる予約文字列
  • $icon$:アイコン(a要素で囲まれたimg要素として書き出します)
  • $screen_name$:アカウント名(a要素で囲まれて書き出します)
  • $name$:表示名(a要素で囲まれて書き出します)
  • $description$:プロファイル文章(Twitterの設定で「URL」を指定している場合はこれも書き出します)
  • $text$:ツイート文章
  • $created_at$:日付(a要素で囲まれて書き出します)
  • $logo$:ロゴ(ツイッターロゴをa要素で囲まれたimg要素として書き出します)
  • $reply$:リプライアクション(「src.reply」で指定していればこの内容で書き出します)
  • $retweet$:リツイートアクション(「src.retweet」で指定していればこの内容で書き出します)
  • $favorite$:お気に入りアクション(「src.favorite」で指定していればこの内容で書き出します)
  • $action$:上記の「$reply$」「$retweet$」「$favorite$」をまとめて書き出します
※「src.header」「src.body」「src.footer」で指定できる予約文字列です。
必ず「$」で囲んでください。



【使用例】
ヘッダは「tw_header」、本体は「tw_body」、フッタは「tw_footer」というクラスを持ったdiv要素の中に書き出されます。
任意で指定したソースで書き出されるので、CSSでお好みのスタイルを付けてください。

html:
<div id='twitter'></div>

JavaScript:
サンプル1
ヘッダとフッタなし、リプライ等のアクションはテキスト表記、スピードが5秒ごとのサンプルです。
var option = {
  screen_name: 'wings1685',
  speed: 5,
  dateformat: 'Y/M/D h:m:s',
  path: './api/',
  src: {
    body: "<div class='tw'><span class='tw_text'>$text$</span> <span class='tw_date'>$created_at$</span><div>$reply$$retweet$$favorite$</div></div>",
    reply: 'Re:',
    retweet: 'RT',
    favorite: '★'
  }
};
$('#twitter').twitterWidget(option);


サンプル2
ヘッダとフッタあり、リプライ等のアクションは画像指定、スピードが10秒ごと、リプライのツイートなし、リツイートなしのサンプルです。
var option = {
  screen_name: 'wings1685',
  speed: 10,
  exclude_replies: true,
  include_rts: false,
  dateformat: 'Y年M月D日 h時m分s秒',
  path: './api/',
  src: {
    header: "<div class='clearfix'><strong>$icon$</strong><span>$screen_name$</span><span>($name$)</span></div><p>$description$</p>",
    body: "<div class='tw'><span class='tw_text'>$text$</span> <span class='tw_date'>$created_at$</span><div>$action$</div></div>",
    footer: "<div class='tw'>$logo$<span>Twitter</span></div>",
    reply: "<img src='./reply.png' alt='' title='' />",
    retweet: "<img src='./retweet.png' alt='' title='' />",
    favorite: "<img src='./favorite.png' alt='' title='' />"
  }
};
$('#twitter').twitterWidget(option);


【サンプルソース】
ひとつのhtmlにまとめた例をサンプルソースをとして以下に挙げます。
<!DOCTYPE HTML>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>jquery.twitter.widget.js</title>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script src="./js/jquery.twitter.widget.min.js"></script>
  <script>
    $(function() {
      var option = {
        screen_name: 'wings1685',
        speed: 10,
        exclude_replies: true,
        include_rts: false,
        dateformat: 'Y年M月D日 h時m分s秒',
        path: './api/',
        src: {
          header: "<div class='clearfix'><strong>$icon$</strong><span>$screen_name$</span><span>($name$)</span></div><p>$description$</p>",
          body: "<div class='tw'><span class='tw_text'>$text$</span> <span class='tw_date'>$created_at$</span><div>$action$</div></div>",
          footer: "<div class='clearfix'>$logo$<span>Twitter</span></div>",
          reply: "<img src='./reply.png' alt='' title='' />",
          retweet: "<img src='./retweet.png' alt='' title='' />",
          favorite: "<img src='./favorite.png' alt='' title='' />"
        }
      };
      $('#twitter').twitterWidget(option);
    });
  </script>
</head>
<body">
  <div id="twitter"></div>
</body>
</html>


【確認環境】
jquery.twitter.widget.js は下記のブラウザでお使いいただけます。
  • Chrome
  • Safari
  • Firefox
  • Opera
  • Internet Explorer 7 以降

【実行結果】
flugel.biz でご確認ください。

8/03/2012

[php で OAuth を使ってみる:第十参回] Twitter でフォローの一覧を取得する

Twitter に OAuth を使ってフォローの一覧を取得してみる。
※この情報は 2012 年 7 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証の流れは Twitter に文字を post する を参照。

フォローの一覧を一覧を取得するには、フォロワのとき と同じく、二段階の手順を踏まないといけないので、少々めんどくさいです。ここでは便宜上、2 つのファイルに分けてます。

1. フォローの id を取得する
<?php
include 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer key
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer secret
$access_token = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);

$api_url = 'http://api.twitter.com/1/friends/ids.json';
$params = array(
  'screen_name' => 'wings1685' // screen_name
);
$response = $consumer->sendRequest($api_url, $params, 'GET');

echo $response->getBody();
?>

2. 取得した id からデータを取得する
<?php
include 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer key
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer secret
$access_token = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);

$api_url = 'http://api.twitter.com/1/users/lookup.json';
$params = array(
  'user_id' => '12345,67890' // ユーザ id(複数の場合はカンマで区切る)
);
$response = $consumer->sendRequest($api_url, $params, 'GET');

echo $response->getBody();
?>

GET friends/ids | Twitter Developers
GET users/lookup | Twitter Developers

[php で OAuth を使ってみる:第十弐回] Twitter でフォロワの一覧を取得する

Twitter に OAuth を使ってフォロワの一覧を取得してみる。
※この情報は 2012 年 7 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証の流れは Twitter に文字を post する を参照。

フォロワの一覧を一覧を取得するには、二段階の手順を踏まないといけないので、少々めんどくさいです。ここでは便宜上、2 つのファイルに分けてます。

1. フォロワの id を取得する
<?php
include 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer key
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer secret
$access_token = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);

$api_url = 'http://api.twitter.com/1/followers/ids.json';
$params = array(
  'screen_name' => 'wings1685' // screen_name
);
$response = $consumer->sendRequest($api_url, $params, 'GET');

echo $response->getBody();
?>

2. 取得した id からデータを取得する
<?php
include 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer key
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer secret
$access_token = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);

$api_url = 'http://api.twitter.com/1/users/lookup.json';
$params = array(
  'user_id' => '12345,67890' // ユーザ id(複数の場合はカンマで区切る)
);
$response = $consumer->sendRequest($api_url, $params, 'GET');

echo $response->getBody();
?>

GET followers/ids | Twitter Developers
GET users/lookup | Twitter Developers

[php で OAuth を使ってみる:第十壱回] Twitter でお気に入りを取得する

Twitter に OAuth を使ってお気に入りを取得してみる。
※この情報は 2012 年 7 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証の流れは Twitter に文字を post する を参照。

お気に入りを取得する
<?php
include 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer key
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer secret
$access_token = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);

$api_url = 'http://api.twitter.com/1/favorites.json';
$params = array(
  'screen_name' => 'wings1685', // screen_name
  'count' => 20, // 取得する数
  'since_id' => 12345, // この tweet ID より新しいデータを取得する場合
  'max_id' => 12345, // この tweet ID より古いデータを取得する場合
);
$response = $consumer->sendRequest($api_url, $params, 'GET');

echo $response->getBody();
?>

GET favorites | Twitter Developers

7/27/2012

wordpress の PostViews プラグインで日付を表示する

Wordpress 便利ですね!これが無料ってホント信じられないです。

さて、その Wordpress の PostViews プラグインって便利なんですが、閲覧数順に表示したい場合もあると思います。でも PostViews では日付を取れないので、中身を改造してやる必要があります。でも簡単!1 分あればできます。

1. ファイルを開く
「wp-postviews」→「wp-postviews.php」をあなたが愛してやまないテキストエディタで開きましょう。

2. 「%POST_DATE%」を追加する
$temp = str_replace("%POST_DATE%", $post->post_date, $temp);

これを追加してアップロードします。追加する場所は、「%POST_URL%」で検索して出た箇所に次々と追加してやればいいです。これで %POST_DATE% が設定画面で扱えるようになります。

3. 管理画面で整形する
管理画面の「設定」→「PostViews」を開いて、「Most Viewed Template:」にあるテキストエリアで整形し、「Save Changes」を押して保存します。例えば、こんな風に。
<div>
<span class="popular_date">%POST_DATE%</span>
<a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</a>
</div>

「3.」の画面で、「Most Viewed Template:」の「Allowed Variables:」に「%PostViews%」がないよ!って焦っても大丈夫です。「wp-postviews」→「postviews-options.php」を開いて、「Allowed Variables:」を検索しましょう。そしたら見えるはずです。そこに「- %POST_DATE%
」を追記してアップロードすれば、ほら、出てきましたね?

2/01/2012

multipart/form-data でデータを Javascript で encode して cookie に送り、php で decode する

form の enctype が multipart/form-data の場合、Javascript で送ったデータが php では文字化けしてしまう(しかも au の android のみという噂あり。Android au を謳ってるのに...)ので、なんとかならないかと思い、cookie へ突っ込んで処理をすると回避できた。

ただ、Javascript と php では encode/decode が違うので、方法を合わせないとやっぱりおかしくなる。

☆Javascript 側
// expires は 2030 年にしてある
document.cookie = 'str=' + encodeURIComponent('化け化け') + '; expires=Tue, 1-Jan-2030 00:00:00 GMT';

☆php 側
$status = rawurldecode($_COOKIE[str]);

1/31/2012

[php で OAuth を使ってみる:第十一回] 4square でチェックインする

4square で OAuth を使ってチェックインしてみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証〜チェックインスポットの流れは 前のエントリー を参照。

チェックインする
<?php
$status = '**にチェックイン!'; // チェックインと一緒に post する文字列
$placeId = 'xxxxxxxxxxxxxxxx'; // 前エントリーで取得したチェックインスポットの ID
$lat = ''xxxxxxxxxxxxxxxx''; // 前エントリーで取得したチェックインスポットの緯度
$lon = 'xxxxxxxxxxxxxxxx'; // 前エントリーで取得したチェックインスポットの経度
$name = 'xxxxxxxxxxxxxxxx'; // 前エントリーで取得したチェックインスポットの名前

$checkin_url = 'https://api.foursquare.com/v2/checkins/add';
$data = array(
  'oauth_token' => $_COOKIE['4sqToken'], // 前エントリーの「3.」で cookie に保存した access_token
  'venueId' => $placeId,
  'venue' => $name,
  'shout' => $status,
  'broadcast' => 'public',
  'll' => $lat. ','. $lon
);
$data = http_build_query($data, '', '&');
$options = array(
  'http' => array(
    'method' => 'POST',
    'content' => $data
  )
);
$result = file_get_contents($checkin_url, false, stream_context_create($options));
?>

1/30/2012

[php で OAuth を使ってみる:第十回] 4square のチェックインスポットを取得する

4square のチェックインスポットを OAuth を使って取得してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

1. アプリを登録する
OAuth Consumer Registration にアクセスし、アプリの登録を行う。
APPLICATION NAME: アプリ名
APPLICATION WEB SITE: アプリ本体の URL
CALLBACK URL: ユーザによる認証動作後にリダイレクトする URL(「4.」でアップする php)

※全ての情報は登録後でも変更できるので、気楽に。

2. 使うキーを確認する
My OAuth Consumers にある「Client ID」と、「Client Secret」を確認する。これが今後必要となるキー。

3. 認証受け渡し用の php を用意する
下記に必要な事項を埋め、アプリのディレクトリにアップする。
<?php
$consumer_key = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Client ID」
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Client Secret」
$callback = 'callback する URL'; // この場合はこの php 本体

if (empty($_GET['code'])) {
// ユーザの認証前、4square にリダイレクトする
  $auth_url = 'https://foursquare.com/oauth2/authenticate?';
  $auth_url .= 'client_id='. $consumer_key;
  $auth_url .= '&response_type=code';
  $auth_url .= '&redirect_uri='. $callback;

  header('Location: '. $auth_url);
} else {
// ユーザの認証後、リダイレクトで帰ってきた後
  $accees_token_url = 'https://foursquare.com/oauth2/access_token?';
  $accees_token_url .= 'client_id='. $consumer_key;
  $accees_token_url .= '&client_secret='. $consumer_secret;
  $accees_token_url .= '&grant_type=authorization_code';
  $accees_token_url .= '&redirect_uri='. $callback;
  $accees_token_url .= '&code='. $_GET['code'];

  $result = json_decode(file_get_contents($accees_token_url), true);
  $access_token = $result['access_token'];

  echo "<script type='text/javascript'>location.href = 'アプリ本体の URL';</script>";
}
?>

4. チェックインスポットを検索して表示する
<?php
// php の文字コードが utf-8 であっても文字化けしたので記載
header('Content-type: application/json; charset=utf-8');

$query = 'モスバーガー'; // 検索語句

$spot_url = 'https://api.foursquare.com/v2/venues/search?';
$spot_url .= 'client_id='. 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Client ID」
$spot_url .= '&client_secret='. 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Client Secret」
$spot_url .= '&access_token='. 'xxxxxxxxxxxxxxxx'; // 「4.」で取得した access_token
$spot_url .= '&ll=34.985214,135.758593'; // 任意の緯度経度
$spot_url .= '&llAcc=1000'; // 1,000m 四方が対象
$spot_url .= '&limit=20'; // 20 件取得
// スポット名で検索する場合
if ($_COOKIE['query']) $spot_url .= '&query='. urlencode($query); // urlencode しないと取得できない
// 結果は json で返ってくるので、そのまま echo してやる
echo file_get_contents($spot_url);
?>
例えばこの php をアプリ本体の Javascript で読み込み、結果で出た json を Javascript で解析してレイアウト後に表示する、などができる。

1/29/2012

[php で OAuth を使ってみる:第九回] Facebook でチェックインする

Facebook で OAuth を使ってチェックインしてみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証〜チェックインスポットの流れは Facebook に文字を post する を参照。

チェックインする
<?php
$status = '**にチェックイン!'; // チェックインと一緒に post する文字列
$placeId = 'xxxxxxxxxxxxxxxx'; // 前エントリーで取得したチェックインスポットの ID
$lat = ''xxxxxxxxxxxxxxxx''; // 前エントリーで取得したチェックインスポットの緯度
$lon = 'xxxxxxxxxxxxxxxx'; // 前エントリーで取得したチェックインスポットの経度
$name = 'xxxxxxxxxxxxxxxx'; // 前エントリーで取得したチェックインスポットの名前

array_push($targets, ' Facebook ');

require_once 'facebook/facebook.php';

$facebook = new Facebook(array(
  'appId' => 'xxxxxxxxxxxxxxxx', // 以前のエントリーで確認した「App ID/API Key」
  'secret' => 'xxxxxxxxxxxxxxxx' // 以前のエントリーで確認した「アプリの秘訣」
));

$attachment = array(
  'access_token' => 'xxxxxxxxxxxxxxxx', // 以前のエントリーで取得した access_token
  'message' => $status,
  'place' => $placeId,
  'coordinates' => array(
    'latitude' => $lat,
    'longitude' => $lon
  )
);

$facebook->api('/me/checkins', 'POST', $attachment);

echo "<script type='text/javascript'>alert('「". $name. "」にチェックインしました!');</script>\n";
?>

1/28/2012

[php で OAuth を使ってみる:第八回] Facebook のチェックインスポット取得する

Facebook のチェックインスポットを OAuth を使って取得してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証の流れは Facebook に文字を post する を参照。その際に、認証時に使う「scope」を「publish_checkins」にする。

チェックインスポットを検索して表示する
<?php
$query = $_POST['query'];
// php の文字コードが utf-8 であっても文字化けしたので記載
header('Content-type: application/json; charset=utf-8');

require_once 'facebook/facebook.php';

$facebook = new Facebook(array(
  'appId' => 'xxxxxxxxxxxxxxxx', // 以前のエントリーで確認した「App ID/API Key」
  'secret' => 'xxxxxxxxxxxxxxxx' // 以前のエントリーで確認した「アプリの秘訣」
));
$attachment = array(
  'type' => 'place',
  'center'=> '34.985214,135.758593', // 任意の緯度経度
  'distance' => '1000', // 1,000m 四方が対象
  'access_token' => 'xxxxxxxxxxxxxxxx' // 以前のエントリーで取得した access_token
);
$query = 'モスバーガー'; // 検索語句
// スポット名で検索する場合
if ($query) $attachment['q'] = $query;

$place = $facebook->api('/search', 'get', $attachment);
// 結果は json で返ってこないので、json_encode してやる
echo json_encode($place);
?>
例えばこの php をアプリ本体の Javascript で読み込み、結果で出た json を Javascript で解析してレイアウト後に表示する、などができる。

1/27/2012

php で OAuth を使ってみる

php で OAuth を使って色々と遊んでみようと思う。

  1. Twitter に文字を post する
  2. tumblr. に文字を post する
  3. Facebook に文字を post する
  4. TwitPic に画像を post する
  5. tumblr. に画像を post する
  6. Facebook に画像を post する
  7. Flickr に画像を post する
  8. Facebook のチェックインスポット取得する
  9. Facebook でチェックインする
  10. 4square のチェックインスポットを取得する
  11. Twitter でお気に入りを取得する
  12. Twitter でフォロワの一覧を取得する
  13. Twitter でフォローの一覧を取得する

1/26/2012

[php で OAuth を使ってみる:第七回] Flickr に画像を post する

Flickr に OAuth を使って画像を post してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

1. Flickr アプリを登録する
The App Garden にアクセスし、アプリの登録を行う。商用でなければ「APPLY FOR A NON-COMMERCIAL KEY」をまずクリックする。
What's the name of your app?: アプリ名
What are you building?: アプリの説明
下 2 つのチェック: チェックする

※登録後、アプリ名は変えられない模様。

2. Flickr の使うキーを確認する
登録後に表示されたページで、「Key」と「Secret」を確認する。これが今後必要となるキー。

3. 書き込みできる権限に変更する
登録後に表示されたページの「Edit app details」をクリックし、続いて右側にある「Edit」をクリックして、入力し、保存する。
App Type: 用途により選ぶ
Callback URL: ユーザによる認証動作後にリダイレクトする URL(「4.」でアップする php)
App Logo: アイコン(GIF のみw)

3. 必要となるライブラリをインストールする
下記からダウンロードし、アプリとするディレクトリにアップする。
phpflickr: phpflickr, /アプリのディレクトリ/Flickr

4. 認証受け渡し用の php を用意する
下記に必要な事項を埋め、アプリのディレクトリにアップする。
<?php
$api_key = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Key」
$api_secret = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Secret」
$permissions = 'write'; // 書き込むので write。読み込むだけなら read、削除もするなら delete
$path_to_phpFlickr_class = './Flickr/';

ob_start();
require_once($path_to_phpFlickr_class . 'phpFlickr.php');
unset($_SESSION['phpFlickr_auth_token']);

if (isset($_SESSION['phpFlickr_auth_redirect']) && !empty($_SESSION['phpFlickr_auth_redirect'])) {
  $redirect = $_SESSION['phpFlickr_auth_redirect'];
  unset($_SESSION['phpFlickr_auth_redirect']);
}

$f = new phpFlickr($api_key, $api_secret);

if (empty($_GET['frob'])) {
  $f->auth($permissions, false);
} else {
  $f->auth_getToken($_GET['frob']);
}

if (empty($redirect)) {
// ユーザの認証後、リダイレクトで帰ってきた後
  $f->auth("read");

  echo "<script type='text/javascript'>location.href = 'アプリ本体の URL';</script>";
} else {
// ユーザの認証前、Flickr にリダイレクトする
  header('Location: '. $redirect);
}
?>

5. post する
下記の php をアプリのディレクトリにアップする(予め tmp ディレクトリを 707 で作っておく)
※html の form 要素内での input type='file' は name='img' としている。
<?php
$title = 'テストタイトル';
$status = 'テスト';
$tag = 'テスト画像';

$key = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Key」
$secret = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Secret」

// 一度自分のサーバにアップ
$uploaddir = './tmp/';
$photo = $uploaddir. basename($_FILES['img']['name']);
move_uploaded_file($_FILES['img']['tmp_name'], $photo);

require_once './Flickr/phpFlickr.php';

$f = new phpFlickr($key, $secret);
$f->auth('write');
$f->sync_upload($photo, $title, $status, $tag);
// 自分のサーバにアップした画像を削除
unlink($photo);

echo "<script type='text/javascript'>alert('画像「". $_FILES['img']['tmp_name']. "」をpostしました!');</script>\n";
?>

1/25/2012

[php で OAuth を使ってみる:第六回] Facebook に画像を post する

Facebook に OAuth を使って画像を post してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証の流れは Facebook に文字を post する を参照。

post する
下記の php をアプリのディレクトリにアップする(予め tmp ディレクトリを 707 で作っておく)
<?php
// 一度自分のサーバにアップ
$uploaddir = './tmp/';
$photo = $uploaddir. basename($_FILES['img']['name']);
move_uploaded_file($_FILES['img']['tmp_name'], $photo);

require_once 'facebook/facebook.php';

$facebook = new Facebook(array(
  'appId' => 'xxxxxxxxxxxxxxxx', // 以前のエントリーで確認した「App ID/API Key」
  'secret' => 'xxxxxxxxxxxxxxxx' // 以前のエントリーで確認した「アプリの秘訣」
));

$attachment = array(
  'access_token' => $_COOKIE['facebookToken'], // 以前のエントリーで cookie に保存した access_token
  'message' => 'テスト', // post する本文
  'src' => '@'. $photo, // 必ず $photo の前に '@' を付ける
);

$facebook->setFileUploadSupport(true);
$post_result = $facebook->api('/me/photos', 'POST', $attachment);

// 自分のサーバにアップした画像を削除
unlink($photo);

echo "<script type='text/javascript'>alert('「". $status. "」をpostしました!');</script>\n";
?>

1/24/2012

[php で OAuth を使ってみる:第五回] tumblr. に画像を post する

tumblr. に OAuth を使って画像を post してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証の流れは tumblr. に文字を post する を参照。

post する
下記の php をアプリのディレクトリにアップする(予め tmp ディレクトリを 707 で作っておく)
<?php
// 一度自分のサーバにアップ
$uploaddir = './tmp/';
$photo = $uploaddir. basename($_FILES['img']['name']);
$path = 'アプリのあるドメイン'. 'tmp/'. basename($_FILES['img']['name']); // full path
move_uploaded_file($_FILES['img']['tmp_name'], $photo);

require_once 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した OAuth Consumer Key
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Secret Key
$access_token = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);

$params = array(
  'type' => 'photo',
  'source' => $path,
  'caption' => 'テスト' // post する本文
);

$api_url = 'http://www.tumblr.com/api/write';
$response = $consumer->sendRequest($api_url, $params);
// 自分のサーバにアップした画像を削除
unlink($photo);

echo "<script type='text/javascript'>alert('画像「". $_FILES['img']['tmp_name']. "」をpostしました!');</script>\n";
?>

「引用」以外で必要な項目は公式ページを参考に。
Tumblr API v1 | Tumblr

1/23/2012

[php で OAuth を使ってみる:第四回] TwitPic に画像を post する

TwitPic に OAuth を使って画像を post してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

OAuth を使った認証の流れは Twitter に文字を post する を参照。

1. TwitPic アプリを登録する
TwitPic Developers - Register an Application にアクセスし、アプリの登録を行う。
Application Title: アプリ名(日本語不可)
Application Description: アプリの説明
Application Homepage: アプリ本体の URL
Your Email: email アドレス
Are You Human?: CAPTCHA による認証

※全ての情報は登録後でも変更できるので、気楽に。

2. TwitPic の使うキーを確認する
TwitPic Developers - Your Applications に表示されている「API Key」を確認する。これも今後必要となるキー。

3. 必要となるライブラリをインストールする
下記からダウンロードし、アプリとするディレクトリにアップする。
meltingice/php-twitpic: meltingice/php-twitpic - GitHub, /アプリのディレクトリ/TwitPic

4. post する
下記の php をアプリのディレクトリにアップする(予め tmp ディレクトリを 707 で作っておく)
※html の form 要素内での input type='file' は name='img' としている。
<?php
$status = 'テスト';
// 一度自分のサーバにアップ
$uploaddir = './tmp/';
$photo = $uploaddir. basename($_FILES['img']['name']);
move_uploaded_file($_FILES['img']['tmp_name'], $photo);

require_once 'TwitPic/TwitPic.php';

$twitpic_key = 'xxxxxxxxxxxxxxxx'; // 「3.」で確認した「API Key」
$consumer_key = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer key
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで確認した Consumer secret
$access_token = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 以前のエントリーで取得した access_token_secret

$twitpic = new TwitPic(
  $twitpic_key,
  $consumer_key,
  $consumer_secret,
  $access_token,
  $access_token_secret
);

try{
  $result = $twitpic->uploadAndPost(
    array(
      'media'=>$photo,
      'message'=>$status // post する本文
    ),
    array('format'=>'xml')
  );
  $result = print_r($result, true);
} catch (Exception $e) {
  echo $e->getMessage();
  exit;
}
// 自分のサーバにアップした画像を削除
unlink($photo);

echo "<script type='text/javascript'>alert('画像「". $_FILES['img']['tmp_name']. "」をpostしました!');</script>\n";
?>

1/22/2012

[php で OAuth を使ってみる:第参回] Facebook に文字を post する

Facebook に OAuth を使って post してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

1. アプリを登録する
Facebook 開発者 にアクセスし、「新しいアプリケーションを作成」を押して、アプリの登録を行う。
App Display Name: アプリ名
App Namespace: アプリに割り当てられる固有ディレクトリ
※初めて登録する際には、携帯電話かクレジットカードでの認証が必要になる。

登録後、編集画面で下記の情報を入力する。
連絡先メールアドレス: email アドレス
ウェブサイト: ユーザによる認証動作後にリダイレクトする URL(「4.」でアップする php)
※その他はそのままでも問題ない。

2. 使うキーを確認する
登録後のページにある「App ID/API Key」と、「アプリの秘訣(Secret Key のこと)」を確認する。これが今後必要となるキー。

3. 必要となるライブラリをインストールする
下記からダウンロードし、アプリとするディレクトリにアップする。
facebook/php-sdk: facebook/php-sdk - GitHub, /アプリのディレクトリ/facebook
※元々は「src」ディレクトリだったものをここでは「facebook」にリネームしている。また、アップするものは「src」ディレクトリ内の全て。

4. 認証受け渡し用の php を用意する
下記に必要な事項を埋め、アプリのディレクトリにアップする。
<?php
require_once 'facebook/facebook.php';

$facebook = new Facebook(array(
  'appId' => 'xxxxxxxxxxxxxxxx', // 「2.」で確認した「App ID/API Key」
  'secret' => 'xxxxxxxxxxxxxxxx', // 「2.」で確認した「アプリの秘訣」
  'cookie' => true
));

$fb_user = $facebook->getUser();

if (!$_GET[code]) {
// ユーザの認証前、Facebook にリダイレクトする
// News Feed に post する publish_stream を記載
  $par = array('scope' => 'publish_stream');
  echo "<script type='text/javascript'>location.href = '". $facebook->getLoginUrl($par). "';</script>";
} else {
// ユーザの認証後、リダイレクトで帰ってきた後
  $access_token = $facebook->getAccessToken();

  echo "<script type='text/javascript'>location.href = 'アプリ本体の URL';</script>";
}
?>


5. post する
下記の php をアプリのディレクトリにアップする
<?php
require_once 'facebook/facebook.php';

$facebook = new Facebook(array(
  'appId' => 'xxxxxxxxxxxxxxxx', // 「2.」で確認した「App ID/API Key」
  'secret' => 'xxxxxxxxxxxxxxxx' // 「2.」で確認した「アプリの秘訣」
));

$attachment = array(
  'access_token' => 'xxxxxxxxxxxxxxxx'「4.」で取得した access_token
  'message' => 'テスト', // post する本文
);

$facebook->api('/me/feed', 'POST', $attachment);
echo "<script type='text/javascript'>alert('「". $status. "」をpostしました!');</script>\n";
?>

[php で OAuth を使ってみる:第弐回] tumblr. に引用を post する

tumblr. に OAuth を使って post してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

1. アプリを登録する
Register your application にアクセスし、アプリの登録を行う。
Application name: アプリ名
Application webSite: アプリ本体の URL
Application description: アプリの説明
Administrative contact email: email アドレス
Default callback URL: ユーザによる認証動作後にリダイレクトする URL(「4.」でアップする php)
Icon: アイコン

※全ての情報は登録後でも変更できるので、気楽に。

2. 使うキーを確認する
登録後のページにある「OAuth Consumer Key」と、「Show secret key」をクリックして表示される「Secret Key」を確認する。これが今後必要となるキー。

3. 必要となるライブラリをインストールする
下記からダウンロードし、アプリとするディレクトリにアップする。
PEAR: PEAR, /アプリのディレクトリ/PEAR
HTTP_OAuth: HTTP_OAuth, /アプリのディレクトリ/HTTP
HTTP_Request2: HTTP_Request2, /アプリのディレクトリ/HTTP/Request2
Net_URL2: Net_URL2, /アプリのディレクトリ/Net

4. 認証受け渡し用の php を用意する
下記に必要な事項を埋め、アプリのディレクトリにアップする。
<?php
include 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「OAuth Consumer Key」
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Secret Key」

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

session_start();

if (empty($_GET['oauth_verifier'])) {
// ユーザの認証前、tumblr. にリダイレクトする
  $consumer->getRequestToken('http://www.tumblr.com/oauth/request_token');

  $_SESSION['request_token'] = $consumer->getToken();
  $_SESSION['request_token_secret'] = $consumer->getTokenSecret();

  $auth_url = $consumer->getAuthorizeUrl('http://www.tumblr.com/oauth/authorize');

  header('Location: '. $auth_url);
} else {
// ユーザの認証後、リダイレクトで帰ってきた後
  $consumer->setToken($_SESSION['request_token']);
  $consumer->setTokenSecret($_SESSION['request_token_secret']);

  $consumer->getAccessToken('http://www.tumblr.com/oauth/access_token', $_GET['oauth_verifier']);

  echo "<script type='text/javascript'>location.href = 'アプリ本体の URL';</script>";
}
?>

5. post する
下記の php をアプリのディレクトリにアップする
<?php
require_once 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「OAuth Consumer Key」
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 「2.」で確認した「Secret Key」

$access_token = 'xxxxxxxxxxxxxxxx'; // 「4.」で取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 「4.」で取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);
// 今回の post のタイプは「引用」
$params = array(
  'type' => 'quote',
  'quote' => 'テスト', // post する本文
  'source' => 'アプリ本体の URL など'
);

$api_url = 'http://www.tumblr.com/api/write';
$response = $consumer->sendRequest($api_url, $params);
echo "<script type='text/javascript'>alert('「". $status. "」をpostしました!');</script>\n";
?>

「引用」以外で必要な項目は公式ページを参考に。
Tumblr API v1 | Tumblr

1/21/2012

京都で遊ぼう!の SNS 連携を強化しました

京都で遊ぼう! の SNS 連携を強化しました。


現在連携できる対象サービスは以下の通りです。
文字 post
  • Twitter
  • Facebook
  • tumblr.

画像 post
  • TwitPic
  • Facebook
  • tumblr.
  • Flickr

※iPhone などの iOS では input type='hidden' が無効化されるのでスマートフォンでの画像アップロードは Android でのみ有効です。

京都で遊ぼう!説明ページ
京都で遊ぼう!

[php で OAuth を使ってみる:第壱回] Twitter に文字を post する

Twitter に OAuth を使って post してみる。
※この情報は 2012 年 1 月現在のものです。仕様が変更される可能性は充分にあるので、ご了承ください。

1. アプリを登録する
Create an application | Twitter Developers にアクセスし、アプリの登録を行う。
Name: アプリ名
Description: アプリの説明
WebSite: アプリ本体の URL
Callback URL: ユーザによる認証動作後にリダイレクトする URL(「5.」でアップする php)

※全ての情報は登録後でも変更できるので、気楽に。

2. 書き込みできる権限に変更する
アプリの詳細ページに「Settings」というタブがあるので、それをクリックし、「Application Type」の「Access」を「Read and Write」に変更し、保存する。

3. 使うキーを確認する
「Details」タブを押し、「Consumer key」と「Consumer secret」を確認する。これが今後必要となるキー。

4. 必要となるライブラリをインストールする
下記からダウンロードし、アプリとするディレクトリにアップする。
PEAR: PEAR, /アプリのディレクトリ/PEAR
HTTP_OAuth: HTTP_OAuth, /アプリのディレクトリ/HTTP
HTTP_Request2: HTTP_Request2, /アプリのディレクトリ/HTTP/Request2
Net_URL2: Net_URL2, /アプリのディレクトリ/Net

5. 認証受け渡し用の php を用意する
下記に必要な事項を埋め、アプリのディレクトリにアップする。
<?php
include './HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 「3.」で確認した「Consumer key」
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 「3.」で確認した「Consumer secret」

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

session_start();

if (empty($_GET['oauth_verifier'])) {
// ユーザの認証前、Twitter にリダイレクトする
  $callback = 'callback する URL'; // この場合はこの php 本体
  $consumer->getRequestToken('https://api.twitter.com/oauth/request_token', $callback);

  $_SESSION['request_token'] = $consumer->getToken();
  $_SESSION['request_token_secret'] = $consumer->getTokenSecret();

  $auth_url = $consumer->getAuthorizeUrl('https://api.twitter.com/oauth/authorize');

  header('Location:'. $auth_url);
} else {
// ユーザの認証後、リダイレクトで帰ってきた後
  $consumer->setToken($_SESSION['request_token']);
  $consumer->setTokenSecret($_SESSION['request_token_secret']);
  $consumer->getAccessToken('https://api.twitter.com/oauth/access_token', $_GET['oauth_verifier']);

  $_SESSION['access_token'] = $consumer->getToken();
  $_SESSION['access_token_secret'] = $consumer->getTokenSecret();

  echo "<script type='text/javascript'>location.href = 'アプリ本体の URL';</script>";
}
?>

6. post する
下記の php をアプリのディレクトリにアップする
<?php
require_once 'HTTP/OAuth/Consumer.php';

$consumer_key = 'xxxxxxxxxxxxxxxx'; // 「3.」で確認した「Consumer key」
$consumer_secret = 'xxxxxxxxxxxxxxxx'; // 「3.」で確認した「Consumer secret」
$access_token = 'xxxxxxxxxxxxxxxx'; // 「5.」で取得した access_token
$access_token_secret = 'xxxxxxxxxxxxxxxx'; // 「5.」で取得した access_token_secret

$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);

$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer_request = new HTTP_OAuth_Consumer_Request;
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);

$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);

$api_url = 'http://api.twitter.com/1/statuses/update.json';
$params = array(
  'status' => 'テスト' // post する本文
);
$response = $consumer->sendRequest($api_url, $params, 'POST');
echo "<script type='text/javascript'>alert('「". $status. "」をpostしました!');</script>\n";
?>

POST statuses/update | Twitter Developers

8/14/2010

php で携帯用に画像を自動で画像を縮小する

携帯版ウェブサイトは、表示できる 1 ページの容量がパソコン版に比べ大幅に制限されているため、画像がデカ過ぎたりするとそれだけでぐんにょりした感じになってしまう。なので、画像がデカい場合は自動で縮小し、表示できるようにするという、パソコン版ではあまり想定しないような配慮も必要となる。

そこで、php でページを自動生成する場合、自動で縮小をする処理を書いておけば大方回避できる。下記は一例として、ファイル名からサイズを取得し、100000 bytes 以上の場合に縮小画像を生成し、表示するものを書いてみる。縮小サイズの横幅は 200px としている。

// 画像ファイル名を変数 imgFile に代入
$imgFile = "./img/xxx.jpg";
// ファイルサイズを取得し、100000 bytes 以上の場合、
// 画像縮小処理の copyImgForMobile() を実行する
if (filesize($imgFile) >= 100000) {
// copyImgForMobile() で縮小画像のファイル名を imgFile に代入
  $imgFile = copyImgForMobile($imgFile);
}
// 画像を表示
  echo = "<div align='center'><img src='". $imgFile. "' width='200' alt='' title=''></div>¥n");

// 画像の縮小処理
function copyImgForMobile($imgFileName) {
// ファイルの横幅を変数 imgWidth に、高さを変数 imgHeight に代入
  list($imgWidth,$imgHeight) = getimagesize($imgFileName);
// 縮小する画像のリソースを変数 imgResource に代入
  $imgResource = @imagecreatefromjpeg($imgFileName);
// 縮小後の横幅を 200px に固定し、変数 imgWidthSmall に代入
  $imgWidthSmall = 200;
// 横幅を縮小する割合から縮小後の高さを変数 imgHeightSmall に代入
  $imgHeightSmall = ($imgWidthSmall / $imgWidth) * $imgHeight;
// TrueColor イメージを新規に作成し、変数 imgCopy に代入
  $imgCopy = imagecreatetruecolor($imgWidthSmall, $imgHeightSmall);
// 画像の縮小を実行する
  imagecopyresized($imgCopy, $imgResource, 0, 0, 0, 0, $imgWidthSmall, $imgHeightSmall, $imgWidth, $imgHeight);
// ファイル名を名称部分と拡張しに分け、変数 imgFileStr に代入
  $imgFileStr = explode(".", $imgFileName);
// ファイル名部分の最後に「携帯用」として「_m」を付け、縮小後のファイル名を生成
  $imgFileNameNew = $imgFileStr[0]. "_m". $imgFileStr[1];
// 縮小後の画像を出力する
  imagejpeg($imgCopy, $imgFileNameNew);
// 縮小後のファイル名を返す
  return $imgFileNameNew;
}