PluginProbe
FeedWordPress / 2011.0211.2
FeedWordPress v2011.0211.2
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 +563 -294 2009.06132011.0211.2 View file →
@@ -1,303 +1,354 @@
1 1 <?php
2 2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 3
4 -function fwp_categories_page () {
5 - global $wpdb, $wp_db_version;
4 +class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
5 + function FeedWordPressCategoriesPage ($link = -1) {
6 + if (is_numeric($link) and -1 == $link) :
7 + $link = $this->submitted_link();
8 + endif;
9 +
10 + FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresscategories', $link);
11 + $this->dispatch = 'feedwordpress_admin_page_categories';
12 + $this->pagenames = array(
13 + 'default' => 'Categories'.FEEDWORDPRESS_AND_TAGS,
14 + 'settings-update' => 'Syndicated Categories'.FEEDWORDPRESS_AND_TAGS,
15 + 'open-sheet' => 'Categories'.FEEDWORDPRESS_AND_TAGS,
16 + );
17 + $this->filename = __FILE__;
18 + }
19 +
20 + function unfamiliar_category_label ($name) {
21 + if (preg_match('/^create:(.*)$/', $name, $refs)) :
22 + $tax = get_taxonomy($refs[1]);
23 + $name = sprintf(__('Create new %s to match them'), $tax->labels->name);
24 + endif;
25 + return $name;
26 + }
27 +
28 +
29 + function feed_categories_box ($page, $box = NULL) {
30 + $link = $page->link;
31 +
32 + $globalPostType = get_option('feedwordpress_syndicated_post_type', 'post');
33 + if ($this->for_feed_settings()) :
34 + $post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
35 + else :
36 + $post_type = $globalPostType;
37 + endif;
38 + $taxonomies = get_object_taxonomies(array('object_type' => $post_type), 'names');
6 39
7 - FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_categories_settings', /*capability=*/ 'manage_links');
40 + $unmatched = array('category' => array(), 'post_tag' => array());
41 + $matchUl = array('cats' => array(), 'tags' => array(), 'filter' => array());
42 + $tagLikeTaxonomies = array();
43 + foreach ($taxonomies as $tax) :
44 + $taxonomy = get_taxonomy($tax);
45 +
46 + if (!$taxonomy->hierarchical) :
47 + $tagLikeTaxonomies[] = $tax;
48 + endif;
8 49
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;
50 + $name = 'create:'.$tax;
51 + foreach (array('category', 'post_tag') as $what) :
52 + $unmatched[$what][$name] = array(
53 + 'label' => $this->unfamiliar_category_label($name),
54 + );
55 + $unmatchedRadio[$what][$name] = '';
56 + endforeach;
16 57
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 -
25 - ////////////////////////////////////////////////
26 - // Process POST request, if any /////////////////
27 - ////////////////////////////////////////////////
28 - if (isset($GLOBALS['fwp_post']['save'])) :
29 - $saveCats = array();
30 - if (isset($GLOBALS['fwp_post']['post_category'])) :
31 - foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) :
32 - $saveCats[] = '{#'.$cat_id.'}';
58 + foreach (array('cats', 'tags', 'filter') as $what) :
59 + $matchUl[$what][$tax] = array(
60 + 'checked' => '',
61 + 'labels' => $taxonomy->labels,
62 + );
33 63 endforeach;
34 - endif;
35 -
36 - if (is_object($link) and $link->found()) :
37 - $alter = array ();
38 -
39 - // Categories
40 - if (!empty($saveCats)) : $link->settings['cats'] = $saveCats;
41 - else : unset($link->settings['cats']);
64 + endforeach;
65 +
66 + foreach ($unmatched as $what => $um) :
67 + $unmatched[$what]['null'] = array('label' => __('Don\'t create any matching terms'));
68 + $unmatchedRadio[$what]['null'] = '';
69 + endforeach;
70 +
71 + $globalUnmatched = array(
72 + 'category' => FeedWordPress::on_unfamiliar('category'),
73 + 'post_tag' => FeedWordPress::on_unfamiliar('post_tag'),
74 + );
75 + foreach ($globalUnmatched as $what => $value) :
76 + if ($value=='create') : $value = 'create:category'; endif;
77 + if ($value=='tag') : $value = 'create:post_tag'; endif;
78 + $globalUnmatched[$what] = $value;
79 + endforeach;
80 +
81 + $globalMatch['cats'] = get_option('feedwordpress_match_cats', $taxonomies);
82 + $globalMatch['tags'] = get_option('feedwordpress_match_tags', $tagLikeTaxonomies);
83 + $globalMatch['filter'] = get_option('feedwordpress_match_filter', array());
84 +
85 + $globalMatchLabels = array();
86 + $nothingDoing = array('cats' => "won't try to match", 'tags' => "won't try to match", "filter" => "won't filter");
87 +
88 + foreach ($globalMatch as $what => $domain) :
89 + $labels = array(); $domain = array_filter($domain, 'remove_dummy_zero');
90 + foreach ($domain as $tax) :
91 + $tax = get_taxonomy($tax);
92 + $labels[] = $tax->labels->name;
93 + endforeach;
94 +
95 + if (count($labels) > 0) :
96 + $globalMatchLabels[$what] = implode(", ", $labels);
97 + else :
98 + $globalMatchLabels[$what] = $nothingDoing[$what];
42 99 endif;
100 + endforeach;
43 101
44 - // Tags
45 - if (isset($GLOBALS['fwp_post']['tags_input'])) :
46 - $link->settings['tags'] = array();
47 - foreach (explode(',', $GLOBALS['fwp_post']['tags_input']) as $tag) :
48 - $link->settings['tags'][] = trim($tag);
49 - endforeach;
50 - endif;
102 + if ($this->for_feed_settings()) :
103 + $href = "admin.php?page={$GLOBALS['fwp_path']}/".basename(__FILE__);
51 104
52 - // Unfamiliar categories
53 - if (isset($GLOBALS['fwp_post']["unfamiliar_category"])) :
54 - if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_category"]) :
55 - unset($link->settings["unfamiliar category"]);
105 + foreach ($unmatched as $what => $um) :
106 + // Is the global default setting appropriate to this post type?
107 + $GUC = $globalUnmatched[$what];
108 + if (isset($um[$GUC])) :
109 + // Yup. Let's add a site-default option
110 + $currently = $um[$GUC]['label'];
111 + $defaultLi = array(
112 + 'site-default' => array(
113 + 'label' => sprintf(
114 + __('Use the <a href="%s">site-wide setting</a> <span class="current-setting">Currently: <strong>%s</strong></span>'),
115 + $href,
116 + $currently
117 + ),
118 + ), );
119 + $unmatchedColumns[$what] = array(
120 + $defaultLi,
121 + );
122 + $unmatchedDefault[$what] = 'site-default';
123 + $unmatchedRadio[$what]['site-default'] = '';
56 124 else :
57 - $link->settings["unfamiliar category"] = $GLOBALS['fwp_post']["unfamiliar_category"];
125 + $opts = array_keys($unmatched[$what]);
126 + $unmatchedDefault[$what] = $opts[0];
127 + $unmatchedColumns[$what] = array();
58 128 endif;
59 - endif;
129 +
130 + $ucKey[$what] = $link->setting("unfamiliar $what", NULL, NULL);
131 + endforeach;
132 +
133 + $match['cats'] = $this->link->setting('match/cats', NULL, NULL);
134 + $match['tags'] = $this->link->setting('match/tags', NULL, NULL);
135 + $match['filter'] = $this->link->setting('match/filter', NULL, NULL);
136 + else :
137 + foreach ($unmatched as $what => $um) :
138 + $ucKey[$what] = FeedWordPress::on_unfamiliar($what);
139 + endforeach;
60 140
61 - // Category spitting regex
62 - if (isset($GLOBALS['fwp_post']['cat_split'])) :
63 - if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) :
64 - $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']);
65 - else :
66 - unset($link->settings['cat_split']);
67 - endif;
141 + $match = $globalMatch;
142 + endif;
143 +
144 + foreach ($ucKey as $what => $uck) :
145 + if ($uck == 'tag') : $uck = 'create:post_tag'; endif;
146 + if ($uck == 'create') : $uck = 'create:category'; endif;
147 +
148 + if (!is_string($uck)) :
149 + $uck = $unmatchedDefault[$what];
68 150 endif;
69 -
70 - $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
71 -
72 - $alter_set = implode(", ", $alter);
73 -
74 - // issue update query
75 - $result = $wpdb->query("
76 - UPDATE $wpdb->links
77 - SET $alter_set
78 - WHERE link_id='$link_id'
79 - ");
80 - $updated_link = true;
81 -
82 - // reload link information from DB
83 - if (function_exists('clean_bookmark_cache')) :
84 - clean_bookmark_cache($link_id);
151 + $ucKey[$what] = $uck;
152 +
153 + if (!array_key_exists($uck, $unmatchedRadio[$what])) :
154 + $obsoleteLi = array(
155 + $uck => array(
156 + 'label' => ' <span style="font-style: italic; color: #777;">'.$this->unfamiliar_category_label($uck).'</span> <span style="background-color: #ffff90; color: black;">(This setting is no longer applicable to the type of post syndicated from this feed!)</span><p>Please change this one of the following settings:</p>',
157 + ),
158 + );
159 + $unmatched[$what] = array_merge($obsoleteLi, $unmatched[$what]);
160 + $unmatchedRadio[$what][$uck] = ' disabled="disabled"';
85 161 endif;
86 - $link =& new SyndicatedLink($link_id);
87 - else :
88 - // Categories
89 - if (!empty($saveCats)) :
90 - update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $saveCats));
91 - else :
92 - delete_option('feedwordpress_syndication_cats');
162 +
163 + $unmatchedRadio[$what][$uck] .= ' checked="checked"';
164 +
165 + $unmatchedColumns[$what][] = $unmatched[$what];
166 + endforeach;
167 +
168 + $defaulted = array();
169 + foreach ($match as $what => $set) :
170 + $defaulted[$what] = false;
171 + if (is_null($set) or (count($set) < 1)) :
172 + $defaulted[$what] = true;
173 + if ($this->for_feed_settings()) :
174 + $set = $globalMatch[$what];
175 + $match[$what] = $globalMatch[$what];
176 + endif;
93 177 endif;
94 -
95 - // Tags
96 - if (isset($_REQUEST['tags_input'])) :
97 - $tags = explode(",", $_REQUEST['tags_input']);
98 - else :
99 - $tags = array();
100 - endif;
101 178
102 - if (!empty($tags)) :
103 - update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $tags));
104 - else :
105 - delete_option('feedwordpress_syndication_tags');
179 + if (!$defaulted[$what] or $this->for_feed_settings()) :
180 + foreach ($set as $against) :
181 + if (array_key_exists($against, $matchUl[$what])) :
182 + $matchUl[$what][$against]['checked'] = ' checked="checked"';
183 + endif;
184 + endforeach;
106 185 endif;
186 + endforeach;
107 187
108 - update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
188 + // Hey ho, let's go...
189 + $offerSiteWideSettings = ($page->for_feed_settings() and ($post_type==$globalPostType));
190 + ?>
191 +<table class="edit-form narrow">
192 +<tr>
193 +<th scope="row">Match feed categories:</th>
194 +<td><input type="hidden" name="match_categories[cats][]" value="0" />
195 +<?php if ($offerSiteWideSettings) : ?>
196 + <table class="twofer">
197 + <tbody>
198 + <tr><td class="equals first <?php if ($defaulted['cats']) : ?>active<?php else: ?>inactive<?php endif; ?>"><p><label><input type="radio" name="match_default[cats]"
199 +value="yes" <?php if ($defaulted['cats']) : ?> checked="checked"<?php endif; ?> />
200 +Use the <a href="<?php print $href; ?>">site-wide setting</a>
201 +<span class="current-setting">Currently: <strong><?php print $globalMatchLabels['cats']; ?></strong></span></label></p></td>
202 + <td class="equals second <?php if ($defaulted['cats']) : ?>inactive<?php else: ?>active<?php endif; ?>"><p><label><input type="radio" name="match_default[cats]"
203 +value="no" <?php if (!$defaulted['cats']) : ?> checked="checked"<?php endif; ?> />
204 +Do something different with this feed.</label>
205 +<?php else : ?>
206 + <p>
207 +<?php endif; ?>
208 +When a feed provides categories for a post, try to match those categories
209 +locally with:</p>
210 +<ul class="options compact">
211 +<?php foreach ($matchUl['cats'] as $name => $li) : ?>
212 + <li><label><input type="checkbox"
213 + name="match_categories[cats][]" value="<?php print $name; ?>"
214 + <?php print $li['checked']; ?> /> <?php $l = $li['labels']; print $l->name; ?></label></li>
215 +<?php endforeach; ?>
216 +</ul>
217 +<?php if ($offerSiteWideSettings) : ?>
218 + </td></tr>
219 + </tbody>
220 + </table>
221 +<?php endif; ?>
222 +</td>
223 +</tr>
109 224
110 - $updated_link = true;
111 - endif;
112 - else :
113 - $updated_link = false;
114 - endif;
225 +<tr>
226 +<th scope="row">Unmatched categories:</th>
227 +<td><p>When <?php print $this->these_posts_phrase(); ?> have categories on
228 +the feed that don't have any local matches yet...</p>
115 229
116 - ////////////////////////////////////////////////
117 - // Get defaults from database //////////////////
118 - ////////////////////////////////////////////////
119 -
120 - $unfamiliar = array ('create'=>'','tag' => '', 'default'=>'','filter'=>'');
121 - if (is_object($link) and $link->found()) :
122 - $unfamiliar['site-default'] = '';
123 - $ucKey = $link->settings["unfamiliar category"];
124 - $ucDefault = 'site-default';
230 +<?php if (count($unmatchedColumns['category']) > 1) : ?>
231 + <table class="twofer">
232 +<?php else : ?>
233 + <table style="width: 100%">
234 +<?php endif; ?>
235 + <tbody>
236 + <tr>
237 + <?php foreach ($unmatchedColumns['category'] as $index => $column) : ?>
238 + <td class="equals <?php print (($index == 0) ? 'first' : 'second'); ?> inactive"><ul class="options">
239 + <?php foreach ($column as $name => $li) : ?>
240 + <li><label><input type="radio" name="unfamiliar_category" value="<?php print $name; ?>"<?php print $unmatchedRadio['category'][$name]; ?> /> <?php print $li['label']; ?></label></li>
241 + <?php endforeach; ?>
242 + </ul></td>
243 + <?php endforeach; ?>
244 + </tr>
245 + </tbody>
246 + </table>
247 +</td></tr>
125 248
126 - if (is_array($link->settings['cats'])) : $cats = $link->settings['cats'];
127 - else : $cats = array();
128 - endif;
129 -
130 - $tags = $link->settings['tags'];
131 - else :
132 - $ucKey = FeedWordPress::on_unfamiliar('category');
133 - $ucDefault = 'create';
134 -
135 - $cats = array_map('trim',
136 - preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats'))
137 - );
138 - $tags = array_map('trim',
139 - preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_tags'))
140 - );
141 - endif;
142 -
143 - if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) :
144 - $ucKey = $ucDefault;
145 - endif;
146 - $unfamiliar[$ucKey] = ' checked="checked"';
147 -
148 - $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL);
149 -?>
150 -<script type="text/javascript">
151 - function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
152 - if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
153 -
154 - var rollup=document.getElementById(item);
155 - var newuser=document.getElementById(appear);
156 - var sitewide=document.getElementById(disappear);
157 - if (rollup) {
158 - if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
159 - if (newuser) newuser.style.display=visibleStyle;
160 - if (sitewide) sitewide.style.display='none';
161 - } else {
162 - if (newuser) newuser.style.display='none';
163 - if (sitewide) sitewide.style.display=visibleStyle;
164 - }
165 - }
166 - }
167 -</script>
168 -
169 -<?php if ($updated_link) : ?>
170 -<div class="updated"><p>Syndicated categories and tags settings updated.</p></div>
171 -<?php elseif (!is_null($mesg)) : ?>
172 -<div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div>
249 +<tr>
250 +<th scope="row">Match inline tags:
251 +<p class="setting-description">Applies only to inline tags marked
252 +as links in the text of syndicated posts, using the
253 +<code>&lt;a rel="tag"&gt;...&lt;/a&gt;</code> microformat.
254 +Most feeds with "tags" just treat them as normal feed categories,
255 +like those handled above.</p>
256 +</th>
257 +<td><input type="hidden" name="match_categories[tags][]" value="0" />
258 +<?php if ($offerSiteWideSettings) : ?>
259 + <table class="twofer">
260 + <tbody>
261 + <tr><td class="equals first <?php if ($defaulted['tags']) : ?>active<?php else: ?>inactive<?php endif; ?>"><p><label><input type="radio" name="match_default[tags]"
262 +value="yes" <?php if ($defaulted['tags']) : ?> checked="checked"<?php endif; ?> />
263 +Use the <a href="<?php print $href; ?>">site-wide setting</a>
264 +<span class="current-setting">Currently: <strong><?php print $globalMatchLabels['tags']; ?></strong></span></label></p>
265 +</td>
266 + <td class="equals second <?php if ($defaulted['tags']) : ?>inactive<?php else: ?>active<?php endif; ?>"><p><label><input type="radio" name="match_default[tags]"
267 +value="no" <?php if (!$defaulted['tags']) : ?> checked="checked"<?php endif; ?> />
268 +Do something different with this feed.</label>
269 +<?php else : ?>
270 + <p>
173 271 <?php endif; ?>
174 -
175 -<div class="wrap">
176 -<form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
177 -<div><?php
178 - FeedWordPressCompatibility::stamp_nonce('feedwordpress_categories_settings');
179 -
180 - if (is_numeric($link_id) and $link_id) :
181 -?>
182 -<input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
183 -<?php
184 - else :
185 -?>
186 -<input type="hidden" name="save_link_id" value="*" />
187 -<?php
188 - endif;
189 -?>
190 -</div>
191 -
192 -<?php $links = FeedWordPress::syndicated_links(); ?>
193 -<?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
194 - <div class="icon32"><img src="<?php print htmlspecialchars(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png'); ?>" alt="" /></div>
272 +When a feed provides tags inline in a post, try to match those tags
273 +locally with:</p>
274 +<ul class="options compact">
275 +<?php foreach ($matchUl['tags'] as $name => $li) : ?>
276 + <li><label><input type="checkbox"
277 + name="match_categories[tags][]" value="<?php print $name; ?>"
278 + <?php print $li['checked']; ?> /> <?php $l = $li['labels']; print $l->name; ?></label></li>
279 +<?php endforeach; ?>
280 +</ul>
281 +<?php if ($offerSiteWideSettings) : ?>
282 + </td></tr>
283 + </tbody>
284 + </table>
195 285 <?php endif; ?>
196 -<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>
286 +</td>
287 +</tr>
197 288
198 -<style type="text/css">
199 - table.edit-form th { width: 27%; vertical-align: top; }
200 - table.edit-form td { width: 73%; vertical-align: top; }
201 - table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
202 -</style>
289 +<tr>
290 +<th scope="row">Unmatched inline tags:</th>
291 +<td><p>When the text of <?php print $this->these_posts_phrase(); ?> contains
292 +inline tags that don't have any local matches yet...</p>
203 293
204 -<?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
205 - <style type="text/css">
206 - #post-search {
207 - float: right;
208 - margin:11px 12px 0;
209 - min-width: 130px;
210 - position:relative;
211 - }
212 - .fwpfs {
213 - color: #dddddd;
214 - background:#797979 url(<?php bloginfo('home') ?>/wp-admin/images/fav.png) repeat-x scroll left center;
215 - border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px;
216 - -moz-border-radius-bottomright:12px;
217 - -moz-border-radius-topleft:12px;
218 - -moz-border-radius-topright:12px;
219 - border-style:solid;
220 - border-width:1px;
221 - line-height:15px;
222 - padding:3px 30px 4px 12px;
223 - }
224 - .fwpfs.slide-down {
225 - border-bottom-color: #626262;
226 - -moz-border-radius-bottomleft:0;
227 - -moz-border-radius-bottomright:0;
228 - -moz-border-radius-topleft:12px;
229 - -moz-border-radius-topright:12px;
230 - background-image:url(<?php bloginfo('home') ?>/wp-admin/images/fav-top.png);
231 - background-position:0 top;
232 - background-repeat:repeat-x;
233 - border-bottom-style:solid;
234 - border-bottom-width:1px;
235 - }
236 - </style>
237 -
238 - <script type="text/javascript">
239 - jQuery(document).ready(function($){
240 - $('.fwpfs').toggle(
241 - function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
242 - function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
243 - );
244 - $('.fwpfs').bind(
245 - 'change',
246 - function () { this.form.submit(); }
247 - );
248 - $('#post-search .button').css( 'display', 'none' );
249 - });
250 - </script>
251 -<?php endif; /* else : */?>
252 -<p id="post-search">
253 -<select name="link_id" class="fwpfs" style="max-width: 20.0em;">
254 - <option value="*"<?php if (is_null($link) or !$link->found()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
255 -<?php if ($links) : foreach ($links as $ddlink) : ?>
256 - <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>
257 -<?php endforeach; endif; ?>
258 -</select>
259 -<input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" />
260 -</p>
261 -<?php /* endif; */ ?>
294 +<?php if (count($unmatchedColumns['post_tag']) > 1) : ?>
295 + <table class="twofer">
296 +<?php else : ?>
297 + <table style="width: 100%">
298 +<?php endif; ?>
299 + <tbody>
300 + <tr>
301 + <?php foreach ($unmatchedColumns['post_tag'] as $index => $column) : ?>
302 + <td class="equals <?php print (($index == 0) ? 'first' : 'second'); ?> inactive"><ul class="options">
303 + <?php foreach ($column as $name => $li) : ?>
304 + <li><label><input type="radio" name="unfamiliar_post_tag" value="<?php print $name; ?>"<?php print $unmatchedRadio['post_tag'][$name]; ?> /> <?php print $li['label']; ?></label></li>
305 + <?php endforeach; ?>
306 + </ul></td>
307 + <?php endforeach; ?>
308 + </tr>
309 + </tbody>
310 + </table>
262 311
263 -<?php if (!is_null($link) and $link->found()) : ?>
264 - <p>These settings only affect posts syndicated from
265 - <strong><?php echo wp_specialchars($link->link->link_name, 1); ?></strong>.</p>
266 -<?php else : ?>
267 - <p>These settings affect posts syndicated from any feed unless they are overridden
268 - by settings for that specific feed.</p>
269 -<?php endif; ?>
312 +</td></tr>
270 313
271 -<div id="poststuff">
272 -<div id="post-body">
273 -<?php
274 - fwp_option_box_opener(__('Categories'), 'categorydiv', 'postbox');
275 - fwp_category_box($dogs, 'all syndicated posts'.((is_object($link) and $link->found()) ? ' from this feed':''));
276 -?>
277 -<table class="edit-form">
278 314 <tr>
279 -<th scope="row">Unfamiliar categories:</th>
280 -<td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
315 +<th scope="row">Filter:</th>
316 +<td><input type="hidden" name="match_categories[filter][]" value="0" />
317 +<?php if ($offerSiteWideSettings) : ?>
318 + <table class="twofer">
319 + <tbody>
320 + <tr>
321 + <td class="equals first <?php if ($defaulted['filter']) : ?>active<?php else: ?>inactive<?php endif; ?>">
322 + <p><label><input type="radio" name="match_default[filter]"
323 +value="yes" <?php if ($defaulted['filter']) : ?> checked="checked"<?php endif; ?> />
324 +Use the <a href="<?php print $href; ?>">site-wide setting</a>
325 +<span class="current-setting">Currently: <strong><?php print $globalMatchLabels['filter']; ?></strong></span></label></p>
326 + </td>
327 + <td class="equals second <?php if ($defaulted['filter']) : ?>inactive<?php else: ?>active<?php endif; ?>">
328 + <p><label><input type="radio" name="match_default[filter]"
329 +value="no" <?php if (!$defaulted['filter']) : ?> checked="checked"<?php endif; ?> />
330 +Do something different with this feed:</label></p>
331 +<div style="margin-left: 3.0em;">
332 +<?php endif; ?>
281 333
282 334 <ul class="options">
283 -<?php if (is_object($link) and ($link->found())) : ?>
284 -<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>
285 -(currently <strong><?php echo FeedWordPress::on_unfamiliar('category'); ?></strong>)</label></li>
286 -<?php endif; ?>
335 +<?php foreach ($matchUl['filter'] as $tax => $li) : ?>
336 +<li><label><input type="checkbox" name="match_categories[filter][]" value="<?php print $tax; ?>"
337 +<?php print $li['checked']; ?> /> Don't syndicate posts unless they match at
338 +least one local <strong><?php $l = $li['labels']; print $l->singular_name; ?></strong></label></li>
339 +<?php endforeach; ?>
340 +</ul>
287 341
288 -<li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['create']; ?> /> create a new category</label></li>
289 -
290 -<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?>
291 -<li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar['tag']; ?>/> create a new tag</label></li>
342 +<?php if ($offerSiteWideSettings) : ?>
343 + </div>
344 + </td></tr>
345 + </tbody>
346 + </table>
292 347 <?php endif; ?>
293 -
294 -<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>
295 -<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>
296 -</ul></td>
348 +</td>
297 349 </tr>
298 -
299 -<?php if (is_object($link) and $link->found()) : ?>
350 +<?php if ($page->for_feed_settings()) : ?>
300 351 <tr>
301 352 <th scope="row">Multiple categories:</th>
302 353 <td>
303 354 <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; ?>" />
@@ -309,38 +360,256 @@
309 360 blank.</p></td>
310 361 </tr>
311 362 <?php endif; ?>
312 363 </table>
313 -<?php
314 - fwp_option_box_closer();
315 - fwp_linkedit_periodic_submit();
364 + <?php
365 + } /* FeedWordPressCategoriesPage::feed_categories_box() */
366 +
367 + function term_option_map () {
368 + return array(
369 + 'category' => 'feedwordpress_syndication_cats',
370 + 'post_tag' => 'feedwordpress_syndication_tags',
371 + );
372 + }
373 + function term_setting_map () {
374 + return array(
375 + 'category' => 'cats',
376 + 'post_tag' => 'tags',
377 + );
378 + }
316 379
317 -if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) :
318 - fwp_tags_box($tags);
319 - fwp_linkedit_periodic_submit();
320 -endif; ?>
321 -</div>
322 -</div>
380 + function categories_box ($page, $box = NULL) {
381 + $link = $page->link;
323 382
324 -<p class="submit">
325 -<input class="button-primary" type="submit" name="save" value="Save Changes" />
326 -</p>
383 + if ($this->for_feed_settings()) :
384 + $post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
385 + else :
386 + $post_type = get_option('feedwordpress_syndicated_post_type', 'post');
387 + endif;
388 + $taxonomies = get_object_taxonomies(array('object_type' => $post_type), 'names');
327 389
328 -<script type="text/javascript">
329 - contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
330 -<?php if (is_object($link) and $link->found()) : ?>
331 -<?php for ($j=1; $j<=$i; $j++) : ?>
332 - contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline');
333 -<?php endfor; ?>
334 - contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
335 - contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
336 -<?php else : ?>
337 - contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
338 -<?php endif; ?>
339 -</script>
340 -</form>
341 -</div> <!-- class="wrap" -->
342 -<?php
343 -} /* function fwp_categories_page () */
390 + $option_map = $this->term_option_map();
391 + $setting_map = $this->term_setting_map();
392 + $globalTax = get_option('feedwordpress_syndication_terms', array());
393 + if ($page->for_feed_settings()) :
394 + $terms = $link->setting('terms', NULL, array());
395 + endif;
344 396
345 - fwp_categories_page();
397 + ?>
398 + <table class="edit-form narrow">
399 + <tbody>
400 + <?php
401 + foreach ($taxonomies as $tax) :
402 + $taxonomy = get_taxonomy($tax);
403 + ?>
404 + <tr><th><?php print $taxonomy->labels->name; ?></th>
405 + <td><?php
406 + if (isset($option_map[$tax])) :
407 + $option = $option_map[$tax];
408 + $globalCats = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option($option));
409 + elseif (isset($globalTax[$tax])) :
410 + $globalCats = $globalTax[$tax];
411 + else :
412 + $globalCats = array();
413 + endif;
414 + $globalCats = array_map('trim', $globalCats);
415 +
416 + if ($page->for_feed_settings()) :
417 + $add_global_categories = $link->setting("add/$tax", NULL, 'yes');
418 + $checked = array('yes' => '', 'no' => '');
419 + $checked[$add_global_categories] = ' checked="checked"';
420 +
421 + if (isset($setting_map[$tax])) :
422 + $setting = $setting_map[$tax];
423 + $cats = $link->setting($setting, NULL, NULL);
424 + if (is_null($cats)) : $cats = array(); endif;
425 + elseif (isset($terms[$tax])) :
426 + $cats = $terms[$tax];
427 + else :
428 + $cats = array();
429 + endif;
430 + else :
431 + $cats = $globalCats;
432 + endif;
433 +
434 + if ($page->for_feed_settings()) :
435 + ?>
436 + <table class="twofer">
437 + <tbody>
438 + <tr>
439 + <td class="primary">
440 + <?php
441 + endif;
442 +
443 + $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax));
444 +
445 + if ($taxonomy->hierarchical) : // Use a category-style checkbox
446 + fwp_category_box($dogs, 'all '.$page->these_posts_phrase(), /*tags=*/ array(), /*params=*/ array('taxonomy' => $tax));
447 + else : // Use a tag-style edit box
448 + fwp_tags_box($cats, 'all '.$page->these_posts_phrase(), /*params=*/ array('taxonomy' => $tax));
449 + endif;
450 +
451 + $globalDogs = SyndicatedPost::category_ids($globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax));
452 +
453 + $siteWideHref = 'admin.php?page='.$GLOBALS['fwp_path'].'/'.basename(__FILE__);
454 + if ($page->for_feed_settings()) :
455 + ?>
456 + </td>
457 + <td class="secondary">
458 + <h4>Site-wide <?php print $taxonomy->labels->name; ?></h4>
459 + <?php if (count($globalCats) > 0) : ?>
460 + <ul class="current-setting">
461 + <?php foreach ($globalDogs as $dog) : ?>
462 + <li><?php $cat = get_term($dog, $tax); print $cat->name; ?></li>
463 + <?php endforeach; ?>
464 + </ul>
465 + </div>
466 + <p>
467 + <?php else : ?>
468 + <p>Site-wide settings may also assign categories to syndicated
469 + posts.
470 + <?php endif; ?>
471 + Should <?php print $page->these_posts_phrase(); ?> be assigned
472 + these <?php print $taxonomy->labels->name; ?> from the <a href="<?php print esc_html($siteWideHref); ?>">site-wide settings</a>, in
473 + addition to the feed-specific <?php print $taxonomy->labels->name; ?> you set up here?</p>
474 +
475 + <ul class="settings">
476 + <li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="yes" <?php print $checked['yes']; ?> /> Yes. Place <?php print $page->these_posts_phrase(); ?> under all these categories.</label></p></li>
477 + <li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="no" <?php print $checked['no']; ?> /> No. Only use the categories I set up on the left. Do not use the global defaults for <?php print $page->these_posts_phrase(); ?></label></p></li>
478 + </ul>
479 + </td>
480 + </tr>
481 + </tbody>
482 + </table>
483 + <?php
484 + endif;
485 + ?>
486 + </td>
487 + </tr>
488 + <?php
489 + endforeach;
490 + ?>
491 + </tbody>
492 + </table>
493 + <?php
494 + } /* FeedWordPressCategoriesPage::categories_box () */
495 +
496 + function save_settings ($post) {
497 + if (isset($post['match_categories'])) :
498 + foreach ($post['match_categories'] as $what => $set) :
499 + // Defaulting is controlled by a separate radio button
500 + if ($this->for_feed_settings()
501 + and isset($post['match_default'])
502 + and isset($post['match_default'][$what])
503 + and $post['match_default'][$what]=='yes') :
504 + $set = NULL; // Defaulted!
505 + endif;
506 +
507 + $this->update_setting("match/$what", $set, NULL);
508 + endforeach;
509 + endif;
510 + $optionMap = $this->term_option_map();
511 + $settingMap = $this->term_setting_map();
512 +
513 + $saveTerms = array(); $separateSaveTerms = array('category' => array(), 'post_tag' => array());
514 +
515 + if (!isset($post['tax_input'])) : $post['tax_input'] = array(); endif;
516 +
517 + // Merge in data from older-notation category check boxes
518 + if (isset($post['post_category'])) :
519 + // Just merging in for processing below.
520 + $post['tax_input']['category'] = array_merge(
521 + (isset($post['tax_input']['category']) ? $post['tax_input']['category'] : array()),
522 + $post['post_category']
523 + );
524 + endif;
525 +
526 + // Process data from term tag boxes and check boxes
527 + foreach ($post['tax_input'] as $tax => $terms) :
528 + $saveTerms[$tax] = array();
529 + if (is_array($terms)) : // Numeric IDs from checklist
530 + foreach ($terms as $term) :
531 + if ($term) :
532 + $saveTerms[$tax][] = '{'.$tax.'#'.$term.'}';
533 + endif;
534 + endforeach;
535 + else : // String from tag input
536 + $saveTerms[$tax] = explode(",", $terms);
537 + endif;
538 + $saveTerms[$tax] = array_map('trim', $saveTerms[$tax]);
539 +
540 + if (isset($optionMap[$tax])) :
541 + $separateSaveTerms[$tax] = $saveTerms[$tax];
542 + unset($saveTerms[$tax]);
543 + endif;
544 + endforeach;
545 +
546 + if (isset($post['post_category'])) :
547 + foreach ($post['post_category'] as $cat) :
548 + $separateSaveTerms['category'][] = '{category#'.$cat.'}';
549 + endforeach;
550 + endif;
551 +
552 + // Unmatched categories and tags
553 + foreach (array('category', 'post_tag') as $what) :
554 + if (isset($post["unfamiliar_{$what}"])) :
555 + $this->update_setting(
556 + "unfamiliar {$what}",
557 + $post["unfamiliar_{$what}"],
558 + 'site-default'
559 + );
560 + endif;
561 + endforeach;
562 +
563 + // Categories and Tags
564 + foreach ($separateSaveTerms as $tax => $terms) :
565 + if ($this->for_feed_settings()) :
566 + $this->link->update_setting($settingMap[$tax], $terms, array());
567 + else :
568 + if (!empty($terms)) :
569 + update_option($optionMap[$tax], implode(FEEDWORDPRESS_CAT_SEPARATOR, $terms));
570 + else :
571 + delete_option($optionMap[$tax]);
572 + endif;
573 + endif;
574 + endforeach;
575 +
576 + // Other terms
577 + $this->update_setting(array('feed'=>'terms', 'global'=>'syndication_terms'), $saveTerms, array());
578 +
579 + if ($this->for_feed_settings()) :
580 + // Category splitting regex
581 + if (isset($post['cat_split'])) :
582 + $this->link->update_setting('cat_split', trim($post['cat_split']), '');
583 + endif;
584 +
585 + // Treat global terms (cats, tags, etc.) as additional,
586 + // or as defaults to be overridden and replaced?
587 + if (isset($post['add_global'])) :
588 + foreach ($post['add_global'] as $what => $value) :
589 + $this->link->update_setting("add/$what", $value);
590 + endforeach;
591 + endif;
592 + endif;
593 + parent::save_settings($post);
594 + } /* FeedWordPressCategoriesPage::save_settings() */
595 +
596 + function display () {
597 + ////////////////////////////////////////////////
598 + // Display settings boxes //////////////////////
599 + ////////////////////////////////////////////////
600 +
601 + $this->boxes_by_methods = array(
602 + 'feed_categories_box' => __('Feed Categories'.FEEDWORDPRESS_AND_TAGS),
603 + 'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'),
604 + );
605 + if (!FeedWordPressCompatibility::post_tags()) :
606 + unset($this->boxes_by_methods['tags_box']);
607 + endif;
608 +
609 + parent::display();
610 + }
611 +}
612 +
613 + $categoriesPage = new FeedWordPressCategoriesPage;
614 + $categoriesPage->display();
346 615