<commit_before><cfscript>

/**
 * Creates a link to another page in your application.
 * Pass in the name of a route to use your configured routes or a controller/action/key combination.
 * Note: Pass any additional arguments like class, rel, and id, and the generated tag will also include those values as HTML attributes.
 *
 * [section: View Helpers]
 * [category: Link Functions]
 *
 * @text The text content of the link.
 * @route Name of a route that you have configured in config/routes.cfm.
 * @controller Name of the controller to include in the URL.
 * @action Name of the action to include in the URL.
 * @key Key(s) to include in the URL.
 * @params Any additional parameters to be set in the query string (example: wheels=cool&x=y). Please note that CFWheels uses the & and = characters to split the parameters and encode them properly for you. However, if you need to pass in & or = as part of the value, then you need to encode them (and only them), example: a=cats%26dogs%3Dtrouble!&b=1.
 * @anchor Sets an anchor name to be appended to the path.
 * @onlyPath If true, returns only the relative URL (no protocol, host name or port).
 * @host Set this to override the current host.
 * @protocol Set this to override the current protocol.
 * @port Set this to override the current port number.
 * @href Pass a link to an external site here if you want to bypass the CFWheels routing system altogether and link to an external URL.
 * @encode [see:styleSheetLinkTag].
 */
public string function linkTo(
	string text,
	string route="",
	string controller="",
	string action="",
	any key="",
	string params="",
	string anchor="",
	boolean onlyPath,
	string host,
	string protocol,
	numeric port,
	string href,
	any encode
) {
	$args(name="linkTo", args=arguments);

	// look for passed in rest method
	if (StructKeyExists(arguments, "method")) {

		// if dealing with delete, keep robots from following link
		if (arguments.method == "delete") {
			if (!StructKeyExists(arguments, "rel")) {
				arguments.rel = "";
			}
			arguments.rel = ListAppend(arguments.rel, "no-follow", " ");
		}
	}

	local.encodeExcept = "";
	if (!StructKeyExists(arguments, "href")) {
		local.args = Duplicate(arguments);
		local.args.$encodeForHtmlAttribute = true;
		if (local.args.encode == "attributes") {
			local.args.encode = true;
		}
		arguments.href = URLFor(argumentCollection=local.args);
		local.encodeExcept = "href";
	}
	if (!StructKeyExists(arguments, "text")) {
		arguments.text = arguments.href;
	}
	local.skip = "text,route,controller,action,key,params,anchor,onlyPath,host,protocol,port,encode";
	if (Len(arguments.route)) {
		// variables passed in as route arguments should not be added to the html element
		local.skip = ListAppend(local.skip, $routeVariables(argumentCollection=arguments));
	}
	return $element(
		name="a",
		skip=local.skip,
		content=arguments.text,
		attributes=arguments,
		encode=arguments.encode,
		encodeExcept=local.encodeExcept
	);
}

/**
 * Creates a form containing a single button that submits to the URL.
 * The URL is built the same way as the `linkTo` function.
 *
 * [section: View Helpers]
 * [category: Link Functions]
 *
 * @text The text content of the button.
 * @image If you want to use an image for the button pass in the link to it here (relative from the `images` folder).
 * @route [see:URLFor].
 * @controller [see:URLFor].
 * @action [see:URLFor].
 * @key [see:URLFor].
 * @params [see:URLFor].
 * @anchor [see:URLFor].
 * @onlyPath [see:URLFor].
 * @host [see:URLFor].
 * @protocol [see:URLFor].
 * @port [see:URLFor].
 * @encode [see:styleSheetLinkTag].
 */
