-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-cli.php
138 lines (113 loc) · 3.09 KB
/
wp-cli.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
<?php
// Popular WP-CLI commands
// Docs: https://github.com/wp-cli/wp-cli/wiki/Commands-Cookbook
class Popular_Command extends WP_CLI_Command {
function __construct() {
// Replicate what happens in plugin.php
$this->factory = new cftp_analytics_factory();
$this->model = new cftp_analytics_option_model();
$analytics = $this->factory->googleAnalyticsSource();
$this->model->addSource( $analytics );
$twitter = $this->factory->twitterSharesSource();
$this->model->addSource( $twitter );
//$fblikes = $this->factory->facebookLikesSource();
//$this->model->addSource( $fblikes );
$fbshares = $this->factory->facebookSharesSource();
$this->model->addSource( $fbshares );
$totalshares = $this->factory->totalSharesSource();
$this->model->addSource( $totalshares );
$decayshares = $this->factory->decaySharesSource();
$this->model->addSource( $decayshares );
$decayviews = $this->factory->decayViewsSource();
$this->model->addSource( $decayviews );
$this->popular = new cftp_analytics( $this->factory, $this->model );
}
/**
* Force updates so you don't have to wait for cron to run.
*
* ## OPTIONS
*
* <source>
* : google|facebook|twitter
*
* ## EXAMPLES
*
* wp popular cron facebook
*/
function cron( $args, $assoc_args ) {
list( $source ) = $args;
$queue = array(); // list of tasks we need to do
switch ( $source ) {
case 'google':
$queue[] = 'googleAnalyticsSource';
$queue[] = 'decayViewsSource';
break;
case 'facebook':
//$queue[] = 'facebookLikesSource';
$queue[] = 'facebookSharesSource';
$queue[] = 'totalSharesSource';
$queue[] = 'decaySharesSource';
break;
case 'twitter':
$queue[] = 'twitterSharesSource';
$queue[] = 'totalSharesSource';
$queue[] = 'decaySharesSource';
break;
case 'total':
$queue[] = 'totalSharesSource';
break;
default:
echo "Unknown source.\n";
return false;
break;
}
foreach ( $queue as $v ) {
$task = $this->factory->cronTask( $this->factory->{$v}() );
echo $task->task();
}
}
/**
* For debugging. Test data collection on a single post.
*
* ## OPTIONS
*
* <source>
* : facebook|twitter
* <post_id>
* : int
*
* ## EXAMPLES
*
* wp popular pageviews facebook 1
*/
function pageviews( $args, $assoc_args ) {
list( $source_name, $post_id ) = $args;
$source = null;
switch ( $source_name ) {
/*case 'facebook':
$source = $this->factory->facebookLikesSource();
break;*/
case 'googleanalytics':
$source = $this->factory->googleAnalyticsSource();
break;
case 'twitter':
$source = $this->factory->twitterSharesSource();
break;
default:
$source = new cftp_null_analytics_source();
break;
}
echo $source->getPageViewsByPostID( $post_id );
}
/**
* Reset Popular/Picshare columns by adjusting 'Screen Options' for all users.
*
* ## EXAMPLES
*
* wp popular reset_user_columns
*/
function reset_user_columns() {
echo $this->factory->settingPage( $this->model )->cftp_popular_activate();
}
}
WP_CLI::add_command( 'popular', 'Popular_Command' );