SlideShare a Scribd company logo
1 of 14
Download to read offline
簡単な TYPO3 エクステンションの作成
                                                          Extension Key: player_profile_basic
                                        Copyright 2000-2002, Oliver Hofmann, <marketing@viv-it.de>


                                         This document is published under the Open Content License
                                                available from http://www.opencontent.org/opl.shtml


                                                 The content of this document is related to TYPO3
                                        - a GNU/GPL CMS/Framework available from www.typo3.com


                        翻訳: コトトイ・ファクトリー株式会社 (http://kototoy.jp/) 藤田 拓 < taku.fujita@kototoy.jp >



目次
簡単な TYPO3 エクステンションの作成.......1                                                             フロントエンド表示のための準備..............................5

 はじめに........................................................................... 2        エクステンションの拡張(Last name フィールドを追
                                                                                          加).............................................................................9
     何を作る?.................................................................. 2
                                                                                          このエクステンションを拡張する際の留意点..........10
 チュートリアル................................................................ 2
                                                                                          TypoScript によるエクステンション対応................. 10
     Kickstarter ウィザード................................................ 2
                                                                                          エクステンション - 本サンプルをさらに拡張したもの
     Frontend plugin........................................................... 4         (コードのみ)......................................................... 11
     Static TypoScript code................................................ 4        既知の問題..................................................................... 13
     エクステンションの保存............................................ 4                       To-Do list........................................................................ 13
     エクステンションのインストール..............................5                                  Changelog...................................................................... 13
     選手のデータを作成する............................................ 5




                                                                                                                 簡単な TYPO3 エクステンションの作成 - 1
はじめに
このチュートリアルは初心者向けです。初心者じゃない人たちもこのチュートリアルをベースに、より発展的な理解を得ることができるで
しょう。このチュートリアルを読めば、初心者もそうじゃない人も TYPO3 の理解を一歩進めることができると思います。そして、TYPO3 を
もっと使いこんで見てください!TYPO3 コミュニティの栄光はあなたのものとなりえます :-)


もしこのチュートリアルに間違いやおかしい部分があったら直接メールを送っていただくか、注釈をおねがいします。typo3.org のユー
ザーに登録してログインしていただくと直接注釈ができます。



何を作る?
このチュートリアルでは「フロントエンド画面に画像とテキストフィールドを表示する」簡単なエクステンションを作成します。そして、それら
を作った後、さらにもう1つテキストフィールドを追加しフロントエンドで表示する拡張を行います。ここでは PHP コードと TypoScript を利
用してこのエクステンションを作成します。


チュートリアル
このチュートリアルではフロントエンドにコンテンツを表示する簡単なエクステンションの作り方を紹介しています。あくまでエクステンショ
ン Kickstarter の使い方とフロントエンドでの表示のやり方をお見せしているだけで、初歩中の初歩とお考えください。そして、この初歩
を手始めに今後のアイディアを拡げていただければ幸いです。
シナリオとしては、
    TYPO3 を利用しているサッカークラブが選手のプロフィールを管理できるようにしたい
という要件に対応するエクステンションを開発する流れです。プロフィールには選手の写真と名前、そしてさらに詳しい情報を付与するた
めのフィールドも求められています。

Kickstarter ウィザード
Kickstarter ウィザードを利用すればエクステンションがとても簡単に作成できます。
まずはバックエンド管理画面にログインし、ツールモジュールの Extension Manager をクリックしてください。そして、ドロップダウンメ
ニューから「Make new extension」を選択した後、extension key として適当な名前を入力してください。今回は「player_profile」という
名前にします。
では、はじめてみましょう。
•   エクステンションについての属性情報を入力します。
    General info
    Title(Player Profile)、Description(Display profile of soccer player )、Category(Frontend
    Plugins)、State(alpha)、Dependencies(cms)、Author Name(あなたの名前)、Author email(あなたの E メールアドレス)




•   新しいデータベーステーブルを作成します。といっても、管理画面の設定を行えば作成できます。
    New Database Tables
    Tablename: tx_playerprofile_list
    Title of the table: Display player profile、 Add 'Deleted' field:   、 Add 'Hidden' flag:    、 Add 'Access group'   、 Manual
    ordering of records:

    Allowed on pages:
    Allowed in 'Insert Records' field in content elements:
    Add 'Save and new' button in forms:



                                                                                              簡単な TYPO3 エクステンションの作成 - 2
•   言語の設定
    Setup languages
    第二言語も含めてエクステンションを作成するため、本ケースでは German にチェックをいれます。その後、各 German のフィール
    ドにドイツ語の翻訳を入力することが可能です。




•   画像を扱う image フィールドを作成
    NEW FIELD: image
    Field name や Field tile、Field type、Is Exclude-field を入力して update を押します。 and そして、Max number of files(今回は
    1)や Max filesize allowed(今回は 1000kb)、Size of selector box(今回は 1)、Show thumbnails 等の画像ファイルのプロパティ
    を決めていきます。




•   名前を入力する first_name フィールドを作成
    FIELD: first_name
    Enter field name (今回は first_name)、 field title (今回は First name)、 field type (今回は string input)、 Is Exclude-field を入
    力して update を押します。 and その後、Field width (今回は 30)、 Max characters (今回は 50)、 Required 、 Create
    VARCHAR, not TINYTEXT field 等のプロパティを決めていきます。




                                                                                   簡単な TYPO3 エクステンションの作成 - 3
Frontend plugin
フロントエンドで利用できるエクステンションとして登録するため、Frontend plugin                     をクリックします。プラグインの英語のタイトルとして
Player profile、 ドイツ語のタイトルとして Spielerprofil を入力します。 'Insert Plugin' list in Content Elements のラジオボタンはそのま
まにしておきます。その他は今回はそのままにしておきます。




Static TypoScript code
あとで画像の幅と高さを設定するためにちょっとしたコードを追加します。なので、Static TypoScript code の Setup フィールドにいくつ
かのダミーテキスト(ここでは#Constants)を入力しておきましょう。



エクステンションの保存
•   まず、View result をクリックします。
•   ページが再度読み込まれたら、ドロップダウンメニューの Write to location から Local を選択してダイアログボックスの OK を押して
    ください。
•   ページが再読み込みされ、the Extension got copied successfully to the server といったメッセージが表示されます。




                                                                       簡単な TYPO3 エクステンションの作成 - 4
エクステンションのインストール
•   これで Kickstarter での操作はひと通り終わりました。エクステンション Player Profile をインストールすることが可能です。
•   Make updates をクリックして、完了です。




選手のデータを作成する
•   ページツリーを開いて、Our Players                という新規ページを作成しましょう。このページは選手のプロフィールを表示
    します。
•   新規ページコンテンツ要素(例えば regular text element.)を作成しましょう。例)
•   タイプを insert plugin.に変更します。
•   ドロップダウンメニューから Player profile を選択し保存します。
•   Our players のページアイコンをクリックして 新規データを作成します。
•   Display player profile を選択します。
•   それから選手のデータを入力します。たとえば First name には Franz を入力し、画像をアップします。
•   保存します。



