Appending categories with template via AMI and PHP - php

I'm using a PHP library to update config files of asterisk.
I add a user like this:
$a->write('Action: updateconfig\r\nReload: yes\r\nSrcfilename: users.conf\r\nDstfilename: users.conf\r\nAction-000000: NewCat\r\nCat-000000:test\r\nAction-000001: append\r\nCat-000001: test\r\nVar-000001: mailbox\r\nValue-000001: test\r\n ...etc user fields');
But also I have a template templatename so I want to add categories with template. I found this question, where is talled that you need simply change category name to test [(templatename)]. But this simply doesn't create anything.
If you need I can post library but it's just custom library with sockets.

You should use quoted string if you sending something like that.
Also it is highly NOT recommended use users.conf in case if you are not guru.
Reason: it can result not what you expect/insecure sections.
Use sip.conf or iax2.conf.

Related

TYPO3 - How to make a get request to a controller action

I have an application in TYPO3 CMS. It has an extension test_extension that has a controller and an action. This action should return some JSON.
class TestRequestController extends ActionController
{
public function testAction(): void
{
echo json_encode([
'test' => 123
]);
}
}
I want to be able to request this action via Postman. How can I do that? TYPO3 version - 8.7. Thanks in advance!
Creating Links
Usually extbase-extensions are created with the help of the extension extension_builder. This extension creates by default templates and links to open list- and detail-view.
It's possible to add additional actions and to create according links.
Also the usage of the templates is not required and your way to return the result of the action without usage of a template is possible.
The logic of the links is this, I break the parts down in single lines:
tx_extension_plugin[controller]=TestRequest
tx_extension_plugin[action]=test
There are still more parameters commonly used like id or search, but it's also possible to define individual parameters.
In your case the listed parameters seem to be sufficient and the link would look like this now:
www.example.com/?id=123&tx_extension_plugin[controller]=TestRequest&tx_extension_plugin[action]=test
for the extension news this would look like this, this is with your parameter-values which are not available in news. This example shows only how the extension-related part is handled (tx_news_pi1):
www.example.com/?id=123&tx_news_pi1[controller]=TestRequest&tx_news_pi1[action]=test
id is for the page here and not a parameter for your extension, else id had to look like this tx_extension_plugin[id]=123. So all extension related parameters have the form tx_extension_plugin[parameter]=value.
While it's possible to create those links with the API, it's easier to create them with the view helpers for the fluid templates. Note that sometimes an hash is added at the end, like this example: &cHash=1234567890.
The cHash-value you can't create without viewHelper or API, so the knowledge about the parameters and the other values is not enough to create the links.
Calling the link
Most often links are directly called by the browser and visible in the URL-bar. But sometimes and in your case you might call the links by AJAX, so that the json is loaded without being directly shown to the user.
It's also possible to wrap the json in script-tags, so that it's every time loaded when the whole page is called, it's not dynamic then and without AJAX it can't adjust to some user-interaction without loading a whole page again.
AJAX responses can be realized in many ways in TYPO3, the most easy one is to define a special page-type and a special page in the pagetree for it. On this page you add the plugin of your extension to return the json. This "Ajax-page" has to be configured to have the correct header for Json and must not return anything else but the JSON, so all HTML-Output has to be disabled.

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.

ezPublish: Unknown template variable 'view_parameters' in namespace in design/dffestival/templates/page_footer.tpl

