assets
1 year ago
html
1 year ago
class-settings-view-model.php
1 year ago
class-settings-view.php
1 year ago
index.php
1 year ago
class-settings-view.php
155 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WPFront Scroll Top |
| 4 | * |
| 5 | * @package wpfront-scroll-top |
| 6 | * @author Syam Mohan |
| 7 | * @copyright 2013 WPFront |
| 8 | * @license GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | namespace WPFront\Scroll_Top; |
| 12 | |
| 13 | defined( 'ABSPATH' ) || exit; |
| 14 | |
| 15 | /** |
| 16 | * Settings view class. |
| 17 | * |
| 18 | * @package wpfront-scroll-top |
| 19 | */ |
| 20 | class Settings_View { |
| 21 | /** |
| 22 | * WordPress wrapper instance. |
| 23 | * |
| 24 | * @var WP_Wrapper |
| 25 | */ |
| 26 | private $wp; |
| 27 | |
| 28 | /** |
| 29 | * Constructor. |
| 30 | * |
| 31 | * @param WP_Wrapper $wp WordPress wrapper instance. |
| 32 | */ |
| 33 | public function __construct( WP_Wrapper $wp ) { |
| 34 | $this->wp = $wp; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Renders the settings view. |
| 39 | * |
| 40 | * @return void |
| 41 | */ |
| 42 | public function render(): void { |
| 43 | $this->add_hooks(); |
| 44 | $this->write_html(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Adds hooks for the settings view. |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | public function add_hooks() { |
| 53 | $this->wp->add_meta_box( 'postbox-display-settings', __( 'Display', 'wpfront-scroll-top' ), array( $this, 'display_html' ), 'wpfront-scroll-top', 'normal', 'default', array( 'file' => 'display-settings.html' ) ); |
| 54 | $this->wp->add_meta_box( 'postbox-location-settings', __( 'Location', 'wpfront-scroll-top' ), array( $this, 'display_html' ), 'wpfront-scroll-top', 'normal', 'default', array( 'file' => 'location-settings.html' ) ); |
| 55 | $this->wp->add_meta_box( 'postbox-filter-settings', __( 'Filter', 'wpfront-scroll-top' ), array( $this, 'display_html' ), 'wpfront-scroll-top', 'normal', 'default', array( 'file' => 'filter-settings.html' ) ); |
| 56 | $this->wp->add_meta_box( 'postbox-button-settings', '{{ button_style_options[data.button_style] }}', array( $this, 'display_html' ), 'wpfront-scroll-top', 'normal', 'default', array( 'file' => array( 'image-button-settings.html', 'text-button-settings.html', 'font-awesome-button-settings.html' ) ) ); |
| 57 | $this->wp->add_meta_box( 'postbox-accessibility-settings', __( 'Accessibility', 'wpfront-scroll-top' ), array( $this, 'display_html' ), 'wpfront-scroll-top', 'normal', 'default', array( 'file' => 'accessibility-settings.html' ) ); |
| 58 | $this->wp->add_meta_box( 'postbox-css-settings', __( 'CSS', 'wpfront-scroll-top' ), array( $this, 'display_html' ), 'wpfront-scroll-top', 'normal', 'default', array( 'file' => 'css-settings.html' ) ); |
| 59 | $this->wp->add_meta_box( 'postbox-side-1', __( 'Actions', 'wpfront-scroll-top' ), array( $this, 'action_area' ), 'wpfront-scroll-top', 'side', 'default' ); |
| 60 | $this->wp->add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Displays the settings html. |
| 65 | * |
| 66 | * @return void |
| 67 | */ |
| 68 | public function write_html() { |
| 69 | ?> |
| 70 | <div class="wrap scroll-top"> |
| 71 | <h1><?php esc_html_e( 'WPFront Scroll Top Settings', 'wpfront-scroll-top' ); ?></h1> |
| 72 | <div id="scroll-top-content" class="wrap" style="display: none;"> |
| 73 | <form id="scroll-top-content-form" onsubmit="return false" @submit.prevent="submit"> |
| 74 | <div id="poststuff"> |
| 75 | <div id="post-body" class="metabox-holder columns-2"> |
| 76 | <div id="post-body-content"> |
| 77 | <?php $this->wp->do_meta_boxes( 'wpfront-scroll-top', 'normal', null ); ?> |
| 78 | </div> |
| 79 | <div id="postbox-container-1" class="postbox-container-right"> |
| 80 | <?php $this->wp->do_meta_boxes( 'wpfront-scroll-top', 'side', null ); ?> |
| 81 | </div> |
| 82 | </div> |
| 83 | </div> |
| 84 | </form> |
| 85 | </div> |
| 86 | </div> |
| 87 | <?php |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Displays the HTML for the settings view. |
| 92 | * |
| 93 | * @param \WP_Post $post The post object. |
| 94 | * @param array<string,mixed> $args The arguments passed to the callback. |
| 95 | * |
| 96 | * @return void |
| 97 | */ |
| 98 | public function display_html( $post, $args ): void { |
| 99 | $file = $args['args']; |
| 100 | |
| 101 | if ( is_array( $file ) ) { |
| 102 | $file = $file['file']; |
| 103 | } |
| 104 | |
| 105 | if ( is_array( $file ) ) { |
| 106 | foreach ( $file as $f ) { |
| 107 | $this->display_html( $post, array( 'args' => array( 'file' => $f ) ) ); |
| 108 | } |
| 109 | |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | if ( ! is_string( $file ) ) { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | include __DIR__ . '/html/' . $file; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Displays the action area for the settings view. |
| 122 | * |
| 123 | * @return void |
| 124 | */ |
| 125 | public function action_area(): void { |
| 126 | ?> |
| 127 | <p class="submit"> |
| 128 | <input type="submit" class="button button-primary" :disabled="save_disabled" value="<?php esc_html_e( 'Save Changes', 'wpfront-scroll-top' ); ?>" /> |
| 129 | </p> |
| 130 | <div class="settings-updated-message" v-if="save_success"> |
| 131 | <?php esc_html_e( 'Settings updated successfully.', 'wpfront-scroll-top' ); ?> |
| 132 | </div> |
| 133 | <div class="settings-error-message" v-if="error_message"> |
| 134 | <?php esc_html_e( 'Save failed.', 'wpfront-scroll-top' ); ?> {{ error_message }} |
| 135 | </div> |
| 136 | <?php |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Modifies the admin footer text. |
| 141 | * |
| 142 | * @param string $text The current admin footer text. |
| 143 | * @return string Modified footer text |
| 144 | */ |
| 145 | public function admin_footer_text( $text ): string { |
| 146 | $settings_link = 'scroll-top-plugin-settings/'; |
| 147 | |
| 148 | $settings_link = sprintf( '<a href="%s" target="_blank">%s</a>', 'https://wpfront.com/' . $settings_link, __( 'Settings description', 'wpfront-scroll-top' ) ); |
| 149 | $review_link = sprintf( '<a href="%s" target="_blank">%s</a>', 'https://wordpress.org/support/plugin/wpfront-scroll-top/reviews/', __( 'Write a review', 'wpfront-scroll-top' ) ); |
| 150 | $donate_link = sprintf( '<a href="%s" target="_blank">%s</a>', 'https://wpfront.com/donate/', __( 'Buy me a Beer or Coffee', 'wpfront-scroll-top' ) ); |
| 151 | |
| 152 | return sprintf( '%s | %s | %s | %s', $settings_link, $review_link, $donate_link, $text ); |
| 153 | } |
| 154 | } |
| 155 |