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 +338 -390 2009.0613 → 2022.0204 View file →
@@ -1,356 +1,67 @@
1 1 <?php
2 2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 3
4 -function fwp_authors_page () {
5 - global $wpdb, $wp_db_version;
6 -
7 - FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_author_settings', /*capability=*/ 'manage_links');
8 -
9 - if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) :
10 - $link_id = $_REQUEST['save_link_id'];
11 - elseif (isset($_REQUEST['link_id'])) :
12 - $link_id = $_REQUEST['link_id'];
13 - else :
14 - $link_id = NULL;
15 - endif;
16 -
17 - if (is_numeric($link_id) and $link_id) :
18 - $link =& new SyndicatedLink($link_id);
19 - else :
20 - $link = NULL;
21 - endif;
22 -
23 - $mesg = null;
24 -
25 - if (isset($GLOBALS['fwp_post']['fix_mismatch'])) :
26 - if ('newuser'==$GLOBALS['fwp_post']['fix_mismatch_to']) :
27 - $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_newuser']);
28 - if (strlen($newuser_name) > 0) :
29 - $userdata = array();
30 - $userdata['ID'] = NULL;
31 -
32 - $userdata['user_login'] = sanitize_user($newuser_name);
33 - $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
34 -
35 - $userdata['user_nicename'] = sanitize_title($newuser_name);
36 - $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
37 -
38 - $userdata['display_name'] = $wpdb->escape($newuser_name);
39 -
40 - $newuser_id = wp_insert_user($userdata);
41 - if (is_numeric($newuser_id)) :
42 - $fix_mismatch_to_id = $newuser_id;
43 - else :
44 - // TODO: Add some error detection and reporting
45 - endif;
46 - else :
47 - // TODO: Add some error reporting
48 - endif;
49 - else :
50 - $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to'];
4 +class FeedWordPressAuthorsPage extends FeedWordPressAdminPage {
5 + var $authorlist = NULL;
6 + var $rule_count = 0;
7 +
8 + public function __construct( $link = -1 ) {
9 + if (is_numeric($link) and -1 == $link) :
10 + $link = $this->submitted_link();
51 11 endif;
52 - $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from'];
53 - if (is_numeric($fix_mismatch_from_id)) :
54 - // Make a list of all the items by this author syndicated from this feed...
55 - $post_ids = $wpdb->get_col("
56 - SELECT {$wpdb->posts}.id
57 - FROM {$wpdb->posts}, {$wpdb->postmeta}
58 - WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)
59 - AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'
60 - AND {$wpdb->postmeta}.meta_value = '{$link_id}'
61 - AND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}'
62 - ");
63 -
64 - if (count($post_ids) > 0) :
65 - // Re-assign them all to the correct author
66 - if (is_numeric($fix_mismatch_to_id)) : // re-assign to a particular user
67 - $post_set = "(".implode(",", $post_ids).")";
68 -
69 - // Getting the revisions too, if there are any
70 - if (fwp_test_wp_version(FWP_SCHEMA_26)) :
71 - $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set";
72 - else :
73 - $parent_in_clause = '';
74 - endif;
75 -
76 - $wpdb->query("
77 - UPDATE {$wpdb->posts}
78 - SET post_author='{$fix_mismatch_to_id}'
79 - WHERE ({$wpdb->posts}.id IN $post_set
80 - $parent_in_clause)
81 - ");
82 - $mesg = "Re-assigned ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
83 12
84 - // ... and kill them all
85 - elseif ($fix_mismatch_to_id=='filter') :
86 - foreach ($post_ids as $post_id) :
87 - wp_delete_post($post_id);
88 - endforeach;
89 - $mesg = "Deleted ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
90 - endif;
91 - else :
92 - $mesg = "Couldn't find any posts that matched your criteria.";
93 - endif;
94 - endif;
95 - elseif (isset($GLOBALS['fwp_post']['save'])) :
96 - if (is_object($link) and $link->found()) :
97 - $alter = array ();
13 + parent::__construct('feedwordpressauthors', $link);
14 + $this->refresh_author_list();
15 + $this->dispatch = 'feedwordpress_author_settings';
16 + $this->filename = __FILE__;
98 17
99 - // Unfamiliar author rule
100 - if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) :
101 - if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
102 - unset($link->settings["unfamiliar author"]);
103 - elseif ('newuser'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
104 - $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]);
105 - $link->map_name_to_new_user(/*name=*/ NULL, $newuser_name);
106 - else :
107 - $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"];
108 - endif;
109 - endif;
110 -
111 - // Handle author mapping rules
112 - if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) :
113 - unset($link->settings['map authors']);
114 - foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) :
115 - // Normalize for case and whitespace
116 - $name = strtolower(trim($name));
117 - $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key]));
118 -
119 - if (strlen($name) > 0) :
120 - if ('newuser' == $author_action) :
121 - $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
122 - $link->map_name_to_new_user($name, $newuser_name);
123 - else :
124 - $link->settings['map authors']['name'][$name] = $author_action;
125 - endif;
126 - endif;
127 - endforeach;
128 - endif;
18 + $this->pagenames = array(
19 + 'default' => 'Authors',
20 + 'settings-update' => 'Syndicated Authors',
21 + 'open-sheet' => 'Syndicated Author',
22 + );
23 + }
24 +
25 + function refresh_author_list () {
26 + $this->authorlist = fwp_author_list();
129 27
130 - if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) :
131 - $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name']));
132 - $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action']));
133 - if (strlen($name) > 0) :
134 - if ('newuser' == $author_action) :
135 - $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
136 - $link->map_name_to_new_user($name, $newuser_name);
137 - else :
138 - $link->settings['map authors']['name'][$name] = $author_action;
139 - endif;
140 - endif;
141 - endif;
28 + // Case-insensitive "natural" alphanumeric sort. Preserves key/value associations.
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' => '');
142 35
143 - $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
144 -
145 - $alter_set = implode(", ", $alter);
146 -
147 - // issue update query
148 - $result = $wpdb->query("
149 - UPDATE $wpdb->links
150 - SET $alter_set
151 - WHERE link_id='$link_id'
152 - ");
153 - $updated_link = true;
154 -
155 - // reload link information from DB
156 - if (function_exists('clean_bookmark_cache')) :
157 - clean_bookmark_cache($link_id);
158 - endif;
159 - $link =& new SyndicatedLink($link_id);
36 + if ($page->for_feed_settings()) :
37 + $key = $this->link->setting('unfamiliar author', NULL, 'site-default');
38 + $unfamiliar['site-default'] = '';
160 39 else :
161 - if ('newuser'==$GLOBALS['fwp_post']['unfamiliar_author']) :
162 - $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']);
163 - if (strlen($newuser_name) > 0) :
164 - $userdata = array();
165 - $userdata['ID'] = NULL;
166 -
167 - $userdata['user_login'] = sanitize_user($newuser_name);
168 - $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
169 -
170 - $userdata['user_nicename'] = sanitize_title($newuser_name);
171 - $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
172 -
173 - $userdata['display_name'] = $wpdb->escape($newuser_name);
174 -
175 - $newuser_id = wp_insert_user($userdata);
176 - if (is_numeric($newuser_id)) :
177 - update_option('feedwordpress_unfamiliar_author', $newuser_id);
178 - else :
179 - // TODO: Add some error detection and reporting
180 - endif;
181 - else :
182 - // TODO: Add some error reporting
183 - endif;
184 - else :
185 - update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']);
186 - endif;
187 -
188 - if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email']=='yes') :
189 - update_option('feedwordpress_do_not_match_author_by_email', 'no');
190 - else :
191 - update_option('feedwordpress_do_not_match_author_by_email', 'yes');
192 - endif;
193 -
194 - if (isset($GLOBALS['fwp_post']['null_emails'])) :
195 - update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']);
196 - endif;
197 -
198 - $updated_link = true;
40 + $key = FeedWordPress::on_unfamiliar('author');
199 41 endif;
200 - else :
201 - $updated_link = false;
202 - endif;
42 + $unfamiliar[$key] = true;
203 43
204 - $unfamiliar = array ('create' => '','default' => '','filter' => '');
44 + $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
45 + $null_emails = FeedWordPress::null_email_set();
205 46
206 - if (is_object($link) and $link->found()) :
207 - if (is_string($link->settings["unfamiliar author"])) :
208 - $key = $link->settings["unfamiliar author"];
209 - else:
210 - $key = 'site-default';
211 - endif;
212 - else :
213 - $key = FeedWordPress::on_unfamiliar('author');
214 - endif;
215 -
216 - $unfamiliar[$key] = ' selected="selected"';
217 -
218 - $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
219 - $null_emails = FeedWordPress::null_email_set();
220 -?>
221 -<script type="text/javascript">
222 - function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
223 - if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
224 -
225 - var rollup=document.getElementById(item);
226 - var newuser=document.getElementById(appear);
227 - var sitewide=document.getElementById(disappear);
228 - if (rollup) {
229 - if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
230 - if (newuser) newuser.style.display=visibleStyle;
231 - if (sitewide) sitewide.style.display='none';
232 - } else {
233 - if (newuser) newuser.style.display='none';
234 - if (sitewide) sitewide.style.display=visibleStyle;
235 - }
236 - }
237 - }
238 -</script>
239 -
240 -<?php if ($updated_link) : ?>
241 -<div class="updated"><p>Syndicated author settings updated.</p></div>
242 -<?php elseif (!is_null($mesg)) : ?>
243 -<div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div>
244 -<?php endif; ?>
245 -
246 -<div class="wrap">
247 -<form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
248 -<div><?php
249 - FeedWordPressCompatibility::stamp_nonce('feedwordpress_author_settings');
250 -
251 - if (is_numeric($link_id) and $link_id) :
252 -?>
253 -<input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
47 + // Hey ho, let's go...
48 + ?>
49 +<table class="form-table">
254 50 <?php
255 - else :
51 +if ($page->for_default_settings()) :
256 52 ?>
257 -<input type="hidden" name="save_link_id" value="*" />
258 -<?php
259 - endif;
260 -?>
261 -</div>
262 -
263 -<?php $links = FeedWordPress::syndicated_links(); ?>
264 -<?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
265 - <div class="icon32"><img src="<?php print htmlspecialchars(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png'); ?>" alt="" /></div>
266 -<?php endif; ?>
267 -<h2>Syndicated Author Settings<?php if (!is_null($link) and $link->found()) : ?>: <?php echo wp_specialchars($link->link->link_name, 1); ?><?php endif; ?></h2>
268 -<?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
269 - <style type="text/css">
270 - #post-search {
271 - float: right;
272 - margin:11px 12px 0;
273 - min-width: 130px;
274 - position:relative;
275 - }
276 - .fwpfs {
277 - color: #dddddd;
278 - background:#797979 url(<?php bloginfo('home') ?>/wp-admin/images/fav.png) repeat-x scroll left center;
279 - border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px;
280 - -moz-border-radius-bottomright:12px;
281 - -moz-border-radius-topleft:12px;
282 - -moz-border-radius-topright:12px;
283 - border-style:solid;
284 - border-width:1px;
285 - line-height:15px;
286 - padding:3px 30px 4px 12px;
287 - }
288 - .fwpfs.slide-down {
289 - border-bottom-color: #626262;
290 - -moz-border-radius-bottomleft:0;
291 - -moz-border-radius-bottomright:0;
292 - -moz-border-radius-topleft:12px;
293 - -moz-border-radius-topright:12px;
294 - background-image:url(<?php bloginfo('home') ?>/wp-admin/images/fav-top.png);
295 - background-position:0 top;
296 - background-repeat:repeat-x;
297 - border-bottom-style:solid;
298 - border-bottom-width:1px;
299 - }
300 - </style>
301 -
302 - <script type="text/javascript">
303 - jQuery(document).ready(function($){
304 - $('.fwpfs').toggle(
305 - function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
306 - function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
307 - );
308 - $('.fwpfs').bind(
309 - 'change',
310 - function () { this.form.submit(); }
311 - );
312 - $('#post-search .button').css( 'display', 'none' );
313 - });
314 - </script>
315 -<?php endif; /* else : */?>
316 -<p id="post-search">
317 -<select name="link_id" class="fwpfs" style="max-width: 20.0em;">
318 - <option value="*"<?php if (is_null($link) or !$link->found()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
319 -<?php if ($links) : foreach ($links as $ddlink) : ?>
320 - <option value="<?php print (int) $ddlink->link_id; ?>"<?php if (!is_null($link) and ($link->link->link_id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print wp_specialchars($ddlink->link_name, 1); ?></option>
321 -<?php endforeach; endif; ?>
322 -</select>
323 -<input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" />
324 -</p>
325 -<?php /* endif; */ ?>
326 -
327 -<?php if (!is_null($link) and $link->found()) : ?>
328 - <p>These settings only affect posts syndicated from
329 - <strong><?php echo wp_specialchars($link->link->link_name, 1); ?></strong>.</p>
330 -<?php else : ?>
331 - <p>These settings affect posts syndicated from any feed unless they are overridden
332 - by settings for that specific feed.</p>
333 -<?php endif; ?>
334 -
335 -<?php
336 - $authorlist = fwp_author_list();
337 -?>
338 -<table class="form-table">
339 -<tbody>
340 -<tr>
341 - <th>New authors</th>
342 - <td><span>Authors who haven't been syndicated before</span>
53 +<tr><th>Unmatched authors</th>
54 +<td><span>Authors who haven&#8217;t been syndicated before</span>
343 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');">
344 -<?php if (is_object($link) and $link->found()) : ?>
345 - <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option>
346 -<?php endif; ?>
347 - <option value="create"<?php $unfamiliar['create']; ?>>will have a new author account created for them</option>
348 - <?php foreach ($authorlist as $author_id => $author_name) : ?>
349 - <option value="<?php echo $author_id; ?>"<?php print $unfamiliar[$author_id]; ?>>will have their posts attributed to <?php echo $author_name; ?></option>
56 + <option value="create"<?php fwp_selected_flag($unfamiliar, 'create'); ?>>will have a new author account created for them</option>
57 + <?php foreach ($page->authorlist as $author_id => $author_name) :
58 + if (!isset($unfamiliar[$author_id])) : $unfamiliar[$author_id] = false; endif;
59 + ?>
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>
350 61 <?php endforeach; ?>
351 62 <option value="newuser">will have their posts attributed to a new user...</option>
352 - <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option>
63 + <option value="filter"<?php fwp_selected_flag($unfamiliar, 'filter'); ?>>get filtered out</option>
353 64 </select>
354 65
355 66 <span id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></span></p>
356 67 </td>
@@ -356,37 +67,71 @@
356 67 </td>
357 68 </tr>
358 69
359 70 <?php
360 -if (is_object($link) and $link->found()) :
71 +endif;
72 +
73 +if ($page->for_feed_settings()) :
74 + $map = $this->link->setting('map authors', NULL, array());
361 75 ?>
362 -<tr><th>Syndicated authors</th>
363 -<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>
76 +<tr><th>Matching authors</th>
77 +<td><p>How should FeedWordPress attribute posts from this feed to WordPress
78 +authors?</p>
79 +<ul class="settings">
80 +<li><p><input type="radio" name="author_rules_name[all]" value="*"
81 +<?php if (isset($map['name']['*'])) : $author_action = $map['name']['*']; ?>
82 + checked="checked"
83 +<?php
84 + else :
85 + $author_action = NULL;
86 + endif; ?>
87 + /> All posts syndicated
88 +from this feed <select class="author-rules" id="author-rules-all"
89 +name="author_rules_action[all]" onchange="contextual_appearance('author-rules-all', 'author-rules-all-newuser', 'author-rules-all-default', 'newuser', 'inline');">
90 + <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?>
91 + <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>
92 + <?php endforeach; ?>
93 + <option value="newuser">will be assigned to a new user...</option>
94 + <option value="filter"<?php fwp_selected_flag('filter'==$author_action); ?>>get filtered out</option>
95 + </select>
96 + <span class="author-rules-newuser" id="author-rules-all-newuser">named
97 + <input type="text" name="author_rules_newuser[all]" value="" /></span></p></li>
98 +<li><p><input type="radio" name="author_rules_name[all]" value=""
99 +<?php if (!isset($map['name']['*'])) : ?>
100 + checked="checked"
101 +<?php endif; ?>
102 +/> Attribute posts to authors based on automatic mapping rules. (Blank out a
103 +name to delete the rule. Fill in a new name at the bottom to create a new rule.)</p>
104 +
364 105 <table style="width: 100%">
365 106 <?php
366 - if (isset($link->settings['map authors'])) :
107 + if (isset($this->link->settings['map authors'])) :
367 108 ?>
368 109 <?php
369 - $i=0;
370 - foreach ($link->settings['map authors'] as $author_rules) :
110 + $page->rule_count=0;
111 + foreach ($this->link->settings['map authors'] as $author_rules) :
371 112 foreach ($author_rules as $author_name => $author_action) :
372 - $i++;
113 + if ($author_name != '*') :
114 + $page->rule_count++;
115 + $authorRulesId = sanitize_html_class(sprintf("author-rules-%d", $page->rule_count));
373 116 ?>
374 117 <tr>
375 -<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>
118 +<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>
376 119 <td>
377 - <select id="author-rules-<?php echo $i; ?>" name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php echo $i; ?>', 'author-rules-<?php echo $i; ?>-newuser', 'author-rules-<?php echo $i; ?>-default', 'newuser', 'inline');">
378 - <?php foreach ($authorlist as $local_author_id => $local_author_name) : ?>
379 - <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>
120 + <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');">
121 + <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?>
122 + <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>
380 123 <?php endforeach; ?>
381 124 <option value="newuser">will be assigned to a new user...</option>
382 - <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option>
125 + <option value="filter"<?php fwp_selected_flag('filter'==$author_action); ?>>get filtered out</option>
383 126 </select>
384 127
385 - <span id="author-rules-<?php echo $i; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span>
128 + <span class="author-rules-newuser" id="<?php echo esc_attr($authorRulesId); ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span>
386 129 </td>
387 130 </tr>
388 -<?php endforeach;
131 +<?php
132 + endif;
133 + endforeach;
389 134 endforeach;
390 135 endif;
391 136 ?>
392 137
@@ -393,10 +138,10 @@
393 138 <tr>
394 139 <th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th>
395 140 <td>
396 141 <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');">
397 - <?php foreach ($authorlist as $author_id => $author_name) : ?>
398 - <option value="<?php echo $author_id; ?>">are assigned to <?php echo $author_name; ?></option>
142 + <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
143 + <option value="<?php echo esc_attr($author_id); ?>">are assigned to <?php echo esc_html($author_name); ?></option>
399 144 <?php endforeach; ?>
400 145 <option value="newuser">will be assigned to a new user...</option>
401 146 <option value="filter">get filtered out</option>
402 147 </select>
@@ -403,70 +148,273 @@
403 148
404 149 <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span>
405 150 </td>
406 151 </tr>
407 -</table>
152 +
153 +<tr>
154 +<th style="text-align: left; width: 15.0em">Unmatched authors</th>
155 +<td>
156 +<span>Authors who haven't been syndicated before</span>
157 + <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');">
158 +<?php if ($page->for_feed_settings()) : ?>
159 + <option value="site-default"<?php fwp_selected_flag($unfamiliar, 'site-default'); ?>>are handled according to the default for all feeds</option>
160 +<?php endif; ?>
161 + <option value="create"<?php fwp_selected_flag($unfamiliar, 'create'); ?>>will have a new author account created for them</option>
162 + <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
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>
164 + <?php endforeach; ?>
165 + <option value="newuser">will have their posts attributed to a user named ...</option>
166 + <option value="filter"<?php fwp_selected_flag($unfamiliar, 'filter'); ?>>get filtered out</option>
167 + </select>
168 +
169 + <span id="unfamiliar-author-newuser"><input type="text" name="unfamiliar_author_newuser" value="" /></span></p>
408 170 </td>
409 171 </tr>
172 +</table></li>
173 +</ul>
174 +
175 +</td>
176 +</tr>
410 177 <?php endif; ?>
411 178
412 -<?php if (!(is_object($link) and $link->found())) : ?>
179 +<?php if ($page->for_default_settings()) : ?>
413 180 <tr>
414 181 <th scope="row">Matching Authors</th>
415 182 <td><ul style="list-style: none; margin: 0; padding: 0;">
416 -<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>
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>
417 184 <div id="unless-null-email">
418 185 <p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
419 186 <textarea name="null_emails" rows="3" style="width: 100%">
420 -<?php print implode("\n", $null_emails); ?>
187 +<?php print esc_html(implode("\n", $null_emails)); ?>
421 188 </textarea>
422 189 </div></li>
423 190 </ul></td>
424 191 </tr>
425 -<?php else : ?>
426 -<th scope="row">Fixing mis-matched authors:</th>
427 -<td><p style="margin: 0.5em 0px">Take all the posts from this feed attributed to
428 -<select name="fix_mismatch_from">
429 -<?php foreach ($authorlist as $author_id => $author_name) : ?>
430 - <option value="<?php echo $author_id; ?>"><?php echo $author_name; ?></option>
431 -<?php endforeach; ?>
432 -</select>
433 -and instead
434 -<select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');">
435 -<?php foreach ($authorlist as $author_id => $author_name) : ?>
436 - <option value="<?php echo $author_id; ?>">re-assign them to <?php echo $author_name; ?></option>
437 -<?php endforeach; ?>
438 - <option value="newuser">re-assign them to a new user...</option>
439 - <option value="filter">delete them</option>
440 -</select>
441 -
442 - <span id="fix-mismatch-to-newuser">named <input type="text" name="fix_mismatch_to_newuser" value="" /></span>
443 - <input type="submit" class="button" name="fix_mismatch" value="Fix it!" />
444 - </td>
445 -</td>
446 192 <?php endif; ?>
447 193 </tbody>
448 194 </table>
195 + <?php
196 + } /* FeedWordPressAuthorsPage::syndicated_authors_box () */
197 +
198 + /*static*/ function fix_authors_box ($page, $box = NULL) {
199 + ?>
200 + <table class="form-table">
201 + <tbody>
202 + <tr>
203 + <th scope="row">Fixing mis-matched authors:</th>
204 + <td><p style="margin: 0.5em 0px">Take all the posts from this feed attributed to
205 + <select name="fix_mismatch_from">
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>
208 + <?php endforeach; ?>
209 + </select>
210 + and instead
211 + <select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');">
212 + <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
213 + <option value="<?php echo esc_attr($author_id); ?>">re-assign them to <?php echo esc_html($author_name); ?></option>
214 + <?php endforeach; ?>
215 + <option value="newuser">re-assign them to a new user...</option>
216 + <option value="filter">delete them</option>
217 + </select>
449 218
450 -<p class="submit">
451 -<input class="button-primary" type="submit" name="save" value="Save Changes" />
452 -</p>
219 + <span id="fix-mismatch-to-newuser">named <input type="text" name="fix_mismatch_to_newuser" value="" /></span>
220 + <input type="submit" class="button" name="fix_mismatch" value="Fix it!" />
221 + </td>
222 + </tr>
223 + </tbody>
224 + </table>
225 + <?php
226 + } /* FeedWordPressAuthorsPage::fix_authors_box () */
453 227
228 + function display () {
229 + $this->boxes_by_methods = array(
230 + 'syndicated_authors_box' => __('Syndicated Authors'),
231 + 'fix_authors_box' => __('Reassign Authors'),
232 + );
233 + if ($this->for_default_settings()) :
234 + unset($this->boxes_by_methods['fix_authors_box']);
235 + endif;
236 +
237 + parent::display();
238 + ?>
454 239 <script type="text/javascript">
455 240 contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
456 -<?php if (is_object($link) and $link->found()) : ?>
457 -<?php for ($j=1; $j<=$i; $j++) : ?>
458 - contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline');
459 -<?php endfor; ?>
241 +</script>
242 +
243 +<?php if ($this->for_feed_settings()) : ?>
244 +<script type="text/javascript">
245 + jQuery('.author-rules').each ( function () {
246 + contextual_appearance(this.id, this.id+'-newuser', this.id+'-default', 'newuser', 'inline');
247 + } );
248 +
460 249 contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
461 250 contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
462 -<?php else : ?>
251 +</script>
252 +<?php else : ?>
253 +<script type="text/javascript">
463 254 contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
464 -<?php endif; ?>
465 255 </script>
466 -</form>
467 -</div> <!-- class="wrap" -->
468 -<?php
469 -} /* function fwp_authors_page () */
256 +<?php endif;
257 + } /* FeedWordPressAuthorsPage::display () */
470 258
471 - fwp_authors_page();
259 + function accept_POST ($post) {
260 + if (isset($post['fix_mismatch']) and (strlen($post['fix_mismatch']) > 0)) :
261 + $this->fix_mismatch($post);
262 + else :
263 + parent::accept_POST($post);
264 + endif;
265 + }
266 +
267 + function fix_mismatch ($post) {
268 + global $wpdb;
269 +
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'];
275 + endif;
276 +
277 + $from = (int) $post['fix_mismatch_from'];
278 + if (is_numeric($from)) :
279 + // Make a list of all the items by this author
280 + // syndicated from this feed...
281 + $post_ids = $wpdb->get_col("
282 + SELECT {$wpdb->posts}.id
283 + FROM {$wpdb->posts}, {$wpdb->postmeta}
284 + WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)
285 + AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'
286 + AND {$wpdb->postmeta}.meta_value = '{$this->link->id}'
287 + AND {$wpdb->posts}.post_author = '{$from}'
288 + ");
289 +
290 + if (count($post_ids) > 0) :
291 + $N = count($post_ids);
292 + $posts = 'post'.(($N==1) ? '' : 's');
293 +
294 + // Re-assign them all to the correct author
295 + if (is_numeric($to)) : // re-assign to a particular user
296 + $post_set = "(".implode(",", $post_ids).")";
297 +
298 + // Getting the revisions too, if there are any
299 + $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set";
300 +
301 + $wpdb->query("
302 + UPDATE {$wpdb->posts}
303 + SET post_author='{$to}'
304 + WHERE ({$wpdb->posts}.id IN $post_set
305 + $parent_in_clause)
306 + ");
307 + $this->mesg = sprintf(__("Re-assigned %d ${posts}."), $N);
308 +
309 + // ... and kill them all
310 + elseif ('filter'==$to) :
311 + foreach ($post_ids as $post_id) :
312 + wp_delete_post($post_id);
313 + endforeach;
314 +
315 + $this->mesg = sprintf(__("Deleted %d ${posts}."), $N);
316 + endif;
317 + else :
318 + $this->mesg = __("Couldn't find any posts that matched your criteria.");
319 + endif;
320 + endif;
321 + $this->updated = false;
322 + }
323 +
324 + function save_settings ($post) {
325 +
326 + if ($this->for_feed_settings()) :
327 + $alter = array ();
328 +
329 + // Unfamiliar author rule
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);
334 + else :
335 + $this->link->update_setting(
336 + "unfamiliar author",
337 + $post['unfamiliar_author'],
338 + 'site-default'
339 + );
340 + endif;
341 + endif;
342 +
343 + // Handle author mapping rules
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'],
350 + );
351 +
352 + // Erase all the rest.
353 + endif;
354 + endif;
355 +
356 + unset($this->link->settings['map authors']);
357 + foreach ($post['author_rules_name'] as $key => $name) :
358 + // Normalize for case and whitespace
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]);
365 + $this->link->map_name_to_new_user($name, $new_name);
366 + else :
367 + $this->link->settings['map authors']['name'][$name] = $author_action;
368 + endif;
369 + endif;
370 + endforeach;
371 + endif;
372 +
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 +
378 + if (strlen($name) > 0) :
379 + if ('newuser' == $author_action) :
380 + $new_name = trim($post['add_author_rule_newuser']);
381 + $this->link->map_name_to_new_user($name, $new_name);
382 + else :
383 + $this->link->settings['map authors']['name'][$name] = $author_action;
384 + endif;
385 + endif;
386 + endif;
387 + else :
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);
393 + else :
394 + // TODO: Add some error detection and reporting
395 + // Put WP_Error stuff into $this->mesg ?
396 + endif;
397 + else :
398 + update_option('feedwordpress_unfamiliar_author', $post['unfamiliar_author']);
399 + endif;
400 +
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'
406 + );
407 +
408 + if (isset($post['null_emails'])) :
409 + update_option('feedwordpress_null_email_set', $post['null_emails']);
410 + endif;
411 + endif;
412 +
413 + parent::save_settings($post);
414 + $this->refresh_author_list();
415 + }
416 +} /* class FeedWordPressAuthorsPage */
417 +
418 + $authorsPage = new FeedWordPressAuthorsPage;
419 + $authorsPage->display();
472 420