| @@ -1,61 +1,357 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | require_once(dirname(__FILE__) . '/admin-ui.php'); |
| 3 | 3 | |
| 4 | 4 | class FeedWordPressCategoriesPage extends FeedWordPressAdminPage { |
| 5 | - function FeedWordPressCategoriesPage ($link) { | |
| 6 | - FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresscategories', $link); | |
| 7 | - $this->dispatch = 'feedwordpress_categories_settings'; | |
| 5 | + public function __construct( $link = -1 ) { | |
| 6 | + if (is_numeric($link) and -1 == $link) : | |
| 7 | + $link = $this->submitted_link(); | |
| 8 | + endif; | |
| 9 | + | |
| 10 | + parent::__construct('feedwordpresscategories', $link); | |
| 11 | + $this->dispatch = 'feedwordpress_admin_page_categories'; | |
| 12 | + $this->pagenames = array( | |
| 13 | + 'default' => 'Categories & Tags', | |
| 14 | + 'settings-update' => 'Syndicated Categories & Tags', | |
| 15 | + 'open-sheet' => 'Categories & Tags', | |
| 16 | + ); | |
| 8 | 17 | $this->filename = __FILE__; |
| 9 | 18 | } |
| 10 | - | |
| 11 | - /*static*/ function feed_categories_box ($page, $box = NULL) { | |
| 12 | 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) { | |
| 13 | 30 | $link = $page->link; |
| 14 | 31 | |
| 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'; | |
| 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'); | |
| 20 | 35 | else : |
| 21 | - $ucKey = FeedWordPress::on_unfamiliar('category'); | |
| 22 | - $ucDefault = 'create'; | |
| 36 | + $post_type = $globalPostType; | |
| 23 | 37 | endif; |
| 24 | - | |
| 25 | - if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) : | |
| 26 | - $ucKey = $ucDefault; | |
| 38 | + $taxonomies = get_object_taxonomies(array('object_type' => $post_type), 'names'); | |
| 39 | + | |
| 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; | |
| 49 | + | |
| 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; | |
| 57 | + | |
| 58 | + foreach (array('cats', 'tags', 'filter') as $what) : | |
| 59 | + $matchUl[$what][$tax] = array( | |
| 60 | + 'checked' => '', | |
| 61 | + 'labels' => $taxonomy->labels, | |
| 62 | + ); | |
| 63 | + endforeach; | |
| 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]; | |
| 99 | + endif; | |
| 100 | + endforeach; | |
| 101 | + | |
| 102 | + if ($this->for_feed_settings()) : | |
| 103 | + $href = $this->admin_page_href(basename(__FILE__)); | |
| 104 | + | |
| 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'] = ''; | |
| 124 | + else : | |
| 125 | + $opts = array_keys($unmatched[$what]); | |
| 126 | + $unmatchedDefault[$what] = $opts[0]; | |
| 127 | + $unmatchedColumns[$what] = array(); | |
| 128 | + 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; | |
| 140 | + | |
| 141 | + $match = $globalMatch; | |
| 27 | 142 | endif; |
| 28 | - $unfamiliar[$ucKey] = ' checked="checked"'; | |
| 29 | - | |
| 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]; | |
| 150 | + endif; | |
| 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"'; | |
| 161 | + endif; | |
| 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; | |
| 177 | + endif; | |
| 178 | + | |
| 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; | |
| 185 | + endif; | |
| 186 | + endforeach; | |
| 187 | + | |
| 30 | 188 | // Hey ho, let's go... |
| 189 | + $offerSiteWideSettings = ($page->for_feed_settings() and ($post_type==$globalPostType)); | |
| 31 | 190 | ?> |
| 32 | -<table class="edit-form"> | |
| 191 | +<table class="edit-form narrow"> | |
| 33 | 192 | <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> | |
| 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> | |
| 36 | 224 | |
| 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> | |
| 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> | |
| 229 | + | |
| 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> | |
| 248 | + | |
| 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><a rel="tag">...</a></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> | |
| 41 | 271 | <?php endif; ?> |
| 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> | |
| 285 | +<?php endif; ?> | |
| 286 | +</td> | |
| 287 | +</tr> | |
| 42 | 288 | |
| 43 | -<li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['create']; ?> /> create a new category</label></li> | |
| 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> | |
| 44 | 293 | |
| 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> | |
| 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> | |
| 311 | + | |
| 312 | +</td></tr> | |
| 313 | + | |
| 314 | +<tr> | |
| 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;"> | |
| 47 | 332 | <?php endif; ?> |
| 48 | 333 | |
| 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> | |
| 334 | +<ul class="options"> | |
| 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> | |
| 341 | + | |
| 342 | +<?php if ($offerSiteWideSettings) : ?> | |
| 343 | + </div> | |
| 344 | + </td></tr> | |
| 345 | + </tbody> | |
| 346 | + </table> | |
| 347 | +<?php endif; ?> | |
| 348 | +</td> | |
| 52 | 349 | </tr> |
| 53 | - | |
| 54 | 350 | <?php if ($page->for_feed_settings()) : ?> |
| 55 | 351 | <tr> |
| 56 | 352 | <th scope="row">Multiple categories:</th> |
| 57 | -<td> | |
| 353 | +<td> | |
| 58 | 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; ?>" /> |
| 59 | 355 | <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 | 356 | categories in a single category element. The regular expression should match |
| 61 | 357 | the characters used to separate one category from the next. If the feed uses |
| @@ -67,214 +363,253 @@ | ||
| 67 | 363 | </table> |
| 68 | 364 | <?php |
| 69 | 365 | } /* FeedWordPressCategoriesPage::feed_categories_box() */ |
| 70 | 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 | + } | |
| 379 | + | |
| 71 | 380 | function categories_box ($page, $box = NULL) { |
| 72 | 381 | $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; | |
| 382 | + $dummy = null; | |
| 383 | + $syndicatedlink = new SyndicatedLink($dummy); | |
| 384 | + | |
| 385 | + if ($this->for_feed_settings()) : | |
| 386 | + $post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post'); | |
| 77 | 387 | else : |
| 78 | - $cats = array_map('trim', | |
| 79 | - preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats')) | |
| 80 | - ); | |
| 388 | + $post_type = get_option('feedwordpress_syndicated_post_type', 'post'); | |
| 81 | 389 | endif; |
| 82 | - $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL); | |
| 390 | + $taxonomies = get_object_taxonomies(array('object_type' => $post_type), 'names'); | |
| 83 | 391 | |
| 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; | |
| 392 | + $option_map = $this->term_option_map(); | |
| 393 | + $setting_map = $this->term_setting_map(); | |
| 394 | + $globalTax = get_option('feedwordpress_syndication_terms', array()); | |
| 89 | 395 | 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 | - ); | |
| 396 | + $terms = $link->setting('terms', NULL, array()); | |
| 95 | 397 | endif; |
| 96 | 398 | |
| 97 | - fwp_tags_box($tags, 'all '.$page->these_posts_phrase()); | |
| 98 | - } /* FeedWordPressCategoriesPage::tags_box () */ | |
| 99 | -} | |
| 399 | + ?> | |
| 400 | + <table class="edit-form narrow"> | |
| 401 | + <tbody> | |
| 402 | + <?php | |
| 403 | + foreach ($taxonomies as $tax) : | |
| 404 | + $taxonomy = get_taxonomy($tax); | |
| 405 | + ?> | |
| 406 | + <tr><th><?php print $taxonomy->labels->name; ?></th> | |
| 407 | + <td><?php | |
| 408 | + if (isset($option_map[$tax])) : | |
| 409 | + $option = $option_map[$tax]; | |
| 410 | + $globalCats = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option($option)); | |
| 411 | + elseif (isset($globalTax[$tax])) : | |
| 412 | + $globalCats = $globalTax[$tax]; | |
| 413 | + else : | |
| 414 | + $globalCats = array(); | |
| 415 | + endif; | |
| 416 | + $globalCats = array_map('trim', $globalCats); | |
| 100 | 417 | |
| 101 | -function fwp_categories_page () { | |
| 102 | - global $wpdb, $wp_db_version; | |
| 103 | - | |
| 104 | - if (FeedWordPress::needs_upgrade()) : | |
| 105 | - fwp_upgrade_page(); | |
| 106 | - return; | |
| 107 | - endif; | |
| 418 | + if ($page->for_feed_settings()) : | |
| 419 | + $add_global_categories = $link->setting("add/$tax", NULL, 'yes'); | |
| 420 | + $checked = array('yes' => '', 'no' => ''); | |
| 421 | + $checked[$add_global_categories] = ' checked="checked"'; | |
| 108 | 422 | |
| 109 | - FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_categories_settings', /*capability=*/ 'manage_links'); | |
| 423 | + if (isset($setting_map[$tax])) : | |
| 424 | + $setting = $setting_map[$tax]; | |
| 425 | + $cats = $link->setting($setting, NULL, NULL); | |
| 426 | + if (is_null($cats)) : $cats = array(); endif; | |
| 427 | + elseif (isset($terms[$tax])) : | |
| 428 | + $cats = $terms[$tax]; | |
| 429 | + else : | |
| 430 | + $cats = array(); | |
| 431 | + endif; | |
| 432 | + else : | |
| 433 | + $cats = $globalCats; | |
| 434 | + endif; | |
| 110 | 435 | |
| 111 | - $link = FeedWordPressAdminPage::submitted_link(); | |
| 112 | - $link_id = $link->id; | |
| 436 | + if ($page->for_feed_settings()) : | |
| 437 | + ?> | |
| 438 | + <table class="twofer"> | |
| 439 | + <tbody> | |
| 440 | + <tr> | |
| 441 | + <td class="primary"> | |
| 442 | + <?php | |
| 443 | + endif; | |
| 113 | 444 | |
| 114 | - $catsPage = new FeedWordPressCategoriesPage($link); | |
| 445 | + $dogs = $syndicatedlink->category_ids(/*post=*/ NULL, $cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax)); | |
| 446 | + | |
| 447 | + if ($taxonomy->hierarchical) : // Use a category-style checkbox | |
| 448 | + fwp_category_box($dogs, 'all '.$page->these_posts_phrase(), /*tags=*/ array(), /*params=*/ array('taxonomy' => $tax)); | |
| 449 | + else : // Use a tag-style edit box | |
| 450 | + fwp_tags_box($cats, 'all '.$page->these_posts_phrase(), /*params=*/ array('taxonomy' => $tax)); | |
| 451 | + endif; | |
| 115 | 452 | |
| 116 | - $mesg = null; | |
| 453 | + $globalDogs = $syndicatedlink->category_ids(/*post=*/ NULL, $globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax)); | |
| 117 | 454 | |
| 118 | - //////////////////////////////////////////////// | |
| 119 | - // Process POST request, if any ///////////////// | |
| 120 | - //////////////////////////////////////////////// | |
| 121 | - if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['submit'])) : | |
| 122 | - $saveCats = array(); | |
| 123 | - if (isset($GLOBALS['fwp_post']['post_category'])) : | |
| 124 | - foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) : | |
| 125 | - $saveCats[] = '{#'.$cat_id.'}'; | |
| 455 | + $siteWideHref = $this->admin_page_href(basename(__FILE__)); | |
| 456 | + | |
| 457 | + if ($page->for_feed_settings()) : | |
| 458 | + ?> | |
| 459 | + </td> | |
| 460 | + <td class="secondary"> | |
| 461 | + <h4>Site-wide <?php print $taxonomy->labels->name; ?></h4> | |
| 462 | + <?php if (count($globalCats) > 0) : ?> | |
| 463 | + <ul class="current-setting"> | |
| 464 | + <?php foreach ($globalDogs as $dog) : ?> | |
| 465 | + <li><?php $cat = get_term($dog, $tax); print $cat->name; ?></li> | |
| 466 | + <?php endforeach; ?> | |
| 467 | + </ul> | |
| 468 | + </div> | |
| 469 | + <p> | |
| 470 | + <?php else : ?> | |
| 471 | + <p>Site-wide settings may also assign categories to syndicated | |
| 472 | + posts. | |
| 473 | + <?php endif; ?> | |
| 474 | + Should <?php print $page->these_posts_phrase(); ?> be assigned | |
| 475 | + these <?php print $taxonomy->labels->name; ?> from the <a href="<?php print esc_html($siteWideHref); ?>">site-wide settings</a>, in | |
| 476 | + addition to the feed-specific <?php print $taxonomy->labels->name; ?> you set up here?</p> | |
| 477 | + | |
| 478 | + <ul class="settings"> | |
| 479 | + <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> | |
| 480 | + <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> | |
| 481 | + </ul> | |
| 482 | + </td> | |
| 483 | + </tr> | |
| 484 | + </tbody> | |
| 485 | + </table> | |
| 486 | + <?php | |
| 487 | + endif; | |
| 488 | + ?> | |
| 489 | + </td> | |
| 490 | + </tr> | |
| 491 | + <?php | |
| 492 | + endforeach; | |
| 493 | + ?> | |
| 494 | + </tbody> | |
| 495 | + </table> | |
| 496 | + <?php | |
| 497 | + } /* FeedWordPressCategoriesPage::categories_box () */ | |
| 498 | + | |
| 499 | + function save_settings ($post) { | |
| 500 | + if (isset($post['match_categories'])) : | |
| 501 | + foreach ($post['match_categories'] as $what => $set) : | |
| 502 | + // Defaulting is controlled by a separate radio button | |
| 503 | + if ($this->for_feed_settings() | |
| 504 | + and isset($post['match_default']) | |
| 505 | + and isset($post['match_default'][$what]) | |
| 506 | + and $post['match_default'][$what]=='yes') : | |
| 507 | + $set = NULL; // Defaulted! | |
| 508 | + endif; | |
| 509 | + | |
| 510 | + $this->update_setting("match/$what", $set, NULL); | |
| 126 | 511 | endforeach; |
| 127 | 512 | endif; |
| 513 | + $optionMap = $this->term_option_map(); | |
| 514 | + $settingMap = $this->term_setting_map(); | |
| 128 | 515 | |
| 129 | - // Different variable names to cope with different WordPress AJAX UIs | |
| 130 | - $syndicatedTags = array(); | |
| 131 | - if (isset($GLOBALS['fwp_post']['tax_input']['post_tag'])) : | |
| 132 | - $syndicatedTags = explode(",", $GLOBALS['fwp_post']['tax_input']['post_tag']); | |
| 133 | - elseif (isset($GLOBALS['fwp_post']['tags_input'])) : | |
| 134 | - $syndicatedTags = explode(",", $GLOBALS['fwp_post']['tags_input']); | |
| 516 | + $saveTerms = array(); $separateSaveTerms = array('category' => array(), 'post_tag' => array()); | |
| 517 | + | |
| 518 | + if (!isset($post['tax_input'])) : $post['tax_input'] = array(); endif; | |
| 519 | + | |
| 520 | + // Merge in data from older-notation category check boxes | |
| 521 | + if (isset($post['post_category'])) : | |
| 522 | + // Just merging in for processing below. | |
| 523 | + $post['tax_input']['category'] = array_merge( | |
| 524 | + (isset($post['tax_input']['category']) ? $post['tax_input']['category'] : array()), | |
| 525 | + $post['post_category'] | |
| 526 | + ); | |
| 135 | 527 | endif; |
| 136 | - $syndicatedTags = array_map('trim', $syndicatedTags); | |
| 137 | 528 | |
| 138 | - if (is_object($link) and $link->found()) : | |
| 139 | - $alter = array (); | |
| 529 | + // Process data from term tag boxes and check boxes | |
| 530 | + foreach ($post['tax_input'] as $tax => $terms) : | |
| 531 | + $saveTerms[$tax] = array(); | |
| 532 | + if (is_array($terms)) : // Numeric IDs from checklist | |
| 533 | + foreach ($terms as $term) : | |
| 534 | + if ($term) : | |
| 535 | + $saveTerms[$tax][] = '{'.$tax.'#'.$term.'}'; | |
| 536 | + endif; | |
| 537 | + endforeach; | |
| 538 | + else : // String from tag input | |
| 539 | + $saveTerms[$tax] = explode(",", $terms); | |
| 540 | + endif; | |
| 541 | + $saveTerms[$tax] = array_map('trim', $saveTerms[$tax]); | |
| 140 | 542 | |
| 141 | - // Categories | |
| 142 | - if (!empty($saveCats)) : $link->settings['cats'] = $saveCats; | |
| 143 | - else : unset($link->settings['cats']); | |
| 543 | + if (isset($optionMap[$tax])) : | |
| 544 | + $separateSaveTerms[$tax] = $saveTerms[$tax]; | |
| 545 | + unset($saveTerms[$tax]); | |
| 144 | 546 | endif; |
| 547 | + endforeach; | |
| 145 | 548 | |
| 146 | - // Tags | |
| 147 | - $link->settings['tags'] = $syndicatedTags; | |
| 549 | + if (isset($post['post_category'])) : | |
| 550 | + foreach ($post['post_category'] as $cat) : | |
| 551 | + $separateSaveTerms['category'][] = '{category#'.$cat.'}'; | |
| 552 | + endforeach; | |
| 553 | + endif; | |
| 148 | 554 | |
| 149 | - // Unfamiliar categories | |
| 150 | - if (isset($GLOBALS['fwp_post']["unfamiliar_category"])) : | |
| 151 | - if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_category"]) : | |
| 152 | - unset($link->settings["unfamiliar category"]); | |
| 153 | - else : | |
| 154 | - $link->settings["unfamiliar category"] = $GLOBALS['fwp_post']["unfamiliar_category"]; | |
| 155 | - endif; | |
| 555 | + // Unmatched categories and tags | |
| 556 | + foreach (array('category', 'post_tag') as $what) : | |
| 557 | + if (isset($post["unfamiliar_{$what}"])) : | |
| 558 | + $this->update_setting( | |
| 559 | + "unfamiliar {$what}", | |
| 560 | + $post["unfamiliar_{$what}"], | |
| 561 | + 'site-default' | |
| 562 | + ); | |
| 156 | 563 | endif; |
| 564 | + endforeach; | |
| 157 | 565 | |
| 158 | - // Category spitting regex | |
| 159 | - if (isset($GLOBALS['fwp_post']['cat_split'])) : | |
| 160 | - if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) : | |
| 161 | - $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']); | |
| 566 | + // Categories and Tags | |
| 567 | + foreach ($separateSaveTerms as $tax => $terms) : | |
| 568 | + if ($this->for_feed_settings()) : | |
| 569 | + $this->link->update_setting($settingMap[$tax], $terms, array()); | |
| 570 | + else : | |
| 571 | + if (!empty($terms)) : | |
| 572 | + update_option($optionMap[$tax], implode(FEEDWORDPRESS_CAT_SEPARATOR, $terms)); | |
| 162 | 573 | else : |
| 163 | - unset($link->settings['cat_split']); | |
| 574 | + delete_option($optionMap[$tax]); | |
| 164 | 575 | endif; |
| 165 | 576 | endif; |
| 577 | + endforeach; | |
| 166 | 578 | |
| 167 | - $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'"; | |
| 579 | + // Other terms | |
| 580 | + $this->update_setting(array('feed'=>'terms', 'global'=>'syndication_terms'), $saveTerms, array()); | |
| 168 | 581 | |
| 169 | - $alter_set = implode(", ", $alter); | |
| 582 | + if ($this->for_feed_settings()) : | |
| 583 | + // Category splitting regex | |
| 584 | + if (isset($post['cat_split'])) : | |
| 585 | + $this->link->update_setting('cat_split', trim($post['cat_split']), ''); | |
| 586 | + endif; | |
| 170 | 587 | |
| 171 | - // issue update query | |
| 172 | - $result = $wpdb->query(" | |
| 173 | - UPDATE $wpdb->links | |
| 174 | - SET $alter_set | |
| 175 | - WHERE link_id='$link_id' | |
| 176 | - "); | |
| 177 | - $catsPage->updated = true; | |
| 178 | - | |
| 179 | - // reload link information from DB | |
| 180 | - if (function_exists('clean_bookmark_cache')) : | |
| 181 | - clean_bookmark_cache($link_id); | |
| 588 | + // Treat global terms (cats, tags, etc.) as additional, | |
| 589 | + // or as defaults to be overridden and replaced? | |
| 590 | + if (isset($post['add_global'])) : | |
| 591 | + foreach ($post['add_global'] as $what => $value) : | |
| 592 | + $this->link->update_setting("add/$what", $value); | |
| 593 | + endforeach; | |
| 182 | 594 | endif; |
| 183 | - $link =& new SyndicatedLink($link_id); | |
| 184 | - else : | |
| 185 | - // Categories | |
| 186 | - if (!empty($saveCats)) : | |
| 187 | - update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $saveCats)); | |
| 188 | - else : | |
| 189 | - delete_option('feedwordpress_syndication_cats'); | |
| 190 | - endif; | |
| 191 | - | |
| 192 | - // Tags | |
| 193 | - if (!empty($syndicatedTags)) : | |
| 194 | - update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $syndicatedTags)); | |
| 195 | - else : | |
| 196 | - delete_option('feedwordpress_syndication_tags'); | |
| 197 | - endif; | |
| 198 | - | |
| 199 | - update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']); | |
| 200 | - | |
| 201 | - $catsPage->updated = true; | |
| 202 | 595 | endif; |
| 203 | - | |
| 204 | - do_action('feedwordpress_admin_page_categories_save', $GLOBALS['fwp_post'], $catsPage); | |
| 205 | - else : | |
| 206 | - $catsPage->updated = false; | |
| 207 | - endif; | |
| 596 | + parent::save_settings($post); | |
| 597 | + } /* FeedWordPressCategoriesPage::save_settings() */ | |
| 208 | 598 | |
| 209 | - //////////////////////////////////////////////// | |
| 210 | - // Prepare settings page /////////////////////// | |
| 211 | - //////////////////////////////////////////////// | |
| 212 | - | |
| 213 | - $catsPage->display_update_notice_if_updated('Syndicated categories'.FEEDWORDPRESS_AND_TAGS, $mesg); | |
| 214 | - $catsPage->open_sheet('Categories'.FEEDWORDPRESS_AND_TAGS); | |
| 215 | - ?> | |
| 216 | - <style type="text/css"> | |
| 217 | - table.edit-form th { width: 27%; vertical-align: top; } | |
| 218 | - table.edit-form td { width: 73%; vertical-align: top; } | |
| 219 | - table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; } | |
| 220 | - </style> | |
| 599 | + function display () { | |
| 600 | + //////////////////////////////////////////////// | |
| 601 | + // Display settings boxes ////////////////////// | |
| 602 | + //////////////////////////////////////////////// | |
| 221 | 603 | |
| 222 | - <div id="post-body"> | |
| 223 | - <?php | |
| 224 | - //////////////////////////////////////////////// | |
| 225 | - // Display settings boxes ////////////////////// | |
| 226 | - //////////////////////////////////////////////// | |
| 227 | - | |
| 228 | - $boxes_by_methods = array( | |
| 229 | - 'feed_categories_box' => __('Feed Categories'.FEEDWORDPRESS_AND_TAGS), | |
| 230 | - 'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'), | |
| 231 | - 'tags_box' => __('Tags'), | |
| 232 | - ); | |
| 233 | - if (!FeedWordPressCompatibility::post_tags()) : | |
| 234 | - unset($boxes_by_methods['tags_box']); | |
| 235 | - endif; | |
| 236 | - | |
| 237 | - foreach ($boxes_by_methods as $method => $row) : | |
| 238 | - if (is_array($row)) : | |
| 239 | - $id = $row['id']; | |
| 240 | - $title = $row['title']; | |
| 241 | - else : | |
| 242 | - $id = 'feedwordpress_'.$method; | |
| 243 | - $title = $row; | |
| 244 | - endif; | |
| 245 | - | |
| 246 | - fwp_add_meta_box( | |
| 247 | - /*id=*/ $id, | |
| 248 | - /*title=*/ $title, | |
| 249 | - /*callback=*/ array('FeedWordPressCategoriesPage', $method), | |
| 250 | - /*page=*/ $catsPage->meta_box_context(), | |
| 251 | - /*context=*/ $catsPage->meta_box_context() | |
| 604 | + $this->boxes_by_methods = array( | |
| 605 | + 'feed_categories_box' => __('Feed Categories & Tags'), | |
| 606 | + 'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'), | |
| 252 | 607 | ); |
| 253 | - endforeach; | |
| 254 | - do_action('feedwordpress_admin_page_categories_meta_boxes', $catsPage); | |
| 255 | -?> | |
| 256 | - <div class="metabox-holder"> | |
| 257 | -<?php | |
| 258 | - fwp_do_meta_boxes($catsPage->meta_box_context(), $catsPage->meta_box_context(), $catsPage); | |
| 259 | -?> | |
| 260 | - </div> <!-- class="metabox-holder" --> | |
| 261 | - </div> <!-- id="post-body" --> | |
| 262 | - <?php $catsPage->close_sheet(); ?> | |
| 263 | 608 | |
| 264 | -<script type="text/javascript"> | |
| 265 | - contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline'); | |
| 266 | -<?php if (is_object($link) and $link->found()) : ?> | |
| 267 | -<?php for ($j=1; $j<=$i; $j++) : ?> | |
| 268 | - contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline'); | |
| 269 | -<?php endfor; ?> | |
| 270 | - contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline'); | |
| 271 | - contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline'); | |
| 272 | -<?php else : ?> | |
| 273 | - contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true); | |
| 274 | -<?php endif; ?> | |
| 275 | -</script> | |
| 276 | -<?php | |
| 277 | -} /* function fwp_categories_page () */ | |
| 609 | + parent::display(); | |
| 610 | + } | |
| 611 | +} | |
| 278 | 612 | |
| 279 | - fwp_categories_page(); | |
| 613 | + $categoriesPage = new FeedWordPressCategoriesPage; | |
| 614 | + $categoriesPage->display(); | |
| 280 | 615 | |