| @@ -1,59 +1,41 @@ | ||
| 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 | - */ | |
| 7 | + | |
| 13 | 8 | public function __construct( $link = -1 ) { |
| 14 | - if ( is_numeric( $link ) and -1 == $link ) : | |
| 9 | + if (is_numeric($link) and -1 == $link) : | |
| 15 | 10 | $link = $this->submitted_link(); |
| 16 | 11 | endif; |
| 17 | 12 | |
| 18 | - parent::__construct( 'feedwordpressauthors', $link ); | |
| 13 | + parent::__construct('feedwordpressauthors', $link); | |
| 19 | 14 | $this->refresh_author_list(); |
| 20 | 15 | $this->dispatch = 'feedwordpress_author_settings'; |
| 21 | 16 | $this->filename = __FILE__; |
| 22 | 17 | |
| 23 | 18 | $this->pagenames = array( |
| 24 | - 'default' => 'Authors', | |
| 19 | + 'default' => 'Authors', | |
| 25 | 20 | 'settings-update' => 'Syndicated Authors', |
| 26 | - 'open-sheet' => 'Syndicated Author', | |
| 21 | + 'open-sheet' => 'Syndicated Author', | |
| 27 | 22 | ); |
| 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() { | |
| 23 | + } | |
| 24 | + | |
| 25 | + function refresh_author_list () { | |
| 35 | 26 | $this->authorlist = fwp_author_list(); |
| 36 | 27 | |
| 37 | 28 | // 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) */ | |
| 29 | + if (function_exists('natcasesort')) : natcasesort($this->authorlist); endif; | |
| 30 | + } | |
| 31 | + | |
| 32 | + /*static*/ function syndicated_authors_box ($page, $box = NULL) { | |
| 33 | + $link = $page->link; | |
| 34 | + $unfamiliar = array ('create' => '','default' => '','filter' => ''); | |
| 42 | 35 | |
| 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' ); | |
| 36 | + if ($page->for_feed_settings()) : | |
| 37 | + $key = $this->link->setting('unfamiliar author', NULL, 'site-default'); | |
| 56 | 38 | $unfamiliar['site-default'] = ''; |
| 57 | 39 | else : |
| 58 | 40 | $key = FeedWordPress::on_unfamiliar('author'); |
| 59 | 41 | endif; |
| @@ -58,9 +40,9 @@ | ||
| 58 | 40 | $key = FeedWordPress::on_unfamiliar('author'); |
| 59 | 41 | endif; |
| 60 | 42 | $unfamiliar[$key] = true; |
| 61 | 43 | |
| 62 | - $match_author_by_email = ! ( 'yes' == get_option( "feedwordpress_do_not_match_author_by_email" ) ); | |
| 44 | + $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email")); | |
| 63 | 45 | $null_emails = FeedWordPress::null_email_set(); |
| 64 | 46 | |
| 65 | 47 | // Hey ho, let's go... |
| 66 | 48 | ?> |
| @@ -65,16 +47,16 @@ | ||
| 65 | 47 | // Hey ho, let's go... |
| 66 | 48 | ?> |
| 67 | 49 | <table class="form-table"> |
| 68 | 50 | <?php |
| 69 | -if ( $page->for_default_settings() ) : | |
| 51 | +if ($page->for_default_settings()) : | |
| 70 | 52 | ?> |
| 71 | 53 | <tr><th>Unmatched authors</th> |
| 72 | -<td><span>Authors who haven’t been syndicated before</span> | |
| 54 | +<td><span>Authors who haven’t been syndicated before</span> | |
| 73 | 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');"> |
| 74 | 56 | <option value="create"<?php fwp_selected_flag($unfamiliar, 'create'); ?>>will have a new author account created for them</option> |
| 75 | 57 | <?php foreach ($page->authorlist as $author_id => $author_name) : |
| 76 | - if ( !isset($unfamiliar[$author_id])) : $unfamiliar[$author_id] = false; endif; | |
| 58 | + if (!isset($unfamiliar[$author_id])) : $unfamiliar[$author_id] = false; endif; | |
| 77 | 59 | ?> |
| 78 | 60 | <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> |
| 79 | 61 | <?php endforeach; ?> |
| 80 | 62 | <option value="newuser">will have their posts attributed to a new user...</option> |
| @@ -113,9 +95,9 @@ | ||
| 113 | 95 | </select> |
| 114 | 96 | <span class="author-rules-newuser" id="author-rules-all-newuser">named |
| 115 | 97 | <input type="text" name="author_rules_newuser[all]" value="" /></span></p></li> |
| 116 | 98 | <li><p><input type="radio" name="author_rules_name[all]" value="" |
| 117 | -<?php if ( !isset($map['name']['*'])) : ?> | |
| 99 | +<?php if (!isset($map['name']['*'])) : ?> | |
| 118 | 100 | checked="checked" |
| 119 | 101 | <?php endif; ?> |
| 120 | 102 | /> Attribute posts to authors based on automatic mapping rules. (Blank out a |
| 121 | 103 | name to delete the rule. Fill in a new name at the bottom to create a new rule.)</p> |
| @@ -141,9 +123,9 @@ | ||
| 141 | 123 | <?php endforeach; ?> |
| 142 | 124 | <option value="newuser">will be assigned to a new user...</option> |
| 143 | 125 | <option value="filter"<?php fwp_selected_flag('filter'==$author_action); ?>>get filtered out</option> |
| 144 | 126 | </select> |
| 145 | - | |
| 127 | + | |
| 146 | 128 | <span class="author-rules-newuser" id="<?php echo esc_attr($authorRulesId); ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span> |
| 147 | 129 | </td> |
| 148 | 130 | </tr> |
| 149 | 131 | <?php |
| @@ -162,9 +144,9 @@ | ||
| 162 | 144 | <?php endforeach; ?> |
| 163 | 145 | <option value="newuser">will be assigned to a new user...</option> |
| 164 | 146 | <option value="filter">get filtered out</option> |
| 165 | 147 | </select> |
| 166 | - | |
| 148 | + | |
| 167 | 149 | <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span> |
| 168 | 150 | </td> |
| 169 | 151 | </tr> |
| 170 | 152 | |
| @@ -176,9 +158,9 @@ | ||
| 176 | 158 | <?php if ($page->for_feed_settings()) : ?> |
| 177 | 159 | <option value="site-default"<?php fwp_selected_flag($unfamiliar, 'site-default'); ?>>are handled according to the default for all feeds</option> |
| 178 | 160 | <?php endif; ?> |
| 179 | 161 | <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 ) : ?> | |
| 162 | + <?php foreach ($page->authorlist as $author_id => $author_name) : ?> | |
| 181 | 163 | <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 | 164 | <?php endforeach; ?> |
| 183 | 165 | <option value="newuser">will have their posts attributed to a user named ...</option> |
| 184 | 166 | <option value="filter"<?php fwp_selected_flag($unfamiliar, 'filter'); ?>>get filtered out</option> |
| @@ -193,9 +175,9 @@ | ||
| 193 | 175 | </td> |
| 194 | 176 | </tr> |
| 195 | 177 | <?php endif; ?> |
| 196 | 178 | |
| 197 | -<?php if ( $page->for_default_settings() ) : ?> | |
| 179 | +<?php if ($page->for_default_settings()) : ?> | |
| 198 | 180 | <tr> |
| 199 | 181 | <th scope="row">Matching Authors</th> |
| 200 | 182 | <td><ul style="list-style: none; margin: 0; padding: 0;"> |
| 201 | 183 | <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> |
| @@ -210,18 +192,11 @@ | ||
| 210 | 192 | <?php endif; ?> |
| 211 | 193 | </tbody> |
| 212 | 194 | </table> |
| 213 | 195 | <?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 | - { | |
| 196 | + } /* FeedWordPressAuthorsPage::syndicated_authors_box () */ | |
| 197 | + | |
| 198 | + /*static*/ function fix_authors_box ($page, $box = NULL) { | |
| 224 | 199 | ?> |
| 225 | 200 | <table class="form-table"> |
| 226 | 201 | <tbody> |
| 227 | 202 | <tr> |
| @@ -227,10 +202,10 @@ | ||
| 227 | 202 | <tr> |
| 228 | 203 | <th scope="row">Fixing mis-matched authors:</th> |
| 229 | 204 | <td><p style="margin: 0.5em 0px">Take all the posts from this feed attributed to |
| 230 | 205 | <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> | |
| 206 | + <?php foreach ($page->authorlist as $author_id => $author_name) : ?> | |
| 207 | + <option value="<?php echo esc_attr($author_id); ?>"><?php echo esc_html($author_name); ?></option> | |
| 233 | 208 | <?php endforeach; ?> |
| 234 | 209 | </select> |
| 235 | 210 | and instead |
| 236 | 211 | <select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');"> |
| @@ -247,11 +222,11 @@ | ||
| 247 | 222 | </tr> |
| 248 | 223 | </tbody> |
| 249 | 224 | </table> |
| 250 | 225 | <?php |
| 251 | - } /* FeedWordPressAuthorsPage::fix_authors_box() */ | |
| 226 | + } /* FeedWordPressAuthorsPage::fix_authors_box () */ | |
| 252 | 227 | |
| 253 | - function display() { | |
| 228 | + function display () { | |
| 254 | 229 | $this->boxes_by_methods = array( |
| 255 | 230 | 'syndicated_authors_box' => __('Syndicated Authors'), |
| 256 | 231 | 'fix_authors_box' => __('Reassign Authors'), |
| 257 | 232 | ); |
| @@ -280,41 +255,27 @@ | ||
| 280 | 255 | </script> |
| 281 | 256 | <?php endif; |
| 282 | 257 | } /* FeedWordPressAuthorsPage::display () */ |
| 283 | 258 | |
| 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 */ | |
| 259 | + public function fix_mismatch_requested () { | |
| 291 | 260 | $fix = FeedWordPress::post( 'fix_mismatch' ); |
| 292 | - return ( ! is_null( $fix ) && strlen( $fix ) > 0 ); // possibly the same as `( ! empty( $fix ) )`. | |
| 293 | - } /* FeedWordPressAuthorsPage::fix_mismatch_requested() */ | |
| 294 | - | |
| 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() { | |
| 261 | + return ( ! is_null( $fix ) && strlen( $fix ) > 0 ); | |
| 262 | + } | |
| 263 | + | |
| 264 | + function accept_POST () { | |
| 300 | 265 | if ( self::fix_mismatch_requested() ) : |
| 301 | 266 | $this->fix_mismatch(); |
| 302 | 267 | else : |
| 303 | 268 | parent::accept_POST(); |
| 304 | 269 | endif; |
| 305 | - } /* FeedWordPressAuthorsPage::accept_POST() */ | |
| 270 | + } | |
| 306 | 271 | |
| 307 | - /** | |
| 308 | - * Fixes an author mismatch. | |
| 309 | - */ | |
| 310 | - function fix_mismatch() { | |
| 272 | + function fix_mismatch () { | |
| 311 | 273 | global $wpdb; |
| 312 | 274 | |
| 313 | 275 | $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', '' ) ); | |
| 276 | + if ( 'newuser' === $fix_to ) : | |
| 277 | + $newuser_name = trim( FeedWordPress::post('fix_mismatch_to_newuser', '' ) ); | |
| 317 | 278 | $to = fwp_insert_new_user( $newuser_name ); |
| 318 | 279 | endif; |
| 319 | 280 | |
| 320 | 281 | $from = (int) FeedWordPress::post( 'fix_mismatch_from' ); |
| @@ -329,38 +290,35 @@ | ||
| 329 | 290 | AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id' |
| 330 | 291 | AND {$wpdb->postmeta}.meta_value = '{$this->link->id}' |
| 331 | 292 | AND {$wpdb->posts}.post_author = '{$from}' |
| 332 | 293 | "); |
| 294 | + | |
| 295 | + if (count($post_ids) > 0) : | |
| 296 | + $N = count($post_ids); | |
| 297 | + $posts = 'post'.(($N==1) ? '' : 's'); | |
| 333 | 298 | |
| 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 | - | |
| 340 | 299 | // 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 | - | |
| 300 | + if (is_numeric($to)) : // re-assign to a particular user | |
| 301 | + $post_set = "(".implode(",", $post_ids).")"; | |
| 302 | + | |
| 344 | 303 | // Getting the revisions too, if there are any |
| 345 | 304 | $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set"; |
| 346 | - | |
| 305 | + | |
| 347 | 306 | $wpdb->query(" |
| 348 | - UPDATE {$wpdb->posts} | |
| 349 | - SET post_author='{$to}' | |
| 350 | - WHERE ({$wpdb->posts}.id IN $post_set | |
| 351 | - $parent_in_clause) | |
| 307 | + UPDATE {$wpdb->posts} | |
| 308 | + SET post_author='{$to}' | |
| 309 | + WHERE ({$wpdb->posts}.id IN $post_set | |
| 310 | + $parent_in_clause) | |
| 352 | 311 | "); |
| 353 | - // $this->mesg = sprintf(__("Re-assigned %d {$posts}."), $N); // see comment abpve | |
| 354 | - $this->mesg = __( "Re-assigned " ) . $posts; | |
| 312 | + $this->mesg = sprintf(__("Re-assigned %d ${posts}."), $N); | |
| 355 | 313 | |
| 356 | 314 | // ... and kill them all |
| 357 | - elseif ( 'filter' == $to ) : | |
| 358 | - foreach ( $post_ids as $post_id ) : | |
| 359 | - wp_delete_post( $post_id ); | |
| 315 | + elseif ('filter'==$to) : | |
| 316 | + foreach ($post_ids as $post_id) : | |
| 317 | + wp_delete_post($post_id); | |
| 360 | 318 | endforeach; |
| 361 | - | |
| 362 | - $this->mesg = __( "Deleted " ) . $posts; | |
| 319 | + | |
| 320 | + $this->mesg = sprintf(__("Deleted %d ${posts}."), $N); | |
| 363 | 321 | endif; |
| 364 | 322 | else : |
| 365 | 323 | $this->mesg = __("Couldn't find any posts that matched your criteria."); |
| 366 | 324 | endif; |
| @@ -365,18 +323,14 @@ | ||
| 365 | 323 | $this->mesg = __("Couldn't find any posts that matched your criteria."); |
| 366 | 324 | endif; |
| 367 | 325 | endif; |
| 368 | 326 | $this->updated = false; |
| 369 | - } /* FeedWordPressAuthorsPage::fix_mismatch() */ | |
| 327 | + } | |
| 370 | 328 | |
| 371 | - /** | |
| 372 | - * Presumably saves settings... | |
| 373 | - * | |
| 374 | - * @return void description | |
| 375 | - */ | |
| 376 | 329 | function save_settings () { |
| 330 | + | |
| 377 | 331 | if ($this->for_feed_settings()) : |
| 378 | - // $alter = array(); // what is this array? It's never used. (gwyneth 20230920) | |
| 332 | + $alter = array (); | |
| 379 | 333 | |
| 380 | 334 | // Unfamiliar author rule |
| 381 | 335 | $unfamiliar_author = FeedWordPress::post( 'unfamiliar_author' ); |
| 382 | 336 | if ( ! is_null( $unfamiliar_author ) ) : |
| @@ -390,9 +344,9 @@ | ||
| 390 | 344 | 'site-default' |
| 391 | 345 | ); |
| 392 | 346 | endif; |
| 393 | 347 | endif; |
| 394 | - | |
| 348 | + | |
| 395 | 349 | // Handle author mapping rules |
| 396 | 350 | $author_rules_name = FeedWordPress::post( 'author_rules_name' ); |
| 397 | 351 | $author_rules_action = FeedWordPress::post('author_rules_action' ); |
| 398 | 352 | if ( ! ( is_null( $author_rules_name ) || is_null( $author_rules_action ) ) ) : |
| @@ -400,13 +354,13 @@ | ||
| 400 | 354 | if ( strlen( $author_rules_name['all']) > 0 ) : |
| 401 | 355 | $author_rules_name = array( |
| 402 | 356 | 'all' => $author_rules_name['all'], |
| 403 | 357 | ); |
| 404 | - | |
| 358 | + | |
| 405 | 359 | // Erase all the rest. |
| 406 | 360 | endif; |
| 407 | 361 | endif; |
| 408 | - | |
| 362 | + | |
| 409 | 363 | unset($this->link->settings['map authors']); |
| 410 | 364 | foreach ($author_rules_name as $key => $name) : |
| 411 | 365 | // Normalize for case and whitespace |
| 412 | 366 | $name = strtolower( trim( $name ) ); |
| @@ -469,10 +423,10 @@ | ||
| 469 | 423 | endif; |
| 470 | 424 | |
| 471 | 425 | parent::save_settings(); |
| 472 | 426 | $this->refresh_author_list(); |
| 473 | - } /* FeedWordPressAuthorsPage::save_settings() */ | |
| 427 | + } | |
| 428 | +} /* class FeedWordPressAuthorsPage */ | |
| 474 | 429 | |
| 475 | -} /* class FeedWordPressAuthorsPage */ | |
| 430 | + $authorsPage = new FeedWordPressAuthorsPage; | |
| 431 | + $authorsPage->display(); | |
| 476 | 432 | |
| 477 | -$authorsPage = new FeedWordPressAuthorsPage; | |
| 478 | -$authorsPage->display(); | |