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