<commit_before><?php
// (c) Copyright 2002-2017 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: Controller.php 61553 2017-03-07 16:50:53Z jonnybradley $

/**
 * Class Services_Edit_PluginController
 *
 * Controller for editing and listing wiki plugins
 *
 */
class Services_Edit_PluginController
{
	private $pluginList;

	function __construct()
	{
		$this->pluginList = [];
	}

	function setUp()
	{
		Services_Exception_Disabled::check('feature_wiki');

		$this->pluginList = TikiLib::lib('wiki')->list_plugins(true);
	}

	/**
	 * List all or some of theplugins for the textarea control panel
	 *
	 * @param JitFilter $input
	 * @return array
	 */
	function action_list($input)
	{
		$filter = $input->filter->text();
		$title = $input->title->text();
		$res = [];

		if ($filter) {
			$query = 'wikiplugin_* AND ' . $filter;
			$sort = '';
		} else {
			$query = 'wikiplugin_*';
			$sort = 'object_id_asc';
		}
		$results = TikiLib::lib('prefs')->getMatchingPreferences($query, null, 500, $sort);

		foreach ($results as $result) {
			if (strpos($result, 'wikiplugin_') === 0) {
				$key = strtoupper(substr($result, 11));
				$arr = array_filter($this->pluginList, function ($plugin) use ($key) {
					return $plugin['name'] === $key;
				});

				foreach ($this->pluginList as $plugin) {
					if ($plugin['name'] === $key) {
						$res[strtolower($key)] = array_shift($arr);
						break;
					}
				}
			}
		}

		if (! $title) {
			if ($res) {
				$title = tr('Plugins found containing: %0', $filter);
			} else {
				$title = tr('No plugins found containing: %0', $filter);
			}
		}

		return array(
			'plugins' => $res,
			'title' => $title,
			'pref_filters' => TikiLib::lib('prefs')->getFilters(),
		);
	}

	/**
	 * Display plugin edit form or process saving changes
	 *
	 * @param JitFilter $input
	 * @return array
	 * @throws Services_Exception_BadRequest
	 * @throws Services_Exception_Denied
	 */
	function action_edit($input)
	{
		global $prefs;

		$parserlib = TikiLib::lib('parser');

		$area_id = $input->area_id->alnumdash();
		$type = $input->type->word();<commit_msg>[FIX] prefs: Obey filters for basic, advanced etc on plugins list<commit_after><?php
// (c) Copyright 2002-2017 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: Controller.php 61553 2017-03-07 16:50:53Z jonnybradley $

/**
 * Class Services_Edit_PluginController
 *
 * Controller for editing and listing wiki plugins
 *
 */
class Services_Edit_PluginController
{
	private $pluginList;

	function __construct()
	{
		$this->pluginList = [];
	}

	function setUp()
	{
		Services_Exception_Disabled::check('feature_wiki');

		$this->pluginList = TikiLib::lib('wiki')->list_plugins(true);
	}

	/**
	 * List all or some of theplugins for the textarea control panel
	 *
	 * @param JitFilter $input
	 * @return array
	 */
	function action_list($input)
	{
		$filter = $input->filter->text();
		$title = $input->title->text();
		$res = [];

		if ($filter) {
			$query = 'wikiplugin_* AND ' . $filter;
			$sort = '';
		} else {
			$query = 'wikiplugin_*';
			$sort = 'object_id_asc';
		}
		$filters = TikiLib::lib('prefs')->getFilters();
		$results = TikiLib::lib('prefs')->getMatchingPreferences($query, $filters, 500, $sort);

		foreach ($results as $result) {
			if (strpos($result, 'wikiplugin_') === 0) {
				$key = strtoupper(substr($result, 11));
				$arr = array_filter($this->pluginList, function ($plugin) use ($key) {
					return $plugin['name'] === $key;
				});

				foreach ($this->pluginList as $plugin) {
					if ($plugin['name'] === $key) {
						$res[strtolower($key)] = array_shift($arr);
						break;
					}
				}
			}
		}

		if (! $title) {
			if ($res) {
				$title = tr('Plugins found containing: %0', $filter);
			} else {
				$title = tr('No plugins found containing: %0', $filter);
			}
		}

		return array(
			'plugins' => $res,
			'title' => $title,
			'pref_filters' => $filters,
		);
	}

	/**
	 * Display plugin edit form or process saving changes
	 *
	 * @param JitFilter $input
	 * @return array
	 * @throws Services_Exception_BadRequest
	 * @throws Services_Exception_Denied
	 */
	function action_edit($input)
	{
		global $prefs;

		$parserlib = TikiLib::lib('parser');

		$area_id = $input->area_id->alnumdash();
		$type = $input->type->word();
{'fraction_non_alphanumeric': 0.16468296905431726, 'fraction_numerical': 0.015148236312486475, 'mean_word_length': 3.5402750491159134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '3302728', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1520, 'n_words': 387}