CQT_Fotolia

factory(String $api_key, String $id)

CQT_Fotolia_APIを生成します。

$api_key
Fotolia のAPIキー
$id
ユーザーID
@return
CQT_Fotolia_API
CQT_Fotolia
  1.  
  2.  <?php
  3.  define('FOTOLIA_API_KEY', 'apikey');
  4.  define('FOTOLIA_ID', 'id');
  5.  
  6.  $fotolia = CQT_Fotolia::factory(FOTOLIA_API_KEY, FOTOLIA_ID);
  7.  ?>

CQT_Fotolia_API

getItems(String|Array $id[,id,id])

指定したidの画像を取得します。

String id
画像のID(メディアID)を指定。
CQT_Fotolia_API::getItems()
  1.  
  2.  <?php
  3.  $photos = $fotolia->getItems('18580260,9933855,error_value');
  4.  $html = '';
  5.  foreach ($photos as $photo) {
  6.   $tr = '';
  7.   foreach ($photo as $key => $value) {
  8.   $tr .= sprintf('
  9.   <tr>
  10.   <th>%s</th>
  11.   <td>%s</td>
  12.   </tr>
  13.   ',
  14.   $key,
  15.   $value
  16.   );
  17.   }
  18.   $html .= '<table>' . $tr . '</table>';
  19.  }
  20.  
  21.  echo $html;
  22.  ?>
実行結果
id 18580260
ex_affiliate_url_creator http://jp.fotolia.com/p/117924/partner/201417048
ex_affiliate_url_media http://jp.fotolia.com/id/18580260/partner/201417048
title Young dancing woman
creator_name George Mayer
creator_id 117924
creation_date 2009-11-21 16:34:03.399564
media_type_id 1
thumbnail_url http://t1.ftcdn.net/jpg/00/18/58/02/110_F_18580260_OnPeYDbxlCPbOO4Nn2QWVvfoiOdevFj9.jpg
thumbnail_width 110
thumbnail_height 110
thumbnail_html_tag Young dancing woman
id 9933855
ex_affiliate_url_creator http://jp.fotolia.com/p/17174/partner/201417048
ex_affiliate_url_media http://jp.fotolia.com/id/9933855/partner/201417048
title Young woman sitting on floor with a laptop
creator_name Yuri Arcurs
creator_id 17174
creation_date 2008-10-16 09:36:59.580849
media_type_id 1
thumbnail_url http://t1.ftcdn.net/jpg/00/09/93/38/110_F_9933855_MgAZrblBZCeFLPkbTueQLZkgSViTNPJZ.jpg
thumbnail_width 93
thumbnail_height 110
thumbnail_html_tag Young woman sitting on floor with a laptop
error 1
error_title Missing Media ID
error_comment The media ID is missing. Media ID is required for this method.

render(String $type, String|Array $ids, $search_options = null, $standard_options = null)

画像の取得とHTML加工。Fotolia/tpl/standard/以下のテンプレートファイルが使用されます。

$type
./tpl/$type/以下のテンプレートが使用されます。standard | gallery | debug

$type = 'standard'

CQT_Fotolia_API::render()
  1.  
  2.  <?php
  3.  echo $fotolia->render('standard', '18580260,10458789');
  4.  ?>
実行結果
Young dancing woman

Young dancing woman

  • George Mayer
Portrait of a woman

Portrait of a woman

  • ant236

$type = 'gallery'

カルーセル形式で出力します。利用するページでjQuery、同梱のfotolia.cssとfotolia.jsを読み込んでください。 殴り書きなので、ブラウザによっては変になります。 愛用のライブラリなどあればそちらを利用したほうが良いです。

CQT_Fotolia_API::getItems()
  1.  
  2.  <?php
  3.  $fotolia->setMediaSize('L');
  4.  $fotolia->gallery('18580260,3792814,5668968,8889955,19268622,5689214,10674034,10458789');
  5.  ?>
実行結果
Young dancing woman

Creator : George Mayer

More...

Slim attractive blond model in black lingerie

Creator : Martin Valigursky

More...

picture of healthy naked woman over white

Creator : Lev Dolgatsjov

More...

Portrait of charming dancing girl

Creator : George Mayer

More...

Portrait of a beautiful young woman.

Creator : T.Tulic

More...

Profile of creativity hairstyle and fashion make-up

Creator : Valua Vitaly

More...

Portrait of a woman

Creator : ant236

More...

$type = 'debug'

CQT_Fotolia_API::getItems()
  1.  
  2.  <?php
  3.  echo $fotolia->render('debug', '18580260,3792814,test');
  4.  ?>