フロントエンド表示のための準備
Kickstarter での操作はひと通りおえましたが、フロントエンドには何も表示されないでしょう。選手のデータを表示させるには数行のコー
ドを書く必要があります。
•   Kickstarter が出力したファイルを編集するため、まずは Extension Manager を開きます。そして、 Player Profile extension
               を探しましょう。
•   Extension Manager で右上のドロップダウンメニューから Edit files を選択しましょう。
•   Player Profile のフロントエンド表示を変更するために pi1/class.tx_playerprofile_p1.php を編集します。今回は下記のコードをコ
    ピー&ペーストすることもできます。コードをみると「Last name」用の記述がコメントアウトされていることに気づくでしょう。この部分は
    あとでこのエクステンションを拡張して Last name 用のフィールドを作るためのものです。ですが、今は無視してください。
•   特定の幅と高さの画像のポップアップを表示するために ext_typoscript_setup.txt というファイルを編集します。このコードも下記に
    用意してあるのでコピー&ペーストしてもよいです。
•   保存してください。




                                                                  簡単な TYPO3 エクステンションの作成 - 5
pi1/class.tx_playerprofile_pi1.php

コードとコメント

<?php
/***************************************************************
* Copyright notice
*
* (c) 2003 Oliver Hofmann (marketing@viv-it.de)
* All rights reserved
*
* This script is part of the Typo3 project. The Typo3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
  * Plugin 'Player profile' for the 'player_profile' extension.
  *
  * @author Oliver Hofmann <marketing@viv-it.de>, Michael Dengler <info@diacc.de>, Andreas Schwarzkopf
<info@meinsystem.de>
  */


require_once(PATH_tslib."class.tslib_pibase.php");

class tx_playerprofile_pi1 extends tslib_pibase {
      var $prefixId = "tx_playerprofile_pi1";                    // Same as class name – no _ allowed
      var $scriptRelPath = "pi1/class.tx_playerprofile_pi1.php"; // Path to this script relative to the
extension dir.
      var $extKey = "player_profile";                            // The extension key.
      var $conf;

     /**
      * [Output for image, first name and last name]
      */
     function main($content,$conf)     {
                                     $this->conf = $conf;
                                     $content="";

                     $rows=$this->getItems();
                     while(list($c,$row)=each($rows))             {
             $this->conf["image."]["file"] = "uploads/tx_playerprofile/".($row["image"]); //The image
field name
             $theImgCode=$this->cObj->IMAGE($this->conf["image."]);
                                         $content.=$theImgCode."<br>";
                                         $content.=($row["first_name"])."&nbsp;";    //This outputs the
first name
                                        // $content.=($row["last_name"])."<br><br>"; //This is the
additional field

                                        //next, the output displayed in a table
                                            $content.="<table border=1><tr><td>".
($row["first_name"])."</td></tr>";
                                           $content.="<tr><td>".($row["last_name"])."</td></tr></table>";


                     }

#t3lib_div::debug($conf);
#t3lib_div::debug($this->getItems());

                     return $content;
     }



                                                                            簡単な TYPO3 エクステンションの作成 - 6
/**
          * function.
          */
         function getItems() {

                        // pid_list is the pid/list of pids from where to fetch the guest items.
            $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this-
>conf["pid_list."]));
            $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",
$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
            list($pid) = explode(",",$config["pid_list"]);

                 $query = "SELECT * FROM tx_playerprofile_list WHERE pid IN (".$pid.") ORDER BY sorting";
                 $res = mysql(TYPO3_db,$query);
                 $out=array();
                 while($row = mysql_fetch_assoc($res))  {
                       $out[]=$row;
                 }
                 return $out;
         }

}

if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]
["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"])       {
      include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]
["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"]);
}

?>


ext_typoscript_setup.txt

詳細を知りたい場合は TypoScript リファレンスの 49 ページを参照してください。
plugin.tx_playerprofile_pi1 {
image {
     file.maxW = {$plugin.player_profile.maxW_single}
     imageLinkWrap = {$plugin.player_profile.clickEnlarge}
     imageLinkWrap {
        enable = 1
        bodyTag = <BODY bgColor=white>
        wrap = <A href="javascript:close();"> | </A>
        width = 400m
        height = 400

             JSwindow = 1
             JSwindow.newWindow = 1
             JSwindow.expand = 17,20
         }
     }
}


ext_typoscript_constants.txt

ここでサムネイル画像の大きさを 70 ピクセルに指定します。
file.maxW = {$plugin.player_profile.maxW_single} = 70




                                                                            簡単な TYPO3 エクステンションの作成 - 7
pi1/class.tx_playerprofilebasic_pi1.php

player_profile_basic エクステンションのサンプルコード

typoscript_setup.txt と typoscript.constants.txt は適宜変更してください。


<?php
/***************************************************************
* Copyright notice
*
* (c) 2003 Oliver Hofmann (marketing@viv-it.de)
* All rights reserved
*
* This script is part of the Typo3 project. The Typo3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
  * Plugin 'Player profile' for the 'player_profile_basic' extension.
  *
  * @author Oliver Hofmann <marketing@viv-it.de>, Michael Dengler <info@diacc.de>, Andreas Schwarzkopf
<info@meinsystem.de>
  */

require_once(PATH_tslib."class.tslib_pibase.php");

class tx_playerprofilebasic_pi1 extends tslib_pibase {
      var $prefixId = "tx_playerprofilebasic_pi1";               // Same as class name – no _ allowed
      var $scriptRelPath = "pi1/class.tx_playerprofilebasic_pi1.php";         // Path to this script
relative to the extension dir.
      var $extKey = "player_profile";                            // The extension key.
      var $conf;

      /**
        * [Output for image, first name and last name]
        */
      function main($content,$conf)      {
                                       $this->conf = $conf;
                                       $content="";
                     $rows=$this->getItems();
                     while(list($c,$row)=each($rows))              {
             $this->conf["image."]["file"] = "uploads/tx_playerprofilebasic/".($row["image"]); //The
image field name
             $theImgCode=$this->cObj->IMAGE($this->conf["image."]);
                                          $content.=$theImgCode."<br>";
                                          $content.=($row["first_name"])."&nbsp;"; //This outputs the
first name
                                      // $content.=($row["last_name"])."<br><br>"; //This is the
additional field
                                      //next, the output displayed in a table
                                          $content.="<table border=1><tr><td>".
($row["first_name"])."</td></tr>";
                                          $content.="<tr><td>".($row["last_name"])."</td></tr></table>";
                     }
#t3lib_div::debug($conf);
#t3lib_div::debug($this->getItems());
                     return $content;
      }
      /**
        * function.
        */
      function getItems() {


                                                                         簡単な TYPO3 エクステンションの作成 - 8
// pid_list is the pid/list of pids from where to fetch the guest items.
            $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this-
>conf["pid_list."]));
            $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",
