1 | <?php
|
---|
2 | require_once(dirname(__FILE__) . '/admin-ui.php');
|
---|
3 |
|
---|
4 | function fwp_categories_page () {
|
---|
5 | global $wpdb, $wp_db_version;
|
---|
6 |
|
---|
7 | FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_categories_settings', /*capability=*/ 'manage_links');
|
---|
8 |
|
---|
9 | if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) :
|
---|
10 | $link_id = $_REQUEST['save_link_id'];
|
---|
11 | elseif (isset($_REQUEST['link_id'])) :
|
---|
12 | $link_id = $_REQUEST['link_id'];
|
---|
13 | else :
|
---|
14 | $link_id = NULL;
|
---|
15 | endif;
|
---|
16 |
|
---|
17 | if (is_numeric($link_id) and $link_id) :
|
---|
18 | $link =& new SyndicatedLink($link_id);
|
---|
19 | else :
|
---|
20 | $link = NULL;
|
---|
21 | endif;
|
---|
22 |
|
---|
23 | $mesg = null;
|
---|
24 |
|
---|
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.'}';
|
---|
33 | endforeach;
|
---|
34 | endif;
|
---|
35 |
|
---|
36 | // Different variable names to cope with different WordPress AJAX UIs
|
---|
37 | $syndicatedTags = array();
|
---|
38 | if (isset($GLOBALS['fwp_post']['tax_input']['post_tag'])) :
|
---|
39 | $syndicatedTags = explode(",", $GLOBALS['fwp_post']['tax_input']['post_tag']);
|
---|
40 | elseif (isset($GLOBALS['fwp_post']['tags_input'])) :
|
---|
41 | $syndicatedTags = explode(",", $GLOBALS['fwp_post']['tags_input']);
|
---|
42 | endif;
|
---|
43 | $syndicatedTags = array_map('trim', $syndicatedTags);
|
---|
44 |
|
---|
45 | if (is_object($link) and $link->found()) :
|
---|
46 | $alter = array ();
|
---|
47 |
|
---|
48 | // Categories
|
---|
49 | if (!empty($saveCats)) : $link->settings['cats'] = $saveCats;
|
---|
50 | else : unset($link->settings['cats']);
|
---|
51 | endif;
|
---|
52 |
|
---|
53 | // Tags
|
---|
54 | $link->settings['tags'] = $syndicatedTags;
|
---|
55 |
|
---|
56 | // Unfamiliar categories
|
---|
57 | if (isset($GLOBALS['fwp_post']["unfamiliar_category"])) :
|
---|
58 | if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_category"]) :
|
---|
59 | unset($link->settings["unfamiliar category"]);
|
---|
60 | else :
|
---|
61 | $link->settings["unfamiliar category"] = $GLOBALS['fwp_post']["unfamiliar_category"];
|
---|
62 | endif;
|
---|
63 | endif;
|
---|
64 |
|
---|
65 | // Category spitting regex
|
---|
66 | if (isset($GLOBALS['fwp_post']['cat_split'])) :
|
---|
67 | if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) :
|
---|
68 | $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']);
|
---|
69 | else :
|
---|
70 | unset($link->settings['cat_split']);
|
---|
71 | endif;
|
---|
72 | endif;
|
---|
73 |
|
---|
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);
|
---|
91 | else :
|
---|
92 | // Categories
|
---|
93 | if (!empty($saveCats)) :
|
---|
94 | update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $saveCats));
|
---|
95 | else :
|
---|
96 | delete_option('feedwordpress_syndication_cats');
|
---|
97 | endif;
|
---|
98 |
|
---|
99 | // Tags
|
---|
100 | if (!empty($syndicatedTags)) :
|
---|
101 | update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $syndicatedTags));
|
---|
102 | else :
|
---|
103 | delete_option('feedwordpress_syndication_tags');
|
---|
104 | endif;
|
---|
105 |
|
---|
106 | update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
|
---|
107 |
|
---|
108 | $updated_link = true;
|
---|
109 | endif;
|
---|
110 | else :
|
---|
111 | $updated_link = false;
|
---|
112 | endif;
|
---|
113 |
|
---|
114 | ////////////////////////////////////////////////
|
---|
115 | // Get defaults from database //////////////////
|
---|
116 | ////////////////////////////////////////////////
|
---|
117 |
|
---|
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';
|
---|
123 |
|
---|
124 | if (is_array($link->settings['cats'])) : $cats = $link->settings['cats'];
|
---|
125 | else : $cats = array();
|
---|
126 | endif;
|
---|
127 |
|
---|
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 | );
|
---|
139 | endif;
|
---|
140 |
|
---|
141 | if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) :
|
---|
142 | $ucKey = $ucDefault;
|
---|
143 | endif;
|
---|
144 | $unfamiliar[$ucKey] = ' checked="checked"';
|
---|
145 |
|
---|
146 | $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL);
|
---|
147 | ?>
|
---|
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; ?>" />
|
---|
181 | <?php
|
---|
182 | else :
|
---|
183 | ?>
|
---|
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 & 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') ?> »" />
|
---|
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" -->
|
---|
347 | <?php
|
---|
348 | } /* function fwp_categories_page () */
|
---|
349 |
|
---|
350 | fwp_categories_page();
|
---|
351 |
|
---|