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
feedwordpress / authors-page.php

authors-page.php in FeedWordPress 2022.0204, at authors-page.php

421 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(dirname(__FILE__) . '/admin-ui.php');
3
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();
11 endif;
12
13 parent::__construct('feedwordpressauthors', $link);
14 $this->refresh_author_list();
15 $this->dispatch = 'feedwordpress_author_settings';
16 $this->filename = __FILE__;
17
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();
27
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' => '');
35
36 if ($page->for_feed_settings()) :
37 $key = $this->link->setting('unfamiliar author', NULL, 'site-default');
38 $unfamiliar['site-default'] = '';
39 else :
40 $key = FeedWordPress::on_unfamiliar('author');
41 endif;
42 $unfamiliar[$key] = true;
43
44 $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
45 $null_emails = FeedWordPress::null_email_set();
46
47 // Hey ho, let's go...
48 ?>
49 <table class="form-table">
50 <?php
51 if ($page->for_default_settings()) :
52 ?>
53 <tr><th>Unmatched authors</th>
54 <td><span>Authors who haven&#8217;t been syndicated before</span>
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');">
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>
61 <?php endforeach; ?>
62 <option value="newuser">will have their posts attributed to a new user...</option>
63 <option value="filter"<?php fwp_selected_flag($unfamiliar, 'filter'); ?>>get filtered out</option>
64 </select>
65
66 <span id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></span></p>
67 </td>
68 </tr>
69
70 <?php
71 endif;
72
73 if ($page->for_feed_settings()) :
74 $map = $this->link->setting('map authors', NULL, array());
75 ?>
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
105 <table style="width: 100%">
106 <?php
107 if (isset($this->link->settings['map authors'])) :
108 ?>
109 <?php
110 $page->rule_count=0;
111 foreach ($this->link->settings['map authors'] as $author_rules) :
112 foreach ($author_rules as $author_name => $author_action) :
113 if ($author_name != '*') :
114 $page->rule_count++;
115 $authorRulesId = sanitize_html_class(sprintf("author-rules-%d", $page->rule_count));
116 ?>
117 <tr>
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>
119 <td>
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>
123 <?php endforeach; ?>
124 <option value="newuser">will be assigned to a new user...</option>
125 <option value="filter"<?php fwp_selected_flag('filter'==$author_action); ?>>get filtered out</option>
126 </select>
127
128 <span class="author-rules-newuser" id="<?php echo esc_attr($authorRulesId); ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span>
129 </td>
130 </tr>
131 <?php
132 endif;
133 endforeach;
134 endforeach;
135 endif;
136 ?>
137
138 <tr>
139 <th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th>
140 <td>
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');">
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>
144 <?php endforeach; ?>
145 <option value="newuser">will be assigned to a new user...</option>
146 <option value="filter">get filtered out</option>
147 </select>
148
149 <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span>
150 </td>
151 </tr>
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>
170 </td>
171 </tr>
172 </table></li>
173 </ul>
174
175 </td>
176 </tr>
177 <?php endif; ?>
178
179 <?php if ($page->for_default_settings()) : ?>
180 <tr>
181 <th scope="row">Matching Authors</th>
182 <td><ul style="list-style: none; margin: 0; padding: 0;">
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>
184 <div id="unless-null-email">
185 <p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
186 <textarea name="null_emails" rows="3" style="width: 100%">
187 <?php print esc_html(implode("\n", $null_emails)); ?>
188 </textarea>
189 </div></li>
190 </ul></td>
191 </tr>
192 <?php endif; ?>
193 </tbody>
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>
218
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 () */
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 ?>
239 <script type="text/javascript">
240 contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
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
249 contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
250 contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
251 </script>
252 <?php else : ?>
253 <script type="text/javascript">
254 contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
255 </script>
256 <?php endif;
257 } /* FeedWordPressAuthorsPage::display () */
258
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();
420
421