[TYPO3-UG Italy] Custom Plugin - come fare a..

Francesco Pessina typo3news at yahoo.it
Tue Mar 7 12:52:36 CET 2006


Grazie infinite a Jan e Franz per gli ottimi consigli, in particolare al 
debugger che si rivela uno strumento molto prezioso!

Nel frattempo ho anche trovato un tutorial simile a quello di Kasper, 
abbastanza completo, di Hack Meister 
(http://typo3.hachmeister.org/Create_your_own_Frontend.137.0.html - 
Create Your Front End Plugin) ma purtroppo anche qui ho dei problemi. 
Studiandomi il codice PHP presentato, ho scoperto che contiene alcuni 
bug di sintassi (tipo un ciclo while che non ha mai termine :-) ma 
aggiustandolo nella funzionalita' a livello di PHP, mi sono accorto con 
grande tristezza che l'oggetto array $conf contiene soltanto 'userFunc' 
e che il codice 'Static TypoScript', sezioni 'Constant' e 'Setup', 
scritti tramite il KickStarter Extension, vengono totalmente ignorati. 
Quindi non riesco ne a caricare il template associato (definito nelle 
costanti di Static TypoScript) ne il codice di setup (sempre sezione 
Setup di Static TypoScript). Il codice PHP del plugin (generato in 
automatico dal Kick Starter e da me in seguito modificato) e' corretto 
perche' mi permette di stampare delle scritte di debug (ad esempio). 
Invece fallisce negli accessi a oggetti come $conf (in tal caso sulo 
userFunc esiste).

Utilizzando il debug($conf) mi viene restituito solo:
|userFunc|tx_imagegallery_pi1->main|

