Migrate php application to typo3 - php

I have a complex php application which I want to include in a typo3 page. I allready found something like this:
page.headerData.20 = PHP_SCRIPT_EXT
page.headerData.20.file = fileadmin/phpScript.inc
...but this inserts the file to template, I just want to show it on one single page instead of content. The application is currently included as an iFrame (same domain) but that's not the best way because the window doesn't resize.
In also think abouth to convert the whole app to typo3 plugin, but I'm very new to typo3 so I don't now how to start. Is there a guide for converting plain php to typo3 plugin?

Hi you can use a simple user extension.
Some where in Typoscript Setup:
includeLibs.mystuff = path_to_file/my_user_class.php
lib.mystuff = USER_INT
lib.mystuff {
userFunc =user_myclassname->main
var_to_pass_at_class=test
}
--
Now you can replace the subpart with dynamic content (depends on your TYPO3 configuration)
+- page.10.subparts.CONTENT<lib.mystuff
--
File: my_user_class.php
<?php
class user_myclassname {
function main($content,$conf){
global $TSFE;
return $conf['var_to_pass_at_class']; //returns test
}
}

Related

Running an external PHP script within a page of Octobercms

to speed up the creation of a CRUD interface in the frontend I am trying to use an external tool/program called PDOCrud within octobercms (PHP 7.2). PDOCrud does perfectly its job when works alone but I am facing problem to integrate it in Octobercms (I hope it can be integrated).
This is the normal code of PDOCrud to render a crud interface:
require_once base_path('script/pdocrud.php');
$pdocrud = new PDOCrud();
echo $pdocrud->dbTable("tablename")->render();
This is how I included it in a normal page
title = "Make tournament"
url = "/make-tournament"
layout = "Default"
description = "some description"
is_hidden = 0
==
<?php
function onstart() {
require_once base_path('script/pdocrud.php');
$this['crud'] = new class {
public function foo() {
$pdocrud = new PDOCrud();
return $pdocrud->dbTable("tablename")->render();
// return phpinfo();
}
};
}
?>
==
<h1>Make crud</h1>
{{ crud.foo()|raw }}
The form appears. But the buttons for crud operations does not perform any actions. Perhaps the session of octobercms collide with that of the external code, or jquery that it is loaded perhaps two times.
Does anybody tried a similar approach and solved the problem?
EDIT: I tried the suggestions but it did not work for me, maybe I missed something. Just few hours ago the author of the external program made un upgrade and my previous code worked perfectly. I am aware of not using properly the framework but I need a workaround to face a deadline. Thanks to all of you!
Using PDOCrud for this purpose is overlooking a significant amount of the features that are built into OctoberCMS. It would be very simple to create a custom plugin for yourself and integrate the incredibly powerful and easy to use backend forms in a component to use on your frontend.
See
https://octobercms.com/plugin/rainlab-builder
https://octobercms.com/docs/backend/forms
https://octobercms.com/forum/post/using-backend-forms-in-frontend

How to call TYPO3 plugin when normal page renders