$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
            list($pid) = explode(",",$config["pid_list"]);

            $query = "SELECT * FROM   tx_playerprofilebasic_list WHERE pid IN (".$pid.") ORDER BY
sorting";
            $res = mysql(TYPO3_db,$query);
            $out=array();
            while($row = mysql_fetch_assoc($res))    {
                  $out[]=$row;
            }
            return $out;
     }
}

if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]
["ext/player_profile_basic/pi1/class.tx_playerprofilebasic_pi1.php"])          {
      include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]
["ext/player_profile_basic/pi1/class.tx_playerprofilebasic_pi1.php"]);
}

?>




                                                                         簡単な TYPO3 エクステンションの作成 - 9
エクステンションの拡張(Last name フィールドを追加)
選手の First name と画像だけではなく Last Name も入力できるように拡張してみましょう。これまでは Kickstarter をひと通り操作し、フ
ロントエンド表示のためのファイルも編集してきました。Last name フィールドを追加するには class ファイルを編集しなくてはなりません。
•   まず、Extension Manager を開き、Player Profile                  を探します。そして、KickStarter で作成された現在のファイルを
    編集します。
•   右上のドロップダウンメニューから Backup/Delete を選択し、 start new.                     をクリックします。
•   Last name フィールドをデータベースのテーブルに追加するために Display player profile をクリックします。
•   新しいフィールド名として Last_name を追加し field title (Last name)、 field type (string input)、 Is Exclude-field を入力、そして、
    Field width (30)、 Max characters (50)、 Required   、 Create VARCHAR、 not TINYTEXT field といったプロパティを設定し
    ます。
•   注意! update ボタンをクリックしたら Extension Manager は既存の設定を上書きします。pi1/class.tx_playerprofile_pi1.php や
    ext_typoscript_setup.txt はあらかじめ別途保存しておいてください。
•   Update します。
•   View result が表示されます。
•   Extension Manager を開き、Player Profile のドロップダウンメニューから edit files を選択します。
•   the pi1/class.tx_playerprofile_pi1.php を開き、すでにこのファイルにコメントアウトして記述されている Last name フィールド用の1
    下記行のコメントアウトを外します。
•   $content.=$row["last_name"].";



エクステンションを拡張する際の留意点
もしこのサンプルコードをベースに独自のエクステンションを作ろうとする場合は、Kickstarter を利用しつつ、このチュートリアルの内容に
沿ってファイルを編集していってください。また、player_profile_basic と名付けられエクステンションの class ファイルでは playerprofile と書
かれています。エクステンション名に含まれるアンダースコアは消されています。例えば、my_gallery と命名したエクステンションを新しく
作ると、class ファイル内では mygallery と記載されます。




                                                                           簡単な TYPO3 エクステンションの作成 - 10
TypoScript によるエクステンション対応
PHP クラスを使わず、TypoScript を使うこともできます。例えば、フロントエンド表示をコントロールするために template setup フィールドに
TypoScript を記述して対応することも可能です。この例では機能的にちょっとだけ違うものを用意しました。まず、選手の画像と Last
name が表示され、選手をクリックすると詳細情報が表示されます。


page.10.subparts.CONTENT >                                              // overwrites statements in the
root template
page.10.subparts.CONTENT = CONTENT
page.10.subparts.CONTENT {
        table = tx_playerprofile_2_listextended                            // takes the table created with
the kickstarter
        select.pidInList = this                                                      // the current pid
where the plugin is installed – could be also an uid
        wrap = <table>|<tr><td><a href="javascript:history.back()">back to
list</a><td></tr></table>       // link back to player overview list
        renderObj = COA
        renderObj.10 = IMAGE                                                     // definitions for the
image start here
        renderObj.10.file.import = uploads/tx_playerprofile_2/      // the upload folder for the images
        renderObj.10.file.import.field = image                              // defines that the image field
should be taken
        renderObj.10.file.import.listNum = 0
        renderObj.10.stdWrap.typolink.parameter.data = TSFE:id
        renderObj.10.stdWrap.typolink.additionalParams.dataWrap = &playeruid={field:uid}
        renderObj.10.stdWrap.wrap = <tr><td>|</td></tr>          // image put in first table row
        renderObj.10.stdWrap.typolink.no_cache = 1

        renderObj.20 = TEXT
        renderObj.20.field = first_name
        renderObj.20.wrap = <tr><td>|</td></tr>                        // first name field displayed in
second table row

        renderObj.30 = TEXT
        renderObj.30.field = last_name
        renderObj.30.wrap = <tr><td>|</td></tr>                        // last name field displayed in
third table row

}


// Start of conditions for the above typoscript code, similar to if / else statement

[globalVar = GP:playeruid > 0]

page.10.subparts.CONTENT.select.where = 1=1
page.10.subparts.CONTENT.select.andWhere.dataWrap = uid={GPvar:playeruid}

[else]

page.10.subparts.CONTENT.wrap = <table>|</table>
# page.10.subparts.CONTENT.renderObj.20 >              // the first name will be shown on the overview
list because here it is commented out
page.10.subparts.CONTENT.renderObj.30 >                 // the last name is taken out from being
displayed

[global]

// Conditions end here




                                                                         簡単な TYPO3 エクステンションの作成 - 11
エクステンション - 本サンプルをさらに拡張したもの(コードのみ)
下記ポイントに留意して今までの基本バージョンを拡張したコードです。
•   一覧表示と個別表示の対応
<?php
/***************************************************************
* Copyright notice
*
* (c) 2003 Oliver Hofmann (marketing@viv-it.de)
* All rights reserved
*
* This script is part of the Typo3 project. The Typo3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
  * Plugin 'Player profile' for the 'player_profile' extension.
  *
  * @author Oliver Hofmann <marketing@viv-it.de>, Michael Dengler <info@diacc.de>, Andreas Schwarzkopf
<info@meinsystem.de>
  */

require_once(PATH_tslib."class.tslib_pibase.php");

class tx_playerprofile_pi1 extends tslib_pibase {
      var $prefixId = "tx_playerprofile_pi1";                    // Same as class name
      var $scriptRelPath = "pi1/class.tx_playerprofile_pi1.php"; // Path to this script relative to the
extension dir.
      var $extKey = "player_profile";                            // The extension key.
      var $conf;

