<commit_before><?php
// (c) Copyright 2002-2013 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$

define('WIKIPLUGIN_PARAM_REQUEST', 'request');

function wikiplugin_param_info()
{
	return array(
		'name' => tra('Param'),
		'documentation' => 'PluginParam',
		'description' => tra('Display content based on URL parameters'),
		'prefs' => array( 'wikiplugin_param' ),
		'body' => tra('Wiki text to display if conditions are met. The body may contain {ELSE}. Text after the marker will be displayed if conditions are not met.'),
		'icon' => 'img/icons/page_gear.png',
		'params' => array(
			'name' => array(
				'required' => true,
				'name' => tra('Name'),
				'description' => tra('Names of parameter required to display text')
			),
			'source' => array(
				'required' => false,
				'name' => tra('Source'),
				'default' => 'request',
				'description' => tra('Source where the parameter is checked. Possible values : request ...')
			)
		)
	);
}

function wikiplugin_param($data, $params)
{
	$dataelse = '';
   $names = array();
	$test = true;

	if (strpos($data, '{ELSE}')) {
		$dataelse = substr($data, strpos($data, '{ELSE}')+6);
		$data = substr($data, 0, strpos($data, '{ELSE}'));
	}

	if (!empty($params['name'])) {
		$names = explode('|', $params['name']);
	}

	if (!isset($params['source']) || empty($params['source'])) {
		$params['source'] = WIKIPLUGIN_PARAM_REQUEST;
	}

        foreach ($names as $name) {
		switch ($params['source']) {
			case WIKIPLUGIN_PARAM_REQUEST:
				$test &= (isset($_REQUEST[$name]) && !empty($_REQUEST[$name]));
    			break;
		}
        }

	return $test ? $data : $dataelse;
}<commit_msg>[ENH] param plugin: Extend the "source" to be able to test for cookies server-side (also added get and post for completeness).  Also some general modernisation and tidying up.<commit_after><?php
// (c) Copyright 2002-2013 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$


function wikiplugin_param_info()
{
	return array(
		'name' => tra('Param'),
		'documentation' => 'PluginParam',
		'description' => tra('Display content based on request parameters'),
		'prefs' => array( 'wikiplugin_param' ),
		'body' => tra('Wiki text to display if conditions are met. The body may contain {ELSE}. Text after the marker will be displayed if conditions are not met.'),
		'icon' => 'img/icons/page_gear.png',
		'params' => array(
			'name' => array(
				'required' => true,
				'name' => tra('Name'),
				'description' => tra('Names of parameters required to display text, separated by |.'),
				'filter' => 'text',
				'separator' => '|',
			),
			'source' => array(
				'required' => false,
				'name' => tra('Source'),
				'default' => 'request',
				'description' => tra('Source where the parameter is checked.'),
				'filter' => 'text',
				'options' => array (
					array('text' => tra('REQUEST'), 'value' => ''),
					array('text' => tra('GET'), 'value' => 'get'),
					array('text' => tra('POST'), 'value' => 'post'),
					array('text' => tra('COOKIE'), 'value' => 'cookie'),
				),
			)
		)
	);
}

function wikiplugin_param($data, $params)
{
	$dataelse = '';
	$test = true;

	if (strpos($data, '{ELSE}')) {
		$dataelse = substr($data, strpos($data, '{ELSE}') + 6);
		$data = substr($data, 0, strpos($data, '{ELSE}'));
	}

	if (!isset($params['source']) || empty($params['source'])) {
		$params['source'] = 'request';
	}

	foreach ($params['name'] as $name) {
		$value = null;
		switch ($params['source']) {
			case 'get':
				$value = isset($_GET[$name]) ? $_GET[$name] : null;
				break;
			case 'post':
				$value = isset($_POST[$name]) ? $_POST[$name] : null;
				break;
			case 'cookie':
				$value = isset($_COOKIE[$name]) ? $_COOKIE[$name] : null;
				break;
			default:
				$value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : null;
				break;
		}
		if (empty($value)) {	// multiple "names" work as AND
			$test = false;
			break;
		}
	}

	return $test ? $data : $dataelse;
}
{'fraction_non_alphanumeric': 0.1914992993928071, 'fraction_numerical': 0.004670714619336758, 'mean_word_length': 3.7536071032186458, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1672358', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1413, 'n_words': 407}