We have received below errors on the home page:
eZTemplate # design/dffestival/templates/page_footer.tpl:8[6]:
Unknown template variable 'view_parameters' in namespace ''
In our pagefooter.tpl file have below code:
<div class="attribute-layout">
{attribute_view_gui attribute=$footerNode.data_map.layout view_parameters=$view_parameters}
</div>
We are using eZ Publish Community Project 2012.6 version.
Could anyone explain why I can't retrieve the view_parameters variable and how to do retrieve it?
Thanks
Sunil
Maybe u should start here:
http://www.ezpedia.org/ez/view_parameters
Remember view parameters are by default available only within the
context of the content module and it's views.
All other modules (by default) do not support this feature.
The recommended alternative to view parameters in these situations
would be using get / post parameters instead.
Or here:
https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Templates/Basic-template-tasks/Custom-view-parameters
In some cases $view_parameters won't work, try
$module_result.view_parameters there. So the example above will be:
The color is: {$module_result.view_parameters.color} The amount
is: {$module_result.view_parameters.amount}
Or here (check "$module_result section"):
https://doc.ez.no/eZ-Publish/Technical-manual/3.10/Templates/The-pagelayout/Variables-in-pagelayout
Short answer :
You are trying to retrieve the $view_parameters within the pagelayout (or a template included in it). This is not possible by design and this is completely normal.
Long answer :
View parameters are meant to be used from the views/templates which are used by the content module : for instance, when viewing a content from its alias URL or using its system URL like /content/view/full/2.
They are useful if you want to pass some parameters from the URL to the content view and they are taken into account by the cache system which is a very important thing to keep in mind (this is not the case when using "vanilla" GET parameters).
The main usage is for pagination, for instance : /content/view/full/2/(offest)/2/(limit)10
One of the best practices when developing with eZ Publish (legacy) is to ask yourself : why do you need to retrieve these parameters into your layout ? I guess that you want to control your global layout using them and this is not a good idea.
If you want to control the layout based on something which depends on the content, then I'll suggest to use persistent variables. You will basically use the ezpagedata_set operator in the content/view template and retrieve this value in your pagelayout with ezpagedata() | see https://doc.ez.no/doc_hidden/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Miscellaneous/ezpagedata_set
Last but not least, remember that the module result is computed before the pagelayout (simply because the pagelayout will include this result using $module_result.content).

How to find location of Smarty custom function

I'm not so familiar with Smarty. In the code I'm exploring, I have found such construction:
...
Can't understand, how does that url construction work. Looks like it is some custom method (or whatever it's called) in our project. But the project is quite large and I can't find it's definition just by word url.
Where to look for? What can it be?
url - is a Smarty custom plugin, which you can find in smartys' plugin folder. a.category, a.subcategory, a.nice_url: are params that passed to the url.
The following:
{url ...}
url is the custom Smarty Function. You can find it in Smarty plug-in directory or in a file that keeps all functions (if there is one) for your project.
In case you want to find the ends, just search through your whole web-site directory for the following content:
smarty_function_url
It must be found anyway, because it's the only way you can register custom Smarty function.
EDIT 1:
As correctly stated by sofl, if the plug-in is registered dynamically using registerPlugin method:
$smarty->registerPlugin("function","url", ...)
then you would have to search for the following instead:
registerPlugin("function","url"
or
registerPlugin(" function ", " url "
If it still doesn't work just try searching for ->registerPlugin, I think there is no other options left after all and you will find it!

include typoscript with php

Is it possible to include a typoscript file via php?
Normally I would include typoscript with this:
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/1.ts">
But I want to do this just with php and not typoscript. Is that possible?
My Purpose: I want to dynamically load typoscript in my page
This can be achieved by invoking accordant functions at an early stage, e.g. in calling or delegating it in ext_localconf.php. For example, the bookstrap package is loading TypoScript in PHP like this:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY
. '/Configuration/PageTS/Mod/Wizards/newContentElement.txt">'
);
Please consider, that TypoScript is cached before the actual front-end rendering starts. This means, that you should not modify TypoScript if you're plugin class or controller logic has been called already.
May be you need to return a value from the php function and use typoscript conditions for choosing the typoscript file.
You might try the following (if I get you right):
$typoscriptFile .= file_get_contents($someFile);
$parser = t3lib_div::makeInstance('t3lib_TSparser');
$parser->parse($typoscriptFile);
$tsArray = $parser->setup;
I really don't know how well that will play with anything related to global typoscript though.
If you wanted a complete correct parse, you might be able to pull something like this off if you populated a fresh t3lib_TStemplate instance from $GLOBALS['TSFE']->tmpl and than ran the code above. Might work, never tried.

Categories