     /**
      * [Put your description here]
      */
     function main($content,$conf)      {
                                      $this->conf = $conf;
                                      $content="";

                                      $GLOBALS["TSFE"]->set_no_cache();

                   if(t3lib_div::GPvar("player"))    {

                                       $row = $this->getSingle(t3lib_div::GPvar("player"));
           $this->conf["image."]["file"] = "uploads/tx_playerprofile/".$row["image"];
           $theImgCode=$this->cObj->IMAGE($this->conf["image."]);

                                        $content.="<table border=0><tr><td></td><td>".
$theImgCode."</td></tr>";
                                        $content.="<tr><td>Name:</td><td>".$row["last_name"]."&nbsp;".
$row["first_name"]."</td></tr>";
                                        $content.="<tr><td>Year:</td><td>".$row["year"]."</td></tr>";
                                        $content.="<tr><td valign=top>Nationality:</td><td>".
$row["nationality"]."</td></tr>";
                                        $content.="<tr><td>Position:</td><td>".
$row["position"]."</td></tr>";
                                        $content.="<tr><td valign=top>Former
clubs:</td><td>".nl2br($row["club"])."</td></tr>";
                                        $content.="<tr><td>Favorite clubs:</td><td>".
$row["favorite_club"]."</td></tr>";

                                        $content.="<tr><td valign=top>Hobbies:</td><td>".
$row["hobbies"]."</td></tr>";
                                        $content.="<tr><td valign=top> Favorite meal:</td><td>".


                                                                          簡単な TYPO3 エクステンションの作成 - 12
$row["food"]."</td></tr>";
                                            $content.="<tr><td valign=top>Music:</td><td>".
$row["music"]."</td></tr>";
                                            $content.="<tr><td valign=top>Profession/studies:</td><td>".
$row["profession"]."</td></tr>";
                                            $content.="<tr><td valign=top>Message to the fans:</td><td>".
$row["message"]."</td></tr>";
                                        $content.="<tr><td colspan=2><a href=index.php?id=".
$GLOBALS["TSFE"]->id.">back</a></td></tr></table>";

                    }
                                        else {

                       $rows=$this->getItems();
                       while(list($c,$row)=each($rows))          {
                 $this->conf["image."]["file"] = "uploads/tx_playerprofile/".$row["image"];
                 $theImgCode=$this->cObj->IMAGE($this->conf["image."]);

                                                  $content.="<table border=0><tr><td></td><td>".
$theImgCode."</td></tr>";
                                              $content.="<tr><td>Details -->:</td><td align=center><a
href=index.php?id=".$GLOBALS["TSFE"]->id."&player=".$row["uid"].">".
$row["last_name"]."</a></td></tr></table>";

                                        }
                }

#t3lib_div::debug($conf);
#t3lib_div::debug($this->getItems());

                    return $content;
      }

      /**
       * function.
       */
      function getItems() {

                        // pid_list is the pid/list of pids from where to fetch the guest items.
            $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this-
>conf["pid_list."]));
            $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",
$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
            list($pid) = explode(",",$config["pid_list"]);

           $query = "SELECT * FROM tx_playerprofile_list WHERE pid IN (".$pid.") ORDER BY sorting";
           $res = mysql(TYPO3_db,$query);
           $out=array();
           while($row = mysql_fetch_assoc($res))  {
                 $out[]=$row;
           }
           return $out;
      }
      /**
        * function.
        */
      function getSingle($uid)          {
                         // pid_list is the pid/list of pids from where to fetch the guest items.
             $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this-
>conf["pid_list."]));
             $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",
$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
             list($pid) = explode(",",$config["pid_list"]);

            $query = "SELECT * FROM tx_playerprofile_list WHERE pid IN (".$pid.") AND uid = ".$uid."
ORDER BY sorting";
            $res = mysql(TYPO3_db,$query);
            $row = array();
            $row = mysql_fetch_assoc($res);
            return $row;
      }
}
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]
["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"])       {
      include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]
["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"]);
}
?>


                                                                           簡単な TYPO3 エクステンションの作成 - 13
既知の問題
•   今のところ確認されている問題はありません。何か問題があればご連絡ください!


To-Do list
•   Extending the basic and extended version of the extension with other basic functions (commented in detail).
•   List view and single view settings of basic extension should be made modifiable through TypoScript in the setup field .
•   View of images currently vertically shown in list view should be positioned also e.g. three in a row or more...
•   Through TypoScript in the setup field, the database table fields shown on the frontend, should be managable.


Changelog
•   03-26-2003 - document first published, created on Typo3 Snowboard Tour in Splügen/Swizerland. Thanks to Michael
    Dengler (diacc.de) and Andreas Schwarzkopf (meinsystem.de) for there great efforts to this extension!
•   03-27-2003 – cleaned up setup.txt and constants.txt as well as php class file of player_profile_pi1.php according to the
    tutorial example. Added the php class code for the extension player_profile_basic to show how the code needs to be
    changed.




                                                                                         簡単な TYPO3 エクステンションの作成 - 14

More Related Content

Similar to 簡単なTYPO3エクステンションの作成

Geopaparazzi & OSMフィールド調査ハンズオン
Geopaparazzi & OSMフィールド調査ハンズオンGeopaparazzi & OSMフィールド調査ハンズオン
Geopaparazzi & OSMフィールド調査ハンズオン
arctic_tern265
 
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
Jumpei Ogawa
 
KEONとPEAKが無くてもFirefox OS開発出来る
KEONとPEAKが無くてもFirefox OS開発出来るKEONとPEAKが無くてもFirefox OS開発出来る
KEONとPEAKが無くてもFirefox OS開発出来る
android sola
 
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組みモバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
MorioImai
 
Linux+PHPを学んで日程調整アプリを作ろう①
Linux+PHPを学んで日程調整アプリを作ろう①Linux+PHPを学んで日程調整アプリを作ろう①
Linux+PHPを学んで日程調整アプリを作ろう①
Aina Hara
 
CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2
CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2
CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2
Computational Materials Science Initiative
 

Similar to 簡単なTYPO3エクステンションの作成 (20)

.NET Gadgeteer のハンズオン資料 (2014年3月版)
.NET Gadgeteer のハンズオン資料 (2014年3月版).NET Gadgeteer のハンズオン資料 (2014年3月版)
.NET Gadgeteer のハンズオン資料 (2014年3月版)
 
Geopaparazzi & OSMフィールド調査ハンズオン
Geopaparazzi & OSMフィールド調査ハンズオンGeopaparazzi & OSMフィールド調査ハンズオン
Geopaparazzi & OSMフィールド調査ハンズオン
 
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会
 
Stagefright入門
Stagefright入門Stagefright入門
Stagefright入門
 
KEONとPEAKが無くてもFirefox OS開発出来る
KEONとPEAKが無くてもFirefox OS開発出来るKEONとPEAKが無くてもFirefox OS開発出来る
KEONとPEAKが無くてもFirefox OS開発出来る
 
Bluemixモバイルのテンプレートを用いたチャットボットアプリ動作確認手順の紹介
Bluemixモバイルのテンプレートを用いたチャットボットアプリ動作確認手順の紹介Bluemixモバイルのテンプレートを用いたチャットボットアプリ動作確認手順の紹介
Bluemixモバイルのテンプレートを用いたチャットボットアプリ動作確認手順の紹介
 
