PluginProbe
FeedWordPress / trunk
FeedWordPress vtrunk
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 trunk, at feedwordpressrpc.class.php

131 lines 3.8 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(); // unused? (gwyneth 20230920)
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 // $user is unused. Is it just a return value, or should it be stored somewhere? (gwyneth 20230920)
41 if ( ! $user = $wp_xmlrpc_server->login($username, $password) ) :
42 $ret = $wp_xmlrpc_server->error;
43 elseif ( !current_user_can('manage_links')) :
44 $ret = new IXR_Error(401, 'Sorry, you cannot change the subscription list.');
45 endif;
46 return $ret;
47 }
48
49 function subscribe ($args) {
50 $ret = $this->validate($args);
51 if (is_array($ret)) : // Success
52 // The remaining params are feed URLs
53 foreach ($args as $arg) :
54 $finder = new FeedFinder($arg, /*verify=*/ false, /*fallbacks=*/ 1);
55 $feeds = array_values(array_unique($finder->find()));
56
57 if (count($feeds) > 0) :
58 // $link_id is never used, possibly because it's just a discardable return value. However,
59 // it _can_ return a WP_Error, so it might make sense to check for it? (gwyneth 20230920)
60 $link_id = FeedWordPress::syndicate_link(
61 /*title=*/ feedwordpress_display_url($feeds[0]),
62 /*homepage=*/ $feeds[0],
63 /*feed=*/ $feeds[0]
64 );
65 // just to make sure! (gwyneth 20230920)
66 if ( is_wp_error( $link_id ) ) :
67 FeedWordPress::diagnostic(
68 'fwp-rpc/subscribe',
69 implode( '|', $link_id->get_error_messages() )
70 );
71 endif;
72 $ret[] = array(
73 'added',
74 $feeds[0],
75 $arg,
76 );
77 else :
78 $ret[] = array(
79 'error',
80 $arg
81 );
82 endif;
83 endforeach;
84 endif;
85 return $ret;
86 } /* FeedWordPressRPC::subscribe () */
87
88 function unsubscribe ($method, $args) {
89 $ret = $this->validate($args);
90 if (is_array($ret)) : // Success
91 // The remaining params are feed URLs
92 foreach ($args as $arg) :
93 $link_id = FeedWordPress::find_link($arg);
94
95 if ( ! $link_id) :
96 $link_id = FeedWordPress::find_link($arg, 'link_url');
97 endif;
98
99 if ($link_id) :
100 $link = new SyndicatedLink($link_id);
101
102 $link->{$method}();
103 $ret[] = array(
104 'deactivated',
105 $arg,
106 );
107 else :
108 $ret[] = array(
109 'error',
110 $arg,
111 );
112 endif;
113 endforeach;
114 endif;
115 return $ret;
116 } /* FeedWordPress::unsubscribe () */
117
118 function deactivate ($args) {
119 return $this->unsubscribe('deactivate', $args);
120 } /* FeedWordPressRPC::deactivate () */
121
122 function delete ($args) {
123 return $this->unsubscribe('delete', $args);
124 } /* FeedWordPressRPC::delete () */
125
126 function nuke ($args) {
127 return $this->unsubscribe('nuke', $args);
128 } /* FeedWordPressRPC::nuke () */
129 } /* class FeedWordPressRPC */
130
131