templates
1 year ago
SendinblueAccount.php
1 year ago
SendinblueApiClient.php
1 year ago
function.wp_mail.php
8 years ago
http-build-url.php
1 year ago
index.php
8 years ago
mailin.php
3 years ago
push-admin.php
1 year ago
push-amp.php
1 year ago
push-api.php
1 year ago
push-httpclient.php
1 year ago
push-public.php
1 year ago
push-settings.php
1 year ago
push-utils.php
1 year ago
push-woocommerce.php
1 year ago
sendinblue.php
3 years ago
sib-api-manager.php
1 year ago
sib-form-preview.php
2 years ago
sib-sms-code.php
3 years ago
table-forms.php
1 year ago
table-forms.php
294 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Subscribe forms class |
| 4 | */ |
| 5 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 6 | require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
| 7 | } |
| 8 | |
| 9 | class SIB_Forms_List extends WP_List_Table { |
| 10 | |
| 11 | /** Class constructor */ |
| 12 | public function __construct() { |
| 13 | |
| 14 | parent::__construct( |
| 15 | array('singular' => __( 'Form', 'mailin' ), //singular name of the listed records |
| 16 | 'plural' => __( 'Forms', 'mailin' ), //plural name of the listed records |
| 17 | 'ajax' => false) //does this table support ajax? |
| 18 | ); |
| 19 | |
| 20 | add_action( 'admin_head', array( &$this, 'admin_header' ) ); |
| 21 | |
| 22 | } |
| 23 | const PAGES = [ |
| 24 | 'sib_page_form', |
| 25 | 'sib_page_home', |
| 26 | 'sib_page_statistics' |
| 27 | ]; |
| 28 | /** |
| 29 | * Retrieve contacts data from the database |
| 30 | * |
| 31 | * @param int $per_page |
| 32 | * @param int $page_number |
| 33 | * |
| 34 | * @return mixed |
| 35 | */ |
| 36 | public static function getForms( $per_page = 5, $page_number = 1 ) { |
| 37 | |
| 38 | $result = SIB_Forms::getForms(); |
| 39 | $start = ( $page_number - 1 ) * $per_page; |
| 40 | usort( $result, array(__CLASS__, 'usort_reorder' ) ); |
| 41 | $result = array_slice($result, $start, $per_page); |
| 42 | return $result; |
| 43 | } |
| 44 | /** |
| 45 | * Returns the count of records in the database. |
| 46 | * |
| 47 | * @return null|string |
| 48 | */ |
| 49 | public static function record_count() { |
| 50 | $result = SIB_Forms::getForms(); |
| 51 | return count($result); |
| 52 | } |
| 53 | /** Text displayed when no customer data is available */ |
| 54 | public function no_items() { |
| 55 | _e( 'No forms avaliable.', 'mailin' ); |
| 56 | } |
| 57 | /** |
| 58 | * Render a column when no column specific method exist. |
| 59 | * |
| 60 | * @param array $item |
| 61 | * @param string $column_name |
| 62 | * |
| 63 | * @return mixed |
| 64 | */ |
| 65 | public function column_default( $item, $column_name ) { |
| 66 | switch ( $column_name ) { |
| 67 | case 'id': |
| 68 | return '[sibwp_form id='.$item['id'].']'; |
| 69 | case 'title': |
| 70 | case 'attributes': |
| 71 | case 'listName': |
| 72 | case 'date': |
| 73 | return $item[ $column_name ]; |
| 74 | //default: |
| 75 | //return print_r( $item, true ); //Show the whole array for troubleshooting purposes |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Render the bulk edit checkbox |
| 81 | * |
| 82 | * @param array $item |
| 83 | * |
| 84 | * @return string |
| 85 | */ |
| 86 | function column_cb( $item ) { |
| 87 | return sprintf( |
| 88 | '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['id'] |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /** |
| 94 | * Method for form title column |
| 95 | * |
| 96 | * @param array $item an array of DB data |
| 97 | * |
| 98 | * @return string |
| 99 | */ |
| 100 | function column_title( $item ) { |
| 101 | |
| 102 | $delete_nonce = wp_create_nonce( 'sib_delete_form' ); |
| 103 | |
| 104 | $title = '<strong>' . $item['title'] . '</strong>'; |
| 105 | $page = isset($_REQUEST['page']) && in_array(strtolower($_REQUEST['page']), self::PAGES) ? $_REQUEST['page'] : ''; |
| 106 | $actions = array( |
| 107 | 'edit' => sprintf( '<a href="?page=%s&action=%s&id=%s">Edit</a>', $page, 'edit', absint( $item['id'] ) ), |
| 108 | 'duplicate' => sprintf( '<a href="?page=%s&action=%s&id=%s">Duplicate</a>', $page, 'duplicate', absint( $item['id'] ) ), |
| 109 | 'delete' => sprintf( '<a class="sib-form-delete" href="?page=%s&action=%s&id=%s&_wpnonce=%s">Delete</a>', $page, 'delete', absint( $item['id'] ), $delete_nonce ) |
| 110 | ); |
| 111 | |
| 112 | return $title . $this->row_actions( $actions ); |
| 113 | } |
| 114 | |
| 115 | function column_trans( $item ) { |
| 116 | $languages = apply_filters('wpml_active_languages', NULL, array()); |
| 117 | |
| 118 | $results = ''; |
| 119 | if(!empty( $languages )) |
| 120 | { |
| 121 | foreach($languages as $language) |
| 122 | { |
| 123 | $exist = SIB_Forms_Lang::get_form_ID($item['id'], $language['language_code']); |
| 124 | $page = isset($_REQUEST['page']) && in_array(strtolower($_REQUEST['page']), self::PAGES) ? $_REQUEST['page'] : ''; |
| 125 | if($exist == null) |
| 126 | { |
| 127 | $img_src = plugins_url('img/add_translation.png', dirname(__FILE__)); |
| 128 | |
| 129 | $href = sprintf( '<a href="?page=%s&action=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', $page, 'edit', absint( $item['id'] ), sanitize_text_field( $language['language_code'] ) ); |
| 130 | $results .= $href .'<img src="'.$img_src.'" style="margin:2px;"></a>'; |
| 131 | } |
| 132 | else{ |
| 133 | $img_src = plugins_url('img/edit_translation.png', dirname(__FILE__)); |
| 134 | $href = sprintf( '<a href="?page=%s&action=%s&id=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', $page, 'edit', absint( $exist ) , absint( $item['id']), sanitize_text_field( $language['language_code'] ) ); |
| 135 | $results .= $href .'<img src="'.$img_src.'" style="margin:2px;"></a>'; |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | } |
| 140 | return $results; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Associative array of columns |
| 145 | * |
| 146 | * @return array |
| 147 | */ |
| 148 | function get_columns() { |
| 149 | $columns = array( |
| 150 | 'cb' => '<input type="checkbox" />', |
| 151 | 'title' => __( 'Form Name', 'mailin' ), |
| 152 | 'id' => __( 'Shortcode', 'mailin' ), |
| 153 | 'attributes' => __( 'Visible attributes', 'mailin' ), |
| 154 | 'listName' => __( 'Linked List', 'mailin' ), |
| 155 | 'date' => __( 'Last Update', 'mailin' ) |
| 156 | ); |
| 157 | if(function_exists('icl_plugin_action_links')) |
| 158 | { |
| 159 | $languages = apply_filters('wpml_active_languages', NULL, array()); |
| 160 | |
| 161 | $results = ''; |
| 162 | if(!empty( $languages )) |
| 163 | { |
| 164 | foreach($languages as $language) |
| 165 | { |
| 166 | $results .= '<img src="'.$language['country_flag_url'].'" style="margin:2px;">'; |
| 167 | } |
| 168 | } |
| 169 | $columns['trans'] = $results; |
| 170 | } |
| 171 | return $columns; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /** |
| 176 | * Columns to make sortable. |
| 177 | * |
| 178 | * @return array |
| 179 | */ |
| 180 | public function get_sortable_columns() { |
| 181 | $sortable_columns = array( |
| 182 | 'date' => array( 'date', true ), |
| 183 | 'title' => array( 'title', false ), |
| 184 | ); |
| 185 | |
| 186 | return $sortable_columns; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Returns an associative array containing the bulk action |
| 191 | * |
| 192 | * @return array |
| 193 | */ |
| 194 | public function get_bulk_actions() { |
| 195 | $actions = array( |
| 196 | 'bulk-delete' => 'Delete' |
| 197 | ); |
| 198 | |
| 199 | $nonce = wp_create_nonce('mailin_bulk_action_nonce'); |
| 200 | echo '<input type="hidden" name="mailin_bulk_action_nonce" value="' . esc_attr($nonce) . '">'; |
| 201 | |
| 202 | return $actions; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /** |
| 207 | * Handles data query and filter, sorting, and pagination. |
| 208 | */ |
| 209 | public function prepare_items() { |
| 210 | |
| 211 | $this->_column_headers = $this->get_column_info(); |
| 212 | |
| 213 | /** Process bulk action */ |
| 214 | $this->process_bulk_action(); |
| 215 | |
| 216 | $per_page = $this->get_items_per_page( 'forms_per_page', 50 ); |
| 217 | $current_page = $this->get_pagenum(); |
| 218 | $total_items = self::record_count(); |
| 219 | |
| 220 | $this->set_pagination_args( array( |
| 221 | 'total_items' => $total_items, //WE have to calculate the total number of items |
| 222 | 'per_page' => $per_page //WE have to determine how many items to show on a page |
| 223 | ) ); |
| 224 | |
| 225 | $this->items = self::getForms( $per_page, $current_page ); |
| 226 | } |
| 227 | |
| 228 | public function process_bulk_action() { |
| 229 | |
| 230 | //Detect when a bulk action is being triggered... |
| 231 | if ( 'delete' === $this->current_action() ) { |
| 232 | |
| 233 | // In our file that handles the request, verify the nonce. |
| 234 | $nonce = sanitize_text_field( $_REQUEST['_wpnonce'] ); |
| 235 | |
| 236 | if ( ! wp_verify_nonce( $nonce, 'sib_delete_form' ) ) { |
| 237 | die( 'Go get a life script kiddies' ); |
| 238 | } |
| 239 | else { |
| 240 | SIB_Forms::deleteForm( absint( sanitize_text_field($_GET['id']) ) ); |
| 241 | SIB_Forms_Lang::remove_trans( absint( sanitize_text_field($_GET['id']) ) ); |
| 242 | wp_redirect(add_query_arg('page', SIB_Page_Form::PAGE_ID, admin_url('admin.php'))); exit; |
| 243 | } |
| 244 | |
| 245 | } |
| 246 | |
| 247 | // If the delete bulk action is triggered |
| 248 | if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' ) |
| 249 | || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' ) |
| 250 | ) { |
| 251 | $bulk_action_nonce = isset($_REQUEST['mailin_bulk_action_nonce'] ) ? sanitize_text_field( $_REQUEST['mailin_bulk_action_nonce'] ) : ""; |
| 252 | if ( ! wp_verify_nonce( $bulk_action_nonce, 'mailin_bulk_action_nonce' ) ) { |
| 253 | die( 'Go get a life script kiddies' ); |
| 254 | } |
| 255 | $delete_ids = array_map('intval', $_POST['bulk-delete']); |
| 256 | |
| 257 | // loop over the array of record IDs and delete them |
| 258 | foreach ( $delete_ids as $id ) { |
| 259 | if( $id > 0 ) { |
| 260 | SIB_Forms::deleteForm( $id ); |
| 261 | SIB_Forms_Lang::remove_trans( $id ); |
| 262 | } |
| 263 | } |
| 264 | wp_redirect(esc_url(add_query_arg(NULL,NULL))); exit; |
| 265 | |
| 266 | } |
| 267 | } |
| 268 | public function pagination($which){ |
| 269 | echo '<a href="'.add_query_arg(array('page' => 'sib_page_form','action'=>'edit'/*,'id'=>'new'*/), admin_url('admin.php')).'" class="btn btn-success" style="float:right; margin: 2px 1px 8px 15px;" >'.__("Add New Form", "mailin").'</a>'; |
| 270 | parent::pagination($which); |
| 271 | } |
| 272 | |
| 273 | static function usort_reorder( $a, $b ) { |
| 274 | // If no sort, default to title |
| 275 | $orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_text_field($_GET['orderby']) : 'title'; // by title |
| 276 | // If no order, default to asc |
| 277 | $order = ( ! empty($_GET['order'] ) ) ? sanitize_text_field($_GET['order']) : 'ask'; |
| 278 | // Determine sort order |
| 279 | $result = strcmp( $a[$orderby], $b[$orderby] ); |
| 280 | // Send final sort direction to usort |
| 281 | return ( $order === 'ask' ) ? $result : -$result; |
| 282 | } |
| 283 | |
| 284 | function admin_header() { |
| 285 | $page = ( isset($_GET['page'] ) ) ? sanitize_text_field( $_GET['page'] ) : false; |
| 286 | if( 'sib_page_form' != $page ) |
| 287 | return; |
| 288 | |
| 289 | echo '<style type="text/css">'; |
| 290 | echo '.wp-list-table .column-date { width: 150px; }'; |
| 291 | echo '</style>'; |
| 292 | } |
| 293 | } |
| 294 |