button
*
* @param $post
* @param bool $btnBlock
* @return string
*/
function genPhoneNumberBtn($post, bool $btnBlock = false): string
{
$post = (is_array($post)) ? Arr::toObject($post) : $post;
$out = '';
if (empty($post->phone_intl) || $post->phone_hidden == 1) {
return $out;
}
$enableWhatsAppBtn = (config('settings.single.enable_whatsapp_btn') == 1);
$whatsAppPreFilledMessage = (config('settings.single.pre_filled_whatsapp_message') == 1)
? '?text=' . rawurlencode(t('whatsapp_pre_filled_message', [
'title' => $post->title,
'appName' => config('app.name'),
])) : '';
$whatsAppLink = 'https://wa.me/' . strToDigit($post->phone) . $whatsAppPreFilledMessage;
$waBtnClass = '';
$btnLink = 'tel:' . $post->phone;
$btnAttr = '';
$btnClass = ' phoneBlock'; /* for the JS showPhone() function */
$btnHint = t('Click to see');
$phone = $post->phone_intl;
if (config('settings.single.hide_phone_number')) {
$phoneToHide = phoneNormalized($phone);
if (config('settings.single.hide_phone_number') == '1') {
$phone = str($phoneToHide)->mask('X', -str($phoneToHide)->length(), str($phoneToHide)->length() - 3);
}
if (config('settings.single.hide_phone_number') == '2') {
$phone = str($phoneToHide)->mask('X', 3);
}
if (config('settings.single.hide_phone_number') == '3') {
$phone = str($phoneToHide)->mask('X', 0);
}
$btnLink = '';
$btnAttrTooltip = 'data-bs-toggle="tooltip" data-bs-placement="bottom" title="' . $btnHint . '"';
$btnClassTooltip = '';
$btnAttr = $btnAttrTooltip;
$btnClass = $btnClass . $btnClassTooltip;
$enableWhatsAppBtn = false;
} else {
if (config('settings.single.convert_phone_number_to_img')) {
try {
$phone = \Larapen\TextToImage\Facades\TextToImage::make($phone, config('larapen.core.textToImage'));
} catch (\Throwable $e) {
$phone = $post->phone;
}
$btnClass = '';
}
}
if (config('settings.single.show_security_tips') == '1') {
/*
Set multiple data-bs-toggle for link in Bootstrap
Tooltip + modal in button - Bootstrap
Usage of '[rel="tooltip"]' as selector instead of '[data-bs-toggle="tooltip"]' for the tooltip,
and trigger that with on hover event from JS
*/
$btnAttrTooltip = 'rel="tooltip" data-bs-placement="bottom" title="' . $btnHint . '"';
$btnClassTooltip = '';
$btnAttrModal = 'data-bs-toggle="modal"';
$btnLink = '#securityTips';
$btnAttr = $btnAttrModal . ' ' . $btnAttrTooltip;
$btnClass = ' phoneBlock'; /* for the JS showPhone() function */
if (!config('settings.single.hide_phone_number')) {
$phone = t('phone_number');
}
$btnClass = $btnClass . ' ' . $btnClassTooltip;
}
if (!auth()->check()) {
if (config('settings.single.guests_can_contact_authors') != '1') {
$btnAttrModal = 'data-bs-toggle="modal"';
$phone = $btnHint;
$btnLink = '#quickLogin';
$btnAttr = $btnAttrModal;
$btnClass = '';
$enableWhatsAppBtn = false;
}
}
if ($btnBlock) {
$waBtnClass = $waBtnClass . ' btn-block';
$btnClass = $btnClass . ' btn-block';
}
// Generate the Phone Number button
$out .= '<a href="' . $btnLink . '" ' . $btnAttr . ' target="_blank" class="btn btn-warning' . $btnClass . '">';
//$out .= '<i class="fas fa-mobile-alt"></i> ';
$out .= $phone;
$out .= '</a>';
if ($enableWhatsAppBtn) {
$waBtnAttr = 'data-bs-toggle="tooltip" data-bs-placement="bottom" title="' . t('chat_on_whatsapp') . '"';
$waBtnClass = $waBtnClass . '';
// Generate the WhatsApp button
$out .= '<a href="' . $whatsAppLink . '" ' . $waBtnAttr . ' target="_blank" class="btn btn-success' . $waBtnClass . '">';
$out .= '<i class="fab fa-whatsapp"></i> ';
$out .= 'WhatsApp';
$out .= '</a>';
}
return $out;
}
Код для ватсапа игнорится, т.к. создал другой генератор
Обсуждают сегодня