PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.2.12
Permalink Manager Lite v2.2.12
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
1086 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 = $_POST['section'];
75 } else if(isset($_GET['section'])) {
76 $this->active_section = $_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 = $_POST['subsection'];
87 } else if(isset($_GET['subsection'])) {
88 $this->active_subsection = $_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
613 $donate_link = (self::is_pro_active()) ? "" : sprintf("<a href=\"%s\" target=\"_blank\" class=\"page-title-action\">%s</a>", PERMALINK_MANAGER_DONATE, __("Donate", "permalink-manager"));
614 $html .= sprintf("<h2 id=\"plugin-name-heading\">%s <a href=\"http://maciejbis.net\" class=\"author-link\" target=\"_blank\">%s</a> %s</h2>", PERMALINK_MANAGER_PLUGIN_NAME, __("by Maciej Bis", "permalink-manager"), $donate_link);
615
616 // Display the tab navigation
617 $html .= "<div id=\"permalink-manager-tab-nav\" class=\"nav-tab-wrapper\">";
618 foreach($this->sections as $section_name => $section_properties) {
619 $active_class = ($this->active_section === $section_name) ? 'nav-tab-active nav-tab' : 'nav-tab';
620 $section_url = $this->get_admin_url("&section={$section_name}");
621
622 $html .= sprintf("<a href=\"%s\" class=\"%s section_%s\">%s</a>", $section_url, $active_class, $section_name, $section_properties['name']);
623 }
624
625 // Upgrade to Pro version
626 $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')) : '';
627 $html .= "</div>";
628
629 // Now display the active section
630 $html .= "<div id=\"permalink-manager-sections\">";
631 $active_section_array = (isset($this->sections[$this->active_section])) ? $this->sections[$this->active_section] : "";
632
633 // Display addidional navigation for subsections
634 if(isset($this->sections[$this->active_section]['subsections'])) {
635 $html .= "<ul class=\"subsubsub\">";
636 foreach ($this->sections[$this->active_section]['subsections'] as $subsection_name => $subsection) {
637 $active_class = ($this->active_subsection === $subsection_name) ? 'current' : '';
638 $subsection_url = $this->get_admin_url("&section={$this->active_section}&subsection={$subsection_name}");
639
640 $html .= "<li><a href=\"{$subsection_url}\" class=\"{$active_class}\">{$subsection['name']}</a></li>";
641 }
642 $html .= "</ul>";
643 }
644
645 // A. Execute the function assigned to the subsection
646 if(isset($active_section_array['subsections'][$this->active_subsection]['function'])) {
647 $class_name = $active_section_array['subsections'][$this->active_subsection]['function']['class'];
648 $section_object = new $class_name();
649
650 $section_content = call_user_func(array($section_object, $active_section_array['subsections'][$this->active_subsection]['function']['method']));
651 }
652 // B. Execute the function assigned to the section
653 else if(isset($active_section_array['function'])) {
654 $class_name = $active_section_array['function']['class'];
655 $section_object = new $class_name();
656
657 $section_content = call_user_func(array($section_object, $active_section_array['function']['method']));
658 }
659 // C. Display the raw HTMl output of subsection
660 else if(isset($active_section_array['subsections'][$this->active_subsection]['html'])) {
661 $section_content = (isset($active_section_array['subsections'][$this->active_subsection]['html'])) ? $active_section_array['subsections'][$this->active_subsection]['html'] : "";
662 }
663 // D. Try to display the raw HTMl output of section
664 else {
665 $section_content = (isset($active_section_array['html'])) ? $active_section_array['html'] : "";
666 }
667
668 $html .= "<div class=\"single-section\" data-section=\"{$this->active_section}\" id=\"{$this->active_section}\">{$section_content}</div>";
669 $html .= "</div>";
670
671 // Display alerts and another content if needed and close .wrap container
672 $html .= $permalink_manager_after_sections_html;
673 $html .= "</div>";
674
675 echo $html;
676 }
677
678 /**
679 * Display the table with updated slugs after one of the actions is triggered
680 */
681 static function display_updated_slugs($updated_array, $return_array = false, $display_full_table = true) {
682 global $permalink_manager_before_sections_html, $permalink_manager_after_sections_html;
683
684 $updated_slugs_count = 0;
685 $html = $main_content = $alert = "";
686
687 if(is_array($updated_array)) {
688 // Check if slugs should be displayed
689 $first_slug = reset($updated_array);
690 $show_slugs = (!empty($_POST['mode']) && $_POST['mode'] == 'slugs') ? true : false;
691
692 $header_footer = '<tr>';
693 $header_footer .= '<th class="column-primary">' . __('Title', 'permalink-manager') . '</th>';
694 if($show_slugs) {
695 $header_footer .= (isset($first_slug['old_slug'])) ? '<th>' . __('Old Slug', 'permalink-manager') . '</th>' : "";
696 $header_footer .= (isset($first_slug['new_slug'])) ? '<th>' . __('New Slug', 'permalink-manager') . '</th>' : "";
697 } else {
698 $header_footer .= '<th>' . __('Old URI', 'permalink-manager') . '</th>';
699 $header_footer .= '<th>' . __('New URI', 'permalink-manager') . '</th>';
700 }
701 $header_footer .= '</tr>';
702
703 foreach($updated_array as $row) {
704 // Odd/even class
705 $updated_slugs_count++;
706 $alternate_class = ($updated_slugs_count % 2 == 1) ? ' class="alternate"' : '';
707
708 // Taxonomy
709 if(!empty($row['tax'])) {
710 $term_link = get_term_link(intval($row['ID']), $row['tax']);
711 $permalink = (is_wp_error($term_link)) ? "-" : $term_link;
712 } else {
713 $permalink = get_permalink($row['ID']);
714 }
715
716 // Decode permalink
717 $permalink = rawurldecode(rawurldecode($permalink));
718
719 $main_content .= "<tr{$alternate_class}>";
720 $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>';
721 if($show_slugs) {
722 $main_content .= (isset($row['old_slug'])) ? '<td data-colname="' . __('Old Slug', 'permalink-manager') . '">' . rawurldecode($row['old_slug']) . '</td>' : "";
723 $main_content .= (isset($row['new_slug'])) ? '<td data-colname="' . __('New Slug', 'permalink-manager') . '">' . rawurldecode($row['new_slug']) . '</td>' : "";
724 } else {
725 $main_content .= '<td data-colname="' . __('Old URI', 'permalink-manager') . '">' . rawurldecode($row['old_uri']) . '</td>';
726 $main_content .= '<td data-colname="' . __('New URI', 'permalink-manager') . '">' . rawurldecode($row['new_uri']) . '</td>';
727 }
728 $main_content .= '</tr>';
729 }
730
731 // Merge header, footer and content
732 if($display_full_table) {
733 $html = '<h3 id="updated-list">' . __('List of updated items', 'permalink-manager') . '</h3>';
734 $html .= '<table class="widefat wp-list-table updated-slugs-table">';
735 $html .= "<thead>{$header_footer}</thead><tbody>{$main_content}</tbody><tfoot>{$header_footer}</tfoot>";
736 } else {
737 $html = $main_content;
738 }
739
740 $html .= '</table>';
741 }
742
743 // 3. Display the alert
744 if(isset($updated_slugs_count)) {
745 if($updated_slugs_count > 0) {
746 $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 ) . ' ';
747 $alert_content .= sprintf( __( '<a %s>Click here</a> to go to the list of updated slugs', 'permalink-manager' ), "href=\"#updated-list\"");
748
749 $alert = self::get_alert_message($alert_content, 'updated updated_slugs');
750 } else {
751 $alert = self::get_alert_message(__( '<strong>No slugs</strong> were updated!', 'permalink-manager' ), 'error updated_slugs');
752 }
753 }
754
755 if($return_array) {
756 return array(
757 'html' => $html,
758 'alert' => $alert
759 );
760 } else {
761 $permalink_manager_before_sections_html .= $alert;
762
763 return $html;
764 }
765 }
766
767 /**
768 * "Quick Edit" Box
769 */
770 public static function quick_edit_column_form($is_taxonomy = false) {
771 $html = self::generate_option_field('permalink-manager-quick-edit', array('value' => true, 'type' => 'hidden'));
772 $html .= "<fieldset class=\"inline-edit-permalink\">";
773 $html .= sprintf("<legend class=\"inline-edit-legend\">%s</legend>", __("Permalink Manager", "permalink-manager"));
774
775 $html .= "<div class=\"inline-edit-col\">";
776 $html .= sprintf("<label class=\"inline-edit-group\"><span class=\"title\">%s</span><span class=\"input-text-wrap\">%s</span></label>",
777 __("Current URI", "permalink-manager"),
778 self::generate_option_field("custom_uri", array("input_class" => "custom_uri", "value" => ''))
779 );
780 $html .= "</div>";
781
782 $html .= "</fieldset>";
783
784 // Append nonce field & element ID
785 $html .= self::generate_option_field("permalink-manager-edit-uri-element-id", array("type" => "hidden", "input_class" => "permalink-manager-edit-uri-element-id", "value" => ""));
786 $html .= wp_nonce_field( 'permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false );
787
788 return $html;
789 }
790
791 /**
792 * Hide "Custom URI" column
793 */
794 function quick_edit_hide_column($hidden, $screen) {
795 $hidden[] = 'permalink-manager-col';
796 return $hidden;
797 }
798
799 /**
800 * Display "Permalink Manager" box
801 */
802 public static function display_uri_box($element, $gutenberg = false) {
803 global $permalink_manager_options, $permalink_manager_uris;
804
805 // Check the user capabilities
806 $edit_uris_cap = (!empty($permalink_manager_options['general']['edit_uris_cap'])) ? $permalink_manager_options['general']['edit_uris_cap'] : 'publish_posts';
807 if(!current_user_can($edit_uris_cap)) {
808 return;
809 }
810
811 if(!empty($element->ID)) {
812 $id = $element_id = $element->ID;
813 $native_slug = $element->post_name;
814 $is_draft = (!empty($element->post_status) && (in_array($element->post_status, array('draft', 'auto-draft')))) ? true : false;
815 $is_front_page = Permalink_Manager_Helper_Functions::is_front_page($id);
816
817 $auto_update_val = get_post_meta($id, "auto_update_uri", true);
818
819 // Get URIs
820 $uri = Permalink_Manager_URI_Functions_Post::get_post_uri($id, true, $is_draft);
821 $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($id);
822 $native_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($id, true);
823 } else if(class_exists('Permalink_Manager_URI_Functions_Tax')) {
824 $id = $element->term_id;
825 $element_id = "tax-{$id}";
826 $native_slug = $element->slug;
827
828 $auto_update_val = get_term_meta($id, "auto_update_uri", true);
829
830 // Get URIs
831 $uri = Permalink_Manager_URI_Functions_Tax::get_term_uri($element->term_id, true);
832 $default_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri($element->term_id);
833 $native_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri($element->term_id, true);
834 } else {
835 return;
836 }
837
838 // Auto-update settings
839 $auto_update_def_val = $permalink_manager_options["general"]["auto_update_uris"];
840 $auto_update_def_label = ($auto_update_def_val) ? __("Yes", "permalink-manager") : __("No", "permalink-manager");
841 $auto_update_choices = array(
842 0 => array("label" => sprintf(__("Use global settings [%s]", "permalink-manager"), $auto_update_def_label), "atts" => "data-auto-update=\"{$auto_update_def_val}\""),
843 1 => array("label" => __("Yes", "permalink-manager"), "atts" => "data-auto-update=\"1\""),
844 -1 => array("label" => __("No", "permalink-manager"), "atts" => "data-auto-update=\"0\""),
845 -2 => array("label" => __("No (ignore this URI in bulk tools)", "permalink-manager"), "atts" => "data-auto-update=\"2\"")
846 );
847
848 // Decode default URI
849 $default_uri = rawurldecode($default_uri);
850
851 // Start HTML output
852 // 1. Button
853 if(!$gutenberg) {
854 $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"));
855
856 $html .= "<div id=\"permalink-manager\" class=\"postbox permalink-manager-edit-uri-box\" style=\"display: none;\">";
857
858 // 2. The heading
859 $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>";
860 $html .= sprintf("<h2><span>%s</span></h2>", __("Permalink Manager", "permalink-manager"));
861
862 // 3. The fields container [start]
863 $html .= "<div class=\"inside\">";
864 } else {
865 $html = "<div class=\"permalink-manager-gutenberg permalink-manager-edit-uri-box\">";
866 }
867
868 // 4. Custom URI
869 if(!empty($is_front_page)) {
870 $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)));
871 $custom_uri_field .= __("The custom URI cannot be edited on frontpage.", "permalink-manager");
872 } else {
873 $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)));
874 $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'));
875 }
876
877 $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>",
878 __("Current URI", "permalink-manager"),
879 ($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")) : "",
880 $custom_uri_field
881 );
882
883 // 5. Auto-update URI
884 if(empty($is_front_page)) {
885 if(!empty($auto_update_choices)) {
886 $html .= sprintf("<div><p><label for=\"auto_auri\" class=\"strong\">%s %s</label></p><span>%s</span></div>",
887 __("Auto-update \"Current URI\"", "permalink-manager"),
888 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")),
889 self::generate_option_field("auto_update_uri", array("type" => "select", "input_class" => "widefat auto_update", "value" => $auto_update_val, "choices" => $auto_update_choices))
890 );
891 }
892 }
893
894 // 6. Native slug
895 if(!empty($element->ID) && !empty($permalink_manager_options["general"]["show_native_slug_field"])) {
896 $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)));
897
898 $html .= sprintf("<div class=\"native_slug_container\"><p><label for=\"native_slug\" class=\"strong\">%s %s</label></p><span>%s</span></div>",
899 __("Native slug", "permalink-manager"),
900 self::help_tooltip(__("The native slug is by default automatically used in native permalinks (when Permalink Manager is disabled).", "permalink-manager")),
901 $native_slug_field
902 );
903 }
904
905 if(empty($is_front_page)) {
906 // 7. Default URI
907 $html .= sprintf(
908 "<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>",
909 __("Default URI", "permalink-manager"), esc_html($default_uri),
910 __("Restore Default URI", "permalink-manager")
911 );
912
913 // 8. Native URI info
914 if(!empty($permalink_manager_options['general']['redirect']) && ((!empty($element->post_status) && in_array($element->post_status, array('auto-draft', 'trash', 'draft'))) == false)) {
915 $native_permalink = trim(Permalink_Manager_Helper_Functions::get_permalink_base($element), "/") . "/";
916 $native_permalink .= $native_uri;
917
918 $html .= sprintf(
919 "<div class=\"default-permalink-row columns-container\"><span><strong>%s</strong> <a href=\"%s\">%s</a></span></div>",
920 __("Automatic redirect for native URI enabled:", "permalink-manager"),
921 $native_permalink,
922 rawurldecode($native_uri)
923 );
924 }
925 }
926
927 // 9. Custom redirects
928 $html .= ($element->ID) ? self::display_redirect_panel($id) : self::display_redirect_panel("tax-{$id}");
929
930 // 10. Extra save button for Gutenberg
931 if($gutenberg) {
932 $html .= sprintf(
933 "<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>",
934 __("Save permalink", "permalink-manager")
935 );
936 } else {
937 $html .= "</div>";
938 }
939
940 $html .= "</div>";
941
942 // 11. Append nonce field, element ID & native slug
943 $html .= self::generate_option_field("permalink-manager-edit-uri-element-slug", array("type" => "hidden", "value" => $native_slug));
944 $html .= self::generate_option_field("permalink-manager-edit-uri-element-id", array("type" => "hidden", "value" => $element_id));
945 $html .= wp_nonce_field('permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false);
946
947 return $html;
948 }
949
950 /**
951 * Display the redirect panel
952 */
953 public static function display_redirect_panel($element_id) {
954 global $permalink_manager_options, $permalink_manager_redirects;
955
956 // Heading
957 $html = "<div class=\"permalink-manager redirects-row redirects-panel columns-container\">";
958
959 $html .= sprintf(
960 "<div><a class=\"button\" href=\"#\" id=\"toggle-redirect-panel\">%s</a></div>",
961 __("Manage redirects", "permalink-manager")
962 );
963
964 $html .= "<div id=\"redirect-panel-inside\">";
965 if(class_exists('Permalink_Manager_Pro_Addons')) {
966 $html .= Permalink_Manager_Pro_Addons::display_redirect_form($element_id);
967 } else {
968 $html .= self::pro_text(true);
969 }
970 $html .= "</div>";
971
972 $html .= "</div>";
973
974 return $html;
975 }
976
977 /**
978 * Display error/info message
979 */
980 public static function get_alert_message($alert_content = "", $alert_type = "", $dismissable = true, $id = false) {
981 // Ignore empty messages (just in case)
982 if(empty($alert_content) || empty($alert_type)) {
983 return "";
984 }
985
986 $class = ($dismissable) ? "is-dismissible" : "";
987 $alert_id = ($id) ? " data-alert_id=\"{$id}\"" : "";
988
989 $html = sprintf( "<div class=\"{$alert_type} permalink-manager-notice notice {$class}\"{$alert_id}> %s</div>", wpautop($alert_content) );
990
991 return $html;
992 }
993
994 /**
995 * Help tooltip
996 */
997 static function help_tooltip($text = '') {
998 $html = " <a href=\"#\" title=\"{$text}\" class=\"help_tooltip\"><span class=\"dashicons dashicons-editor-help\"></span></a>";
999 return $html;
1000 }
1001
1002 /**
1003 * Display global notices (throughout wp-admin dashboard)
1004 */
1005 function display_global_notices() {
1006 global $permalink_manager_alerts, $active_section;
1007
1008 $html = "";
1009 if(!empty($permalink_manager_alerts) && is_array($permalink_manager_alerts)) {
1010 foreach($permalink_manager_alerts as $alert_id => $alert) {
1011 if(!empty($alert['show'])) {
1012 // Hide notice in Permalink Manager Pro
1013 if(defined('PERMALINK_MANAGER_PRO') && $alert['show'] == 'pro_hide') { continue; }
1014
1015 // Display the notice only on the plugin pages
1016 if(empty($active_section) && !empty($alert['plugin_only'])) { continue; }
1017
1018 // Check if the notice did not expire
1019 if(isset($alert['until']) && (time() > strtotime($alert['until']))) { continue; }
1020
1021 $html .= self::get_alert_message($alert['txt'], $alert['type'], true, $alert_id);
1022 }
1023 }
1024 }
1025
1026 echo $html;
1027 }
1028
1029 /**
1030 * Hide global notices (AJAX)
1031 */
1032 function hide_global_notice() {
1033 global $permalink_manager_alerts;
1034
1035 // Get the ID of the alert
1036 $alert_id = (!empty($_REQUEST['alert_id'])) ? sanitize_title($_REQUEST['alert_id']) : "";
1037 if(!empty($permalink_manager_alerts[$alert_id])) {
1038 $permalink_manager_alerts[$alert_id]['show'] = 0;
1039 }
1040
1041 update_option( 'permalink-manager-alerts', $permalink_manager_alerts);
1042 }
1043
1044 /**
1045 * Display notices generated by Permalink Manager tools
1046 */
1047 function display_plugin_notices() {
1048 global $permalink_manager_before_sections_html;
1049
1050 echo $permalink_manager_before_sections_html;
1051 }
1052
1053 /**
1054 * Check if Permalink Manager Pro is active
1055 */
1056 public static function is_pro_active($return_text = false) {
1057 if(defined('PERMALINK_MANAGER_PRO') && PERMALINK_MANAGER_PRO == true) {
1058 $is_pro = true;
1059 } else {
1060 $is_pro = false;
1061 }
1062
1063 // Check if license is active
1064 if(class_exists('Permalink_Manager_Pro_Functions')) {
1065 $exp_date = Permalink_Manager_Pro_Functions::get_expiration_date(true);
1066
1067 $is_pro = ($exp_date > 1) ? false : true;
1068 } else {
1069 $is_pro = false;
1070 }
1071
1072 return $is_pro;
1073 }
1074
1075 static function pro_text($text_only = false) {
1076 if(class_exists('Permalink_Manager_Pro_Functions')) {
1077 $text = Permalink_Manager_Pro_Functions::get_expiration_date(false, true);
1078 } else {
1079 $text = sprintf(__('This functionality is available only in <a href="%s" target="_blank">Permalink Manager Pro</a>.', 'permalink-manager'), PERMALINK_MANAGER_WEBSITE);
1080 }
1081
1082 return ($text_only) ? $text : sprintf("<div class=\"alert info\"> %s</div>", wpautop($text, 'alert', false));
1083 }
1084
1085 }
1086