osCommerce / oscommerce2

osCommerce Online Merchant v2.x
http://www.oscommerce.com
MIT License
281 stars 222 forks source link

Bug regarding MODULE_PAYMENT_MONEYORDER_PAYTO (line breaks) #606

Open mgutt opened 6 years ago

mgutt commented 6 years ago

Its not possible to add a multiline strings to MODULE_PAYMENT_MONEYORDER_PAYTO like the following:

Account: John Doe\nIBAN: AB12 3546 7890 0012 3456 00\nVWZ: Your Order ID

or:

Account: John Doe<br>IBAN: AB12 3546 7890 0012 3456 00<br>VWZ: Your Order ID

Because the language file uses the same value for email (\n) and html output (<br>):

  define('MODULE_PAYMENT_MONEYORDER_TEXT_DESCRIPTION', 'Make Payable To:&nbsp;' . MODULE_PAYMENT_MONEYORDER_PAYTO . '<br /><br />Send To:<br />' . nl2br(STORE_NAME_ADDRESS) . '<br /><br />' . 'Your order will not ship until we receive payment.');
  define('MODULE_PAYMENT_MONEYORDER_TEXT_EMAIL_FOOTER', "Make Payable To: ". MODULE_PAYMENT_MONEYORDER_PAYTO . "\n\nSend To:\n" . STORE_NAME_ADDRESS . "\n\n" . 'Your order will not ship until we receive payment.');

I think the best would be to allow \n and use nl2br() in the lang file as it is still used for the STORE_NAME_ADDRESS value:

  define('MODULE_PAYMENT_MONEYORDER_TEXT_DESCRIPTION', 'Make Payable To:&nbsp;' . nl2br(MODULE_PAYMENT_MONEYORDER_PAYTO) . '<br /><br />Send To:<br />' . nl2br(STORE_NAME_ADDRESS) . '<br /><br />' . 'Your order will not ship until we receive payment.');

But before this makes sense, we have to solve a bug. After saving our string with \n it is correctly added to the database: Image

But if we want to edit it, the data runs in admin/modules.php through objectInfo() and this class uses tep_db_prepare_input() and removes the backlash (admin/includes/classes/object_info.php) resulting n: Image

My temporary solution in modules.php:

// because of a bug: https://github.com/osCommerce/oscommerce2/issues/606
function prepare_value_for_stripslashes(&$data) {
    foreach ($data as &$value) {
        if (is_array($value)) {
            prepare_value_for_stripslashes($value);
        }
        else {
            $value = str_replace('\\', '\\\\', $value);
        }
    }
}
        $module_info['keys'] = $keys_extra;

prepare_value_for_stripslashes($module_info);

        $mInfo = new objectInfo($module_info);

I tried tep_cfg_textarea( in the database column set_function as well (as done with STORE_NAME_ADDRESS), but it does not solve the problem because the line breaks are replaced by \n text strings before they are saved in the database. :(