Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/greenhouse fix #256

Merged
merged 14 commits into from
Sep 7, 2022
Merged
7 changes: 6 additions & 1 deletion src/AdminMenus/FormGlobalSettingsAdminSubMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,18 @@ protected function processAttributes($attr): array
{
$type = isset($_GET['type']) ? \sanitize_text_field(\wp_unslash($_GET['type'])) : SettingsGeneral::SETTINGS_TYPE_KEY; // phpcs:ignore WordPress.Security.NonceVerification.Recommended

$settingsSidebarOutput = [];
foreach ($this->settingsGlobal->getSettingsSidebar($type) as $item) {
$settingsSidebarOutput[$item['type'] ?? 'general'][] = $item;
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
}

return [
// translators: %s replaces form title name.
'adminSettingsPageTitle' => \esc_html__('Settings', 'eightshift-forms'),
'adminSettingsSubTitle' => \esc_html__('These settings apply to all forms.', 'eightshift-forms'),
'adminSettingsBackLink' => Helper::getListingPageUrl(),
'adminSettingsLink' => Helper::getSettingsGlobalPageUrl(''),
'adminSettingsSidebar' => $this->settingsGlobal->getSettingsSidebar($type),
'adminSettingsSidebar' => $settingsSidebarOutput,
'adminSettingsForm' => $this->settingsGlobal->getSettingsForm($type),
'adminSettingsType' => $type,
'adminSettingsIsGlobal' => true,
Expand Down
7 changes: 6 additions & 1 deletion src/AdminMenus/FormSettingsAdminSubMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,18 @@ protected function processAttributes($attr): array
$formTitle = \esc_html__('No form title', 'eightshift-forms');
}

$settingsSidebarOutput = [];
foreach ($this->settingsAll->getSettingsSidebar($formId, $type) as $item) {
$settingsSidebarOutput[$item['type'] ?? 'general'][] = $item;
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
}

return [
// translators: %s replaces the form name.
'adminSettingsPageTitle' => \sprintf(\esc_html__('Form settings: %s', 'eightshift-forms'), $formTitle),
'adminSettingsBackLink' => Helper::getListingPageUrl(),
'adminSettingsFormEditLink' => Helper::getFormEditPageUrl($formId),
'adminSettingsLink' => Helper::getSettingsPageUrl($formId, ''),
'adminSettingsSidebar' => $this->settingsAll->getSettingsSidebar($formId, $type),
'adminSettingsSidebar' => $settingsSidebarOutput,
'adminSettingsForm' => $this->settingsAll->getSettingsForm($formId, $type),
'adminSettingsType' => $type,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@

&__sidebar {
background-color: var(--global-colors-es-white);
height: 100vh;
overflow-x: hidden;

> * {
margin-bottom: var(--global-es-spacing-horizontal);
border-top: 1px solid var(--global-colors-es-ebb);

&:first-child {
border-top: 0;
}
}
}

&__sidebar-label {
padding: 1rem 1.1rem 0.5rem;
font-size: 1.1rem;
font-weight: bold;
line-height: 1.2;
}

&__main {
border-left: 1px solid var(--global-colors-es-ebb);

Expand Down Expand Up @@ -87,7 +101,7 @@
}

&:hover,
&:focus, {
&:focus {
color: var(--global-colors-es-matisse);
background-color: var(--global-colors-es-matisse-05);
}
Expand Down
38 changes: 14 additions & 24 deletions src/Blocks/components/admin-settings/admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

echo Components::outputCssVariablesGlobal(); // phpcs:ignore Eightshift.Security.ComponentsEscape.OutputNotEscaped

$componentName = $manifest['componentName'] ?? '';
$componentClass = $manifest['componentClass'] ?? '';
$sectionClass = $manifestSection['componentClass'] ?? '';

Expand Down Expand Up @@ -47,30 +48,19 @@
</a>
</div>

<div class="<?php echo esc_attr("{$sectionClass}__section"); ?>">
<div class="<?php echo esc_attr("{$sectionClass}__content"); ?>">
<ul class="<?php echo esc_attr("{$sectionClass}__menu"); ?>">
<?php foreach ($adminSettingsSidebar as $item) { ?>
<?php
$label = $item['label'] ?? '';
$value = $item['value'] ?? '';
$icon = $item['icon'] ?? '';
?>
<li class="<?php echo esc_attr("{$sectionClass}__menu-item"); ?>">
<a
href="<?php echo esc_url("{$adminSettingsLink}&type={$value}"); ?>"
class="<?php echo esc_attr("{$sectionClass}__menu-link " . Components::selector($value === $adminSettingsType, $sectionClass, 'menu-link', 'active')); ?>"
>
<span class="<?php echo esc_attr("{$sectionClass}__menu-link-wrap"); ?>">
<?php echo $icon; // phpcs:ignore Eightshift.Security.ComponentsEscape.OutputNotEscaped ?>
<?php echo esc_html($label); ?>
</span>
</a>
</li>
<?php } ?>
</ul>
</div>
</div>
<?php
echo Components::renderPartial( // phpcs:ignore Eightshift.Security.ComponentsEscape.OutputNotEscaped
'component',
$componentName,
'sidebar-section',
[
'items' => $adminSettingsSidebar,
'sectionClass' => $sectionClass,
'adminSettingsLink' => $adminSettingsLink,
'adminSettingsType' => $adminSettingsType,
]
);
?>
</div>
<div class="<?php echo esc_attr("{$sectionClass}__main"); ?>">
<div class="<?php echo esc_attr("{$sectionClass}__section"); ?>">
Expand Down
75 changes: 75 additions & 0 deletions src/Blocks/components/admin-settings/partials/sidebar-section.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Template for admin settings page - sidebar section partial.
*
* @package EightshiftForms\Blocks.
*/

use EightshiftForms\Settings\Settings\SettingsAll;
use EightshiftFormsVendor\EightshiftLibs\Helpers\Components;

$items = $attributes['items'] ?? [];

$output = [];

if (!$items) {
return $output;
}

$sectionClass = $attributes['sectionClass'] ?? '';
$adminSettingsLink = $attributes['adminSettingsLink'] ?? '';
$adminSettingsType = $attributes['adminSettingsType'] ?? '';

// Provide order we want on output.
$sortOrder = SettingsAll::SIDEBAR_SORT_ORDER;
uksort($items, function ($key1, $key2) use ($sortOrder) {
return ((array_search($key1, $sortOrder, true) > array_search($key2, $sortOrder, true)) ? 1 : -1);
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
});

foreach ($items as $key => $innerItems) {
switch ($key) {
case SettingsAll::SETTINGS_SIEDBAR_TYPE_INTEGRATION:
$sidebarTitle = __('Integrations', 'eightshift-forms');
break;
case SettingsAll::SETTINGS_SIEDBAR_TYPE_TROUBLESHOOTING:
$sidebarTitle = __('Troubleshooting', 'eightshift-forms');
break;
case SettingsAll::SETTINGS_SIEDBAR_TYPE_DEVELOP:
$sidebarTitle = __('Develop Mode', 'eightshift-forms');
break;
default:
$sidebarTitle = __('General', 'eightshift-forms');
break;
}
?>

<div class="<?php echo esc_attr("{$sectionClass}__section"); ?>">
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
<div class="<?php echo esc_attr("{$sectionClass}__content"); ?>">
<div class="<?php echo esc_attr("{$sectionClass}__sidebar-label"); ?>">
<?php echo esc_html($sidebarTitle); ?>
</div>
<ul class="<?php echo esc_attr("{$sectionClass}__menu"); ?>">
<?php foreach ($innerItems as $item) { ?>
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for closing and opening PHP tags 🙂

$label = $item['label'] ?? '';
$value = $item['value'] ?? '';
$icon = $item['icon'] ?? '';
?>
<li class="<?php echo esc_attr("{$sectionClass}__menu-item"); ?>">
<a
href="<?php echo esc_url("{$adminSettingsLink}&type={$value}"); ?>"
class="<?php echo esc_attr("{$sectionClass}__menu-link " . Components::selector($value === $adminSettingsType, $sectionClass, 'menu-link', 'active')); ?>"
>
<span class="<?php echo esc_attr("{$sectionClass}__menu-link-wrap"); ?>">
<?php echo $icon; // phpcs:ignore Eightshift.Security.ComponentsEscape.OutputNotEscaped ?>
<?php echo esc_html($label); ?>
</span>
</a>
</li>
<?php } ?>
</ul>
</div>
</div>

<?php }
2 changes: 2 additions & 0 deletions src/Cache/SettingsCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use EightshiftForms\Integrations\Mailerlite\MailerliteClient;
use EightshiftForms\Settings\SettingsHelper;
use EightshiftForms\Settings\GlobalSettings\SettingsGlobalDataInterface;
use EightshiftForms\Settings\Settings\SettingsAll;
use EightshiftFormsVendor\EightshiftLibs\Services\ServiceInterface;

/**
Expand Down Expand Up @@ -95,6 +96,7 @@ public function getSettingsSidebar(): array
'label' => \__('Clear cache', 'eightshift-forms'),
'value' => self::SETTINGS_TYPE_KEY,
'icon' => Filters::ALL[self::SETTINGS_TYPE_KEY]['icon'],
'type' => SettingsAll::SETTINGS_SIEDBAR_TYPE_TROUBLESHOOTING,
];
}

Expand Down
6 changes: 4 additions & 2 deletions src/Enqueue/Blocks/EnqueueBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use EightshiftForms\Settings\Settings\SettingsGeneral;
use EightshiftForms\Settings\SettingsHelper;
use EightshiftForms\Tracking\TrackingInterface;
use EightshiftForms\Troubleshooting\SettingsTroubleshooting;
use EightshiftForms\Validation\SettingsCaptcha;
use EightshiftForms\Validation\ValidatorInterface;
use EightshiftFormsVendor\EightshiftLibs\Enqueue\Blocks\AbstractEnqueueBlocks;
Expand Down Expand Up @@ -228,8 +229,9 @@ protected function getLocalizations(): array
SettingsGeneral::SETTINGS_GENERAL_DISABLE_AUTOINIT_ENQUEUE_SCRIPT_KEY,
SettingsGeneral::SETTINGS_GENERAL_DISABLE_DEFAULT_ENQUEUE_KEY
);
$output['formResetOnSuccess'] = !Variables::isDevelopMode();
$output['formServerErrorMsg'] = \esc_html__('A server error occurred while submitting your form. Please try again.', 'eightshift-forms');
$output['formResetOnSuccess'] = !$this->isCheckboxOptionChecked(SettingsTroubleshooting::SETTINGS_TROUBLESHOOTING_SKIP_RESET_KEY, SettingsTroubleshooting::SETTINGS_TROUBLESHOOTING_DEBUGGING_KEY);
$output['formServerErrorMsg'] = \esc_html__('An server error occurred while submitting your form. Please try again.', 'eightshift-forms');
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
iruzevic marked this conversation as resolved.
Show resolved Hide resolved

$output['captcha'] = '';
$output['storageConfig'] = '';

Expand Down
71 changes: 44 additions & 27 deletions src/Geolocation/Geolocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use EightshiftForms\Hooks\Filters;
use EightshiftForms\Hooks\Variables;
use EightshiftForms\Settings\SettingsHelper;
use EightshiftForms\Troubleshooting\SettingsTroubleshooting;
use EightshiftFormsVendor\EightshiftLibs\Services\ServiceInterface;
use Throwable;

Expand All @@ -23,6 +24,9 @@
*/
class Geolocation implements ServiceInterface, GeolocationInterface
{
/**
* Use general helper trait.
*/
use SettingsHelper;

/**
Expand Down Expand Up @@ -111,15 +115,20 @@ public function isUserGeolocated(string $formId, array $defaultLocations, array
return $formId;
}

$useLogger = $this->isCheckboxOptionChecked(SettingsTroubleshooting::SETTINGS_TROUBLESHOOTING_LOG_MODE_KEY, SettingsTroubleshooting::SETTINGS_TROUBLESHOOTING_DEBUGGING_KEY);

// Add ability to disable geolocation from external source. (Generaly used for GDPR).
$filterName = Filters::getGeolocationFilterName('disable');
if (\has_filter($filterName) && \apply_filters($filterName, null)) {
Helper::logger([
'geolocation' => 'Filter disabled active, skip geolocation.',
'formIdOriginal' => $formId,
'formIdUsed' => $formId,
'userLocation' => '',
]);
if ($useLogger) {
Helper::logger([
'geolocation' => 'Filter disabled active, skip geolocation.',
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
'formIdOriginal' => $formId,
'formIdUsed' => $formId,
'userLocation' => '',
]);
}

return $formId;
}

Expand Down Expand Up @@ -155,12 +164,14 @@ function ($geo) use ($userLocation) {

// If additional locations match output that new form.
if ($matchAdditionalLocations) {
Helper::logger([
'geolocation' => 'Locations exists, locations match. Outputing new form.',
'formIdOriginal' => $formId,
'formIdUsed' => $matchAdditionalLocations['formId'] ?? '',
'userLocation' => $userLocation,
]);
if ($useLogger) {
Helper::logger([
'geolocation' => 'Locations exists, locations match. Outputing new form.',
'formIdOriginal' => $formId,
'formIdUsed' => $matchAdditionalLocations['formId'] ?? '',
'userLocation' => $userLocation,
]);
}
return $matchAdditionalLocations['formId'] ?? '';
}
}
Expand All @@ -181,32 +192,38 @@ function ($location) use ($userLocation) {

// If default locations match output that new form.
if ($matchDefaultLocations) {
if ($useLogger) {
Helper::logger([
'geolocation' => 'Locations doesn\'t match or exist, default location match. Outputing new form.',
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
'formIdOriginal' => $formId,
'formIdUsed' => $formId,
'userLocation' => $userLocation,
]);
}
return $formId;
}

// If we have set default locations but no match return empty form.
if ($useLogger) {
Helper::logger([
'geolocation' => 'Locations doesn\'t match or exist, default location match. Outputing new form.',
'geolocation' => 'Locations doesn\'t exists, default location doesn\'t match. Outputing nothing.',
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
'formIdOriginal' => $formId,
'formIdUsed' => $formId,
'formIdUsed' => '',
'userLocation' => $userLocation,
]);
return $formId;
}
return '';
}

// If we have set default locations but no match return empty form.
// Final fallback if the user has no locations, no default locations or they didn't match. Just return the current form.
if ($useLogger) {
Helper::logger([
'geolocation' => 'Locations doesn\'t exists, default location doesn\'t match. Outputing nothing.',
'geolocation' => 'Final fallback that returns the current form. Outputing the original form.',
'formIdOriginal' => $formId,
'formIdUsed' => '',
'formIdUsed' => $formId,
'userLocation' => $userLocation,
]);
return '';
}

// Final fallback if the user has no locations, no default locations or they didn't match. Just return the current form.
Helper::logger([
'geolocation' => 'Final fallback that returns the current form. Outputing the original form.',
'formIdOriginal' => $formId,
'formIdUsed' => $formId,
'userLocation' => $userLocation,
]);
return $formId;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Geolocation/SettingsGeolocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace EightshiftForms\Geolocation;

use EightshiftForms\Hooks\Filters;
use EightshiftForms\Settings\Settings\SettingsAll;
use EightshiftForms\Settings\Settings\SettingsDataInterface;
use EightshiftForms\Settings\SettingsHelper;
use EightshiftFormsVendor\EightshiftLibs\Services\ServiceInterface;
Expand Down Expand Up @@ -83,6 +84,7 @@ public function getSettingsSidebar(): array
'label' => \__('Geolocation', 'eightshift-forms'),
'value' => self::SETTINGS_TYPE_KEY,
'icon' => Filters::ALL[self::SETTINGS_TYPE_KEY]['icon'],
'type' => SettingsAll::SETTINGS_SIEDBAR_TYPE_GENERAL,
];
}

Expand Down
Loading