PluginProbe
FeedWordPress / 2008.1105
FeedWordPress v2008.1105
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.1105, at authors.php

413 lines 16.6 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 $link =& new SyndicatedLink($link_id);
159 else :
160 if ('newuser'==$GLOBALS['fwp_post']['unfamiliar_author']) :
161 $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']);
162 if (strlen($newuser_name) > 0) :
163 $userdata = array();
164 $userdata['ID'] = NULL;
165
166 $userdata['user_login'] = sanitize_user($newuser_name);
167 $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
168
169 $userdata['user_nicename'] = sanitize_title($newuser_name);
170 $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
171
172 $userdata['display_name'] = $wpdb->escape($newuser_name);
173
174 $newuser_id = wp_insert_user($userdata);
175 if (is_numeric($newuser_id)) :
176 update_option('feedwordpress_unfamiliar_author', $newuser_id);
177 else :
178 // TODO: Add some error detection and reporting
179 endif;
180 else :
181 // TODO: Add some error reporting
182 endif;
183 else :
184 update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']);
185 endif;
186
187 if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email']=='yes') :
188 update_option('feedwordpress_do_not_match_author_by_email', 'no');
189 else :
190 update_option('feedwordpress_do_not_match_author_by_email', 'yes');
191 endif;
192
193 if (isset($GLOBALS['fwp_post']['null_emails'])) :
194 update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']);
195 endif;
196
197 $updated_link = true;
198 endif;
199 else :
200 $updated_link = false;
201 endif;
202
203 $unfamiliar = array ('create' => '','default' => '','filter' => '');
204
205 if (is_object($link) and $link->found()) :
206 if (is_string($link->settings["unfamiliar author"])) :
207 $key = $link->settings["unfamiliar author"];
208 else:
209 $key = 'site-default';
210 endif;
211 else :
212 $key = FeedWordPress::on_unfamiliar('author');
213 endif;
214
215 $unfamiliar[$key] = ' selected="selected"';
216
217 $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
218 $null_emails = FeedWordPress::null_email_set();
219 ?>
220 <script type="text/javascript">
221 function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
222 if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
223
224 var rollup=document.getElementById(item);
225 var newuser=document.getElementById(appear);
226 var sitewide=document.getElementById(disappear);
227 if (rollup) {
228 if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
229 if (newuser) newuser.style.display=visibleStyle;
230 if (sitewide) sitewide.style.display='none';
231 } else {
232 if (newuser) newuser.style.display='none';
233 if (sitewide) sitewide.style.display=visibleStyle;
234 }
235 }
236 }
237 </script>
238
239 <?php if ($updated_link) : ?>
240 <div class="updated"><p>Syndicated author settings updated.</p></div>
241 <?php elseif (!is_null($mesg)) : ?>
242 <div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div>
243 <?php endif; ?>
244
245 <div class="wrap">
246 <form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
247 <?php if (is_numeric($link_id) and $link_id) : ?>
248 <input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
249 <?php else : ?>
250 <input type="hidden" name="save_link_id" value="*" />
251 <?php endif; ?>
252
253 <?php $links = FeedWordPress::syndicated_links(); ?>
254 <h2>Syndicated Author Settings<?php if (!is_null($link) and $link->found()) : ?>: <?php echo wp_specialchars($link->link->link_name, 1); ?><?php endif; ?></h2>
255 <p id="post-search">
256 <select name="link_id" style="max-width: 20.0em">
257 <option value="*"<?php if (is_null($link) or !$link->found()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
258 <?php if ($links) : foreach ($links as $ddlink) : ?>
259 <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>
260 <?php endforeach; endif; ?>
261 </select>
262 <input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" />
263 </p>
264
265 <?php if (!is_null($link) and $link->found()) : ?>
266 <p>These settings only affect posts syndicated from
267 <strong><?php echo wp_specialchars($link->link->link_name, 1); ?></strong>.</p>
268 <?php else : ?>
269 <p>These settings affect posts syndicated from any feed unless they are overridden
270 by settings for that specific feed.</p>
271 <?php endif; ?>
272
273 <h3>Assigning posts to authors</h3>
274 <?php
275 $authorlist = fwp_author_list();
276 ?>
277 <table class="form-table">
278 <tbody>
279 <tr>
280 <th>New authors</th>
281 <td><span>Authors who haven't been syndicated before</span>
282 <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');">
283 <?php if (is_object($link) and $link->found()) : ?>
284 <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option>
285 <?php endif; ?>
286 <option value="create"<?php $unfamiliar['create']; ?>>will have a new author account created for them</option>
287 <?php foreach ($authorlist as $author_id => $author_name) : ?>
288 <option value="<?php echo $author_id; ?>"<?php print $unfamiliar[$author_id]; ?>>will have their posts attributed to <?php echo $author_name; ?></option>
289 <?php endforeach; ?>
290 <option value="newuser">will have their posts attributed to a new user...</option>
291 <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option>
292 </select>
293
294 <span id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></span></p>
295 </td>
296 </tr>
297
298 <?php
299 if (is_object($link) and $link->found()) :
300 ?>
301 <tr><th>Syndicated authors</th>
302 <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>
303 <table style="width: 100%">
304 <?php
305 if (isset($link->settings['map authors'])) :
306 ?>
307 <?php
308 $i=0;
309 foreach ($link->settings['map authors'] as $author_rules) :
310 foreach ($author_rules as $author_name => $author_action) :
311 $i++;
312 ?>
313 <tr>
314 <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>
315 <td>
316 <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');">
317 <?php foreach ($authorlist as $local_author_id => $local_author_name) : ?>
318 <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>
319 <?php endforeach; ?>
320 <option value="newuser">will be assigned to a new user...</option>
321 <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option>
322 </select>
323
324 <span id="author-rules-<?php echo $i; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span>
325 </td>
326 </tr>
327 <?php endforeach;
328 endforeach;
329 endif;
330 ?>
331
332 <tr>
333 <th style="text-align: left; width: 15.0em">Posts by <input type="text" name="add_author_rule_name" size="11" /></th>
334 <td>
335 <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');">
336 <?php foreach ($authorlist as $author_id => $author_name) : ?>
337 <option value="<?php echo $author_id; ?>">are assigned to <?php echo $author_name; ?></option>
338 <?php endforeach; ?>
339 <option value="newuser">will be assigned to a new user...</option>
340 <option value="filter">get filtered out</option>
341 </select>
342
343 <span id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></span>
344 </td>
345 </tr>
346 </table>
347 </td>
348 </tr>
349 <?php endif; ?>
350
351 <?php if (!(is_object($link) and $link->found())) : ?>
352 <tr>
353 <th scope="row">Matching Authors</th>
354 <td><ul style="list-style: none; margin: 0; padding: 0;">
355 <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>
356 <div id="unless-null-email">
357 <p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
358 <textarea name="null_emails" rows="3" style="width: 100%">
359 <?php print implode("\n", $null_emails); ?>
360 </textarea>
361 </div></li>
362 </ul></td>
363 </tr>
364 <?php else : ?>
365 <th scope="row">Fixing mis-matched authors:</th>
366 <td><p>Take all the posts from this feed attributed to
367 <select name="fix_mismatch_from">
368 <?php foreach ($authorlist as $author_id => $author_name) : ?>
369 <option value="<?php echo $author_id; ?>"><?php echo $author_name; ?></option>
370 <?php endforeach; ?>
371 </select>
372 and instead
373 <select id="fix-mismatch-to" name="fix_mismatch_to" onchange="contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');">
374 <?php foreach ($authorlist as $author_id => $author_name) : ?>
375 <option value="<?php echo $author_id; ?>">re-assign them to <?php echo $author_name; ?></option>
376 <?php endforeach; ?>
377 <option value="newuser">re-assign them to a new user...</option>
378 <option value="filter">delete them</option>
379 </select>
380
381 <span id="fix-mismatch-to-newuser">named <input type="text" name="fix_mismatch_to_newuser" value="" /></span>
382 <input type="submit" class="button" name="fix_mismatch" value="Fix it!" />
383 </td>
384 </td>
385 <?php endif; ?>
386 </tbody>
387 </table>
388
389 <script type="text/javascript">
390 contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
391 <?php if (is_object($link) and $link->found()) : ?>
392 <?php for ($j=1; $j<=$i; $j++) : ?>
393 contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline');
394 <?php endfor; ?>
395 contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
396 contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
397 <?php else : ?>
398 contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
399 <?php endif; ?>
400 </script>
401
402 <p class="submit">
403 <input type="submit" name="save" value="Save Changes" />
404 </p>
405 </form>
406 </div> <!-- class="wrap" -->
407 <?php
408 endif;
409 } /* function fwp_authors_page () */
410
411 fwp_authors_page();
412
413