PluginProbe
FeedWordPress / 2010.0531
FeedWordPress v2010.0531
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 2010.0531, at categories-page.php

258 lines 9.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 // Save settings
168 $link->save_settings(/*reload=*/ true);
169 $catsPage->updated = true;
170
171 // Reset, reload
172 unset($link);
173 $link = new SyndicatedLink($link_id);
174 else :
175 // Categories
176 if (!empty($saveCats)) :
177 update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $saveCats));
178 else :
179 delete_option('feedwordpress_syndication_cats');
180 endif;
181
182 // Tags
183 if (!empty($syndicatedTags)) :
184 update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $syndicatedTags));
185 else :
186 delete_option('feedwordpress_syndication_tags');
187 endif;
188
189 update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
190
191 $catsPage->updated = true;
192 endif;
193
194 do_action('feedwordpress_admin_page_categories_save', $GLOBALS['fwp_post'], $catsPage);
195 else :
196 $catsPage->updated = false;
197 endif;
198
199 ////////////////////////////////////////////////
200 // Prepare settings page ///////////////////////
201 ////////////////////////////////////////////////
202
203 $catsPage->display_update_notice_if_updated('Syndicated categories'.FEEDWORDPRESS_AND_TAGS, $mesg);
204 $catsPage->open_sheet('Categories'.FEEDWORDPRESS_AND_TAGS);
205 ?>
206 <style type="text/css">
207 table.edit-form th { width: 27%; vertical-align: top; }
208 table.edit-form td { width: 73%; vertical-align: top; }
209 table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
210 </style>
211
212 <div id="post-body">
213 <?php
214 ////////////////////////////////////////////////
215 // Display settings boxes //////////////////////
216 ////////////////////////////////////////////////
217
218 $boxes_by_methods = array(
219 'feed_categories_box' => __('Feed Categories'.FEEDWORDPRESS_AND_TAGS),
220 'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'),
221 'tags_box' => __('Tags'),
222 );
223 if (!FeedWordPressCompatibility::post_tags()) :
224 unset($boxes_by_methods['tags_box']);
225 endif;
226
227 foreach ($boxes_by_methods as $method => $row) :
228 if (is_array($row)) :
229 $id = $row['id'];
230 $title = $row['title'];
231 else :
232 $id = 'feedwordpress_'.$method;
233 $title = $row;
234 endif;
235
236 fwp_add_meta_box(
237 /*id=*/ $id,
238 /*title=*/ $title,
239 /*callback=*/ array('FeedWordPressCategoriesPage', $method),
240 /*page=*/ $catsPage->meta_box_context(),
241 /*context=*/ $catsPage->meta_box_context()
242 );
243 endforeach;
244 do_action('feedwordpress_admin_page_categories_meta_boxes', $catsPage);
245 ?>
246 <div class="metabox-holder">
247 <?php
248 fwp_do_meta_boxes($catsPage->meta_box_context(), $catsPage->meta_box_context(), $catsPage);
249 ?>
250 </div> <!-- class="metabox-holder" -->
251 </div> <!-- id="post-body" -->
252 <?php $catsPage->close_sheet(); ?>
253 <?php
254 } /* function fwp_categories_page () */
255
256 fwp_categories_page();
257
258