-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.php
302 lines (236 loc) · 8.43 KB
/
admin.php
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
/*
Plugin Name: Search Keyword Statistics
Plugin URI: http://www.blogfordeveloper.com/
Description: Keep statistics of keywords being searched on your website.
Version: 2.2
Author: Ramen Dey & Bivash Kanti Pal
Author URI: http://www.blogfordeveloper.com/about-us/
*/
global $wpdb;
define( 'SS_TABLE', $wpdb->prefix . 'search_statistics' );
define('SS_BG_VERSION',22);
/* Handlers for Detect and save search keywords */
add_action( 'wp_loaded', 'ss_keyword_trace' );
function ss_keyword_trace( ) {
require 'ss-keyword-trace.php';
if( strpos($_SERVER['PHP_SELF'], 'wp-admin')==false)
{
if(!empty($_GET['s']) ) {
$keyword = trim($_GET['s']);
save_keyword($keyword,@$_SERVER['HTTP_REFERER']);
}
}
}
/* Admin menu */
add_action( 'admin_menu', 'ss_menu' );
add_action( 'plugins_loaded', 'ss_plugins_update' );
function ss_plugins_update()
{
include plugin_dir_path( __FILE__ ).'update.php';
}
function admin_dashboard() {
require 'ss-admin-dashboard.php';
}
function ss_menu() {
add_menu_page( 'Keyword Statistics', 'Keyword Statistics', 'administrator', 'ss-menu', 'admin_dashboard' );
//add_submenu_page( 'ss-menu', 'Active Post Type', 'Active Post Type', 'administrator','active-post-type', 'active_post_type_func' );
}
function active_post_type_func()
{
$args = array(
'public' => true,
'_builtin' => true
);
$output = 'names'; // names or objects, note names is the default
//$operator = 'and'; // 'and' or 'or'
if(isset($_POST['ss_post']))
{
$arr=serialize($_POST['ss_post']);
update_option('ss_post_types',$arr);
}
$post_types = get_post_types( $args, $output );
echo '<form method="post">';
echo '<div><div style="float:left; width:200px;">Operation</div><div style="float:left; width:200px;"> Post Type</div></div>';
//var_dump($post_types);
foreach ( $post_types as $post_type ) {
if($post_type!='attachment')
echo '<div style="clear:both;"><div style="float:left; width:200px;"><input type="checkbox" name="ss_post[]" value="'.$post_type.'" checked="checked"></div><div style="float:left; width:200px;"> ' . $post_type . '</div></div>';
}
echo '<input type="submit" name="submit" value="submit">';
echo '</form>';
}
// Function that outputs the contents of the dashboard widget
function ss_dashboard_widget_function($post, $callback_args ) {
global $wpdb;
$rows=$wpdb->get_results( "SELECT * FROM " . SS_TABLE . " ORDER BY repeat_count DESC LIMIT 0,10" );
?>
<div>
<h3> Search Keyword Statistics <span style="color: gray;">2.2</span> - Most repeated result</h3>
<div>
<?php
if(isset($error) && $error!='')
{
echo '<span style="color:red;font-size:12px;font-weight:bold;">'.$error.'</span>';
}
?>
</div>
<style type="text/css">
.ss_dasboard_table {
margin:0px;padding:0px;
width:100%;
box-shadow: 10px 10px 5px #888888;
border:1px solid #000000;
-moz-border-radius-bottomleft:4px;
-webkit-border-bottom-left-radius:4px;
border-bottom-left-radius:4px;
-moz-border-radius-bottomright:4px;
-webkit-border-bottom-right-radius:4px;
border-bottom-right-radius:4px;
-moz-border-radius-topright:4px;
-webkit-border-top-right-radius:4px;
border-top-right-radius:4px;
-moz-border-radius-topleft:4px;
-webkit-border-top-left-radius:4px;
border-top-left-radius:4px;
}.ss_dasboard_table table{
border-collapse: collapse;
border-spacing: 0;
width:100%;
height:100%;
margin:0px;padding:0px;
}.ss_dasboard_table tr:last-child td:last-child {
-moz-border-radius-bottomright:4px;
-webkit-border-bottom-right-radius:4px;
border-bottom-right-radius:4px;
}
.ss_dasboard_table table tr:first-child td:first-child {
-moz-border-radius-topleft:4px;
-webkit-border-top-left-radius:4px;
border-top-left-radius:4px;
}
.ss_dasboard_table table tr:first-child td:last-child {
-moz-border-radius-topright:4px;
-webkit-border-top-right-radius:4px;
border-top-right-radius:4px;
}.ss_dasboard_table tr:last-child td:first-child{
-moz-border-radius-bottomleft:4px;
-webkit-border-bottom-left-radius:4px;
border-bottom-left-radius:4px;
}.ss_dasboard_table tr:hover td{
}
.ss_dasboard_table tr:nth-child(odd){ background-color:#b2b2b2; }
.ss_dasboard_table tr:nth-child(even) { background-color:#ffffff; }.ss_dasboard_table td{
vertical-align:middle;
border:1px solid #000000;
border-width:0px 1px 1px 0px;
text-align:left;
padding:7px;
font-size:10px;
font-family:Arial;
font-weight:normal;
color:#000000;
}.ss_dasboard_table tr:last-child td{
border-width:0px 1px 0px 0px;
}.ss_dasboard_table tr td:last-child{
border-width:0px 0px 1px 0px;
}.ss_dasboard_table tr:last-child td:last-child{
border-width:0px 0px 0px 0px;
}
.ss_dasboard_table tr:first-child td{
background:-o-linear-gradient(bottom, #7f7f7f 5%, #191919 100%); background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #7f7f7f), color-stop(1, #191919) );
background:-moz-linear-gradient( center top, #7f7f7f 5%, #191919 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#7f7f7f", endColorstr="#191919"); background: -o-linear-gradient(top,#7f7f7f,191919);
background-color:#7f7f7f;
border:0px solid #000000;
text-align:center;
border-width:0px 0px 1px 1px;
font-size:14px;
font-family:Arial;
font-weight:bold;
color:#ffffff;
}
.ss_dasboard_table tr:first-child:hover td{
background:-o-linear-gradient(bottom, #7f7f7f 5%, #191919 100%); background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #7f7f7f), color-stop(1, #191919) );
background:-moz-linear-gradient( center top, #7f7f7f 5%, #191919 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#7f7f7f", endColorstr="#191919"); background: -o-linear-gradient(top,#7f7f7f,191919);
background-color:#7f7f7f;
}
.ss_dasboard_table tr:first-child td:first-child{
border-width:0px 0px 1px 0px;
}
.ss_dasboard_table tr:first-child td:last-child{
border-width:0px 0px 1px 1px;
}
</style>
<div class="ss_dasboard_table">
<form action="" method="post" name="frmKeyword" >
<table cellpadding="1" cellspacing="1" border="1" class="display" id="example" width="100%">
<tr>
<td>Sl No</td>
<td>keywords</td>
<td>Repeat</td>
<td>No. of Result</td>
</tr>
<?php
for($i=0;$i<count($rows);$i++)
{
if(is_numeric($rows[$i]->user))
{
$user_info =get_userdata($rows[$i]->user);
$user=$user_info->user_login;
}
else
$user='Non-Registered';
?>
<tr class="odd gradeX">
<td><?php echo $i+1; ?></td>
<td><?php echo $rows[$i]->keywords; ?></td>
<td class="center"><?php echo $rows[$i]->repeat_count; ?></td>
<td class="center"><?php echo $rows[$i]->search_count; ?></td>
</tr>
<?php
}
?>
</table>
</form>
</div>
</div>
<?php
}
// Function used in the action hook
function add_dashboard_widgets() {
wp_add_dashboard_widget('dashboard_widget', 'Keyword Statistics', 'ss_dashboard_widget_function');
}
// Register the new dashboard widget with the 'wp_dashboard_setup' action
add_action('wp_dashboard_setup', 'add_dashboard_widgets' );
/* Uninstall and Activation handlers */
register_activation_hook( __FILE__, 'ss_activate' );
register_deactivation_hook( __FILE__, 'ss_deactivate' );
register_uninstall_hook( __FILE__, 'ss_deactivate_uninstall' );
function ss_activate( ) {
global $wpdb;
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . SS_TABLE . "'" ) != SS_TABLE ) {
$query = "CREATE TABLE IF NOT EXISTS " . SS_TABLE . "(
id INT PRIMARY KEY AUTO_INCREMENT,
keywords VARCHAR(255) NOT NULL,
query_date varchar(12) NOT NULL,
repeat_count INT,
source VARCHAR(50),
user varchar(10),
agent varchar(150)
)";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$wpdb->query( $query );
}
}
function ss_deactivate_uninstall( ) {
global $wpdb;
$query = "DROP TABLE IF EXISTS " . SS_TABLE;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$wpdb->query( $query );
}
function ss_deactivate( ) {
delete_option( 'SS_BG_VERSION' );
}
?>