最低限の開発環境を整えるには
最低限の開発環境を整えるには最低限の開発環境を整えるには
最低限の開発環境を整えるには
 
Grafana Dashboards as Code
Grafana Dashboards as CodeGrafana Dashboards as Code
Grafana Dashboards as Code
 
Instalaciones de servidores ejemplo
Instalaciones de servidores ejemploInstalaciones de servidores ejemplo
Instalaciones de servidores ejemplo
 
20120118 titanium
20120118 titanium20120118 titanium
20120118 titanium
 
ワンストップ技術書を書こう おためし版
ワンストップ技術書を書こう おためし版ワンストップ技術書を書こう おためし版
ワンストップ技術書を書こう おためし版
 
Build 番号の自動更新スクリプトについて #cocoa_kansai
Build 番号の自動更新スクリプトについて #cocoa_kansaiBuild 番号の自動更新スクリプトについて #cocoa_kansai
Build 番号の自動更新スクリプトについて #cocoa_kansai
 
Firefox DevTools
Firefox DevToolsFirefox DevTools
Firefox DevTools
 
OpenCV2.2 Install Guide ver.0.5
OpenCV2.2 Install Guide ver.0.5OpenCV2.2 Install Guide ver.0.5
OpenCV2.2 Install Guide ver.0.5
 
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組みモバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
 
TIBCO Spotfire Desktop チュートリアル6.5
TIBCO Spotfire Desktop チュートリアル6.5 TIBCO Spotfire Desktop チュートリアル6.5
TIBCO Spotfire Desktop チュートリアル6.5
 
Linux+PHPを学んで日程調整アプリを作ろう①
Linux+PHPを学んで日程調整アプリを作ろう①Linux+PHPを学んで日程調整アプリを作ろう①
Linux+PHPを学んで日程調整アプリを作ろう①
 
CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2
CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2
CMSI計算科学技術特論B(15) インテル Xeon Phi コプロセッサー向け最適化、並列化概要 2
 
Install guide ja_jp
Install guide ja_jpInstall guide ja_jp
Install guide ja_jp
 
eZ Publishのextension開発チュートリアル
eZ Publishのextension開発チュートリアルeZ Publishのextension開発チュートリアル
eZ Publishのextension開発チュートリアル
 

More from 株式会社ミツエーリンクス

More from 株式会社ミツエーリンクス (6)

イマドキのCMSトレンドからWeb運用を再考する
イマドキのCMSトレンドからWeb運用を再考するイマドキのCMSトレンドからWeb運用を再考する
イマドキのCMSトレンドからWeb運用を再考する
 
これからのCMSマーケットトレンドとPHP (for fukuoka.php)
これからのCMSマーケットトレンドとPHP (for fukuoka.php)これからのCMSマーケットトレンドとPHP (for fukuoka.php)
これからのCMSマーケットトレンドとPHP (for fukuoka.php)
 
イマドキなCMS案件のステークホルダー + 私の考えるCMS
イマドキなCMS案件のステークホルダー + 私の考えるCMSイマドキなCMS案件のステークホルダー + 私の考えるCMS
イマドキなCMS案件のステークホルダー + 私の考えるCMS
 
Elggで作るソーシャルメディアWeb
Elggで作るソーシャルメディアWebElggで作るソーシャルメディアWeb
Elggで作るソーシャルメディアWeb
 
eZ Publish 実装 はじめの一歩
eZ Publish 実装 はじめの一歩eZ Publish 実装 はじめの一歩
eZ Publish 実装 はじめの一歩
 
eZ Publish ディスクール (デモ付き)@OSC 2009 Tokyo
eZ Publish ディスクール (デモ付き)@OSC 2009 TokyoeZ Publish ディスクール (デモ付き)@OSC 2009 Tokyo
eZ Publish ディスクール (デモ付き)@OSC 2009 Tokyo
 

Recently uploaded

Recently uploaded (12)

論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 

