PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Options/Page.php +22 -130 trunk2.1 View file →
@@ -16,12 +16,9 @@
16 16 use Packetery\Core\Entity\PacketStatus;
17 17 use Packetery\Core\Log;
18 18 use Packetery\Latte\Engine;
19 19 use Packetery\Module\Dashboard\DashboardPage;
20 -use Packetery\Module\DiagnosticsLogger\DiagnosticsLogger;
21 20 use Packetery\Module\FormFactory;
22 -use Packetery\Module\Forms\BugReportForm;
23 -use Packetery\Module\Forms\DiagnosticsLoggingFormFactory;
24 21 use Packetery\Module\Framework\WpAdapter;
25 22 use Packetery\Module\MessageManager;
26 23 use Packetery\Module\ModuleHelper;
27 24 use Packetery\Module\Order\PacketAutoSubmitter;
@@ -27,9 +24,8 @@
27 24 use Packetery\Module\Order\PacketAutoSubmitter;
28 25 use Packetery\Module\Order\PacketSynchronizer;
29 26 use Packetery\Module\PaymentGatewayHelper;
30 27 use Packetery\Module\Views\UrlBuilder;
31 -use Packetery\Module\WcLogger;
32 28 use Packetery\Nette\Forms\Container;
33 29 use Packetery\Nette\Forms\Controls\BaseControl;
34 30 use Packetery\Nette\Forms\Controls\SubmitButton;
35 31 use Packetery\Nette\Forms\Form;
@@ -41,13 +37,12 @@
41 37 * @package Packetery\Options
42 38 */
43 39 class Page {
44 40
45 - private const FORM_FIELDS_CONTAINER = 'packetery';
46 - private const FORM_FIELD_PACKETA_LABEL_FORMAT = 'packeta_label_format';
47 - private const FORM_FIELD_CARRIER_LABEL_FORMAT = 'carrier_label_format';
48 - private const FORM_FIELD_FREE_SHIPPING_SHOWN = 'free_shipping_shown';
49 - public const FORM_PICKUP_POINT_VALIDATION_ENABLED = 'pickup_point_validation_enabled';
41 + private const FORM_FIELDS_CONTAINER = 'packetery';
42 + private const FORM_FIELD_PACKETA_LABEL_FORMAT = 'packeta_label_format';
43 + private const FORM_FIELD_CARRIER_LABEL_FORMAT = 'carrier_label_format';
44 + private const FORM_FIELD_FREE_SHIPPING_SHOWN = 'free_shipping_shown';
50 45
51 46 public const ACTION_VALIDATE_SENDER = 'validate-sender';
52 47
53 48 public const SLUG = 'packeta-options';
@@ -133,21 +128,8 @@
133 128 * @var string
134 129 */
135 130 private $supportEmailAddress;
136 131
137 - /**
138 - * @var BugReportForm
139 - */
140 - private $bugReportForm;
141 -
142 - /**
143 - * @var DiagnosticsLoggingFormFactory
144 - */
145 - private $diagnosticsLoggingFormFactory;
146 -
147 - /** @var DiagnosticsLogger */
148 - private $diagnosticsLogger;
149 -
150 132 public function __construct(
151 133 Engine $latteEngine,
152 134 OptionsProvider $optionsProvider,
153 135 FormFactory $formFactory,
@@ -158,28 +140,22 @@
158 140 ModuleHelper $moduleHelper,
159 141 UrlBuilder $urlBuilder,
160 142 PacketSynchronizer $packetSynchronizer,
161 143 WpAdapter $wpAdapter,
162 - string $supportEmailAddress,
163 - BugReportForm $bugReportForm,
164 - DiagnosticsLoggingFormFactory $diagnosticsLoggingFormFactory,
165 - DiagnosticsLogger $diagnosticsLogger
144 + string $supportEmailAddress
166 145 ) {
167 - $this->latteEngine = $latteEngine;
168 - $this->optionsProvider = $optionsProvider;
169 - $this->formFactory = $formFactory;
170 - $this->packetaClient = $packetaClient;
171 - $this->logger = $logger;
172 - $this->messageManager = $messageManager;
173 - $this->httpRequest = $httpRequest;
174 - $this->moduleHelper = $moduleHelper;
175 - $this->urlBuilder = $urlBuilder;
176 - $this->packetSynchronizer = $packetSynchronizer;
177 - $this->supportEmailAddress = $supportEmailAddress;
178 - $this->wpAdapter = $wpAdapter;
179 - $this->bugReportForm = $bugReportForm;
180 - $this->diagnosticsLoggingFormFactory = $diagnosticsLoggingFormFactory;
181 - $this->diagnosticsLogger = $diagnosticsLogger;
146 + $this->latteEngine = $latteEngine;
147 + $this->optionsProvider = $optionsProvider;
148 + $this->formFactory = $formFactory;
149 + $this->packetaClient = $packetaClient;
150 + $this->logger = $logger;
151 + $this->messageManager = $messageManager;
152 + $this->httpRequest = $httpRequest;
153 + $this->moduleHelper = $moduleHelper;
154 + $this->urlBuilder = $urlBuilder;
155 + $this->packetSynchronizer = $packetSynchronizer;
156 + $this->supportEmailAddress = $supportEmailAddress;
157 + $this->wpAdapter = $wpAdapter;
182 158 }
183 159
184 160 public function register(): void {
185 161 add_action( 'admin_init', [ $this, 'admin_init' ] );
@@ -216,19 +192,13 @@
216 192
217 193 /**
218 194 * Returns menu_order with Packeta item in last position.
219 195 *
220 - * @param array|mixed $menuOrder WP $menu_order.
196 + * @param array $menuOrder WP $menu_order.
221 197 *
222 - * @return array|mixed
198 + * @return array
223 199 */
224 - public function customMenuOrder( $menuOrder ) {
225 - if ( ! is_array( $menuOrder ) ) {
226 - WcLogger::logArgumentTypeError( __METHOD__, 'menuOrder', 'array', $menuOrder );
227 -
228 - return $menuOrder;
229 - }
230 -
200 + public function customMenuOrder( array $menuOrder ): array {
231 201 $currentPosition = array_search( self::SLUG, $menuOrder, true );
232 202
233 203 if ( $currentPosition !== false ) {
234 204 unset( $menuOrder[ $currentPosition ] );
@@ -474,8 +444,9 @@
474 444 *
475 445 * @return void
476 446 */
477 447 public function onPacketStatusSyncFormSuccess( Form $form, array $values ): void {
448 +
478 449 $values['status_syncing_order_statuses'] = $this->getChosenKeys(
479 450 self::getOrderStatusesChoiceData(),
480 451 $values['status_syncing_order_statuses']
481 452 );
@@ -661,14 +632,8 @@
661 632 $container->addCheckbox( 'hide_checkout_logo', __( 'Hide Packeta checkout logo', 'packeta' ) )
662 633 ->setRequired( false )
663 634 ->setDefaultValue( OptionsProvider::HIDE_CHECKOUT_LOGO_DEFAULT );
664 635
665 - $container->addCheckbox( 'auto_email_info_insertion', __( 'Automatically insert packet and pickup point information into emails', 'packeta' ) )
666 - ->setRequired( false )
667 - ->setDefaultValue( OptionsProvider::AUTO_EMAIL_INFO_INSERTION_DEFAULT )
668 - ->addCondition( Form::EQUAL, true )
669 - ->toggle( '#packetery-email-hook' );
670 -
671 636 $container->addSelect(
672 637 'email_hook',
673 638 __( 'Hook used to view information in email', 'packeta' ),
674 639 [
@@ -694,16 +659,8 @@
694 659 $container->addCheckbox( 'prices_include_tax', __( 'Prices include tax', 'packeta' ) )
695 660 ->setRequired( false )
696 661 ->setDefaultValue( OptionsProvider::PRICES_INCLUDE_TAX_DEFAULT );
697 662
698 - $container->addCheckbox( self::FORM_PICKUP_POINT_VALIDATION_ENABLED, __( 'Validate the pickup point using the API before accepting the order', 'packeta' ) )
699 - ->setRequired( false )
700 - ->setDefaultValue( OptionsProvider::PICKUP_POINT_VALIDATION_ENABLED_DEFAULT );
701 -
702 - $container->addCheckbox( 'show_consign_password_for_z_box', __( 'Show consignment code', 'packeta' ) )
703 - ->setRequired( false )
704 - ->setDefaultValue( OptionsProvider::SHOW_CONSIGN_PASSWORD_FOR_Z_BOX_DEFAULT );
705 -
706 663 $form->addSubmit( 'save', __( 'Save changes', 'packeta' ) );
707 664
708 665 if ( $this->optionsProvider->has_any( OptionNames::PACKETERY ) ) {
709 666 $container->setDefaults( $this->optionsProvider->getOptionsByName( OptionNames::PACKETERY ) );
@@ -716,12 +673,9 @@
716 673 * Admin_init callback.
717 674 */
718 675 public function admin_init(): void {
719 676 add_filter( 'pre_update_option_packetery', [ $this, 'validatePacketeryOptions' ] );
720 -
721 - // Registered callback is called when the form is submitted.
722 677 register_setting( self::FORM_FIELDS_CONTAINER, self::FORM_FIELDS_CONTAINER, [ $this, 'sanitizePacketeryOptions' ] );
723 -
724 678 add_settings_section( 'packetery_main', __( 'Main Settings', 'packeta' ), function () {}, self::SLUG );
725 679 }
726 680
727 681 /**
@@ -774,14 +728,8 @@
774 728 *
775 729 * @var Container $packeteryContainer
776 730 */
777 731 $packeteryContainer = $form[ self::FORM_FIELDS_CONTAINER ];
778 - if ( ! isset( $options['auto_email_info_insertion'] ) ) {
779 - $options['auto_email_info_insertion'] = false;
780 - }
781 - if ( ! isset( $options['show_consign_password_for_z_box'] ) ) {
782 - $options['show_consign_password_for_z_box'] = false;
783 - }
784 732 $packeteryContainer->setValues( $options );
785 733 if ( $form->isValid() === false ) {
786 734 foreach ( $packeteryContainer->getControls() as $control ) {
787 735 if ( $control->hasErrors() === false ) {
@@ -840,12 +788,8 @@
840 788 }
841 789 }
842 790 }
843 791
844 - if ( $options['api_key'] === '' ) {
845 - $options[ self::FORM_PICKUP_POINT_VALIDATION_ENABLED ] = false;
846 - }
847 -
848 792 return $options;
849 793 }
850 794
851 795 /**
@@ -938,26 +882,8 @@
938 882 $advancedForm['save']->isSubmittedBy()
939 883 ) {
940 884 $advancedForm->fireEvents();
941 885 }
942 -
943 - $bugReportForm = $this->bugReportForm->createForm();
944 - if (
945 - $bugReportForm['submit'] instanceof SubmitButton &&
946 - $bugReportForm['submit']->isSubmittedBy() &&
947 - $bugReportForm->isSuccess()
948 - ) {
949 - $bugReportForm->fireEvents();
950 - }
951 -
952 - $diagnosticsLoggingForm = $this->diagnosticsLoggingFormFactory->createForm();
953 - if (
954 - $diagnosticsLoggingForm['save'] instanceof SubmitButton &&
955 - $diagnosticsLoggingForm['save']->isSubmittedBy() &&
956 - $diagnosticsLoggingForm->isSuccess()
957 - ) {
958 - $diagnosticsLoggingForm->fireEvents();
959 - }
960 886 }
961 887
962 888 /**
963 889 * Renders page.
@@ -973,15 +899,8 @@
973 899 } elseif ( $activeTab === self::TAB_ADVANCED ) {
974 900 $latteParams = [ 'form' => $this->createAdvancedForm() ];
975 901 } elseif ( $activeTab === self::TAB_GENERAL ) {
976 902 $latteParams = [ 'form' => $this->create_form() ];
977 - } elseif ( $activeTab === self::TAB_SUPPORT ) {
978 - $latteParams = [
979 - 'bugReportFormEnabled' => false,
980 - 'bugReportForm' => $this->bugReportForm->createForm(),
981 - 'diagnosticsLoggingForm' => $this->diagnosticsLoggingFormFactory->createForm(),
982 - 'hasPacketaLog' => is_file( $this->diagnosticsLogger->getPacketaLogPath() ),
983 - ];
984 903 }
985 904
986 905 if ( ! extension_loaded( 'soap' ) ) {
987 906 $latteParams['error'] = __( 'This plugin requires an active SOAP library for proper operation. Contact your web hosting administrator.', 'packeta' );
@@ -996,17 +915,8 @@
996 915 ],
997 916 get_admin_url( null, 'admin.php' )
998 917 );
999 918
1000 - $latteParams['deleteDiagnosticsLogsLink'] = add_query_arg(
1001 - [
1002 - 'page' => self::SLUG,
1003 - 'action' => DiagnosticsLogger::ACTION_DELETE_PACKETA_LOG,
1004 - 'tab' => self::TAB_SUPPORT,
1005 - ],
1006 - get_admin_url( null, 'admin.php' )
1007 - );
1008 -
1009 919 $latteParams['activeTab'] = ( $this->httpRequest->getQuery( self::PARAM_TAB ) ?? self::TAB_GENERAL );
1010 920 $latteParams['generalTabLink'] = $this->createLink();
1011 921 $latteParams['advancedTabLink'] = $this->createLink( self::TAB_ADVANCED );
1012 922 $latteParams['supportTabLink'] = $this->createLink( self::TAB_SUPPORT );
@@ -1041,9 +951,9 @@
1041 951 $latteParams['logoZasilkovna'] = $this->urlBuilder->buildAssetUrl( 'public/images/logo-zasilkovna.svg' );
1042 952 $latteParams['logoPacketa'] = $this->urlBuilder->buildAssetUrl( 'public/images/logo-packeta.svg' );
1043 953 $advancedCarrierSettingsDescription = sprintf(
1044 954 // translators: first %s is line break, second one is e-mail address
1045 - __( 'When this feature is active, Packeta carriers will appear as separate shipping methods under WooCommerce → Settings → Shipping. After enabling or disabling this feature, you need to reconfigure your shipping methods in WooCommerce.%1$sIf you encounter any issues, please contact us at %2$s.', 'packeta' ),
955 + __( 'BETA: Once enabled, Packeta carriers will appear as separate shipping methods in WooCommerce - Settings - Shipping. After enabling this feature, you will need to set up shipping methods in WooCommerce again.%1$sThis is an experimental feature. If you experience any issues, please email us at %2$s with a description of the issue.', 'packeta' ),
1046 956 '<br>',
1047 957 '<a href="mailto:' . $this->supportEmailAddress . '">' . $this->supportEmailAddress . '</a>'
1048 958 );
1049 959 $latteParams['translations'] = [
@@ -1069,13 +979,8 @@
1069 979 ),
1070 980 'exportPluginSettings' => __( 'Export the plugin settings', 'packeta' ),
1071 981 'settingsExportDatetime' => __( 'Date and time of the last export of settings', 'packeta' ),
1072 982 'settingsNotYetExported' => __( 'The settings have not been exported yet.', 'packeta' ),
1073 - 'bugReportTitle' => $this->wpAdapter->__( 'Report a bug', 'packeta' ),
1074 - 'bugReportDescription' => $this->wpAdapter->__( 'If you encounter any issues with the Packeta plugin, please use this form to report them. Your message will be sent to our technical support team along with system information.', 'packeta' ),
1075 - 'bugReportInfo' => $this->wpAdapter->__( 'We will also zip the following files and attach them to the email, if available: WooCommerce Log, Diagnostics Log, Tracy Log, Wordpress Debug Log, WooCommerce System Status Log, Packeta plugin settings export.', 'packeta' ),
1076 - 'exportSettingsTitle' => $this->wpAdapter->__( 'Export settings', 'packeta' ),
1077 - 'diagnosticsLoggingTitle' => $this->wpAdapter->__( 'Diagnostics logging', 'packeta' ),
1078 983 'senderDescription' => sprintf(
1079 984 /* translators: 1: emphasis start 2: emphasis end 3: client section link start 4: client section link end */
1080 985 esc_html__( 'Fill here %1$ssender label%2$s - you will find it in %3$sclient section%4$s - user information - field \'Indication\'.', 'packeta' ),
1081 986 '<strong>',
@@ -1098,21 +1003,8 @@
1098 1003 'autoOrderStatusChangeDescription' => __( 'Change order status after data submission to Packeta.', 'packeta' ),
1099 1004 'freeShippingTextDescription' => __( 'If enabled, "FREE" will be displayed after the name of the shipping method, if free shipping is applied.', 'packeta' ),
1100 1005 'orderStatusChangeSettings' => __( 'Order status change settings', 'packeta' ),
1101 1006 'dimensionsLabel' => __( 'Dimensions', 'packeta' ),
1102 - 'autoEmailInfoInsertionDescription' => __( 'When enabled, the plugin automatically adds packet and pickup point details to emails. Disable this if you prefer to insert them manually using shortcodes.', 'packeta' ),
1103 - 'diagnosticsLoggingDescription' => $this->wpAdapter->__( 'If some plugin functionality is not working correctly, you can enable diagnostic logging. After enabling it, please repeat the action that is not working as expected. The log will then record important function calls, passed parameters, and their results. Once you have reproduced the issue, disable diagnostic logging again. This information can help developers troubleshoot the problem. You can find the log in the packeta.log file, which is stored by default in wp-content/plugins/packeta/log.', 'packeta' ),
1104 - 'diagnosticsLoggingLink' => $this->wpAdapter->__( 'Delete log', 'packeta' ),
1105 - 'bugReportScreenshotsTitle' => $this->wpAdapter->__( 'If possible, please provide screenshots showing the problem. You can do it this way:', 'packeta' ),
1106 - 'bugReportScreenshotsFirstStep' => sprintf(
1107 - /* translators: 1: ImgBB link start 2: ImgBB link end */
1108 - $this->wpAdapter->__( 'Go to %1$sImgBB%2$s and upload your screenshots.', 'packeta' ),
1109 - '<a href="https://imgbb.com/" target="_blank">',
1110 - '</a>'
1111 - ),
1112 - 'bugReportScreenshotsSecondStep' => $this->wpAdapter->__( 'Copy the link(s) generated after uploading', 'packeta' ),
1113 - 'bugReportScreenshotsThirdStep' => $this->wpAdapter->__( 'Paste the link(s) into your message.', 'packeta' ),
1114 - 'message' => $this->wpAdapter->__( 'Message', 'packeta' ),
1115 1007 ];
1116 1008
1117 1009 $this->latteEngine->render( PACKETERY_PLUGIN_DIR . '/template/options/page.latte', $latteParams );
1118 1010 }