forked from SurefireStudios/PostPoster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-admin.php
More file actions
395 lines (347 loc) · 21.8 KB
/
Copy pathclass-admin.php
File metadata and controls
395 lines (347 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
/**
* Admin interface for Post Poster plugin
*
* @package PostPoster
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Admin class
*/
class PP_Admin {
/**
* Constructor
*/
public function __construct() {
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('wp_ajax_pp_preview_shortcode', array($this, 'ajax_preview_shortcode'));
add_action('wp_ajax_pp_save_settings', array($this, 'ajax_save_settings'));
add_action('admin_init', array($this, 'register_settings'));
}
/**
* Add admin menu
*/
public function add_admin_menu() {
add_menu_page(
__('Post Poster', 'post-poster'), // Page title
__('Post Poster', 'post-poster'), // Menu title
'manage_options', // Capability
'post-poster', // Menu slug
array($this, 'admin_page'), // Callback function
'dashicons-grid-view', // Icon
25 // Position (after Comments)
);
// Add submenu page (same as main page but cleaner URL structure)
add_submenu_page(
'post-poster', // Parent slug
__('Shortcode Generator', 'post-poster'), // Page title
__('Shortcode Generator', 'post-poster'), // Menu title
'manage_options', // Capability
'post-poster', // Menu slug (same as parent for main page)
array($this, 'admin_page') // Callback function
);
}
/**
* Register settings
*/
public function register_settings() {
register_setting('pp_settings_group', 'pp_settings');
register_setting('pp_settings_group', 'pp_user_settings');
}
/**
* Admin page content
*/
public function admin_page() {
if (!PP_Helpers::user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'post-poster'));
}
// Get current user settings
$user_id = get_current_user_id();
$user_settings = get_user_meta($user_id, 'pp_last_settings', true);
if (!is_array($user_settings)) {
$user_settings = array();
}
// Default settings
$defaults = array(
'categories' => '',
'columns' => '3',
'per_page' => '9',
'show_image' => 'true',
'show_title' => 'true',
'show_excerpt' => 'true',
'excerpt_words' => '18',
'show_date' => 'true',
'show_author' => 'false',
'show_categories' => 'true',
'orderby' => 'date',
'order' => 'DESC',
'pagination' => 'none',
'image_ratio' => '16x9',
'gutter' => '16',
'theme' => 'auto',
'cache_minutes' => '15'
);
$settings = array_merge($defaults, $user_settings);
?>
<div class="wrap">
<h1><?php esc_html_e('Post Poster - Shortcode Generator', 'post-poster'); ?></h1>
<div class="pp-admin-container">
<div class="pp-admin-form">
<form id="pp-shortcode-form">
<?php wp_nonce_field('pp_admin_nonce', 'pp_nonce'); ?>
<div class="pp-form-section">
<h2><?php esc_html_e('Content Selection', 'post-poster'); ?></h2>
<div class="pp-form-row">
<label for="pp_categories">
<?php esc_html_e('Categories', 'post-poster'); ?>
<span class="pp-help" title="<?php esc_attr_e('Select one or more categories. Leave empty to show posts from all categories.', 'post-poster'); ?>">?</span>
</label>
<select id="pp_categories" name="categories" multiple>
<?php
$categories = PP_Helpers::get_all_categories();
$selected_categories = explode(',', $settings['categories']);
foreach ($categories as $category) {
$selected = in_array($category['value'], $selected_categories) ? 'selected' : '';
echo '<option value="' . esc_attr($category['value']) . '" ' . $selected . '>' . esc_html($category['label']) . '</option>';
}
?>
</select>
</div>
<div class="pp-form-row">
<label for="pp_per_page">
<?php esc_html_e('Posts per page', 'post-poster'); ?>
<span class="pp-help" title="<?php esc_attr_e('Number of posts to display (1-50)', 'post-poster'); ?>">?</span>
</label>
<input type="number" id="pp_per_page" name="per_page" value="<?php echo esc_attr($settings['per_page']); ?>" min="1" max="50">
</div>
<div class="pp-form-row">
<label for="pp_orderby">
<?php esc_html_e('Order by', 'post-poster'); ?>
</label>
<select id="pp_orderby" name="orderby">
<option value="date" <?php selected($settings['orderby'], 'date'); ?>><?php esc_html_e('Date', 'post-poster'); ?></option>
<option value="title" <?php selected($settings['orderby'], 'title'); ?>><?php esc_html_e('Title', 'post-poster'); ?></option>
<option value="modified" <?php selected($settings['orderby'], 'modified'); ?>><?php esc_html_e('Modified', 'post-poster'); ?></option>
<option value="rand" <?php selected($settings['orderby'], 'rand'); ?>><?php esc_html_e('Random', 'post-poster'); ?></option>
<option value="comment_count" <?php selected($settings['orderby'], 'comment_count'); ?>><?php esc_html_e('Comment Count', 'post-poster'); ?></option>
</select>
</div>
<div class="pp-form-row">
<label for="pp_order">
<?php esc_html_e('Sort order', 'post-poster'); ?>
</label>
<select id="pp_order" name="order">
<option value="DESC" <?php selected($settings['order'], 'DESC'); ?>><?php esc_html_e('Descending', 'post-poster'); ?></option>
<option value="ASC" <?php selected($settings['order'], 'ASC'); ?>><?php esc_html_e('Ascending', 'post-poster'); ?></option>
</select>
</div>
</div>
<div class="pp-form-section">
<h2><?php esc_html_e('Layout Options', 'post-poster'); ?></h2>
<div class="pp-form-row">
<label><?php esc_html_e('Columns', 'post-poster'); ?></label>
<div class="pp-columns-selector">
<?php for ($i = 1; $i <= 4; $i++) : ?>
<label class="pp-column-option">
<input type="radio" name="columns" value="<?php echo $i; ?>" <?php checked($settings['columns'], (string)$i); ?>>
<span class="pp-column-visual pp-cols-<?php echo $i; ?>">
<?php for ($j = 1; $j <= $i; $j++) : ?>
<div class="pp-column-block"></div>
<?php endfor; ?>
</span>
<span class="pp-column-label"><?php echo $i; ?> <?php echo $i === 1 ? __('Column', 'post-poster') : __('Columns', 'post-poster'); ?></span>
</label>
<?php endfor; ?>
</div>
</div>
<div class="pp-form-row">
<label for="pp_gutter">
<?php esc_html_e('Gutter size (px)', 'post-poster'); ?>
<span class="pp-help" title="<?php esc_attr_e('Space between cards in pixels', 'post-poster'); ?>">?</span>
</label>
<input type="range" id="pp_gutter" name="gutter" value="<?php echo esc_attr($settings['gutter']); ?>" min="0" max="50" step="2">
<span class="pp-range-value"><?php echo esc_html($settings['gutter']); ?>px</span>
</div>
<div class="pp-form-row">
<label for="pp_image_ratio">
<?php esc_html_e('Image ratio', 'post-poster'); ?>
</label>
<select id="pp_image_ratio" name="image_ratio">
<option value="16x9" <?php selected($settings['image_ratio'], '16x9'); ?>>16:9 (<?php esc_html_e('Widescreen', 'post-poster'); ?>)</option>
<option value="4x3" <?php selected($settings['image_ratio'], '4x3'); ?>>4:3 (<?php esc_html_e('Standard', 'post-poster'); ?>)</option>
<option value="1x1" <?php selected($settings['image_ratio'], '1x1'); ?>>1:1 (<?php esc_html_e('Square', 'post-poster'); ?>)</option>
<option value="auto" <?php selected($settings['image_ratio'], 'auto'); ?>><?php esc_html_e('Auto', 'post-poster'); ?></option>
</select>
</div>
<div class="pp-form-row">
<label for="pp_theme">
<?php esc_html_e('Theme', 'post-poster'); ?>
<span class="pp-help" title="<?php esc_attr_e('Choose between light and dark card themes', 'post-poster'); ?>">?</span>
</label>
<select id="pp_theme" name="theme">
<option value="auto" <?php selected($settings['theme'] ?? 'auto', 'auto'); ?>><?php esc_html_e('Auto (Follow site theme)', 'post-poster'); ?></option>
<option value="light" <?php selected($settings['theme'] ?? 'auto', 'light'); ?>><?php esc_html_e('Light', 'post-poster'); ?></option>
<option value="dark" <?php selected($settings['theme'] ?? 'auto', 'dark'); ?>><?php esc_html_e('Dark', 'post-poster'); ?></option>
</select>
</div>
</div>
<div class="pp-form-section">
<h2><?php esc_html_e('Display Options', 'post-poster'); ?></h2>
<div class="pp-form-row pp-checkbox-row">
<label>
<input type="checkbox" name="show_image" value="true" <?php checked($settings['show_image'], 'true'); ?>>
<?php esc_html_e('Show featured image', 'post-poster'); ?>
</label>
</div>
<div class="pp-form-row pp-checkbox-row">
<label>
<input type="checkbox" name="show_title" value="true" <?php checked($settings['show_title'], 'true'); ?>>
<?php esc_html_e('Show post title', 'post-poster'); ?>
</label>
</div>
<div class="pp-form-row pp-checkbox-row">
<label>
<input type="checkbox" name="show_excerpt" value="true" <?php checked($settings['show_excerpt'], 'true'); ?>>
<?php esc_html_e('Show excerpt', 'post-poster'); ?>
</label>
</div>
<div class="pp-form-row" id="pp_excerpt_words_row">
<label for="pp_excerpt_words">
<?php esc_html_e('Excerpt length (words)', 'post-poster'); ?>
</label>
<input type="number" id="pp_excerpt_words" name="excerpt_words" value="<?php echo esc_attr($settings['excerpt_words']); ?>" min="5" max="100">
</div>
<div class="pp-form-row pp-checkbox-row">
<label>
<input type="checkbox" name="show_date" value="true" <?php checked($settings['show_date'] ?? 'true', 'true'); ?>>
<?php esc_html_e('Show post date', 'post-poster'); ?>
</label>
</div>
<div class="pp-form-row pp-checkbox-row">
<label>
<input type="checkbox" name="show_author" value="true" <?php checked($settings['show_author'] ?? 'false', 'true'); ?>>
<?php esc_html_e('Show author', 'post-poster'); ?>
</label>
</div>
<div class="pp-form-row pp-checkbox-row">
<label>
<input type="checkbox" name="show_categories" value="true" <?php checked($settings['show_categories'] ?? 'true', 'true'); ?>>
<?php esc_html_e('Show categories', 'post-poster'); ?>
</label>
</div>
</div>
<div class="pp-form-section">
<h2><?php esc_html_e('Advanced Options', 'post-poster'); ?></h2>
<div class="pp-form-row">
<label for="pp_pagination">
<?php esc_html_e('Pagination', 'post-poster'); ?>
</label>
<select id="pp_pagination" name="pagination">
<option value="none" <?php selected($settings['pagination'], 'none'); ?>><?php esc_html_e('None', 'post-poster'); ?></option>
<option value="numeric" <?php selected($settings['pagination'], 'numeric'); ?>><?php esc_html_e('Numeric', 'post-poster'); ?></option>
<option value="load_more" <?php selected($settings['pagination'], 'load_more'); ?>><?php esc_html_e('Load More Button', 'post-poster'); ?></option>
</select>
</div>
<div class="pp-form-row">
<label for="pp_cache_minutes">
<?php esc_html_e('Cache duration (minutes)', 'post-poster'); ?>
<span class="pp-help" title="<?php esc_attr_e('Cache results for better performance. Set to 0 to disable.', 'post-poster'); ?>">?</span>
</label>
<select id="pp_cache_minutes" name="cache_minutes">
<option value="0" <?php selected($settings['cache_minutes'], '0'); ?>><?php esc_html_e('No cache', 'post-poster'); ?></option>
<option value="15" <?php selected($settings['cache_minutes'], '15'); ?>>15 <?php esc_html_e('minutes', 'post-poster'); ?></option>
<option value="60" <?php selected($settings['cache_minutes'], '60'); ?>>1 <?php esc_html_e('hour', 'post-poster'); ?></option>
<option value="240" <?php selected($settings['cache_minutes'], '240'); ?>>4 <?php esc_html_e('hours', 'post-poster'); ?></option>
<option value="1440" <?php selected($settings['cache_minutes'], '1440'); ?>>24 <?php esc_html_e('hours', 'post-poster'); ?></option>
</select>
</div>
</div>
<div class="pp-form-actions">
<button type="button" id="pp_preview_btn" class="button button-secondary">
<?php esc_html_e('Preview', 'post-poster'); ?>
</button>
<button type="button" id="pp_generate_btn" class="button button-primary">
<?php esc_html_e('Generate Shortcode', 'post-poster'); ?>
</button>
</div>
</form>
</div>
<div class="pp-admin-output">
<div class="pp-shortcode-output">
<h3><?php esc_html_e('Generated Shortcode', 'post-poster'); ?></h3>
<div class="pp-shortcode-container">
<textarea id="pp_shortcode_result" readonly placeholder="<?php esc_attr_e('Click "Generate Shortcode" to create your shortcode...', 'post-poster'); ?>"></textarea>
<button type="button" id="pp_copy_btn" class="button button-secondary" disabled>
<?php esc_html_e('Copy', 'post-poster'); ?>
</button>
</div>
</div>
<div id="pp_preview_container" class="pp-preview-container" style="display: none;">
<h3><?php esc_html_e('Preview', 'post-poster'); ?></h3>
<div id="pp_preview_content"></div>
</div>
</div>
</div>
</div>
<?php
}
/**
* AJAX handler for shortcode preview
*/
public function ajax_preview_shortcode() {
// Verify nonce and capabilities
if (!PP_Helpers::verify_nonce($_POST['nonce'], 'pp_admin_nonce') || !PP_Helpers::user_can('manage_options')) {
wp_die(__('Security check failed.', 'post-poster'));
}
// Get and sanitize form data
$atts = array();
$form_fields = array(
'categories', 'columns', 'per_page', 'show_image', 'show_title',
'show_excerpt', 'excerpt_words', 'show_date', 'show_author',
'show_categories', 'orderby', 'order', 'pagination',
'image_ratio', 'gutter', 'theme', 'cache_minutes'
);
foreach ($form_fields as $field) {
if (isset($_POST[$field])) {
$atts[$field] = sanitize_text_field($_POST[$field]);
}
}
// Generate preview
$shortcode = new PP_Shortcode();
$preview_html = $shortcode->get_admin_preview($atts);
wp_send_json_success(array(
'html' => $preview_html
));
}
/**
* AJAX handler for saving user settings
*/
public function ajax_save_settings() {
// Verify nonce and capabilities
if (!PP_Helpers::verify_nonce($_POST['nonce'], 'pp_admin_nonce') || !PP_Helpers::user_can('manage_options')) {
wp_die(__('Security check failed.', 'post-poster'));
}
// Get and sanitize form data
$settings = array();
$form_fields = array(
'categories', 'columns', 'per_page', 'show_image', 'show_title',
'show_excerpt', 'excerpt_words', 'show_date', 'show_author',
'show_categories', 'orderby', 'order', 'pagination',
'image_ratio', 'gutter', 'theme', 'cache_minutes'
);
foreach ($form_fields as $field) {
if (isset($_POST[$field])) {
$settings[$field] = sanitize_text_field($_POST[$field]);
}
}
// Save user settings
$user_id = get_current_user_id();
update_user_meta($user_id, 'pp_last_settings', $settings);
wp_send_json_success(array(
'message' => __('Settings saved.', 'post-poster')
));
}
}