/var/www/vhosts/ihelp.ro/ajutam.ro/wp-content/plugins/give/src/Views
Edit: /var/www/vhosts/ihelp.ro/ajutam.ro/wp-content/plugins/give/src/Views/IframeView.php (8377B)
uniqueId = uniqid('give-');
$this->buttonTitle = esc_html__('Click to donate', 'give');
}
/**
* Set iframe URL.
*
* @param string $url
*
* @return $this
*/
public function setURL($url = null)
{
$this->url = add_query_arg(
['giveDonationFormInIframe' => 1],
$url
);
return $this;
}
/**
* Set whether or not show modal.
*
* @param bool $set
*
* @return $this
*/
public function showInModal($set)
{
$this->modal = $set;
return $this;
}
/**
* Button title.
*
* @param string $title
*
* @return $this
*/
public function setButtonTitle($title)
{
$this->buttonTitle = $title;
return $this;
}
/**
* Button color.
*
* @param string $color
*
* @return $this
*/
public function setButtonColor($color)
{
$this->buttonColor = $color;
return $this;
}
/**
* Form id.
*
* @param int $id
*
* @return $this
*/
public function setFormId($id)
{
$this->formId = $id;
return $this;
}
/**
* Return whether or not rest api request to render donation form block.
*
* @since 2.7.0
* @return bool
*/
private function isDonationFormBlockRendererApiRequest()
{
return false !== strpos(
$_SERVER['REQUEST_URI'],
rest_get_url_prefix() . '/wp/v2/block-renderer/give/donation-form'
);
}
/**
* Extra extra query param to iframe url.
*
* @since 2.7.0
*/
private function addExtraQueryParams()
{
// We can prevent live donation on in appropriate situation like: previewing donation form (with draft status)
if (FormTemplateUtils\Utils\Frontend::getPreviewDonationFormId(
) || $this->isDonationFormBlockRendererApiRequest()) {
$this->url = add_query_arg(
['giveDisableDonateNowButton' => 1],
$this->url
);
}
}
/**
* Get iframe HTML.
*
* @return string
*/
private function getIframeHTML()
{
ob_start();
$this->template->renderLoadingView($this->formId);
$loader = sprintf(
'
%1$s
',
ob_get_clean()
);
$iframe = sprintf(
'
%5$s',
$this->modal ? "data-src=\"{$this->url}\"" : "src=\"{$this->url}\"",
$this->autoScroll,
$this->minHeight ? "min-height: {$this->minHeight}px;" : '',
$this->modal ? 'class="in-modal"' : '',
$loader
);
if ($this->modal) {
$iframe = sprintf(
'
',
$iframe,
esc_html__('Close', 'give'),
$this->uniqueId
);
}
return $iframe;
}
/**
* Get button HTML.
*
* @return string
*/
private function getButtonHTML()
{
return sprintf(
'
',
$this->uniqueId,
$this->buttonTitle,
$this->buttonColor ? " style=\"background-color: {$this->buttonColor}\"" : ''
);
}
/**
* Get iframe URL.
*
* @return string
*/
private function getIframeURL()
{
$query_string = array_map('give_clean', wp_parse_args($_SERVER['QUERY_STRING']));
$donationHistory = give_get_purchase_session();
$hasAction = ! empty($query_string['giveDonationAction']);
$this->autoScroll = absint($hasAction);
$donationFormHasSession = null;
if ($donationHistory) {
$donationFormHasSession = $this->formId === absint($donationHistory['post_data'] ['give-form-id']);
}
// Do not pass donation acton by query param if does not belong to current form.
if (
$hasAction &&
! empty($donationHistory) &&
! $donationFormHasSession
) {
unset($query_string['giveDonationAction']);
$hasAction = false;
$this->autoScroll = 0;
}
// Build iframe url.
$url = Give()->routeForm->getURL(get_post_field('post_name', $this->formId));
if (($hasAction && 'showReceipt' === $query_string['giveDonationAction']) || FormUtils::isViewingFormReceipt(
)) {
$url = FormUtils::getSuccessPageURL();
} elseif (($hasAction && 'failedDonation' === $query_string['giveDonationAction'])) {
$url = $this->template->getFailedPageURL($this->formId);
$query_string['showFailedDonationError'] = 1;
}
$iframe_url = add_query_arg(
array_merge(['giveDonationFormInIframe' => 1], $query_string),
$url
);
return GlobalUtils::removeDonationAction($iframe_url);
}
/**
* Setup Default config.
*/
private function loadDefaultConfig()
{
$activeFormTemplate = FormTemplateUtils::getActiveID($this->formId);
$this->template = Give()->templates->getTemplate($activeFormTemplate);
$this->minHeight = $this->template->getFormStartingHeight($this->formId);
$this->url = $this->url ?: $this->getIframeURL();
$this->addExtraQueryParams();
}
/**
* Render view.
*
* Note: if you want to overwrite this function then do not forget to add action hook in footer and header.
* We use these hooks to manipulated donation form related actions.
*
* @since 2.7.0
*/
public function render()
{
ob_start();
$this->loadDefaultConfig();
if ($this->modal) {
echo $this->getButtonHTML();
}
printf(
'
%3$s
',
$this->modal ? ' is-hide' : '',
$this->uniqueId,
$this->getIframeHTML()
);
return ob_get_clean();
}
}