Commit 48f9b378 authored by oskar's avatar oskar

shorting-function moved into helper-class. fix #43

parent 164b427c
......@@ -7,6 +7,7 @@
// HOOK_BESTELLVORGANG_PAGE_STEPZAHLUNG
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPalPlus.class.php';
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPal.helper.class.php';
if (isset($_GET['refresh'])) {
header('location: bestellvorgang.php');
......@@ -28,31 +29,6 @@ $api = new PayPalPlus();
$items = PayPalHelper::getProducts();
$shippingId = $_SESSION['Versandart']->kVersandart;
/**
* shorten a long payment-name to 'nLimit', by inserting a placholder 'szPlaceHolder' and
* show the 'nLastShownChars' characters
*
* @param $szPaymentDesc string to shorten
* @return string string of length 'nLimit'
*/
function shortenPaymentName($szPaymentDesc) {
$nLimit = 25; // hard limit of the payment-wall (should not be altered)
$nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...';
$szShortedDesc = $szPaymentDesc;
if ($nLimit < strlen($szPaymentDesc)) {
$szShortedDesc =
substr($szPaymentDesc, 0, ($nLimit - (strlen($szPlaceHolder) + $nLastShownChars)))
. $szPlaceHolder
. ($nLastShownChars ? substr($szPaymentDesc, - $nLastShownChars) : '')
;
}
return $szShortedDesc;
}
if ($api->isConfigured(false) && $api->isUseable($items, $shippingId)) {
$payment = $api->createPayment();
......
......@@ -696,4 +696,28 @@ class PayPalHelper
$d = is_object($d) ? get_object_vars($d) : $d;
return is_array($d) ? array_map([__CLASS__, __METHOD__], $d) : $d;
}
/**
* shorten a long payment-name to 'nLimit', by inserting a placholder 'szPlaceHolder' and
* show the 'nLastShownChars' characters
*
* @param $szPaymentDesc string to shorten
* @return string string of length 'nLimit'
*/
function shortenPaymentName($szPaymentDesc) {
$nLimit = 25; // hard limit of the payment-wall (should not be altered)
$nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...';
$szShortedDesc = $szPaymentDesc;
if ($nLimit < strlen($szPaymentDesc)) {
$szShortedDesc =
substr($szPaymentDesc, 0, ($nLimit - (strlen($szPlaceHolder) + $nLastShownChars)))
. $szPlaceHolder
. ($nLastShownChars ? substr($szPaymentDesc, - $nLastShownChars) : '')
;
}
return $szShortedDesc;
}
}
......@@ -7,6 +7,7 @@
// HOOK_BESTELLVORGANG_PAGE_STEPZAHLUNG
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPalPlus.class.php';
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPal.helper.class.php';
if (isset($_GET['refresh'])) {
header('location: bestellvorgang.php');
......
......@@ -725,4 +725,27 @@ class PayPalHelper
}
}
}
/**
* shorten a long payment-name to 'nLimit', by inserting a placholder 'szPlaceHolder' and
* show the 'nLastShownChars' characters
*
* @param $szPaymentDesc string to shorten
* @return string string of length 'nLimit'
*/
function shortenPaymentName($szPaymentDesc) {
$nLimit = 25; // hard limit of the payment-wall (should not be altered)
$nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...';
$szShortedDesc = $szPaymentDesc;
if ($nLimit < strlen($szPaymentDesc)) {
$szShortedDesc =
substr($szPaymentDesc, 0, ($nLimit - (strlen($szPlaceHolder) + $nLastShownChars)))
. $szPlaceHolder
. ($nLastShownChars ? substr($szPaymentDesc, - $nLastShownChars) : '')
;
}
return $szShortedDesc;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment