-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow-data-table.php
More file actions
135 lines (121 loc) · 3.96 KB
/
Copy pathshow-data-table.php
File metadata and controls
135 lines (121 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* Plugin Name: Show Data Table
* Plugin URI: https://wordpress.org
* Description: Simple show data table plugin.
* Version: 1.0.0
* Author: Nguyen Thanh Luan
* Author URI: https://thanhluan.tk
* license: GPLv2 or Later
* Text Domain: show_data_table
*/
if(!function_exists('add_action')) {
exit;
}
require_once(plugin_dir_path(__FILE__) . './config.php');
require_once(plugin_dir_path(__FILE__) . './models/Crawler.php');
require_once(plugin_dir_path(__FILE__) . './includes/class.show-data-table.php');
define('SHOW_TABLE_VERSION', '1.0.0');
define('SHOW_TABLE_MINIMUM_WP_VERSION', '5.2.2');
//Class Crawler
new Crawler();
//activation
function showdata_table_activation() {
if ( ! wp_next_scheduled( 'example_event' ) ) {
wp_schedule_event( time(), 'one_minute', 'example_event' );
}
}
register_activation_hook(__FILE__,'showdata_table_activation');
// deactivation
function showdata_table_deactivation() {
global $wpdb;
$table_4d = $wpdb->prefix . "4d";
$table_schedule_4d = $wpdb->prefix . "schedule_4d";
$table_toto = $wpdb->prefix . "toto";
$table_schedule_toto = $wpdb->prefix . "schedule_toto";
//delete table
$wpdb->get_results("DROP table IF Exists $table_4d");
$wpdb->get_results("DROP table IF Exists $table_schedule_4d");
$wpdb->get_results("DROP table IF Exists $table_toto");
$wpdb->get_results("DROP table IF Exists $table_schedule_toto");
}
register_deactivation_hook( __FILE__, 'showdata_table_deactivation');
//uninstall
function showdata_table_uninstall()
{
wp_clear_scheduled_hook('example_event');
global $wpdb;
$table_4d = $wpdb->prefix . "4d";
$table_schedule_4d = $wpdb->prefix . "schedule_4d";
$table_toto = $wpdb->prefix . "toto";
$table_schedule_toto = $wpdb->prefix . "schedule_toto";
//delete table
$wpdb->get_results("DROP table IF Exists $table_4d");
$wpdb->get_results("DROP table IF Exists $table_schedule_4d");
$wpdb->get_results("DROP table IF Exists $table_toto");
$wpdb->get_results("DROP table IF Exists $table_schedule_toto");
}
register_uninstall_hook(__FILE__, 'showdata_table_uninstall');
//add menu plugin
function showdata_table_menu() {
add_options_page( 'Welcome plugin crawl html', 'Show Data Table', 'manage_options', 'my-unique-identifier', 'showdata_plugin_options' );
}
add_action( 'admin_menu', 'showdata_table_menu' );
function showdata_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
require_once(plugin_dir_path(__FILE__).'views/view-index.php');
}
//list option 4d
function list_option_4d()
{
global $wpdb;
$table_4d = $wpdb->prefix . "4d";
$result = $wpdb->get_results("SELECT date FROM $table_4d GROUP BY date ORDER BY date ASC");
return $result;
}
//list option toto
function list_option_toto()
{
global $wpdb;
$table_toto = $wpdb->prefix . "toto";
$result = $wpdb->get_results("SELECT date FROM $table_toto GROUP BY date ORDER BY date ASC");
return $result;
}
//view 4d
function view_4d($date)
{
global $wpdb;
$table_4d = $wpdb->prefix . "4d";
$date_default = date('Y:m:d');
$date = $date ? $date : $date_default;
$result = $wpdb->get_results("SELECT * FROM $table_4d WHERE DATE(date) = '". $date ."' ORDER BY prizes ASC , id ASC LIMIT 23");
return $result;
}
//view toto
function view_toto($date)
{
global $wpdb;
$table_toto = $wpdb->prefix . "toto";
$date_default = date('Y:m:d');
$date = $date ? $date : $date_default;
$result = $wpdb->get_results("SELECT * FROM $table_toto WHERE DATE(date) = '". $date ."' ORDER BY toto_name ASC , id ASC LIMIT 7");
return $result;
}
//shortcode 4d
function shortcode_4d(){
ob_start();
require_once( plugin_dir_path(__FILE__) . 'views/view-4d.php');
$content = ob_get_clean();
return $content;
}
add_shortcode( 'show-table-4d', 'shortcode_4d' );
//shortcode toto
function shortcode_toto(){
ob_start();
require_once( plugin_dir_path(__FILE__) . 'views/view-toto.php');
$content = ob_get_clean();
return $content;
}
add_shortcode('show-table-toto', 'shortcode_toto');