| @@ -1,187 +1,174 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; | |
| 3 | - | |
| 4 | -if (!class_exists('WP_List_Table')) { | |
| 5 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); | |
| 2 | +if(!class_exists('WP_List_Table')){ | |
| 3 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); | |
| 6 | 4 | } |
| 7 | 5 | |
| 8 | 6 | class Accua_Forms_List_Table extends WP_List_Table { |
| 9 | - var $message = NULL; | |
| 10 | - var $active_items = 0; | |
| 11 | - var $del_items = 0; | |
| 12 | - var $accua_orderby = null; | |
| 13 | - var $accua_order_asc = null; | |
| 14 | 7 | |
| 15 | - function __construct(){ | |
| 16 | - global $status, $page; | |
| 17 | - $this->message = ''; | |
| 18 | - parent::__construct(array( | |
| 19 | - 'singular' => 'form', | |
| 20 | - 'plural' => 'forms', | |
| 21 | - 'ajax' => false | |
| 22 | - )); | |
| 23 | - } | |
| 8 | + var $message = NULL; | |
| 9 | + var $active_items = 0; | |
| 10 | + var $del_items = 0; | |
| 24 | 11 | |
| 25 | - function get_num_of_active_items(){ | |
| 26 | - return $this->active_items; | |
| 27 | - } | |
| 12 | + var $accua_orderby = null; | |
| 13 | + var $accua_order_asc = null; | |
| 28 | 14 | |
| 29 | - function get_num_of_del_items(){ | |
| 30 | - return $this->del_items; | |
| 31 | - } | |
| 15 | + function __construct(){ | |
| 16 | + global $status, $page; | |
| 17 | + $this->message = ''; | |
| 18 | + parent::__construct( array( | |
| 19 | + 'singular' => 'form', | |
| 20 | + 'plural' => 'forms', | |
| 21 | + 'ajax' => false | |
| 22 | + ) ); | |
| 23 | + } | |
| 32 | 24 | |
| 33 | - function column_default($item, $column_name){ | |
| 34 | - if (isset($item[$column_name])) { | |
| 35 | - return esc_attr($item[$column_name]); | |
| 36 | - } else { | |
| 37 | - return ''; | |
| 25 | + function get_num_of_active_items () { | |
| 26 | + return $this->active_items; | |
| 38 | 27 | } |
| 39 | - } | |
| 40 | 28 | |
| 41 | - function column_cb($item){ | |
| 42 | - return sprintf( | |
| 43 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', | |
| 44 | - /*$1%s*/ $this->_args['singular'], | |
| 45 | - /*$2%s*/ $item['ID'] | |
| 46 | - ); | |
| 47 | - } | |
| 29 | + function get_num_of_del_items () { | |
| 30 | + return $this->del_items; | |
| 31 | + } | |
| 48 | 32 | |
| 49 | - function column_title($item){ | |
| 50 | - if ($item['deleted']) { | |
| 51 | - if (isset($item['title'])) { | |
| 52 | - $item_name = esc_html($item['title']); | |
| 33 | + function column_default($item, $column_name){ | |
| 34 | + if (isset($item[$column_name])) { | |
| 35 | + return htmlspecialchars($item[$column_name], ENT_QUOTES); | |
| 53 | 36 | } else { |
| 54 | - $item_name = $item['ID']; | |
| 37 | + return ''; | |
| 55 | 38 | } |
| 56 | - $nonced_edit = wp_nonce_url('admin.php?page=accua_forms_list&fid=' . $item['ID'] . '&restore=1', 'edit_posts'); | |
| 57 | - $actions = array( | |
| 58 | - 'edit' => "<a href='" . $nonced_edit . "'>" . __("Restore", 'contact-forms') . "</a>", | |
| 59 | - ); | |
| 60 | - return "<strong>" . $item_name . "</strong>" . $this->row_actions($actions); | |
| 61 | - } else { | |
| 62 | - $nonced_edit = wp_nonce_url('admin.php?page=accua_forms_list&fid=' . $item['ID'], 'edit_posts'); | |
| 63 | - $nonced_clone = wp_nonce_url('admin.php?page=accua_forms_add&clonefrom=' . $item['ID'], 'clone_posts'); | |
| 64 | - $nonced_del = wp_nonce_url('admin.php?page=accua_forms_list&fid_del=' . $item['ID'], 'trash_posts'); | |
| 65 | - $actions = array( | |
| 66 | - 'edit' => "<a href='{$nonced_edit}'>" . __("Edit", 'contact-forms') . "</a>" | |
| 67 | - . " · <a href='{$nonced_clone}'>" . __("Clone", 'contact-forms') . "</a>" | |
| 68 | - . " · <a href='admin.php?page=accua_forms_submissions_list&fid={$item['ID']}'>" . __("Report", 'contact-forms') . "</a>" | |
| 69 | - . " · <a href='{$nonced_del}'>" . __("Trash", 'contact-forms') . "</a>", | |
| 70 | - ); | |
| 71 | - return "<strong><a class='row-title' href='{$nonced_edit}'>" . esc_html($item['title']) . "</a></strong>" . $this->row_actions($actions); | |
| 72 | 39 | } |
| 73 | - } | |
| 74 | 40 | |
| 75 | - function column_submissions($item){ | |
| 76 | - if ($item['submissions'] != 0) | |
| 77 | - return sprintf( | |
| 78 | - '<a href="admin.php?page=accua_forms_submissions_list&fid=%1$s">%2$s</a>', | |
| 79 | - /*$1%s*/ $item['ID'], | |
| 80 | - /*$2%s*/ $item['submissions'] | |
| 81 | - ); | |
| 82 | - else | |
| 83 | - return "0"; | |
| 84 | - } | |
| 41 | + function column_cb($item){ | |
| 42 | + return sprintf( | |
| 43 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', | |
| 44 | + /*$1%s*/ $this->_args['singular'], | |
| 45 | + /*$2%s*/ $item['ID'] | |
| 46 | + ); | |
| 47 | + } | |
| 85 | 48 | |
| 86 | - function get_columns(){ | |
| 87 | - $columns = array( | |
| 88 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text | |
| 89 | - 'title' => __('Title', 'contact-forms'), | |
| 90 | - 'ID' => 'ID', | |
| 91 | - 'shortcode' => __('Shortcode', 'contact-forms'), | |
| 92 | - 'phpcode' => __('PHP code', 'contact-forms'), | |
| 93 | - 'fromemail' => __('From Email', 'contact-forms'), | |
| 94 | - 'fromname' => __('From Name', 'contact-forms'), | |
| 95 | - 'adminemail' => __('Admin Email', 'contact-forms'), | |
| 96 | - 'bccemail' => __('BCC Email', 'contact-forms'), | |
| 97 | - 'retention' => __('Data Retention', 'contact-forms'), | |
| 98 | - 'submissions' => __('Submissions', 'contact-forms'), | |
| 99 | - ); | |
| 100 | - return $columns; | |
| 101 | - } | |
| 49 | + function column_title($item){ | |
| 50 | + if ($item['deleted']) { | |
| 51 | + if (isset($item['title'])) { | |
| 52 | + $item_name = htmlspecialchars($item['title']); | |
| 53 | + } else { | |
| 54 | + $item_name = $item['ID']; | |
| 55 | + } | |
| 56 | + $nonced_edit = wp_nonce_url('admin.php?page=accua_forms_list&fid=' . $item['ID'] . '&restore=1', 'edit_posts'); | |
| 57 | + $actions = array( | |
| 58 | + 'edit' => "<a href='" . $nonced_edit . "'>".__("Restore", 'contact-forms')."</a>", | |
| 59 | + ); | |
| 60 | + return "<strong>".$item_name."</strong>".$this->row_actions($actions); | |
| 61 | + } else { | |
| 62 | + $nonced_edit = wp_nonce_url('admin.php?page=accua_forms_list&fid=' . $item['ID'], 'edit_posts'); | |
| 63 | + $nonced_clone = wp_nonce_url('admin.php?page=accua_forms_add&clonefrom=' . $item['ID'], 'clone_posts'); | |
| 64 | + $nonced_del = wp_nonce_url('admin.php?page=accua_forms_list&fid_del=' . $item['ID'], 'trash_posts'); | |
| 65 | + $actions = array( | |
| 66 | + 'edit' => "<a href='{$nonced_edit}'>".__("Edit", 'contact-forms')."</a>" | |
| 67 | + . " · <a href='{$nonced_clone}'>".__("Clone", 'contact-forms')."</a>" | |
| 68 | + . " · <a href='admin.php?page=accua_forms_submissions_list&fid={$item['ID']}'>".__("Report", 'contact-forms')."</a>" | |
| 69 | + . " · <a href='{$nonced_del}'>".__("Trash", 'contact-forms')."</a>", | |
| 70 | + ); | |
| 71 | + return "<strong><a class='row-title' href='{$nonced_edit}'>".htmlspecialchars($item['title'])."</a></strong>".$this->row_actions($actions); | |
| 72 | + } | |
| 73 | + } | |
| 102 | 74 | |
| 103 | - function column_retention( $item ) { | |
| 104 | - return isset( $item['retention'] ) ? esc_html( $item['retention'] ) : ''; | |
| 105 | - } | |
| 106 | 75 | |
| 107 | - function get_sortable_columns(){ | |
| 108 | - return array( | |
| 109 | - 'title' => array('title', false), | |
| 110 | - 'ID' => array('ID', false), | |
| 111 | - 'shortcode' => array('ID', false), | |
| 112 | - 'phpcode' => array('ID', false), | |
| 113 | - 'fromemail' => array('fromemail', false), | |
| 114 | - 'fromname' => array('fromname', false), | |
| 115 | - 'adminemail' => array('adminemail', false), | |
| 116 | - 'bccemail' => array('bccemail', false), | |
| 117 | - 'retention' => array('retention_seconds', false), | |
| 118 | - 'submissions' => array('submissions', false), | |
| 119 | - ); | |
| 120 | - } | |
| 121 | 76 | |
| 122 | - function get_bulk_actions(){ | |
| 123 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display logic only, no data processing | |
| 124 | - if (isset($_GET['del']) && absint($_GET['del']) === 1) { | |
| 125 | - $actions = array(); | |
| 126 | - } else { | |
| 127 | - $actions = array( | |
| 128 | - 'delete' => __('Move to trash', 'contact-forms') | |
| 77 | + | |
| 78 | + function column_submissions($item){ | |
| 79 | + if($item['submissions']!=0) | |
| 80 | + return sprintf( | |
| 81 | + '<a href="admin.php?page=accua_forms_submissions_list&fid=%1$s">%2$s</a>', | |
| 82 | + /*$1%s*/ $item['ID'], | |
| 83 | + /*$2%s*/ $item['submissions'] | |
| 84 | + ); | |
| 85 | + else | |
| 86 | + return "0"; | |
| 87 | + } | |
| 88 | + | |
| 89 | + | |
| 90 | + function get_columns(){ | |
| 91 | + $columns = array( | |
| 92 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text | |
| 93 | + 'title' => __('Title', 'contact-forms'), | |
| 94 | + 'ID' => 'ID', | |
| 95 | + 'shortcode' => __('Shortcode', 'contact-forms'), | |
| 96 | + 'phpcode' => __('PHP code', 'contact-forms'), | |
| 97 | + 'fromemail' => __('From Email', 'contact-forms'), | |
| 98 | + 'fromname' => __('From Name', 'contact-forms'), | |
| 99 | + 'adminemail' => __('Admin Email', 'contact-forms'), | |
| 100 | + 'bccemail' => __('BCC Email', 'contact-forms'), | |
| 101 | + 'submissions' => __('Submissions', 'contact-forms'), | |
| 102 | + ); | |
| 103 | + return $columns; | |
| 104 | + } | |
| 105 | + | |
| 106 | + function get_sortable_columns() { | |
| 107 | + return array( | |
| 108 | + 'title' => array('title', false), | |
| 109 | + 'ID' => array('ID', false), | |
| 110 | + 'submissions' => array('submissions', false), | |
| 129 | 111 | ); |
| 130 | 112 | } |
| 131 | - return $actions; | |
| 132 | - } | |
| 133 | 113 | |
| 134 | - function set_message($single_message){ | |
| 135 | - $this->message = $single_message; | |
| 136 | - } | |
| 114 | + function get_bulk_actions() { | |
| 115 | + if(isset($_GET['del']) && $_GET['del']==1) { | |
| 116 | + $actions = array(); | |
| 117 | + } else { | |
| 118 | + $actions = array( | |
| 119 | + 'delete' => __('Move to trash', 'contact-forms') | |
| 120 | + ); | |
| 121 | + } | |
| 122 | + return $actions; | |
| 123 | + } | |
| 137 | 124 | |
| 138 | - function get_message(){ | |
| 139 | - if ($this->message != NULL) | |
| 140 | - return $this->message; | |
| 141 | - else | |
| 142 | - return NULL; | |
| 143 | - } | |
| 125 | + function set_message($single_message) { | |
| 126 | + $this->message=$single_message; | |
| 127 | + } | |
| 144 | 128 | |
| 145 | - function accua_usort_numeric($a, $b){ | |
| 146 | - $result = ((int)$a[$this->accua_orderby]) - ((int)$b[$this->accua_orderby]); | |
| 147 | - if (!$result) { | |
| 148 | - $result = ((int)$a['ID']) - ((int)$b['ID']); | |
| 129 | + function get_message() { | |
| 130 | + if($this->message!=NULL) | |
| 131 | + return $this->message; | |
| 132 | + else | |
| 133 | + return NULL; | |
| 149 | 134 | } |
| 150 | - return ($this->accua_order_asc) ? $result : -$result; | |
| 151 | - } | |
| 152 | 135 | |
| 153 | - function accua_usort_string($a, $b){ | |
| 154 | - $result = strcasecmp($a[$this->accua_orderby], $b[$this->accua_orderby]); | |
| 155 | - if (!$result) { | |
| 156 | - $result = ((int)$a['ID']) - ((int)$b['ID']); | |
| 136 | + function accua_usort_numeric( $a, $b ) { | |
| 137 | + $result = ((int)$a[$this->accua_orderby]) - ((int)$b[$this->accua_orderby]); | |
| 138 | + if (!$result) { | |
| 139 | + $result = ((int)$a['ID']) - ((int)$b['ID']); | |
| 140 | + } | |
| 141 | + return ( $this->accua_order_asc ) ? $result : -$result; | |
| 157 | 142 | } |
| 158 | - return ($this->accua_order_asc) ? $result : -$result; | |
| 159 | - } | |
| 160 | 143 | |
| 161 | - function process_bulk_action(){ | |
| 162 | - $current_action = $this->current_action(); | |
| 163 | - if ($current_action) { | |
| 164 | - check_admin_referer('bulk-forms'); //check nonce generated for 'bulk-'.$this->_args['plural'] | |
| 165 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Values sanitized in array_map below | |
| 166 | - $forms_raw = (isset($_GET['form']) && is_array($_GET['form'])) ? wp_unslash($_GET['form']) : array(); | |
| 167 | - $forms = array_map('sanitize_text_field', $forms_raw); | |
| 168 | - if ('delete' === $current_action) { | |
| 144 | + function accua_usort_string( $a, $b ) { | |
| 145 | + $result = strcasecmp($a[$this->accua_orderby], $b[$this->accua_orderby]); | |
| 146 | + if (!$result) { | |
| 147 | + $result = ((int)$a['ID']) - ((int)$b['ID']); | |
| 148 | + } | |
| 149 | + return ( $this->accua_order_asc ) ? $result : -$result; | |
| 150 | + } | |
| 151 | + | |
| 152 | + function process_bulk_action() { | |
| 153 | + | |
| 154 | + $forms = (isset($_GET['form']) && is_array($_GET['form'])) ? $_GET['form'] : array(); | |
| 155 | + if('delete'===$this->current_action() ) { | |
| 169 | 156 | $forms_deleted = false; |
| 170 | 157 | $forms_data = get_option('accua_forms_saved_forms', array()); |
| 171 | 158 | $trash_data = get_option('accua_forms_trash_forms', array()); |
| 172 | 159 | |
| 173 | - foreach ($forms as $single_form) { | |
| 174 | - if (isset($forms_data[$single_form])) { | |
| 160 | + foreach($forms as $single_form) { | |
| 161 | + if(isset($forms_data[$single_form])) { | |
| 175 | 162 | $trash_data[$single_form] = $forms_data[$single_form]; |
| 176 | 163 | unset($forms_data[$single_form]); |
| 177 | 164 | $forms_deleted = true; |
| 178 | 165 | ?> |
| 179 | - <script type="text/javascript"> | |
| 180 | - jQuery(function($){ | |
| 181 | - jQuery("#the-list tr:has(th.check-column input[type='checkbox'][value='<?php echo esc_js( $single_form ); ?>'])").fadeOut(); | |
| 182 | - }); | |
| 183 | - </script> | |
| 166 | + <script type="text/javascript"> | |
| 167 | + jQuery(function($){ | |
| 168 | + jQuery("#the-list tr:has(th.check-column input[type='checkbox'][value='<?php echo $single_form; ?>'])").fadeOut(); | |
| 169 | + }); | |
| 170 | + </script> | |
| 184 | 171 | <?php |
| 185 | 172 | } |
| 186 | 173 | } |
| 187 | 174 | if ($forms_deleted) { |
| @@ -190,174 +177,141 @@ | ||
| 190 | 177 | $this->set_message(__("Forms deleted", 'contact-forms')); |
| 191 | 178 | } |
| 192 | 179 | |
| 193 | 180 | } |
| 181 | + | |
| 194 | 182 | } |
| 195 | - } | |
| 196 | 183 | |
| 197 | - function prepare_items(){ | |
| 198 | - global $wpdb, $hook_suffix; | |
| 199 | - $per_page = 50; | |
| 200 | - $del = isset($_GET['del']) && $_GET['del'] == 1; | |
| 184 | + function prepare_items() { | |
| 185 | + global $wpdb, $hook_suffix; | |
| 186 | + $per_page = 50; | |
| 187 | + $del = isset($_GET['del']) && $_GET['del']==1; | |
| 201 | 188 | |
| 202 | - $columns = $this->get_columns(); | |
| 203 | - $hidden = get_hidden_columns($hook_suffix); | |
| 204 | - $sortable = $this->get_sortable_columns(); | |
| 189 | + $columns = $this->get_columns(); | |
| 190 | + $hidden = get_hidden_columns($hook_suffix); | |
| 191 | + $sortable = $this->get_sortable_columns(); | |
| 205 | 192 | |
| 206 | - $this->_column_headers = array($columns, $hidden, $sortable); | |
| 207 | 193 | |
| 208 | - $current_page = $this->get_pagenum(); | |
| 194 | + $this->_column_headers = array($columns, $hidden, $sortable); | |
| 209 | 195 | |
| 210 | - $limit = ($current_page - 1) * $per_page; | |
| 196 | + $current_page = $this->get_pagenum(); | |
| 211 | 197 | |
| 212 | - $forms_data = get_option('accua_forms_saved_forms', array()); | |
| 213 | - $forms_trash = get_option('accua_forms_trash_forms', array()); | |
| 214 | - $forms_default = get_option('accua_forms_default_form_data', array()); | |
| 198 | + $limit = ($current_page - 1) * $per_page; | |
| 215 | 199 | |
| 216 | - $this->active_items = count($forms_data); | |
| 217 | - $this->del_items = count($forms_trash); | |
| 200 | + $forms_data = get_option('accua_forms_saved_forms', array()); | |
| 201 | + $forms_trash = get_option('accua_forms_trash_forms', array()); | |
| 202 | + $forms_default = get_option('accua_forms_default_form_data',array()); | |
| 218 | 203 | |
| 219 | - $data = array(); | |
| 220 | - $global_retention = get_option( 'accua_forms_retention_data', array() ); | |
| 204 | + $this->active_items = count($forms_data); | |
| 205 | + $this->del_items = count($forms_trash); | |
| 221 | 206 | |
| 222 | - if ($del) { | |
| 223 | - check_admin_referer('deleted_forms'); | |
| 224 | - $start = $forms_trash; | |
| 225 | - } else { | |
| 226 | - $start = $forms_data; | |
| 227 | - } | |
| 207 | + $data = array(); | |
| 228 | 208 | |
| 229 | - foreach ($start as $id => $form) { | |
| 230 | - if (isset($form['title']) && (trim($form['title']) !== '')) { | |
| 231 | - $title = $form['title']; | |
| 232 | - } else { | |
| 233 | - $title = __('(no title)', 'contact-forms'); | |
| 234 | - } | |
| 209 | + if ($del) { | |
| 210 | + check_admin_referer('deleted_forms'); | |
| 211 | + $start = $forms_trash; | |
| 212 | + } else { | |
| 213 | + $start = $forms_data; | |
| 214 | + } | |
| 235 | 215 | |
| 236 | - $data[$id] = array( | |
| 237 | - 'ID' => $id, | |
| 238 | - 'title' => $title, | |
| 239 | - 'submissions' => 0, | |
| 240 | - 'shortcode' => $del ? '' : '[accua-form fid="' . $id . '"]', | |
| 241 | - 'phpcode' => $del ? '' : "<?php accua_forms_include('$id'); ?>", | |
| 242 | - 'deleted' => $del, | |
| 243 | - ); | |
| 216 | + foreach ($start as $id => $form) { | |
| 217 | + if (isset($form['title']) && (trim($form['title']) !== '')) { | |
| 218 | + $title = $form['title']; | |
| 219 | + } else { | |
| 220 | + $title = __('(no title)','contact-forms'); | |
| 221 | + } | |
| 244 | 222 | |
| 245 | - $forminfos = array( | |
| 246 | - 'fromemail' => 'emails_from', | |
| 247 | - 'fromname' => 'emails_from_name', | |
| 248 | - 'adminemail' => 'admin_emails_to', | |
| 249 | - 'bccemail' => 'emails_bcc', | |
| 250 | - ); | |
| 223 | + $data[$id] = array ( | |
| 224 | + 'ID' => $id, | |
| 225 | + 'title' => $title, | |
| 226 | + 'submissions' => 0, | |
| 227 | + 'shortcode'=> $del?'':'[accua-form fid="'.$id.'"]', | |
| 228 | + 'phpcode'=> $del?'':"<?php accua_forms_include('$id'); ?>", | |
| 229 | + 'deleted' => $del, | |
| 230 | + ); | |
| 251 | 231 | |
| 252 | - foreach ($forminfos as $infodest => $infoid) { | |
| 253 | - if (isset($form[$infoid])) { | |
| 254 | - $data[$id][$infodest] = $form[$infoid]; | |
| 255 | - } else { | |
| 256 | - $data[$id][$infodest] = $forms_default[$infoid] . " (default)"; | |
| 232 | + $forminfos = array( | |
| 233 | + 'fromemail' => 'emails_from', | |
| 234 | + 'fromname' => 'emails_from_name', | |
| 235 | + 'adminemail' => 'admin_emails_to', | |
| 236 | + 'bccemail' => 'emails_bcc', | |
| 237 | + ); | |
| 238 | + | |
| 239 | + foreach ($forminfos as $infodest => $infoid) { | |
| 240 | + if (isset($form[$infoid])) { | |
| 241 | + $data[$id][$infodest] = $form[$infoid]; | |
| 242 | + } else { | |
| 243 | + $data[$id][$infodest] = $forms_default[$infoid] . " (default)"; | |
| 244 | + } | |
| 245 | + } | |
| 246 | + | |
| 257 | 247 | } |
| 258 | - } | |
| 259 | 248 | |
| 260 | - // Compute effective data retention column | |
| 261 | - $config = accua_forms_get_retention_config( $id ); | |
| 262 | - $has_override = ! empty( $form['submission_retention_override'] ); | |
| 263 | - $unit_labels = array( 'days' => __( 'days', 'contact-forms' ), 'months' => __( 'months', 'contact-forms' ), 'years' => __( 'years', 'contact-forms' ) ); | |
| 264 | - $mode_labels = array( 'anonymize' => __( 'Anonymize', 'contact-forms' ), 'delete' => __( 'Delete', 'contact-forms' ) ); | |
| 265 | - $data[$id]['retention_seconds'] = $config['seconds']; | |
| 266 | - if ( $config['seconds'] > 0 ) { | |
| 267 | - // Reverse-engineer the display value from the form or global settings | |
| 268 | - if ( $has_override ) { | |
| 269 | - $r_val = isset( $form['submission_retention_value'] ) ? (int) $form['submission_retention_value'] : 0; | |
| 270 | - $r_unit = isset( $form['submission_retention_unit'] ) ? $form['submission_retention_unit'] : 'months'; | |
| 271 | - } else { | |
| 272 | - $r_val = isset( $global_retention['retention_value'] ) ? (int) $global_retention['retention_value'] : 0; | |
| 273 | - $r_unit = isset( $global_retention['retention_unit'] ) ? $global_retention['retention_unit'] : 'months'; | |
| 249 | + $query = "SELECT afs_form_id AS fid, count(*) AS submissions | |
| 250 | + FROM `{$wpdb->prefix}accua_forms_submissions` | |
| 251 | + WHERE afs_status >= 0 | |
| 252 | + GROUP BY afs_form_id"; | |
| 253 | + | |
| 254 | + $submissions = $wpdb->get_results($query, OBJECT); | |
| 255 | + foreach ($submissions as $fsub) { | |
| 256 | + if (isset($data[$fsub->fid])) { | |
| 257 | + $data[$fsub->fid]['submissions'] = $fsub->submissions; | |
| 258 | + } else if ($del){ | |
| 259 | + if (!isset($forms_data[$fsub->fid])) { | |
| 260 | + $data[$fsub->fid] = array( | |
| 261 | + 'ID' => $fsub->fid, | |
| 262 | + 'submissions' => $fsub->submissions, | |
| 263 | + 'deleted' => true, | |
| 264 | + 'shortcode' => '', | |
| 265 | + 'phpcode' => '', | |
| 266 | + 'fromemail' => '', | |
| 267 | + 'fromname' => '', | |
| 268 | + 'adminemail' => '', | |
| 269 | + 'bccemail' => '', | |
| 270 | + ); | |
| 271 | + $this->del_items++; | |
| 272 | + } | |
| 273 | + } else if (!isset($forms_trash[$fsub->fid])) { | |
| 274 | + $this->del_items++; | |
| 275 | + } | |
| 274 | 276 | } |
| 275 | - $r_unit_label = $unit_labels[ $r_unit ] ?? $r_unit; | |
| 276 | - $r_mode_label = $mode_labels[ $config['mode'] ] ?? $config['mode']; | |
| 277 | - $data[$id]['retention'] = sprintf( '%d %s / %s', $r_val, $r_unit_label, $r_mode_label ); | |
| 278 | - } else { | |
| 279 | - $data[$id]['retention'] = __( 'Keep indefinitely', 'contact-forms' ); | |
| 280 | - } | |
| 281 | 277 | |
| 282 | - } | |
| 283 | - | |
| 284 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table query for form submissions count | |
| 285 | - $submissions = $wpdb->get_results( | |
| 286 | - $wpdb->prepare( | |
| 287 | - "SELECT afs_form_id AS fid, count(*) AS submissions | |
| 288 | - FROM `{$wpdb->prefix}accua_forms_submissions` | |
| 289 | - WHERE afs_status >= %d | |
| 290 | - GROUP BY afs_form_id", | |
| 291 | - 0 | |
| 292 | - ), | |
| 293 | - OBJECT | |
| 294 | - ); | |
| 295 | - foreach ($submissions as $fsub) { | |
| 296 | - if (isset($data[$fsub->fid])) { | |
| 297 | - $data[$fsub->fid]['submissions'] = $fsub->submissions; | |
| 298 | - } else if ($del) { | |
| 299 | - if (!isset($forms_data[$fsub->fid])) { | |
| 300 | - $data[$fsub->fid] = array( | |
| 301 | - 'ID' => $fsub->fid, | |
| 302 | - 'submissions' => $fsub->submissions, | |
| 303 | - 'deleted' => true, | |
| 304 | - 'shortcode' => '', | |
| 305 | - 'phpcode' => '', | |
| 306 | - 'fromemail' => '', | |
| 307 | - 'fromname' => '', | |
| 308 | - 'adminemail' => '', | |
| 309 | - 'bccemail' => '', | |
| 310 | - ); | |
| 311 | - $this->del_items++; | |
| 278 | + $this->accua_order_asc = empty($_GET['order']) || ($_GET['order'] != 'desc'); | |
| 279 | + $this->accua_orderby = (isset($_GET['orderby'])) ? $_GET['orderby'] : 'title'; | |
| 280 | + switch($this->accua_orderby) { | |
| 281 | + case 'ID': | |
| 282 | + case 'submissions': | |
| 283 | + $this->accua_orderby = $_GET['orderby']; | |
| 284 | + @ usort( $data, array( &$this, 'accua_usort_numeric' ) ); | |
| 285 | + break; | |
| 286 | + //case 'title': | |
| 287 | + default: | |
| 288 | + $this->accua_orderby = 'title'; | |
| 289 | + @ usort( $data, array( &$this, 'accua_usort_string' ) ); | |
| 312 | 290 | } |
| 313 | - } else if (!isset($forms_trash[$fsub->fid])) { | |
| 314 | - $this->del_items++; | |
| 315 | - } | |
| 316 | - } | |
| 317 | 291 | |
| 318 | - $numeric_keys = array( 'ID', 'submissions', 'retention_seconds' ); | |
| 319 | - $string_keys = array( 'title', 'fromemail', 'fromname', 'adminemail', 'bccemail' ); | |
| 320 | - $allowed_keys = array_merge( $numeric_keys, $string_keys ); | |
| 292 | + $total_items = count($data); | |
| 321 | 293 | |
| 322 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only sort parameter | |
| 323 | - $this->accua_orderby = isset($_GET['orderby']) ? sanitize_key(wp_unslash($_GET['orderby'])) : 'ID'; | |
| 324 | - if ( ! in_array( $this->accua_orderby, $allowed_keys, true ) ) { | |
| 325 | - $this->accua_orderby = 'ID'; | |
| 326 | - } | |
| 327 | - // Default order: ascending for string columns, descending for numeric columns | |
| 328 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only sort direction | |
| 329 | - if (empty($_GET['order'])) { | |
| 330 | - $this->accua_order_asc = in_array( $this->accua_orderby, $string_keys, true ); | |
| 331 | - } else { | |
| 332 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only sort direction | |
| 333 | - $this->accua_order_asc = (sanitize_key(wp_unslash($_GET['order'])) !== 'desc'); | |
| 334 | - } | |
| 335 | - if ( in_array( $this->accua_orderby, $numeric_keys, true ) ) { | |
| 336 | - usort($data, array(&$this, 'accua_usort_numeric')); | |
| 337 | - } else { | |
| 338 | - usort($data, array(&$this, 'accua_usort_string')); | |
| 339 | - } | |
| 294 | + $this->items = array_slice($data,$limit,$per_page); | |
| 340 | 295 | |
| 341 | - $total_items = count($data); | |
| 296 | + $this->set_pagination_args( array( | |
| 297 | + 'total_items' => $total_items, | |
| 298 | + 'per_page' => $per_page, | |
| 299 | + 'total_pages' => ceil($total_items/$per_page) | |
| 300 | + ) ); | |
| 342 | 301 | |
| 343 | - $this->items = array_slice($data, $limit, $per_page); | |
| 302 | + } | |
| 344 | 303 | |
| 345 | - $this->set_pagination_args(array( | |
| 346 | - 'total_items' => $total_items, | |
| 347 | - 'per_page' => $per_page, | |
| 348 | - 'total_pages' => ceil($total_items / $per_page) | |
| 349 | - )); | |
| 350 | - } | |
| 351 | 304 | } |
| 352 | 305 | |
| 353 | 306 | function accua_forms_list_page_table($head = false){ |
| 307 | + | |
| 354 | 308 | static $listTable = null; |
| 355 | - //var_dump($_REQUEST); | |
| 356 | - | |
| 357 | - if (isset($_GET['fid_del'])) { | |
| 309 | + //var_dump($_REQUEST); | |
| 310 | + | |
| 311 | + if(isset($_GET['fid_del'])) { | |
| 358 | 312 | check_admin_referer('trash_posts'); |
| 359 | - $fid = sanitize_text_field( wp_unslash( $_GET['fid_del'] ) ); | |
| 313 | + $fid = $_GET['fid_del']; | |
| 360 | 314 | $forms_data = get_option('accua_forms_saved_forms', array()); |
| 361 | 315 | if (isset($forms_data[$fid])) { |
| 362 | 316 | $trash_data = get_option('accua_forms_trash_forms', array()); |
| 363 | 317 | $trash_data[$fid] = $forms_data[$fid]; |
| @@ -366,8 +320,9 @@ | ||
| 366 | 320 | update_option('accua_forms_saved_forms', $forms_data); |
| 367 | 321 | } |
| 368 | 322 | } |
| 369 | 323 | |
| 324 | + | |
| 370 | 325 | if ($listTable === null) { |
| 371 | 326 | $listTable = new Accua_Forms_List_Table(); |
| 372 | 327 | $listTable->process_bulk_action(); |
| 373 | 328 | $listTable->prepare_items(); |
| @@ -376,30 +331,27 @@ | ||
| 376 | 331 | if ($head === true) { |
| 377 | 332 | return; |
| 378 | 333 | } |
| 379 | 334 | |
| 380 | - if ($listTable->get_message() != NULL) { ?> | |
| 381 | - <div class="updated"><p><?php echo esc_html( $listTable->get_message() ); ?></p></div> | |
| 335 | + if($listTable->get_message()!=NULL) { ?> | |
| 336 | + <div class="updated"><p><?php echo $listTable->get_message(); ?></p></div> | |
| 382 | 337 | <?php } ?> |
| 383 | - <ul class="subsubsub"> | |
| 384 | - <li> | |
| 338 | + <ul class="subsubsub"> | |
| 339 | + <li> | |
| 385 | 340 | <?php $nonced_url = wp_nonce_url('admin.php?page=accua_forms_list', 'home_forms') ?> |
| 386 | - <a <?php if (!isset($_GET['del']) || ($_GET['del'] != 1)) { echo " class='current' "; } ?> href="<?php echo esc_url($nonced_url) ?>"> | |
| 387 | - <?php esc_html_e("Active", 'contact-forms'); ?></a> (<?php echo esc_html($listTable->get_num_of_active_items()); ?>) | | |
| 388 | - </li> | |
| 389 | - <li> | |
| 341 | + <a <?php if (!isset($_GET['del']) || ($_GET['del']!=1)) { echo " class='current' "; } ?> href="<?php echo $nonced_url ?>"> | |
| 342 | + <?php _e("Active", 'contact-forms'); ?></a> (<?php echo $listTable->get_num_of_active_items(); ?>) | | |
| 343 | + </li> | |
| 344 | + <li> | |
| 390 | 345 | <?php $nonced_url = wp_nonce_url('admin.php?page=accua_forms_list&del=1', 'deleted_forms'); ?> |
| 391 | - <a <?php if (isset($_GET['del']) && ($_GET['del'] == 1)) { echo " class='current' "; } ?> href="<?php echo esc_url($nonced_url) ?>"> | |
| 392 | - <?php esc_html_e("Trash", 'contact-forms'); ?></a> (<?php echo esc_html($listTable->get_num_of_del_items()); ?>) | |
| 393 | - </li> | |
| 394 | - </ul> | |
| 346 | + <a <?php if (isset($_GET['del']) && ($_GET['del']==1)) { echo " class='current' "; } ?> href="<?php echo $nonced_url ?>"> | |
| 347 | + <?php _e("Trash", 'contact-forms'); ?></a> (<?php echo $listTable->get_num_of_del_items(); ?>) | |
| 348 | + </li> | |
| 349 | + </ul> | |
| 395 | 350 | |
| 396 | - <form id="accua-forms-list-filter" method="get"> | |
| 397 | - <input type="hidden" name="page" value="<?php echo esc_attr( isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : '' ); ?>" /> | |
| 398 | - <?php | |
| 399 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- WP_List_Table display() outputs safe HTML | |
| 400 | - $listTable->display(); | |
| 401 | - ?> | |
| 402 | - </form> | |
| 351 | + <form id="accua-forms-list-filter" method="get"> | |
| 352 | + <input type="hidden" name="page" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['page'])); ?>" /> | |
| 353 | + <?php $listTable->display(); ?> | |
| 354 | + </form> | |
| 403 | 355 | <?php /* echo '<pre>$listTable = ' htmlspecialchars(print_r($listTable, true)); ?></pre> */ ?> |
| 404 | - <?php | |
| 356 | +<?php | |
| 405 | 357 | } |