PluginProbe
FeedWordPress / 2011.0211.2
FeedWordPress v2011.0211.2
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 2011.0211.2, at authors-page.php

393 lines 14.7 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 function FeedWordPressAuthorsPage ($link = -1) {
9 if (is_numeric($link) and -1 == $link) :
10 $link = FeedWordPressAdminPage::submitted_link();
11 endif;
12
13 FeedWordPressAdminPage::FeedWordPressAdminPage('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
29 /*static*/ function syndicated_authors_box ($page, $box = NULL) {
30 $link = $page->link;
31 $unfamiliar = array ('create' => '','default' => '','filter' => '');
32
33 if ($page->for_feed_settings()) :
34 $key = $this->link->setting('unfamiliar author', NULL, 'site-default');
35 $unfamiliar['site-default'] = '';
36 else :
37 $key = FeedWordPress::on_unfamiliar('author');
38 endif;
39 $unfamiliar[$key] = ' selected="selected"';
40
41 $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
42 $null_emails = FeedWordPress::null_email_set();
43
44 // Hey ho, let's go...
45 ?>
46 <table class="form-table">
47 <?php
48 if ($page->for_feed_settings()) :
49 $map = $this->link->setting('map authors', NULL, array());
50 ?>
51 <tr><th>Matching authors</th>
52 <td><p>How should FeedWordPress attribute posts from this feed to WordPress
53 authors?</p>
54 <ul class="settings">
55 <li><p><input type="radio" name="author_rules_name[all]" value="*"
56 <?php if (isset($map['name']['*'])) : $author_action = $map['name']['*']; ?>
57 checked="checked"
58 <?php else : $author_action = NULL; ?>
59 <?php endif; ?>
60 /> All posts syndicated
61 from this feed <select class="author-rules" id="author-rules-all"
62 name="author_rules_action[all]" onchange="contextual_appearance('author-rules-all', 'author-rules-all-newuser', 'author-rules-all-default', 'newuser', 'inline');">
63 <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?>
64 <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>
65 <?php endforeach; ?>
66 <option value="newuser">will be assigned to a new user...</option>
67 <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option>
68 </select>
69 <span class="author-rules-newuser" id="author-rules-all-newuser">named
70 <input type="text" name="author_rules_newuser[all]" value="" /></span></p></li>
71 <li><p><input type="radio" name="author_rules_name[all]" value=""
72 <?php if (!isset($map['name']['*'])) : ?>
73 checked="checked"
74 <?php endif; ?>
75 /> Attribute posts to authors based on automatic mapping rules. (Blank out a
76 name to delete the rule. Fill in a new name at the bottom to create a new rule.)</p>
77
78 <table style="width: 100%">
79 <?php
80 if (isset($this->link->settings['map authors'])) :
81 ?>
82 <?php
83 $page->rule_count=0;
84 foreach ($this->link->settings['map authors'] as $author_rules) :
85 foreach ($author_rules as $author_name => $author_action) :
86 if ($author_name != '*') :
87 $page->rule_count++;
88 ?>
89 <tr>
90 <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>
91 <td>
92 <select class="author-rules" id="author-rules-<?php echo $page->rule_count; ?>" name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php echo $page->rule_count; ?>', 'author-rules-<?php echo $page->rule_count; ?>-newuser', 'author-rules-<?php echo $page->rule_count; ?>-default', 'newuser', 'inline');">
93 <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?>
94 <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>
95 <?php endforeach; ?>
96 <option value="newuser">will be assigned to a new user...</option>
97 <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option>
98 </select>
99
100 <span class="author-rules-newuser" id="author-rules-<?php echo $page->rule_count; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span>
101 </td>
102 </tr>
103 <?php
104 endif;
105 endforeach;
106 endforeach;
107 endif;
108 ?>
109
110 <tr>
111 <th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th>
112 <td>
113 <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');">
114 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
115 <option value="<?php echo $author_id; ?>">are assigned to <?php echo $author_name; ?></option>
116 <?php endforeach; ?>
117 <option value="newuser">will be assigned to a new user...</option>
118 <option value="filter">get filtered out</option>
119 </select>
120
121 <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span>
122 </td>
123 </tr>
124
125 <tr>
126 <th style="text-align: left; width: 15.0em">Unmatched authors</th>
127 <td>
128 <span>Authors who haven't been syndicated before</span>
129 <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');">
130 <?php if ($page->for_feed_settings()) : ?>
131 <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option>
132 <?php endif; ?>
133 <option value="create"<?php print $unfamiliar['create']; ?>>will have a new author account created for them</option>
134 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
135 <option value="<?php echo $author_id; ?>"<?php print (isset($unfamiliar[$author_id]) ? $unfamiliar[$author_id] : ''); ?>>will have their posts attributed to <?php echo $author_name; ?></option>
136 <?php endforeach; ?>
137 <option value="newuser">will have their posts attributed to a user named ...</option>
138 <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option>
139 </select>
140
141 <span id="unfamiliar-author-newuser"><input type="text" name="unfamiliar_author_newuser" value="" /></span></p>
142 </td>
143 </tr>
144 </table></li>
145 </ul>
146
147 </td>
148 </tr>
149 <?php endif; ?>
150
151 <?php if ($page->for_default_settings()) : ?>
152 <tr>
153 <th scope="row">Matching Authors</th>
154 <td><ul style="list-style: none; margin: 0; padding: 0;">
155 <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>
156 <div id="unless-null-email">
157 <p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
158 <textarea name="null_emails" rows="3" style="width: 100%">
159 <?php print implode("\n", $null_emails); ?>
160 </textarea>
161 </div></li>
162 </ul></td>
163 </tr>
164 <?php endif; ?>
165 </tbody>
166 </table>
167 <?php
168 } /* FeedWordPressAuthorsPage::syndicated_authors_box () */
169
170 /*static*/ function fix_authors_box ($page, $box = NULL) {
171 ?>
172 <table class="form-table">
173 <tbody>
174 <tr>
175 <th scope="row">Fixing mis-matched authors:</th>
176 <td><p style="margin: 0.5em 0px">Take all the posts from this feed attributed to
177 <select name="fix_mismatch_from">
178 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
179 <option value="<?php echo $author_id; ?>"><?php echo $author_name; ?></option>
180 <?php endforeach; ?>
181 </select>
182 and instead
183 <select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');">
184 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
185 <option value="<?php echo $author_id; ?>">re-assign them to <?php echo $author_name; ?></option>
186 <?php endforeach; ?>
187 <option value="newuser">re-assign them to a new user...</option>
188 <option value="filter">delete them</option>
189 </select>
190
191 <span id="fix-mismatch-to-newuser">named <input type="text" name="fix_mismatch_to_newuser" value="" /></span>
192 <input type="submit" class="button" name="fix_mismatch" value="Fix it!" />
193 </td>
194 </tr>
195 </tbody>
196 </table>
197 <?php
198 } /* FeedWordPressAuthorsPage::fix_authors_box () */
199
200 function display () {
201 $this->boxes_by_methods = array(
202 'syndicated_authors_box' => __('Syndicated Authors'),
203 'fix_authors_box' => __('Reassign Authors'),
204 );
205 if ($this->for_default_settings()) :
206 unset($this->boxes_by_methods['fix_authors_box']);
207 endif;
208
209 parent::display();
210 ?>
211 <script type="text/javascript">
212 contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
213 </script>
214
215 <?php if ($this->for_feed_settings()) : ?>
216 <script type="text/javascript">
217 jQuery('.author-rules').each ( function () {
218 contextual_appearance(this.id, this.id+'-newuser', this.id+'-default', 'newuser', 'inline');
219 } );
220
221 contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
222 contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
223 </script>
224 <?php else : ?>
225 <script type="text/javascript">
226 contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
227 </script>
228 <?php endif;
229 } /* FeedWordPressAuthorsPage::display () */
230
231 function accept_POST ($post) {
232 if (isset($post['fix_mismatch']) and (strlen($post['fix_mismatch']) > 0)) :
233 $this->fix_mismatch($post);
234 else :
235 parent::accept_POST($post);
236 endif;
237 }
238
239 function fix_mismatch ($post) {
240 global $wpdb;
241
242 if ('newuser'==$post['fix_mismatch_to']) :
243 $newuser_name = trim($post['fix_mismatch_to_newuser']);
244 $to = fwp_insert_new_user($newuser_name);
245 else :
246 $to = $post['fix_mismatch_to'];
247 endif;
248
249 $from = (int) $post['fix_mismatch_from'];
250 if (is_numeric($from)) :
251 // Make a list of all the items by this author
252 // syndicated from this feed...
253 $post_ids = $wpdb->get_col("
254 SELECT {$wpdb->posts}.id
255 FROM {$wpdb->posts}, {$wpdb->postmeta}
256 WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)
257 AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'
258 AND {$wpdb->postmeta}.meta_value = '{$this->link->id}'
259 AND {$wpdb->posts}.post_author = '{$from}'
260 ");
261
262 if (count($post_ids) > 0) :
263 $N = count($post_ids);
264 $posts = 'post'.(($N==1) ? '' : 's');
265
266 // Re-assign them all to the correct author
267 if (is_numeric($to)) : // re-assign to a particular user
268 $post_set = "(".implode(",", $post_ids).")";
269
270 // Getting the revisions too, if there are any
271 $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set";
272
273 $wpdb->query("
274 UPDATE {$wpdb->posts}
275 SET post_author='{$to}'
276 WHERE ({$wpdb->posts}.id IN $post_set
277 $parent_in_clause)
278 ");
279 $this->mesg = sprintf(__("Re-assigned %d ${posts}."), $N);
280
281 // ... and kill them all
282 elseif ('filter'==$to) :
283 foreach ($post_ids as $post_id) :
284 wp_delete_post($post_id);
285 endforeach;
286
287 $this->mesg = sprintf(__("Deleted %d ${posts}."), $N);
288 endif;
289 else :
290 $this->mesg = __("Couldn't find any posts that matched your criteria.");
291 endif;
292 endif;
293 $this->updated = false;
294 }
295
296 function save_settings ($post) {
297
298 if ($this->for_feed_settings()) :
299 $alter = array ();
300
301 // Unfamiliar author rule
302 if (isset($post["unfamiliar_author"])) :
303 if ('newuser'==$post['unfamiliar_author']) :
304 $new_name = trim($post["unfamiliar_author_newuser"]);
305 $this->link->map_name_to_new_user(/*name=*/ NULL, $new_name);
306 else :
307 $this->link->update_setting(
308 "unfamiliar author",
309 $post['unfamiliar_author'],
310 'site-default'
311 );
312 endif;
313 endif;
314
315 // Handle author mapping rules
316 if (isset($post['author_rules_name'])
317 and isset($post['author_rules_action'])) :
318 if (isset($post['author_rules_name']['all'])) :
319 if (strlen($post['author_rules_name']['all']) > 0) :
320 $post['author_rules_name'] = array(
321 'all' => $post['author_rules_name']['all'],
322 );
323
324 // Erase all the rest.
325 endif;
326 endif;
327
328 unset($this->link->settings['map authors']);
329 foreach ($post['author_rules_name'] as $key => $name) :
330 // Normalize for case and whitespace
331 $name = strtolower(trim($name));
332 $author_action = strtolower(trim($post['author_rules_action'][$key]));
333
334 if (strlen($name) > 0) :
335 if ('newuser' == $author_action) :
336 $new_name = trim($post['author_rules_newuser'][$key]);
337 $this->link->map_name_to_new_user($name, $new_name);
338 else :
339 $this->link->settings['map authors']['name'][$name] = $author_action;
340 endif;
341 endif;
342 endforeach;
343 endif;
344
345 if (isset($post['add_author_rule_name'])
346 and isset($post['add_author_rule_action'])) :
347 $name = strtolower(trim($post['add_author_rule_name']));
348 $author_action = strtolower(trim($post['add_author_rule_action']));
349
350 if (strlen($name) > 0) :
351 if ('newuser' == $author_action) :
352 $new_name = trim($post['add_author_rule_newuser']);
353 $this->link->map_name_to_new_user($name, $new_name);
354 else :
355 $this->link->settings['map authors']['name'][$name] = $author_action;
356 endif;
357 endif;
358 endif;
359 else :
360 if ('newuser'==$post['unfamiliar_author']) :
361 $new_name = trim($post['unfamiliar_author_newuser']);
362 $new_id = fwp_insert_new_user($new_name);
363 if (is_numeric($new_id)) :
364 update_option('feedwordpress_unfamiliar_author', $new_id);
365 else :
366 // TODO: Add some error detection and reporting
367 // Put WP_Error stuff into $this->mesg ?
368 endif;
369 else :
370 update_option('feedwordpress_unfamiliar_author', $post['unfamiliar_author']);
371 endif;
372
373 update_option('feedwordpress_do_not_match_author_by_email',
374 (isset($post['match_author_by_email'])
375 and 'yes'==$post['match_author_by_email'])
376 ? 'no'
377 : 'yes'
378 );
379
380 if (isset($post['null_emails'])) :
381 update_option('feedwordpress_null_email_set', $post['null_emails']);
382 endif;
383 endif;
384
385 parent::save_settings($post);
386 $this->refresh_author_list();
387 }
388 } /* class FeedWordPressAuthorsPage */
389
390 $authorsPage = new FeedWordPressAuthorsPage;
391 $authorsPage->display();
392
393