PluginProbe
ShareMyPost / trunk
ShareMyPost vtrunk
trunk 1.0.4 1.0.5 1.0.6
sharemypost / main / settings / ui.php

ui.php in ShareMyPost trunk, at main/settings/ui.php

205 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ShareMyPost\Settings;
4
5 use ShareMyPost\Helpers;
6
7 if(!defined('ABSPATH')){
8 exit;
9 }
10
11 class UI{
12
13 static function inline_content_settings() {
14 $settings = \ShareMyPost\Util::get_settings();
15
16 echo '<form method="post" action="options.php" class="sharemypost-settings-form">
17 <input type="hidden" name="sharemypost_settings[section]" value="inline" />';
18 settings_fields('sharemypost_settings_group');
19
20 echo '<div class="sharemypost-wrap">
21 <div class="sharemypost-hero-card">
22 <div class="sharemypost-hero-info">
23 <h2>' . esc_html__('Inline Content', 'sharemypost') . '</h2>
24 <p>' . esc_html__('Configure how share buttons appear inside your post content.', 'sharemypost') . '</p>
25 </div>
26 <div class="sharemypost-hero-action">
27 <label class="sharemypost-toggle">
28 <input type="checkbox" name="sharemypost_settings[inline_enabled]" value="1" ' . checked(1, $settings['inline_enabled'], false) . ' />
29 <span class="sharemypost-slider"></span>
30 </label>
31 </div>
32 </div>';
33 self::render_inline_network_selection_settings($settings,'sharemypost_settings');
34
35 echo '<div class="sharemypost-dashboard-grid">';
36
37 // --- CARD 1: Displays Rules ---
38 echo '<div class="sharemypost-card">
39 <h3><span class="dashicons dashicons-visibility"></span> ' . esc_html__('Display Rules', 'sharemypost') . '</h3>
40
41 <div class="sharemypost-field-row">
42 <span class="sharemypost-field-label">' . esc_html__('Position', 'sharemypost') . '</span>
43 <select class="sharemypost-large-input" name="sharemypost_settings[inline_position]">
44 <option value="above" ' . selected($settings['inline_position'], 'above', false) . '>
45 ' . esc_html__('Above content', 'sharemypost') . '
46 </option>
47 <option value="below" ' . selected($settings['inline_position'], 'below', false) . '>
48 ' . esc_html__('Below content', 'sharemypost') . '
49 </option>
50 <option value="both" ' . selected($settings['inline_position'], 'both', false) . '>
51 ' . esc_html__('Both above and below', 'sharemypost') . '
52 </option>
53 </select>
54 </div>
55
56 <div class="sharemypost-field-row">
57 <span class="sharemypost-field-label">' . esc_html__('Display on Post Types', 'sharemypost') . '</span>
58 <div class="sharemypost-pill-group">';
59
60 $post_types = get_post_types(['public' => true], 'objects');
61 unset($post_types['attachment']);
62 $ordered_types = [];
63 $core_slugs = ['post', 'page'];
64 foreach($core_slugs as $slug){
65 if(isset($post_types[$slug])){
66 $ordered_types[$slug] = $post_types[$slug];
67 unset($post_types[$slug]);
68 }
69 }
70 foreach($post_types as $pt => $obj){
71 $ordered_types[$pt] = $obj;
72 }
73
74 foreach ( $ordered_types as $pt => $obj ) {
75 $label = isset( $obj->labels->singular_name ) ? $obj->labels->singular_name : ucfirst( $pt );
76 $is_checked = in_array( $pt, (array) $settings['inline_post_types'], true );
77 echo '<label class="sharemypost-pill">
78 <input type="checkbox" name="sharemypost_settings[inline_post_types][]" value="' . esc_attr($pt) . '"' . checked($is_checked, true, false) . ' />
79 <span>' . esc_html( $label ) . '</span>
80 </label>';
81 }
82 echo '</div>
83 </div>
84
85 <div class="sharemypost-field-row">
86 <span class="sharemypost-field-label">' . esc_html__('Show on Mobile', 'sharemypost') . '</span>
87 <label class="sharemypost-toggle">
88 <input type="checkbox" name="sharemypost_settings[mobile]" value="1"' . checked(1, $settings['mobile'], false) . ' />
89 <span class="sharemypost-slider"></span>
90 </label>
91 </div>
92 </div>';
93
94 // Style Card
95 do_action("sharemypost_inline_style_settings",$settings,'sharemypost_settings');
96
97 self::render_extras_settings( $settings, 'sharemypost_settings', 'inline');
98
99 echo '</div>';
100
101 self::render_inline_ai_network_settings($settings, 'sharemypost_settings');
102
103 echo '<div class="sharemypost-sticky-footer">
104 <div class="sharemypost-footer-content">';
105 submit_button(__('Save Settings', 'sharemypost'),'button-primary button-large','submit', false );
106
107 echo '</div>
108 </div>
109 </div>
110 </form>';
111 }
112
113 static function render_extras_settings($settings, $opt, $type = 'inline') {
114
115 $show_labels = isset($settings['inline_show_labels'])? $settings['inline_show_labels']: (isset($settings['show_labels']) ? $settings['show_labels'] : 'icon_only');
116 $color_type = isset($settings['inline_button_color_type'])? $settings['inline_button_color_type']: (isset($settings['button_color_type']) ? $settings['button_color_type'] : 'custom');
117 $button_color = isset($settings['inline_button_color'])? $settings['inline_button_color']: (isset($settings['button_color']) ? $settings['button_color'] : '#1f75e1');
118
119 echo '<div class="sharemypost-card">
120 <h3><span class="dashicons dashicons-admin-appearance"></span> ' . esc_html__('Inline Button Appearance', 'sharemypost') . '</h3>
121 <div class="sharemypost-field-row">
122 <span class="sharemypost-field-label">' . esc_html__('Show Labels', 'sharemypost') . '</span>
123 <select class="sharemypost-large-input" name="' . esc_attr($opt) . '[inline_show_labels]">
124 <option value="icon_only" ' . selected($show_labels, 'icon_only', false) . '>' . esc_html__('Icon Only', 'sharemypost') . '</option>
125 <option value="label_only" ' . selected($show_labels, 'label_only', false) . '>' . esc_html__('Label Only', 'sharemypost') . '</option>
126 <option value="both" ' . selected($show_labels, 'both', false) . '>' . esc_html__('Icon + Label', 'sharemypost') . '</option>
127 </select>
128 </div>
129
130 <div class="sharemypost-field-row">
131 <span class="sharemypost-field-label">' . esc_html__('Button Colors', 'sharemypost') . '</span>
132 <select class="sharemypost-large-input sharemypost-preview-input" name="' . esc_attr($opt) . '[inline_button_color_type]" id="sharemypost_inline_color_type_select">
133 <option value="original" ' . selected($color_type, 'original', false) . '>' . esc_html__('Original', 'sharemypost') . '</option>
134 <option value="custom" ' . selected($color_type, 'custom', false) . '>' . esc_html__('Custom Color', 'sharemypost') . '</option>
135 </select>
136 </div>
137
138 <div class="sharemypost-field-row" id="sharemypost_inline_custom_color_container" style="' . ($color_type === 'original' ? 'display:none;' : '') . '">
139 <span class="sharemypost-field-label">' . esc_html__('Select Custom Color', 'sharemypost') . '</span>
140 <input id="sharemypost_inline_button_color_input" class="sharemypost-preview-input" type="color" name="' . esc_attr($opt) . '[inline_button_color]" value="' . esc_attr($button_color) . '" />
141 </div>
142 </div>';
143
144 do_action('sharemypost_inline_content_settings', $settings, $opt);
145 }
146
147 static function render_inline_network_selection_settings($settings, $opt){
148 $enabled_list = (array) $settings['inline_enabled_networks'];
149 $order = Helpers::normalize_network_order($settings['inline_network_order']);
150 $inline_sortable = apply_filters('sharemypost_network_grid_sortable', true) ? ' sharemypost-core-sortable' : '';
151 $inline_note = apply_filters('sharemypost_network_grid_note', esc_html__('Choose which networks should appear in share bars. Drag cards to reorder.', 'sharemypost'));
152
153 echo '<div class="sharemypost-card sharemypost-network-selection-card" style="margin-top: 20px;">
154 <h3><span class="dashicons dashicons-admin-post"></span> ' . esc_html__('Inline Networks', 'sharemypost') . '</h3>
155 <p style="font-size: 13px; color: #666; margin-bottom: 15px;">' . esc_html($inline_note) . '</p>
156 <div class="sharemypost-network-grid' . esc_attr($inline_sortable) . ' sharemypost-inline-network-grid" data-order-input="#sharemypost-inline-network-order">';
157
158 static $allowed_svg = null;
159 if(null === $allowed_svg){
160 $allowed_svg = [
161 'svg' => [
162 'viewbox' => true,
163 'viewBox' => true,
164 'xmlns' => true,
165 'fill' => true,
166 'style' => true,
167 ],
168 'path' => [
169 'd' => true,
170 'fill' => true,
171 'style' => true,
172 ],
173 ];
174 }
175
176 foreach(Helpers::get_networks_ordered('inline') as $network => $data){
177 $is_checked = in_array($network, $enabled_list, true);
178 $active_class = $is_checked ? 'is-active' : '';
179
180 echo '<label class="sharemypost-network-item ' . esc_attr($active_class) . '" data-network="' . esc_attr($network) . '">
181 <input type="checkbox" class="sharemypost-network-checkbox" style="display:none;" name="' . esc_attr($opt) . '[inline_enabled_networks][]" value="' . esc_attr($network) . '" ' . checked($is_checked, true, false) . ' />
182 <div class="sharemypost-network-tile sharemypost-share-button sharemypost-network-' . esc_attr($network) . ' sharemypost-style-minimal">
183 <span class="sharemypost-icon">' . wp_kses($data['icon'], $allowed_svg) . '</span>
184 <span class="sharemypost-label">' . esc_html($data['label']) . '</span>
185 </div>
186 </label>';
187 }
188 echo '</div>
189 <input type="hidden" id="sharemypost-inline-network-order" class="sharemypost-order-input" name="' . esc_attr($opt) . '[inline_network_order]" value="' . esc_attr(implode(',', $order)) . '" />
190 </div>';
191 }
192
193 static function render_inline_ai_network_settings($settings, $opt) {
194 do_action('sharemypost_inline_ai_network_settings', $settings, $opt);
195 }
196
197 static function configuration_settings(){
198 do_action('sharemypost_configuration_settings');
199 }
200
201 static function click_to_tweet_settings(){
202 do_action('sharemypost_click_to_x_settings');
203 }
204
205 }