forked from radgeek/feedwordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedwordpressrpc.class.php
120 lines (103 loc) · 3.27 KB
/
feedwordpressrpc.class.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
<?php
################################################################################
## XML-RPC HOOKS: accept XML-RPC update pings from Contributors ################
################################################################################
class FeedWordPressRPC {
function FeedWordPressRPC () {
add_filter('xmlrpc_methods', array($this, 'xmlrpc_methods'));
}
function xmlrpc_methods ($args = array()) {
$args['weblogUpdates.ping'] = array($this, 'ping');
$args['feedwordpress.subscribe'] = array($this, 'subscribe');
$args['feedwordpress.deactivate'] = array($this, 'deactivate');
$args['feedwordpress.delete'] = array($this, 'delete');
$args['feedwordpress.nuke'] = array($this, 'nuke');
return $args;
}
function ping ($args) {
global $feedwordpress;
$delta = @$feedwordpress->update($args[1]);
if (is_null($delta)):
return array('flerror' => true, 'message' => "Sorry. I don't syndicate <$args[1]>.");
else:
$mesg = array();
return array('flerror' => false, 'message' => "Thanks for the ping.".fwp_update_set_results_message($delta));
endif;
}
function validate (&$args) {
global $wp_xmlrpc_server;
// First two params are username/password
$username = $wp_xmlrpc_server->escape(array_shift($args));
$password = $wp_xmlrpc_server->escape(array_shift($args));
$ret = array();
if ( !$user = $wp_xmlrpc_server->login($username, $password) ) :
$ret = $wp_xmlrpc_server->error;
elseif (!current_user_can('manage_links')) :
$ret = new IXR_Error(401, 'Sorry, you cannot change the subscription list.');
endif;
return $ret;
}
function subscribe ($args) {
$ret = $this->validate($args);
if (is_array($ret)) : // Success
// The remaining params are feed URLs
foreach ($args as $arg) :
$finder = new FeedFinder($arg, /*verify=*/ false, /*fallbacks=*/ 1);
$feeds = array_values(array_unique($finder->find()));
if (count($feeds) > 0) :
$link_id = FeedWordPress::syndicate_link(
/*title=*/ feedwordpress_display_url($feeds[0]),
/*homepage=*/ $feeds[0],
/*feed=*/ $feeds[0]
);
$ret[] = array(
'added',
$feeds[0],
$arg,
);
else :
$ret[] = array(
'error',
$arg
);
endif;
endforeach;
endif;
return $ret;
} /* FeedWordPressRPC::subscribe () */
function unsubscribe ($method, $args) {
$ret = $this->validate($args);
if (is_array($ret)) : // Success
// The remaining params are feed URLs
foreach ($args as $arg) :
$link_id = FeedWordPress::find_link($arg);
if (!$link_id) :
$link_id = FeedWordPress::find_link($arg, 'link_url');
endif;
if ($link_id) :
$link = new SyndicatedLink($link_id);
$link->{$method}();
$ret[] = array(
'deactivated',
$arg,
);
else :
$ret[] = array(
'error',
$arg,
);
endif;
endforeach;
endif;
return $ret;
} /* FeedWordPress::unsubscribe () */
function deactivate ($args) {
return $this->unsubscribe('deactivate', $args);
} /* FeedWordPressRPC::deactivate () */
function delete ($args) {
return $this->unsubscribe('delete', $args);
} /* FeedWordPressRPC::delete () */
function nuke ($args) {
return $this->unsubscribe('nuke', $args);
} /* FeedWordPressRPC::nuke () */
} /* class FeedWordPressRPC */