| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/a/w/e/awebpaca/piwik/plugins/TagManager/Template/Variable/ |
Upload File : |
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\TagManager\Template\Variable;
use Piwik\Settings\FieldConfig;
use Piwik\Validators\NotEmpty;
class CustomJsFunctionVariable extends BaseVariable
{
const ID = 'CustomJsFunction';
public function getId()
{
return self::ID;
}
public function getCategory()
{
return self::CATEGORY_PAGE_VARIABLES;
}
public function isCustomTemplate()
{
return true;
}
public function getParameters()
{
return array(
$this->makeSetting('jsFunction', 'function () { return ""; }', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'JavaScript Function';
$field->description = 'The value should start with "function() { " and end with "return yourValue; }". You have to define a function and return a value. We highly recommend to test the pasted JavaScript function to avoid JavaScript errors on your website.';
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
$field->validators[] = new NotEmpty();
$field->validate = function ($value) {
$value = trim($value);
if (strpos($value, 'function') !== 0) {
throw new \Exception('The value needs to start with "function() { ... }"');
}
if (strpos($value, 'return ') === false) {
throw new \Exception('The function needs to return a value');
}
};
}),
);
}
public function loadTemplate($context, $entity)
{
if (!empty($entity['parameters']['jsFunction'])) {
$function = rtrim(trim($entity['parameters']['jsFunction']), ';');
return '(function () { return function (parameters, TagManager) { this.get = ' . $function .'; } })();';
}
}
}