PluginProbe
FeedWordPress / 2022.0222
FeedWordPress v2022.0222
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpressrpc.class.php

feedwordpressrpc.class.php in FeedWordPress 2022.0222, at feedwordpressrpc.class.php

121 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ################################################################################
3 ## XML-RPC HOOKS: accept XML-RPC update pings from Contributors ################
4 ################################################################################
5
6 class FeedWordPressRPC {
7 public function __construct () {
8 add_filter('xmlrpc_methods', array($this, 'xmlrpc_methods'));
9 }
10
11 function xmlrpc_methods ($args = array()) {
12 $args['weblogUpdates.ping'] = array($this, 'ping');
13 $args['feedwordpress.subscribe'] = array($this, 'subscribe');
14 $args['feedwordpress.deactivate'] = array($this, 'deactivate');
15 $args['feedwordpress.delete'] = array($this, 'delete');
16 $args['feedwordpress.nuke'] = array($this, 'nuke');
17 return $args;
18 }
19
20 function ping ($args) {
21 global $feedwordpress;
22
23 $delta = @$feedwordpress->update($args[1]);
24 if (is_null($delta)):
25 return array('flerror' => true, 'message' => "Sorry. I don't syndicate <$args[1]>.");
26 else:
27 $mesg = array();
28 return array('flerror' => false, 'message' => "Thanks for the ping.".fwp_update_set_results_message($delta));
29 endif;
30 }
31
32 function validate (&$args) {
33 global $wp_xmlrpc_server;
34
35 // First two params are username/password
36 $username = $wp_xmlrpc_server->escape(array_shift($args));
37 $password = $wp_xmlrpc_server->escape(array_shift($args));
38
39 $ret = array();
40 if ( !$user = $wp_xmlrpc_server->login($username, $password) ) :
41 $ret = $wp_xmlrpc_server->error;
42 elseif (!current_user_can('manage_links')) :
43 $ret = new IXR_Error(401, 'Sorry, you cannot change the subscription list.');
44 endif;
45 return $ret;
46 }
47
48 function subscribe ($args) {
49 $ret = $this->validate($args);
50 if (is_array($ret)) : // Success
51 // The remaining params are feed URLs
52 foreach ($args as $arg) :
53 $finder = new FeedFinder($arg, /*verify=*/ false, /*fallbacks=*/ 1);
54 $feeds = array_values(array_unique($finder->find()));
55
56 if (count($feeds) > 0) :
57 $link_id = FeedWordPress::syndicate_link(
58 /*title=*/ feedwordpress_display_url($feeds[0]),
59 /*homepage=*/ $feeds[0],
60 /*feed=*/ $feeds[0]
61 );
62 $ret[] = array(
63 'added',
64 $feeds[0],
65 $arg,
66 );
67 else :
68 $ret[] = array(
69 'error',
70 $arg
71 );
72 endif;
73 endforeach;
74 endif;
75 return $ret;
76 } /* FeedWordPressRPC::subscribe () */
77
78 function unsubscribe ($method, $args) {
79 $ret = $this->validate($args);
80 if (is_array($ret)) : // Success
81 // The remaining params are feed URLs
82 foreach ($args as $arg) :
83 $link_id = FeedWordPress::find_link($arg);
84
85 if (!$link_id) :
86 $link_id = FeedWordPress::find_link($arg, 'link_url');
87 endif;
88
89 if ($link_id) :
90 $link = new SyndicatedLink($link_id);
91
92 $link->{$method}();
93 $ret[] = array(
94 'deactivated',
95 $arg,
96 );
97 else :
98 $ret[] = array(
99 'error',
100 $arg,
101 );
102 endif;
103 endforeach;
104 endif;
105 return $ret;
106 } /* FeedWordPress::unsubscribe () */
107
108 function deactivate ($args) {
109 return $this->unsubscribe('deactivate', $args);
110 } /* FeedWordPressRPC::deactivate () */
111
112 function delete ($args) {
113 return $this->unsubscribe('delete', $args);
114 } /* FeedWordPressRPC::delete () */
115
116 function nuke ($args) {
117 return $this->unsubscribe('nuke', $args);
118 } /* FeedWordPressRPC::nuke () */
119 } /* class FeedWordPressRPC */
120
121