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

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