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
← All changes | categories-page.php +160 -254 2009.07072010.0528 View file →
@@ -1,25 +1,118 @@
1 1 <?php
2 2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 3
4 +class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
5 + function FeedWordPressCategoriesPage ($link) {
6 + FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresscategories', $link);
7 + $this->dispatch = 'feedwordpress_categories_settings';
8 + $this->filename = __FILE__;
9 + }
10 +
11 + /*static*/ function feed_categories_box ($page, $box = NULL) {
12 +
13 + $link = $page->link;
14 +
15 + $unfamiliar = array ('create'=>'','tag' => '', 'default'=>'','filter'=>'');
16 + if ($page->for_feed_settings()) :
17 + $unfamiliar['site-default'] = '';
18 + $ucKey = $link->settings["unfamiliar category"];
19 + $ucDefault = 'site-default';
20 + else :
21 + $ucKey = FeedWordPress::on_unfamiliar('category');
22 + $ucDefault = 'create';
23 + endif;
24 +
25 + if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) :
26 + $ucKey = $ucDefault;
27 + endif;
28 + $unfamiliar[$ucKey] = ' checked="checked"';
29 +
30 + // Hey ho, let's go...
31 + ?>
32 +<table class="edit-form">
33 +<tr>
34 +<th scope="row">Unfamiliar categories:</th>
35 +<td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
36 +
37 +<ul class="options">
38 +<?php if ($page->for_feed_settings()) : ?>
39 +<li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php echo $unfamiliar['site-default']; ?> /> use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>">site-wide setting</a>
40 +(currently <strong><?php echo FeedWordPress::on_unfamiliar('category'); ?></strong>)</label></li>
41 +<?php endif; ?>
42 +
43 +<li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['create']; ?> /> create a new category</label></li>
44 +
45 +<?php if (FeedWordPressCompatibility::post_tags()) : ?>
46 +<li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar['tag']; ?>/> create a new tag</label></li>
47 +<?php endif; ?>
48 +
49 +<li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar['default']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?></label></li>
50 +<li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar['filter']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?> and don't syndicate posts unless they match at least one familiar category</label></li>
51 +</ul></td>
52 +</tr>
53 +
54 +<?php if ($page->for_feed_settings()) : ?>
55 +<tr>
56 +<th scope="row">Multiple categories:</th>
57 +<td>
58 +<input type="text" size="20" id="cat_split" name="cat_split" value="<?php if (isset($link->settings['cat_split'])) : echo htmlspecialchars($link->settings['cat_split']); endif; ?>" />
59 +<p class="setting-description">Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
60 +categories in a single category element. The regular expression should match
61 +the characters used to separate one category from the next. If the feed uses
62 +spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
63 +If the feed does not provide multiple categories in a single element, leave this
64 +blank.</p></td>
65 +</tr>
66 +<?php endif; ?>
67 +</table>
68 + <?php
69 + } /* FeedWordPressCategoriesPage::feed_categories_box() */
70 +
71 + function categories_box ($page, $box = NULL) {
72 + $link = $page->link;
73 + if ($page->for_feed_settings()) :
74 + if (is_array($link->settings['cats'])) : $cats = $link->settings['cats'];
75 + else : $cats = array();
76 + endif;
77 + else :
78 + $cats = array_map('trim',
79 + preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats'))
80 + );
81 + endif;
82 + $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL);
83 +
84 + fwp_category_box($dogs, 'all '.$page->these_posts_phrase());
85 + } /* FeedWordPressCategoriesPage::categories_box () */
86 +
87 + function tags_box ($page, $box = NULL) {
88 + $link = $page->link;
89 + if ($page->for_feed_settings()) :
90 + $tags = $link->settings['tags'];
91 + else :
92 + $tags = array_map('trim',
93 + preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_tags'))
94 + );
95 + endif;
96 +
97 + fwp_tags_box($tags, 'all '.$page->these_posts_phrase());
98 + } /* FeedWordPressCategoriesPage::tags_box () */
99 +}
100 +
4 101 function fwp_categories_page () {
5 102 global $wpdb, $wp_db_version;
103 +
104 + if (FeedWordPress::needs_upgrade()) :
105 + fwp_upgrade_page();
106 + return;
107 + endif;
6 108
7 109 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_categories_settings', /*capability=*/ 'manage_links');
8 110
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;
111 + $link = FeedWordPressAdminPage::submitted_link();
112 + $link_id = $link->id;
16 113
17 - if (is_numeric($link_id) and $link_id) :
18 - $link =& new SyndicatedLink($link_id);
19 - else :
20 - $link = NULL;
21 - endif;
114 + $catsPage = new FeedWordPressCategoriesPage($link);
22 115
23 116 $mesg = null;
24 117
25 118 ////////////////////////////////////////////////
@@ -24,9 +117,9 @@
24 117
25 118 ////////////////////////////////////////////////
26 119 // Process POST request, if any /////////////////
27 120 ////////////////////////////////////////////////
28 - if (isset($GLOBALS['fwp_post']['save'])) :
121 + if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['submit'])) :
29 122 $saveCats = array();
30 123 if (isset($GLOBALS['fwp_post']['post_category'])) :
31 124 foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) :
32 125 $saveCats[] = '{#'.$cat_id.'}';
@@ -70,25 +163,15 @@
70 163 unset($link->settings['cat_split']);
71 164 endif;
72 165 endif;
73 166
74 - $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
75 -
76 - $alter_set = implode(", ", $alter);
77 -
78 - // issue update query
79 - $result = $wpdb->query("
80 - UPDATE $wpdb->links
81 - SET $alter_set
82 - WHERE link_id='$link_id'
83 - ");
84 - $updated_link = true;
85 -
86 - // reload link information from DB
87 - if (function_exists('clean_bookmark_cache')) :
88 - clean_bookmark_cache($link_id);
89 - endif;
90 - $link =& new SyndicatedLink($link_id);
167 + // Save settings
168 + $link->save_settings(/*reload=*/ true);
169 + $catsPage->updated = true;
170 +
171 + // Reset, reload
172 + unset($link);
173 + $link = new SyndicatedLink($link_id);
91 174 else :
92 175 // Categories
93 176 if (!empty($saveCats)) :
94 177 update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $saveCats));
@@ -104,247 +187,70 @@
104 187 endif;
105 188
106 189 update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
107 190
108 - $updated_link = true;
191 + $catsPage->updated = true;
109 192 endif;
193 +
194 + do_action('feedwordpress_admin_page_categories_save', $GLOBALS['fwp_post'], $catsPage);
110 195 else :
111 - $updated_link = false;
196 + $catsPage->updated = false;
112 197 endif;
113 198
114 199 ////////////////////////////////////////////////
115 - // Get defaults from database //////////////////
200 + // Prepare settings page ///////////////////////
116 201 ////////////////////////////////////////////////
117 202
118 - $unfamiliar = array ('create'=>'','tag' => '', 'default'=>'','filter'=>'');
119 - if (is_object($link) and $link->found()) :
120 - $unfamiliar['site-default'] = '';
121 - $ucKey = $link->settings["unfamiliar category"];
122 - $ucDefault = 'site-default';
203 + $catsPage->display_update_notice_if_updated('Syndicated categories'.FEEDWORDPRESS_AND_TAGS, $mesg);
204 + $catsPage->open_sheet('Categories'.FEEDWORDPRESS_AND_TAGS);
205 + ?>
206 + <style type="text/css">
207 + table.edit-form th { width: 27%; vertical-align: top; }
208 + table.edit-form td { width: 73%; vertical-align: top; }
209 + table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
210 + </style>
123 211
124 - if (is_array($link->settings['cats'])) : $cats = $link->settings['cats'];
125 - else : $cats = array();
126 - endif;
212 + <div id="post-body">
213 + <?php
214 + ////////////////////////////////////////////////
215 + // Display settings boxes //////////////////////
216 + ////////////////////////////////////////////////
127 217
128 - $tags = $link->settings['tags'];
129 - else :
130 - $ucKey = FeedWordPress::on_unfamiliar('category');
131 - $ucDefault = 'create';
132 -
133 - $cats = array_map('trim',
134 - preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats'))
135 - );
136 - $tags = array_map('trim',
137 - preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_tags'))
138 - );
218 + $boxes_by_methods = array(
219 + 'feed_categories_box' => __('Feed Categories'.FEEDWORDPRESS_AND_TAGS),
220 + 'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'),
221 + 'tags_box' => __('Tags'),
222 + );
223 + if (!FeedWordPressCompatibility::post_tags()) :
224 + unset($boxes_by_methods['tags_box']);
139 225 endif;
140 226
141 - if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) :
142 - $ucKey = $ucDefault;
143 - endif;
144 - $unfamiliar[$ucKey] = ' checked="checked"';
227 + foreach ($boxes_by_methods as $method => $row) :
228 + if (is_array($row)) :
229 + $id = $row['id'];
230 + $title = $row['title'];
231 + else :
232 + $id = 'feedwordpress_'.$method;
233 + $title = $row;
234 + endif;
145 235
146 - $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL);
236 + fwp_add_meta_box(
237 + /*id=*/ $id,
238 + /*title=*/ $title,
239 + /*callback=*/ array('FeedWordPressCategoriesPage', $method),
240 + /*page=*/ $catsPage->meta_box_context(),
241 + /*context=*/ $catsPage->meta_box_context()
242 + );
243 + endforeach;
244 + do_action('feedwordpress_admin_page_categories_meta_boxes', $catsPage);
147 245 ?>
148 -<script type="text/javascript">
149 - function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
150 - if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
151 -
152 - var rollup=document.getElementById(item);
153 - var newuser=document.getElementById(appear);
154 - var sitewide=document.getElementById(disappear);
155 - if (rollup) {
156 - if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
157 - if (newuser) newuser.style.display=visibleStyle;
158 - if (sitewide) sitewide.style.display='none';
159 - } else {
160 - if (newuser) newuser.style.display='none';
161 - if (sitewide) sitewide.style.display=visibleStyle;
162 - }
163 - }
164 - }
165 -</script>
166 -
167 -<?php if ($updated_link) : ?>
168 -<div class="updated"><p>Syndicated categories and tags settings updated.</p></div>
169 -<?php elseif (!is_null($mesg)) : ?>
170 -<div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div>
171 -<?php endif; ?>
172 -
173 -<div class="wrap">
174 -<form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
175 -<div><?php
176 - FeedWordPressCompatibility::stamp_nonce('feedwordpress_categories_settings');
177 -
178 - if (is_numeric($link_id) and $link_id) :
179 -?>
180 -<input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
246 + <div class="metabox-holder">
181 247 <?php
182 - else :
248 + fwp_do_meta_boxes($catsPage->meta_box_context(), $catsPage->meta_box_context(), $catsPage);
183 249 ?>
184 -<input type="hidden" name="save_link_id" value="*" />
185 -<?php
186 - endif;
187 -?>
188 -</div>
189 -
190 -<?php $links = FeedWordPress::syndicated_links(); ?>
191 -<?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
192 - <div class="icon32"><img src="<?php print htmlspecialchars(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png'); ?>" alt="" /></div>
193 -<?php endif; ?>
194 -<h2>Categories &amp; Tags Settings<?php if (!is_null($link) and $link->found()) : ?>: <?php echo wp_specialchars($link->link->link_name, 1); ?><?php endif; ?></h2>
195 -
196 -<style type="text/css">
197 - table.edit-form th { width: 27%; vertical-align: top; }
198 - table.edit-form td { width: 73%; vertical-align: top; }
199 - table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
200 -</style>
201 -
202 -<?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
203 - <style type="text/css">
204 - #post-search {
205 - float: right;
206 - margin:11px 12px 0;
207 - min-width: 130px;
208 - position:relative;
209 - }
210 - .fwpfs {
211 - color: #dddddd;
212 - background:#797979 url(<?php bloginfo('home') ?>/wp-admin/images/fav.png) repeat-x scroll left center;
213 - border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px;
214 - -moz-border-radius-bottomright:12px;
215 - -moz-border-radius-topleft:12px;
216 - -moz-border-radius-topright:12px;
217 - border-style:solid;
218 - border-width:1px;
219 - line-height:15px;
220 - padding:3px 30px 4px 12px;
221 - }
222 - .fwpfs.slide-down {
223 - border-bottom-color: #626262;
224 - -moz-border-radius-bottomleft:0;
225 - -moz-border-radius-bottomright:0;
226 - -moz-border-radius-topleft:12px;
227 - -moz-border-radius-topright:12px;
228 - background-image:url(<?php bloginfo('home') ?>/wp-admin/images/fav-top.png);
229 - background-position:0 top;
230 - background-repeat:repeat-x;
231 - border-bottom-style:solid;
232 - border-bottom-width:1px;
233 - }
234 - </style>
235 -
236 - <script type="text/javascript">
237 - jQuery(document).ready(function($){
238 - $('.fwpfs').toggle(
239 - function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
240 - function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
241 - );
242 - $('.fwpfs').bind(
243 - 'change',
244 - function () { this.form.submit(); }
245 - );
246 - $('#post-search .button').css( 'display', 'none' );
247 - });
248 - </script>
249 -<?php endif; /* else : */?>
250 -<p id="post-search">
251 -<select name="link_id" class="fwpfs" style="max-width: 20.0em;">
252 - <option value="*"<?php if (is_null($link) or !$link->found()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
253 -<?php if ($links) : foreach ($links as $ddlink) : ?>
254 - <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>
255 -<?php endforeach; endif; ?>
256 -</select>
257 -<input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" />
258 -</p>
259 -<?php /* endif; */ ?>
260 -
261 -<?php if (!is_null($link) and $link->found()) : ?>
262 - <p>These settings only affect posts syndicated from
263 - <strong><?php echo wp_specialchars($link->link->link_name, 1); ?></strong>.</p>
264 -<?php else : ?>
265 - <p>These settings affect posts syndicated from any feed unless they are overridden
266 - by settings for that specific feed.</p>
267 -<?php endif; ?>
268 -
269 -<div id="poststuff">
270 -<div id="post-body">
271 -<?php
272 - fwp_option_box_opener("Feed Categories & Tags", 'fromfeeddiv', 'postbox');
273 -?>
274 -<table class="edit-form">
275 -<tr>
276 -<th scope="row">Unfamiliar categories:</th>
277 -<td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
278 -
279 -<ul class="options">
280 -<?php if (is_object($link) and ($link->found())) : ?>
281 -<li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php echo $unfamiliar['site-default']; ?> /> use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>">site-wide setting</a>
282 -(currently <strong><?php echo FeedWordPress::on_unfamiliar('category'); ?></strong>)</label></li>
283 -<?php endif; ?>
284 -
285 -<li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['create']; ?> /> create a new category</label></li>
286 -
287 -<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?>
288 -<li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar['tag']; ?>/> create a new tag</label></li>
289 -<?php endif; ?>
290 -
291 -<li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar['default']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?></label></li>
292 -<li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar['filter']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?> and don't syndicate posts unless they match at least one familiar category</label></li>
293 -</ul></td>
294 -</tr>
295 -
296 -<?php if (is_object($link) and $link->found()) : ?>
297 -<tr>
298 -<th scope="row">Multiple categories:</th>
299 -<td>
300 -<input type="text" size="20" id="cat_split" name="cat_split" value="<?php if (isset($link->settings['cat_split'])) : echo htmlspecialchars($link->settings['cat_split']); endif; ?>" />
301 -<p class="setting-description">Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
302 -categories in a single category element. The regular expression should match
303 -the characters used to separate one category from the next. If the feed uses
304 -spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
305 -If the feed does not provide multiple categories in a single element, leave this
306 -blank.</p></td>
307 -</tr>
308 -<?php endif; ?>
309 -</table>
310 -<?php
311 - fwp_option_box_closer();
312 - fwp_linkedit_periodic_submit();
313 -?>
314 -<?php
315 - fwp_option_box_opener(__('Categories'), 'categorydiv', 'postbox');
316 - fwp_category_box($dogs, 'all syndicated posts'.((is_object($link) and $link->found()) ? ' from this feed':''));
317 -?>
318 -<?php
319 - fwp_option_box_closer();
320 - fwp_linkedit_periodic_submit();
321 -
322 -if (fwp_test_wp_version(FWP_SCHEMA_25)) :
323 - fwp_tags_box($tags, 'all syndicated posts'.((is_object($link) and $link->found()) ? ' from this feed':''));
324 - fwp_linkedit_periodic_submit();
325 -endif; ?>
326 -</div>
327 -</div>
328 -
329 -<p class="submit">
330 -<input class="button-primary" type="submit" name="save" value="Save Changes" />
331 -</p>
332 -
333 -<script type="text/javascript">
334 - contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
335 -<?php if (is_object($link) and $link->found()) : ?>
336 -<?php for ($j=1; $j<=$i; $j++) : ?>
337 - contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline');
338 -<?php endfor; ?>
339 - contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
340 - contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
341 -<?php else : ?>
342 - contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
343 -<?php endif; ?>
344 -</script>
345 -</form>
346 -</div> <!-- class="wrap" -->
250 + </div> <!-- class="metabox-holder" -->
251 + </div> <!-- id="post-body" -->
252 + <?php $catsPage->close_sheet(); ?>
347 253 <?php
348 254 } /* function fwp_categories_page () */
349 255
350 256 fwp_categories_page();