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