PluginProbe
WP-Stateless – Google Cloud Storage / 3.1.1
WP-Stateless – Google Cloud Storage v3.1.1
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / vendor / udx / lib-ud-api-client / lib / classes / class-licenses-table.php

class-licenses-table.php in WP-Stateless – Google Cloud Storage 3.1.1, at vendor/udx/lib-ud-api-client/lib/classes/class-licenses-table.php

199 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Licenses Table
4 *
5 * @namespace UsabilityDynamics
6 *
7 */
8 namespace UsabilityDynamics\UD_API {
9
10 if( !class_exists( 'UsabilityDynamics\UD_API\Licenses_Table' ) ) {
11
12 if ( ! defined( 'ABSPATH' ) ) exit; //** Exit if accessed directly */
13
14 if( ! class_exists( 'WP_List_Table' ) ) {
15 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
16 }
17
18 /**
19 *
20 * @author: peshkov@UD
21 */
22 class Licenses_Table extends \WP_List_Table {
23
24 public $data;
25 public $found_data;
26 public $name;
27 public $domain;
28 public $page;
29 public $per_page = 100;
30 public $activation_email;
31
32 /**
33 * Constructor.
34 * @since 1.0.0
35 */
36 public function __construct ( $args ) {
37 global $status, $page;
38
39 $this->name = !empty( $args[ 'name' ] ) ? $args[ 'name' ] : '';
40 $this->domain = !empty( $args[ 'domain' ] ) ? $args[ 'domain' ] : false;
41 $this->page = !empty( $args[ 'page' ] ) ? $args[ 'page' ] : false;
42 $this->activation_email = isset( $args[ 'activation_email' ] ) && $args[ 'activation_email' ] ? true : false;
43
44 $args = array(
45 'singular' => 'license', //singular name of the listed records
46 'plural' => 'licenses', //plural name of the listed records
47 'ajax' => false //does this table support ajax?
48 );
49
50 $this->data = array();
51
52 //** Make sure this file is loaded, so we have access to plugins_api(), etc. */
53 require_once( ABSPATH . '/wp-admin/includes/plugin-install.php' );
54
55 parent::__construct( $args );
56 }
57
58 /**
59 * Text to display if no items are present.
60 *
61 * @since 1.0.0
62 * @return void
63 */
64 public function no_items () {
65 echo wpautop( sprintf( __( 'No active %s products found.', $this->domain ), $this->name ) );
66 }
67
68 /**
69 * The content of each column.
70 *
71 * @param array $item The current item in the list.
72 * @param string $column_name The key of the current column.
73 * @since 1.0.0
74 * @return string Output for the current column.
75 */
76 public function column_default ( $item, $column_name ) {
77 switch( $column_name ) {
78 case 'product':
79 case 'product_status':
80 case 'product_version':
81 return $item[$column_name];
82 break;
83 }
84 }
85
86 /**
87 * Retrieve an array of sortable columns.
88 * @since 1.0.0
89 * @return array
90 */
91 public function get_sortable_columns () {
92 return array();
93 }
94
95 /**
96 * Retrieve an array of columns for the list table.
97 *
98 * @since 1.0.0
99 * @return array Key => Value pairs.
100 */
101 public function get_columns () {
102 $columns = array(
103 'product_name' => __( 'Product', $this->domain ),
104 'product_version' => __( 'Version', $this->domain ),
105 'product_status' => __( 'Activation Status', $this->domain ),
106 );
107 return $columns;
108 }
109
110 /**
111 * Content for the "product_name" column.
112 *
113 * @param array $item The current item.
114 * @since 1.0.0
115 * @return string The content of this column.
116 */
117 public function column_product_name ( $item ) {
118 return wpautop( '<strong>' . $item['product_name'] . '</strong>' );
119 }
120
121 /**
122 * Content for the "product_version" column.
123 * @param array $item The current item.
124 * @since 1.0.0
125 * @return string The content of this column.
126 */
127 public function column_product_version ( $item ) {
128 return wpautop( $item['product_version'] );
129 }
130
131 /**
132 * Content for the "status" column.
133 *
134 * @param array $item The current item.
135 * @since 1.0.0
136 * @return string The content of this column.
137 */
138 public function column_product_status ( $item ) {
139 $response = '';
140 if ( 'active' == $item['product_status'] ) {
141 $deactivate_url = wp_nonce_url(\UsabilityDynamics\Utility::current_url( array(
142 'action' => 'deactivate-product',
143 'filepath' => urlencode( $item['product_file_path'] ),
144 ) ), 'bulk-licenses' );
145 //$deactivate_url = wp_nonce_url( add_query_arg( 'action', 'deactivate-product', add_query_arg( 'filepath', $item['product_file_path'], add_query_arg( 'page', $this->page, network_admin_url( 'index.php' ) ) ) ), 'bulk-licenses' );
146 $response = '<a href="' . esc_url( $deactivate_url ) . '" onclick="return confirm(\'' . __( 'Are you sure you want to deactivate the license?', $this->domain ) . '\');">' . __( 'Deactivate', $this->domain ) . '</a>' . "\n";
147 } else {
148 $response .= '<ul>' . "\n";
149 $response .= '<li><input name="products[' . esc_attr( $item['product_file_path'] ) . '][license_key]" id="license_key-' . esc_attr( $item['product_file_path'] ) . '" type="text" value="" size="37" aria-required="true" placeholder="' . esc_attr( __( 'Place License Key here', $this->domain ) ) . '" /><li>' . "\n";
150
151 if( !$this->activation_email ) {
152 $response .= '</ul>' . "\n";
153 $response .= '<input name="products[' . esc_attr( $item['product_file_path'] ) . '][activation_email]" type="hidden" value="" />' . "\n";
154 } else {
155 $response .= '<li><input name="products[' . esc_attr( $item['product_file_path'] ) . '][activation_email]" id="activation_email-' . esc_attr( $item['product_file_path'] ) . '" type="text" value="" size="37" aria-required="true" placeholder="' . esc_attr( __( 'Place Activation Email here', $this->domain ) ) . '" /></li>' . "\n";
156 $response .= '</ul>' . "\n";
157 }
158
159 }
160 return $response;
161 }
162
163 /**
164 * Retrieve an array of possible bulk actions.
165 *
166 * @since 1.0.0
167 * @return array
168 */
169 public function get_bulk_actions () {
170 $actions = array();
171 return $actions;
172 }
173
174 /**
175 * Prepare an array of items to be listed.
176 * @since 1.0.0
177 * @return array Prepared items.
178 */
179 public function prepare_items () {
180 $columns = $this->get_columns();
181 $hidden = array();
182 $sortable = $this->get_sortable_columns();
183 $this->_column_headers = array( $columns, $hidden, $sortable );
184 $total_items = count( $this->data );
185 //** only ncessary because we have sample data */
186 $this->found_data = $this->data;
187 $this->set_pagination_args( array(
188 'total_items' => $total_items, //WE have to calculate the total number of items
189 'per_page' => $total_items //WE have to determine how many items to show on a page
190 ) );
191 $this->items = $this->found_data;
192 }
193
194 }
195
196 }
197
198 }
199