PluginProbe
FeedWordPress / 2009.0612
FeedWordPress v2009.0612
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / categories-page.php

categories-page.php in FeedWordPress 2009.0612, at categories-page.php

347 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(dirname(__FILE__) . '/admin-ui.php');
3
4 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 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']);
42 endif;
43
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;
51
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"]);
56 else :
57 $link->settings["unfamiliar category"] = $GLOBALS['fwp_post']["unfamiliar_category"];
58 endif;
59 endif;
60
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;
68 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);
85 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');
93 endif;
94
95 // Tags
96 if (isset($_REQUEST['tags_input'])) :
97 $tags = explode(",", $_REQUEST['tags_input']);
98 else :
99 $tags = array();
100 endif;
101
102 if (!empty($tags)) :
103 update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $tags));
104 else :
105 delete_option('feedwordpress_syndication_tags');
106 endif;
107
108 update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
109
110 $updated_link = true;
111 endif;
112 else :
113 $updated_link = false;
114 endif;
115
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';
125
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>
173 <?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>
195 <?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>
197
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>
203
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; */ ?>
262
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; ?>
270
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 <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>
281
282 <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; ?>
287
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>
292 <?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>
297 </tr>
298
299 <?php if (is_object($link) and $link->found()) : ?>
300 <tr>
301 <th scope="row">Multiple categories:</th>
302 <td>
303 <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; ?>" />
304 <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
305 categories in a single category element. The regular expression should match
306 the characters used to separate one category from the next. If the feed uses
307 spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
308 If the feed does not provide multiple categories in a single element, leave this
309 blank.</p></td>
310 </tr>
311 <?php endif; ?>
312 </table>
313 <?php
314 fwp_option_box_closer();
315 fwp_linkedit_periodic_submit();
316
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>
323
324 <p class="submit">
325 <input class="button-primary" type="submit" name="save" value="Save Changes" />
326 </p>
327
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 () */
344
345 fwp_categories_page();
346
347