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