PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.2.7.3
Permalink Manager Lite v2.2.7.3
2.5.4 2.5.3.4 2.2.18 2.2.19.2 2.2.19.3 2.2.19.3.1 2.2.2 2.2.20 2.2.20.1 2.2.20.3 2.2.4 2.2.5 2.2.6 2.2.7.2 2.2.7.3 2.2.7.5 2.2.7.6 2.2.8.4 2.2.8.5 2.2.8.6 2.2.8.7 2.2.8.9 2.2.9.1 2.2.9.2 2.2.9.2.1 2.2.9.3 2.2.9.4 2.2.9.6 2.2.9.7 2.2.9.9 2.3.0 2.3.1.1 2.4.0 2.4.1 2.4.1.2 2.4.1.3 2.4.1.4 2.4.1.5 2.4.1.6 2.4.2 2.4.2.1 2.4.3 2.4.3.1 2.4.3.2 2.4.3.3 2.4.3.4 2.4.4 2.4.4.1 2.4.4.2 2.4.4.3 2.5.0 2.5.1 2.5.1.1 2.5.1.2 2.5.1.3 2.5.1.4 2.5.2 2.5.2.1 2.5.2.2 2.5.2.3 2.5.2.4 2.5.3 2.5.3.1 2.5.3.2 2.5.3.3 trunk 0.2 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.4.8 0.4.9 0.5.3 0.5.4 1.0.0 1.0.1 1.0.4 1.1.0 1.1.1 1.1.2 1.11.6.3 2.0.0 2.0.3 2.0.4 2.0.4.3 2.0.5.1 2.0.5.2 2.0.5.3 2.0.5.3.1 2.0.5.4 2.0.5.4a 2.0.5.5 2.0.5.6 2.0.5.6.1 2.0.5.7 2.0.5.9a 2.0.6.2.1 2.0.6.2a 2.0.6.3 2.1.0 2.1.1 2.1.2.4 2.2.0 2.2.1.1 2.2.1.2 2.2.11 2.2.12 2.2.13.1 2.2.14 2.2.15.1 2.2.16 2.2.17
permalink-manager / includes / core / permalink-manager-admin-functions.php
permalink-manager / includes / core Last commit date
permalink-manager-actions.php 6 years ago permalink-manager-admin-functions.php 6 years ago permalink-manager-core-functions.php 6 years ago permalink-manager-debug.php 6 years ago permalink-manager-gutenberg.php 6 years ago permalink-manager-helper-functions.php 6 years ago permalink-manager-third-parties.php 6 years ago permalink-manager-uri-functions-post.php 6 years ago
permalink-manager-admin-functions.php
1062 lines
1 <?php
2
3 /**
4 * Additional back-end functions related to Wordpress Dashboard UI
5 */
6 class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
7
8 public $menu_name, $sections, $active_section, $active_subsection;
9 public $plugin_basename = PERMALINK_MANAGER_BASENAME;
10
11 public function __construct() {
12 add_action( 'admin_menu', array($this, 'add_menu_page') );
13 add_action( 'admin_init', array($this, 'init') );
14 add_action( 'admin_init', array($this, 'redirect_customizer') );
15
16 add_action( 'admin_notices', array($this, 'display_plugin_notices'));
17 add_action( 'admin_notices', array($this, 'display_global_notices'));
18 add_action( 'wp_ajax_dismissed_notice_handler', array($this, 'hide_global_notice') );
19
20 add_filter( 'default_hidden_columns', array($this, 'quick_edit_hide_column'), 10, 2 );
21
22 add_action( 'wp_ajax_detect_duplicates', array($this, 'ajax_detect_duplicates') );
23 }
24
25 /**
26 * Hooks that should be triggered with "admin_init"
27 */
28 public function init() {
29 // Additional links in "Plugins" page
30 add_filter( "plugin_action_links_{$this->plugin_basename}", array($this, "plugins_page_links") );
31 add_filter( "plugin_row_meta", array($this, "plugins_page_meta"), 10, 2 );
32
33 // Detect current section
34 $this->sections = apply_filters('permalink_manager_sections', array());
35 $this->get_current_section();
36 }
37
38 /**
39 * Redirect custom permalinks to the native ones in Customizer editor
40 */
41 public function redirect_customizer() {
42 if(strpos($_SERVER['REQUEST_URI'], 'customize.php') && !empty($_GET['url'])) {
43 $old_url = $_GET['url'];
44 $old_path = trim(parse_url($old_url, PHP_URL_PATH), "/");
45 $old_query = parse_url($old_url, PHP_URL_QUERY);
46
47 // Detect the post/term
48 $element = Permalink_Manager_Core_Functions::detect_post(null, $old_url, true);
49
50 if(!empty($element->ID)) {
51 $correct_permalink = get_permalink($element->ID);
52 } else if(!empty($element->term_id)) {
53 $correct_permalink = get_term_link($element, $element->taxonomy);
54 }
55
56 // Get the full URL
57 if(!empty($correct_permalink)) {
58 $new_path = trim(parse_url($correct_permalink, PHP_URL_PATH), "/");
59
60 $new_customize_url = wp_customize_url();
61 $new_customize_url .= "?" . str_replace(urlencode($old_path), urlencode($new_path), parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY));
62 $new_customize_url .= ($old_query) ? "&{$old_query}" : "";
63
64 // Redirect to customizer with native permalink
65 if($old_path !== $new_path) {
66 wp_safe_redirect($new_customize_url);
67 exit();
68 }
69 }
70 }
71 }
72
73 /**
74 * Get current section (only in plugin sections)
75 */
76 public function get_current_section() {
77 global $active_section, $active_subsection, $current_admin_tax;
78
79 // 1. Get current section
80 if(isset($_GET['page']) && $_GET['page'] == PERMALINK_MANAGER_PLUGIN_SLUG) {
81 if(isset($_POST['section'])) {
82 $this->active_section = $_POST['section'];
83 } else if(isset($_GET['section'])) {
84 $this->active_section = $_GET['section'];
85 } else {
86 $sections_names = array_keys($this->sections);
87 $this->active_section = $sections_names[0];
88 }
89 }
90
91 // 2. Get current subsection
92 if($this->active_section && isset($this->sections[$this->active_section]['subsections'])) {
93 if(isset($_POST['subsection'])) {
94 $this->active_subsection = $_POST['subsection'];
95 } else if(isset($_GET['subsection'])) {
96 $this->active_subsection = $_GET['subsection'];
97 } else {
98 $subsections_names = array_keys($this->sections[$this->active_section]['subsections']);
99 $this->active_subsection = $subsections_names[0];
100 }
101 }
102
103 // Check if current admin page is related to taxonomies
104 if(substr($this->active_subsection, 0, 4) == 'tax_') {
105 $current_admin_tax = substr($this->active_subsection, 4, strlen($this->active_subsection));
106 } else {
107 $current_admin_tax = false;
108 }
109
110 // Set globals
111 $active_section = $this->active_section;
112 $active_subsection = $this->active_subsection;
113 }
114
115 /**
116 * Add menu page.
117 */
118 public function add_menu_page() {
119 $this->menu_name = add_management_page( __('Permalink Manager', 'permalink-manager'), __('Permalink Manager', 'permalink-manager'), 'manage_options', PERMALINK_MANAGER_PLUGIN_SLUG, array($this, 'display_section') );
120
121 add_action( 'admin_init', array($this, 'enqueue_styles' ) );
122 add_action( 'admin_init', array($this, 'enqueue_scripts' ) );
123 }
124
125 /**
126 * Register the CSS file for the dashboard.
127 */
128 public function enqueue_styles() {
129 wp_enqueue_style( 'permalink-manager-plugins', PERMALINK_MANAGER_URL . '/out/permalink-manager-plugins.css', array(), PERMALINK_MANAGER_VERSION, 'all' );
130 wp_enqueue_style( 'permalink-manager', PERMALINK_MANAGER_URL . '/out/permalink-manager-admin.css', array('permalink-manager-plugins'), PERMALINK_MANAGER_VERSION, 'all' );
131 }
132
133 /**
134 * Register the JavaScript file for the dashboard.
135 */
136 public function enqueue_scripts() {
137 wp_enqueue_script( 'permalink-manager-plugins', PERMALINK_MANAGER_URL . '/out/permalink-manager-plugins.js', array( 'jquery', ), PERMALINK_MANAGER_VERSION, false );
138 wp_enqueue_script( 'permalink-manager', PERMALINK_MANAGER_URL . '/out/permalink-manager-admin.js', array( 'jquery', 'permalink-manager-plugins' ), PERMALINK_MANAGER_VERSION, false );
139
140 wp_localize_script( 'permalink-manager', 'permalink_manager', array('ajax_url' => admin_url('admin-ajax.php'), 'url' => PERMALINK_MANAGER_URL, 'spinners' => admin_url('images')) );
141
142 }
143
144 /**
145 * Get admin url for the plugin
146 */
147 public static function get_admin_url($append = '') {
148 //return menu_page_url(PERMALINK_MANAGER_PLUGIN_SLUG, false) . $append;
149 $admin_page = sprintf("tools.php?page=%s", PERMALINK_MANAGER_PLUGIN_SLUG . $append);
150
151 return admin_url($admin_page);
152 }
153
154 /**
155 * Additional links on "Plugins" page
156 */
157 public function plugins_page_links($links) {
158 $new_links = array(
159 sprintf('<a href="%s">%s</a>', $this->get_admin_url(), __( 'URI Editor', 'permalink-manager' )),
160 sprintf('<a href="%s">%s</a>', $this->get_admin_url('&section=settings'), __( 'Settings', 'permalink-manager' )),
161 );
162
163 return array_merge($links, $new_links);
164 }
165
166 /**
167 * Additional meta links on "Plugins" page
168 */
169 public function plugins_page_meta($links, $file) {
170 if($file == PERMALINK_MANAGER_BASENAME) {
171 $new_links = array(
172 'doc' => sprintf('<a href="%s?utm_source=plugin_admin_page" target="_blank">%s</a>', 'https://permalinkmanager.pro/docs/', __( 'Documentation', 'permalink-manager' ))
173 );
174
175 if(!defined('PERMALINK_MANAGER_PRO')) {
176 $new_links['upgrade'] = sprintf('<a href="%s?utm_source=plugin_admin_page" target="_blank"><strong>%s</strong></a>', PERMALINK_MANAGER_WEBSITE, __( 'Buy Permalink Manager Pro', 'permalink-manager' ));
177 }
178
179 $links = array_merge($links, $new_links);
180 }
181
182 return $links;
183 }
184
185 /**
186 * Generate the fields
187 */
188 static public function generate_option_field($input_name, $args) {
189 global $permalink_manager_options, $permalink_manager_permastructs;
190
191 // Reset $fields variables
192 $fields = $section_name = $field_name = '';
193
194 // Allow to filter the $args
195 $args = apply_filters('permalink_manager_field_args', $args, $input_name);
196
197 $field_type = (isset($args['type'])) ? $args['type'] : 'text';
198 $default = (isset($args['default'])) ? $args['default'] : '';
199 $label = (isset($args['label'])) ? $args['label'] : '';
200 $rows = (isset($args['rows'])) ? "rows=\"{$rows}\"" : "rows=\"5\"";
201 $container_class = (isset($args['container_class'])) ? " class=\"{$args['container_class']} field-container\"" : " class=\"field-container\"";
202 $description = (isset($args['before_description'])) ? $args['before_description'] : "";
203 $description .= (isset($args['description'])) ? "<p class=\"field-description description\">{$args['description']}</p>" : "";
204 $description .= (isset($args['after_description'])) ? $args['after_description'] : "";
205 $description .= (isset($args['pro'])) ? sprintf("<p class=\"field-description description alert info\">%s</p>", (Permalink_Manager_Admin_Functions::pro_text(true))) : "";
206 $append_content = (isset($args['append_content'])) ? "{$args['append_content']}" : "";
207
208 // Input attributes
209 $input_atts = (isset($args['input_class'])) ? "class='{$args['input_class']}'" : '';
210 $input_atts .= (isset($args['readonly'])) ? " readonly='readonly'" : '';
211 $input_atts .= (isset($args['disabled'])) ? " disabled='disabled'" : '';
212 $input_atts .= (isset($args['placeholder'])) ? " placeholder='{$args['placeholder']}'" : '';
213 $input_atts .= (isset($args['extra_atts'])) ? " {$args['extra_atts']}" : '';
214
215 // Get the field value (if it is not set in $args)
216 if(isset($args['value']) && empty($args['value']) == false) {
217 $value = $args['value'];
218 } else {
219 // Extract the section and field name from $input_name
220 preg_match('/([^\[]+)(?:\[([^\[]+)\])(?:\[([^\[]+)\])?/', $input_name, $field_section_and_name);
221
222 if($field_section_and_name) {
223 $section_name = $field_section_and_name[1];
224 if(!empty($field_section_and_name[3])) {
225 $field_name = $field_section_and_name[2];
226 $subsection_name = $field_section_and_name[3];
227 $value = (isset($permalink_manager_options[$section_name][$field_name][$subsection_name])) ? $permalink_manager_options[$section_name][$field_name][$subsection_name] : $default;
228 } else {
229 $field_name = $field_section_and_name[2];
230 $value = (isset($permalink_manager_options[$section_name][$field_name])) ? $permalink_manager_options[$section_name][$field_name] : $default;
231 }
232 } else {
233 $value = (isset($permalink_manager_options[$input_name])) ? $permalink_manager_options[$input_name] : $default;
234 }
235 }
236
237 switch($field_type) {
238 case 'checkbox' :
239 $fields .= '<div class="checkboxes">';
240 foreach($args['choices'] as $choice_value => $choice) {
241 $input_template = "<label for='%s[]'><input type='checkbox' %s value='%s' name='%s[]' %s /> %s</label>";
242
243 if(empty($choice['label']) && is_array($choice)) {
244 foreach($choice as $sub_choice_value => $sub_choice) {
245 $label = (!empty($sub_choice['label'])) ? $sub_choice['label'] : $sub_choice;
246 $atts = (!empty($value[$choice_value]) && in_array($sub_choice_value, $value[$choice_value])) ? "checked='checked'" : "";
247 $atts .= (!empty($sub_choice['atts'])) ? " {$sub_choice['atts']}" : "";
248
249 $fields .= sprintf($input_template, $input_name, $input_atts, $sub_choice_value, "{$input_name}[{$choice_value}]", $atts, $label);
250 }
251 } else {
252 $label = (!empty($choice['label'])) ? $choice['label'] : $choice;
253 $atts = (is_array($value) && in_array($choice_value, $value)) ? "checked='checked'" : "";
254 $atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
255
256 $fields .= sprintf($input_template, $input_name, $input_atts, $choice_value, $input_name, $atts, $label);
257 }
258 }
259 $fields .= '</div>';
260
261 // Add helper checkboxes for bulk actions
262 if(isset($args['select_all']) || isset($args['unselect_all'])) {
263 $select_all_label = (!empty($args['select_all'])) ? $args['select_all'] : __('Select all', 'permalink-manager');
264 $unselect_all_label = (!empty($args['unselect_all'])) ? $args['unselect_all'] : __('Unselect all', 'permalink-manager');
265
266 $fields .= "<p class=\"checkbox_actions extra-links\">";
267 $fields .= (isset($args['select_all'])) ? "<a href=\"#\" class=\"select_all\">{$select_all_label}</a>&nbsp;" : "";
268 $fields .= (isset($args['unselect_all'])) ? "<a href=\"#\" class=\"unselect_all\">{$unselect_all_label}</a>" : "";
269 $fields .= "</p>";
270 }
271 break;
272
273 case 'single_checkbox' :
274 $fields .= '<div class="single_checkbox">';
275 if(is_array($value)) {
276 $input_key = preg_replace('/(.*)(?:\[([^\[]+)\])$/', '$2', $input_name);
277 $checked = (!empty($value[$input_key])) ? "checked='checked'" : "";
278 } else {
279 $checked = ($value == 1) ? "checked='checked'" : "";
280 }
281 $checkbox_label = (isset($args['checkbox_label'])) ? $args['checkbox_label'] : '';
282
283 $fields .= "<input type='hidden' {$input_atts} value='0' name='{$input_name}' />";
284 $fields .= "<label for='{$input_name}'><input type='checkbox' {$input_atts} value='1' name='{$input_name}' {$checked} /> {$checkbox_label}</label>";
285 $fields .= '</div>';
286 break;
287
288 case 'radio' :
289 $fields .= '<div class="radios">';
290 foreach($args['choices'] as $choice_value => $choice) {
291 $label = (is_array($choice)) ? $choice['label'] : $choice;
292 $atts = ($choice_value == $value) ? "checked='checked'" : "";
293 $atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
294
295 $fields .= "<label for='{$input_name}[]'><input type='radio' {$input_atts} value='{$choice_value}' name='{$input_name}[]' {$atts} /> {$label}</label>";
296 }
297 $fields .= '</div>';
298 break;
299
300 case 'select' :
301 $fields .= '<span class="select">';
302 $fields .= "<select name='{$input_name}' {$input_atts}>";
303 foreach($args['choices'] as $choice_value => $choice) {
304 $label = (is_array($choice)) ? $choice['label'] : $choice;
305 $atts = ($choice_value == $value) ? "selected='selected'" : "";
306 $atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
307
308 $fields .= "<option value='{$choice_value}' {$atts}>{$label}</option>";
309 }
310 $fields .= '</select>';
311 $fields .= '</span>';
312 break;
313
314 case 'number' :
315 $fields .= "<input type='number' {$input_atts} value='{$value}' name='{$input_name}' />";
316 break;
317
318 case 'hidden' :
319 $fields .= "<input type='hidden' {$input_atts} value='{$value}' name='{$input_name}' />";
320 break;
321
322 case 'textarea' :
323 $fields .= "<textarea {$input_atts} name='{$input_name}' {$rows}>{$value}</textarea>";
324 break;
325
326 case 'pre' :
327 $fields .= "<pre {$input_atts}>{$value}</pre>";
328 break;
329
330 case 'info' :
331 $fields .= "<div {$input_atts}>{$value}</div>";
332 break;
333
334 case 'clearfix' :
335 return "<div class=\"clearfix\"></div>";
336
337 case 'permastruct' :
338 $siteurl = Permalink_Manager_Helper_Functions::get_permalink_base();
339
340 if(!empty($args['post_type'])) {
341 $type = $args['post_type'];
342 $type_name = $type['name'];
343 $content_type = 'post_types';
344
345 $permastructures = (!empty($permalink_manager_permastructs['post_types'])) ? $permalink_manager_permastructs['post_types'] : array();
346 } else if(!empty($args['taxonomy'])) {
347 $type = $args['taxonomy'];
348 $type_name = $type['name'];
349 $content_type = "taxonomies";
350
351 $permastructures = (!empty($permalink_manager_permastructs['taxonomies'])) ? $permalink_manager_permastructs['taxonomies'] : array();
352 } else {
353 break;
354 }
355
356 // Get permastructures
357 $default_permastruct = trim(Permalink_Manager_Helper_Functions::get_default_permastruct($type_name), "/");
358 $current_permastruct = isset($permastructures[$type_name]) ? $permastructures[$type_name] : $default_permastruct;
359
360 // Append extra attributes
361 $input_atts .= " data-default=\"{$default_permastruct}\"";
362 $input_atts .= " placeholder=\"{$default_permastruct}\"";
363
364 $fields .= "<div class=\"all-permastruct-container\">";
365
366 // 1. Default permastructure
367 $fields .= "<div class=\"permastruct-container\">";
368 $fields .= "<span><code>{$siteurl}/</code></span>";
369 $fields .= "<span><input type='text' {$input_atts} value='{$current_permastruct}' name='{$input_name}'/></span>";
370 $fields .= "</div>";
371
372 $fields .= "<div class=\"permastruct-toggle\">";
373
374 // 2A. Permastructure for each language
375 $languages = (array) Permalink_Manager_Third_Parties::get_all_languages(true);
376 if($languages) {
377 $fields .= sprintf(
378 "<h4>%s</h4><p class=\"permastruct-instruction\">%s</p>",
379 __("Permastructure translations", "permalink-manager"),
380 __("If you would like to translate the permastructures and set-up different permalink structure per language, please fill in the fields below. Otherwise the permastructure set for default language (see field above) will be applied.", "permalink-manager")
381 );
382
383 foreach($languages as $lang => $name) {
384 $current_lang_permastruct = isset($permastructures["{$type_name}_{$lang}"]) ? $permastructures["{$type_name}_{$lang}"] : '';
385
386 $fields .= "<label>{$name}</label>";
387 $fields .= "<div class=\"permastruct-container\">";
388 $fields .= "<span><code>{$siteurl}/</code></span>";
389 $fields .= sprintf("<span><input type='text' %s value='%s' name='%s'/></span>", $input_atts, $current_lang_permastruct, str_replace("]", "_{$lang}]", $input_name));
390 $fields .= "</div>";
391 }
392 }
393
394 // 2B. Restore default permalinks
395 $fields .= sprintf(
396 "<p class=\"default-permastruct-row columns-container\"><span class=\"column-2_4\"><strong>%s:</strong> %s</span><span class=\"column-2_4\"><a href=\"#\" class=\"restore-default\"><span class=\"dashicons dashicons-image-rotate\"></span> %s</a></span></p>",
397 __("Default permastructure", "permalink-manager"), esc_html($default_permastruct),
398 __("Restore default permastructure", "permalink-manager")
399 );
400
401 // 2B. Do not auto-append slug field
402 $fields .= sprintf(
403 "<h4>%s</h4><div class=\"settings-container\">%s</div>",
404 __("Permastructure settings", "permalink-manager"),
405 self::generate_option_field("permastructure-settings[do_not_append_slug][$content_type][{$type_name}]", array('type' => 'single_checkbox', 'checkbox_label' => __("Do not automatically append the slug", "permalink-manager")))
406 );
407
408 $fields .= "</div>";
409
410 // 3. Show toggle button
411 $fields .= sprintf(
412 "<p class=\"permastruct-toggle-button\"><a href=\"#\"><span class=\"dashicons dashicons-admin-settings\"></span> %s</a></p>",
413 __("Show additional settings", "permalink-manager")
414 );
415
416 $fields .= "</div>";
417
418 break;
419
420 default :
421 $fields .= "<input type='text' {$input_atts} value='{$value}' name='{$input_name}'/>";
422 }
423
424 // Get the final HTML output
425 if(isset($args['container']) && $args['container'] == 'tools') {
426 $html = "<div{$container_class}>";
427 $html .= "<h4>{$label}</h4>";
428 $html .= "<div class='{$input_name}-container'>{$fields}</div>";
429 $html .= $description;
430 $html .= $append_content;
431 $html .= "</div>";
432 } else if(isset($args['container']) && $args['container'] == 'row') {
433 $html = "<tr data-field=\"{$input_name}\" {$container_class}><th><label for='{$input_name}'>{$args['label']}</label></th>";
434 $html .= "<td><fieldset>{$fields}{$description}</fieldset></td></tr>";
435 $html .= ($append_content) ? "<tr class=\"appended-row\"><td colspan=\"2\">{$append_content}</td></tr>" : "";
436 } else if(isset($args['container']) && $args['container'] == 'screen-options') {
437 $html = "<fieldset data-field=\"{$input_name}\" {$container_class}><legend>{$args['label']}</legend>";
438 $html .= "<div class=\"field-content\">{$fields}{$description}</div>";
439 $html .= ($append_content) ? "<div class=\"appended-row\">{$append_content}</div>" : "";
440 $html .= "</fieldset>";
441 } else {
442 $html = $fields . $append_content;
443 }
444
445 return apply_filters('permalink_manager_field_output', $html);
446 }
447
448 /**
449 * Display hidden field to indicate posts or taxonomies admin sections
450 */
451 static public function section_type_field($type = 'post') {
452 return self::generate_option_field('content_type', array('value' => $type, 'type' => 'hidden'));
453 }
454
455 /**
456 * Display the form
457 */
458 static public function get_the_form($fields = array(), $container = '', $button = array(), $sidebar = '', $nonce = array(), $wrap = false, $form_class = '') {
459 // 1. Check if the content will be displayed in columns and button details
460 switch($container) {
461 case 'columns-3' :
462 $wrapper_class = 'columns-container';
463 $form_column_class = 'column column-2_3';
464 $sidebar_class = 'column column-1_3';
465 break;
466
467 // there will be more cases in future ...
468 default :
469 $form_column_class = 'form';
470 $sidebar_class = 'sidebar';
471 $wrapper_class = $form_column_class = '';
472 }
473
474 // 2. Process the array with button and nonce field settings
475 $button_text = (!empty($button['text'])) ? $button['text'] : '';
476 $button_class = (!empty($button['class'])) ? $button['class'] : '';
477 $button_attributes = (!empty($button['attributes'])) ? $button['attributes'] : '';
478 $nonce_action = (!empty($nonce['action'])) ? $nonce['action'] : '';
479 $nonce_name = (!empty($nonce['name'])) ? $nonce['name'] : '';
480 $form_classes = (!empty($form_class)) ? $form_class : '';
481
482 // 2. Now get the HTML output (start section row container)
483 $html = ($wrapper_class) ? "<div class=\"{$wrapper_class}\">" : '';
484
485 // 3. Display some notes
486 if($sidebar_class && $sidebar) {
487 $html .= "<div class=\"{$sidebar_class}\">";
488 $html .= "<div class=\"section-notes\">";
489 $html .= $sidebar;
490 $html .= "</div>";
491 $html .= "</div>";
492 }
493
494 // 4. Start fields' section
495 $html .= ($form_column_class) ? "<div class=\"{$form_column_class}\">" : "";
496 $html .= "<form method=\"POST\" class=\"{$form_classes}\">";
497 $html .= ($wrap) ? "<table class=\"form-table\">" : "";
498
499 // Loop through all fields assigned to this section
500 foreach($fields as $field_name => $field) {
501 $field_name = (!empty($field['name'])) ? $field['name'] : $field_name;
502
503 // A. Display table row
504 if(isset($field['container']) && $field['container'] == 'row') {
505 $row_output = "";
506
507 // Loop through all fields assigned to this section
508 if(isset($field['fields'])) {
509 foreach($field['fields'] as $section_field_id => $section_field) {
510 $section_field_name = (!empty($section_field['name'])) ? $section_field['name'] : "{$field_name}[$section_field_id]";
511 $section_field['container'] = 'row';
512
513 $row_output .= self::generate_option_field($section_field_name, $section_field);
514 }
515 } else {
516 $row_output .= self::generate_option_field($field_name, $field);
517 }
518
519 if(isset($field['section_name'])) {
520 $html .= "<h3>{$field['section_name']}</h3>";
521 $html .= (isset($field['append_content'])) ? $field['append_content'] : "";
522 $html .= (isset($field['description'])) ? "<p class=\"description\">{$field['description']}</p>" : "";
523 $html .= "<table class=\"form-table\" data-field=\"{$field_name}\">{$row_output}</table>";
524 } else {
525 $html .= $row_output;
526 }
527 }
528 // B. Display single field
529 else {
530 $html .= self::generate_option_field($field_name, $field);
531 }
532 }
533
534 $html .= ($wrap) ? "</table>" : "";
535
536 // End the fields' section + add button & nonce fields
537 if($nonce_action && $nonce_name) {
538 $html .= wp_nonce_field($nonce_action, $nonce_name, true, true);
539 $html .= self::generate_option_field('pm_session_id', array('value' => uniqid(), 'type' => 'hidden'));
540 }
541 $html .= ($button_text) ? get_submit_button($button_text, $button_class, '', false, $button_attributes) : "";
542 $html .= '</form>';
543 $html .= ($form_column_class) ? "</div>" : "";
544
545 // 5. End the section row container
546 $html .= ($wrapper_class) ? "</div>" : "";
547
548 return $html;
549 }
550
551 /**
552 * Display the plugin sections.
553 */
554 public function display_section() {
555 global $wpdb, $permalink_manager_before_sections_html, $permalink_manager_after_sections_html;
556
557 $html = "<div id=\"permalink-manager\" class=\"wrap\">";
558
559 $donate_link = (Permalink_Manager_Admin_Functions::is_pro_active()) ? "" : sprintf("<a href=\"%s\" target=\"_blank\" class=\"page-title-action\">%s</a>", PERMALINK_MANAGER_DONATE, __("Donate", "permalink-manager"));
560 $html .= sprintf("<h2 id=\"plugin-name-heading\">%s <a href=\"http://maciejbis.net\" class=\"author-link\" target=\"_blank\">%s</a> %s</h2>", PERMALINK_MANAGER_PLUGIN_NAME, __("by Maciej Bis", "permalink-manager"), $donate_link);
561
562 // Display the tab navigation
563 $html .= "<div id=\"permalink-manager-tab-nav\" class=\"nav-tab-wrapper\">";
564 foreach($this->sections as $section_name => $section_properties) {
565 $active_class = ($this->active_section === $section_name) ? 'nav-tab-active nav-tab' : 'nav-tab';
566 $section_url = $this->get_admin_url("&section={$section_name}");
567
568 $html .= sprintf("<a href=\"%s\" class=\"%s section_%s\">%s</a>", $section_url, $active_class, $section_name, $section_properties['name']);
569 }
570
571 // Upgrade to Pro version
572 $html .= (Permalink_Manager_Admin_Functions::is_pro_active() == false) ? sprintf("<a href=\"%s\" target=\"_blank\" class=\"nav-tab section_upgrade\">%s</a>", 'https://permalinkmanager.pro/buy-permalink-manager-pro/?utm_source=plugin_upgrade', __('Upgrade to PRO', 'permalink-manager')) : '';
573 $html .= "</div>";
574
575 // Now display the active section
576 $html .= "<div id=\"permalink-manager-sections\">";
577 $active_section_array = (isset($this->sections[$this->active_section])) ? $this->sections[$this->active_section] : "";
578
579 // Display addidional navigation for subsections
580 if(isset($this->sections[$this->active_section]['subsections'])) {
581 $html .= "<ul class=\"subsubsub\">";
582 foreach ($this->sections[$this->active_section]['subsections'] as $subsection_name => $subsection) {
583 $active_class = ($this->active_subsection === $subsection_name) ? 'current' : '';
584 $subsection_url = $this->get_admin_url("&section={$this->active_section}&subsection={$subsection_name}");
585
586 $html .= "<li><a href=\"{$subsection_url}\" class=\"{$active_class}\">{$subsection['name']}</a></li>";
587 }
588 $html .= "</ul>";
589 }
590
591 // A. Execute the function assigned to the subsection
592 if(isset($active_section_array['subsections'][$this->active_subsection]['function'])) {
593 $class_name = $active_section_array['subsections'][$this->active_subsection]['function']['class'];
594 $section_object = new $class_name();
595
596 $section_content = call_user_func(array($section_object, $active_section_array['subsections'][$this->active_subsection]['function']['method']));
597 }
598 // B. Execute the function assigned to the section
599 else if(isset($active_section_array['function'])) {
600 $class_name = $active_section_array['function']['class'];
601 $section_object = new $class_name();
602
603 $section_content = call_user_func(array($section_object, $active_section_array['function']['method']));
604 }
605 // C. Display the raw HTMl output of subsection
606 else if(isset($active_section_array['subsections'][$this->active_subsection]['html'])) {
607 $section_content = (isset($active_section_array['subsections'][$this->active_subsection]['html'])) ? $active_section_array['subsections'][$this->active_subsection]['html'] : "";
608 }
609 // D. Try to display the raw HTMl output of section
610 else {
611 $section_content = (isset($active_section_array['html'])) ? $active_section_array['html'] : "";
612 }
613
614 $html .= "<div class=\"single-section\" data-section=\"{$this->active_section}\" id=\"{$this->active_section}\">{$section_content}</div>";
615 $html .= "</div>";
616
617 // Display alerts and another content if needed and close .wrap container
618 $html .= $permalink_manager_after_sections_html;
619 $html .= "</div>";
620
621 echo $html;
622 }
623
624 /**
625 * Display the table with updated slugs after one of the actions is triggered
626 */
627 static function display_updated_slugs($updated_array, $return_array = false, $display_full_table = true) {
628 global $permalink_manager_before_sections_html, $permalink_manager_after_sections_html;
629
630 $updated_slugs_count = 0;
631 $html = $main_content = $alert = "";
632
633 if(is_array($updated_array)) {
634 // Check if slugs should be displayed
635 $first_slug = reset($updated_array);
636 $show_slugs = (!empty($_POST['mode']) && $_POST['mode'] == 'slugs') ? true : false;
637
638 $header_footer = '<tr>';
639 $header_footer .= '<th class="column-primary">' . __('Title', 'permalink-manager') . '</th>';
640 if($show_slugs) {
641 $header_footer .= (isset($first_slug['old_slug'])) ? '<th>' . __('Old Slug', 'permalink-manager') . '</th>' : "";
642 $header_footer .= (isset($first_slug['new_slug'])) ? '<th>' . __('New Slug', 'permalink-manager') . '</th>' : "";
643 } else {
644 $header_footer .= '<th>' . __('Old URI', 'permalink-manager') . '</th>';
645 $header_footer .= '<th>' . __('New URI', 'permalink-manager') . '</th>';
646 }
647 $header_footer .= '</tr>';
648
649 foreach($updated_array as $row) {
650 // Odd/even class
651 $updated_slugs_count++;
652 $alternate_class = ($updated_slugs_count % 2 == 1) ? ' class="alternate"' : '';
653
654 // Taxonomy
655 if(!empty($row['tax'])) {
656 $term_link = get_term_link(intval($row['ID']), $row['tax']);
657 $permalink = (is_wp_error($term_link)) ? "-" : $term_link;
658 } else {
659 $permalink = get_permalink($row['ID']);
660 }
661
662 // Decode permalink
663 $permalink = rawurldecode(rawurldecode($permalink));
664
665 $main_content .= "<tr{$alternate_class}>";
666 $main_content .= '<td class="row-title column-primary" data-colname="' . __('Title', 'permalink-manager') . '">' . $row['item_title'] . "<a target=\"_blank\" href=\"{$permalink}\"><span class=\"small\">{$permalink}</span></a>" . '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'permalink-manager') . '</span></button></td>';
667 if($show_slugs) {
668 $main_content .= (isset($row['old_slug'])) ? '<td data-colname="' . __('Old Slug', 'permalink-manager') . '">' . rawurldecode($row['old_slug']) . '</td>' : "";
669 $main_content .= (isset($row['new_slug'])) ? '<td data-colname="' . __('New Slug', 'permalink-manager') . '">' . rawurldecode($row['new_slug']) . '</td>' : "";
670 } else {
671 $main_content .= '<td data-colname="' . __('Old URI', 'permalink-manager') . '">' . rawurldecode($row['old_uri']) . '</td>';
672 $main_content .= '<td data-colname="' . __('New URI', 'permalink-manager') . '">' . rawurldecode($row['new_uri']) . '</td>';
673 }
674 $main_content .= '</tr>';
675 }
676
677 // Merge header, footer and content
678 if($display_full_table) {
679 $html = '<h3 id="updated-list">' . __('List of updated items', 'permalink-manager') . '</h3>';
680 $html .= '<table class="widefat wp-list-table updated-slugs-table">';
681 $html .= "<thead>{$header_footer}</thead><tbody>{$main_content}</tbody><tfoot>{$header_footer}</tfoot>";
682 } else {
683 $html = $main_content;
684 }
685
686 $html .= '</table>';
687 }
688
689 // 3. Display the alert
690 if(isset($updated_slugs_count)) {
691 if($updated_slugs_count > 0) {
692 $alert_content = sprintf( _n( '<strong class="updated_count">%d</strong> slug was updated!', '<strong class="updated_count">%d</strong> slugs were updated!', $updated_slugs_count, 'permalink-manager' ), $updated_slugs_count ) . ' ';
693 $alert_content .= sprintf( __( '<a %s>Click here</a> to go to the list of updated slugs', 'permalink-manager' ), "href=\"#updated-list\"");
694
695 $alert = Permalink_Manager_Admin_Functions::get_alert_message($alert_content, 'updated updated_slugs');
696 } else {
697 $alert = Permalink_Manager_Admin_Functions::get_alert_message(__( '<strong>No slugs</strong> were updated!', 'permalink-manager' ), 'error updated_slugs');
698 }
699 }
700
701 if($return_array) {
702 return array(
703 'html' => $html,
704 'alert' => $alert
705 );
706 } else {
707 $permalink_manager_before_sections_html .= $alert;
708
709 return $html;
710 }
711 }
712
713 /**
714 * "Quick Edit" Box
715 */
716 public static function quick_edit_column_form($is_taxonomy = false) {
717 $html = self::generate_option_field('permalink-manager-quick-edit', array('value' => true, 'type' => 'hidden'));
718 $html .= "<fieldset class=\"inline-edit-permalink\">";
719 $html .= sprintf("<legend class=\"inline-edit-legend\">%s</legend>", __("Permalink Manager", "permalink-manager"));
720
721 $html .= "<div class=\"inline-edit-col\">";
722 $html .= sprintf("<label class=\"inline-edit-group\"><span class=\"title\">%s</span><span class=\"input-text-wrap\">%s</span></label>",
723 __("Current URI", "permalink-manager"),
724 self::generate_option_field("custom_uri", array("input_class" => "custom_uri", "value" => ''))
725 );
726 $html .= "</div>";
727
728 $html .= "</fieldset>";
729
730 // Append nonce field & element ID
731 $html .= Permalink_Manager_Admin_Functions::generate_option_field("permalink-manager-edit-uri-element-id", array("type" => "hidden", "input_class" => "permalink-manager-edit-uri-element-id", "value" => ""));
732 $html .= wp_nonce_field( 'permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false );
733
734 return $html;
735 }
736
737 /**
738 * Hide "Custom URI" column
739 */
740 function quick_edit_hide_column($hidden, $screen) {
741 $hidden[] = 'permalink-manager-col';
742 return $hidden;
743 }
744
745 /**
746 * Display "Permalink Manager" box
747 */
748 public static function display_uri_box($element, $gutenberg = false) {
749 global $permalink_manager_options, $permalink_manager_uris;
750
751 // Check the user capabilities
752 $edit_uris_cap = (!empty($permalink_manager_options['general']['edit_uris_cap'])) ? $permalink_manager_options['general']['edit_uris_cap'] : 'publish_posts';
753 if(!current_user_can($edit_uris_cap)) {
754 return;
755 }
756
757 if(!empty($element->ID)) {
758 $id = $element_id = $element->ID;
759 $native_slug = $element->post_name;
760 $is_draft = (!empty($element->post_status) && (in_array($element->post_status, array('draft', 'auto-draft')))) ? true : false;
761 $is_front_page = Permalink_Manager_Helper_Functions::is_front_page($id);
762
763 // Auto-update settings
764 $auto_update_val = get_post_meta($id, "auto_update_uri", true);
765 $auto_update_def_val = $permalink_manager_options["general"]["auto_update_uris"];
766 $auto_update_def_label = ($auto_update_def_val) ? __("Yes", "permalink-manager") : __("No", "permalink-manager");
767 $auto_update_choices = array(
768 0 => array("label" => sprintf(__("Use global settings [%s]", "permalink-manager"), $auto_update_def_label), "atts" => "data-auto-update=\"{$auto_update_def_val}\""),
769 1 => array("label" => __("Yes", "permalink-manager"), "atts" => "data-auto-update=\"1\""),
770 -1 => array("label" => __("No", "permalink-manager"), "atts" => "data-auto-update=\"0\""),
771 -2 => array("label" => __("No (ignore this URI in bulk tools)", "permalink-manager"), "atts" => "data-auto-update=\"2\"")
772 );
773
774 // Get URIs
775 $uri = Permalink_Manager_URI_Functions_Post::get_post_uri($id, true, $is_draft);
776 $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($id);
777 $native_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($id, true);
778 } else if(class_exists('Permalink_Manager_URI_Functions_Tax')) {
779 $id = $element->term_id;
780 $element_id = "tax-{$id}";
781 $native_slug = $element->slug;
782
783 // Get URIs
784 $uri = Permalink_Manager_URI_Functions_Tax::get_term_uri($element->term_id, true);
785 $default_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri($element->term_id);
786 $native_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri($element->term_id, true);
787 } else {
788 return;
789 }
790
791 // Decode default URI
792 $default_uri = rawurldecode($default_uri);
793
794 // Start HTML output
795 // 1. Button
796 if(!$gutenberg) {
797 $html = sprintf("<span><button type=\"button\" class=\"button button-small hide-if-no-js\" id=\"permalink-manager-toggle\">%s</button></span>", __("Permalink Manager", "permalink-manager"));
798
799 $html .= "<div id=\"permalink-manager\" class=\"postbox permalink-manager-edit-uri-box\" style=\"display: none;\">";
800
801 // 2. The heading
802 $html .= "<a class=\"close-button\"><span class=\"screen-reader-text\">" . __("Close: ", "permalink-manager") . __("Permalink Manager", "permalink-manager") . "</span><span class=\"close-icon\" aria-hidden=\"false\"></span></a>";
803 $html .= sprintf("<h2><span>%s</span></h2>", __("Permalink Manager", "permalink-manager"));
804
805 // 3. The fields container [start]
806 $html .= "<div class=\"inside\">";
807 } else {
808 $html = "<div class=\"permalink-manager-gutenberg permalink-manager-edit-uri-box\">";
809 }
810
811 // 4. Custom URI
812 if(!empty($is_front_page)) {
813 $custom_uri_field = Permalink_Manager_Admin_Functions::generate_option_field("custom_uri", array("type" => "hidden", "extra_atts" => "data-default=\"{$default_uri}\" data-element-id=\"{$element_id}\"", "input_class" => "widefat custom_uri", "value" => rawurldecode($uri)));
814 $custom_uri_field .= __("The custom URI cannot be edited on frontpage.", "permalink-manager");
815 } else {
816 $custom_uri_field = Permalink_Manager_Admin_Functions::generate_option_field("custom_uri", array("extra_atts" => "data-default=\"{$default_uri}\" data-element-id=\"{$element_id}\"", "input_class" => "widefat custom_uri", "value" => rawurldecode($uri)));
817 }
818
819 $html .= sprintf("<div class=\"custom_uri_container\"><p><label for=\"custom_uri\" class=\"strong\">%s %s</label></p><span>%s</span><span class=\"duplicated_uri_alert\"></span></div>",
820 __("Current URI", "permalink-manager"),
821 ($element->ID) ? Permalink_Manager_Admin_Functions::help_tooltip(__("If custom URI is not defined, a default URI will be set (see below). The custom URI can be edited only if 'Auto-update the URI' feature is not enabled.", "permalink-manager")) : "",
822 $custom_uri_field
823 );
824
825 // 5. Native slug
826 if(!empty($element->ID) && !empty($permalink_manager_options["general"]["show_native_slug_field"])) {
827 $native_slug_field = Permalink_Manager_Admin_Functions::generate_option_field("native_slug", array("extra_atts" => "data-default=\"{$native_slug}\" data-element-id=\"{$element_id}\"", "input_class" => "widefat native_slug", "value" => rawurldecode($native_slug)));
828
829 $html .= sprintf("<div class=\"native_slug_container\"><p><label for=\"native_slug\" class=\"strong\">%s %s</label></p><span>%s</span></div>",
830 __("Native slug", "permalink-manager"),
831 Permalink_Manager_Admin_Functions::help_tooltip(__("The native slug is by default automatically used in native permalinks (when Permalink Manager is disabled).", "permalink-manager")),
832 $native_slug_field
833 );
834 }
835
836 // Three fields that should be hidden on front-page
837 if(empty($is_front_page)) {
838 // 6. Auto-update URI
839 if(!empty($auto_update_choices)) {
840 $html .= sprintf("<div><p><label for=\"auto_auri\" class=\"strong\">%s %s</label></p><span>%s</span></div>",
841 __("Auto-update the URI", "permalink-manager"),
842 Permalink_Manager_Admin_Functions::help_tooltip(__("If enabled, the 'Current URI' field will be automatically changed to 'Default URI' (displayed below) after the post is saved or updated.", "permalink-manager")),
843 Permalink_Manager_Admin_Functions::generate_option_field("auto_update_uri", array("type" => "select", "input_class" => "widefat auto_update", "value" => $auto_update_val, "choices" => $auto_update_choices))
844 );
845 }
846
847 // 7. Default URI
848 $html .= sprintf(
849 "<div class=\"default-permalink-row columns-container\"><span class=\"column-3_4\"><strong>%s:</strong> %s</span><span class=\"column-1_4\"><a href=\"#\" class=\"restore-default\"><span class=\"dashicons dashicons-image-rotate\"></span> %s</a></span></div>",
850 __("Default URI", "permalink-manager"), esc_html($default_uri),
851 __("Restore Default URI", "permalink-manager")
852 );
853
854 // 8. Native URI info
855 if(!empty($permalink_manager_options['general']['redirect']) && ((!empty($element->post_status) && in_array($element->post_status, array('auto-draft', 'trash', 'draft'))) == false)) {
856 $native_permalink = trim(Permalink_Manager_Helper_Functions::get_permalink_base($element), "/") . "/";
857 $native_permalink .= $native_uri;
858
859 $html .= sprintf(
860 "<div class=\"default-permalink-row columns-container\"><span><strong>%s</strong> <a href=\"%s\">%s</a></span></div>",
861 __("Automatic redirect for native URI enabled:", "permalink-manager"),
862 $native_permalink,
863 rawurldecode($native_uri)
864 );
865 }
866 }
867
868 // 10. Extra discount
869 if(Permalink_Manager_Admin_Functions::is_pro_active() == false) {
870 $html .= sprintf(
871 "<div class=\"default-permalink-row save-row columns-container hidden\"><div>%s</div></div>",
872 __('<span><strong>Need more functionalities and dedicated support?</strong> Buy Permalink Manager Pro and apply <a href="https://permalinkmanager.pro/buy-permalink-manager-pro/">PMLITE coupon code</a> to get 10% off.</a></span>', 'permalink-manager')
873 );
874 }
875
876 // 10. Custom redirects
877 $html .= ($element->ID) ? self::display_redirect_panel($id) : self::display_redirect_panel("tax-{$id}");
878
879 // 11. Extra save button for Gutenberg
880 if($gutenberg) {
881 $html .= sprintf(
882 "<div class=\"default-permalink-row save-row columns-container hidden\"><div><a href=\"#\" class=\"button button-primary\" id=\"permalink-manager-save-button\">%s</a></div></div>",
883 __("Save permalink", "permalink-manager")
884 );
885 }
886
887
888 $html .= "</div>";
889 $html .= "</div>";
890
891 // 11. Append nonce field, element ID & native slug
892 $html .= Permalink_Manager_Admin_Functions::generate_option_field("permalink-manager-edit-uri-element-slug", array("type" => "hidden", "value" => $native_slug));
893 $html .= Permalink_Manager_Admin_Functions::generate_option_field("permalink-manager-edit-uri-element-id", array("type" => "hidden", "value" => $element_id));
894 $html .= wp_nonce_field('permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false);
895
896 return $html;
897 }
898
899 /**
900 * Display the redirect panel
901 */
902 public static function display_redirect_panel($element_id) {
903 global $permalink_manager_options, $permalink_manager_redirects;
904
905 // Heading
906 $html = "<div class=\"permalink-manager redirects-row redirects-panel columns-container\">";
907
908 $html .= sprintf(
909 "<div><a class=\"button\" href=\"#\" id=\"toggle-redirect-panel\">%s</a></span></div>",
910 __("Manage redirects", "permalink-manager")
911 );
912
913 $html .= "<div id=\"redirect-panel-inside\">";
914 if(Permalink_Manager_Admin_Functions::is_pro_active() && class_exists('Permalink_Manager_Pro_Addons')) {
915 $html .= Permalink_Manager_Pro_Addons::display_redirect_form($element_id);
916 } else {
917 $html .= self::pro_text(true);
918 }
919 $html .= "</div>";
920
921 $html .= "</div>";
922
923 return $html;
924 }
925
926 /**
927 * Display error/info message
928 */
929 public static function get_alert_message($alert_content = "", $alert_type = "", $dismissable = true, $id = false) {
930 // Ignore empty messages (just in case)
931 if(empty($alert_content) || empty($alert_type)) {
932 return "";
933 }
934
935 $class = ($dismissable) ? "is-dismissible" : "";
936 $alert_id = ($id) ? " data-alert_id=\"{$id}\"" : "";
937
938 $html = sprintf( "<div class=\"{$alert_type} permalink-manager-notice notice {$class}\"{$alert_id}> %s</div>", wpautop($alert_content) );
939
940 return $html;
941 }
942
943 /**
944 * Help tooltip
945 */
946 static function help_tooltip($text = '') {
947 $html = " <a href=\"#\" title=\"{$text}\" class=\"help_tooltip\"><span class=\"dashicons dashicons-editor-help\"></span></a>";
948 return $html;
949 }
950
951 /**
952 * Display global notices (throughout wp-admin dashboard)
953 */
954 function display_global_notices() {
955 global $permalink_manager_alerts, $active_section;
956
957 $html = "";
958 if(!empty($permalink_manager_alerts) && is_array($permalink_manager_alerts)) {
959 foreach($permalink_manager_alerts as $alert_id => $alert) {
960 if(!empty($alert['show'])) {
961 // Hide notice in Permalink Manager Pro
962 if(defined('PERMALINK_MANAGER_PRO') && $alert['show'] == 'pro_hide') { continue; }
963
964 // Display the notice only on the plugin pages
965 if(empty($active_section) && !empty($alert['plugin_only'])) { continue; }
966
967 // Check if the notice did not expire
968 if(isset($alert['until']) && (time() > strtotime($alert['until']))) { continue; }
969
970 $html .= self::get_alert_message($alert['txt'], $alert['type'], true, $alert_id);
971 }
972 }
973 }
974
975 echo $html;
976 }
977
978 /**
979 * Hide global notices (AJAX)
980 */
981 function hide_global_notice() {
982 global $permalink_manager_alerts;
983
984 // Get the ID of the alert
985 $alert_id = (!empty($_REQUEST['alert_id'])) ? sanitize_title($_REQUEST['alert_id']) : "";
986 if(!empty($permalink_manager_alerts[$alert_id])) {
987 $permalink_manager_alerts[$alert_id]['show'] = 0;
988 }
989
990 update_option( 'permalink-manager-alerts', $permalink_manager_alerts);
991 }
992
993 /**
994 * Display notices generated by Permalink Manager tools
995 */
996 function display_plugin_notices() {
997 global $permalink_manager_before_sections_html;
998
999 echo $permalink_manager_before_sections_html;
1000 }
1001
1002 /**
1003 * Check if URI was used before
1004 */
1005 function ajax_detect_duplicates($uri = null, $element_id = null) {
1006 $duplicate_alert = __("URI is already in use, please select another one!", "permalink-manager");
1007
1008 if(!empty($_REQUEST['custom_uris'])) {
1009 // Sanitize the array
1010 $custom_uris = Permalink_Manager_Helper_Functions::sanitize_array($_REQUEST['custom_uris']);
1011 $duplicates_array = array();
1012
1013 // Check each URI
1014 foreach($custom_uris as $element_id => $uri) {
1015 $duplicates_array[$element_id] = Permalink_Manager_Helper_Functions::is_uri_duplicated($uri, $element_id) ? $duplicate_alert : 0;
1016 }
1017
1018 // Convert the output to JSON and stop the function
1019 echo json_encode($duplicates_array);
1020 } else if(!empty($_REQUEST['custom_uri']) && !empty($_REQUEST['element_id'])) {
1021 $is_duplicated = Permalink_Manager_Helper_Functions::is_uri_duplicated($uri, $element_id);
1022
1023 echo ($is_duplicated) ? $duplicate_alert : 0;;
1024 }
1025
1026 die();
1027 }
1028
1029 /**
1030 * Check if Permalink Manager Pro is active
1031 */
1032 public static function is_pro_active($return_text = false) {
1033 if(defined('PERMALINK_MANAGER_PRO') && PERMALINK_MANAGER_PRO == true) {
1034 $is_pro = true;
1035 } else {
1036 $is_pro = false;
1037 }
1038
1039 // Check if license is active
1040 if(class_exists('Permalink_Manager_Pro_Functions')) {
1041 $exp_date = Permalink_Manager_Pro_Functions::get_expiration_date(true);
1042
1043 $is_pro = ($exp_date > 0) ? false : true;
1044 } else {
1045 $is_pro = false;
1046 }
1047
1048 return $is_pro;
1049 }
1050
1051 static function pro_text($text_only = false) {
1052 if(class_exists('Permalink_Manager_Pro_Functions')) {
1053 $text = Permalink_Manager_Pro_Functions::get_expiration_date(false, true);
1054 } else {
1055 $text = sprintf(__('This functionality is available only in <a href="%s" target="_blank">Permalink Manager Pro</a>.', 'permalink-manager'), PERMALINK_MANAGER_WEBSITE);
1056 }
1057
1058 return ($text_only) ? $text : sprintf("<div class=\"alert info\"> %s</div>", wpautop($text, 'alert', false));
1059 }
1060
1061 }
1062