Skip to content

[FIX] function.smart_display_field.php #21

Open
@stfour

Description

@stfour

Hi Benkeen, may I propose these changes to .php in the subject? This fix csv output if there are textarea fields:

function smarty_function_smart_display_field($params, &$smarty)
{
    $value = FieldTypes::generateViewableField($params);

    // additional code for CSV encoding
    if (isset($params["escape"])) {
        if ($params["escape"] == "csv") {
			// Check if we need to enclose field between double quotas
			$needQuote = (strstr($value, ",") || strstr($value, "\n"));
			// trim spaces and other useless char
			$value = trim($value);
			$value = preg_replace("/\"/", "\"\"", $value);
			// replace inner "\n" or "\r" with '|' character, otherwhise csv will be corrupted.
			$value = str_replace(array("\n","\r"), '|', $value);
			// add double quotas if required
			if ($needQuote)
				{
				$value = "\"$value\"";
				}
        }
        if ($params["escape"] == "excel") {
            $value = preg_replace("/(\n\r|\n)/", "<br style=\"mso-data-placement:same-cell;\" />", $value);
        }
    }

    echo $value;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions