PluginProbe
FeedWordPress / 2012.1212
FeedWordPress v2012.1212
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 2012.1212, at feedwordpressrpc.class.php

124 lines 3.4 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 function FeedWordPressRPC () {
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 if (isset($delta['new'])) { $mesg[] = ' '.$delta['new'].' new posts were syndicated'; }
29 if (isset($delta['updated'])) { $mesg[] = ' '.$delta['updated'].' existing posts were updated'; }
30
31 return array('flerror' => false, 'message' => "Thanks for the ping.".implode(' and', $mesg));
32 endif;
33 }
34
35 function validate (&$args) {
36 global $wp_xmlrpc_server;
37
38 // First two params are username/password
39 $username = $wp_xmlrpc_server->escape(array_shift($args));
40 $password = $wp_xmlrpc_server->escape(array_shift($args));
41
42 $ret = array();
43 if ( !$user = $wp_xmlrpc_server->login($username, $password) ) :
44 $ret = $wp_xmlrpc_server->error;
45 elseif (!current_user_can('manage_links')) :
46 $ret = new IXR_Error(401, 'Sorry, you cannot change the subscription list.');
47 endif;
48 return $ret;
49 }
50
51 function subscribe ($args) {
52 $ret = $this->validate($args);
53 if (is_array($ret)) : // Success
54 // The remaining params are feed URLs
55 foreach ($args as $arg) :
56 $finder = new FeedFinder($arg, /*verify=*/ false, /*fallbacks=*/ 1);
57 $feeds = array_values(array_unique($finder->find()));
58
59 if (count($feeds) > 0) :
60 $link_id = FeedWordPress::syndicate_link(
61 /*title=*/ feedwordpress_display_url($feeds[0]),
62 /*homepage=*/ $feeds[0],
63 /*feed=*/ $feeds[0]
64 );
65 $ret[] = array(
66 'added',
67 $feeds[0],
68 $arg,
69 );
70 else :
71 $ret[] = array(
72 'error',
73 $arg
74 );
75 endif;
76 endforeach;
77 endif;
78 return $ret;
79 } /* FeedWordPressRPC::subscribe () */
80
81 function unsubscribe ($method, $args) {
82 $ret = $this->validate($args);
83 if (is_array($ret)) : // Success
84 // The remaining params are feed URLs
85 foreach ($args as $arg) :
86 $link_id = FeedWordPress::find_link($arg);
87
88 if (!$link_id) :
89 $link_id = FeedWordPress::find_link($arg, 'link_url');
90 endif;
91
92 if ($link_id) :
93 $link = new SyndicatedLink($link_id);
94
95 $link->{$method}();
96 $ret[] = array(
97 'deactivated',
98 $arg,
99 );
100 else :
101 $ret[] = array(
102 'error',
103 $arg,
104 );
105 endif;
106 endforeach;
107 endif;
108 return $ret;
109 } /* FeedWordPress::unsubscribe () */
110
111 function deactivate ($args) {
112 return $this->unsubscribe('deactivate', $args);
113 } /* FeedWordPressRPC::deactivate () */
114
115 function delete ($args) {
116 return $this->unsubscribe('delete', $args);
117 } /* FeedWordPressRPC::delete () */
118
119 function nuke ($args) {
120 return $this->unsubscribe('nuke', $args);
121 } /* FeedWordPressRPC::nuke () */
122 } /* class FeedWordPressRPC */
123
124