<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TYPO3 - Fulda, Kassel, Projekte, Online Marketing &#124; Web-aktiv Blog &#187; Extension: typoscript_code</title>
	<atom:link href="http://www.web-aktiv.com/blog/index.php/tag/extension-typoscript_code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-aktiv.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 25 Nov 2011 16:52:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>TYPO3: Individuelle Inhalte mit TypoScript</title>
		<link>http://www.web-aktiv.com/blog/index.php/2009/09/23/typo3-individuelle-inhalte-mit-typoscript/</link>
		<comments>http://www.web-aktiv.com/blog/index.php/2009/09/23/typo3-individuelle-inhalte-mit-typoscript/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 14:40:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[TYPO3]]></category>
		<category><![CDATA[Datenbank]]></category>
		<category><![CDATA[Extension: typoscript_code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[TypoScript]]></category>

		<guid isPermaLink="false">http://www.web-aktiv.com/blog/?p=71</guid>
		<description><![CDATA[Hin und wieder möchte man seine TYPO3 Website mit individuellen Funktionen bereichern. Dafür gleich eine Extension zu entwickeln ist wohl etwas übertrieben. Ich möchte hier an einem konkreten Beispiel demonstrieren, wie man mit TypoScript, etwas PHP auf die Typo3 Datenbank zugreift und eine Ausgabe in der Website erzeugt.

1. Das Projekt

Auf meiner Website http://www.gps-mountainbiker.de befindet sich [...]]]></description>
			<content:encoded><![CDATA[<p>Hin und wieder möchte man seine TYPO3 Website mit individuellen Funktionen bereichern. Dafür gleich eine Extension zu entwickeln ist wohl etwas übertrieben. Ich möchte hier an einem konkreten Beispiel demonstrieren, wie man mit TypoScript, etwas <acronym title="Hypertext Preprocessor">PHP</acronym> auf die Typo3 Datenbank zugreift und eine Ausgabe in der Website erzeugt.<br />
<span id="more-71"></span></p>
<h2><a id="das_projekt" name="das_projekt">1. Das Projekt</a></h2>
<div>
<p><iframe scrolling="no" frameBorder="0" src="http://rcm-de.amazon.de/e/cm?t=gpsmoun-21&amp;o=3&amp;p=8&amp;l=as1&amp;ASINs=3827323223&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=transparent&amp;bg1=transparent&amp;f=ifr" marginheight="0" marginwidth="0" style="float:right; width:120px; margin-left:10px; height:240px; background-color:#FFFFFF; border:1px solid #000000;"></iframe>Auf meiner Website <a title="http://www.gps-mountainbiker.de" rel="nofollow" href="http://www.gps-mountainbiker.de/" target="_blank">http://www.gps-mountainbiker.de</a> befindet sich unter Links eine Linkliste. Sie wurde mit der Extension <a title="http://typo3.org/extensions/repository/view/cmw_linklist/current/" rel="nofollow" href="http://typo3.org/extensions/repository/view/cmw_linklist/current/" target="_blank">cmwlinklist</a> erstellt und bietet u.a. die Möglichkeit, einen Link vorzuschlagen. Ich wollte meinen Besuchern Infos über die Anzahl der Links und den Klicks darauf zur Verfügung stellen. Alle dazu notwendigen Daten befinden sich in der Datenbank-Tabelle der o.g. Extension.</p>
<h2><a id="was_benoetigen_wir" name="was_benoetigen_wir">2. Was benötigen wir?</a></h2>
<ul>
<li>
<div>Die Extension typoscript_code ermöglicht das Einbinden von TypoScript als Inhaltselement</div>
</li>
<li>
<div>TypoScript, das die <acronym title="Hypertext Preprocessor">PHP</acronym>- Datei einbindet und die Funktion aufruft</div>
</li>
<li>
<div>Eine <acronym title="Hypertext Preprocessor">PHP</acronym> Datei, die unsere Infos aus der Datenbank ausließt und darstellt</div>
</li>
</ul>
<p>Als erstes lädt man  sich die Extension <a title="http://typo3.org/extensions/repository/view/typoscript_code/current/" rel="nofollow" href="http://typo3.org/extensions/repository/view/typoscript_code/current/" target="_blank">typoscript_code</a> vom TER herunter und installiert sie mit dem Extension Manager. Sie ermöglicht das komfortable Einbinden von TypoScript als Inhaltselement.</p>
<p><img class="alignnone size-full wp-image-75" title="ind_inhalte_ts_01" src="http://www.web-aktiv.com/blog/wp-content/uploads/2009/09/ind_inhalte_ts_01.gif" alt="ind_inhalte_ts_01" width="346" height="39" /></p>
<h2><a id="typoscript" name="typoscript">3. Typoscript</a></h2>
<p>Das TypoScript ist schnell erklärt. Es besteht im Wesentlichen aus 2 Teilen. Erstens dem Befehl zum Einbinden der <acronym title="Hypertext Preprocessor">PHP</acronym>-Datei. Das war für mich zunächst nicht so trivial wie man denkt. Wollte ich doch zunächst die Datei auch im Inhaltselement einbinden. Das funktioniert natürlich nicht! Die Datei wird im PAGE-Objekt eingebunden.</p>
<pre lang="typoscript" escaped="true">page <span>=</span> PAGE
page <span>{</span>
 <span># Bibliotheken einbinden</span>
 includeLibs<span>.</span>dataCount <span>=</span> fileadmin<span>/</span>scripts<span>/</span><span>class</span><span>.</span>user_datacount<span>.</span>php
<span>...</span></pre>
</div>
<p>Ob die Datei korrekt eingebunden wurde kann auch im TypoScript Object Browser prüfen.</p>
<p><img class="alignnone size-full wp-image-78" title="ind_inhalte_ts_02" src="http://www.web-aktiv.com/blog/wp-content/uploads/2009/09/ind_inhalte_ts_02.gif" alt="ind_inhalte_ts_02" width="579" height="111" /></p>
<p>Das eigentliche TypoScript wird nun als Inhaltselement mit der o.g. Extension in der Seite angelegt.</p>
<pre lang="typoscript" escaped="true"><span>10</span> <span>=</span> TEXT
<span>10</span><span>{</span>
  postUserFunc <span>=</span> user_datacount<span>-&gt;</span><span>main</span>
  postUserFunc<span>{</span>
     label_1 <span>=</span> Links
     label_2 <span>=</span> Klicks
     table <span>=</span> tx_cmwlinklist_link
     field <span>=</span> clicks
     where = status=1
<span>}</span></pre>
<p><strong>Das Script im Einzelnen</strong></p>
<p>Da ich eine Ausgabe erzeugen möchte, habe ich das cObject TEXT gewählt. Mit <em>postUserFunc</em> wird die Methode <em>main()</em> der Klasse<em> user_datacount</em> aufgerufen. Die Methode <em>main()</em> erwartet die Parameter <em>$content</em> und <em>$conf</em>. Der erste ist gewöhnlich leer, der zweite enthält ein Array. Dieses Array wird nun mit den Werten<em> label_1</em>, <em>label_2</em> für die Beschreibungstexte, <em>table</em> für den Tabellennamen und<em> field</em> für den Namen des Feldes in der Tabelle gefüllt.</p>
<h2><a id="php" name="php">4. PHP</a></h2>
<p>Die <acronym title="Hypertext Preprocessor">PHP</acronym> Datei enthält eine Klasse <em>user_datacount</em> mit den Methoden<em> main()</em> und <em>getData()</em>. Letzere stellt die Verbindung zur Datenbanktabelle der CMW Linklist Extension her, ermittelt die Anzahl der eingetragenen Links und die Gesamtzahl der Klicks auf alle Links. Die Methode <em>main()</em> erzeugt schließlich die Ausgabe als <acronym title="HyperText Markup Language">HTML</acronym> auf der Website. Wie man sieht, stehen die im TypoScript angegebenen Werte als Array <em>$this-&gt;conf[]</em> zur Verfügung.</p>
<pre lang="typoscript" escaped="true"><span>&lt;?php</span>

<span>class</span> user_datacount<span>{</span>
   <span>private</span> <span>$conf</span>;

 <span>public</span> <span>function</span> main<span>(</span><span>$content</span><span>,</span><span>$conf</span><span>)</span><span>{</span>
 <span>  $this</span><span>-&gt;</span><span>conf</span> <span>=</span> <span>$conf</span>;
 <span>  $data</span> <span>=</span> <span>$this</span><span>-&gt;</span><span>getData</span><span>(</span><span>)</span>;
 <span>  $html</span> <span>=</span> <span>'
   &lt;div&gt;
    &lt;p&gt;'</span>
 <span>    .</span><span>$this</span><span>-&gt;</span><span>conf</span><span>[</span><span>'label_1'</span><span>]</span><span>.</span><span>': '</span><span>.</span><span>$data</span><span>[</span><span>'datasets'</span><span>]</span><span>.</span><span>'&lt;br&gt;'</span>
 <span>    .</span><span>$this</span><span>-&gt;</span><span>conf</span><span>[</span><span>'label_2'</span><span>]</span><span>.</span><span>': '</span><span>.</span><span>$data</span><span>[</span><span>'datasum'</span><span>]</span><span>.</span><span>'
    &lt;/p&gt;
   &lt;/div&gt;'</span>;

   <span>return</span> <span>$html</span>;
 <span>}</span>

 protected <span>function</span> getData<span>(</span><span>)</span><span>{</span>
 <span>  $result</span> <span>=</span> <span>$GLOBALS</span><span>[</span><span>'TYPO3_DB'</span><span>]</span><span>-&gt;</span><span>exec_SELECTquery</span><span>(</span>
 <span>  'COUNT(*) AS datasets , SUM('.$this-&gt;conf['field'].') AS datasum'</span><span>,</span>  //SELECT
 <span>  $this</span><span>-&gt;</span><span>conf</span><span>[</span><span>'table'</span><span>]</span><span>,</span>  //FROM
 <span>  $this-&gt;conf['where']</span><span>,</span> //WHERE
 <span>  ''</span><span>,</span> //GROUP BY
 <span>  ''</span><span>, //ORDER BY</span>
 <span>  ''  //LIMIT</span>
 <span>  )</span>;

   <span>$entries</span> <span>=</span> <span>$GLOBALS</span><span>[</span><span>'TYPO3_DB'</span><span>]</span><span>-&gt;</span><span>sql_fetch_assoc</span><span>(</span><span>$result</span><span>)</span>;

   <span>return</span> <span>$entries</span>;
 <span>}</span>

<span>}</span>
<span>?&gt;</span></pre>
<h2><a id="ausblick" name="ausblick"><br />
5. Ergebnis &amp; Ausblick</a></h2>
<div>
<div id="attachment_93" class="wp-caption alignleft" style="width: 260px"><img class="size-full wp-image-93" title="ind_inhalte_ts_03" src="http://www.web-aktiv.com/blog/wp-content/uploads/2009/09/ind_inhalte_ts_03.gif" alt="ind_inhalte_ts_03" width="250" height="148" /><p class="wp-caption-text">Ausgabe auf www.gps-mountainbiker.de</p></div>
<p>Die <acronym title="Hypertext Preprocessor">PHP</acronym> Klasse wurde im Sinne von OOP allgemein gehalten um wiederverwendbar zu sein. Ich werde die Klasse auch noch zum Anzeigen der verfügbaren GPS-Touren und der Anzahl der Downloads verwenden. Eine Erweiterung der Klasse um eine Funktion, die eine Top 5 Liste ermittelt ist ebenfalls angedacht.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.web-aktiv.com/blog/index.php/2009/09/23/typo3-individuelle-inhalte-mit-typoscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

