1414
1515declare (strict_types=1 );
1616
17+ if ( ! defined ( 'ABSPATH ' ) ) {
18+ exit ;
19+ }
20+
1721/**
1822 * The core plugin class.
1923 *
6367 </th>
6468 <td>
6569 <?php
66- $ types = array (
70+ $ google_ss2db_types = array (
6771 'json ' => 'json_encode ' ,
6872 'json-unescp ' => 'json_encode (JSON_UNESCAPED_UNICODE) ' ,
6973 );
7074 ?>
7175 <select id="google_ss2db_dataformat" name="google_ss2db_dataformat" style="font-size: 11px; width: 330px;">
72- <?php foreach ( $ types as $ key => $ type ) : ?>
73- <?php $ selected = ( get_option ( 'google_ss2db_dataformat ' ) === $ key ) ? 'selected ' : '' ; ?>
74- <option value="<?php echo esc_attr ( $ key ); ?> " <?php echo esc_attr ( $ selected ); ?> ><?php echo esc_html ( $ type ); ?> </option>
76+ <?php foreach ( $ google_ss2db_types as $ google_ss2db_key => $ type ) : ?>
77+ <?php $ google_ss2db_selected = ( get_option ( 'google_ss2db_dataformat ' ) === $ google_ss2db_key ) ? 'selected ' : '' ; ?>
78+ <option value="<?php echo esc_attr ( $ google_ss2db_key ); ?> " <?php echo esc_attr ( $ google_ss2db_selected ); ?> ><?php echo esc_html ( $ type ); ?> </option>
7579 <?php endforeach ; ?>
7680 </select>
7781 </td>
157161 <p><?php echo esc_html__ ( 'This process may takes a few minutes. ' , 'google-spreadsheet-to-db ' ); ?> </p>
158162 <?php wp_nonce_field ( 'google_ss2db ' , 'nonce ' ); ?>
159163 <?php
160- $ text = esc_html__ ( 'Import from Google Spreadsheet ' , 'google-spreadsheet-to-db ' );
161- submit_button ( $ text , 'primary ' , 'save-spreadsheet ' , false );
164+ $ google_ss2db_text = esc_html__ ( 'Import from Google Spreadsheet ' , 'google-spreadsheet-to-db ' );
165+ submit_button ( $ google_ss2db_text , 'primary ' , 'save-spreadsheet ' , false );
162166 ?>
163167 </form>
164168 </section>
165169 <?php
166170 global $ wpdb ;
167- $ table = GOOGLE_SS2DB_TABLE_NAME ;
171+ $ google_ss2db_table = GOOGLE_SS2DB_TABLE_NAME ;
168172
169173 // Get sort parameters.
170- $ orderby = filter_input ( INPUT_GET , 'orderby ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
171- $ order = filter_input ( INPUT_GET , 'order ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
174+ $ google_ss2db_orderby = filter_input ( INPUT_GET , 'orderby ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
175+ $ google_ss2db_order = filter_input ( INPUT_GET , 'order ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
172176
173177 // Default sort settings.
174- $ default_orderby = 'date ' ;
175- $ default_order = 'DESC ' ;
178+ $ google_ss2db_default_orderby = 'date ' ;
179+ $ google_ss2db_default_order = 'DESC ' ;
176180
177181 // Allowed sort columns.
178- $ allowed_orderby = array (
182+ $ google_ss2db_allowed_orderby = array (
179183 'id ' => 'id ' ,
180184 'worksheet_id ' => 'worksheet_id ' ,
181185 'worksheet_name ' => 'worksheet_name ' ,
185189 );
186190
187191 // Sort column validation.
188- $ order = $ order ?? $ default_order ;
189- $ orderby = isset ( $ allowed_orderby [ $ orderby ] ) ? $ orderby : $ default_orderby ;
190- $ order = in_array ( strtoupper ( $ order ), array ( 'ASC ' , 'DESC ' ), true ) ? strtoupper ( $ order ) : $ default_order ;
192+ $ google_ss2db_order = $ google_ss2db_order ?? $ google_ss2db_default_order ;
193+ $ google_ss2db_orderby = isset ( $ google_ss2db_allowed_orderby [ $ google_ss2db_orderby ] ) ? $ google_ss2db_orderby : $ google_ss2db_default_orderby ;
194+ $ google_ss2db_order = in_array ( strtoupper ( $ google_ss2db_order ), array ( 'ASC ' , 'DESC ' ), true ) ? strtoupper ( $ google_ss2db_order ) : $ google_ss2db_default_order ;
191195
192- $ paged = filter_input ( INPUT_GET , 'paged ' , FILTER_VALIDATE_INT );
193- $ nonce = filter_input ( INPUT_GET , 'nonce ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
196+ $ google_ss2db_paged = filter_input ( INPUT_GET , 'paged ' , FILTER_VALIDATE_INT );
197+ $ google_ss2db_nonce = filter_input ( INPUT_GET , 'nonce ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
194198
195199 // Verify pagination nonce.
196- if ( $ paged && ! wp_verify_nonce ( $ nonce , 'google_ss2db_pagination ' ) ) {
197- $ paged = 1 ;
200+ if ( $ google_ss2db_paged && ! wp_verify_nonce ( $ google_ss2db_nonce , 'google_ss2db_pagination ' ) ) {
201+ $ google_ss2db_paged = 1 ;
198202 }
199203
200- $ paged = $ paged ? $ paged : 1 ;
201- $ limit = 24 ;
202- $ offset = ( $ paged - 1 ) * $ limit ;
204+ $ google_ss2db_paged = $ google_ss2db_paged ? $ google_ss2db_paged : 1 ;
205+ $ google_ss2db_limit = 24 ;
206+ $ google_ss2db_offset = ( $ google_ss2db_paged - 1 ) * $ google_ss2db_limit ;
203207
204208 // SQL with sorting.
205- $ countsql = "SELECT * FROM {$ table } ORDER BY {$ orderby } {$ order }" ;
206- $ allrows = count ( $ wpdb ->get_results ( $ countsql ) ); // phpcs:ignore
207- $ max_num_pages = ceil ( $ allrows / $ limit );
209+ $ google_ss2db_countsql = "SELECT * FROM {$ google_ss2db_table } ORDER BY {$ google_ss2db_orderby } {$ google_ss2db_order }" ;
210+ $ google_ss2db_allrows = count ( $ wpdb ->get_results ( $ google_ss2db_countsql ) ); // phpcs:ignore
211+ $ google_ss2db_max_num_pages = ceil ( $ google_ss2db_allrows / $ google_ss2db_limit );
208212
209- $ sql = "SELECT * FROM {$ table } ORDER BY {$ orderby } {$ order } LIMIT %d OFFSET %d " ;
210- $ prepared = $ wpdb ->prepare (
211- $ sql , // phpcs:ignore
212- $ limit ,
213- $ offset
213+ $ google_ss2db_sql = "SELECT * FROM {$ google_ss2db_table } ORDER BY {$ google_ss2db_orderby } {$ google_ss2db_order } LIMIT %d OFFSET %d " ;
214+ $ google_ss2db_prepared = $ wpdb ->prepare (
215+ $ google_ss2db_sql , // phpcs:ignore
216+ $ google_ss2db_limit ,
217+ $ google_ss2db_offset
214218 );
215219
216- $ myrows = $ wpdb ->get_results ( $ prepared ); // phpcs:ignore
217- $ count = count ( $ myrows );
220+ $ google_ss2db_myrows = $ wpdb ->get_results ( $ google_ss2db_prepared ); // phpcs:ignore
221+ $ google_ss2db_count = count ( $ google_ss2db_myrows );
218222
219223 /**
220224 * Generate sort URLs for table columns.
221225 *
222226 * @param string $column The column to generate sort URL for.
223227 * @return string The generated sort URL.
224228 */
225- function get_sort_url ( string $ column ): string {
229+ function google_ss2db_get_sort_url ( string $ column ): string {
226230 $ current_page = filter_input ( INPUT_GET , 'page ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
227231 $ current_orderby = filter_input ( INPUT_GET , 'orderby ' , FILTER_SANITIZE_FULL_SPECIAL_CHARS );
228232 $ current_orderby = $ current_orderby ? $ current_orderby : 'date ' ;
@@ -241,45 +245,45 @@ function get_sort_url( string $column ): string {
241245 return esc_url ( add_query_arg ( $ url_params ) );
242246 }
243247
244- if ( 0 < $ count ) :
248+ if ( 0 < $ google_ss2db_count ) :
245249 ?>
246250 <section id="list">
247251 <hr />
248252 <table class="wp-list-table widefat fixed striped">
249253 <thead>
250254 <tr>
251- <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'id ' === $ orderby ? 'sorted ' . strtolower ( $ order ) : '' ); ?> ">
252- <a href="<?php echo esc_url ( get_sort_url ( 'id ' ) ); ?> ">
255+ <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'id ' === $ google_ss2db_orderby ? 'sorted ' . strtolower ( $ google_ss2db_order ) : '' ); ?> ">
256+ <a href="<?php echo esc_url ( google_ss2db_get_sort_url ( 'id ' ) ); ?> ">
253257 <span>ID</span>
254258 <span class="sorting-indicator"></span>
255259 </a>
256260 </th>
257- <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'worksheet_id ' === $ orderby ? 'sorted ' . strtolower ( $ order ) : '' ); ?> ">
258- <a href="<?php echo esc_url ( get_sort_url ( 'worksheet_id ' ) ); ?> ">
261+ <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'worksheet_id ' === $ google_ss2db_orderby ? 'sorted ' . strtolower ( $ google_ss2db_order ) : '' ); ?> ">
262+ <a href="<?php echo esc_url ( google_ss2db_get_sort_url ( 'worksheet_id ' ) ); ?> ">
259263 <span>Worksheet ID</span>
260264 <span class="sorting-indicator"></span>
261265 </a>
262266 </th>
263- <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'worksheet_name ' === $ orderby ? 'sorted ' . strtolower ( $ order ) : '' ); ?> ">
264- <a href="<?php echo esc_url ( get_sort_url ( 'worksheet_name ' ) ); ?> ">
267+ <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'worksheet_name ' === $ google_ss2db_orderby ? 'sorted ' . strtolower ( $ google_ss2db_order ) : '' ); ?> ">
268+ <a href="<?php echo esc_url ( google_ss2db_get_sort_url ( 'worksheet_name ' ) ); ?> ">
265269 <span>Worksheet Name</span>
266270 <span class="sorting-indicator"></span>
267271 </a>
268272 </th>
269- <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'sheet_name ' === $ orderby ? 'sorted ' . strtolower ( $ order ) : '' ); ?> ">
270- <a href="<?php echo esc_url ( get_sort_url ( 'sheet_name ' ) ); ?> ">
273+ <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'sheet_name ' === $ google_ss2db_orderby ? 'sorted ' . strtolower ( $ google_ss2db_order ) : '' ); ?> ">
274+ <a href="<?php echo esc_url ( google_ss2db_get_sort_url ( 'sheet_name ' ) ); ?> ">
271275 <span>Sheet Name</span>
272276 <span class="sorting-indicator"></span>
273277 </a>
274278 </th>
275- <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'title ' === $ orderby ? 'sorted ' . strtolower ( $ order ) : '' ); ?> ">
276- <a href="<?php echo esc_url ( get_sort_url ( 'title ' ) ); ?> ">
279+ <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'title ' === $ google_ss2db_orderby ? 'sorted ' . strtolower ( $ google_ss2db_order ) : '' ); ?> ">
280+ <a href="<?php echo esc_url ( google_ss2db_get_sort_url ( 'title ' ) ); ?> ">
277281 <span>Title</span>
278282 <span class="sorting-indicator"></span>
279283 </a>
280284 </th>
281- <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'date ' === $ orderby ? 'sorted ' . strtolower ( $ order ) : '' ); ?> ">
282- <a href="<?php echo esc_url ( get_sort_url ( 'date ' ) ); ?> ">
285+ <th scope="col" class="manage-column sortable <?php echo esc_attr ( 'date ' === $ google_ss2db_orderby ? 'sorted ' . strtolower ( $ google_ss2db_order ) : '' ); ?> ">
286+ <a href="<?php echo esc_url ( google_ss2db_get_sort_url ( 'date ' ) ); ?> ">
283287 <span>Date</span>
284288 <span class="sorting-indicator"></span>
285289 </a>
@@ -288,31 +292,31 @@ function get_sort_url( string $column ): string {
288292 </tr>
289293 </thead>
290294 <tbody>
291- <?php foreach ( $ myrows as $ row ) : ?>
292- <tr data-id="<?php echo esc_attr ( $ row ->id ); ?> ">
293- <td><?php echo esc_html ( $ row ->id ); ?> </td>
294- <td><?php echo esc_html ( google_ss2db_truncate_middle ( $ row ->worksheet_id ?? '(no ID) ' ) ); ?> </td>
295- <td><?php echo esc_html ( $ row ->worksheet_name ); ?> </td>
296- <td><?php echo esc_html ( $ row ->sheet_name ); ?> </td>
297- <td style="color: <?php echo $ row ->title ? 'inherit ' : '#aaa ' ; ?> ">
298- <?php echo esc_html ( $ row ->title ? $ row ->title : '(no title) ' ); ?>
295+ <?php foreach ( $ google_ss2db_myrows as $ google_ss2db_row ) : ?>
296+ <tr data-id="<?php echo esc_attr ( $ google_ss2db_row ->id ); ?> ">
297+ <td><?php echo esc_html ( $ google_ss2db_row ->id ); ?> </td>
298+ <td><?php echo esc_html ( google_ss2db_truncate_middle ( $ google_ss2db_row ->worksheet_id ?? '(no ID) ' ) ); ?> </td>
299+ <td><?php echo esc_html ( $ google_ss2db_row ->worksheet_name ); ?> </td>
300+ <td><?php echo esc_html ( $ google_ss2db_row ->sheet_name ); ?> </td>
301+ <td style="color: <?php echo $ google_ss2db_row ->title ? 'inherit ' : '#aaa ' ; ?> ">
302+ <?php echo esc_html ( $ google_ss2db_row ->title ? $ google_ss2db_row ->title : '(no title) ' ); ?>
299303 </td>
300304 <td>
301305 <?php
302- $ date = new DateTime ( $ row ->date );
303- $ date_format = is_string ( get_option ( 'date_format ' ) ) ? get_option ( 'date_format ' ) : 'Y-m-d ' ;
304- $ time_format = is_string ( get_option ( 'time_format ' ) ) ? get_option ( 'time_format ' ) : 'H:i:s ' ;
305- echo esc_html ( date_i18n ( $ date_format . ' ' . $ time_format , $ date ->getTimestamp () ) );
306+ $ google_ss2db_date = new DateTime ( $ google_ss2db_row ->date );
307+ $ google_ss2db_date_format = is_string ( get_option ( 'date_format ' ) ) ? get_option ( 'date_format ' ) : 'Y-m-d ' ;
308+ $ google_ss2db_time_format = is_string ( get_option ( 'time_format ' ) ) ? get_option ( 'time_format ' ) : 'H:i:s ' ;
309+ echo esc_html ( date_i18n ( $ google_ss2db_date_format . ' ' . $ google_ss2db_time_format , $ google_ss2db_date ->getTimestamp () ) );
306310 ?>
307311 </td>
308312 <td>
309- <button class="button view-details" data-id="<?php echo esc_attr ( $ row ->id ); ?> ">
313+ <button class="button view-details" data-id="<?php echo esc_attr ( $ google_ss2db_row ->id ); ?> ">
310314 <?php echo esc_html__ ( 'Details ' , 'google-spreadsheet-to-db ' ); ?>
311315 </button>
312- <button class="button view-raw-data" data-id="<?php echo esc_attr ( $ row ->id ); ?> ">
316+ <button class="button view-raw-data" data-id="<?php echo esc_attr ( $ google_ss2db_row ->id ); ?> ">
313317 <?php echo esc_html__ ( 'Raw Data ' , 'google-spreadsheet-to-db ' ); ?>
314318 </button>
315- <button class="button delete-entry" data-id="<?php echo esc_attr ( $ row ->id ); ?> ">
319+ <button class="button delete-entry" data-id="<?php echo esc_attr ( $ google_ss2db_row ->id ); ?> ">
316320 <?php echo esc_html__ ( 'Delete ' , 'google-spreadsheet-to-db ' ); ?>
317321 </button>
318322 </td>
@@ -322,13 +326,13 @@ function get_sort_url( string $column ): string {
322326 </table>
323327
324328 <?php
325- $ pagination_nonce = esc_attr ( wp_create_nonce ( 'google_ss2db_pagination ' ) );
329+ $ google_ss2db_pagination_nonce = esc_attr ( wp_create_nonce ( 'google_ss2db_pagination ' ) );
326330 if ( function_exists ( 'google_ss2db_options_pagination ' ) ) {
327331 google_ss2db_options_pagination (
328- $ paged ,
329- (int ) $ max_num_pages ,
332+ $ google_ss2db_paged ,
333+ (int ) $ google_ss2db_max_num_pages ,
330334 2 ,
331- $ pagination_nonce
335+ $ google_ss2db_pagination_nonce
332336 );
333337 }
334338 ?>
0 commit comments