Well, I am developing a plugin a and I need to display some stuff from my plugin when TYPO3 page load.
Is there some function how to hook action, like in WordPress when page loads than plugin will execute some controller method? Then this controller will produce some output a HTML, which I would like to dispaly in frontend page. Specially I would like display custom script in the head. So the script should be like this <head>...<script>my content</script>...</head>
Ok, what you probably want to do is to develop a so-called TYPO3 extension - that's what plugins/add-ons are called in TYPO3 (which is the term you will likely find google results for).
To get started fast you can try the TYPO3 extension builder (https://docs.typo3.org/typo3cms/extensions/extension_builder/) - which can generate a skeleton extension for you.
For more information you can also have a look at https://docs.typo3.org/typo3cms/CoreApiReference/latest/ExtensionArchitecture/Index.html which explains the concepts in far more detail.
Additional information is available in https://docs.typo3.org/typo3cms/ExtbaseFluidBook/Index.html
in TYPO3 there is something named plugins, but you should differ to the meaning in other context.
first TYPO3 is a CMS which content is structured in a hierarchical tree of pages. These pages are the basis for navigation. and each page contains individual contentelmenents (CE).
As Susi already told: add ons to TYPO3 are in general 'extensions' which could extend(!) the functinality of TYPO3 in different ways. one way is the definition of (TYPO3-)Plugins. These are special ContentElements which enable to show special information.
While normal CEs have all the information what to show in the record (e.g. Text & Image), plugins can be more flexible.
typical examples are: show a list of records OR one record in detail.
These Plugins can be controlled with typoscript or the plugin-CE could have additional fields to hold information what to display.
For detailed information how a plugin is defined consult the links given by Susi.
And be aware: for security reasons it is not possible to just execute a plain PHP file to echo any output. You need to register your plugin using the API, build your output as string and return the generated HTML as string to the calling function. For beginners the ExtensionBuilder will help you to generate a well formed extension which uses the API to register and output your data.
OK guys, thanks for your answers, but it was not very concrete. I found this solution, is not the best one, but it works! If anybody has better please share.
At first, you have to make a file for the class which will be called from the hook at location /your-plugin-name/Classes/class.tx_contenthook.php. Filename have to have this pattern class.tx_yourname.php Inside we will have a code with one method which will be called by the hook.
class tx_contenthook {
function displayContent(&$params, &$that){
//content of page from param
$content = $params['pObj']->content;
//your content
$inject = '4747474747';
// inject content on
$content = str_replace('</body>', $inject. '</body>', $content);
// save
$params['pObj']->content = $content;
}
}
And next, we have to call it on the hook. So Let's go to /your-plugin-name/ext_localconf.php and add there these two lines, which makes a magic and handles also caching.
// hook is called after caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'][] = 'EXT:' . $_EXTKEY . '/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
// hook is called before caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all'][] = 'EXT:'. $_EXTKEY .'/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
I hope this will help those who struggling with typo3.

CKFinder 3 upgrade difficulty

I'm following the CKFinder 2 to 3 upgrade guide and it's not making much sense. In CKFinder 2, the PHP code provided could be used to generate the JS snippet with appropriate config and params, like this:
require_once 'ckfinder/core/ckfinder_php5.php';
$finder = new CKFinder() ;
$finder->SelectFunction = 'ShowFileInfo' ;
$finder->DisableThumbnailSelection = true;
$finder->RememberLastFolder = true;
$finder->Id = $name;
$finder->StartupFolderExpanded = true;
$finder->Width = $width;
$finder->Height = $height;
echo $finder->CreateHtml();
This code picks up the config and incorporates it into the generated JS.
In 3 this seems to have disappeared entirely - the upgrade guide describes the changes needed in config.php, but there is no indication of how this is ever used since there is no other PHP involved, and it says
It is no longer possible to enable CKFinder on a page from the PHP level
All that is shown is how to create the JS snippet, which does not contain any config, and so will use incorrect settings. There is no indication of how the config properties set in config.php ever get to the JS code - as far as I can see there is no connection at all and no mention of any other PHP files, even though some are provided but not documented.
This makes no sense - PHP can quite happily generate HTML and JS that is run on the page, which is all the old CreateHTML function did. I don't understand why there is no mention of this mechanism since it was how we were supposed to use CKFinder previously - it's as if the migration guide is for some unrelated package!
If I update the config file and use the default JS widget code as suggested, it breaks the page completely, altering the MIME output type so it does not get rendered as HTML and appends this error:
{"error":{"number":10,"message":"Invalid command."}}
The docs cover various fine details of what PHP config settings mean, but nowhere that I've found says how it's ever loaded, triggered or associated with the JS. How is this supposed to work?
Indeed the CKFinder 3 documentation was lacking some important information. We're gradually adding new articles there. Based on topics you mentioned I just added:
Explanation how PHP code that worked for CKFinder 2 can be refactored to plain JavaScript in CKFinder 3. Should look familiar ;)
A table with Configuration Options Migration - JavaScript Settings which should help you with discovering again options like rememberLastFolder

Include PHP file into TemplaVoilà template through TypoScript

I need to include a PHP file (containing some database-checks 'n' stuff) into a very bad programmed TYPO3 website. They used TemplaVoilà for templating purposes. This is the definition in the master TypoScript template:
[...]
page = PAGE
page {
[...]
10 = USER
10.userFunc = tx_templavoila_pi1->main_page
[...]
}
[...]
Within the used TemplaVoilà template they mapped the main content div (where I'd like to insert my PHP script) with the attribute „field_content“. Don't know if this helps to answer my question.
I tried nearly everything I know to somehow overwrite/fill the „Main Content Area“ through TypoScript, as it is completly empty () on the page I created for my PHP file.
Is it possible to fill a specific mapped tag with my PHP file through TypoScript?
(TYPO3 Version 4.5.32)
I figured out a solution for my problem: With the hint in the answer by Urs (using _INT) I altered an already included DS object to be extended through additional sub-objects (as the markup allows my code to be placed there with some modifications to the stylesheet):
lib.social.20 = PHP_SCRIPT_INT
lib.social.20.file = fileadmin/path_to_my_file
Now it works like a charm althrough it's a bit hacky...
What about
lib.myscript= USER
lib.myscript {
userFunc =user_myScript->main
}
and in the DS
<TypoScript><![CDATA[
10 < lib.myscript
]]></TypoScript>
I'm no TemplaVoilà expert, I just pulled the second snippet from http://typo3-beispiel.net/index.php?id=10
PS: if its's USER, it will be cached, if it's USER_INT, it will prevent static file caching. So you may be better off running those checks in the background via AJAX?

Determine Joomla version in plugin

I'm making a simple Joomla plugin that loads a CSS file, but I want to load a different file for Joomla 2.5 and 3.2, using a PHP if-else statement. Is it possible to determine the Joomla version of the site using PHP?
You can use the named constant JVERSION or if you need more functions use the JVersion object like:
$j = new JVersion()
echo $j->getLongVersion();
echo $j->$RELEASE;

Categories