PluginProbe
FeedWordPress / 2022.0204
FeedWordPress v2022.0204
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
← All changes | authors-page.php +113 -171 trunk2022.0204 View file →
@@ -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&rsquo;t been syndicated before</span>
54 +<td><span>Authors who haven&#8217;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,47 +255,28 @@
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 */
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() */
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() {
300 - if ( self::fix_mismatch_requested() ) :
301 - $this->fix_mismatch();
259 + function accept_POST ($post) {
260 + if (isset($post['fix_mismatch']) and (strlen($post['fix_mismatch']) > 0)) :
261 + $this->fix_mismatch($post);
302 262 else :
303 - parent::accept_POST();
263 + parent::accept_POST($post);
304 264 endif;
305 - } /* FeedWordPressAuthorsPage::accept_POST() */
265 + }
306 266
307 - /**
308 - * Fixes an author mismatch.
309 - */
310 - function fix_mismatch() {
267 + function fix_mismatch ($post) {
311 268 global $wpdb;
312 269
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 );
270 + if ('newuser'==$post['fix_mismatch_to']) :
271 + $newuser_name = trim($post['fix_mismatch_to_newuser']);
272 + $to = fwp_insert_new_user($newuser_name);
273 + else :
274 + $to = $post['fix_mismatch_to'];
318 275 endif;
319 276
320 - $from = (int) FeedWordPress::post( 'fix_mismatch_from' );
321 - if ( is_numeric( $from ) ) :
322 -
277 + $from = (int) $post['fix_mismatch_from'];
278 + if (is_numeric($from)) :
323 279 // Make a list of all the items by this author
324 280 // syndicated from this feed...
325 281 $post_ids = $wpdb->get_col("
326 282 SELECT {$wpdb->posts}.id
@@ -329,38 +285,35 @@
329 285 AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'
330 286 AND {$wpdb->postmeta}.meta_value = '{$this->link->id}'
331 287 AND {$wpdb->posts}.post_author = '{$from}'
332 288 ");
289 +
290 + if (count($post_ids) > 0) :
291 + $N = count($post_ids);
292 + $posts = 'post'.(($N==1) ? '' : 's');
333 293
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 294 // 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 -
295 + if (is_numeric($to)) : // re-assign to a particular user
296 + $post_set = "(".implode(",", $post_ids).")";
297 +
344 298 // Getting the revisions too, if there are any
345 299 $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set";
346 -
300 +
347 301 $wpdb->query("
348 - UPDATE {$wpdb->posts}
349 - SET post_author='{$to}'
350 - WHERE ({$wpdb->posts}.id IN $post_set
351 - $parent_in_clause)
302 + UPDATE {$wpdb->posts}
303 + SET post_author='{$to}'
304 + WHERE ({$wpdb->posts}.id IN $post_set
305 + $parent_in_clause)
352 306 ");
353 - // $this->mesg = sprintf(__("Re-assigned %d {$posts}."), $N); // see comment abpve
354 - $this->mesg = __( "Re-assigned " ) . $posts;
307 + $this->mesg = sprintf(__("Re-assigned %d ${posts}."), $N);
355 308
356 309 // ... and kill them all
357 - elseif ( 'filter' == $to ) :
358 - foreach ( $post_ids as $post_id ) :
359 - wp_delete_post( $post_id );
310 + elseif ('filter'==$to) :
311 + foreach ($post_ids as $post_id) :
312 + wp_delete_post($post_id);
360 313 endforeach;
361 -
362 - $this->mesg = __( "Deleted " ) . $posts;
314 +
315 + $this->mesg = sprintf(__("Deleted %d ${posts}."), $N);
363 316 endif;
364 317 else :
365 318 $this->mesg = __("Couldn't find any posts that matched your criteria.");
366 319 endif;
@@ -365,58 +318,51 @@
365 318 $this->mesg = __("Couldn't find any posts that matched your criteria.");
366 319 endif;
367 320 endif;
368 321 $this->updated = false;
369 - } /* FeedWordPressAuthorsPage::fix_mismatch() */
322 + }
370 323
371 - /**
372 - * Presumably saves settings...
373 - *
374 - * @return void description
375 - */
376 - function save_settings () {
324 + function save_settings ($post) {
325 +
377 326 if ($this->for_feed_settings()) :
378 - // $alter = array(); // what is this array? It's never used. (gwyneth 20230920)
327 + $alter = array ();
379 328
380 329 // 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);
330 + if (isset($post["unfamiliar_author"])) :
331 + if ('newuser'==$post['unfamiliar_author']) :
332 + $new_name = trim($post["unfamiliar_author_newuser"]);
333 + $this->link->map_name_to_new_user(/*name=*/ NULL, $new_name);
386 334 else :
387 335 $this->link->update_setting(
388 336 "unfamiliar author",
389 - $unfamiliar_author,
337 + $post['unfamiliar_author'],
390 338 'site-default'
391 339 );
392 340 endif;
393 341 endif;
394 -
342 +
395 343 // 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'],
344 + if (isset($post['author_rules_name'])
345 + and isset($post['author_rules_action'])) :
346 + if (isset($post['author_rules_name']['all'])) :
347 + if (strlen($post['author_rules_name']['all']) > 0) :
348 + $post['author_rules_name'] = array(
349 + 'all' => $post['author_rules_name']['all'],
403 350 );
404 -
351 +
405 352 // Erase all the rest.
406 353 endif;
407 354 endif;
408 -
355 +
409 356 unset($this->link->settings['map authors']);
410 - foreach ($author_rules_name as $key => $name) :
357 + foreach ($post['author_rules_name'] as $key => $name) :
411 358 // 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 ] );
359 + $name = strtolower(trim($name));
360 + $author_action = strtolower(trim($post['author_rules_action'][$key]));
361 +
362 + if (strlen($name) > 0) :
363 + if ('newuser' == $author_action) :
364 + $new_name = trim($post['author_rules_newuser'][$key]);
419 365 $this->link->map_name_to_new_user($name, $new_name);
420 366 else :
421 367 $this->link->settings['map authors']['name'][$name] = $author_action;
422 368 endif;
@@ -423,17 +369,16 @@
423 369 endif;
424 370 endforeach;
425 371 endif;
426 372
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 -
373 + if (isset($post['add_author_rule_name'])
374 + and isset($post['add_author_rule_action'])) :
375 + $name = strtolower(trim($post['add_author_rule_name']));
376 + $author_action = strtolower(trim($post['add_author_rule_action']));
377 +
433 378 if (strlen($name) > 0) :
434 379 if ('newuser' == $author_action) :
435 - $new_name = trim( FeedWordPress::post( 'add_author_rule_newuser' ));
380 + $new_name = trim($post['add_author_rule_newuser']);
436 381 $this->link->map_name_to_new_user($name, $new_name);
437 382 else :
438 383 $this->link->settings['map authors']['name'][$name] = $author_action;
439 384 endif;
@@ -438,41 +383,38 @@
438 383 $this->link->settings['map authors']['name'][$name] = $author_action;
439 384 endif;
440 385 endif;
441 386 endif;
442 -
443 387 else :
444 -
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 );
388 + if ('newuser'==$post['unfamiliar_author']) :
389 + $new_name = trim($post['unfamiliar_author_newuser']);
390 + $new_id = fwp_insert_new_user($new_name);
391 + if (is_numeric($new_id)) :
392 + update_option('feedwordpress_unfamiliar_author', $new_id);
451 393 else :
452 394 // TODO: Add some error detection and reporting
453 395 // Put WP_Error stuff into $this->mesg ?
454 396 endif;
455 397 else :
456 - update_option( 'feedwordpress_unfamiliar_author', $unfamiliar_author );
398 + update_option('feedwordpress_unfamiliar_author', $post['unfamiliar_author']);
457 399 endif;
458 400
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'
401 + update_option('feedwordpress_do_not_match_author_by_email',
402 + (isset($post['match_author_by_email'])
403 + and 'yes'==$post['match_author_by_email'])
404 + ? 'no'
405 + : 'yes'
463 406 );
464 407
465 - $null_emails = FeedWordPress::post( 'null_emails', null, 'textarea' );
466 - if ( ! is_null( $null_emails ) ) :
467 - update_option( 'feedwordpress_null_email_set', $null_emails );
408 + if (isset($post['null_emails'])) :
409 + update_option('feedwordpress_null_email_set', $post['null_emails']);
468 410 endif;
469 411 endif;
470 412
471 - parent::save_settings();
413 + parent::save_settings($post);
472 414 $this->refresh_author_list();
473 - } /* FeedWordPressAuthorsPage::save_settings() */
415 + }
416 +} /* class FeedWordPressAuthorsPage */
474 417
475 -} /* class FeedWordPressAuthorsPage */
418 + $authorsPage = new FeedWordPressAuthorsPage;
419 + $authorsPage->display();
476 420
477 -$authorsPage = new FeedWordPressAuthorsPage;
478 -$authorsPage->display();