| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | class FeedWordPressRPC { |
| 7 | 7 | public function __construct () { |
| 8 | 8 | add_filter('xmlrpc_methods', array($this, 'xmlrpc_methods')); |
| 9 | 9 | } |
| 10 | - | |
| 10 | + | |
| 11 | 11 | function xmlrpc_methods ($args = array()) { |
| 12 | 12 | $args['weblogUpdates.ping'] = array($this, 'ping'); |
| 13 | 13 | $args['feedwordpress.subscribe'] = array($this, 'subscribe'); |
| 14 | 14 | $args['feedwordpress.deactivate'] = array($this, 'deactivate'); |
| @@ -15,21 +15,21 @@ | ||
| 15 | 15 | $args['feedwordpress.delete'] = array($this, 'delete'); |
| 16 | 16 | $args['feedwordpress.nuke'] = array($this, 'nuke'); |
| 17 | 17 | return $args; |
| 18 | 18 | } |
| 19 | - | |
| 19 | + | |
| 20 | 20 | function ping ($args) { |
| 21 | 21 | global $feedwordpress; |
| 22 | - | |
| 22 | + | |
| 23 | 23 | $delta = @$feedwordpress->update($args[1]); |
| 24 | 24 | if (is_null($delta)): |
| 25 | 25 | return array('flerror' => true, 'message' => "Sorry. I don't syndicate <$args[1]>."); |
| 26 | 26 | else: |
| 27 | - $mesg = array(); // unused? (gwyneth 20230920) | |
| 27 | + $mesg = array(); | |
| 28 | 28 | return array('flerror' => false, 'message' => "Thanks for the ping.".fwp_update_set_results_message($delta)); |
| 29 | 29 | endif; |
| 30 | 30 | } |
| 31 | - | |
| 31 | + | |
| 32 | 32 | function validate (&$args) { |
| 33 | 33 | global $wp_xmlrpc_server; |
| 34 | 34 | |
| 35 | 35 | // First two params are username/password |
| @@ -36,12 +36,11 @@ | ||
| 36 | 36 | $username = $wp_xmlrpc_server->escape(array_shift($args)); |
| 37 | 37 | $password = $wp_xmlrpc_server->escape(array_shift($args)); |
| 38 | 38 | |
| 39 | 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) ) : | |
| 40 | + if ( !$user = $wp_xmlrpc_server->login($username, $password) ) : | |
| 42 | 41 | $ret = $wp_xmlrpc_server->error; |
| 43 | - elseif ( !current_user_can('manage_links')) : | |
| 42 | + elseif (!current_user_can('manage_links')) : | |
| 44 | 43 | $ret = new IXR_Error(401, 'Sorry, you cannot change the subscription list.'); |
| 45 | 44 | endif; |
| 46 | 45 | return $ret; |
| 47 | 46 | } |
| @@ -52,24 +51,15 @@ | ||
| 52 | 51 | // The remaining params are feed URLs |
| 53 | 52 | foreach ($args as $arg) : |
| 54 | 53 | $finder = new FeedFinder($arg, /*verify=*/ false, /*fallbacks=*/ 1); |
| 55 | 54 | $feeds = array_values(array_unique($finder->find())); |
| 56 | - | |
| 55 | + | |
| 57 | 56 | 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 | 57 | $link_id = FeedWordPress::syndicate_link( |
| 61 | 58 | /*title=*/ feedwordpress_display_url($feeds[0]), |
| 62 | 59 | /*homepage=*/ $feeds[0], |
| 63 | 60 | /*feed=*/ $feeds[0] |
| 64 | 61 | ); |
| 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 | 62 | $ret[] = array( |
| 73 | 63 | 'added', |
| 74 | 64 | $feeds[0], |
| 75 | 65 | $arg, |
| @@ -83,9 +73,9 @@ | ||
| 83 | 73 | endforeach; |
| 84 | 74 | endif; |
| 85 | 75 | return $ret; |
| 86 | 76 | } /* FeedWordPressRPC::subscribe () */ |
| 87 | - | |
| 77 | + | |
| 88 | 78 | function unsubscribe ($method, $args) { |
| 89 | 79 | $ret = $this->validate($args); |
| 90 | 80 | if (is_array($ret)) : // Success |
| 91 | 81 | // The remaining params are feed URLs |
| @@ -90,16 +80,16 @@ | ||
| 90 | 80 | if (is_array($ret)) : // Success |
| 91 | 81 | // The remaining params are feed URLs |
| 92 | 82 | foreach ($args as $arg) : |
| 93 | 83 | $link_id = FeedWordPress::find_link($arg); |
| 94 | - | |
| 95 | - if ( ! $link_id) : | |
| 84 | + | |
| 85 | + if (!$link_id) : | |
| 96 | 86 | $link_id = FeedWordPress::find_link($arg, 'link_url'); |
| 97 | 87 | endif; |
| 98 | - | |
| 88 | + | |
| 99 | 89 | if ($link_id) : |
| 100 | 90 | $link = new SyndicatedLink($link_id); |
| 101 | - | |
| 91 | + | |
| 102 | 92 | $link->{$method}(); |
| 103 | 93 | $ret[] = array( |
| 104 | 94 | 'deactivated', |
| 105 | 95 | $arg, |
| @@ -113,17 +103,17 @@ | ||
| 113 | 103 | endforeach; |
| 114 | 104 | endif; |
| 115 | 105 | return $ret; |
| 116 | 106 | } /* FeedWordPress::unsubscribe () */ |
| 117 | - | |
| 107 | + | |
| 118 | 108 | function deactivate ($args) { |
| 119 | 109 | return $this->unsubscribe('deactivate', $args); |
| 120 | 110 | } /* FeedWordPressRPC::deactivate () */ |
| 121 | - | |
| 111 | + | |
| 122 | 112 | function delete ($args) { |
| 123 | 113 | return $this->unsubscribe('delete', $args); |
| 124 | 114 | } /* FeedWordPressRPC::delete () */ |
| 125 | - | |
| 115 | + | |
| 126 | 116 | function nuke ($args) { |
| 127 | 117 | return $this->unsubscribe('nuke', $args); |
| 128 | 118 | } /* FeedWordPressRPC::nuke () */ |
| 129 | 119 | } /* class FeedWordPressRPC */ |