[TYPO3-english] Embedding Remote Content into Typo3 CMS Page

Stephan Schuler Stephan.Schuler at netlogix.de
Fri Jul 1 18:18:47 CEST 2011


Hi Adam.


Writing a plugin is exactly what you want to do, I guess.

You create a class extending tslib_pibase [1]. Inside that class you do a method called "main" that should return the content to be shown in the frontend. To bring this to your frontend, you have to select your plugin at the TYPO3 backend and position it where you want it to be shown.

When implementing the main method, you can use each and every PHP command. But you should stick to the TYPO3 API wherever possible to benefit from the TYPO3 instead of reimplementing functionality that may stop working when you try to change some environment settings they rely on.

Getting a remote URLs content, for example, can be done with t3lib_div::getURL [2]. This static method uses the PHP implementation of CURL. If any CURL settings such as a proxy server or this proxy server authentication credentials are needed, you have to add them to your install tool (or you will find them there, depending if you are the TYPO3 administrator or just using the installation). As soon as the install tool settings are updated, the t3lib_div::getURL mechanism will make use of them automatically. So if you need http proxy settings, just add them to your install tool and use t3lib_div::getUrl. Maybe at the moment you can use raw PHPs "file_get_contents" mechanism. This *will* stop working as soon as the PHP "allow_url_wrapper" flag is set to "OFF" or a proxy enforcement is set up by your network administrator. So using TYPO3s CURL internal mechanism is the way to go.

t3lib_div::getURL will provide you the raw response as a string. If it's kind of valid HTML, you could try to pass t3lib_parsehtml [3, 4].

Some guys told you to use a hook to manipulate the DOM in some former emails. I suggest not to do so. If you want to add some additional JavaScript, CSS or "other header information" (like meta tags), you should make use of the $GLOBALS['TSFE'] object which is an instance of tslib_fe [5]. You add additional JavaScript files or CSS files to its $additionalHeaderData array [6] with the corresponding HTML statements (<script> and <link> tags). Plain JS and CSS source goes directly to its arrays $additionalJavaScript and $additionalCSS [7, 8] without any HTML tags.

If you want to add some content to the <body> part of your page, just return those string by your main method.

Debugging goes with t3lib_utility_Debug::debug() [9]. If you get an exception like a HTTP-500 error, you should use the raw PHP "die()" after that to be able to read at least the debug output or use t3lib_utility_Debug::debugInPopupWindow(). Die() will stop any PHP processing, which will protect you from running into the HTTP-500, so in this case you have to use die().


[1] http://api.typo3.org/typo3v4/current/html/classtslib__pibase.html
[2] http://api.typo3.org/typo3v4/current/html/classt3lib__div.html#ad8a5917910d8268d0b4320ba183e176f
[3] http://api.typo3.org/typo3v4/current/html/classt3lib__parsehtml.html
[4] http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.3.0/view/3/13/#id2514838
[5] http://api.typo3.org/typo3v4/current/html/classtslib__fe.html
[6] http://api.typo3.org/typo3v4/current/html/classtslib__fe.html#a915c3afc421df4494c3830865e74cfb2
[7] http://api.typo3.org/typo3v4/current/html/classtslib__fe.html#a869a16661dbf838fbe67136026404868
[8] http://api.typo3.org/typo3v4/current/html/classtslib__fe.html#a53eb8b0e67a60e57fe942ca147fbc764
[9] http://api.typo3.org/typo3v4/current/html/classt3lib__utility___debug.html





Stephan Schuler
Web-Entwickler

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de


--
netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Andernacher Straße 53 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Internet: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



-----Ursprüngliche Nachricht-----
Von: typo3-english-bounces at lists.typo3.org [mailto:typo3-english-bounces at lists.typo3.org] Im Auftrag von Adam Retter
Gesendet: Freitag, 1. Juli 2011 16:34
An: TYPO3 English
Betreff: Re: [TYPO3-english] Embedding Remote Content into Typo3 CMS Page

I have managed to follow a tutorial on building an extension on the
Typo3 website, however I cannot seem to understand how to do the Web Request to the remote server from my PHP script. I was trying to use the http_get PHP function, but each time I do, Typo3 just gives me a HTTP 500 error when I view my page.

Any suggestions please?

On 28 June 2011 21:45, Philipp Gampe <typo3.lists at philippgampe.info> wrote:
> Hi Adam,
>
> Adam Retter wrote:
>
>> 1) Cross Site Scripting - the URL I am requesting is from a different
>> domain! This is problematic in older browsers. But none the less, it
>> can be done.
>>
>> 2) I could not get it to work correctly inside the TYPO3 page. I made
>> an example which uses a pure minimal HTML page -
>> view-source:http://kjc-ws2.kjc.uni-heidelberg.de:8600/exist/apps/test
>> -
> embedd1.html
>>
>> However when I reuse the JavaScript inside my TYPO3 page, I get
>> JavaScript errors, and I really cannot discern why, there seems to me
>> that there should be no difference. My TYPO3 page -
>> http://www.asia-europe.uni-heidelberg.de/index.php?id=1664
>
> I guess you run into trouble with other JS on the same site.
>
>> So maybe I was not clear, I need to do 1 request to the remote site,
>> and from the returned content, extract some items that must be
>> inserted into the <head> of the page, and some items that must be
>> inserted into the body of the page. So two separate approaches wont
>> work, I need a single approach whereby I can manipulate the entire
>> page output from TYPO3. I agree that JavaScript (client side) would
>> seem like a good idea, but as I have written above, I cant get it to
>> work inside a TYPO3 page. Any ideas?
>
> There is a hook to manipulate the whole output. The following
> extension uses
> it:
> http://typo3.org/extensions/repository/view/naw_securedl/current/
>
> This should give you an overview over the page rendering process:
>
>
>
>>> There are often different ways to reach your goal in TYPO3 as you
>>> may have noticed, I don't thinnk there is a "best way" for your problem.
>>> I'd try the pure javascript approach since it may be the easiest for you.
>>>
>>>> Also, it appears that TypoScript does not seem to be a full-fledged
>>>> Server side programming language, or am I missing something? If
>>>> not, is there something else as well like server side JavaScript in Typo3?
>>>
>>> Typoscript ain't a "programming language" at all :)
>>> See: http://tinyurl.com/6gtegxg (What is Typoscript)
>>
>> Ah right, So am I right in thinking that TYPO3, support call-outs to
>> PHP as the server-side language? If so, is there a mechanism in
>> TYPO3, for me to call a PHP script before the entire page is output
>> from TYPO3, and then somehow in PHP modify the DOM of that page,
>> before returning it to the web-browser?
> see above... there are plenty ways:
> http://buzz.typo3.org/people/stucki/article/typo3-frontend-rendering-
> explained/
>
> Best regards
> --
> Philipp Gampe
> _______________________________________________
> TYPO3-english mailing list
> TYPO3-english at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english
>



--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk
_______________________________________________
TYPO3-english mailing list
TYPO3-english at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english


More information about the TYPO3-english mailing list