utilities
3 days ago
ehssl-config.php
1 year ago
ehssl-cronjob.php
1 year ago
ehssl-custom-post-types.php
1 year ago
ehssl-debug-logger.php
1 year ago
ehssl-email-handler.php
1 year ago
ehssl-init-time-tasks.php
3 days ago
ehssl-installation.php
3 days ago
ehssl-non-https-resources-scan-result-table.php
3 days ago
ehssl-non-https-resources-scan-update.php
3 days ago
ehssl-rules-helper.php
3 days ago
ehssl-ssl-certificate.php
1 year ago
index.php
1 year ago
ehssl-non-https-resources-scan-result-table.php
144 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 4 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 5 | } |
| 6 | |
| 7 | class EHSSL_Static_Resources_Scan_Result_Table extends WP_List_Table { |
| 8 | |
| 9 | private $total_items_count; |
| 10 | |
| 11 | public function __construct() { |
| 12 | parent::__construct( |
| 13 | array( |
| 14 | 'singular' => 'result', |
| 15 | 'plural' => 'results', |
| 16 | 'ajax' => true, |
| 17 | ) |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | public function get_columns() { |
| 22 | return array( |
| 23 | 'cb' => '<input type="checkbox" />', |
| 24 | 'id' => 'ID', |
| 25 | 'context' => 'Context/Location', |
| 26 | 'urls' => 'Non HTTPS URLs', |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | public function prepare_items() { |
| 31 | $per_page = 10; |
| 32 | |
| 33 | $current_page = $this->get_pagenum(); |
| 34 | |
| 35 | $offset = ( $current_page - 1 ) * $per_page; |
| 36 | |
| 37 | $total_items = EHSSL_Non_HTTPS_Resources_Scan_Update::get_scan_results_count(true); |
| 38 | |
| 39 | $this->total_items_count = $total_items; |
| 40 | |
| 41 | $this->items = EHSSL_Non_HTTPS_Resources_Scan_Update::get_scan_results_chunk( $offset, $per_page, array(), true); |
| 42 | |
| 43 | $this->_column_headers = array( |
| 44 | $this->get_columns(), |
| 45 | array(), |
| 46 | array(), |
| 47 | ); |
| 48 | |
| 49 | $this->set_pagination_args( |
| 50 | array( |
| 51 | 'total_items' => $total_items, |
| 52 | 'per_page' => $per_page, |
| 53 | 'total_pages' => ceil( $total_items / $per_page ), |
| 54 | ) |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | public function column_default( $item, $column_name ) { |
| 59 | global $wpdb; |
| 60 | |
| 61 | switch ( $column_name ) { |
| 62 | case 'id': |
| 63 | return $item['id']; |
| 64 | |
| 65 | case 'urls': |
| 66 | $output = ''; |
| 67 | $urls_map = array_merge( maybe_unserialize($item['cols_map']), maybe_unserialize($item['meta_map'])); |
| 68 | if (!empty($urls_map)) { |
| 69 | $this->get_urls_output( $urls_map, $output); |
| 70 | } |
| 71 | |
| 72 | return $output; |
| 73 | |
| 74 | case 'context': |
| 75 | $output = 'Unknown'; |
| 76 | if ($item['source_table'] == $wpdb->posts) { |
| 77 | $output = get_the_title( $item['source_uid'] ) . " (Post ID: ".$item['source_uid'].")"; |
| 78 | } elseif ($item['source_table'] == $wpdb->options) { |
| 79 | $output = $item['source_uid'] . " (WP Option)"; |
| 80 | } else { |
| 81 | $output = __('Unknown', 'http-redirection'); |
| 82 | } |
| 83 | |
| 84 | return $output; |
| 85 | } |
| 86 | |
| 87 | return ''; |
| 88 | } |
| 89 | |
| 90 | public function column_cb( $item ) { |
| 91 | return sprintf( |
| 92 | '<input type="checkbox" name="ehssl_non_https_resources_scan_ids[]" value="%d" />', |
| 93 | $item['id'] |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | public function get_bulk_actions() { |
| 98 | return array( |
| 99 | 'update_to_https' => __( 'Update to HTTPS Version', 'http-redirection' ), |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | public function get_urls_output($urls, &$output ) { |
| 104 | foreach ($urls as $url) { |
| 105 | if(is_array($url)) { |
| 106 | $this->get_urls_output($url, $output); |
| 107 | } else { |
| 108 | $output .= '<div style="margin-bottom: 4px"><code>' . esc_url_raw( $url ) . '</code></div>'; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | protected function extra_tablenav( $which ) { |
| 114 | if ( 'top' !== $which ) { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | if (empty($this->total_items_count)){ |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | ?> |
| 123 | <div class="alignleft actions"> |
| 124 | <button |
| 125 | type="button" |
| 126 | class="button" |
| 127 | id="ehssl_update_all_found_http_urls" |
| 128 | > |
| 129 | <?php _e('Update All URLs', 'https-redirection'); ?> |
| 130 | </button> |
| 131 | |
| 132 | </div> |
| 133 | <style> |
| 134 | .column-urls { |
| 135 | width: 50%; |
| 136 | } |
| 137 | |
| 138 | .column-id { |
| 139 | width: 10%; |
| 140 | } |
| 141 | </style> |
| 142 | <?php |
| 143 | } |
| 144 | } |