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

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