簡単なTYPO3エクステンションの作成

  • 1. 簡単な TYPO3 エクステンションの作成 Extension Key: player_profile_basic Copyright 2000-2002, Oliver Hofmann, <marketing@viv-it.de> This document is published under the Open Content License available from http://www.opencontent.org/opl.shtml The content of this document is related to TYPO3 - a GNU/GPL CMS/Framework available from www.typo3.com 翻訳: コトトイ・ファクトリー株式会社 (http://kototoy.jp/) 藤田 拓 < taku.fujita@kototoy.jp > 目次 簡単な TYPO3 エクステンションの作成.......1 フロントエンド表示のための準備..............................5 はじめに........................................................................... 2 エクステンションの拡張(Last name フィールドを追 加).............................................................................9 何を作る?.................................................................. 2 このエクステンションを拡張する際の留意点..........10 チュートリアル................................................................ 2 TypoScript によるエクステンション対応................. 10 Kickstarter ウィザード................................................ 2 エクステンション - 本サンプルをさらに拡張したもの Frontend plugin........................................................... 4 (コードのみ)......................................................... 11 Static TypoScript code................................................ 4 既知の問題..................................................................... 13 エクステンションの保存............................................ 4 To-Do list........................................................................ 13 エクステンションのインストール..............................5 Changelog...................................................................... 13 選手のデータを作成する............................................ 5 簡単な TYPO3 エクステンションの作成 - 1
  • 2. はじめに このチュートリアルは初心者向けです。初心者じゃない人たちもこのチュートリアルをベースに、より発展的な理解を得ることができるで しょう。このチュートリアルを読めば、初心者もそうじゃない人も TYPO3 の理解を一歩進めることができると思います。そして、TYPO3 を もっと使いこんで見てください!TYPO3 コミュニティの栄光はあなたのものとなりえます :-) もしこのチュートリアルに間違いやおかしい部分があったら直接メールを送っていただくか、注釈をおねがいします。typo3.org のユー ザーに登録してログインしていただくと直接注釈ができます。 何を作る? このチュートリアルでは「フロントエンド画面に画像とテキストフィールドを表示する」簡単なエクステンションを作成します。そして、それら を作った後、さらにもう1つテキストフィールドを追加しフロントエンドで表示する拡張を行います。ここでは PHP コードと TypoScript を利 用してこのエクステンションを作成します。 チュートリアル このチュートリアルではフロントエンドにコンテンツを表示する簡単なエクステンションの作り方を紹介しています。あくまでエクステンショ ン Kickstarter の使い方とフロントエンドでの表示のやり方をお見せしているだけで、初歩中の初歩とお考えください。そして、この初歩 を手始めに今後のアイディアを拡げていただければ幸いです。 シナリオとしては、 TYPO3 を利用しているサッカークラブが選手のプロフィールを管理できるようにしたい という要件に対応するエクステンションを開発する流れです。プロフィールには選手の写真と名前、そしてさらに詳しい情報を付与するた めのフィールドも求められています。 Kickstarter ウィザード Kickstarter ウィザードを利用すればエクステンションがとても簡単に作成できます。 まずはバックエンド管理画面にログインし、ツールモジュールの Extension Manager をクリックしてください。そして、ドロップダウンメ ニューから「Make new extension」を選択した後、extension key として適当な名前を入力してください。今回は「player_profile」という 名前にします。 では、はじめてみましょう。 • エクステンションについての属性情報を入力します。 General info Title(Player Profile)、Description(Display profile of soccer player )、Category(Frontend Plugins)、State(alpha)、Dependencies(cms)、Author Name(あなたの名前)、Author email(あなたの E メールアドレス) • 新しいデータベーステーブルを作成します。といっても、管理画面の設定を行えば作成できます。 New Database Tables Tablename: tx_playerprofile_list Title of the table: Display player profile、 Add 'Deleted' field: 、 Add 'Hidden' flag: 、 Add 'Access group' 、 Manual ordering of records: Allowed on pages: Allowed in 'Insert Records' field in content elements: Add 'Save and new' button in forms: 簡単な TYPO3 エクステンションの作成 - 2
  • 3. 言語の設定 Setup languages 第二言語も含めてエクステンションを作成するため、本ケースでは German にチェックをいれます。その後、各 German のフィール ドにドイツ語の翻訳を入力することが可能です。 • 画像を扱う image フィールドを作成 NEW FIELD: image Field name や Field tile、Field type、Is Exclude-field を入力して update を押します。 and そして、Max number of files(今回は 1)や Max filesize allowed(今回は 1000kb)、Size of selector box(今回は 1)、Show thumbnails 等の画像ファイルのプロパティ を決めていきます。 • 名前を入力する first_name フィールドを作成 FIELD: first_name Enter field name (今回は first_name)、 field title (今回は First name)、 field type (今回は string input)、 Is Exclude-field を入 力して update を押します。 and その後、Field width (今回は 30)、 Max characters (今回は 50)、 Required 、 Create VARCHAR, not TINYTEXT field 等のプロパティを決めていきます。 簡単な TYPO3 エクステンションの作成 - 3
  • 4. Frontend plugin フロントエンドで利用できるエクステンションとして登録するため、Frontend plugin をクリックします。プラグインの英語のタイトルとして Player profile、 ドイツ語のタイトルとして Spielerprofil を入力します。 'Insert Plugin' list in Content Elements のラジオボタンはそのま まにしておきます。その他は今回はそのままにしておきます。 Static TypoScript code あとで画像の幅と高さを設定するためにちょっとしたコードを追加します。なので、Static TypoScript code の Setup フィールドにいくつ かのダミーテキスト(ここでは#Constants)を入力しておきましょう。 エクステンションの保存 • まず、View result をクリックします。 • ページが再度読み込まれたら、ドロップダウンメニューの Write to location から Local を選択してダイアログボックスの OK を押して ください。 • ページが再読み込みされ、the Extension got copied successfully to the server といったメッセージが表示されます。 簡単な TYPO3 エクステンションの作成 - 4
  • 5. エクステンションのインストール • これで Kickstarter での操作はひと通り終わりました。エクステンション Player Profile をインストールすることが可能です。 • Make updates をクリックして、完了です。 選手のデータを作成する • ページツリーを開いて、Our Players という新規ページを作成しましょう。このページは選手のプロフィールを表示 します。 • 新規ページコンテンツ要素(例えば regular text element.)を作成しましょう。例) • タイプを insert plugin.に変更します。 • ドロップダウンメニューから Player profile を選択し保存します。 • Our players のページアイコンをクリックして 新規データを作成します。 • Display player profile を選択します。 • それから選手のデータを入力します。たとえば First name には Franz を入力し、画像をアップします。 • 保存します。 フロントエンド表示のための準備 Kickstarter での操作はひと通りおえましたが、フロントエンドには何も表示されないでしょう。選手のデータを表示させるには数行のコー ドを書く必要があります。 • Kickstarter が出力したファイルを編集するため、まずは Extension Manager を開きます。そして、 Player Profile extension を探しましょう。 • Extension Manager で右上のドロップダウンメニューから Edit files を選択しましょう。 • Player Profile のフロントエンド表示を変更するために pi1/class.tx_playerprofile_p1.php を編集します。今回は下記のコードをコ ピー&ペーストすることもできます。コードをみると「Last name」用の記述がコメントアウトされていることに気づくでしょう。この部分は あとでこのエクステンションを拡張して Last name 用のフィールドを作るためのものです。ですが、今は無視してください。 • 特定の幅と高さの画像のポップアップを表示するために ext_typoscript_setup.txt というファイルを編集します。このコードも下記に 用意してあるのでコピー&ペーストしてもよいです。 • 保存してください。 簡単な TYPO3 エクステンションの作成 - 5
  • 6. pi1/class.tx_playerprofile_pi1.php コードとコメント <?php /*************************************************************** * Copyright notice * * (c) 2003 Oliver Hofmann (marketing@viv-it.de) * All rights reserved * * This script is part of the Typo3 project. The Typo3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ /** * Plugin 'Player profile' for the 'player_profile' extension. * * @author Oliver Hofmann <marketing@viv-it.de>, Michael Dengler <info@diacc.de>, Andreas Schwarzkopf <info@meinsystem.de> */ require_once(PATH_tslib."class.tslib_pibase.php"); class tx_playerprofile_pi1 extends tslib_pibase { var $prefixId = "tx_playerprofile_pi1"; // Same as class name – no _ allowed var $scriptRelPath = "pi1/class.tx_playerprofile_pi1.php"; // Path to this script relative to the extension dir. var $extKey = "player_profile"; // The extension key. var $conf; /** * [Output for image, first name and last name] */ function main($content,$conf) { $this->conf = $conf; $content=""; $rows=$this->getItems(); while(list($c,$row)=each($rows)) { $this->conf["image."]["file"] = "uploads/tx_playerprofile/".($row["image"]); //The image field name $theImgCode=$this->cObj->IMAGE($this->conf["image."]); $content.=$theImgCode."<br>"; $content.=($row["first_name"])."&nbsp;"; //This outputs the first name // $content.=($row["last_name"])."<br><br>"; //This is the additional field //next, the output displayed in a table $content.="<table border=1><tr><td>". ($row["first_name"])."</td></tr>"; $content.="<tr><td>".($row["last_name"])."</td></tr></table>"; } #t3lib_div::debug($conf); #t3lib_div::debug($this->getItems()); return $content; } 簡単な TYPO3 エクステンションの作成 - 6
  • 7. /** * function. */ function getItems() { // pid_list is the pid/list of pids from where to fetch the guest items. $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this- >conf["pid_list."])); $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",", $config["pid_list"]),",") : $GLOBALS["TSFE"]->id; list($pid) = explode(",",$config["pid_list"]); $query = "SELECT * FROM tx_playerprofile_list WHERE pid IN (".$pid.") ORDER BY sorting"; $res = mysql(TYPO3_db,$query); $out=array(); while($row = mysql_fetch_assoc($res)) { $out[]=$row; } return $out; } } if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"] ["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"]) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"] ["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"]); } ?> ext_typoscript_setup.txt 詳細を知りたい場合は TypoScript リファレンスの 49 ページを参照してください。 plugin.tx_playerprofile_pi1 { image { file.maxW = {$plugin.player_profile.maxW_single} imageLinkWrap = {$plugin.player_profile.clickEnlarge} imageLinkWrap { enable = 1 bodyTag = <BODY bgColor=white> wrap = <A href="javascript:close();"> | </A> width = 400m height = 400 JSwindow = 1 JSwindow.newWindow = 1 JSwindow.expand = 17,20 } } } ext_typoscript_constants.txt ここでサムネイル画像の大きさを 70 ピクセルに指定します。 file.maxW = {$plugin.player_profile.maxW_single} = 70 簡単な TYPO3 エクステンションの作成 - 7
  • 8. pi1/class.tx_playerprofilebasic_pi1.php player_profile_basic エクステンションのサンプルコード typoscript_setup.txt と typoscript.constants.txt は適宜変更してください。 <?php /*************************************************************** * Copyright notice * * (c) 2003 Oliver Hofmann (marketing@viv-it.de) * All rights reserved * * This script is part of the Typo3 project. The Typo3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ /** * Plugin 'Player profile' for the 'player_profile_basic' extension. * * @author Oliver Hofmann <marketing@viv-it.de>, Michael Dengler <info@diacc.de>, Andreas Schwarzkopf <info@meinsystem.de> */ require_once(PATH_tslib."class.tslib_pibase.php"); class tx_playerprofilebasic_pi1 extends tslib_pibase { var $prefixId = "tx_playerprofilebasic_pi1"; // Same as class name – no _ allowed var $scriptRelPath = "pi1/class.tx_playerprofilebasic_pi1.php"; // Path to this script relative to the extension dir. var $extKey = "player_profile"; // The extension key. var $conf; /** * [Output for image, first name and last name] */ function main($content,$conf) { $this->conf = $conf; $content=""; $rows=$this->getItems(); while(list($c,$row)=each($rows)) { $this->conf["image."]["file"] = "uploads/tx_playerprofilebasic/".($row["image"]); //The image field name $theImgCode=$this->cObj->IMAGE($this->conf["image."]); $content.=$theImgCode."<br>"; $content.=($row["first_name"])."&nbsp;"; //This outputs the first name // $content.=($row["last_name"])."<br><br>"; //This is the additional field //next, the output displayed in a table $content.="<table border=1><tr><td>". ($row["first_name"])."</td></tr>"; $content.="<tr><td>".($row["last_name"])."</td></tr></table>"; } #t3lib_div::debug($conf); #t3lib_div::debug($this->getItems()); return $content; } /** * function. */ function getItems() { 簡単な TYPO3 エクステンションの作成 - 8
  • 9. // pid_list is the pid/list of pids from where to fetch the guest items. $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this- >conf["pid_list."])); $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",", $config["pid_list"]),",") : $GLOBALS["TSFE"]->id; list($pid) = explode(",",$config["pid_list"]); $query = "SELECT * FROM tx_playerprofilebasic_list WHERE pid IN (".$pid.") ORDER BY sorting"; $res = mysql(TYPO3_db,$query); $out=array(); while($row = mysql_fetch_assoc($res)) { $out[]=$row; } return $out; } } if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"] ["ext/player_profile_basic/pi1/class.tx_playerprofilebasic_pi1.php"]) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"] ["ext/player_profile_basic/pi1/class.tx_playerprofilebasic_pi1.php"]); } ?> 簡単な TYPO3 エクステンションの作成 - 9
  • 10. エクステンションの拡張(Last name フィールドを追加) 選手の First name と画像だけではなく Last Name も入力できるように拡張してみましょう。これまでは Kickstarter をひと通り操作し、フ ロントエンド表示のためのファイルも編集してきました。Last name フィールドを追加するには class ファイルを編集しなくてはなりません。 • まず、Extension Manager を開き、Player Profile を探します。そして、KickStarter で作成された現在のファイルを 編集します。 • 右上のドロップダウンメニューから Backup/Delete を選択し、 start new. をクリックします。 • Last name フィールドをデータベースのテーブルに追加するために Display player profile をクリックします。 • 新しいフィールド名として Last_name を追加し field title (Last name)、 field type (string input)、 Is Exclude-field を入力、そして、 Field width (30)、 Max characters (50)、 Required 、 Create VARCHAR、 not TINYTEXT field といったプロパティを設定し ます。 • 注意! update ボタンをクリックしたら Extension Manager は既存の設定を上書きします。pi1/class.tx_playerprofile_pi1.php や ext_typoscript_setup.txt はあらかじめ別途保存しておいてください。 • Update します。 • View result が表示されます。 • Extension Manager を開き、Player Profile のドロップダウンメニューから edit files を選択します。 • the pi1/class.tx_playerprofile_pi1.php を開き、すでにこのファイルにコメントアウトして記述されている Last name フィールド用の1 下記行のコメントアウトを外します。 • $content.=$row["last_name"]."; エクステンションを拡張する際の留意点 もしこのサンプルコードをベースに独自のエクステンションを作ろうとする場合は、Kickstarter を利用しつつ、このチュートリアルの内容に 沿ってファイルを編集していってください。また、player_profile_basic と名付けられエクステンションの class ファイルでは playerprofile と書 かれています。エクステンション名に含まれるアンダースコアは消されています。例えば、my_gallery と命名したエクステンションを新しく 作ると、class ファイル内では mygallery と記載されます。 簡単な TYPO3 エクステンションの作成 - 10
  • 11. TypoScript によるエクステンション対応 PHP クラスを使わず、TypoScript を使うこともできます。例えば、フロントエンド表示をコントロールするために template setup フィールドに TypoScript を記述して対応することも可能です。この例では機能的にちょっとだけ違うものを用意しました。まず、選手の画像と Last name が表示され、選手をクリックすると詳細情報が表示されます。 page.10.subparts.CONTENT > // overwrites statements in the root template page.10.subparts.CONTENT = CONTENT page.10.subparts.CONTENT { table = tx_playerprofile_2_listextended // takes the table created with the kickstarter select.pidInList = this // the current pid where the plugin is installed – could be also an uid wrap = <table>|<tr><td><a href="javascript:history.back()">back to list</a><td></tr></table> // link back to player overview list renderObj = COA renderObj.10 = IMAGE // definitions for the image start here renderObj.10.file.import = uploads/tx_playerprofile_2/ // the upload folder for the images renderObj.10.file.import.field = image // defines that the image field should be taken renderObj.10.file.import.listNum = 0 renderObj.10.stdWrap.typolink.parameter.data = TSFE:id renderObj.10.stdWrap.typolink.additionalParams.dataWrap = &playeruid={field:uid} renderObj.10.stdWrap.wrap = <tr><td>|</td></tr> // image put in first table row renderObj.10.stdWrap.typolink.no_cache = 1 renderObj.20 = TEXT renderObj.20.field = first_name renderObj.20.wrap = <tr><td>|</td></tr> // first name field displayed in second table row renderObj.30 = TEXT renderObj.30.field = last_name renderObj.30.wrap = <tr><td>|</td></tr> // last name field displayed in third table row } // Start of conditions for the above typoscript code, similar to if / else statement [globalVar = GP:playeruid > 0] page.10.subparts.CONTENT.select.where = 1=1 page.10.subparts.CONTENT.select.andWhere.dataWrap = uid={GPvar:playeruid} [else] page.10.subparts.CONTENT.wrap = <table>|</table> # page.10.subparts.CONTENT.renderObj.20 > // the first name will be shown on the overview list because here it is commented out page.10.subparts.CONTENT.renderObj.30 > // the last name is taken out from being displayed [global] // Conditions end here 簡単な TYPO3 エクステンションの作成 - 11
  • 12. エクステンション - 本サンプルをさらに拡張したもの(コードのみ) 下記ポイントに留意して今までの基本バージョンを拡張したコードです。 • 一覧表示と個別表示の対応 <?php /*************************************************************** * Copyright notice * * (c) 2003 Oliver Hofmann (marketing@viv-it.de) * All rights reserved * * This script is part of the Typo3 project. The Typo3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ /** * Plugin 'Player profile' for the 'player_profile' extension. * * @author Oliver Hofmann <marketing@viv-it.de>, Michael Dengler <info@diacc.de>, Andreas Schwarzkopf <info@meinsystem.de> */ require_once(PATH_tslib."class.tslib_pibase.php"); class tx_playerprofile_pi1 extends tslib_pibase { var $prefixId = "tx_playerprofile_pi1"; // Same as class name var $scriptRelPath = "pi1/class.tx_playerprofile_pi1.php"; // Path to this script relative to the extension dir. var $extKey = "player_profile"; // The extension key. var $conf; /** * [Put your description here] */ function main($content,$conf) { $this->conf = $conf; $content=""; $GLOBALS["TSFE"]->set_no_cache(); if(t3lib_div::GPvar("player")) { $row = $this->getSingle(t3lib_div::GPvar("player")); $this->conf["image."]["file"] = "uploads/tx_playerprofile/".$row["image"]; $theImgCode=$this->cObj->IMAGE($this->conf["image."]); $content.="<table border=0><tr><td></td><td>". $theImgCode."</td></tr>"; $content.="<tr><td>Name:</td><td>".$row["last_name"]."&nbsp;". $row["first_name"]."</td></tr>"; $content.="<tr><td>Year:</td><td>".$row["year"]."</td></tr>"; $content.="<tr><td valign=top>Nationality:</td><td>". $row["nationality"]."</td></tr>"; $content.="<tr><td>Position:</td><td>". $row["position"]."</td></tr>"; $content.="<tr><td valign=top>Former clubs:</td><td>".nl2br($row["club"])."</td></tr>"; $content.="<tr><td>Favorite clubs:</td><td>". $row["favorite_club"]."</td></tr>"; $content.="<tr><td valign=top>Hobbies:</td><td>". $row["hobbies"]."</td></tr>"; $content.="<tr><td valign=top> Favorite meal:</td><td>". 簡単な TYPO3 エクステンションの作成 - 12
  • 13. $row["food"]."</td></tr>"; $content.="<tr><td valign=top>Music:</td><td>". $row["music"]."</td></tr>"; $content.="<tr><td valign=top>Profession/studies:</td><td>". $row["profession"]."</td></tr>"; $content.="<tr><td valign=top>Message to the fans:</td><td>". $row["message"]."</td></tr>"; $content.="<tr><td colspan=2><a href=index.php?id=". $GLOBALS["TSFE"]->id.">back</a></td></tr></table>"; } else { $rows=$this->getItems(); while(list($c,$row)=each($rows)) { $this->conf["image."]["file"] = "uploads/tx_playerprofile/".$row["image"]; $theImgCode=$this->cObj->IMAGE($this->conf["image."]); $content.="<table border=0><tr><td></td><td>". $theImgCode."</td></tr>"; $content.="<tr><td>Details -->:</td><td align=center><a href=index.php?id=".$GLOBALS["TSFE"]->id."&player=".$row["uid"].">". $row["last_name"]."</a></td></tr></table>"; } } #t3lib_div::debug($conf); #t3lib_div::debug($this->getItems()); return $content; } /** * function. */ function getItems() { // pid_list is the pid/list of pids from where to fetch the guest items. $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this- >conf["pid_list."])); $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",", $config["pid_list"]),",") : $GLOBALS["TSFE"]->id; list($pid) = explode(",",$config["pid_list"]); $query = "SELECT * FROM tx_playerprofile_list WHERE pid IN (".$pid.") ORDER BY sorting"; $res = mysql(TYPO3_db,$query); $out=array(); while($row = mysql_fetch_assoc($res)) { $out[]=$row; } return $out; } /** * function. */ function getSingle($uid) { // pid_list is the pid/list of pids from where to fetch the guest items. $config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this- >conf["pid_list."])); $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",", $config["pid_list"]),",") : $GLOBALS["TSFE"]->id; list($pid) = explode(",",$config["pid_list"]); $query = "SELECT * FROM tx_playerprofile_list WHERE pid IN (".$pid.") AND uid = ".$uid." ORDER BY sorting"; $res = mysql(TYPO3_db,$query); $row = array(); $row = mysql_fetch_assoc($res); return $row; } } if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"] ["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"]) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"] ["ext/player_profile/pi1/class.tx_playerprofile_pi1.php"]); } ?> 簡単な TYPO3 エクステンションの作成 - 13
  • 14. 既知の問題 • 今のところ確認されている問題はありません。何か問題があればご連絡ください! To-Do list • Extending the basic and extended version of the extension with other basic functions (commented in detail). • List view and single view settings of basic extension should be made modifiable through TypoScript in the setup field . • View of images currently vertically shown in list view should be positioned also e.g. three in a row or more... • Through TypoScript in the setup field, the database table fields shown on the frontend, should be managable. Changelog • 03-26-2003 - document first published, created on Typo3 Snowboard Tour in Splügen/Swizerland. Thanks to Michael Dengler (diacc.de) and Andreas Schwarzkopf (meinsystem.de) for there great efforts to this extension! • 03-27-2003 – cleaned up setup.txt and constants.txt as well as php class file of player_profile_pi1.php according to the tutorial example. Added the php class code for the extension player_profile_basic to show how the code needs to be changed. 簡単な TYPO3 エクステンションの作成 - 14