<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$

function wikiplugin_draw_info()
{
	return array(
		'name' => tra('Draw'),
		'documentation' => 'PluginDraw',
		'description' => tra('Display or create an image from TikiDraw that is stored into the File Gallery'),
		'prefs' => array( 'feature_draw' , 'wikiplugin_draw'),
		'icon' => 'img/icons/shape_square_edit.png',
		'tags' => array( 'basic' ),
		'params' => array(
			'id' => array(
				'required' => false,
				'name' => tra('Drawing ID'),
				'description' => tra('Internal ID of the file id'),
				'filter' => 'digits',
				'accepted' => ' ID number',
				'default' => '',
				'since' => '7.1',
				'profile_reference' => 'file',
			),
			'width' => array(
				'required' => false,
				'name' => tra('Width'),
				'description' => tra('Width in pixels or percentage. Default value is page width. e.g. "200px" or "100%"'),
				'filter' => 'striptags',
				'accepted' => 'Number of pixels followed by \'px\' or percent followed by % (e.g. "200px" or "100%").',
				'default' => 'Image width',
				'since' => '7.1'
			),
			'height' => array(
				'required' => false,
				'name' => tra('Height'),
				'description' => tra('Height in pixels or percentage. Default value is complete drawing height.'),
				'filter' => 'striptags',
				'accepted' => 'Number of pixels followed by \'px\' or percent followed by % (e.g. "200px" or "100%").',
				'default' => 'Image height',
				'since' => '7.1'
			),
			'archive' => array(
				'required' => false,
				'name' => tra('Force Display Archive'),
				'description' => tra('The latest revision of file is automatically shown, by setting archive to y, it bypasses this check and shows the archive rather than the latest revision'),
				'filter' => 'striptags',
				'accepted' => 'y or n',
				'default' => 'n',
				'since' => '8',
				'options' => array(
					array('text' => '', 'value' => ''),
					array('text' => tra('Yes'), 'value' => 'y'),
					array('text' => tra('No'), 'value' => 'n')
				)
			),
		),
	);
}

function wikiplugin_draw($data, $params)
{
	global $dbTiki, $tiki_p_edit, $tiki_p_admin,$tiki_p_upload_files, $prefs, $user, $page, $tikilib, $smarty, $headerlib, $globalperms;
	global $filegallib; include_once ('lib/filegals/filegallib.php');
	extract(array_merge($params, array()), EXTR_SKIP);

	static $drawIndex = 0;
	++$drawIndex;

	if (!isset($id)) {
		//check permissions
		if ($tiki_p_upload_files != 'y') {
			return;
		}

		$label = tra('Draw New SVG Image');
		$page = htmlentities($page);
		$content = htmlentities($data);
		$formId = "form$drawIndex";
		$gals=$filegallib->list_file_galleries(0, -1, 'name_desc', $user);

		$galHtml = "";
		function cmp($a, $b) {
			return strcmp(strtolower($a["name"]), strtolower($b["name"]));
		}
		usort($gals['data'], 'cmp');
		foreach ($gals['data'] as $gal) {
			if ($gal['name'] != "Wiki Attachments" && $gal['name'] != "Users File Galleries")
				$galHtml .= "<option value='".$gal['id']."'>".$gal['name']."</option>";
		}

		$in = tr(" in ");

		$headerlib->add_jq_onready(
<<<JQ
			$('#newDraw$drawIndex').submit(function() {
				var form = $(this);
				var fields = form.serializeArray();
				$.wikiTrackingDraw = {
					fileId: 0,
					page: '$page',
					index: '$drawIndex',
					label: '$label',
					type: 'draw',
					content: '',
					params: {<commit_msg>[FIX] Possible fatal error with multiple draw plugin per page<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_draw_info()
{
	return array(
		'name' => tra('Draw'),
		'documentation' => 'PluginDraw',
		'description' => tra('Display or create an image from TikiDraw that is stored into the File Gallery'),
		'prefs' => array( 'feature_draw' , 'wikiplugin_draw'),
		'icon' => 'img/icons/shape_square_edit.png',
		'tags' => array( 'basic' ),
		'params' => array(
			'id' => array(
				'required' => false,
				'name' => tra('Drawing ID'),
				'description' => tra('Internal ID of the file id'),
				'filter' => 'digits',
				'accepted' => ' ID number',
				'default' => '',
				'since' => '7.1',
				'profile_reference' => 'file',
			),
			'width' => array(
				'required' => false,
				'name' => tra('Width'),
				'description' => tra('Width in pixels or percentage. Default value is page width. e.g. "200px" or "100%"'),
				'filter' => 'striptags',
				'accepted' => 'Number of pixels followed by \'px\' or percent followed by % (e.g. "200px" or "100%").',
				'default' => 'Image width',
				'since' => '7.1'
			),
			'height' => array(
				'required' => false,
				'name' => tra('Height'),
				'description' => tra('Height in pixels or percentage. Default value is complete drawing height.'),
				'filter' => 'striptags',
				'accepted' => 'Number of pixels followed by \'px\' or percent followed by % (e.g. "200px" or "100%").',
				'default' => 'Image height',
				'since' => '7.1'
			),
			'archive' => array(
				'required' => false,
				'name' => tra('Force Display Archive'),
				'description' => tra('The latest revision of file is automatically shown, by setting archive to y, it bypasses this check and shows the archive rather than the latest revision'),
				'filter' => 'striptags',
				'accepted' => 'y or n',
				'default' => 'n',
				'since' => '8',
				'options' => array(
					array('text' => '', 'value' => ''),
					array('text' => tra('Yes'), 'value' => 'y'),
					array('text' => tra('No'), 'value' => 'n')
				)
			),
		),
	);
}

function wikiplugin_draw($data, $params)
{
	global $dbTiki, $tiki_p_edit, $tiki_p_admin,$tiki_p_upload_files, $prefs, $user, $page, $tikilib, $smarty, $headerlib, $globalperms;
	global $filegallib; include_once ('lib/filegals/filegallib.php');
	extract(array_merge($params, array()), EXTR_SKIP);

	static $drawIndex = 0;
	++$drawIndex;

	if (!isset($id)) {
		//check permissions
		if ($tiki_p_upload_files != 'y') {
			return;
		}

		$label = tra('Draw New SVG Image');
		$page = htmlentities($page);
		$content = htmlentities($data);
		$formId = "form$drawIndex";
		$gals=$filegallib->list_file_galleries(0, -1, 'name_desc', $user);

		$galHtml = "";
		if (!function_exists('wp_draw_cmp')) {
			function wp_draw_cmp($a, $b) {
				return strcmp(strtolower($a["name"]), strtolower($b["name"]));
			}
		}
		usort($gals['data'], 'wp_draw_cmp');
		foreach ($gals['data'] as $gal) {
			if ($gal['name'] != "Wiki Attachments" && $gal['name'] != "Users File Galleries")
				$galHtml .= "<option value='".$gal['id']."'>".$gal['name']."</option>";
		}

		$in = tr(" in ");

		$headerlib->add_jq_onready(
<<<JQ
			$('#newDraw$drawIndex').submit(function() {
				var form = $(this);
				var fields = form.serializeArray();
				$.wikiTrackingDraw = {
					fileId: 0,
					page: '$page',
					index: '$drawIndex',
					label: '$label',
					type: 'draw',
					content: '',
					params: {
{'fraction_non_alphanumeric': 0.20085588072887908, 'fraction_numerical': 0.010215350635008284, 'mean_word_length': 3.6, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 105, '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': '3851823', 'n_tokens_mistral': 2949, 'n_tokens_neox': 2501, 'n_words': 679}