PluginProbe
FeedWordPress / 2010.0528
FeedWordPress v2010.0528
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 2010.0528, at authors-page.php

426 lines 16.3 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) {
9 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressauthors', $link);
10 $this->authorlist = fwp_author_list();
11 $this->dispatch = 'feedwordpress_author_settings';
12 $this->filename = __FILE__;
13 }
14
15 /*static*/ function syndicated_authors_box ($page, $box = NULL) {
16 $link = $page->link;
17 $unfamiliar = array ('create' => '','default' => '','filter' => '');
18
19 if ($page->for_feed_settings()) :
20 if (is_string($link->settings["unfamiliar author"])) :
21 $key = $link->settings["unfamiliar author"];
22 else:
23 $key = 'site-default';
24 endif;
25 else :
26 $key = FeedWordPress::on_unfamiliar('author');
27 endif;
28 $unfamiliar[$key] = ' selected="selected"';
29
30 $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
31 $null_emails = FeedWordPress::null_email_set();
32
33 // Hey ho, let's go...
34 ?>
35 <table class="form-table">
36 <tbody>
37 <tr>
38 <th>New authors</th>
39 <td><span>Authors who haven't been syndicated before</span>
40 <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');">
41 <?php if ($page->for_feed_settings()) : ?>
42 <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option>
43 <?php endif; ?>
44 <option value="create"<?php $unfamiliar['create']; ?>>will have a new author account created for them</option>
45 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
46 <option value="<?php echo $author_id; ?>"<?php print $unfamiliar[$author_id]; ?>>will have their posts attributed to <?php echo $author_name; ?></option>
47 <?php endforeach; ?>
48 <option value="newuser">will have their posts attributed to a new user...</option>
49 <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option>
50 </select>
51
52 <span id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></span></p>
53 </td>
54 </tr>
55
56 <?php
57 if ($page->for_feed_settings()) :
58 ?>
59 <tr><th>Syndicated authors</th>
60 <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>
61 <table style="width: 100%">
62 <?php
63 if (isset($link->settings['map authors'])) :
64 ?>
65 <?php
66 $page->rule_count=0;
67 foreach ($link->settings['map authors'] as $author_rules) :
68 foreach ($author_rules as $author_name => $author_action) :
69 $page->rule_count++;
70 ?>
71 <tr>
72 <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>
73 <td>
74 <select 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');">
75 <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?>
76 <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>
77 <?php endforeach; ?>
78 <option value="newuser">will be assigned to a new user...</option>
79 <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option>
80 </select>
81
82 <span id="author-rules-<?php echo $page->rule_count; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span>
83 </td>
84 </tr>
85 <?php endforeach;
86 endforeach;
87 endif;
88 ?>
89
90 <tr>
91 <th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th>
92 <td>
93 <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');">
94 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
95 <option value="<?php echo $author_id; ?>">are assigned to <?php echo $author_name; ?></option>
96 <?php endforeach; ?>
97 <option value="newuser">will be assigned to a new user...</option>
98 <option value="filter">get filtered out</option>
99 </select>
100
101 <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span>
102 </td>
103 </tr>
104 </table>
105 </td>
106 </tr>
107 <?php endif; ?>
108
109 <?php if ($page->for_default_settings()) : ?>
110 <tr>
111 <th scope="row">Matching Authors</th>
112 <td><ul style="list-style: none; margin: 0; padding: 0;">
113 <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>
114 <div id="unless-null-email">
115 <p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
116 <textarea name="null_emails" rows="3" style="width: 100%">
117 <?php print implode("\n", $null_emails); ?>
118 </textarea>
119 </div></li>
120 </ul></td>
121 </tr>
122 <?php endif; ?>
123 </tbody>
124 </table>
125 <?php
126 } /* FeedWordPressAuthorsPage::syndicated_authors_box () */
127
128 /*static*/ function fix_authors_box ($page, $box = NULL) {
129 ?>
130 <table class="form-table">
131 <tbody>
132 <tr>
133 <th scope="row">Fixing mis-matched authors:</th>
134 <td><p style="margin: 0.5em 0px">Take all the posts from this feed attributed to
135 <select name="fix_mismatch_from">
136 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
137 <option value="<?php echo $author_id; ?>"><?php echo $author_name; ?></option>
138 <?php endforeach; ?>
139 </select>
140 and instead
141 <select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');">
142 <?php foreach ($page->authorlist as $author_id => $author_name) : ?>
143 <option value="<?php echo $author_id; ?>">re-assign them to <?php echo $author_name; ?></option>
144 <?php endforeach; ?>
145 <option value="newuser">re-assign them to a new user...</option>
146 <option value="filter">delete them</option>
147 </select>
148
149 <span id="fix-mismatch-to-newuser">named <input type="text" name="fix_mismatch_to_newuser" value="" /></span>
150 <input type="submit" class="button" name="fix_mismatch" value="Fix it!" />
151 </td>
152 </tr>
153 </tbody>
154 </table>
155 <?php
156 } /* FeedWordPressAuthorsPage::fix_authors_box () */
157 } /* class FeedWordPressAuthorsPage */
158
159 function fwp_authors_page () {
160 global $wpdb, $wp_db_version;
161
162 if (FeedWordPress::needs_upgrade()) :
163 fwp_upgrade_page();
164 return;
165 endif;
166
167 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_author_settings', /*capability=*/ 'manage_links');
168
169 $link = FeedWordPressAdminPage::submitted_link();
170 $link_id = $link->id;
171 $authorsPage = new FeedWordPressAuthorsPage($link);
172
173 $mesg = null;
174
175 if (isset($GLOBALS['fwp_post']['fix_mismatch'])) :
176 if ('newuser'==$GLOBALS['fwp_post']['fix_mismatch_to']) :
177 $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_newuser']);
178 if (strlen($newuser_name) > 0) :
179 $userdata = array();
180 $userdata['ID'] = NULL;
181
182 $userdata['user_login'] = sanitize_user($newuser_name);
183 $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
184
185 $userdata['user_nicename'] = sanitize_title($newuser_name);
186 $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
187
188 $userdata['display_name'] = $wpdb->escape($newuser_name);
189
190 $newuser_id = wp_insert_user($userdata);
191 if (is_numeric($newuser_id)) :
192 $fix_mismatch_to_id = $newuser_id;
193 else :
194 // TODO: Add some error detection and reporting
195 endif;
196 else :
197 // TODO: Add some error reporting
198 endif;
199 else :
200 $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to'];
201 endif;
202 $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from'];
203 if (is_numeric($fix_mismatch_from_id)) :
204 // Make a list of all the items by this author syndicated from this feed...
205 $post_ids = $wpdb->get_col("
206 SELECT {$wpdb->posts}.id
207 FROM {$wpdb->posts}, {$wpdb->postmeta}
208 WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)
209 AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'
210 AND {$wpdb->postmeta}.meta_value = '{$link_id}'
211 AND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}'
212 ");
213
214 if (count($post_ids) > 0) :
215 // Re-assign them all to the correct author
216 if (is_numeric($fix_mismatch_to_id)) : // re-assign to a particular user
217 $post_set = "(".implode(",", $post_ids).")";
218
219 // Getting the revisions too, if there are any
220 if (fwp_test_wp_version(FWP_SCHEMA_26)) :
221 $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set";
222 else :
223 $parent_in_clause = '';
224 endif;
225
226 $wpdb->query("
227 UPDATE {$wpdb->posts}
228 SET post_author='{$fix_mismatch_to_id}'
229 WHERE ({$wpdb->posts}.id IN $post_set
230 $parent_in_clause)
231 ");
232 $mesg = "Re-assigned ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
233
234 // ... and kill them all
235 elseif ($fix_mismatch_to_id=='filter') :
236 foreach ($post_ids as $post_id) :
237 wp_delete_post($post_id);
238 endforeach;
239 $mesg = "Deleted ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
240 endif;
241 else :
242 $mesg = "Couldn't find any posts that matched your criteria.";
243 endif;
244 endif;
245 elseif (isset($GLOBALS['fwp_post']['save'])) :
246 if (is_object($link) and $link->found()) :
247 $alter = array ();
248
249 // Unfamiliar author rule
250 if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) :
251 if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
252 unset($link->settings["unfamiliar author"]);
253 elseif ('newuser'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
254 $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]);
255 $link->map_name_to_new_user(/*name=*/ NULL, $newuser_name);
256 else :
257 $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"];
258 endif;
259 endif;
260
261 // Handle author mapping rules
262 if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) :
263 unset($link->settings['map authors']);
264 foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) :
265 // Normalize for case and whitespace
266 $name = strtolower(trim($name));
267 $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key]));
268
269 if (strlen($name) > 0) :
270 if ('newuser' == $author_action) :
271 $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
272 $link->map_name_to_new_user($name, $newuser_name);
273 else :
274 $link->settings['map authors']['name'][$name] = $author_action;
275 endif;
276 endif;
277 endforeach;
278 endif;
279
280 if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) :
281 $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name']));
282 $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action']));
283 if (strlen($name) > 0) :
284 if ('newuser' == $author_action) :
285 $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
286 $link->map_name_to_new_user($name, $newuser_name);
287 else :
288 $link->settings['map authors']['name'][$name] = $author_action;
289 endif;
290 endif;
291 endif;
292
293 // Save settings
294 $link->save_settings(/*reload=*/ true);
295 $updated_link = true;
296
297 // Reset, reload
298 unset($link);
299 $link = new SyndicatedLink($link_id);
300 else :
301 if ('newuser'==$GLOBALS['fwp_post']['unfamiliar_author']) :
302 $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']);
303 if (strlen($newuser_name) > 0) :
304 $userdata = array();
305 $userdata['ID'] = NULL;
306
307 $userdata['user_login'] = sanitize_user($newuser_name);
308 $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
309
310 $userdata['user_nicename'] = sanitize_title($newuser_name);
311 $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
312
313 $userdata['display_name'] = $wpdb->escape($newuser_name);
314
315 $newuser_id = wp_insert_user($userdata);
316 if (is_numeric($newuser_id)) :
317 update_option('feedwordpress_unfamiliar_author', $newuser_id);
318 else :
319 // TODO: Add some error detection and reporting
320 endif;
321 else :
322 // TODO: Add some error reporting
323 endif;
324 else :
325 update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']);
326 endif;
327
328 if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email']=='yes') :
329 update_option('feedwordpress_do_not_match_author_by_email', 'no');
330 else :
331 update_option('feedwordpress_do_not_match_author_by_email', 'yes');
332 endif;
333
334 if (isset($GLOBALS['fwp_post']['null_emails'])) :
335 update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']);
336 endif;
337
338 $updated_link = true;
339 endif;
340
341 do_action('feedwordpress_admin_page_authors_save', $GLOBALS['fwp_post'], $authorsPage);
342 else :
343 $updated_link = false;
344 endif;
345
346 ////////////////////////////////////////////////
347 // Prepare settings page ///////////////////////
348 ////////////////////////////////////////////////
349
350 if ($updated_link) :
351 ?>
352 <div class="updated"><p>Syndicated author settings updated.</p></div>
353 <?php elseif (!is_null($mesg)) : ?>
354 <div class="updated"><p><?php print esc_html($mesg); ?></p></div>
355 <?php endif;
356
357 if (function_exists('add_meta_box')) :
358 add_action(
359 FeedWordPressCompatibility::bottom_script_hook(__FILE__),
360 /*callback=*/ array($authorsPage, 'fix_toggles'),
361 /*priority=*/ 10000
362 );
363 FeedWordPressSettingsUI::ajax_nonce_fields();
364 endif;
365
366 $authorsPage->open_sheet('Syndicated Author');
367 ?>
368 <div id="post-body">
369 <?php
370 ////////////////////////////////////////////////
371 // Display settings boxes //////////////////////
372 ////////////////////////////////////////////////
373
374 $boxes_by_methods = array(
375 'syndicated_authors_box' => __('Syndicated Authors'),
376 'fix_authors_box' => __('Reassign Authors'),
377 );
378 if ($authorsPage->for_default_settings()) :
379 unset($boxes_by_methods['fix_authors_box']);
380 endif;
381
382 foreach ($boxes_by_methods as $method => $row) :
383 if (is_array($row)) :
384 $id = $row['id'];
385 $title = $row['title'];
386 else :
387 $id = 'feedwordpress_'.$method;
388 $title = $row;
389 endif;
390
391 fwp_add_meta_box(
392 /*id=*/ $id,
393 /*title=*/ $title,
394 /*callback=*/ array('FeedWordPressAuthorsPage', $method),
395 /*page=*/ $authorsPage->meta_box_context(),
396 /*context=*/ $authorsPage->meta_box_context()
397 );
398 endforeach;
399 do_action('feedwordpress_admin_page_authors_meta_boxes', $authorsPage);
400 ?>
401 <div class="metabox-holder">
402 <?php
403 fwp_do_meta_boxes($authorsPage->meta_box_context(), $authorsPage->meta_box_context(), $authorsPage);
404 ?>
405 </div> <!-- class="metabox-holder" -->
406 </div> <!-- id="post-body" -->
407 <?php $authorsPage->close_sheet(); ?>
408
409 <script type="text/javascript">
410 contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
411 <?php if (is_object($link) and $link->found()) : ?>
412 <?php for ($j=1; $j<=$authorsPage->rule_count; $j++) : ?>
413 contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline');
414 <?php endfor; ?>
415 contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
416 contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
417 <?php else : ?>
418 contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
419 <?php endif; ?>
420 </script>
421 <?php
422 } /* function fwp_authors_page () */
423
424 fwp_authors_page();
425
426