public string function buttonTo(
	string text,
	string image,
	string route="",
	string controller="",
	string action="",
	any key="",
	string params="",
	string anchor="",
	boolean onlyPath,
	string host,
	string protocol,
	numeric port,
	any encode
) {
	local.method = "post";
	$args(name="buttonTo", args=arguments);
	local.content = "";
	if (StructKeyExists(arguments, "method")) {
		if (!ListFindNoCase("post,get", arguments.method)) {
			local.content &= hiddenFieldTag(name="_method", value=arguments.method);
		} else if (arguments.method == "get") {
			local.method = "get";
		}
	}
	arguments.method = local.method;
	local.args = Duplicate(arguments);
	local.args.$encodeForHtmlAttribute = true;
	if (local.args.encode == "attributes") {
		local.args.encode = true;
	}
	arguments.action = URLFor(argumentCollection=local.args);
	local.encodeExcept = "action";
	local.args = $innerArgs(name="input", args=arguments);
	local.args.value = arguments.text;
	local.args.image = arguments.image;
	local.args.encode = arguments.encode;
	local.content &= submitTag(argumentCollection=local.args);
	local.skip = "image,text,route,controller,key,params,anchor,onlyPath,host,protocol,port,encode";
	if (Len(arguments.route)) {
		// variables passed in as route arguments should not be added to the html element
		local.skip = ListAppend(local.skip, $routeVariables(argumentCollection=arguments));
	}
	local.encode = arguments.encode ? "attributes" : false;
	return $element(name="form", skip=local.skip, content=local.content, attributes=arguments, encode=local.encode, encodeExcept=local.encodeExcept);
}

/**
 * Creates a `mailto` link tag to the specified email address, which is also used as the name of the link unless name is specified.
 *
 * [section: View Helpers]
 * [category: Link Functions]
 *
 * @emailAddress The email address to link to.
 * @name A string to use as the link text ("Joe" or "Support Department", for example).
 * @encode [see:styleSheetLinkTag].
 */
