1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
3
|
|
|
|
4
|
|
|
//Main plugin object to define the plugin |
5
|
|
|
if ( ! class_exists( 'CGSS_BUILD' ) ) { |
6
|
|
|
|
7
|
|
|
final class CGSS_BUILD { |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
|
11
|
|
|
public function installation() { |
12
|
|
|
|
13
|
|
|
if (class_exists('CGSS_INSTALL')) { |
14
|
|
|
|
15
|
|
|
$install = new CGSS_INSTALL(); |
16
|
|
|
$install->textDomin = 'cgss'; |
17
|
|
|
$install->phpVerAllowed = '5.4'; |
18
|
|
|
$install->pluginPageLinks = array( |
19
|
|
|
array( |
20
|
|
|
'slug' => home_url().'/wp-admin/admin.php?page=seo-scan', |
|
|
|
|
21
|
|
|
'label' => __( 'Dashboard', 'cgss' ) |
|
|
|
|
22
|
|
|
), |
23
|
|
|
); |
24
|
|
|
$install->do(); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
public function db_install() { |
30
|
|
|
|
31
|
|
|
if ( class_exists( 'CGSS_DB' ) ) { |
32
|
|
|
$db = new CGSS_DB(); |
33
|
|
|
$db->table = 'cgss_insight'; |
34
|
|
|
$db->sql = "ID mediumint(9) NOT NULL AUTO_INCREMENT, |
35
|
|
|
item varchar(256) NOT NULL, |
36
|
|
|
remark varchar(512) NOT NULL, |
37
|
|
|
UNIQUE KEY ID (ID)"; |
38
|
|
|
$db->build(); |
39
|
|
|
|
40
|
|
|
$insert_data = $this->insert_prelim_data(); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public function db_uninstall() { |
46
|
|
|
|
47
|
|
|
$tableName = 'cgss_insight'; |
48
|
|
|
|
49
|
|
|
global $wpdb; |
50
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$tableName" ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function insert_prelim_data() { |
55
|
|
|
|
56
|
|
|
global $wpdb; |
57
|
|
|
|
58
|
|
|
$result = $wpdb->get_results("SELECT * from {$wpdb->prefix}cgss_insight"); |
59
|
|
|
if(count($result) == 0) { |
60
|
|
|
|
61
|
|
|
$init_insight = array( |
62
|
|
|
__('Score','cgss'), |
|
|
|
|
63
|
|
|
__('Snippet','cgss'), |
64
|
|
|
__('Text','cgss'), |
65
|
|
|
__('Links','cgss'), |
66
|
|
|
__('Keywords','cgss'), |
67
|
|
|
__('Images','cgss'), |
68
|
|
|
__('Responsive','cgss'), |
69
|
|
|
__('Speed','cgss'), |
70
|
|
|
__('Social','cgss') |
71
|
|
|
); |
72
|
|
|
$no_data = __( 'No scan reports are available yet', 'cgss' ); |
73
|
|
|
foreach ($init_insight as $key => $value) { |
74
|
|
|
$sql = $wpdb->prepare( |
75
|
|
|
"INSERT INTO {$wpdb->prefix}cgss_insight ( ID, item, remark ) VALUES ( %d, %s, %s )", ($key+1), $value, $no_data |
76
|
|
|
); |
77
|
|
|
$query = $wpdb->query($sql); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
//Include scripts |
84
|
|
|
public function scripts() { |
85
|
|
|
|
86
|
|
|
if ( class_exists( 'CGSS_SCRIPT' ) ) new CGSS_SCRIPT(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
|
91
|
|
|
//Include settings pages |
92
|
|
|
public function settings() { |
93
|
|
|
|
94
|
|
|
if ( class_exists( 'CGSS_SETTINGS' ) ) new CGSS_SETTINGS(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
|
99
|
|
|
// Add custom insight action |
100
|
|
|
public function insight() { |
101
|
|
|
|
102
|
|
|
if ( class_exists( 'CGSS_INSIGHT' ) ) new CGSS_INSIGHT(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
// Add custom insight action |
108
|
|
|
public function scan() { |
109
|
|
|
|
110
|
|
|
if ( class_exists( 'CGSS_SCAN' ) ) new CGSS_SCAN(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
|
115
|
|
|
//Add files for crawling as external resource |
116
|
|
|
public function vendor() { |
117
|
|
|
|
118
|
|
|
require_once ('vendor/lib/tags.php'); |
119
|
|
|
require_once ('vendor/lib/text.php'); |
120
|
|
|
require_once ('vendor/lib/keywords.php'); |
121
|
|
|
require_once ('vendor/lib/social.php'); |
122
|
|
|
require_once ('vendor/lib/server.php'); |
123
|
|
|
require_once ('vendor/lib/design.php'); |
124
|
|
|
require_once ('vendor/lib/score.php'); |
125
|
|
|
require_once ('vendor/crawl.php'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
//Add functionality files |
131
|
|
|
public function functionality() { |
132
|
|
|
|
133
|
|
|
require_once ('src/db.php'); |
134
|
|
|
require_once ('src/install.php'); |
135
|
|
|
require_once ('src/settings.php'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
|
140
|
|
|
//Call the dependency files |
141
|
|
|
public function helpers() { |
142
|
|
|
|
143
|
|
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
144
|
|
|
require_once( ABSPATH . 'wp-admin/includes/screen.php' ); |
|
|
|
|
145
|
|
|
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
require_once ('lib/table.php'); |
149
|
|
|
require_once ('lib/overview-table.php'); |
150
|
|
|
require_once ('lib/script.php'); |
151
|
|
|
|
152
|
|
|
require_once ('lib/action/scan.php'); |
153
|
|
|
require_once ('lib/action/insight.php'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function __construct() { |
159
|
|
|
|
160
|
|
|
$this->vendor(); |
161
|
|
|
$this->helpers(); |
162
|
|
|
$this->functionality(); |
163
|
|
|
|
164
|
|
|
register_activation_hook( CGSS_FILE, array( $this, 'db_install' ) ); |
|
|
|
|
165
|
|
|
register_uninstall_hook( CGSS_FILE, array( 'CGSS_BUILD', 'db_uninstall' ) ); //$this won't work here. |
|
|
|
|
166
|
|
|
|
167
|
|
|
add_action('init', array($this, 'installation')); |
|
|
|
|
168
|
|
|
|
169
|
|
|
$this->scripts(); |
170
|
|
|
|
171
|
|
|
$this->settings(); |
172
|
|
|
|
173
|
|
|
// Add custom actions, defined in settings |
174
|
|
|
add_action( 'cgss_scan', array( $this, 'scan' ) ); |
175
|
|
|
add_action( 'cgss_fetch_insight', array( $this, 'insight' ) ); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} ?> |
|
|
|
|