<commit_before><?php
// (c) Copyright 2002-2010 by authors of the Tiki Wiki/CMS/Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: wikiplugin_tracker.php 29720 2010-09-29 13:57:55Z sylvieg $

// Test a tracker field value
// Usage:
// {TRACKERIF(test="(...)")}{ELSE}{TRACKERIF}
// test can be for example :
//      - (1=1)
//      - (1!=2)
//      - (2>1)
//      - (1<2)
//      - (3>=2)
//      - (2<=4)
//      - (f_xx=some_value) where xx is a field id in the tracker
//      - (f_xx=*value) f_xx must ends with value
//      - (f_xx=value*) f_xx must starts with value
//      - (f_xx=*value*) f_xx must contain value
//      - (&(f_xx=value)(f_yy=other_value)) test A and test B
//      - (|(f_xx=value)(f_yy=other_value)) test A or test B

require_once('lib/ldap/filter.php');
require_once('lib/trackers/trackerlib.php');

function wikiplugin_trackerif_info()
{
	return array(
		'name' => tra('Trackerif'),
		'description' => tra("Displays something after testing tracker fields"),
		'prefs' => array( 'feature_trackers', 'wikiplugin_tracker' ),
		'params' => array(
			'test' => array(
				'required' => true,
				'name' => tra('Test'),
				'description' => tra('Test'),
			),
		),
	);
}

function wikiplugin_trackerif($data, $params)
{
        global $trklib;

        if (!isset($_REQUEST['trackerId']) || !isset($_REQUEST['itemId'])) {
                return '';
        }

        $test = null;
        $values = array();
        $dataelse = '';

        try {
                // Parse test
                $test = LDAPFilter::parse($params['test']);
        } catch (Exception $e) {
                return $e->getMessage();
        }

	if (strpos($data,'{ELSE}')) {
                // Else bloc when test does not pass
		$dataelse = substr($data,strpos($data,'{ELSE}')+6);
		$data = substr($data,0,strpos($data,'{ELSE}'));
	}

        $xfields = $trklib->list_tracker_fields($_REQUEST["trackerId"]);

        foreach ($xfields['data'] as $field) {
                // Retrieve values from the current item
                $values[$field['fieldId']] = $trklib->get_item_value($_REQUEST['trackerId'], $_REQUEST['itemId'], $field['fieldId']);
        }

        if (!wikiplugin_trackerif_test($test, $values)) {
                if ($dataelse) {
                        return $dataelse;
                }<commit_msg>[MOD] Add an 'ignore' parameter to display the block content in edit mode<commit_after><?php
// (c) Copyright 2002-2010 by authors of the Tiki Wiki/CMS/Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: wikiplugin_tracker.php 29720 2010-09-29 13:57:55Z sylvieg $

// Test a tracker field value
// Usage:
// {TRACKERIF(test="(...)")}{ELSE}{TRACKERIF}
// test can be for example :
//      - (1=1)
//      - (1!=2)
//      - (2>1)
//      - (1<2)
//      - (3>=2)
//      - (2<=4)
//      - (f_xx=some_value) where xx is a field id in the tracker
//      - (f_xx=*value) f_xx must ends with value
//      - (f_xx=value*) f_xx must starts with value
//      - (f_xx=*value*) f_xx must contain value
//      - (&(f_xx=value)(f_yy=other_value)) test A and test B
//      - (|(f_xx=value)(f_yy=other_value)) test A or test B

require_once('lib/ldap/filter.php');
require_once('lib/trackers/trackerlib.php');

function wikiplugin_trackerif_info()
{
	return array(
		'name' => tra('Trackerif'),
		'description' => tra("Displays something after testing tracker fields"),
		'prefs' => array( 'feature_trackers', 'wikiplugin_tracker' ),
		'params' => array(
			'test' => array(
				'required' => true,
				'name' => tra('Test'),
				'description' => tra('Test'),
			),
			'ignore' => array(
				'required' => false,
				'name' => tra('Ignore'),
				'default' => 'y',
				'description' => tra('Ignore test in edit mode'),
			),
		),
	);
}

function wikiplugin_trackerif($data, $params)
{
        global $trklib;

        if (!isset($_REQUEST['trackerId']) || !isset($_REQUEST['itemId'])) {
		// Edit mode
		if (!isset($params['ignore']) || $params['ignore'] == 'y') {
			return $data;
		}

                return '';
        }

        $test = null;
        $values = array();
        $dataelse = '';

        try {
                // Parse test
                $test = LDAPFilter::parse($params['test']);
        } catch (Exception $e) {
                return $e->getMessage();
        }

	if (strpos($data,'{ELSE}')) {
                // Else bloc when test does not pass
		$dataelse = substr($data,strpos($data,'{ELSE}')+6);
		$data = substr($data,0,strpos($data,'{ELSE}'));
	}

        $xfields = $trklib->list_tracker_fields($_REQUEST["trackerId"]);

        foreach ($xfields['data'] as $field) {
                // Retrieve values from the current item
                $values[$field['fieldId']] = $trklib->get_item_value($_REQUEST['trackerId'], $_REQUEST['itemId'], $field['fieldId']);
        }

        if (!wikiplugin_trackerif_test($test, $values)) {
                if ($dataelse) {
                        return $dataelse;
                }
{'fraction_non_alphanumeric': 0.17729688686408504, 'fraction_numerical': 0.015565679574791193, 'mean_word_length': 2.434810951760104, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7237065', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1733, 'n_words': 410}