PluginProbe
FeedWordPress / 2022.0222
FeedWordPress v2022.0222
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
← All changes | admin-ui.php +683 -245 2009.07072022.0222 View file →
@@ -1,47 +1,159 @@
1 1 <?php
2 -function fwp_linkedit_single_submit ($status = NULL) {
3 - if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_27)) :
4 -?>
5 -<div class="submitbox" id="submitlink">
6 -<div id="previewview"></div>
7 -<div class="inside"></div>
2 +/**
3 + * Admin UI Compatibility (admin-ui.php): This is kind of a junk pile of utility functions
4 + * mostly created to smooth out interactions to make things show up, or behave correctly,
5 + * within the WordPress admin settings interface. Major chunks of this code that deal with
6 + * making it easy for FWP, add-on modules, etc. to create new settings panels have since
7 + * been hived off into class FeedWordPressAdminPage. Many of the functions that remain here
8 + * were created to handle compatibility across multiple, sometimes very old, versions of
9 + * WordPress, many of which are no longer supported anymore. It's likely that some of these
10 + * functions will be re-evaluated, re-organized, deprecated, or clipped out in the next few
11 + * versions.
12 + * -cj 2017-10-27
13 + *
14 + * @package FeedWordPress
15 + */
8 16
9 -<p class="submit">
10 -<input type="submit" name="submit" value="<?php _e('Save') ?>" />
11 -</p>
12 -</div>
13 -<?php
17 +$dir = dirname( __FILE__ );
18 +require_once "${dir}/feedwordpressadminpage.class.php";
19 +require_once "${dir}/feedwordpresssettingsui.class.php";
20 +
21 +/**
22 + * Prints the class="..." attribute (if any) for an HTML form element
23 + *
24 + * If there is at least one class to add to the element, escape it for attribute contet and print;
25 + * if not, omit the attribute entirely.
26 + *
27 + * @param string $class_name The name(s) of the HTML class or classes to apply.
28 + * @param string $before Separator prefix string to print just before class="..." attribute, when printed (usually whitespace).
29 + * @param string $after Separator suffix string to print just after class="..." attribute, when printed (usually blank).
30 + */
31 +function fwp_form_class_attr( $class_name, $before = ' ', $after = '' ) {
32 +
33 + if ( is_string( $class_name ) ) :
34 + if ( strlen( $class_name ) > 0 ) :
35 + $s_class_name = sanitize_html_class( $class_name );
36 + printf( '%sclass="%s"%s', esc_html( $before ), esc_attr( $s_class_name ), esc_html( $after ) );
37 + endif;
14 38 endif;
39 +
40 +} /* fwp_form_class_attr() */
41 +
42 +/**
43 + * Prints a flag attribute for selected UI elements (selected="selected" or checked="checked", etc.) when appropriate
44 + *
45 + * In HTML form output templates, this allows conditional output of the selected="selected"
46 + * (or checked="checked", etc.) attribute on input or option controls when appropriate, and
47 + * omits the element when not appropriate, as measured by a flag that is monitored and updated
48 + * by the caller.
49 + *
50 + * @param mixed $arg Flag monitoring variable.
51 + * @param mixed $key When $arg is an array, $key provides the index within the array to check for the flag.
52 + * @param string $flag The name of the flag attribute to output when appropriate; default, "selected".
53 + */
54 +function fwp_selected_flag( /* mixed */ $arg = null, $key = null, $flag = 'selected' ) {
55 +
56 + $is_on = false;
57 +
58 + $s_arg = $arg;
59 + if ( is_array( $arg ) && ! is_null( $key ) ) :
60 + if ( array_key_exists( $key, $arg ) ) :
61 + $s_arg = $arg[ $key ];
62 + else :
63 + $s_arg = false;
64 + endif;
65 + endif;
66 +
67 + if ( is_string( $s_arg ) ) :
68 + $is_on = ( strlen( $s_arg ) > 0 );
69 + else :
70 + $is_on = (bool) ( $s_arg );
71 + endif;
72 +
73 + if ( $is_on ) :
74 + print sprintf( '%s="%s"', esc_attr( $flag ), esc_attr( $flag ) );
75 + endif;
76 +} /* fwp_selected_flag() */
77 +
78 +/**
79 + * Outputs a flag attribute for checked UI elements (checked="checked") when appropriate
80 + *
81 + * In HTML form output templates, this allows conditional output of the check="checked"
82 + * attribute on input controls (e.g. checkbox, radio) when appropriate, and omits when
83 + * inappropriate (unchecked), as determined by a flag monitored and updated by caller.
84 + *
85 + * @param mixed $arg Flag monitoring variable.
86 + * @param mixed $key When $arg is an array, $key provides index within the array to check for flag value.
87 + *
88 + * @uses fwp_selected_flag()
89 + */
90 +function fwp_checked_flag( /* mixed */ $arg = null, $key = null ) {
91 + fwp_selected_flag( $arg, $key, 'checked' );
92 +} /* fwp_checked_flag() */
93 +
94 +/**
95 + * Retrieves a plural or singular form of a string based on the supplied number.
96 + *
97 + * Used when you want to use the appropriate form of a string based on whether
98 + * a number is singular or plural. Very similar to WordPress l10n.php _n(),
99 + * but designed for a nice short form in the
100 + * default case (provide "s" when plural, "" otherwise).
101 + *
102 + * @param int $n The counter to determine singular or plural form.
103 + * @param string $plural The text to use if the counter is plural.
104 + * @param string $singular The text to use if the counter is singular.
105 + *
106 + * @return string The text of the singular or plural form.
107 + */
108 +function _s( $n = 0, $plural = 's', $singular = '' ) {
109 + $is_singular = ( is_numeric( $n ) && intval( $n ) === 1 );
110 + return ( $is_singular ? $singular : $plural );
15 111 }
16 112
17 -function fwp_linkedit_periodic_submit ($caption = NULL) {
18 - if (!fwp_test_wp_version(FWP_SCHEMA_25)) :
19 - if (is_null($caption)) : $caption = __('Save Changes &raquo;'); endif;
20 -?>
21 -<p class="submit">
22 -<input type="submit" name="submit" value="<?php print $caption; ?>" />
23 -</p>
24 -<?php
113 +/**
114 + * Outputs a status message for the aggregate results of polling a set of feeds.
115 + *
116 + * This will always output the number of new syndicated posts added, even if this is 0.
117 + * Posts updated and alternate versions stored will be added to the message iff > 0.
118 + *
119 + * @param array $delta Counters indicating results in "new", "updated" and "stored".
120 + * @param string $joiner Default ';'. Delimiter used to separate messages about new, updated and stored posts.
121 + */
122 +function fwp_update_set_results_message( $delta, $joiner = ';' ) {
123 +
124 + $mesg = array();
125 +
126 + $delta = wp_parse_args(
127 + $delta,
128 + array(
129 + 'new' => 0,
130 + 'updated' => 0,
131 + 'stored' => 0,
132 + )
133 + );
134 +
135 + $mesg[] = sprintf( ' %d new post%s syndicated', intval( $delta['new'] ), _s( $delta['new'], 's were', ' was' ) );
136 + if ( $delta['updated'] > 0 ) :
137 + $mesg[] = sprintf( ' %d existing post%s updated', intval( $delta['updated'] ), _s( $delta['updated'], 's were', ' was' ) );
25 138 endif;
26 -}
139 + if ( $delta['stored'] > 0 ) :
140 + $mesg[] = sprintf( ' %d alternate version%s of existing post%s stored for reference', intval( $delta['stored'] ), _s( $delta['stored'] ), _s( $delta['stored'], 's were', ' was' ) );
141 + endif;
27 142
28 -function fwp_linkedit_single_submit_closer ($caption = NULL) {
29 - if (fwp_test_wp_version(FWP_SCHEMA_27)) :
30 - if (is_null($caption)) : $caption = __('Save Changes'); endif;
31 -?>
32 -<p class="submit">
33 -<input class="button-primary" type="submit" name="submit" value="<?php print $caption; ?>" />
34 -</p>
35 -<?php
143 + if ( ! is_null( $joiner ) ) :
144 + $mesg = implode( $joiner, $mesg );
36 145 endif;
37 -}
146 + return $mesg;
147 +} /* function fwp_update_set_results_message () */
38 148
39 -function fwp_authors_single_submit ($link = NULL) {
40 - global $wp_db_version;
41 -
42 - if (fwp_test_wp_version(FWP_SCHEMA_25)) :
43 -?>
149 +/**
150 + * Outputs the HTML template for a "Submit" button on FWP admin pages.
151 + *
152 + * @param mixed $link The syndicated link, if any, that we are viewing settings for.
153 + */
154 +function fwp_authors_single_submit( $link = null ) {
155 + ?>
44 156 <div class="submitbox" id="submitlink">
45 157 <div id="previewview">
46 158 </div>
47 159 <div class="inside">
@@ -47,168 +159,253 @@
47 159 <div class="inside">
48 160 </div>
49 161
50 162 <p class="submit">
51 -<input type="submit" name="save" value="<?php _e('Save') ?>" />
163 +<input type="submit" name="save" value="<?php esc_html_e( 'Save' ); ?>" />
52 164 </p>
53 165 </div>
54 -<?php
166 + <?php
167 +}
168 +
169 +/**
170 + * Outputs the HTML template for a Tags (or similar taxonomy) add / remove box in FeedWordPress admin UI pages.
171 + *
172 + * @param array $tags An array of tags already applied to the object.
173 + * @param string $object The human-readable description of the objects to be tagged ("post", "posts from this feed", etc.).
174 + * @param array $params An array of optional parameters.
175 + */
176 +function fwp_tags_box( $tags, $object, $params = array() ) {
177 + $params = wp_parse_args(
178 + $params,
179 + array( // Default values.
180 + 'taxonomy' => 'post_tag',
181 + 'textarea_name' => null,
182 + 'textarea_id' => null,
183 + 'input_id' => null,
184 + 'input_name' => null,
185 + 'id' => null,
186 + 'box_title' => __( 'Post Tags' ),
187 + )
188 + );
189 +
190 + if ( ! is_array( $tags ) ) :
191 + $tags = array();
55 192 endif;
56 -}
57 193
58 -function fwp_option_box_opener ($legend, $id, $class = "stuffbox") {
59 - global $wp_db_version;
60 - if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) :
61 -?>
62 -<div id="<?php print $id; ?>" class="<?php print $class; ?>">
63 -<h3><?php print htmlspecialchars($legend); ?></h3>
64 -<div class="inside">
65 -<?php
66 - else :
67 -?>
68 -<fieldset class="options"><legend><?php print htmlspecialchars($legend); ?></legend>
69 -<?php
194 + $tax_name = $params['taxonomy'];
195 + $o_tax = get_taxonomy( $params['taxonomy'] );
196 + $o_tax_labels = get_taxonomy_labels( $o_tax );
197 + $is_enabled = current_user_can( $o_tax->cap->assign_terms );
198 +
199 + if ( is_null( $params['textarea_name'] ) ) :
200 + $params['textarea_name'] = "tax_input[$tax_name]";
70 201 endif;
202 + if ( is_null( $params['textarea_id'] ) ) :
203 + $params['textarea_id'] = "tax-input-${tax_name}";
204 + endif;
205 + if ( is_null( $params['input_id'] ) ) :
206 + $params['input_id'] = "new-tag-${tax_name}";
207 + endif;
208 + if ( is_null( $params['input_name'] ) ) :
209 + $params['input_name'] = "newtag[$tax_name]";
210 + endif;
211 +
212 + if ( is_null( $params['id'] ) ) :
213 + $params['id'] = $tax_name;
214 + endif;
215 +
216 + printf( /* $desc = */ '<p style="font-size:smaller;font-style:bold;margin:0\">Tag %s as...</p>', esc_html( $object ) );
217 + $helps = __( 'Separate tags with commas.' );
218 + $box['title'] = __( 'Tags' );
219 + ?>
220 +<div class="tagsdiv" id="<?php echo esc_attr( $params['id'] ); ?>">
221 + <div class="jaxtag">
222 + <div class="nojs-tags hide-if-js">
223 + <p><?php echo esc_html( $o_tax_labels->add_or_remove_items ); ?></p>
224 + <textarea name="<?php echo esc_attr( $params['textarea_name'] ); ?>" class="the-tags" id="<?php echo esc_attr( $params['textarea_id'] ); ?>"><?php echo esc_attr( implode( ',', $tags ) ); ?></textarea></div>
225 +
226 + <?php if ( $is_enabled ) : ?>
227 + <div class="ajaxtag hide-if-no-js">
228 + <label class="screen-reader-text" for="<?php echo esc_attr( $params['input_id'] ); ?>"><?php echo esc_html( $params['box_title'] ); ?></label>
229 + <div class="taghint"><?php echo esc_html( $o_tax_labels->add_new_item ); ?></div>
230 + <p><input type="text" id="<?php print esc_attr( $params['input_id'] ); ?>" name="<?php print esc_attr( $params['input_name'] ); ?>" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
231 + <input type="button" class="button tagadd" value="<?php esc_attr_e( 'Add' ); ?>" tabindex="3" /></p>
232 + </div>
233 + <p class="howto"><?php echo esc_attr( $o_tax_labels->separate_items_with_commas ); ?></p>
234 + <?php endif; ?>
235 + </div>
236 +
237 + <div class="tagchecklist"></div>
238 +</div>
239 + <?php
240 + if ( $is_enabled ) :
241 + ?>
242 +<p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo esc_attr( $tax_name ); ?>"><?php echo esc_html( $o_tax_labels->choose_from_most_used ); ?></a></p>
243 + <?php
244 + endif;
245 +
71 246 }
72 247
73 -function fwp_option_box_closer () {
248 +/**
249 + * Outputs the HTML template for a Category (or similar taxonomy) add / remove box in FeedWordPress admin UI pages.
250 + *
251 + * @param array $checked An array of cats already applied to the object.
252 + * @param string $object The human-readable description of the objects to be tagged ("post", "posts from this feed", etc.).
253 + * @param array $tags Not used.
254 + * @param array $params An array of optional parameters.
255 + */
256 +function fwp_category_box( $checked, $object, $tags = array(), $params = array() ) {
74 257 global $wp_db_version;
75 - if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) :
76 -?>
77 - </div> <!-- class="inside" -->
78 - </div> <!-- class="stuffbox" -->
79 -<?php
80 - else :
81 -?>
82 -</fieldset>
83 -<?php
258 +
259 + if ( is_string( $params ) ) :
260 + $prefix = $params;
261 + $taxonomy = 'category';
262 + elseif ( is_array( $params ) ) :
263 + $params = wp_parse_args(
264 + $params,
265 + array(
266 + 'prefix' => '',
267 + 'taxonomy' => 'category',
268 + )
269 + );
270 +
271 + $prefix = $params['prefix'];
272 + $taxonomy = $params['taxonomy'];
84 273 endif;
85 -}
86 274
87 -function fwp_tags_box ($tags, $object) {
88 - if (!is_array($tags)) : $tags = array(); endif;
89 -
90 - $desc = "<p style=\"font-size:smaller;font-style:bold;margin:0\">Tag $object as...</p>";
275 + $o_tax = get_taxonomy( $taxonomy );
276 + $o_tax_labels = get_taxonomy_labels( $o_tax );
91 277
92 - if (fwp_test_wp_version(FWP_SCHEMA_28)) : // WordPress 2.8+
93 - fwp_option_box_opener(__('Tags'), 'tagsdiv', 'postbox');
94 -?>
95 - <?php print $desc; ?>
96 - <div class="tagsdiv" id="post_tag">
97 - <div class="jaxtag">
98 - <div class="nojs-tags hide-if-js">
99 - <p><?php _e('Add or remove tags'); ?></p>
100 - <textarea name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]"><?php echo implode(",", $tags); ?></textarea>
101 - </div>
102 -
103 - <span class="ajaxtag hide-if-no-js">
104 - <label class="screen-reader-text" for="new-tag-post_tag"><?php _e('Tags'); ?></label>
105 - <input type="text" id="new-tag-post_tag" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="<?php esc_attr_e('Add new tag'); ?>" />
106 - <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
107 - </span>
108 - </div>
109 - <p class="howto"><?php echo __('Separate tags with commas.'); ?></p>
110 - <div class="tagchecklist"></div>
111 - </div>
112 - <p class="tagcloud-link hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php printf( __('Choose from the most used tags in %s'), 'Post Tags'); ?></a></p>
113 - </div>
114 - </div>
115 -<?php
116 - else :
117 - fwp_option_box_opener(__('Tags'), 'tagsdiv', 'postbox');
118 -?>
119 - <?php print $desc; ?>
120 - <p id="jaxtag"><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo implode(",", $tags); ?>" /></p>
121 - <div id="tagchecklist"></div>
122 - </div>
123 - </div>
124 -<?php
278 + if ( strlen( $prefix ) === 0 ) :
279 + $prefix = 'feedwordpress';
125 280 endif;
126 -}
127 281
128 -function fwp_category_box ($checked, $object, $tags = array()) {
129 - global $wp_db_version;
282 + $id_prefix = $prefix . '-';
283 + $id_suffix = '-' . $prefix;
284 + $name_prefix = $prefix . '_';
130 285
131 - if (fwp_test_wp_version(FWP_SCHEMA_25)) : // WordPress 2.5.x
132 -?>
133 -<div id="category-adder" class="wp-hidden-children">
134 - <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
135 - <p id="category-add" class="wp-hidden-child">
136 - <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" />
137 - <?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?>
138 - <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" />
139 - <?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
140 - <span id="category-ajax-response"></span>
141 - </p>
286 + $box_div_id = sanitize_html_class( $id_prefix . 'taxonomy-' . $taxonomy );
287 + $tabs_ul_id = sanitize_html_class( $id_prefix . $taxonomy . '-tabs' );
288 + $all_tab_id = sanitize_html_class( $id_prefix . $taxonomy . '-all' );
289 + $chk_lst_id = sanitize_html_class( $id_prefix . $taxonomy . 'checklist' );
290 + $add_tax_id = sanitize_html_class( $id_prefix . $taxonomy . '-adder' );
291 + $add_tog_id = sanitize_html_class( $id_prefix . $taxonomy . '-add-toggle' );
292 + $add_cat_id = sanitize_html_class( $id_prefix . $taxonomy . '-add' );
293 + $new_tax_id = sanitize_html_class( $id_prefix . 'new' . $taxonomy );
294 +
295 + $tax_id_add_submit = sanitize_html_class( $id_prefix . $taxonomy . '-add-sumbit' );
296 + ?>
297 +<div id="<?php print esc_attr( $box_div_id ); ?>" class="feedwordpress-category-div">
298 + <ul id="<?php print esc_attr( $tabs_ul_id ); ?>" class="category-tabs">
299 + <li class="ui-tabs-selected tabs"><a href="#<?php print esc_attr( $all_tab_id ); ?>" tabindex="3"><?php esc_html_e( 'All posts' ); ?></a>
300 + <p style="font-size:smaller;font-style:bold;margin:0">Give <?php print esc_html( $object ); ?> these <?php print esc_html( $o_tax_labels->name ); ?></p>
301 + </li>
302 + </ul>
303 +
304 +<div id="<?php print esc_attr( $all_tab_id ); ?>" class="tabs-panel">
305 + <input type="hidden" value="0" name="tax_input[<?php print esc_attr( $taxonomy ); ?>][]" />
306 + <ul id="<?php print esc_attr( $chk_lst_id ); ?>" class="list:<?php print esc_attr( $taxonomy ); ?> categorychecklist form-no-clear">
307 + <?php fwp_category_checklist( null, false, $checked, $params ); ?>
308 + </ul>
142 309 </div>
143 310
144 -<ul id="category-tabs">
145 - <?php /* ui-tabs-selected in WP 2.7 CSS = tabs in WP 2.8 CSS. Thank you, o brilliant wordsmiths of the WordPress 2.8 stylesheet... */ ?>
146 - <li class="ui-tabs-selected tabs"><a href="#categories-all" tabindex="3"><?php _e( 'All posts' ); ?></a>
147 - <p style="font-size:smaller;font-style:bold;margin:0">Give <?php print $object; ?> these categories</p>
148 -</li>
149 -</ul>
311 +<div id="<?php print esc_attr( $add_tax_id ); ?>" class="<?php print esc_attr( $taxonomy ); ?>-adder wp-hidden-children">
312 + <h4><a id="<?php print esc_attr( $add_tog_id ); ?>" class="category-add-toggle" href="#<?php print esc_attr( $add_cat_id ); ?>" class="hide-if-no-js" tabindex="3"><?php esc_html_e( '+ Add New Category' ); ?></a></h4>.
313 + <p id="<?php print esc_attr( $add_cat_id ); ?>" class="category-add wp-hidden-child">
314 + <?php
315 + $newcat = 'new' . $taxonomy;
316 + ?>
317 + <label class="screen-reader-text" for="<?php print esc_attr( $new_tax_id ); ?>"><?php esc_html_e( 'Add New Category' ); ?></label>
318 + <input
319 + id="<?php print esc_attr( $new_tax_id ); ?>"
320 + class="<?php print esc_attr( $newcat ); ?> form-required form-input-tip"
321 + aria-required="true"
322 + tabindex="3"
323 + type="text" name="<?php print esc_attr( $newcat ); ?>"
324 + value="<?php esc_attr_e( 'New category name' ); ?>"
325 + />
326 + <label class="screen-reader-text" for="<?php print esc_attr( $new_tax_id ); ?>-parent"><?php esc_html_e( 'Parent Category:' ); ?></label>
327 + <?php
328 + wp_dropdown_categories(
329 + array(
330 + 'taxonomy' => $taxonomy,
331 + 'hide_empty' => 0,
332 + 'id' => $new_tax_id . '-parent',
333 + 'class' => $newcat . '-parent',
334 + 'name' => $newcat . '_parent',
335 + 'orderby' => 'name',
336 + 'hierarchical' => 1,
337 + 'show_option_none' => __( 'Parent category' ),
338 + 'tab_index' => 3,
339 + )
340 + );
150 341
151 -<?php /* ui-tabs-panel in WP 2.7 CSS = tabs-panel in WP 2.8 CSS. Thank you, o brilliant wordsmiths of the WordPress 2.8 stylesheet... */ ?>
152 -<div id="categories-all" class="ui-tabs-panel tabs-panel">
153 - <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
154 - <?php fwp_category_checklist(NULL, false, $checked) ?>
155 - </ul>
342 + $nonce_code = ( 'add-' . $taxonomy );
343 + ?>
344 + <input type="button" id="<?php print esc_attr( $tax_id_add_submit ); ?>" class="add:<?php print esc_attr( $id_prefix . $taxonomy ); ?>checklist:<?php print esc_attr( $id_prefix . $taxonomy ); ?>-add add-categorychecklist-category-add button category-add-submit" value="<?php esc_attr_e( 'Add' ); ?>" tabindex="3" />
345 + <?php /* wp_nonce_field currently doesn't let us set an id different from name, but we need a non-unique name and a unique id */ ?>
346 + <input type="hidden" id="_ajax_nonce<?php print esc_html( $id_suffix ); ?>" name="_ajax_nonce" value="<?php print esc_attr( wp_create_nonce( $nonce_code ) ); ?>" />
347 + <input type="hidden" id="_ajax_nonce-add-<?php print esc_attr( $taxonomy . $id_suffix ); ?>" name="_ajax_nonce-add-<?php print esc_attr( $taxonomy ); ?>" value="<?php print esc_attr( wp_create_nonce( $nonce_code ) ); ?>" />
348 + <span id="<?php print esc_attr( $id_prefix . $taxonomy ); ?>-ajax-response" class="<?php print esc_attr( $taxonomy ); ?>-ajax-response"></span>
349 + </p>
156 350 </div>
157 -<?php
158 - elseif (fwp_test_wp_version(FWP_SCHEMA_20)) : // WordPress 2.x
159 -?>
160 - <div id="moremeta">
161 - <div id="grabit" class="dbx-group">
162 - <fieldset id="categorydiv" class="dbx-box">
163 - <h3 class="dbx-handle"><?php _e('Categories') ?></h3>
164 - <div class="dbx-content">
165 - <p style="font-size:smaller;font-style:bold;margin:0">Place <?php print $object; ?> under...</p>
166 - <p id="jaxcat"></p>
167 - <div id="categorychecklist"><?php fwp_category_checklist(NULL, false, $checked); ?></div>
168 - </div>
169 - </fieldset>
170 - </div>
171 - </div>
172 -<?php
173 - else : // WordPress 1.5
174 -?>
175 - <fieldset style="width: 60%;">
176 - <legend><?php _e('Categories') ?></legend>
177 - <p style="font-size:smaller;font-style:bold;margin:0">Place <?php print $object; ?> under...</p>
178 - <div style="height: 10em; overflow: scroll;"><?php fwp_category_checklist(NULL, false, $checked); ?></div>
179 - </fieldset>
180 -<?php
181 - endif;
351 +
352 +</div>
353 + <?php
182 354 }
183 355
184 -function update_feeds_mention ($feed) {
185 - echo "<li>Updating <cite>".$feed['link/name']."</cite> from &lt;<a href=\""
186 - .$feed['link/uri']."\">".$feed['link/uri']."</a>&gt; ...";
356 +/**
357 + * Outputs a text/html status message indicating that FWP has started polling a feed.
358 + *
359 + * @param array $feed An associative array containing meta-data about the feed being polled.
360 + */
361 +function update_feeds_mention( $feed ) {
362 + printf(
363 + '<li>Updating <cite>%s</cite> from &lt;<a href="%s">%s</a>&gt; ...',
364 + esc_html( $feed['link/name'] ),
365 + esc_url( $feed['link/uri'] ),
366 + esc_html( $feed['link/uri'] )
367 + );
187 368 flush();
188 369 }
189 -function update_feeds_finish ($feed, $added, $dt) {
190 - echo " completed in $dt second".(($dt==1)?'':'s')."</li>\n";
370 +
371 +/**
372 + * Outputs a text/html status message indicating that FWP has completed polling a feed.
373 + *
374 + * @param array $feed An associative array containing meta-data about the feed being polled.
375 + * @param mixed $added a WP_Error object with error codes and messages, if there was an error in polling.
376 + * @param int $dt seconds it took to complete the poll.
377 + */
378 +function update_feeds_finish( $feed, $added, $dt ) {
379 + if ( is_wp_error( $added ) ) :
380 + $mesgs = $added->get_error_messages();
381 + foreach ( $mesgs as $mesg ) :
382 + printf( '<br/><strong>Feed error:</strong> <code>%s</code>', esc_html( $mesg ) );
383 + endforeach;
384 + echo "</li>\n";
385 + else :
386 + printf( " completed in %d second%s</li>\n", esc_html( $dt ), esc_html( _s( $dt ) ) );
387 + endif;
388 + flush();
191 389 }
192 390
193 -function fwp_author_list () {
391 +/**
392 + * Retrieves a list of users via the WordPress API.
393 + *
394 + * @return array List of users, by numeric ID => display_name
395 + */
396 +function fwp_author_list() {
194 397 global $wpdb;
195 398 $ret = array();
196 399
197 - // display_name introduced in WP 2.0
198 - if (fwp_test_wp_version(FWP_SCHEMA_20)) :
199 - $name_column = 'display_name';
200 - else :
201 - $name_column = 'user_nickname';
202 - endif;
400 + $users = get_users();
401 + if ( is_array( $users ) ) :
402 + foreach ( $users as $user ) :
403 + $id = (int) $user->ID;
404 + $ret[ $id ] = $user->display_name;
203 405
204 - $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY {$name_column}");
205 - if (is_array($users)) :
206 - foreach ($users as $user) :
207 - $id = (int) $user->ID;
208 - $ret[$id] = $user->{$name_column};
209 - if (strlen(trim($ret[$id])) == 0) :
210 - $ret[$id] = $user->user_login;
406 + if ( strlen( trim( $ret[ $id ] ) ) === 0 ) :
407 + $ret[ $id ] = $user->user_login;
211 408 endif;
212 409 endforeach;
213 410 endif;
214 411 return $ret;
@@ -213,96 +410,337 @@
213 410 endif;
214 411 return $ret;
215 412 }
216 413
217 -class FeedWordPressSettingsUI {
218 - function instead_of_posts_box ($link_id = null) {
219 - fwp_option_box_opener('Syndicated Posts, Comments & Pings', 'syndicatedpostsdiv', 'postbox');
220 - if (!is_null($link_id)) :
221 - $from_this_feed = 'from this feed';
222 - $by_default = '';
223 - $id_param = "&amp;link_id=".$link_id;
414 +/**
415 + * Insert a new user into the WordPress database, with some FeedWordPress-specific default behaviors.
416 + *
417 + * @param string $newuser_name The "Display Name" for the new user; user logins and the like will be determined by a formula.
418 + * @return mixed Either a numeric ID or a WP_Error object.
419 + */
420 +function fwp_insert_new_user( $newuser_name ) {
421 + global $wpdb;
422 +
423 + $ret = null;
424 + if ( strlen( $newuser_name ) > 0 ) :
425 + $userdata = array();
426 + $userdata['ID'] = null;
427 + $userdata['user_login'] = apply_filters( 'pre_user_login', sanitize_user( $newuser_name ) );
428 + $userdata['user_nicename'] = apply_filters( 'pre_user_nicename', sanitize_title( $newuser_name ) );
429 + $userdata['display_name'] = $newuser_name;
430 + $userdata['user_pass'] = substr( md5( uniqid( microtime() ) ), 0, 6 ); // just something random to lock it up.
431 +
432 + $blah_url = get_bloginfo( 'url' );
433 + $url = wp_parse_url( $blah_url );
434 +
435 + $userdata['user_email'] = substr( md5( uniqid( microtime() ) ), 0, 6 ) . '@' . $url['host'];
436 +
437 + $newuser_id = wp_insert_user( $userdata );
438 +
439 + $ret = $newuser_id; // Either a numeric ID or a WP_Error object.
440 +
441 + else :
442 +
443 + $ret = new WP_Error( 'empty_username', 'Provide a non-empty string for the Display Name to fwp_insert_new_user' );
444 +
445 + endif;
446 + return $ret;
447 +} /* fwp_insert_new_user ( ) */
448 +
449 +/**
450 + * Output HTML for table row in FeedWordPress Syndicated Sources list.
451 + *
452 + * @param array $links array of WordPress link objects.
453 + * @param object $page FeedWordPress admin page object.
454 + * @param string $visible 'Y' or 'N', whether to display syndicated sources marked as visible or as hidden.
455 + */
456 +function fwp_syndication_manage_page_links_table_rows( $links, $page, $visible = 'Y' ) {
457 +
458 + $fwp_syndicated_sources_columns = array( __( 'Name' ), __( 'Feed' ), __( 'Updated' ) );
459 +
460 + $subscribed = ( 'Y' === strtoupper( $visible ) );
461 + if ( $subscribed || ( count( $links ) > 0 ) ) :
462 + $table_classes = array( 'widefat' );
463 + if ( ! $subscribed ) :
464 + $table_classes[] = 'unsubscribed';
465 + endif;
466 + $table_classes = implode( ' ', $table_classes );
467 + ?>
468 + <table class="<?php print esc_attr( $table_classes ); ?>">
469 + <thead>
470 + <tr>
471 + <th class="check-column" scope="col"><input type="checkbox" /></th>
472 + <?php
473 + foreach ( $fwp_syndicated_sources_columns as $col ) :
474 + printf( "\t<th scope='col'>%s</th>\n", esc_html( $col ) );
475 + endforeach;
476 + print "</tr>\n";
477 + print "</thead>\n";
478 + print "\n";
479 + print "<tbody>\n";
480 +
481 + $alt_row = true;
482 + if ( count( $links ) > 0 ) :
483 + foreach ( $links as $link ) :
484 + $tr_class = array();
485 +
486 + $o_s_link = new SyndicatedLink( $link->link_id );
487 +
488 + if ( is_null( $o_s_link->setting( 'update/error' ) ) ) :
489 +
490 + $the_error = null;
491 +
492 + else :
493 + $tr_class[] = 'feed-error';
494 + $the_error = unserialize( $o_s_link->setting( 'update/error' ) );
495 + endif;
496 +
497 + $ttl = $o_s_link->setting( 'update/ttl' );
498 +
499 + $alt_row = ! $alt_row;
500 +
501 + if ( $alt_row ) :
502 + $tr_class[] = 'alternate';
503 + endif;
504 + ?>
505 + <tr<?php fwp_form_class_attr( implode( ' ', $tr_class ) ); ?>>
506 + <th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php echo esc_attr( $link->link_id ); ?>" /></th>
507 + <?php
508 + $caption = (
509 + ( strlen( $link->link_rss ) > 0 )
510 + ? __( 'Switch Feed' )
511 + : __( 'Find Feed' )
512 + );
513 + ?>
514 + <td>
515 + <strong><a href="<?php print esc_url( $page->admin_page_href( 'feeds-page.php', array(), $link ) ); ?>"><?php print esc_html( $link->link_name ); ?></a></strong>
516 + <div class="row-actions">
517 + <?php
518 + if ( $subscribed ) :
519 + $page->display_feed_settings_page_links(
520 + array(
521 + 'before' => '<div><strong>Settings &gt;</strong> ',
522 + 'after' => '</div>',
523 + 'subscription' => $link,
524 + )
525 + );
526 + endif;
527 + ?>
528 +
529 + <div><strong>Actions &gt;</strong>
530 + <?php if ( $subscribed ) : ?>
531 + <a href="<?php print esc_url( $page->admin_page_href( 'syndication.php', array( 'action' => 'feedfinder' ), $link ) ); ?>"><?php echo esc_html( $caption ); ?></a>
532 + <?php else : ?>
533 + <a href="<?php print esc_url( $page->admin_page_href( 'syndication.php', array( 'action' => FWP_RESUB_CHECKED ), $link ) ); ?>"><?php esc_html_e( 'Re-subscribe' ); ?></a>
534 + <?php endif; ?>
535 + | <a href="<?php print esc_url( $page->admin_page_href( 'syndication.php', array( 'action' => 'Unsubscribe' ), $link ) ); ?>">
536 + <?php
537 + if ( $subscribed ) :
538 + esc_html_e( 'Unsubscribe' );
539 + else :
540 + esc_html_e( 'Delete permanently' );
541 + endif;
542 + ?>
543 + </a>
544 + | <a href="<?php print esc_url( $link->link_url ); ?>"><?php esc_html_e( 'View' ); ?></a></div>
545 + </div>
546 + </td>
547 + <?php if ( strlen( $link->link_rss ) > 0 ) : ?>
548 + <td><div><a href="<?php echo esc_html( $link->link_rss ); ?>"><?php echo esc_html( feedwordpress_display_url( $link->link_rss, 32 ) ); ?></a></div></td>
549 + <?php else : ?>
550 + <td class="feed-missing"><p><strong>no feed assigned</strong></p></td>
551 + <?php endif; ?>
552 +
553 + <td><div style="float: right; padding-left: 10px">
554 + <input type="submit" class="button" name="update_uri[<?php print esc_html( $link->link_rss ); ?>]" value="<?php esc_html_e( 'Update Now' ); ?>" />
555 + </div>
556 + <?php
557 + fwp_links_table_rows_last_updated( $o_s_link );
558 + fwp_links_table_rows_file_size( $o_s_link );
559 + fwp_links_table_rows_errors_since( $the_error );
560 + fwp_links_table_rows_next_update( $o_s_link );
561 + ?>
562 + </td>
563 + </tr>
564 + <?php
565 + unset( $o_s_link );
566 +
567 + endforeach;
224 568 else :
225 - $from_this_feed = 'from syndicated feeds';
226 - $by_default = " by default";
227 - $id_param = "";
569 + ?>
570 +<tr><td colspan="4"><p>There are no websites currently listed for syndication.</p></td></tr>
571 + <?php
572 +
228 573 endif;
229 -?>
230 -<p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php<?php print $id_param; ?>"><?php _e('Posts'); ?></a>
231 -settings page to set up how new posts <?php print $from_this_feed; ?> will be published<?php $by_default; ?>, whether they will accept
232 -comments and pings, any custom fields that should be set on each post, etc.</p>
233 -<?php
234 - fwp_option_box_closer();
235 - } /* FeedWordPressSettingsUI::instead_of_posts_box () */
236 -
237 - function instead_of_authors_box ($link_id = null) {
238 - if (!is_null($link_id)) :
239 - $from_this_feed = 'from this feed';
240 - $by_default = '';
241 - $id_param = "&amp;link_id=".$link_id;
242 - else :
243 - $from_this_feed = 'from syndicated feeds';
244 - $by_default = " by default";
245 - $id_param = "";
574 +
575 + ?>
576 +
577 +</tbody>
578 +</table>
579 +
580 + <?php
581 +
582 + endif;
583 +} /* function fwp_syndication_manage_page_links_table_rows ( ) */
584 +
585 +/**
586 + * Output HTML message indicating feed errors, if a feed has been returning errors, in Syndicated Sites table.
587 + *
588 + * @param mixed $the_error If last poll on this feed was successful, this is null.
589 + * If last poll returned an error, contains an array with 'since' (timestamp of first time an error was an encountered), 'ts' (timestamp of most recent time an error was encountered), and 'object' (a WP_Error object representing the most recent error when you polled the feed).
590 + */
591 +function fwp_links_table_rows_errors_since( $the_error ) {
592 + if ( ! is_null( $the_error ) ) :
593 +
594 + $s_elapsed = fwp_time_elapsed( $the_error['since'] );
595 + $s_recent = fwp_time_elapsed( $the_error['ts'] );
596 + ?>
597 +
598 +<div class="returning-errors"><p><strong>Returning errors</strong> since <?php print esc_html( $s_elapsed ); ?></p>
599 +<p>Most recent (<?php print esc_html( $s_recent ); ?>):
600 + <?php
601 + foreach ( $the_error['object']->get_error_messages() as $mesg ) :
602 + printf( '<br/><code>%s</code>', esc_html( $mesg ) );
603 + endforeach;
604 + ?>
605 +</p>
606 +</div>
607 +
608 + <?php
609 + endif;
610 +}
611 +
612 +/**
613 + * Output the "Last checked..." status message in Syndicated Sites table.
614 + *
615 + * @param SyndicatedLink $o_s_link The SyndicatedLink object representing the feed displayed on this row.
616 + */
617 +function fwp_links_table_rows_last_updated( $o_s_link ) {
618 + if ( ! is_null( $o_s_link->setting( 'update/last' ) ) ) :
619 + print esc_html( 'Last checked ' . fwp_time_elapsed( $o_s_link->setting( 'update/last' ) ) );
620 + else :
621 + esc_html_e( 'None yet' );
622 + endif;
623 +
624 + $ttl = $o_s_link->setting( 'update/ttl' );
625 + if ( is_numeric( $ttl ) ) :
626 + $next = $o_s_link->setting( 'update/last' ) + $o_s_link->setting( 'update/fudge' ) + ( (int) $ttl * 60 );
627 +
628 + if ( 'automatically' !== $o_s_link->setting( 'update/timed' ) ) :
629 +
630 + print ' &middot; Next ';
631 + print esc_html( fwp_relative_time_string( $next ) );
632 +
246 633 endif;
634 + endif;
247 635
248 - fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox')
249 -?>
250 -<p>Use the <a
251 -href="admin.php?page=<?php print $GLOBALS['fwp_path']
252 -?>/authors-page.php<?php print $id_param; ?>"><?php _e('Authors');
253 -?></a> settings page to set up how new posts
254 -<?php print $from_this_feed; ?> will be assigned to
255 -authors.</p>
256 -<?php
257 - fwp_option_box_closer();
258 - } /* FeedWordPressSettingsUI::instead_of_authors_box () */
259 -
260 - function instead_of_categories_box ($link_id = null) {
261 - if (!is_null($link_id)) :
262 - $from_this_feed = 'from this feed';
263 - $by_default = '';
264 - $id_param = "&amp;link_id=".$link_id;
265 - else :
266 - $from_this_feed = 'from syndicated feeds';
267 - $by_default = " by default";
268 - $id_param = "";
636 +}
637 +
638 +/**
639 + * Return a status message indicating when a feed will next be polled, based on a next-update timestamp.
640 + *
641 + * @param int $ts Timestamp for next updrate.
642 + * @param bool $ago Display "[relative time] ago", or "ASAP", if the timestamp is in the past.
643 + */
644 +function fwp_relative_time_string( $ts, $ago = false ) {
645 +
646 + $dt = ( $ts - time() );
647 +
648 + if ( $dt < 0 && ! $ago ) :
649 + $ret = 'ASAP';
650 + elseif ( $dt < 60 * 60 ) :
651 + $ret = fwp_time_elapsed( $ts );
652 + elseif ( $dt < 60 * 60 * 24 ) :
653 + $ret = wp_date( 'g:ia', $ts );
654 + else :
655 + $ret = wp_date( 'F j', $ts );
656 + endif;
657 + return $ret;
658 +}
659 +
660 +/**
661 + * Output the File Size / Format status message in Syndicated Sites table.
662 + *
663 + * @param SyndicatedLink $o_s_link Object representing the feed displayed on this row.
664 + */
665 +function fwp_links_table_rows_file_size( $o_s_link ) {
666 +
667 + $mesg_file_size_lines = array();
668 +
669 + $feed_type = $o_s_link->get_feed_type();
670 +
671 + if ( ! is_null( $o_s_link->setting( 'link/item count' ) ) ) :
672 + $n = $o_s_link->setting( 'link/item count' );
673 +
674 + // translators: %1$d is the item count; %2$s is the plural marker (if any) for item.
675 + $mesg_file_size_lines[] = sprintf( __( '%1$d item%2$s' ), $n, _s( $n ) ) . ', ' . $feed_type;
676 +
677 + endif;
678 +
679 + if ( is_null( $o_s_link->setting( 'update/error' ) ) ) :
680 +
681 + if ( ! is_null( $o_s_link->setting( 'link/filesize' ) ) ) :
682 + $mesg_file_size_lines[] = size_format( $o_s_link->setting( 'link/filesize' ) ) . ' total';
269 683 endif;
270 -
271 - fwp_option_box_opener(__('Categories & Tags'), 'categorydiv', 'postbox');
272 -?>
273 -<p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/categories-page.php<?php print $id_param; ?>"><?php _e('Categories & Tags'); ?></a>
274 -settings page to set up how new posts <?php print $from_this_feed; ?> are assigned categories or tags<?php print $by_default; ?>.</p>
275 -<?php
276 - fwp_option_box_closer();
277 - } /* FeedWordPressSettingsUI::instead_of_categories_box () */
278 684
279 -} /* class FeedWordPressSettingsUI */
685 + endif;
280 686
281 -function fwp_insert_new_user ($newuser_name) {
282 - global $wpdb;
687 + if ( count( $mesg_file_size_lines ) > 0 ) :
283 688
284 - $ret = null;
285 - if (strlen($newuser_name) > 0) :
286 - $userdata = array();
287 - $userdata['ID'] = NULL;
288 -
289 - $userdata['user_login'] = sanitize_user($newuser_name);
290 - $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
291 -
292 - $userdata['user_nicename'] = sanitize_title($newuser_name);
293 - $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
294 -
295 - $userdata['display_name'] = $wpdb->escape($newuser_name);
689 + print '<div>';
690 + $sep = '';
691 + foreach ( $mesg_file_size_lines as $line ) :
692 + print esc_html( $sep );
693 + print esc_html( $line );
694 + $sep = ' / ';
695 + endforeach;
696 + print '</div>';
296 697
297 - $newuser_id = wp_insert_user($userdata);
298 - if (is_numeric($newuser_id)) :
299 - $ret = $newuser_id;
698 + endif;
699 +
700 +}
701 +
702 +/**
703 + * Output the Scheduled For Next Update status message in Syndicated Sites table.
704 + *
705 + * @param SyndicatedLink $o_s_link Object representing the feed displayed on this row.
706 + */
707 +function fwp_links_table_rows_next_update( $o_s_link ) {
708 + $ttl = $o_s_link->setting( 'update/ttl' );
709 + ?>
710 + <div style="max-width: 30.0em; font-size: 0.9em;"><div style="font-style:italic;">
711 + <?php
712 + if ( is_numeric( $ttl ) ) :
713 + $next = $o_s_link->setting( 'update/last' ) + $o_s_link->setting( 'update/fudge' ) + ( (int) $ttl * 60 );
714 + if ( 'automatically' === $o_s_link->setting( 'update/timed' ) ) :
715 + if ( $next < time() ) :
716 + print 'Ready and waiting to be updated since ';
717 + else :
718 + print 'Scheduled for next update ';
719 + endif;
720 +
721 + print esc_html( fwp_time_elapsed( $next ) );
722 + if ( FEEDWORDPRESS_DEBUG ) :
723 + $interval = ( ( $next - time() ) / 60 );
724 + printf( ' [%d minute%s]', intval( $interval ), esc_html( _s( $interval ) ) );
725 + endif;
300 726 else :
301 - // TODO: Add some error detection and reporting
727 + printf( '. Scheduled to be checked for updates every %d minute%s', intval( $ttl ), esc_html( _s( $ttl ) ) );
728 + ?>
729 + </div>
730 +
731 + <div style="size:0.9em; margin-top: 0.5em">This update schedule was requested by the feed provider
732 + <?php
733 + if ( $o_s_link->setting( 'update/xml' ) ) :
734 + ?>
735 + using a standard <code style="font-size: inherit; padding: 0; background: transparent">&lt;<?php print esc_html( $o_s_link->setting( 'update/xml' ) ); ?>&gt;</code> element
736 + <?php
737 + endif;
302 738 endif;
303 739 else :
304 - // TODO: Add some error reporting
740 + print 'Scheduled for update as soon as possible';
305 741 endif;
306 - return $ret;
307 -} /* fwp_insert_new_user () */
308 -
742 + print '.';
743 + ?>
744 + </div></div>
745 + <?php
746 +}