PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.4.2
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.4.2
3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 All 177 releases
simple-tags / inc / class.admin.php

class.admin.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.4.2, at inc/class.admin.php

801 lines 27.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SimpleTags_Admin {
4 // CPT and Taxonomy support
5 public static $post_type = 'post';
6 public static $post_type_name = '';
7 public static $taxonomy = '';
8 public static $taxo_name = '';
9 public static $admin_url = '';
10
11 const MENU_SLUG = 'st_options';
12
13 /**
14 * Initialize Admin
15 *
16 * @return void
17 * @author WebFactory Ltd
18 */
19 public function __construct() {
20 // DB Upgrade ?
21 self::upgrade();
22
23 // Which taxo ?
24 self::register_taxonomy();
25
26 // Admin menu
27 add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
28
29 //Admin footer credit
30 add_action( 'in_admin_footer', array( __CLASS__, 'taxopress_admin_footer') );
31
32 // Load JavaScript and CSS
33 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) );
34
35 //ui class is used accross many pages. So, it should be here
36 require STAGS_DIR . '/inc/class.admin.taxonomies.ui.php';
37
38 //tag clouds/ terms display
39 $active_terms_display = isset($_POST['updateoptions']) &&
40 (
41 !isset($_POST['active_terms_display']) ||
42 (isset($_POST['active_terms_display']) && (int)$_POST['active_terms_display'] === 0)
43 ) ? 0 : 1;
44 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_terms_display' ) || (isset($_POST['active_terms_display']) && (int)$_POST['active_terms_display'] === 1)) && $active_terms_display === 1 ) {
45 require_once STAGS_DIR . '/inc/tag-clouds-action.php';
46 require STAGS_DIR . '/inc/tag-clouds-table.php';
47 require STAGS_DIR . '/inc/tag-clouds.php';
48 SimpleTags_Tag_Clouds::get_instance();
49 }
50
51 //post tags
52 $active_post_tags = isset($_POST['updateoptions']) &&
53 (
54 !isset($_POST['active_post_tags']) ||
55 (isset($_POST['active_post_tags']) && (int)$_POST['active_post_tags'] === 0)
56 ) ? 0 : 1;
57 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_post_tags' ) || (isset($_POST['active_post_tags']) && (int)$_POST['active_post_tags'] === 1)) && $active_post_tags === 1 ) {
58 require_once STAGS_DIR . '/inc/post-tags-action.php';
59 require STAGS_DIR . '/inc/post-tags-table.php';
60 require STAGS_DIR . '/inc/post-tags.php';
61 SimpleTags_Post_Tags::get_instance();
62 }
63
64 //Related Posts
65 $active_related_posts_new = isset($_POST['updateoptions']) &&
66 (
67 !isset($_POST['active_related_posts_new']) ||
68 (isset($_POST['active_related_posts_new']) && (int)$_POST['active_related_posts_new'] === 0)
69 ) ? 0 : 1;
70 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_related_posts_new' ) || (isset($_POST['active_related_posts_new']) && (int)$_POST['active_related_posts_new'] === 1)) && $active_related_posts_new === 1 ) {
71 require_once STAGS_DIR . '/inc/related-posts-action.php';
72 require STAGS_DIR . '/inc/related-posts-table.php';
73 require STAGS_DIR . '/inc/related-posts.php';
74 SimpleTags_Related_Post::get_instance();
75 }
76
77 //Auto Links
78 $active_auto_links = isset($_POST['updateoptions']) &&
79 (
80 !isset($_POST['active_auto_links']) ||
81 (isset($_POST['active_auto_links']) && (int)$_POST['active_auto_links'] === 0)
82 ) ? 0 : 1;
83 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_links' ) || (isset($_POST['active_auto_links']) && (int)$_POST['active_auto_links'] === 1)) && $active_auto_links === 1 ) {
84 require STAGS_DIR . '/inc/autolinks-table.php';
85 require STAGS_DIR . '/inc/autolinks.php';
86 SimpleTags_Autolink::get_instance();
87 }
88
89 //Auto Terms
90 $active_auto_terms = isset($_POST['updateoptions']) &&
91 (
92 !isset($_POST['active_auto_terms']) ||
93 (isset($_POST['active_auto_terms']) && (int)$_POST['active_auto_terms'] === 0)
94 ) ? 0 : 1;
95 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_terms' ) || (isset($_POST['active_auto_terms']) && (int)$_POST['active_auto_terms'] === 1)) && $active_auto_terms === 1 ) {
96 require STAGS_DIR . '/inc/autoterms-table.php';
97 require STAGS_DIR . '/inc/autoterms.php';
98 SimpleTags_Autoterms::get_instance();
99 }
100
101 //Suggest Terms
102 $active_suggest_terms = isset($_POST['updateoptions']) &&
103 (
104 !isset($_POST['active_suggest_terms']) ||
105 (isset($_POST['active_suggest_terms']) && (int)$_POST['active_suggest_terms'] === 0)
106 ) ? 0 : 1;
107 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_suggest_terms' ) || (isset($_POST['active_suggest_terms']) && (int)$_POST['active_suggest_terms'] === 1)) && $active_suggest_terms === 1 ) {
108 require STAGS_DIR . '/inc/suggestterms-table.php';
109 require STAGS_DIR . '/inc/suggestterms.php';
110 SimpleTags_SuggestTerms::get_instance();
111 }
112
113 //suggest terms option
114 $active_mass_edit = isset($_POST['updateoptions']) &&
115 (
116 !isset($_POST['active_mass_edit']) ||
117 (isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 0)
118 ) ? 0 : 1;
119 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_mass_edit' ) || (isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 1)) && $active_mass_edit === 1 ) {
120 require STAGS_DIR . '/inc/class.admin.suggest.php';
121 new SimpleTags_Admin_Suggest();
122 }
123
124 //click terms option
125 require STAGS_DIR . '/inc/class.admin.clickterms.php';
126 new SimpleTags_Admin_ClickTags();
127
128 require STAGS_DIR . '/inc/class.admin.autocomplete.php';
129 new SimpleTags_Admin_Autocomplete();
130
131 $active_mass_edit = isset($_POST['updateoptions']) &&
132 (
133 !isset($_POST['active_mass_edit']) ||
134 (isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 0)
135 ) ? 0 : 1;
136 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_mass_edit' ) || (isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 1)) && $active_mass_edit === 1 ) {
137 require STAGS_DIR . '/inc/class.admin.mass.php';
138 new SimpleTags_Admin_Mass();
139 }
140
141 $active_manage = isset($_POST['updateoptions']) &&
142 (
143 !isset($_POST['active_manage']) ||
144 (isset($_POST['active_manage']) && (int)$_POST['active_manage'] === 0)
145 ) ? 0 : 1;
146 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_manage' ) || (isset($_POST['active_manage']) && (int)$_POST['active_manage'] === 1)) && $active_manage === 1 ) {
147 require STAGS_DIR . '/inc/class-tag-table.php';
148 require STAGS_DIR . '/inc/class.admin.manage.php';
149 SimpleTags_Admin_Manage::get_instance();
150 }
151
152 require STAGS_DIR . '/inc/class.admin.post.php';
153 new SimpleTags_Admin_Post_Settings();
154
155 //taxonomies
156 $active_taxonomies = isset($_POST['updateoptions']) &&
157 (
158 !isset($_POST['active_taxonomies']) ||
159 (isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 0)
160 ) ? 0 : 1;
161 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_taxonomies' ) || (isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 1)) && $active_taxonomies === 1 ) {
162 require_once STAGS_DIR . '/inc/taxonomies-action.php';
163 require STAGS_DIR . '/inc/class-taxonomies-table.php';
164 require STAGS_DIR . '/inc/taxonomies.php';
165 SimpleTags_Admin_Taxonomies::get_instance();
166 }
167
168 do_action('taxopress_admin_class_after_includes');
169
170 // Ajax action, JS Helper and admin action
171 add_action( 'wp_ajax_simpletags', array( __CLASS__, 'ajax_check' ) );
172
173 }
174
175 /**
176 * Ajax Dispatcher
177 */
178 public static function ajax_check() {
179 if ( isset( $_GET['stags_action'] ) && 'maybe_create_tag' === $_GET['stags_action'] && isset( $_GET['tag'] ) ) {
180 self::maybe_create_tag( wp_unslash( $_GET['tag'] ) );
181 }
182 }
183
184 /**
185 * Maybe create a tag, and return the term_id
186 *
187 * @param string $tag_name
188 */
189 public static function maybe_create_tag( $tag_name = '' ) {
190 $term_id = 0;
191 //restore & in tag post
192 $tag_name = str_replace("simpletagand", "&", $tag_name);
193 $result_term = term_exists( $tag_name, 'post_tag', 0 );
194 if ( empty( $result_term ) ) {
195 $result_term = wp_insert_term(
196 $tag_name,
197 'post_tag'
198 );
199
200 if ( ! is_wp_error( $result_term ) ) {
201 $term_id = (int) $result_term['term_id'];
202 }
203 } else {
204 $term_id = (int) $result_term['term_id'];
205 }
206
207 wp_send_json_success( [ 'term_id' => $term_id ] );
208 }
209
210 /**
211 * Test if current URL is not a DEV environnement
212 *
213 * Copy from monsterinsights_is_dev_url(), thanks !
214 *
215 * @param string $url
216 *
217 * @return bool
218 */
219 private static function is_dev_url( $url = '' ) {
220 $is_local_url = false;
221
222 // Trim it up
223 $url = strtolower( trim( $url ) );
224 // Need to get the host...so let's add the scheme so we can use parse_url
225 if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) {
226 $url = 'http://' . $url;
227 }
228
229 $url_parts = wp_parse_url( $url );
230 $host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false;
231 if ( ! empty( $url ) && ! empty( $host ) ) {
232 if ( false !== ip2long( $host ) ) {
233 if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
234 $is_local_url = true;
235 }
236 } elseif ( 'localhost' === $host ) {
237 $is_local_url = true;
238 }
239
240 $tlds_to_check = array( '.local', ':8888', ':8080', ':8081', '.invalid', '.example', '.test' );
241 foreach ( $tlds_to_check as $tld ) {
242 if ( false !== strpos( $host, $tld ) ) {
243 $is_local_url = true;
244 break;
245 }
246 }
247
248 if ( substr_count( $host, '.' ) > 1 ) {
249 $subdomains_to_check = array( 'dev.', '*.staging.', 'beta.', 'test.' );
250 foreach ( $subdomains_to_check as $subdomain ) {
251 $subdomain = str_replace( '.', '(.)', $subdomain );
252 $subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain );
253 if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) {
254 $is_local_url = true;
255 break;
256 }
257 }
258 }
259 }
260
261 return $is_local_url;
262 }
263
264 /**
265 * Init taxonomy class variable, load this action after all actions on init !
266 * Make a public static function for call it from children class...
267 *
268 * @return void
269 * @author WebFactory Ltd
270 */
271 public static function register_taxonomy() {
272 add_action( 'init', array( __CLASS__, 'init' ), 99999999 );
273 }
274
275 /**
276 * Put in var class the current taxonomy choose by the user
277 *
278 * @return void
279 * @author WebFactory Ltd
280 */
281 public static function init() {
282 self::$taxo_name = __( 'Post tags', 'simple-tags' );
283 self::$post_type_name = __( 'Posts', 'simple-tags' );
284
285 // Custom CPT ?
286 if ( isset( $_GET['cpt'] ) && ! empty( $_GET['cpt'] ) && post_type_exists( $_GET['cpt'] ) ) {
287 $cpt = get_post_type_object( $_GET['cpt'] );
288 self::$post_type = $cpt->name;
289 self::$post_type_name = $cpt->labels->name;
290 }
291
292 // Get compatible taxo for current post type
293 $compatible_taxonomies = get_object_taxonomies( self::$post_type );
294
295 // Custom taxo ?
296 if ( isset( $_GET['taxo'] ) && ! empty( $_GET['taxo'] ) && taxonomy_exists( $_GET['taxo'] ) ) {
297 $taxo = get_taxonomy( $_GET['taxo'] );
298
299 // Taxo is compatible ?
300 if ( in_array( $taxo->name, $compatible_taxonomies ) ) {
301 self::$taxonomy = $taxo->name;
302 self::$taxo_name = $taxo->labels->name;
303 } else {
304 unset( $taxo );
305 }
306 }
307
308 // Default taxo from CPT...
309 if ( ! isset( $taxo ) && is_array( $compatible_taxonomies ) && ! empty( $compatible_taxonomies ) ) {
310 // Take post_tag before category
311 if ( in_array( 'post_tag', $compatible_taxonomies, true ) ) {
312 $taxo = get_taxonomy( 'post_tag' );
313 } else {
314 $taxo = get_taxonomy( current( $compatible_taxonomies ) );
315 }
316
317 self::$taxonomy = $taxo->name;
318 self::$taxo_name = $taxo->labels->name;
319
320 // TODO: Redirect for help user that see the URL...
321 } elseif ( ! isset( $taxo ) ) {
322 wp_die( __( 'This custom post type not have taxonomies.', 'simple-tags' ) );
323 }
324
325 // Free memory
326 unset( $cpt, $taxo );
327 }
328
329 /**
330 * Build HTML form for allow user to change taxonomy for the current page.
331 *
332 * @param string $page_value
333 *
334 * @return void
335 * @author Olatechpro
336 */
337 public static function boxSelectorTaxonomy( $page_value = '' ) {
338 echo '<div class="box-selector-taxonomy">' . PHP_EOL;
339
340 echo '<div class="change-taxo">' . PHP_EOL;
341 echo '<form action="" method="get">' . PHP_EOL;
342 if ( ! empty( $page_value ) ) {
343 echo '<input type="hidden" name="page" value="' . $page_value . '" />' . PHP_EOL;
344 }
345 $taxonomies = [];
346 echo '<select name="cpt" id="cpt-select" class="st-cpt-select">' . PHP_EOL;
347 foreach ( get_post_types( array( 'show_ui' => true ), 'objects' ) as $post_type ) {
348 $taxonomies_children = get_object_taxonomies( $post_type->name );
349 if ( empty( $taxonomies_children ) ) {
350 continue;
351 }
352 $taxonomies[$post_type->name] = $taxonomies_children;
353 echo '<option ' . selected( $post_type->name, self::$post_type, false ) . ' value="' . esc_attr( $post_type->name ) . '">' . esc_html( $post_type->labels->name ) . '</option>' . PHP_EOL;
354 }
355 echo '</select>' . PHP_EOL;
356
357 echo '<select name="taxo" id="taxonomy-select" class="st-taxonomy-select">' . PHP_EOL;
358 foreach ( $taxonomies as $parent_post => $taxonomy ) {
359 if ( count($taxonomy) > 0){
360 foreach($taxonomy as $tax_name){
361 $taxonomy = get_taxonomy( $tax_name );
362 if ( false === (bool) $taxonomy->show_ui ) {
363 continue;
364 }
365
366 if( self::$post_type == $parent_post){
367 $class = "";
368 }else{
369 $class="st-hide-content";
370 }
371
372 echo '<option ' . selected( $tax_name, self::$taxonomy, false ) . ' value="' . esc_attr( $tax_name ) . '" data-post="'.$parent_post.'" class="'.$class.'">' . esc_html( $taxonomy->labels->name ) . '</option>' . PHP_EOL;
373 }
374 }
375 }
376 echo '</select>' . PHP_EOL;
377
378 echo '<input type="submit" class="button" id="submit-change-taxo" value="' . __( 'Change selection', 'simple-tags' ) . '" />' . PHP_EOL;
379 echo '</form>' . PHP_EOL;
380 echo '</div>' . PHP_EOL;
381 echo '</div>' . PHP_EOL;
382
383 }
384
385 /**
386 * Init somes JS and CSS need for TaxoPress.
387 *
388 * @return void
389 * @author WebFactory Ltd
390 */
391 public static function admin_enqueue_scripts() {
392 global $pagenow;
393
394
395 do_action('taxopress_admin_class_before_assets_register');
396
397 //color picker style
398 wp_enqueue_style( 'wp-color-picker' );
399
400 // Helper TaxoPress
401 wp_register_script( 'st-helper-add-tags', STAGS_URL . '/assets/js/helper-add-tags.js', array( 'jquery' ), STAGS_VERSION );
402 wp_register_script( 'st-helper-options', STAGS_URL . '/assets/js/helper-options.js', array( 'jquery', 'wp-color-picker' ), STAGS_VERSION );
403
404 // Register CSS
405 wp_register_style( 'st-admin', STAGS_URL . '/assets/css/admin.css', array(), STAGS_VERSION, 'all' );
406
407 //Register and enqueue admin js
408 wp_register_script( 'st-admin-js', STAGS_URL . '/assets/js/admin.js', array( 'jquery' ), STAGS_VERSION );
409 wp_enqueue_script( 'st-admin-js' );
410 //localize script
411 wp_localize_script( 'st-admin-js', 'st_admin_localize', [
412 'ajaxurl' => admin_url('admin-ajax.php'),
413 'select_valid'=> __( 'Please select a valid', 'simple-tags' ),
414 'check_nonce' => wp_create_nonce('st-admin-js'),
415 ]);
416
417
418 //Register remodal assets
419 wp_register_script( 'st-remodal-js', STAGS_URL . '/assets/js/remodal.min.js', array( 'jquery' ), STAGS_VERSION );
420 wp_register_style( 'st-remodal-css', STAGS_URL . '/assets/css/remodal.css', array(), STAGS_VERSION, 'all' );
421 wp_register_style( 'st-remodal-default-theme-css', STAGS_URL . '/assets/css/remodal-default-theme.css', array(), STAGS_VERSION, 'all' );
422
423 // Register location
424 $wp_post_pages = array( 'post.php', 'post-new.php' );
425 $wp_page_pages = array( 'page.php', 'page-new.php' );
426
427 $taxopress_pages = taxopress_admin_pages();
428
429 // Common Helper for Post, Page and Plugin Page
430 if (
431 in_array( $pagenow, $wp_post_pages ) ||
432 ( in_array( $pagenow, $wp_page_pages ) && is_page_have_tags() ) ||
433 ( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages ) )
434 ) {
435 wp_enqueue_script( 'st-remodal-js' );
436 wp_enqueue_style( 'st-remodal-css' );
437 wp_enqueue_style( 'st-remodal-default-theme-css' );
438 wp_enqueue_style( 'st-admin' );
439
440 do_action('taxopress_admin_class_after_styles_enqueue');
441 }
442
443 // add jQuery tabs for options page. Use jQuery UI Tabs from WP
444 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array('st_options','st_terms_display') ) ) {
445 wp_enqueue_script( 'jquery-ui-tabs' );
446 wp_enqueue_script( 'st-helper-options' );
447 }
448
449 do_action('taxopress_admin_class_after_assets_enqueue');
450 }
451
452 /**
453 * Add settings page on WordPress admin menu
454 *
455 * @return void
456 * @author WebFactory Ltd
457 */
458 public static function admin_menu() {
459 self::$admin_url = admin_url( 'admin.php?page=' . self::MENU_SLUG );
460
461 add_menu_page(
462 __( 'TaxoPress: Options', 'simple-tags' ),
463 __( 'TaxoPress', 'simple-tags' ),
464 'admin_simple_tags',
465 self::MENU_SLUG,
466 array(
467 __CLASS__,
468 'page_options',
469 ),
470 'dashicons-tag',
471 69.999
472 );
473 add_submenu_page(
474 self::MENU_SLUG,
475 __( 'TaxoPress: Options', 'simple-tags' ),
476 __( 'Settings', 'simple-tags' ),
477 'admin_simple_tags',
478 self::MENU_SLUG,
479 array(
480 __CLASS__,
481 'page_options',
482 )
483 );
484 }
485
486 /**
487 * Build HTML for page options, manage also save/reset settings
488 *
489 * @return void
490 * @author WebFactory Ltd
491 */
492 public static function page_options() {
493 // Get options
494 $options = SimpleTags_Plugin::get_option();
495
496 // Update or reset options
497 if ( isset( $_POST['updateoptions'] ) ) {
498 check_admin_referer( 'updateresetoptions-simpletags' );
499
500 foreach ( (array) $options as $key => $value ) {
501 $newval = ( isset( $_POST[ $key ] ) ) ? stripslashes( $_POST[ $key ] ) : '0';
502 if ( $newval != $value ) {
503 $options[ $key ] = $newval;
504 }
505 }
506 SimpleTags_Plugin::set_option( $options );
507
508 do_action( 'simpletags_settings_save_general_end' );
509
510 add_settings_error( __CLASS__, __CLASS__, __( 'Options saved', 'simple-tags' ), 'updated' );
511 } elseif ( isset( $_POST['reset_options'] ) ) {
512 check_admin_referer( 'updateresetoptions-simpletags' );
513
514 SimpleTags_Plugin::set_default_option();
515
516 add_settings_error( __CLASS__, __CLASS__, __( 'TaxoPress options resetted to default options!', 'simple-tags' ), 'updated' );
517 }
518
519 settings_errors( __CLASS__ );
520 include STAGS_DIR . '/views/admin/page-settings.php';
521 }
522
523 /**
524 * Get terms for a post, format terms for input and autocomplete usage
525 *
526 * @param string $taxonomy
527 * @param integer $post_id
528 *
529 * @return string
530 * @author WebFactory Ltd
531 */
532 public static function getTermsToEdit( $taxonomy = 'post_tag', $post_id = 0 ) {
533 $post_id = (int) $post_id;
534 if ( ! $post_id ) {
535 return '';
536 }
537
538 $terms = wp_get_post_terms( $post_id, $taxonomy, array( 'fields' => 'names' ) );
539 if ( empty( $terms ) || is_wp_error( $terms ) ) {
540 return '';
541 }
542
543 $terms = array_unique( $terms ); // Remove duplicate
544 $terms = join( ', ', $terms );
545 $terms = esc_attr( $terms );
546 $terms = apply_filters( 'tags_to_edit', $terms );
547
548 return $terms;
549 }
550
551 /**
552 * Default content for meta box of TaxoPress
553 *
554 * @return string
555 * @author WebFactory Ltd
556 */
557 public static function getDefaultContentBox() {
558 if ( (int) wp_count_terms( 'post_tag', array( 'hide_empty' => false ) ) == 0 ) { // TODO: Custom taxonomy
559 return __( 'This feature requires at least 1 tag to work. Begin by adding tags!', 'simple-tags' );
560 } else {
561 return __( 'This feature works only with activated JavaScript. Activate it in your Web browser so you can!', 'simple-tags' );
562 }
563 }
564
565 /**
566 * A short public static function for display the same copyright on all admin pages
567 *
568 * @return void
569 * @author WebFactory Ltd
570 */
571 public static function printAdminFooter() {
572 /* ?>
573 <p class="footer_st"><?php printf( __( 'Thanks for using TaxoPress | <a href="https://taxopress.com/">TaxoPress.com</a> | Version %s', 'simple-tags' ), STAGS_VERSION ); ?></p>
574 <?php */
575 }
576
577 /**
578 * A short public static function for display the same copyright on all taxopress admin pages
579 *
580 * @return void
581 * @author Olatechpro
582 */
583 public static function taxopress_admin_footer() {
584
585 $taxopress_pages = taxopress_admin_pages();
586
587 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages )) {
588 ?>
589 <p class="footer_st"><?php printf( __( 'Thanks for using TaxoPress | <a href="https://taxopress.com/">TaxoPress.com</a> | Version %s', 'simple-tags' ), STAGS_VERSION ); ?></p>
590 <?php
591 }
592 }
593
594 /**
595 * Ouput formatted options
596 *
597 * @param array $option_data
598 *
599 * @return string
600 * @author WebFactory Ltd
601 */
602 public static function print_options( $option_data ) {
603 // Get options
604 $option_actual = SimpleTags_Plugin::get_option();
605
606 // Generate output
607 $output = '';
608 foreach ( $option_data as $section => $options ) {
609 $colspan = count( $options ) > 1 ? 'colspan="2"' : '';
610 $desc_html_tag = 'div';
611
612 if($section === 'legacy'){
613 $table_sub_tab = '<div class="st-legacy-subtab">
614 <span class="active" data-content=".legacy-tag-cloud-content">Tag Cloud</span> |
615 <span data-content=".legacy-post-tags-content">Tags for Current Post</span> |
616 <span data-content=".legacy-related-posts-content">Related Posts</span> |
617 <span data-content=".legacy-auto-link-content">Auto link</span>
618 </div>' . PHP_EOL;
619 }else{
620 $table_sub_tab = '';
621 }
622
623 $output .= '<div class="group" id="' . sanitize_title( $section ) . '">' . PHP_EOL;
624 $output .= $table_sub_tab;
625 $output .= '<fieldset class="options">' . PHP_EOL;
626 $output .= '<legend>' . self::getNiceTitleOptions( $section ) . '</legend>' . PHP_EOL;
627 $output .= '<table class="form-table">' . PHP_EOL;
628 foreach ( (array) $options as $option ) {
629
630 $class = '';
631 if($section === 'legacy'){
632 $class = $option[5];
633 }
634
635 // Helper
636 if ( $option[2] == 'helper' ) {
637 $output .= '<tr style="vertical-align: middle;" class="'.$class.'"><td class="helper" ' . $colspan . '>' . stripslashes( $option[4] ) . '</td></tr>' . PHP_EOL;
638 continue;
639 }
640
641 // Fix notices
642 if ( ! isset( $option_actual[ $option[0] ] ) ) {
643 $option_actual[ $option[0] ] = '';
644 }
645
646 $input_type = '';
647 switch ( $option[2] ) {
648 case 'radio':
649 $input_type = array();
650 foreach ( $option[3] as $value => $text ) {
651 $input_type[] = '<label><input type="radio" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $value ) . '" ' . checked( $value, $option_actual[ $option[0] ], false ) . ' /> ' . $text . '</label>' . PHP_EOL;
652 }
653 $input_type = implode( '<br />', $input_type );
654 break;
655
656 case 'checkbox':
657 $desc_html_tag = 'span';
658 $input_type = '<input type="checkbox" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option[3] ) . '" ' . ( ( $option_actual[ $option[0] ] ) ? 'checked="checked"' : '' ) . ' />' . PHP_EOL;
659 break;
660
661 case 'dropdown':
662 $selopts = explode( '/', $option[3] );
663 $seldata = '';
664 foreach ( (array) $selopts as $sel ) {
665 $seldata .= '<option value="' . esc_attr( $sel ) . '" ' . ( ( isset( $option_actual[ $option[0] ] ) && $option_actual[ $option[0] ] == $sel ) ? 'selected="selected"' : '' ) . ' >' . ucfirst( $sel ) . '</option>' . PHP_EOL;
666 }
667 $input_type = '<select id="' . $option[0] . '" name="' . $option[0] . '">' . $seldata . '</select>' . PHP_EOL;
668 break;
669
670 case 'text-color':
671 $input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="text-color ' . $option[3] . '" />' . PHP_EOL;
672 break;
673
674 case 'text':
675 $input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" />' . PHP_EOL;
676 break;
677
678 case 'number':
679 $input_type = '<input type="number" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" />' . PHP_EOL;
680 break;
681 }
682
683 if( is_array($option[2]) ){
684 $input_type = '<input type="'.$option[2]["type"].'" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" '.$option[2]["attr"].' />' . PHP_EOL;
685 }
686
687 // Additional Information
688 $extra = '';
689 if ( ! empty( $option[4] ) ) {
690 $extra = '<' . $desc_html_tag . ' class="stpexplan">' . __( $option[4] ) . '</' . $desc_html_tag . '>' . PHP_EOL;
691 }
692
693 // Output
694 $output .= '<tr style="vertical-align: top;" class="'.$class.'"><th scope="row"><label for="' . $option[0] . '">' . __( $option[1] ) . '</label></th><td>' . $input_type . ' ' . $extra . '</td></tr>' . PHP_EOL;
695 }
696 $output .= '</table>' . PHP_EOL;
697 $output .= '</fieldset>' . PHP_EOL;
698 $output .= '</div>' . PHP_EOL;
699 }
700
701 return $output;
702 }
703
704 /**
705 * Get nice title for tabs title option
706 *
707 * @param string $id
708 *
709 * @return string
710 */
711 public static function getNiceTitleOptions( $id = '' ) {
712 switch ( $id ) {
713 case 'administration':
714 return __( 'Administration', 'simple-tags' );
715 case 'auto-links':
716 return __( 'Auto link', 'simple-tags' );
717 case 'features':
718 return __( 'Features', 'simple-tags' );
719 case 'embeddedtags':
720 return __( 'Embedded Tags', 'simple-tags' );
721 case 'tagspost':
722 return __( 'Tags for Current Post', 'simple-tags' );
723 case 'relatedposts':
724 return __( 'Related Posts', 'simple-tags' );
725 case 'legacy':
726 return __( 'Legacy', 'simple-tags' );
727 }
728
729 return '';
730 }
731
732 /**
733 * This method allow to check if the DB is up to date, and if a upgrade is need for options
734 * TODO, useful or delete ?
735 *
736 * @return void
737 * @author WebFactory Ltd
738 */
739 public static function upgrade() {
740 // Get current version number
741 $current_version = get_option( STAGS_OPTIONS_NAME . '-version' );
742
743 // Upgrade needed ?
744 if ( $current_version == false || version_compare( $current_version, STAGS_VERSION, '<' ) ) {
745 $current_options = get_option( STAGS_OPTIONS_NAME );
746 $default_options = (array) include( STAGS_DIR . '/inc/helper.options.default.php' );
747
748 // Add new options
749 foreach ( $default_options as $key => $default_value ) {
750 if ( ! isset( $current_options[ $key ] ) ) {
751 $current_options[ $key ] = $default_value;
752 }
753 }
754
755 // Remove old options
756 foreach ( $current_options as $key => $current_value ) {
757 if ( ! isset( $default_options[ $key ] ) ) {
758 unset( $current_options[ $key ] );
759 }
760 }
761
762 update_option( STAGS_OPTIONS_NAME . '-version', STAGS_VERSION );
763 update_option( STAGS_OPTIONS_NAME, $current_options );
764 }
765 }
766
767 /**
768 * Make a simple SQL query with some args for get terms for ajax display
769 *
770 * @param string $taxonomy
771 * @param string $search
772 * @param string $order_by
773 * @param string $order
774 *
775 * @return array
776 * @author WebFactory Ltd
777 */
778 public static function getTermsForAjax( $taxonomy = 'post_tag', $search = '', $order_by = 'name', $order = 'ASC', $limit = '' ) {
779 global $wpdb;
780
781 if ( ! empty( $search ) ) {
782 return $wpdb->get_results( $wpdb->prepare( "
783 SELECT DISTINCT t.name, t.term_id
784 FROM {$wpdb->terms} AS t
785 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
786 WHERE tt.taxonomy = %s
787 AND t.name LIKE %s
788 ORDER BY $order_by $order $limit
789 ", $taxonomy, '%' . $search . '%' ) );
790 } else {
791 return $wpdb->get_results( $wpdb->prepare( "
792 SELECT DISTINCT t.name, t.term_id
793 FROM {$wpdb->terms} AS t
794 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
795 WHERE tt.taxonomy = %s
796 ORDER BY $order_by $order $limit
797 ", $taxonomy ) );
798 }
799 }
800 }
801