PluginProbe
FeedWordPress / 2008.1214
FeedWordPress v2008.1214
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.php

authors.php in FeedWordPress 2008.1214, at authors.php

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