PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.4.3
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.4.3
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.3, at inc/class.admin.php

804 lines 28.1 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 = sanitize_text_field(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 if(current_user_can('admin_simple_tags')){
497 // Update or reset options
498 if ( isset( $_POST['updateoptions'] ) ) {
499 check_admin_referer( 'updateresetoptions-simpletags' );
500
501 foreach ( (array) $options as $key => $value ) {
502 $newval = ( isset( $_POST[ $key ] ) ) ? stripslashes( $_POST[ $key ] ) : '0';
503 if ( $newval != $value ) {
504 $options[ $key ] = $newval;
505 }
506 }
507 SimpleTags_Plugin::set_option( $options );
508
509 do_action( 'simpletags_settings_save_general_end' );
510
511 add_settings_error( __CLASS__, __CLASS__, __( 'Options saved', 'simple-tags' ), 'updated' );
512 } elseif ( isset( $_POST['reset_options'] ) ) {
513 check_admin_referer( 'updateresetoptions-simpletags' );
514
515 SimpleTags_Plugin::set_default_option();
516
517 add_settings_error( __CLASS__, __CLASS__, __( 'TaxoPress options resetted to default options!', 'simple-tags' ), 'updated' );
518 }
519
520 }
521
522 settings_errors( __CLASS__ );
523 include STAGS_DIR . '/views/admin/page-settings.php';
524 }
525
526 /**
527 * Get terms for a post, format terms for input and autocomplete usage
528 *
529 * @param string $taxonomy
530 * @param integer $post_id
531 *
532 * @return string
533 * @author WebFactory Ltd
534 */
535 public static function getTermsToEdit( $taxonomy = 'post_tag', $post_id = 0 ) {
536 $post_id = (int) $post_id;
537 if ( ! $post_id ) {
538 return '';
539 }
540
541 $terms = wp_get_post_terms( $post_id, $taxonomy, array( 'fields' => 'names' ) );
542 if ( empty( $terms ) || is_wp_error( $terms ) ) {
543 return '';
544 }
545
546 $terms = array_unique( $terms ); // Remove duplicate
547 $terms = join( ', ', $terms );
548 $terms = esc_attr( $terms );
549 $terms = apply_filters( 'tags_to_edit', $terms );
550
551 return $terms;
552 }
553
554 /**
555 * Default content for meta box of TaxoPress
556 *
557 * @return string
558 * @author WebFactory Ltd
559 */
560 public static function getDefaultContentBox() {
561 if ( (int) wp_count_terms( 'post_tag', array( 'hide_empty' => false ) ) == 0 ) { // TODO: Custom taxonomy
562 return __( 'This feature requires at least 1 tag to work. Begin by adding tags!', 'simple-tags' );
563 } else {
564 return __( 'This feature works only with activated JavaScript. Activate it in your Web browser so you can!', 'simple-tags' );
565 }
566 }
567
568 /**
569 * A short public static function for display the same copyright on all admin pages
570 *
571 * @return void
572 * @author WebFactory Ltd
573 */
574 public static function printAdminFooter() {
575 /* ?>
576 <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>
577 <?php */
578 }
579
580 /**
581 * A short public static function for display the same copyright on all taxopress admin pages
582 *
583 * @return void
584 * @author Olatechpro
585 */
586 public static function taxopress_admin_footer() {
587
588 $taxopress_pages = taxopress_admin_pages();
589
590 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages )) {
591 ?>
592 <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>
593 <?php
594 }
595 }
596
597 /**
598 * Ouput formatted options
599 *
600 * @param array $option_data
601 *
602 * @return string
603 * @author WebFactory Ltd
604 */
605 public static function print_options( $option_data ) {
606 // Get options
607 $option_actual = SimpleTags_Plugin::get_option();
608
609 // Generate output
610 $output = '';
611 foreach ( $option_data as $section => $options ) {
612 $colspan = count( $options ) > 1 ? 'colspan="2"' : '';
613 $desc_html_tag = 'div';
614
615 if($section === 'legacy'){
616 $table_sub_tab = '<div class="st-legacy-subtab">
617 <span class="active" data-content=".legacy-tag-cloud-content">Tag Cloud</span> |
618 <span data-content=".legacy-post-tags-content">Tags for Current Post</span> |
619 <span data-content=".legacy-related-posts-content">Related Posts</span> |
620 <span data-content=".legacy-auto-link-content">Auto link</span>
621 </div>' . PHP_EOL;
622 }else{
623 $table_sub_tab = '';
624 }
625
626 $output .= '<div class="group" id="' . sanitize_title( $section ) . '">' . PHP_EOL;
627 $output .= $table_sub_tab;
628 $output .= '<fieldset class="options">' . PHP_EOL;
629 $output .= '<legend>' . self::getNiceTitleOptions( $section ) . '</legend>' . PHP_EOL;
630 $output .= '<table class="form-table">' . PHP_EOL;
631 foreach ( (array) $options as $option ) {
632
633 $class = '';
634 if($section === 'legacy'){
635 $class = $option[5];
636 }
637
638 // Helper
639 if ( $option[2] == 'helper' ) {
640 $output .= '<tr style="vertical-align: middle;" class="'.$class.'"><td class="helper" ' . $colspan . '>' . stripslashes( $option[4] ) . '</td></tr>' . PHP_EOL;
641 continue;
642 }
643
644 // Fix notices
645 if ( ! isset( $option_actual[ $option[0] ] ) ) {
646 $option_actual[ $option[0] ] = '';
647 }
648
649 $input_type = '';
650 switch ( $option[2] ) {
651 case 'radio':
652 $input_type = array();
653 foreach ( $option[3] as $value => $text ) {
654 $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;
655 }
656 $input_type = implode( '<br />', $input_type );
657 break;
658
659 case 'checkbox':
660 $desc_html_tag = 'span';
661 $input_type = '<input type="checkbox" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option[3] ) . '" ' . ( ( $option_actual[ $option[0] ] ) ? 'checked="checked"' : '' ) . ' />' . PHP_EOL;
662 break;
663
664 case 'dropdown':
665 $selopts = explode( '/', $option[3] );
666 $seldata = '';
667 foreach ( (array) $selopts as $sel ) {
668 $seldata .= '<option value="' . esc_attr( $sel ) . '" ' . ( ( isset( $option_actual[ $option[0] ] ) && $option_actual[ $option[0] ] == $sel ) ? 'selected="selected"' : '' ) . ' >' . ucfirst( $sel ) . '</option>' . PHP_EOL;
669 }
670 $input_type = '<select id="' . $option[0] . '" name="' . $option[0] . '">' . $seldata . '</select>' . PHP_EOL;
671 break;
672
673 case 'text-color':
674 $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;
675 break;
676
677 case 'text':
678 $input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" />' . PHP_EOL;
679 break;
680
681 case 'number':
682 $input_type = '<input type="number" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" />' . PHP_EOL;
683 break;
684 }
685
686 if( is_array($option[2]) ){
687 $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;
688 }
689
690 // Additional Information
691 $extra = '';
692 if ( ! empty( $option[4] ) ) {
693 $extra = '<' . $desc_html_tag . ' class="stpexplan">' . __( $option[4] ) . '</' . $desc_html_tag . '>' . PHP_EOL;
694 }
695
696 // Output
697 $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;
698 }
699 $output .= '</table>' . PHP_EOL;
700 $output .= '</fieldset>' . PHP_EOL;
701 $output .= '</div>' . PHP_EOL;
702 }
703
704 return $output;
705 }
706
707 /**
708 * Get nice title for tabs title option
709 *
710 * @param string $id
711 *
712 * @return string
713 */
714 public static function getNiceTitleOptions( $id = '' ) {
715 switch ( $id ) {
716 case 'administration':
717 return __( 'Administration', 'simple-tags' );
718 case 'auto-links':
719 return __( 'Auto link', 'simple-tags' );
720 case 'features':
721 return __( 'Features', 'simple-tags' );
722 case 'embeddedtags':
723 return __( 'Embedded Tags', 'simple-tags' );
724 case 'tagspost':
725 return __( 'Tags for Current Post', 'simple-tags' );
726 case 'relatedposts':
727 return __( 'Related Posts', 'simple-tags' );
728 case 'legacy':
729 return __( 'Legacy', 'simple-tags' );
730 }
731
732 return '';
733 }
734
735 /**
736 * This method allow to check if the DB is up to date, and if a upgrade is need for options
737 * TODO, useful or delete ?
738 *
739 * @return void
740 * @author WebFactory Ltd
741 */
742 public static function upgrade() {
743 // Get current version number
744 $current_version = get_option( STAGS_OPTIONS_NAME . '-version' );
745
746 // Upgrade needed ?
747 if ( $current_version == false || version_compare( $current_version, STAGS_VERSION, '<' ) ) {
748 $current_options = get_option( STAGS_OPTIONS_NAME );
749 $default_options = (array) include( STAGS_DIR . '/inc/helper.options.default.php' );
750
751 // Add new options
752 foreach ( $default_options as $key => $default_value ) {
753 if ( ! isset( $current_options[ $key ] ) ) {
754 $current_options[ $key ] = $default_value;
755 }
756 }
757
758 // Remove old options
759 foreach ( $current_options as $key => $current_value ) {
760 if ( ! isset( $default_options[ $key ] ) ) {
761 unset( $current_options[ $key ] );
762 }
763 }
764
765 update_option( STAGS_OPTIONS_NAME . '-version', STAGS_VERSION );
766 update_option( STAGS_OPTIONS_NAME, $current_options );
767 }
768 }
769
770 /**
771 * Make a simple SQL query with some args for get terms for ajax display
772 *
773 * @param string $taxonomy
774 * @param string $search
775 * @param string $order_by
776 * @param string $order
777 *
778 * @return array
779 * @author WebFactory Ltd
780 */
781 public static function getTermsForAjax( $taxonomy = 'post_tag', $search = '', $order_by = 'name', $order = 'ASC', $limit = '' ) {
782 global $wpdb;
783
784 if ( ! empty( $search ) ) {
785 return $wpdb->get_results( $wpdb->prepare( "
786 SELECT DISTINCT t.name, t.term_id
787 FROM {$wpdb->terms} AS t
788 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
789 WHERE tt.taxonomy = %s
790 AND t.name LIKE %s
791 ORDER BY $order_by $order $limit
792 ", $taxonomy, '%' . $wpdb->esc_like($search) . '%' ) );
793 } else {
794 return $wpdb->get_results( $wpdb->prepare( "
795 SELECT DISTINCT t.name, t.term_id
796 FROM {$wpdb->terms} AS t
797 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
798 WHERE tt.taxonomy = %s
799 ORDER BY $order_by $order $limit
800 ", $taxonomy ) );
801 }
802 }
803 }
804