Il che presumo sia incompleto perche' dovrebbe l'array contenere anche 
altre due posizioni indicizzate con 'templateFile' e 'columns'.
Invece con la debug($this) nel printing dell'oggetto non compare alcun 
riferimento alle variabili 'templateFile' e 'columns' (corretto in 
quanto non sono gia' presenti a monte in $conf).

Dove sta l'inghippo stavolta?

Grazie ancora!

Francesco Pessina from Italy.

P.S. Per maggiore chiarezza allego un po' di codice, scusate 
l'allungamento del post :-)

##### Static TypoScript - Constant #####

plugin.tx_imagegallery_pi1 {
     file.templateFile = media/scripts/gallery_template.tmpl
     columns = 3
}

#####  Static TypoScript - Setup #####

plugin.tx_imagegallery_pi1 {
      userFunc = tx_imagegallery_pi1->main
      templateFile = {$plugin.tx_imagegallery_pi1.file.templateFile}
      columns = {$plugin.tx_imagegallery_pi1.columns}
}

tx_imagegallery_pi1 >
tx_imagegallery_pi1 = < plugin.tx_imagegallery_pi1

##### class.tx_imagegallery_pi1.php #####

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

class tx_imagegallery_pi1 extends tslib_pibase {
     var $prefixId = "tx_imagegallery_pi1";
     var $scriptRelPath = "pi1/class.tx_imagegallery_pi1.php";
     var $extKey = "image_gallery";
     var $pi_checkCHash = TRUE;

     var $conf;
     var $templateCode;
     var $columns;

     /**
      * Image gallery Frontend Plugin
      */
     function main($content, $conf) {
         $GLOBALS["TSFE"]->set_no_cache();

         $this->conf=$conf;
         $this->pi_setPiVarDefaults();
         $this->pi_loadLL();

         /**
          * Get the necessary database rows
          */

         debug($conf);
         debug($this);

         // 001: Database query
         $query = "SELECT title,image " . "FROM tx_imagegallery_images " 
. "WHERE pid=" . $GLOBALS["TSFE"]->id . 
$this->cObj->enableFields("tx_imagegallery_images");

         // 002: Execute query
         $res = mysql(TYPO3_db, $query);

         /*
          * Generate output
          */

         // 003: Get the template
         $this->templateCode = 
$this->cObj->fileResource($this->conf["templateFile"]);
         print "#".$this->conf["templateFile"]."#";

         // 004: Get the parts out of the template
         $t = array();
         $t["total"] = $this->cObj->getSubpart($this->templateCode, 
"###GALLERY_TABLE###");
         $t["row"] = $this->cObj->getSubpart($t["total"], 
"###GALLERY_TABLE_ROW###");
         $t["item"] = $this->cObj->getSubpart($t["row"], 
"###GALLERY_TABLE_ITEM###");

         // 005: Some values
         $this->columns = $this->conf["columns"];
         mysql_data_seek($res, 0);
         $row = mysql_fetch_array($res, MYSQL_NUM);
         $content_table = "";

         // 006: For all database rows from the query
         mysql_data_seek($res, 0);
         while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
             // 007: Clear content_row
             $content_row = "";

             // 008: Collects items for one row
             for ($i = 0; $i < mysql_num_fields($res); $i++) {
                 // 009: Initialise $markerArray
                 $markerArray = array();
                 if ($row) {
                     // 010: Create one item
                     $img = $this->conf["image"];
                     $img["file"] = "uploads/tx_imagegallery/" . 
$row["image"];
                     $markerArray["###GALLERY_IMAGE###"] = 
$this->cObj->IMAGE($img);
                 } else {
                     // 011: Create one dummy icon
                     $markerArray["###GALLERY_IMAGE###"] = " ";
                 }

                 // 012: Add item to $content_row
                 $content_row .= 
$this->cObj->substituteMarkerArrayCached($t["item"], $markerArray, 
array(), array());

                 // 013: Fetch new row from the query
                 //$row = mysql_fetch_array($res, MYSQL_NUM);
             }

             // 014: Create one row
             $subpartArray = array();
             $subpartArray["###CONTENT_ROW###"] = $content_row;
             $content_table .= 
$this->cObj->substituteMarkerArrayCached($t["row"], array(), 
$subpartArray, array());
         }

         // 015: Create the whole table
         $subpartArray = array();
         $subpartArray["###CONTENT###"] = $content_table;
         $content .= 
$this->cObj->substituteMarkerArrayCached($t["total"], array(), 
$subpartArray, array());

         mysql_free_result($res);
         // 016: Return the created table
         print $content;
         return $this->pi_wrapInBaseClass($content);
     }
}



if (defined('TYPO3_MODE') && 
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/image_gallery/pi1/class.tx_imagegallery_pi1.php']) 
{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/image_gallery/pi1/class.tx_imagegallery_pi1.php']);
}


Francesco ha scritto:
> Salve a tutti, sono nuovo con Typo3 e ho realizzato un mio plugin con 
> Extension KickStart per una mia gestione documentale. Dal lato Back-End 
> sono quasi ok mentre dal lato Front-End sono in alto mare.
> 
> Il mio problema che il plugin, seguendo l'ottimo video di Kasper 
> relativo all'argomento plugin (Episodio III della saga), genera, lato 
> FE, l'elenco dei contenuti che, via BE, inserisco. Il mio problema che 
> vorrei customizzare l'output generato a FE in modo da incastonare il 
> contenuto generato in una lista <dl> anziche' in un tabella (default).
> 
> Ho gia' creato un template speciale da associare, con tanto di codice 
> TS. Ma la parte "CONTENT" (marcata ###CONTENT###) rimane sempre vuoto!
> 
> Come faccio a recuperare il contenuto generato? A esempio, prendendo da 
> esempio la CD Collection del video di Kasper, come si scrive in TS il 
> recupero (ciclico) dei vari campi definiti nella costruzione del plugin?
> 
> Ringrazio anticipatamente chiunque mi dia un qualsiasi consiglio!!!
> 
> Salutissmi e forza Typo3!
> 
> Francesco.



More information about the TYPO3-UG-italy mailing list