public string function mailTo(
	required string emailAddress,
	string name="",
	any encode
) {
	$args(name="mailTo", reserved="href", args=arguments);
	arguments.href = "mailto:" & arguments.emailAddress;
	local.content = Len(arguments.name) ? arguments.name : arguments.emailAddress;
	return $element(
		name="a",
		skip="emailAddress,name,encode",
		content=local.content,
		attributes=arguments,
		encode=arguments.encode
	);<commit_msg>Closes #808.<commit_after><cfscript>

/**
 * Creates a link to another page in your application.
 * Pass in the name of a route to use your configured routes or a controller/action/key combination.
 * Note: Pass any additional arguments like class, rel, and id, and the generated tag will also include those values as HTML attributes.
 *
 * [section: View Helpers]
 * [category: Link Functions]
 *
 * @text The text content of the link.
 * @route Name of a route that you have configured in config/routes.cfm.
 * @controller Name of the controller to include in the URL.
 * @action Name of the action to include in the URL.
 * @key Key(s) to include in the URL.
 * @params Any additional parameters to be set in the query string (example: wheels=cool&x=y). Please note that CFWheels uses the & and = characters to split the parameters and encode them properly for you. However, if you need to pass in & or = as part of the value, then you need to encode them (and only them), example: a=cats%26dogs%3Dtrouble!&b=1.
 * @anchor Sets an anchor name to be appended to the path.
 * @onlyPath If true, returns only the relative URL (no protocol, host name or port).
 * @host Set this to override the current host.
 * @protocol Set this to override the current protocol.
 * @port Set this to override the current port number.
 * @href Pass a link to an external site here if you want to bypass the CFWheels routing system altogether and link to an external URL.
 * @encode [see:styleSheetLinkTag].
 */
public string function linkTo(
	string text,
	string route="",
	string controller="",
	string action="",
	any key="",
	string params="",
	string anchor="",
	boolean onlyPath,
	string host,
	string protocol,
	numeric port,
	string href,
	any encode
) {
	$args(name="linkTo", args=arguments);

	// look for passed in rest method
	if (StructKeyExists(arguments, "method")) {

		// if dealing with delete, keep robots from following link
		if (arguments.method == "delete") {
			if (!StructKeyExists(arguments, "rel")) {
				arguments.rel = "";
			}
			arguments.rel = ListAppend(arguments.rel, "no-follow", " ");
		}
	}

	local.encodeExcept = "";
	if (!StructKeyExists(arguments, "href")) {
		local.args = Duplicate(arguments);
		local.args.$encodeForHtmlAttribute = true;
		if (local.args.encode == "attributes") {
			local.args.encode = true;
		}
		arguments.href = URLFor(argumentCollection=local.args);
		local.encodeExcept = "href";
	}
	if (!StructKeyExists(arguments, "text")) {
		arguments.text = arguments.href;
	}
	local.skip = "text,route,controller,action,key,params,anchor,onlyPath,host,protocol,port,encode";
	if (Len(arguments.route)) {
		// variables passed in as route arguments should not be added to the html element
		local.skip = ListAppend(local.skip, $routeVariables(argumentCollection=arguments));
	}
	return $element(
		name="a",
		skip=local.skip,
		content=arguments.text,
		attributes=arguments,
		encode=arguments.encode,
		encodeExcept=local.encodeExcept
	);
}

/**
 * Creates a form containing a single button that submits to the URL.
 * The URL is built the same way as the `linkTo` function.
 *
 * [section: View Helpers]
 * [category: Link Functions]
 *
 * @text The text content of the button.
 * @image If you want to use an image for the button pass in the link to it here (relative from the `images` folder).
 * @route [see:URLFor].
 * @controller [see:URLFor].
 * @action [see:URLFor].
 * @key [see:URLFor].
 * @params [see:URLFor].
 * @anchor [see:URLFor].
 * @onlyPath [see:URLFor].
 * @host [see:URLFor].
 * @protocol [see:URLFor].
 * @port [see:URLFor].
 * @encode [see:styleSheetLinkTag].
 */
public string function buttonTo(
	string text,
	string image,
	string route="",
	string controller="",
	string action="",
	any key="",
	string params="",
	string anchor="",
	boolean onlyPath,
	string host,
	string protocol,
	numeric port,
	any encode
) {
	local.method = "post";
	$args(name="buttonTo", args=arguments);
	local.content = "";
	if (StructKeyExists(arguments, "method")) {
		if (!ListFindNoCase("post,get", arguments.method)) {
			local.content &= hiddenFieldTag(name="_method", value=arguments.method);
		} else if (arguments.method == "get") {
			local.method = "get";
		}
	}
	arguments.method = local.method;
	local.args = Duplicate(arguments);
	local.args.$encodeForHtmlAttribute = true;
	if (local.args.encode == "attributes") {
		local.args.encode = true;
	}
	arguments.action = URLFor(argumentCollection=local.args);
	local.encodeExcept = "action";
	local.args = $innerArgs(name="input", args=arguments);
	local.args.value = arguments.text;
	local.args.image = arguments.image;
	local.args.encode = arguments.encode;
	local.content &= submitTag(argumentCollection=local.args);
	local.skip = "image,text,route,controller,key,params,anchor,onlyPath,host,protocol,port,encode";
	if (Len(arguments.route)) {
		// variables passed in as route arguments should not be added to the html element
		local.skip = ListAppend(local.skip, $routeVariables(argumentCollection=arguments));
	}
	local.encode = arguments.encode ? "attributes" : false;
	if ($isRequestProtectedFromForgery() && ListFindNoCase("post,put,patch,delete", arguments.method)) {
		local.content &= authenticityTokenField();
	}
	return $element(name="form", skip=local.skip, content=local.content, attributes=arguments, encode=local.encode, encodeExcept=local.encodeExcept);
}

/**
 * Creates a `mailto` link tag to the specified email address, which is also used as the name of the link unless name is specified.
 *
 * [section: View Helpers]
 * [category: Link Functions]
 *
 * @emailAddress The email address to link to.
 * @name A string to use as the link text ("Joe" or "Support Department", for example).
 * @encode [see:styleSheetLinkTag].
 */
public string function mailTo(
	required string emailAddress,
	string name="",
	any encode
) {
	$args(name="mailTo", reserved="href", args=arguments);
	arguments.href = "mailto:" & arguments.emailAddress;
	local.content = Len(arguments.name) ? arguments.name : arguments.emailAddress;
	return $element(
		name="a",
		skip="emailAddress,name,encode",
		content=local.content,
		attributes=arguments,
		encode=arguments.encode
	);
{'fraction_non_alphanumeric': 0.12603322694164826, 'fraction_numerical': 0.0009002373352974875, 'mean_word_length': 4.567198177676538, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6399610', 'n_tokens_mistral': 3760, 'n_tokens_neox': 3627, 'n_words': 1233}