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

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