PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 1.1.0
Permalink Manager Lite v1.1.0
2.6.0 2.5.5 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 9 years ago permalink-manager-admin-functions.php 9 years ago permalink-manager-helper-functions.php 9 years ago permalink-manager-third-parties.php 9 years ago permalink-manager-uri-functions-post.php 9 years ago
permalink-manager-admin-functions.php
569 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_slug = PERMALINK_MANAGER_PLUGIN_SLUG;
10 public $plugin_basename = PERMALINK_MANAGER_BASENAME;
11
12 public function __construct() {
13 add_action( 'admin_menu', array($this, 'add_menu_page') );
14 add_action( 'admin_init', array($this, 'init') );
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
21 /**
22 * Hooks that should be triggered with "admin_init"
23 */
24 public function init() {
25 // Additional link in "Plugins" page
26 add_filter( "plugin_action_links_{$this->plugin_basename}", array($this, "plugins_page_links") );
27
28 // Detect current section
29 $this->sections = apply_filters('permalink-manager-sections', array());
30 $this->get_current_section();
31 }
32
33 /**
34 * Get current section (only in plugin sections)
35 */
36 public function get_current_section() {
37 global $active_section, $active_subsection, $current_admin_tax;
38
39 // 1. Get current section
40 if(isset($_GET['page']) && $_GET['page'] == $this->plugin_slug) {
41 if(isset($_POST['section'])) {
42 $this->active_section = $_POST['section'];
43 } else if(isset($_GET['section'])) {
44 $this->active_section = $_GET['section'];
45 } else {
46 $sections_names = array_keys($this->sections);
47 $this->active_section = $sections_names[0];
48 }
49 }
50
51 // 2. Get current subsection
52 if($this->active_section && isset($this->sections[$this->active_section]['subsections'])) {
53 if(isset($_POST['subsection'])) {
54 $this->active_subsection = $_POST['subsection'];
55 } else if(isset($_GET['subsection'])) {
56 $this->active_subsection = $_GET['subsection'];
57 } else {
58 $subsections_names = array_keys($this->sections[$this->active_section]['subsections']);
59 $this->active_subsection = $subsections_names[0];
60 }
61 }
62
63 // Check if current admin page is related to taxonomies
64 if(substr($this->active_subsection, 0, 4) == 'tax_') {
65 $current_admin_tax = substr($this->active_subsection, 4, strlen($this->active_subsection));
66 } else {
67 $current_admin_tax = false;
68 }
69
70 // Set globals
71 $active_section = $this->active_section;
72 $active_subsection = $this->active_subsection;
73 }
74
75 /**
76 * Add menu page.
77 */
78 public function add_menu_page() {
79 $this->menu_name = add_management_page( __('Permalink Manager', 'permalink-manager'), __('Permalink Manager', 'permalink-manager'), 'manage_options', $this->plugin_slug, array($this, 'display_section') );
80
81 add_action( 'admin_init', array($this, 'enqueue_styles' ) );
82 add_action( 'admin_init', array($this, 'enqueue_scripts' ) );
83 }
84
85 /**
86 * Register the CSS file for the dashboard.
87 */
88 public function enqueue_styles() {
89 wp_enqueue_style( 'permalink-manager-plugins', PERMALINK_MANAGER_URL . '/out/permalink-manager-plugins.css', array(), PERMALINK_MANAGER_VERSION, 'all' );
90 wp_enqueue_style( 'permalink-manager', PERMALINK_MANAGER_URL . '/out/permalink-manager-admin.css', array('permalink-manager-plugins'), PERMALINK_MANAGER_VERSION, 'all' );
91 }
92
93 /**
94 * Register the JavaScript file for the dashboard.
95 */
96 public function enqueue_scripts() {
97 wp_enqueue_script( 'permalink-manager-plugins', PERMALINK_MANAGER_URL . '/out/permalink-manager-plugins.js', array( 'jquery', ), PERMALINK_MANAGER_VERSION, false );
98 wp_enqueue_script( 'permalink-manager', PERMALINK_MANAGER_URL . '/out/permalink-manager-admin.js', array( 'jquery', 'permalink-manager-plugins' ), PERMALINK_MANAGER_VERSION, false );
99
100 wp_localize_script( 'permalink-manager', 'permalink_manager', array('url' => PERMALINK_MANAGER_URL) );
101 }
102
103 /**
104 * Get admin url for the plugin
105 */
106 function get_admin_url($append = '') {
107 return menu_page_url( "{$this->plugin_slug}", false ) . $append;
108 }
109
110 /**
111 * Additional links on "Plugins" page
112 */
113 public function plugins_page_links($links) {
114 $links[] = sprintf('<a href="%s">%s</a>', $this->get_admin_url(), __( 'URI Editor', 'permalink-manager' ));
115 if(!defined('PERMALINK_MANAGER_PRO') || PERMALINK_MANAGER_PRO !== true) {
116 $links[] = sprintf('<a href="%s" target="_blank">%s</a>', PERMALINK_MANAGER_WEBSITE, __( 'Buy Permalink Manager Pro', 'permalink-manager' ));
117 }
118 return $links;
119 }
120
121 /**
122 * Generate the fields
123 */
124 static public function generate_option_field($input_name, $args) {
125 global $permalink_manager_options;
126
127 // Reset $fields variables
128 $fields = $section_name = $field_name = '';
129
130 // Allow to filter the $args
131 $args = apply_filters('permalink-manager-field-args', $args, $input_name);
132
133 $field_type = (isset($args['type'])) ? $args['type'] : 'text';
134 $default = (isset($args['default'])) ? $args['default'] : '';
135 $label = (isset($args['label'])) ? $args['label'] : '';
136 $rows = (isset($args['rows'])) ? "rows=\"{$rows}\"" : "rows=\"5\"";
137 $container_class = (isset($args['container_class'])) ? " class=\"{$args['container_class']} field-container\"" : " class=\"field-container\"";
138 $description = (isset($args['before_description'])) ? $args['before_description'] : "";
139 $description .= (isset($args['description'])) ? "<p class=\"field-description description\">{$args['description']}</p>" : "";
140 $description .= (isset($args['after_description'])) ? $args['after_description'] : "";
141 $description .= (isset($args['pro'])) ? sprintf("<p class=\"field-description description\">%s</p>", strip_tags(Permalink_Manager_Admin_Functions::pro_text(true))) : "";
142 $append_content = (isset($args['append_content'])) ? "{$args['append_content']}" : "";
143
144 // Input attributes
145 $input_atts = (isset($args['input_class'])) ? "class='{$args['input_class']}'" : '';
146 $input_atts .= (isset($args['readonly'])) ? " readonly='readonly'" : '';
147 $input_atts .= (isset($args['disabled'])) ? " disabled='disabled'" : '';
148 $input_atts .= (isset($args['placeholder'])) ? " placeholder='{$args['placeholder']}'" : '';
149 $input_atts .= (isset($args['extra_atts'])) ? " {$args['extra_atts']}" : '';
150
151 // Get the field value (if it is not set in $args)
152 if(isset($args['value']) && empty($args['value']) == false) {
153 $value = $args['value'];
154 } else {
155 // Extract the section and field name from $input_name
156 preg_match("/(.*)\[(.*)\]/", $input_name, $field_section_and_name);
157
158 if($field_section_and_name) {
159 $section_name = $field_section_and_name[1];
160 $field_name = $field_section_and_name[2];
161 $value = (isset($permalink_manager_options[$section_name][$field_name])) ? $permalink_manager_options[$section_name][$field_name] : $default;
162 } else {
163 $value = (isset($permalink_manager_options[$input_name])) ? $permalink_manager_options[$input_name] : $default;
164 }
165 }
166
167 switch($field_type) {
168 case 'checkbox' :
169 $fields .= '<div class="checkboxes">';
170 foreach($args['choices'] as $choice_value => $choice) {
171 $label = (is_array($choice)) ? $choice['label'] : $choice;
172 $atts = (is_array($value) && in_array($choice_value, $value)) ? "checked='checked'" : "";
173 $atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
174
175 $fields .= "<label for='{$input_name}[]'><input type='checkbox' {$input_atts} value='{$choice_value}' name='{$input_name}[]' {$atts} /> {$label}</label>";
176 }
177 $fields .= '</div>';
178
179 // Add helper checkboxes for bulk actions
180 if(isset($args['select_all']) || isset($args['unselect_all'])) {
181 $select_all_label = (!empty($args['select_all'])) ? $args['select_all'] : __('Select all', 'permalink-manager');
182 $unselect_all_label = (!empty($args['unselect_all'])) ? $args['unselect_all'] : __('Unselect all', 'permalink-manager');
183
184 $fields .= "<p class=\"checkbox_actions extra-links\">";
185 $fields .= (isset($args['select_all'])) ? "<a href=\"#\" class=\"select_all\">{$select_all_label}</a>&nbsp;" : "";
186 $fields .= (isset($args['unselect_all'])) ? "<a href=\"#\" class=\"unselect_all\">{$unselect_all_label}</a>" : "";
187 $fields .= "</p>";
188 }
189 break;
190
191 case 'single_checkbox' :
192 $fields .= '<div class="checkboxes">';
193 $checked = ($value == 1) ? "checked='checked'" : "";
194 $checkbox_label = (isset($args['checkbox_label'])) ? $args['checkbox_label'] : '';
195
196 $fields .= "<input type='hidden' {$input_atts} value='0' name='{$input_name}' checked=\"checked\" />";
197 $fields .= "<label for='{$input_name}'><input type='checkbox' {$input_atts} value='1' name='{$input_name}' {$checked} /> {$checkbox_label}</label>";
198 $fields .= '</div>';
199 break;
200
201 case 'radio' :
202 $fields .= '<div class="radios">';
203 foreach($args['choices'] as $choice_value => $choice) {
204 $label = (is_array($choice)) ? $choice['label'] : $choice;
205 $atts = ($choice_value == $value) ? "checked='checked'" : "";
206 $atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
207
208 $fields .= "<label for='{$input_name}[]'><input type='radio' {$input_atts} value='{$choice_value}' name='{$input_name}[]' {$atts} /> {$label}</label>";
209 }
210 $fields .= '</div>';
211 break;
212
213 case 'select' :
214 $fields .= '<div class="select">';
215 $fields .= "<select name='{$input_name}' {$input_atts}>";
216 foreach($args['choices'] as $choice_value => $choice) {
217 $label = (is_array($choice)) ? $choice['label'] : $choice;
218 $atts = ($choice_value == $value) ? "selected='selected'" : "";
219 $atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
220
221 $fields .= "<option value='{$choice_value}' {$atts} />{$label}</option>";
222 }
223 $fields .= '</select>';
224 $fields .= '</div>';
225 break;
226
227 case 'number' :
228 $fields .= "<input type='number' {$input_atts} value='{$value}' name='{$input_name}' />";
229 break;
230
231 case 'hidden' :
232 $fields .= "<input type='hidden' {$input_atts} value='{$value}' name='{$input_name}' />";
233 break;
234
235 case 'textarea' :
236 $fields .= "<textarea {$input_atts} name='{$input_name}' {$rows}>{$value}</textarea>";
237 break;
238
239 case 'pre' :
240 $fields .= "<pre {$input_atts}>{$value}</pre>";
241 break;
242
243 case 'info' :
244 $fields .= "<div {$input_atts}>{$value}</div>";
245 break;
246
247 case 'clearfix' :
248 return "<div class=\"clearfix\"></div>";
249
250 case 'permastruct' :
251 $siteurl = get_option('home');
252 $fields .= "<code>{$siteurl}/</code><input type='text' {$input_atts} value='{$value}' name='{$input_name}'/>";
253 break;
254
255 default :
256 $fields .= "<input type='text' {$input_atts} value='{$value}' name='{$input_name}'/>";
257 }
258
259 // Get the final HTML output
260 if(isset($args['container']) && $args['container'] == 'tools') {
261 $html = "<div{$container_class}>";
262 $html .= "<h4>{$label}</h4>";
263 $html .= "<div class='{$input_name}-container'>{$fields}</div>";
264 $html .= $description;
265 $html .= $append_content;
266 $html .= "</div>";
267 } else if(isset($args['container']) && $args['container'] == 'row') {
268 $html = "<tr data-field=\"{$input_name}\" {$container_class}><th><label for='{$input_name}'>{$args['label']}</label></th>";
269 $html .= "<td>{$fields}{$description}</td></tr>";
270 $html .= ($append_content) ? "<tr class=\"appended-row\"><td colspan=\"2\">{$append_content}</td></tr>" : "";
271 } else if(isset($args['container']) && $args['container'] == 'screen-options') {
272 $html = "<fieldset data-field=\"{$input_name}\" {$container_class}><legend>{$args['label']}</legend>";
273 $html .= "<div class=\"field-content\">{$fields}{$description}</div>";
274 $html .= ($append_content) ? "<div class=\"appended-row\">{$append_content}</div>" : "";
275 $html .= "</fieldset>";
276 } else {
277 $html = $fields . $append_content;
278 }
279
280 return apply_filters('permalink-manager-field-output', $html);
281 }
282
283 /**
284 * Display hidden field to indicate posts or taxonomies admin sections
285 */
286 static public function section_type_field($type = 'post') {
287 return self::generate_option_field('content_type', array('value' => $type, 'type' => 'hidden'));
288 }
289
290 /**
291 * Display the form
292 */
293 static public function get_the_form($fields = array(), $container = '', $button = array(), $sidebar = '', $nonce = array(), $wrap = false) {
294 // 1. Check if the content will be displayed in columns and button details
295 switch($container) {
296 case 'columns-3' :
297 $wrapper_class = 'columns-container';
298 $form_column_class = 'column column-2_3';
299 $sidebar_class = 'column column-1_3';
300 break;
301
302 // there will be more cases in future ...
303 default :
304 $form_column_class = 'form';
305 $sidebar_class = 'sidebar';
306 $wrapper_class = $form_column_class = '';
307 }
308
309 // 2. Process the array with button and nonce field settings
310 $button_text = (!empty($button['text'])) ? $button['text'] : '';
311 $button_class = (!empty($button['class'])) ? $button['class'] : '';
312 $nonce_action = (!empty($nonce['action'])) ? $nonce['action'] : '';
313 $nonce_name = (!empty($nonce['name'])) ? $nonce['name'] : '';
314
315 // 2. Now get the HTML output (start section row container)
316 $html = ($wrapper_class) ? "<div class=\"{$wrapper_class}\">" : '';
317
318 // 3. Display some notes
319 if($sidebar_class && $sidebar) {
320 $html .= "<div class=\"{$sidebar_class}\">";
321 $html .= "<div class=\"section-notes\">";
322 $html .= $sidebar;
323 $html .= "</div>";
324 $html .= "</div>";
325 }
326
327 // 4. Start fields' section
328 $html .= ($form_column_class) ? "<div class=\"{$form_column_class}\">" : "";
329 $html .= "<form method=\"POST\">";
330 $html .= ($wrap) ? "<table class=\"form-table\">" : "";
331
332 // Loop through all fields assigned to this section
333 foreach($fields as $field_name => $field) {
334 $field_name = (!empty($field['name'])) ? $field['name'] : $field_name;
335
336 // A. Display table row
337 if(isset($field['container']) && $field['container'] == 'row') {
338 $row_output = "";
339
340 // Loop through all fields assigned to this section
341 if(isset($field['fields'])) {
342 foreach($field['fields'] as $section_field_id => $section_field) {
343 $section_field_name = (!empty($section_field['name'])) ? $section_field['name'] : "{$field_name}[$section_field_id]";
344 $section_field['container'] = 'row';
345
346 $row_output .= self::generate_option_field($section_field_name, $section_field);
347 }
348 } else {
349 $row_output .= self::generate_option_field($field_name, $field);
350 }
351
352 if(isset($field['section_name'])) {
353 $html .= "<h3>{$field['section_name']}</h3>";
354 $html .= (isset($field['append_content'])) ? $field['append_content'] : "";
355 $html .= (isset($field['description'])) ? "<p class=\"description\">{$field['description']}</p>" : "";
356 $html .= "<table class=\"form-table\" data-field=\"{$field_name}\">{$row_output}</table>";
357 } else {
358 $html .= $row_output;
359 }
360 }
361 // B. Display single field
362 else {
363 $html .= self::generate_option_field($field_name, $field);
364 }
365 }
366
367 $html .= ($wrap) ? "</table>" : "";
368
369 // End the fields' section + add button & nonce fields
370 $html .= ($nonce_action && $nonce_name) ? wp_nonce_field($nonce_action, $nonce_name, true, true) : "";
371 $html .= ($button_text) ? get_submit_button($button_text, $button_class, '', false) : "";
372 $html .= '</form>';
373 $html .= ($form_column_class) ? "</div>" : "";
374
375 // 5. End the section row container
376 $html .= ($wrapper_class) ? "</div>" : "";
377
378 return $html;
379 }
380
381 /**
382 * Display the plugin sections.
383 */
384 public function display_section() {
385 global $wpdb, $permalink_manager_before_sections_html, $permalink_manager_after_sections_html;
386
387 $html = "<div id=\"permalink-manager\" class=\"wrap\">";
388
389 // Display alerts [moved to display_plugin_notices() function] and another content if needed and the plugin header
390 // $html .= $permalink_manager_before_sections_html;
391 $buy_link = (!defined('PERMALINK_MANAGER_PRO')) ? sprintf("<a href=\"%s\" target=\"_blank\" class=\"page-title-action\">%s</a>", PERMALINK_MANAGER_WEBSITE, __("Buy Permalink Manager Pro", "permalink-manager")) : "";
392 $donate_link = sprintf("<a href=\"%s\" target=\"_blank\" class=\"page-title-action\">%s</a>", PERMALINK_MANAGER_DONATE, __("Donate", "permalink-manager"));
393 $html .= sprintf("<h2 id=\"plugin-name-heading\">%s <a href=\"http://maciejbis.net\" class=\"author-link\" target=\"_blank\">%s</a> %s %s</h2>", PERMALINK_MANAGER_PLUGIN_NAME, __("by Maciej Bis", "permalink-manager"), $buy_link, $donate_link);
394
395 // Display the tab navigation
396 $html .= "<div id=\"permalink-manager-tab-nav\" class=\"nav-tab-wrapper\">";
397 foreach($this->sections as $section_name => $section_properties) {
398 $active_class = ($this->active_section === $section_name) ? 'nav-tab-active nav-tab' : 'nav-tab';
399 $section_url = $this->get_admin_url("&section={$section_name}");
400
401 $html .= "<a href=\"{$section_url}\" class=\"{$active_class} section_{$section_name}\">{$section_properties['name']}</a>";
402 }
403 $html .= "</div>";
404
405 // Now display the active section
406 $html .= "<div id=\"permalink-manager-sections\">";
407 $active_section_array = (isset($this->sections[$this->active_section])) ? $this->sections[$this->active_section] : "";
408
409 // Display addidional navigation for subsections
410 if(isset($this->sections[$this->active_section]['subsections'])) {
411 $html .= "<ul class=\"subsubsub\">";
412 foreach ($this->sections[$this->active_section]['subsections'] as $subsection_name => $subsection) {
413 $active_class = ($this->active_subsection === $subsection_name) ? 'current' : '';
414 $subsection_url = $this->get_admin_url("&section={$this->active_section}&subsection={$subsection_name}");
415
416 $html .= "<li><a href=\"{$subsection_url}\" class=\"{$active_class}\">{$subsection['name']}</a></li>";
417 }
418 $html .= "</ul>";
419 }
420
421 // A. Execute the function assigned to the subsection
422 if(isset($active_section_array['subsections'][$this->active_subsection]['function'])) {
423 $class_name = $active_section_array['subsections'][$this->active_subsection]['function']['class'];
424 $section_object = new $class_name();
425
426 $section_content = call_user_func(array($section_object, $active_section_array['subsections'][$this->active_subsection]['function']['method']));
427 }
428 // B. Execute the function assigned to the section
429 else if(isset($active_section_array['function'])) {
430 $class_name = $active_section_array['function']['class'];
431 $section_object = new $class_name();
432
433 $section_content = call_user_func(array($section_object, $active_section_array['function']['method']));
434 }
435 // C. Display the raw HTMl output of subsection
436 else if(isset($active_section_array['subsections'][$this->active_subsection]['html'])) {
437 $section_content = (isset($active_section_array['subsections'][$this->active_subsection]['html'])) ? $active_section_array['subsections'][$this->active_subsection]['html'] : "";
438 }
439 // D. Try to display the raw HTMl output of section
440 else {
441 $section_content = (isset($active_section_array['html'])) ? $active_section_array['html'] : "";
442 }
443
444 $html .= "<div class=\"single-section\" data-section=\"{$this->active_section}\" id=\"{$this->active_section}\">{$section_content}</div>";
445 $html .= "</div>";
446
447 // Display alerts and another content if needed and close .wrap container
448 $html .= $permalink_manager_after_sections_html;
449 $html .= "</div>";
450
451 echo $html;
452 }
453
454 /**
455 * Display error/info message
456 */
457 public static function get_alert_message($alert_content, $alert_type, $dismissable = true, $id = false) {
458 $class = ($dismissable) ? "is-dismissible" : "";
459 $alert_id = ($id) ? " data-alert_id=\"{$id}\"" : "";
460
461 $html = sprintf( "<div class=\"{$alert_type} permalink-manager-notice notice {$class}\"{$alert_id}> %s</div>", wpautop($alert_content) );
462
463 return $html;
464 }
465
466 static function pro_text($text_only = false) {
467 $text = sprintf(__('This functionality is available only in <a href="%s" target="_blank">Permalink Manager Pro</a>.', 'permalink-manager'), PERMALINK_MANAGER_WEBSITE);
468
469 return ($text_only) ? $text : sprintf("<div class=\"alert info\"> %s</div>", wpautop($text, 'alert', false));
470 }
471
472 /**
473 * Help tooltip
474 */
475 static function help_tooltip($text = '') {
476 $html = " <a href=\"#\" title=\"{$text}\" class=\"help_tooltip\"><span class=\"dashicons dashicons-editor-help\"></span></a>";
477 return $html;
478 }
479
480 /**
481 * Display the table with updated slugs after one of the actions is triggered
482 */
483 static function display_updated_slugs($updated_array, $uri_type = 'post') {
484 // Check if slugs should be displayed
485 $first_slug = reset($updated_array);
486
487 $header_footer = '<tr>';
488 $header_footer .= '<th class="column-primary">' . __('Title', 'permalink-manager') . '</th>';
489 $header_footer .= '<th>' . __('Old URI', 'permalink-manager') . '</th>';
490 $header_footer .= '<th>' . __('New URI', 'permalink-manager') . '</th>';
491 $header_footer .= (isset($first_slug['old_slug'])) ? '<th>' . __('Old Slug', 'permalink-manager') . '</th>' : "";
492 $header_footer .= (isset($first_slug['new_slug'])) ? '<th>' . __('New Slug', 'permalink-manager') . '</th>' : "";
493 $header_footer .= '</tr>';
494
495 $updated_slugs_count = 0;
496 $main_content = "";
497 foreach($updated_array as $row) {
498 // Odd/even class
499 $updated_slugs_count++;
500 $alternate_class = ($updated_slugs_count % 2 == 1) ? ' class="alternate"' : '';
501
502 // Taxonomy
503 if(!empty($row['tax'])) {
504 $term_link = get_term_link(intval($row['ID']), $row['tax']);
505 $permalink = (is_wp_error($term_link)) ? "-" : $term_link;
506 } else {
507 $permalink = get_permalink($row['ID']);
508 }
509
510 $main_content .= "<tr{$alternate_class}>";
511 $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>';
512 $main_content .= '<td data-colname="' . __('Old URI', 'permalink-manager') . '">' . $row['old_uri'] . '</td>';
513 $main_content .= '<td data-colname="' . __('New URI', 'permalink-manager') . '">' . $row['new_uri'] . '</td>';
514 $main_content .= (isset($row['old_slug'])) ? '<td data-colname="' . __('Old Slug', 'permalink-manager') . '">' . $row['old_slug'] . '</td>' : "";
515 $main_content .= (isset($row['new_slug'])) ? '<td data-colname="' . __('New Slug', 'permalink-manager') . '">' . $row['new_slug'] . '</td>' : "";
516 $main_content .= '</tr>';
517 }
518
519 // Merge header, footer and content
520 $html = '<h3 id="updated-list">' . __('List of updated items', 'permalink-manager') . '</h3>';
521 $html .= '<table class="widefat wp-list-table updated-slugs-table">';
522 $html .= "<thead>{$header_footer}</thead><tbody>{$main_content}</tbody><tfoot>{$header_footer}</tfoot>";
523 $html .= '</table>';
524
525 return $html;
526 }
527
528 /**
529 * Display global notices (throughout wp-admin dashboard)
530 */
531 function display_global_notices() {
532 global $permalink_manager_alerts;
533
534 $html = "";
535 if(!empty($permalink_manager_alerts) && is_array($permalink_manager_alerts)) {
536 foreach($permalink_manager_alerts as $alert_id => $alert) {
537 $html .= (!empty($alert['show'])) ? self::get_alert_message($alert['txt'], $alert['type'], true, $alert_id) : "";
538 }
539 }
540
541 echo $html;
542 }
543
544 /**
545 * Hide global notices (AJAX)
546 */
547 function hide_global_notice() {
548 global $permalink_manager_alerts;
549
550 // Get the ID of the alert
551 $alert_id = (!empty($_REQUEST['alert_id'])) ? sanitize_title($_REQUEST['alert_id']) : "";
552 if(!empty($permalink_manager_alerts[$alert_id])) {
553 $permalink_manager_alerts[$alert_id]['show'] = 0;
554 }
555
556 update_option( 'permalink-manager-alerts', $permalink_manager_alerts);
557 }
558
559 /**
560 * Display notices generated by Permalink Manager tools
561 */
562 function display_plugin_notices() {
563 global $permalink_manager_before_sections_html;
564
565 echo $permalink_manager_before_sections_html;
566 }
567
568 }
569