| @@ -4,25 +4,39 @@ | ||
| 4 | 4 | class FeedWordPressAuthorsPage extends FeedWordPressAdminPage { |
| 5 | 5 | var $authorlist = NULL; |
| 6 | 6 | var $rule_count = 0; |
| 7 | 7 | |
| 8 | - function FeedWordPressAuthorsPage ($link) { | |
| 9 | - FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressauthors', $link); | |
| 10 | - $this->authorlist = fwp_author_list(); | |
| 8 | + public function __construct( $link = -1 ) { | |
| 9 | + if (is_numeric($link) and -1 == $link) : | |
| 10 | + $link = $this->submitted_link(); | |
| 11 | + endif; | |
| 12 | + | |
| 13 | + parent::__construct('feedwordpressauthors', $link); | |
| 14 | + $this->refresh_author_list(); | |
| 11 | 15 | $this->dispatch = 'feedwordpress_author_settings'; |
| 12 | 16 | $this->filename = __FILE__; |
| 17 | + | |
| 18 | + $this->pagenames = array( | |
| 19 | + 'default' => 'Authors', | |
| 20 | + 'settings-update' => 'Syndicated Authors', | |
| 21 | + 'open-sheet' => 'Syndicated Author', | |
| 22 | + ); | |
| 13 | 23 | } |
| 14 | 24 | |
| 25 | + function refresh_author_list () { | |
| 26 | + $this->authorlist = fwp_author_list(); | |
| 27 | + | |
| 28 | + // Case-insensitive "natural" alphanumeric sort. Preserves key/value associations. | |
| 29 | + if (function_exists('natcasesort')) : natcasesort($this->authorlist); endif; | |
| 30 | + } | |
| 31 | + | |
| 15 | 32 | /*static*/ function syndicated_authors_box ($page, $box = NULL) { |
| 16 | 33 | $link = $page->link; |
| 17 | 34 | $unfamiliar = array ('create' => '','default' => '','filter' => ''); |
| 18 | 35 | |
| 19 | 36 | if ($page->for_feed_settings()) : |
| 20 | - if (is_string($link->settings["unfamiliar author"])) : | |
| 21 | - $key = $link->settings["unfamiliar author"]; | |
| 22 | - else: | |
| 23 | - $key = 'site-default'; | |
| 24 | - endif; | |
| 37 | + $key = $this->link->setting('unfamiliar author', NULL, 'site-default'); | |
| 38 | + $unfamiliar['site-default'] = ''; | |
| 25 | 39 | else : |
| 26 | 40 | $key = FeedWordPress::on_unfamiliar('author'); |
| 27 | 41 | endif; |
| 28 | 42 | $unfamiliar[$key] = ' selected="selected"'; |
| @@ -32,19 +46,17 @@ | ||
| 32 | 46 | |
| 33 | 47 | // Hey ho, let's go... |
| 34 | 48 | ?> |
| 35 | 49 | <table class="form-table"> |
| 36 | -<tbody> | |
| 37 | -<tr> | |
| 38 | - <th>New authors</th> | |
| 39 | - <td><span>Authors who haven't been syndicated before</span> | |
| 50 | +<?php | |
| 51 | +if ($page->for_default_settings()) : | |
| 52 | +?> | |
| 53 | +<tr><th>Unmatched authors</th> | |
| 54 | +<td><span>Authors who haven’t been syndicated before</span> | |
| 40 | 55 | <select style="max-width: 27.0em" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');"> |
| 41 | -<?php if ($page->for_feed_settings()) : ?> | |
| 42 | - <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option> | |
| 43 | -<?php endif; ?> | |
| 44 | - <option value="create"<?php $unfamiliar['create']; ?>>will have a new author account created for them</option> | |
| 56 | + <option value="create"<?php print $unfamiliar['create']; ?>>will have a new author account created for them</option> | |
| 45 | 57 | <?php foreach ($page->authorlist as $author_id => $author_name) : ?> |
| 46 | - <option value="<?php echo $author_id; ?>"<?php print $unfamiliar[$author_id]; ?>>will have their posts attributed to <?php echo $author_name; ?></option> | |
| 58 | + <option value="<?php echo $author_id; ?>"<?php print (isset($unfamiliar[$author_id]) ? $unfamiliar[$author_id] : ''); ?>>will have their posts attributed to <?php echo $author_name; ?></option> | |
| 47 | 59 | <?php endforeach; ?> |
| 48 | 60 | <option value="newuser">will have their posts attributed to a new user...</option> |
| 49 | 61 | <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option> |
| 50 | 62 | </select> |
| @@ -53,26 +65,57 @@ | ||
| 53 | 65 | </td> |
| 54 | 66 | </tr> |
| 55 | 67 | |
| 56 | 68 | <?php |
| 69 | +endif; | |
| 70 | + | |
| 57 | 71 | if ($page->for_feed_settings()) : |
| 72 | + $map = $this->link->setting('map authors', NULL, array()); | |
| 58 | 73 | ?> |
| 59 | -<tr><th>Syndicated authors</th> | |
| 60 | -<td>For attributing posts by specific authors. Blank out a name to delete the rule. Fill in a new name at the bottom to create a new rule.</p> | |
| 74 | +<tr><th>Matching authors</th> | |
| 75 | +<td><p>How should FeedWordPress attribute posts from this feed to WordPress | |
| 76 | +authors?</p> | |
| 77 | +<ul class="settings"> | |
| 78 | +<li><p><input type="radio" name="author_rules_name[all]" value="*" | |
| 79 | +<?php if (isset($map['name']['*'])) : $author_action = $map['name']['*']; ?> | |
| 80 | + checked="checked" | |
| 81 | +<?php | |
| 82 | + else : | |
| 83 | + $author_action = NULL; | |
| 84 | + endif; ?> | |
| 85 | + /> All posts syndicated | |
| 86 | +from this feed <select class="author-rules" id="author-rules-all" | |
| 87 | +name="author_rules_action[all]" onchange="contextual_appearance('author-rules-all', 'author-rules-all-newuser', 'author-rules-all-default', 'newuser', 'inline');"> | |
| 88 | + <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?> | |
| 89 | + <option value="<?php echo $local_author_id; ?>"<?php if ($local_author_id==$author_action) : echo ' selected="selected"'; endif; ?>>are assigned to <?php echo $local_author_name; ?></option> | |
| 90 | + <?php endforeach; ?> | |
| 91 | + <option value="newuser">will be assigned to a new user...</option> | |
| 92 | + <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option> | |
| 93 | + </select> | |
| 94 | + <span class="author-rules-newuser" id="author-rules-all-newuser">named | |
| 95 | + <input type="text" name="author_rules_newuser[all]" value="" /></span></p></li> | |
| 96 | +<li><p><input type="radio" name="author_rules_name[all]" value="" | |
| 97 | +<?php if (!isset($map['name']['*'])) : ?> | |
| 98 | + checked="checked" | |
| 99 | +<?php endif; ?> | |
| 100 | +/> Attribute posts to authors based on automatic mapping rules. (Blank out a | |
| 101 | +name to delete the rule. Fill in a new name at the bottom to create a new rule.)</p> | |
| 102 | + | |
| 61 | 103 | <table style="width: 100%"> |
| 62 | 104 | <?php |
| 63 | - if (isset($link->settings['map authors'])) : | |
| 105 | + if (isset($this->link->settings['map authors'])) : | |
| 64 | 106 | ?> |
| 65 | 107 | <?php |
| 66 | 108 | $page->rule_count=0; |
| 67 | - foreach ($link->settings['map authors'] as $author_rules) : | |
| 109 | + foreach ($this->link->settings['map authors'] as $author_rules) : | |
| 68 | 110 | foreach ($author_rules as $author_name => $author_action) : |
| 69 | - $page->rule_count++; | |
| 111 | + if ($author_name != '*') : | |
| 112 | + $page->rule_count++; | |
| 70 | 113 | ?> |
| 71 | 114 | <tr> |
| 72 | 115 | <th style="text-align: left; width: 15.0em">Posts by <input type="text" name="author_rules_name[]" value="<?php echo htmlspecialchars($author_name); ?>" size="11" /></th> |
| 73 | 116 | <td> |
| 74 | - <select id="author-rules-<?php echo $page->rule_count; ?>" name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php echo $page->rule_count; ?>', 'author-rules-<?php echo $page->rule_count; ?>-newuser', 'author-rules-<?php echo $page->rule_count; ?>-default', 'newuser', 'inline');"> | |
| 117 | + <select class="author-rules" id="author-rules-<?php echo $page->rule_count; ?>" name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php echo $page->rule_count; ?>', 'author-rules-<?php echo $page->rule_count; ?>-newuser', 'author-rules-<?php echo $page->rule_count; ?>-default', 'newuser', 'inline');"> | |
| 75 | 118 | <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?> |
| 76 | 119 | <option value="<?php echo $local_author_id; ?>"<?php if ($local_author_id==$author_action) : echo ' selected="selected"'; endif; ?>>are assigned to <?php echo $local_author_name; ?></option> |
| 77 | 120 | <?php endforeach; ?> |
| 78 | 121 | <option value="newuser">will be assigned to a new user...</option> |
| @@ -78,12 +121,14 @@ | ||
| 78 | 121 | <option value="newuser">will be assigned to a new user...</option> |
| 79 | 122 | <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option> |
| 80 | 123 | </select> |
| 81 | 124 | |
| 82 | - <span id="author-rules-<?php echo $page->rule_count; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span> | |
| 125 | + <span class="author-rules-newuser" id="author-rules-<?php echo $page->rule_count; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span> | |
| 83 | 126 | </td> |
| 84 | 127 | </tr> |
| 85 | -<?php endforeach; | |
| 128 | +<?php | |
| 129 | + endif; | |
| 130 | + endforeach; | |
| 86 | 131 | endforeach; |
| 87 | 132 | endif; |
| 88 | 133 | ?> |
| 89 | 134 | |
| @@ -100,11 +145,33 @@ | ||
| 100 | 145 | |
| 101 | 146 | <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span> |
| 102 | 147 | </td> |
| 103 | 148 | </tr> |
| 104 | -</table> | |
| 149 | + | |
| 150 | +<tr> | |
| 151 | +<th style="text-align: left; width: 15.0em">Unmatched authors</th> | |
| 152 | +<td> | |
| 153 | +<span>Authors who haven't been syndicated before</span> | |
| 154 | + <select style="max-width: 27.0em" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');"> | |
| 155 | +<?php if ($page->for_feed_settings()) : ?> | |
| 156 | + <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option> | |
| 157 | +<?php endif; ?> | |
| 158 | + <option value="create"<?php print $unfamiliar['create']; ?>>will have a new author account created for them</option> | |
| 159 | + <?php foreach ($page->authorlist as $author_id => $author_name) : ?> | |
| 160 | + <option value="<?php echo $author_id; ?>"<?php print (isset($unfamiliar[$author_id]) ? $unfamiliar[$author_id] : ''); ?>>will have their posts attributed to <?php echo $author_name; ?></option> | |
| 161 | + <?php endforeach; ?> | |
| 162 | + <option value="newuser">will have their posts attributed to a user named ...</option> | |
| 163 | + <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option> | |
| 164 | + </select> | |
| 165 | + | |
| 166 | + <span id="unfamiliar-author-newuser"><input type="text" name="unfamiliar_author_newuser" value="" /></span></p> | |
| 105 | 167 | </td> |
| 106 | 168 | </tr> |
| 169 | +</table></li> | |
| 170 | +</ul> | |
| 171 | + | |
| 172 | +</td> | |
| 173 | +</tr> | |
| 107 | 174 | <?php endif; ?> |
| 108 | 175 | |
| 109 | 176 | <?php if ($page->for_default_settings()) : ?> |
| 110 | 177 | <tr> |
| @@ -153,283 +220,198 @@ | ||
| 153 | 220 | </tbody> |
| 154 | 221 | </table> |
| 155 | 222 | <?php |
| 156 | 223 | } /* FeedWordPressAuthorsPage::fix_authors_box () */ |
| 157 | -} /* class FeedWordPressAuthorsPage */ | |
| 158 | 224 | |
| 159 | -function fwp_authors_page () { | |
| 160 | - global $wpdb, $wp_db_version; | |
| 225 | + function display () { | |
| 226 | + $this->boxes_by_methods = array( | |
| 227 | + 'syndicated_authors_box' => __('Syndicated Authors'), | |
| 228 | + 'fix_authors_box' => __('Reassign Authors'), | |
| 229 | + ); | |
| 230 | + if ($this->for_default_settings()) : | |
| 231 | + unset($this->boxes_by_methods['fix_authors_box']); | |
| 232 | + endif; | |
| 161 | 233 | |
| 162 | - if (FeedWordPress::needs_upgrade()) : | |
| 163 | - fwp_upgrade_page(); | |
| 164 | - return; | |
| 165 | - endif; | |
| 234 | + parent::display(); | |
| 235 | + ?> | |
| 236 | +<script type="text/javascript"> | |
| 237 | + contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline'); | |
| 238 | +</script> | |
| 166 | 239 | |
| 167 | - FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_author_settings', /*capability=*/ 'manage_links'); | |
| 240 | +<?php if ($this->for_feed_settings()) : ?> | |
| 241 | +<script type="text/javascript"> | |
| 242 | + jQuery('.author-rules').each ( function () { | |
| 243 | + contextual_appearance(this.id, this.id+'-newuser', this.id+'-default', 'newuser', 'inline'); | |
| 244 | + } ); | |
| 168 | 245 | |
| 169 | - $link = FeedWordPressAdminPage::submitted_link(); | |
| 170 | - $link_id = $link->id; | |
| 171 | - $authorsPage = new FeedWordPressAuthorsPage($link); | |
| 246 | + contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline'); | |
| 247 | + contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline'); | |
| 248 | +</script> | |
| 249 | +<?php else : ?> | |
| 250 | +<script type="text/javascript"> | |
| 251 | + contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true); | |
| 252 | +</script> | |
| 253 | +<?php endif; | |
| 254 | + } /* FeedWordPressAuthorsPage::display () */ | |
| 172 | 255 | |
| 173 | - $mesg = null; | |
| 256 | + function accept_POST ($post) { | |
| 257 | + if (isset($post['fix_mismatch']) and (strlen($post['fix_mismatch']) > 0)) : | |
| 258 | + $this->fix_mismatch($post); | |
| 259 | + else : | |
| 260 | + parent::accept_POST($post); | |
| 261 | + endif; | |
| 262 | + } | |
| 174 | 263 | |
| 175 | - if (isset($GLOBALS['fwp_post']['fix_mismatch'])) : | |
| 176 | - if ('newuser'==$GLOBALS['fwp_post']['fix_mismatch_to']) : | |
| 177 | - $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_newuser']); | |
| 178 | - if (strlen($newuser_name) > 0) : | |
| 179 | - $userdata = array(); | |
| 180 | - $userdata['ID'] = NULL; | |
| 181 | - | |
| 182 | - $userdata['user_login'] = sanitize_user($newuser_name); | |
| 183 | - $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']); | |
| 184 | - | |
| 185 | - $userdata['user_nicename'] = sanitize_title($newuser_name); | |
| 186 | - $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']); | |
| 187 | - | |
| 188 | - $userdata['display_name'] = $wpdb->escape($newuser_name); | |
| 264 | + function fix_mismatch ($post) { | |
| 265 | + global $wpdb; | |
| 189 | 266 | |
| 190 | - $newuser_id = wp_insert_user($userdata); | |
| 191 | - if (is_numeric($newuser_id)) : | |
| 192 | - $fix_mismatch_to_id = $newuser_id; | |
| 193 | - else : | |
| 194 | - // TODO: Add some error detection and reporting | |
| 195 | - endif; | |
| 196 | - else : | |
| 197 | - // TODO: Add some error reporting | |
| 198 | - endif; | |
| 267 | + if ('newuser'==$post['fix_mismatch_to']) : | |
| 268 | + $newuser_name = trim($post['fix_mismatch_to_newuser']); | |
| 269 | + $to = fwp_insert_new_user($newuser_name); | |
| 199 | 270 | else : |
| 200 | - $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to']; | |
| 271 | + $to = $post['fix_mismatch_to']; | |
| 201 | 272 | endif; |
| 202 | - $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from']; | |
| 203 | - if (is_numeric($fix_mismatch_from_id)) : | |
| 204 | - // Make a list of all the items by this author syndicated from this feed... | |
| 273 | + | |
| 274 | + $from = (int) $post['fix_mismatch_from']; | |
| 275 | + if (is_numeric($from)) : | |
| 276 | + // Make a list of all the items by this author | |
| 277 | + // syndicated from this feed... | |
| 205 | 278 | $post_ids = $wpdb->get_col(" |
| 206 | 279 | SELECT {$wpdb->posts}.id |
| 207 | 280 | FROM {$wpdb->posts}, {$wpdb->postmeta} |
| 208 | 281 | WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id) |
| 209 | 282 | AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id' |
| 210 | - AND {$wpdb->postmeta}.meta_value = '{$link_id}' | |
| 211 | - AND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}' | |
| 283 | + AND {$wpdb->postmeta}.meta_value = '{$this->link->id}' | |
| 284 | + AND {$wpdb->posts}.post_author = '{$from}' | |
| 212 | 285 | "); |
| 213 | 286 | |
| 214 | 287 | if (count($post_ids) > 0) : |
| 288 | + $N = count($post_ids); | |
| 289 | + $posts = 'post'.(($N==1) ? '' : 's'); | |
| 290 | + | |
| 215 | 291 | // Re-assign them all to the correct author |
| 216 | - if (is_numeric($fix_mismatch_to_id)) : // re-assign to a particular user | |
| 292 | + if (is_numeric($to)) : // re-assign to a particular user | |
| 217 | 293 | $post_set = "(".implode(",", $post_ids).")"; |
| 218 | 294 | |
| 219 | 295 | // Getting the revisions too, if there are any |
| 220 | - if (fwp_test_wp_version(FWP_SCHEMA_26)) : | |
| 221 | - $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set"; | |
| 222 | - else : | |
| 223 | - $parent_in_clause = ''; | |
| 224 | - endif; | |
| 296 | + $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set"; | |
| 225 | 297 | |
| 226 | 298 | $wpdb->query(" |
| 227 | 299 | UPDATE {$wpdb->posts} |
| 228 | - SET post_author='{$fix_mismatch_to_id}' | |
| 300 | + SET post_author='{$to}' | |
| 229 | 301 | WHERE ({$wpdb->posts}.id IN $post_set |
| 230 | 302 | $parent_in_clause) |
| 231 | 303 | "); |
| 232 | - $mesg = "Re-assigned ".count($post_ids)." post".((count($post_ids)==1)?'':'s')."."; | |
| 304 | + $this->mesg = sprintf(__("Re-assigned %d ${posts}."), $N); | |
| 233 | 305 | |
| 234 | 306 | // ... and kill them all |
| 235 | - elseif ($fix_mismatch_to_id=='filter') : | |
| 307 | + elseif ('filter'==$to) : | |
| 236 | 308 | foreach ($post_ids as $post_id) : |
| 237 | 309 | wp_delete_post($post_id); |
| 238 | - endforeach; | |
| 239 | - $mesg = "Deleted ".count($post_ids)." post".((count($post_ids)==1)?'':'s')."."; | |
| 310 | + endforeach; | |
| 311 | + | |
| 312 | + $this->mesg = sprintf(__("Deleted %d ${posts}."), $N); | |
| 240 | 313 | endif; |
| 241 | 314 | else : |
| 242 | - $mesg = "Couldn't find any posts that matched your criteria."; | |
| 315 | + $this->mesg = __("Couldn't find any posts that matched your criteria."); | |
| 243 | 316 | endif; |
| 244 | 317 | endif; |
| 245 | - elseif (isset($GLOBALS['fwp_post']['save'])) : | |
| 246 | - if (is_object($link) and $link->found()) : | |
| 318 | + $this->updated = false; | |
| 319 | + } | |
| 320 | + | |
| 321 | + function save_settings ($post) { | |
| 322 | + | |
| 323 | + if ($this->for_feed_settings()) : | |
| 247 | 324 | $alter = array (); |
| 248 | 325 | |
| 249 | 326 | // Unfamiliar author rule |
| 250 | - if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) : | |
| 251 | - if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_author"]) : | |
| 252 | - unset($link->settings["unfamiliar author"]); | |
| 253 | - elseif ('newuser'==$GLOBALS['fwp_post']["unfamiliar_author"]) : | |
| 254 | - $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]); | |
| 255 | - $link->map_name_to_new_user(/*name=*/ NULL, $newuser_name); | |
| 327 | + if (isset($post["unfamiliar_author"])) : | |
| 328 | + if ('newuser'==$post['unfamiliar_author']) : | |
| 329 | + $new_name = trim($post["unfamiliar_author_newuser"]); | |
| 330 | + $this->link->map_name_to_new_user(/*name=*/ NULL, $new_name); | |
| 256 | 331 | else : |
| 257 | - $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"]; | |
| 332 | + $this->link->update_setting( | |
| 333 | + "unfamiliar author", | |
| 334 | + $post['unfamiliar_author'], | |
| 335 | + 'site-default' | |
| 336 | + ); | |
| 258 | 337 | endif; |
| 259 | 338 | endif; |
| 260 | 339 | |
| 261 | 340 | // Handle author mapping rules |
| 262 | - if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) : | |
| 263 | - unset($link->settings['map authors']); | |
| 264 | - foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) : | |
| 341 | + if (isset($post['author_rules_name']) | |
| 342 | + and isset($post['author_rules_action'])) : | |
| 343 | + if (isset($post['author_rules_name']['all'])) : | |
| 344 | + if (strlen($post['author_rules_name']['all']) > 0) : | |
| 345 | + $post['author_rules_name'] = array( | |
| 346 | + 'all' => $post['author_rules_name']['all'], | |
| 347 | + ); | |
| 348 | + | |
| 349 | + // Erase all the rest. | |
| 350 | + endif; | |
| 351 | + endif; | |
| 352 | + | |
| 353 | + unset($this->link->settings['map authors']); | |
| 354 | + foreach ($post['author_rules_name'] as $key => $name) : | |
| 265 | 355 | // Normalize for case and whitespace |
| 266 | 356 | $name = strtolower(trim($name)); |
| 267 | - $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key])); | |
| 357 | + $author_action = strtolower(trim($post['author_rules_action'][$key])); | |
| 268 | 358 | |
| 269 | 359 | if (strlen($name) > 0) : |
| 270 | 360 | if ('newuser' == $author_action) : |
| 271 | - $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]); | |
| 272 | - $link->map_name_to_new_user($name, $newuser_name); | |
| 361 | + $new_name = trim($post['author_rules_newuser'][$key]); | |
| 362 | + $this->link->map_name_to_new_user($name, $new_name); | |
| 273 | 363 | else : |
| 274 | - $link->settings['map authors']['name'][$name] = $author_action; | |
| 364 | + $this->link->settings['map authors']['name'][$name] = $author_action; | |
| 275 | 365 | endif; |
| 276 | 366 | endif; |
| 277 | 367 | endforeach; |
| 278 | 368 | endif; |
| 279 | 369 | |
| 280 | - if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) : | |
| 281 | - $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name'])); | |
| 282 | - $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action'])); | |
| 370 | + if (isset($post['add_author_rule_name']) | |
| 371 | + and isset($post['add_author_rule_action'])) : | |
| 372 | + $name = strtolower(trim($post['add_author_rule_name'])); | |
| 373 | + $author_action = strtolower(trim($post['add_author_rule_action'])); | |
| 374 | + | |
| 283 | 375 | if (strlen($name) > 0) : |
| 284 | 376 | if ('newuser' == $author_action) : |
| 285 | - $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']); | |
| 286 | - $link->map_name_to_new_user($name, $newuser_name); | |
| 377 | + $new_name = trim($post['add_author_rule_newuser']); | |
| 378 | + $this->link->map_name_to_new_user($name, $new_name); | |
| 287 | 379 | else : |
| 288 | - $link->settings['map authors']['name'][$name] = $author_action; | |
| 380 | + $this->link->settings['map authors']['name'][$name] = $author_action; | |
| 289 | 381 | endif; |
| 290 | 382 | endif; |
| 291 | 383 | endif; |
| 292 | - | |
| 293 | - $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'"; | |
| 294 | - | |
| 295 | - $alter_set = implode(", ", $alter); | |
| 296 | - | |
| 297 | - // issue update query | |
| 298 | - $result = $wpdb->query(" | |
| 299 | - UPDATE $wpdb->links | |
| 300 | - SET $alter_set | |
| 301 | - WHERE link_id='$link_id' | |
| 302 | - "); | |
| 303 | - $updated_link = true; | |
| 304 | - | |
| 305 | - // reload link information from DB | |
| 306 | - if (function_exists('clean_bookmark_cache')) : | |
| 307 | - clean_bookmark_cache($link_id); | |
| 308 | - endif; | |
| 309 | - $link =& new SyndicatedLink($link_id); | |
| 310 | 384 | else : |
| 311 | - if ('newuser'==$GLOBALS['fwp_post']['unfamiliar_author']) : | |
| 312 | - $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']); | |
| 313 | - if (strlen($newuser_name) > 0) : | |
| 314 | - $userdata = array(); | |
| 315 | - $userdata['ID'] = NULL; | |
| 316 | - | |
| 317 | - $userdata['user_login'] = sanitize_user($newuser_name); | |
| 318 | - $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']); | |
| 319 | - | |
| 320 | - $userdata['user_nicename'] = sanitize_title($newuser_name); | |
| 321 | - $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']); | |
| 322 | - | |
| 323 | - $userdata['display_name'] = $wpdb->escape($newuser_name); | |
| 324 | - | |
| 325 | - $newuser_id = wp_insert_user($userdata); | |
| 326 | - if (is_numeric($newuser_id)) : | |
| 327 | - update_option('feedwordpress_unfamiliar_author', $newuser_id); | |
| 328 | - else : | |
| 329 | - // TODO: Add some error detection and reporting | |
| 330 | - endif; | |
| 385 | + if ('newuser'==$post['unfamiliar_author']) : | |
| 386 | + $new_name = trim($post['unfamiliar_author_newuser']); | |
| 387 | + $new_id = fwp_insert_new_user($new_name); | |
| 388 | + if (is_numeric($new_id)) : | |
| 389 | + update_option('feedwordpress_unfamiliar_author', $new_id); | |
| 331 | 390 | else : |
| 332 | - // TODO: Add some error reporting | |
| 333 | - endif; | |
| 391 | + // TODO: Add some error detection and reporting | |
| 392 | + // Put WP_Error stuff into $this->mesg ? | |
| 393 | + endif; | |
| 334 | 394 | else : |
| 335 | - update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']); | |
| 395 | + update_option('feedwordpress_unfamiliar_author', $post['unfamiliar_author']); | |
| 336 | 396 | endif; |
| 337 | 397 | |
| 338 | - if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email']=='yes') : | |
| 339 | - update_option('feedwordpress_do_not_match_author_by_email', 'no'); | |
| 340 | - else : | |
| 341 | - update_option('feedwordpress_do_not_match_author_by_email', 'yes'); | |
| 342 | - endif; | |
| 398 | + update_option('feedwordpress_do_not_match_author_by_email', | |
| 399 | + (isset($post['match_author_by_email']) | |
| 400 | + and 'yes'==$post['match_author_by_email']) | |
| 401 | + ? 'no' | |
| 402 | + : 'yes' | |
| 403 | + ); | |
| 343 | 404 | |
| 344 | - if (isset($GLOBALS['fwp_post']['null_emails'])) : | |
| 345 | - update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']); | |
| 405 | + if (isset($post['null_emails'])) : | |
| 406 | + update_option('feedwordpress_null_email_set', $post['null_emails']); | |
| 346 | 407 | endif; |
| 347 | - | |
| 348 | - $updated_link = true; | |
| 349 | 408 | endif; |
| 350 | 409 | |
| 351 | - do_action('feedwordpress_admin_page_authors_save', $GLOBALS['fwp_post'], $authorsPage); | |
| 352 | - else : | |
| 353 | - $updated_link = false; | |
| 354 | - endif; | |
| 355 | - | |
| 356 | - //////////////////////////////////////////////// | |
| 357 | - // Prepare settings page /////////////////////// | |
| 358 | - //////////////////////////////////////////////// | |
| 410 | + parent::save_settings($post); | |
| 411 | + $this->refresh_author_list(); | |
| 412 | + } | |
| 413 | +} /* class FeedWordPressAuthorsPage */ | |
| 359 | 414 | |
| 360 | - if ($updated_link) : | |
| 361 | -?> | |
| 362 | -<div class="updated"><p>Syndicated author settings updated.</p></div> | |
| 363 | -<?php elseif (!is_null($mesg)) : ?> | |
| 364 | -<div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div> | |
| 365 | -<?php endif; | |
| 366 | - | |
| 367 | - if (function_exists('add_meta_box')) : | |
| 368 | - add_action( | |
| 369 | - FeedWordPressCompatibility::bottom_script_hook(__FILE__), | |
| 370 | - /*callback=*/ array($authorsPage, 'fix_toggles'), | |
| 371 | - /*priority=*/ 10000 | |
| 372 | - ); | |
| 373 | - FeedWordPressSettingsUI::ajax_nonce_fields(); | |
| 374 | - endif; | |
| 375 | - | |
| 376 | - $authorsPage->open_sheet('Syndicated Author'); | |
| 377 | - ?> | |
| 378 | - <div id="post-body"> | |
| 379 | - <?php | |
| 380 | - //////////////////////////////////////////////// | |
| 381 | - // Display settings boxes ////////////////////// | |
| 382 | - //////////////////////////////////////////////// | |
| 383 | - | |
| 384 | - $boxes_by_methods = array( | |
| 385 | - 'syndicated_authors_box' => __('Syndicated Authors'), | |
| 386 | - 'fix_authors_box' => __('Reassign Authors'), | |
| 387 | - ); | |
| 388 | - if ($authorsPage->for_default_settings()) : | |
| 389 | - unset($boxes_by_methods['fix_authors_box']); | |
| 390 | - endif; | |
| 391 | - | |
| 392 | - foreach ($boxes_by_methods as $method => $row) : | |
| 393 | - if (is_array($row)) : | |
| 394 | - $id = $row['id']; | |
| 395 | - $title = $row['title']; | |
| 396 | - else : | |
| 397 | - $id = 'feedwordpress_'.$method; | |
| 398 | - $title = $row; | |
| 399 | - endif; | |
| 400 | - | |
| 401 | - fwp_add_meta_box( | |
| 402 | - /*id=*/ $id, | |
| 403 | - /*title=*/ $title, | |
| 404 | - /*callback=*/ array('FeedWordPressAuthorsPage', $method), | |
| 405 | - /*page=*/ $authorsPage->meta_box_context(), | |
| 406 | - /*context=*/ $authorsPage->meta_box_context() | |
| 407 | - ); | |
| 408 | - endforeach; | |
| 409 | - do_action('feedwordpress_admin_page_authors_meta_boxes', $authorsPage); | |
| 410 | -?> | |
| 411 | - <div class="metabox-holder"> | |
| 412 | -<?php | |
| 413 | - fwp_do_meta_boxes($authorsPage->meta_box_context(), $authorsPage->meta_box_context(), $authorsPage); | |
| 414 | -?> | |
| 415 | - </div> <!-- class="metabox-holder" --> | |
| 416 | -</div> <!-- id="post-body" --> | |
| 417 | -<?php $authorsPage->close_sheet(); ?> | |
| 418 | - | |
| 419 | -<script type="text/javascript"> | |
| 420 | - contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline'); | |
| 421 | -<?php if (is_object($link) and $link->found()) : ?> | |
| 422 | -<?php for ($j=1; $j<=$authorsPage->rule_count; $j++) : ?> | |
| 423 | - contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline'); | |
| 424 | -<?php endfor; ?> | |
| 425 | - contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline'); | |
| 426 | - contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline'); | |
| 427 | -<?php else : ?> | |
| 428 | - contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true); | |
| 429 | -<?php endif; ?> | |
| 430 | -</script> | |
| 431 | -<?php | |
| 432 | -} /* function fwp_authors_page () */ | |
| 433 | - | |
| 434 | - fwp_authors_page(); | |
| 415 | + $authorsPage = new FeedWordPressAuthorsPage; | |
| 416 | + $authorsPage->display(); | |
| 435 | 417 | |