実行結果
key value
id18580260
titleYoung dancing woman
creator_nameGeorge Mayer
creator_id117924
creation_date2009-11-21 16:34:03.399564
media_type_id1
thumbnail_urlhttp://t1.ftcdn.net/jpg/00/18/58/02/400_F_18580260_OnPeYDbxlCPbOO4Nn2QWVvfoiOdevFj9.jpg
thumbnail_width400
thumbnail_height400
thumbnail_html_tagYoung dancing woman
baseurl_homehttp://jp.fotolia.com/
baseurl_creatorhttp://jp.fotolia.com/p/
baseurl_mediahttp://jp.fotolia.com/id/
affiliate_pathpartner
affiliate_url_homehttp://jp.fotolia.com/partner/201417048
affiliate_url_creatorhttp://jp.fotolia.com/p/117924/partner/201417048
affiliate_url_mediahttp://jp.fotolia.com/id/18580260/partner/201417048
id10458789
titlePortrait of a woman
creator_nameant236
creator_id200702983
creation_date2008-11-15 23:01:50.883379
media_type_id1
thumbnail_urlhttp://t2.ftcdn.net/jpg/00/10/45/87/400_F_10458789_oPuVz9yrOhfSI1bBxdTBjpu0civDskuX.jpg
thumbnail_width267
thumbnail_height400
thumbnail_html_tagPortrait of a woman
baseurl_homehttp://jp.fotolia.com/
baseurl_creatorhttp://jp.fotolia.com/p/
baseurl_mediahttp://jp.fotolia.com/id/
affiliate_pathpartner
affiliate_url_homehttp://jp.fotolia.com/partner/201417048
affiliate_url_creatorhttp://jp.fotolia.com/p/200702983/partner/201417048
affiliate_url_mediahttp://jp.fotolia.com/id/10458789/partner/201417048

setImageSize(String $size = 'M')

画像サイズの変更。()でS、M、Lまたは30、110、400を指定する。デフォルトはM

$size
S|M|L|30|110|400
CQT_Fotolia_API::getItems()
  1.  
  2.  <?php
  3.  $fotolia->setImageSize('S');
  4.  $fotolia->render('standard', '18580260');
  5.  
  6.  $fotolia->setImageSize('M');
  7.  $fotolia->render('standard', '18580260');
  8.  
  9.  $fotolia->setImageSize('L');
  10.  $fotolia->render('standard', '18580260');
  11.  ?>
実行結果
Young dancing woman

Young dancing woman

  • George Mayer
Young dancing woman

Young dancing woman

  • George Mayer
Young dancing woman

Young dancing woman

  • George Mayer

HMTLの出力を変更

lib/standard | gallery | debug/以下が出力されるHTMLのテンプレートになります。element.htmlがlayout.htmlで囲まれる感じです。

layout.html

element.html

element.html

element.html

error.htmlは現在利用できません。

プログラムから渡されるデータは下記で参照できます。

key value
id18580260
titleYoung dancing woman
creator_nameGeorge Mayer
creator_id117924
creation_date2009-11-21 16:34:03.399564
media_type_id1
thumbnail_urlhttp://t1.ftcdn.net/jpg/00/18/58/02/400_F_18580260_OnPeYDbxlCPbOO4Nn2QWVvfoiOdevFj9.jpg
thumbnail_width400
thumbnail_height400
thumbnail_html_tagYoung dancing woman
baseurl_homehttp://jp.fotolia.com/
baseurl_creatorhttp://jp.fotolia.com/p/
baseurl_mediahttp://jp.fotolia.com/id/
affiliate_pathpartner
affiliate_url_homehttp://jp.fotolia.com/partner/201417048
affiliate_url_creatorhttp://jp.fotolia.com/p/117924/partner/201417048
affiliate_url_mediahttp://jp.fotolia.com/id/18580260/partner/201417048
メディアID{{{ id }}}
画像のタイトル{{{ title }}}
作者名{{{ creator_name }}}
作者ID{{{ creator_id }}}
作成日{{{ creation_date }}}
メディアID{{{ media_type_id }}}
画像のURL{{{ thumbnail_url }}}
画像の横幅{{{ thumbnail_width }}}
画像の縦{{{ thumbnail_height }}}
imgタグ{{{ thumbnail_html_tag }}}
fotoliaのHOMEのURL{{{ baseurl_home }}}
作者ページへのURL{{{ baseurl_creator }}}
写真(メディア)ページのURL{{{ baseurl_media }}}
affiliate_path{{{ affiliate_path }}}
fotoliaのHOMEのアフィリエイトURL{{{ affiliate_url_home }}}
作者ページのアフィリエイトURL{{{ affiliate_url_creator }}}
写真(メディア)ページのアフィリエイトURL{{{ affiliate_url_media }}}

useCache($type = 'File', $lifetime = null, $path = null)

結果をキャッシュします。けっこう重いのでこれを利用しないと使いものになりません。