PluginProbe
FeedWordPress / 2009.1112
FeedWordPress v2009.1112
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.1112, at categories-page.php

281 lines 10.1 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 class FeedWordPressCategoriesPage extends FeedWordPressAdminPage {
5 function FeedWordPressCategoriesPage ($link) {
6 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresscategories', $link);
7 $this->dispatch = 'feedwordpress_categories_settings';
8 $this->filename = __FILE__;
9 }
10
11 /*static*/ function feed_categories_box ($page, $box = NULL) {
12
13 $link = $page->link;
14
15 $unfamiliar = array ('create'=>'','tag' => '', 'default'=>'','filter'=>'');
16 if ($page->for_feed_settings()) :
17 $unfamiliar['site-default'] = '';
18 $ucKey = $link->settings["unfamiliar category"];
19 $ucDefault = 'site-default';
20 else :
21 $ucKey = FeedWordPress::on_unfamiliar('category');
22 $ucDefault = 'create';
23 endif;
24
25 if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) :
26 $ucKey = $ucDefault;
27 endif;
28 $unfamiliar[$ucKey] = ' checked="checked"';
29
30 // Hey ho, let's go...
31 ?>
32 <table class="edit-form">
33 <tr>
34 <th scope="row">Unfamiliar categories:</th>
35 <td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
36
37 <ul class="options">
38 <?php if ($page->for_feed_settings()) : ?>
39 <li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php echo $unfamiliar['site-default']; ?> /> use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>">site-wide setting</a>
40 (currently <strong><?php echo FeedWordPress::on_unfamiliar('category'); ?></strong>)</label></li>
41 <?php endif; ?>
42
43 <li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['create']; ?> /> create a new category</label></li>
44
45 <?php if (FeedWordPressCompatibility::post_tags()) : ?>
46 <li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar['tag']; ?>/> create a new tag</label></li>
47 <?php endif; ?>
48
49 <li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar['default']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?></label></li>
50 <li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar['filter']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?> and don't syndicate posts unless they match at least one familiar category</label></li>
51 </ul></td>
52 </tr>
53
54 <?php if ($page->for_feed_settings()) : ?>
55 <tr>
56 <th scope="row">Multiple categories:</th>
57 <td>
58 <input type="text" size="20" id="cat_split" name="cat_split" value="<?php if (isset($link->settings['cat_split'])) : echo htmlspecialchars($link->settings['cat_split']); endif; ?>" />
59 <p class="setting-description">Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
60 categories in a single category element. The regular expression should match
61 the characters used to separate one category from the next. If the feed uses
62 spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
63 If the feed does not provide multiple categories in a single element, leave this
64 blank.</p></td>
65 </tr>
66 <?php endif; ?>
67 </table>
68 <?php
69 } /* FeedWordPressCategoriesPage::feed_categories_box() */
70
71 function categories_box ($page, $box = NULL) {
72 $link = $page->link;
73 if ($page->for_feed_settings()) :
74 if (is_array($link->settings['cats'])) : $cats = $link->settings['cats'];
75 else : $cats = array();
76 endif;
77 else :
78 $cats = array_map('trim',
79 preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats'))
80 );
81 endif;
82 $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL);
83
84 fwp_category_box($dogs, 'all '.$page->these_posts_phrase());
85 } /* FeedWordPressCategoriesPage::categories_box () */
86
87 function tags_box ($page, $box = NULL) {
88 $link = $page->link;
89 if ($page->for_feed_settings()) :
90 $tags = $link->settings['tags'];
91 else :
92 $tags = array_map('trim',
93 preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_tags'))
94 );
95 endif;
96
97 fwp_tags_box($tags, 'all '.$page->these_posts_phrase());
98 } /* FeedWordPressCategoriesPage::tags_box () */
99 }
100
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;
108
109 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_categories_settings', /*capability=*/ 'manage_links');
110
111 $link = FeedWordPressAdminPage::submitted_link();
112 $link_id = $link->id;
113
114 $catsPage = new FeedWordPressCategoriesPage($link);
115
116 $mesg = null;
117
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.'}';
126 endforeach;
127 endif;
128
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']);
135 endif;
136 $syndicatedTags = array_map('trim', $syndicatedTags);
137
138 if (is_object($link) and $link->found()) :
139 $alter = array ();
140
141 // Categories
142 if (!empty($saveCats)) : $link->settings['cats'] = $saveCats;
143 else : unset($link->settings['cats']);
144 endif;
145
146 // Tags
147 $link->settings['tags'] = $syndicatedTags;
148
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;
156 endif;
157
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']);
162 else :
163 unset($link->settings['cat_split']);
164 endif;
165 endif;
166
167 $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
168
169 $alter_set = implode(", ", $alter);
170
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);
182 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 endif;
203
204 do_action('feedwordpress_admin_page_categories_save', $GLOBALS['fwp_post'], $catsPage);
205 else :
206 $catsPage->updated = false;
207 endif;
208
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>
221
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()
252 );
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
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 () */
278
279 fwp_categories_page();
280
281