<commit_before><?php
// (c) Copyright 2002-2011 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_perspective_info() {
	return array(
		'name' => tra('Perspective'),
		'documentation' => 'PluginPerspective',
		'description' => tra('Display content based on the user\'s current perspective'),
		'prefs' => array( 'feature_perspective', 'wikiplugin_perspective' ),
		'body' => tra('Wiki text to display if conditions are met. The body may contain {ELSE}. Text after the marker will be displayed to users not matching the condition.'),
		'prefs' => array('wikiplugin_perspective'),
		'filter' => 'wikicontent',
		'params' => array(
			'perspectives' => array(
				'required' => false,
				'name' => tra('Allowed Perspectives'),
				'description' => tra('Pipe separated list of perspectives allowed to view the block. Perspectives may be specified by name or id. ex: Admins|2|Managers'),
				'filter' => 'text',
				'default' => ''
			),
			'notperspectives' => array(
				'required' => false,
				'name' => tra('Denied Perspectives'),
				'description' => tra('Pipe separated list of perspectives denied from viewing the block. Perspectives may be specified by name or id. ex: Anonymous|Managers|1'),
				'filter' => 'text',
				'default' => ''
			),
		),
	);
}

function wikiplugin_perspective($data, $params)
{
	global $access, $prefs, $perspectivelib;
	$access->check_feature('feature_perspective');

	require_once 'lib/perspectivelib.php';
	$currentPerspective = $perspectivelib->get_current_perspective( $prefs );

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

	if (!empty($params['perspectives'])) {
		$perspectives = array();
		foreach (explode('|', $params['perspectives']) as $p) {
			$perspectives[] = (!is_numeric($p))
				? $perspectivelib->get_perspective_with_given_name($p)
				: $p;
		}
	}

	if (!empty($params['notperspectives'])) {
		$notperspectives = array();
		foreach (explode('|', $params['notperspectives']) as $p) {
			$notperspectives[] = (!is_numeric($p))
				? $perspectivelib->get_perspective_with_given_name($p)
				: $p;
		}
	}

	if (!empty($perspectives) && !in_array($currentPerspective, $perspectives)) {
		return $dataelse;
	}

	if (!empty($notperspectives) && in_array($currentPerspective, $notperspectives)) {
		return $dataelse;
	}

	return $data;
}<commit_msg>[FIX] set svn:keywords Id property, removed redefinition of prefs element, reworded descriptions, removed identification by perspective name due to ambiguity.<commit_after><?php
// (c) Copyright 2002-2011 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_perspective_info() {
	return array(
		'name' => tra('Perspective'),
		'documentation' => 'PluginPerspective',
		'description' => tra('Display content based on the user\'s current perspective'),
		'prefs' => array( 'feature_perspective', 'wikiplugin_perspective' ),
		'body' => tra('Wiki text to display if conditions are met. The body may contain {ELSE}. Text after the marker will be displayed to users not matching the condition.'),
		'filter' => 'wikicontent',
		'params' => array(
			'perspectives' => array(
				'required' => false,
				'name' => tra('Allowed Perspectives'),
				'description' => tra('Pipe separated list of Ids for perspectives in which the block is shown. ex: 2|3|5'),
				'filter' => 'text',
				'default' => ''
			),
			'notperspectives' => array(
				'required' => false,
				'name' => tra('Denied Perspectives'),
				'description' => tra('Pipe separated list of Ids for perspectives in which the block is not shown. ex: 3|5|8'),
				'filter' => 'text',
				'default' => ''
			),
		),
	);
}

function wikiplugin_perspective($data, $params)
{
	global $prefs, $perspectivelib;

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

	if (!empty($params['perspectives'])) {
		$perspectives = explode('|', $params['perspectives']);
	}
	if (!empty($params['notperspectives'])) {
		$notperspectives = explode('|', $params['notperspectives']);
	}
	if (empty($perspectives) && empty($notperspectives)) {
		return '';
	}

	require_once 'lib/perspectivelib.php';
	$currentPerspective = $perspectivelib->get_current_perspective( $prefs );

	// if the current perspective is not an allowed perspective, return the content after the "{ELSE}"
	if (!empty($perspectives) && !in_array($currentPerspective, $perspectives)) {
		return $dataelse;
	}

	// if the current perspective is a denied perspective, return the content after the "{ELSE}"
	if (!empty($notperspectives) && in_array($currentPerspective, $notperspectives)) {
		return $dataelse;
	}

	return $data;
}
{'fraction_non_alphanumeric': 0.16100213633715285, 'fraction_numerical': 0.005437949116333269, 'mean_word_length': 4.767077267637178, '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': '7476507', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1626, 'n_words': 449}