PluginProbe
FeedWordPress / trunk
FeedWordPress vtrunk
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 +674 -726 2010.0127trunk View file →
@@ -1,346 +1,164 @@
1 1 <?php
2 -class FeedWordPressAdminPage {
3 - var $context;
4 - var $updated = false;
5 - var $link = NULL;
6 - var $dispatch = NULL;
7 - var $filename = NULL;
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 - /**
10 - * Construct the admin page object.
11 - *
12 - * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings
13 - */
14 - function FeedWordPressAdminPage ($page = 'feedwordpressadmin', $link = NULL) {
15 - $this->link = $link;
17 +$dir = dirname( __FILE__ );
18 +require_once "{$dir}/feedwordpressadminpage.class.php";
19 +require_once "{$dir}/feedwordpresssettingsui.class.php";
16 20
17 - // Set meta-box context name
18 - $this->context = $page;
19 - if ($this->for_feed_settings()) :
20 - $this->context .= 'forfeed';
21 - endif;
22 - } /* FeedWordPressAdminPage constructor */
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 = '' ) {
23 32
24 - function for_feed_settings () { return (is_object($this->link) and method_exists($this->link, 'found') and $this->link->found()); }
25 - function for_default_settings () { return !$this->for_feed_settings(); }
26 -
27 - /*static*/ function submitted_link_id () {
28 - global $fwp_post;
29 -
30 - // Presume global unless we get a specific link ID
31 - $link_id = NULL;
32 -
33 - $submit_buttons = array(
34 - 'save',
35 - 'submit',
36 - 'fix_mismatch',
37 - 'feedfinder',
38 - );
39 - foreach ($submit_buttons as $field) :
40 - if (isset($fwp_post[$field])) :
41 - $link_id = $_REQUEST['save_link_id'];
42 - endif;
43 - endforeach;
44 -
45 - if (is_null($link_id) and isset($_REQUEST['link_id'])) :
46 - $link_id = $_REQUEST['link_id'];
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 ) );
47 37 endif;
38 + endif;
48 39
49 - return $link_id;
50 - } /* FeedWordPressAdminPage::submitted_link_id() */
40 +} /* fwp_form_class_attr() */
51 41
52 - /*static*/ function submitted_link () {
53 - $link_id = FeedWordPressAdminPage::submitted_link_id();
54 - if (is_numeric($link_id) and $link_id) :
55 - $link =& new SyndicatedLink($link_id);
56 - else :
57 - $link = NULL;
58 - endif;
59 - return $link;
60 - } /* FeedWordPressAdminPage::submitted_link () */
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' ) {
61 55
62 - function stamp_link_id ($field = null) {
63 - if (is_null($field)) : $field = 'save_link_id'; endif;
64 - ?>
65 - <input type="hidden" name="<?php print wp_specialchars($field, 'both'); ?>" value="<?php print ($this->for_feed_settings() ? $this->link->id : '*'); ?>" />
66 - <?php
67 - } /* FeedWordPressAdminPage::stamp_link_id () */
56 + $is_on = false;
68 57
69 - function these_posts_phrase () {
70 - if ($this->for_feed_settings()) :
71 - $phrase = __('posts from this feed');
58 + $s_arg = $arg;
59 + if ( is_array( $arg ) && ! is_null( $key ) ) :
60 + if ( array_key_exists( $key, $arg ) ) :
61 + $s_arg = $arg[ $key ];
72 62 else :
73 - $phrase = __('syndicated posts');
63 + $s_arg = false;
74 64 endif;
75 - return $phrase;
76 - } /* FeedWordPressAdminPage::these_posts_phrase() */
65 + endif;
77 66
78 - /**
79 - * Provides a uniquely identifying name for the interface context for
80 - * use with add_meta_box() and do_meta_boxes(),
81 - *
82 - * @return string the context name
83 - *
84 - * @see add_meta_box()
85 - * @see do_meta_boxes()
86 - */
87 - function meta_box_context () {
88 - return $this->context;
89 - } /* FeedWordPressAdminPage::meta_box_context () */
90 -
91 - /**
92 - * Outputs JavaScript to fix AJAX toggles settings.
93 - *
94 - * @uses FeedWordPressAdminPage::meta_box_context()
95 - */
96 - function fix_toggles () {
97 - FeedWordPressSettingsUI::fix_toggles_js($this->meta_box_context());
98 - } /* FeedWordPressAdminPage::fix_toggles() */
67 + if ( is_string( $s_arg ) ) :
68 + $is_on = ( strlen( $s_arg ) > 0 );
69 + else :
70 + $is_on = (bool) ( $s_arg );
71 + endif;
99 72
100 - function ajax_interface_js () {
101 -?>
102 -<script type="text/javascript">
103 - function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
104 - if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
73 + if ( $is_on ) :
74 + print sprintf( '%s="%s"', esc_attr( $flag ), esc_attr( $flag ) );
75 + endif;
76 +} /* fwp_selected_flag() */
105 77
106 - var rollup=document.getElementById(item);
107 - var newuser=document.getElementById(appear);
108 - var sitewide=document.getElementById(disappear);
109 - if (rollup) {
110 - if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
111 - if (newuser) newuser.style.display=visibleStyle;
112 - if (sitewide) sitewide.style.display='none';
113 - } else {
114 - if (newuser) newuser.style.display='none';
115 - if (sitewide) sitewide.style.display=visibleStyle;
116 - }
117 - }
118 - }
119 -</script>
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() */
120 93
121 -<?php
122 - } /* FeedWordPressAdminPage::ajax_interface_js () */
94 +if ( ! function_exists( '_s' ) ) :
95 +/**
96 + * Retrieves a plural or singular form of a string based on the supplied number.
97 + *
98 + * Used when you want to use the appropriate form of a string based on whether
99 + * a number is singular or plural. Very similar to WordPress l10n.php _n(),
100 + * but designed for a nice short form in the
101 + * default case (provide "s" when plural, "" otherwise).
102 + *
103 + * @note This function *may* have been defined elsewhere; also, consider
104 + * using WordPress's own `_n()` function and derivatives. (gwyneth 20230920)
105 + *
106 + * @param int $n The counter to determine singular or plural form.
107 + * @param string $plural The text to use if the counter is plural.
108 + * @param string $singular The text to use if the counter is singular.
109 + *
110 + * @return string The text of the singular or plural form.
111 + */
112 +function _s( $n = 0, $plural = 's', $singular = '' ) {
113 + $is_singular = ( is_numeric( $n ) && intval( $n ) === 1 );
114 + return ( $is_singular ? $singular : $plural );
115 +} /* _s() */
116 +endif;
123 117
124 - function display_feed_select_dropdown() {
125 - $links = FeedWordPress::syndicated_links();
126 - if (fwp_test_wp_version(FWP_SCHEMA_27)) :
127 - ?>
128 - <style type="text/css">
129 - #post-search {
130 - float: right;
131 - margin:11px 12px 0;
132 - min-width: 130px;
133 - position:relative;
134 - }
135 - .fwpfs {
136 - color: #dddddd;
137 - background:#797979 url(<?php bloginfo('home') ?>/wp-admin/images/fav.png) repeat-x scroll left center;
138 - border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px;
139 - -moz-border-radius-bottomright:12px;
140 - -moz-border-radius-topleft:12px;
141 - -moz-border-radius-topright:12px;
142 - border-style:solid;
143 - border-width:1px;
144 - line-height:15px;
145 - padding:3px 30px 4px 12px;
146 - }
147 - .fwpfs.slide-down {
148 - border-bottom-color: #626262;
149 - -moz-border-radius-bottomleft:0;
150 - -moz-border-radius-bottomright:0;
151 - -moz-border-radius-topleft:12px;
152 - -moz-border-radius-topright:12px;
153 - background-image:url(<?php bloginfo('home') ?>/wp-admin/images/fav-top.png);
154 - background-position:0 top;
155 - background-repeat:repeat-x;
156 - border-bottom-style:solid;
157 - border-bottom-width:1px;
158 - }
159 - </style>
160 -
161 - <script type="text/javascript">
162 - jQuery(document).ready(function($){
163 - $('.fwpfs').toggle(
164 - function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
165 - function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
166 - );
167 - $('.fwpfs').bind(
168 - 'change',
169 - function () { this.form.submit(); }
170 - );
171 - $('#post-search .button').css( 'display', 'none' );
172 - });
173 - </script>
174 - <?php
175 - endif;
176 -
177 - ?>
178 - <p id="post-search">
179 - <select name="link_id" class="fwpfs" style="max-width: 20.0em;">
180 - <option value="*"<?php if ($this->for_default_settings()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
181 - <?php if ($links) : foreach ($links as $ddlink) : ?>
182 - <option value="<?php print (int) $ddlink->link_id; ?>"<?php if (!is_null($this->link) and ($this->link->id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print wp_specialchars($ddlink->link_name, 1); ?></option>
183 - <?php endforeach; endif; ?>
184 - </select>
185 - <input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" />
186 - </p>
187 - <?php
188 - } /* FeedWordPressAdminPage::display_feed_select_dropdown() */
118 +/**
119 + * Outputs a status message for the aggregate results of polling a set of feeds.
120 + *
121 + * This will always output the number of new syndicated posts added, even if this is 0.
122 + * Posts updated and alternate versions stored will be added to the message iff > 0.
123 + *
124 + * @param array $delta Counters indicating results in "new", "updated" and "stored".
125 + * @param string $joiner Default ';'. Delimiter used to separate messages about new, updated and stored posts.
126 + */
127 +function fwp_update_set_results_message( $delta, $joiner = ';' ) {
189 128
190 - function display_sheet_header ($pagename = 'Syndication', $all = false) {
191 - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_27)) :
192 - ?>
193 - <div class="icon32"><img src="<?php print wp_specialchars(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png', 1); ?>" alt="" /></div>
194 - <?php
195 - endif;
196 - ?>
129 + $mesg = array();
197 130
198 - <h2><?php print wp_specialchars(__($pagename.($all ? '' : ' Settings')), 1); ?><?php if ($this->for_feed_settings()) : ?>: <?php echo wp_specialchars($this->link->link->link_name, 1); ?><?php endif; ?></h2>
199 - <?php
200 - }
131 + $delta = wp_parse_args(
132 + $delta,
133 + array(
134 + 'new' => 0,
135 + 'updated' => 0,
136 + 'stored' => 0,
137 + )
138 + );
201 139
202 - function display_update_notice_if_updated ($pagename = 'Syndication', $mesg = NULL) {
203 - if ($this->updated) :
204 - if ($this->updated === true) :
205 - $mesg = $pagename . ' settings updated.';
206 - else :
207 - $mesg = $this->updated;
208 - endif;
209 - endif;
210 -
211 - if (!is_null($mesg)) :
212 - ?>
213 - <div class="updated">
214 - <p><?php print wp_specialchars($mesg, 1); ?></p>
215 - </div>
216 - <?php
217 - endif;
218 - } /* FeedWordPressAdminPage::display_update_notice_if_updated() */
219 -
220 - function display_settings_scope_message () {
221 - if ($this->for_feed_settings()) :
222 - ?>
223 - <p>These settings only affect posts syndicated from
224 - <strong><?php echo wp_specialchars($this->link->link->link_name, 1); ?></strong>.</p>
225 - <?php
226 - else :
227 - ?>
228 - <p>These settings affect posts syndicated from any feed unless they are overridden
229 - by settings for that specific feed.</p>
230 - <?php
231 - endif;
232 - } /* FeedWordPressAdminPage::display_settings_scope_message () */
233 -
234 - /*static*/ function has_link () { return true; }
235 -
236 - function open_sheet ($header) {
237 - // Set up prepatory AJAX stuff
238 - $this->ajax_interface_js();
239 - if (function_exists('add_meta_box')) :
240 - add_action(
241 - FeedWordPressCompatibility::bottom_script_hook($this->filename),
242 - /*callback=*/ array($this, 'fix_toggles'),
243 - /*priority=*/ 10000
244 - );
245 - FeedWordPressSettingsUI::ajax_nonce_fields();
246 - endif;
247 -
248 - ?>
249 - <div class="wrap" style="position:relative">
250 - <?php
251 - if (!is_null($header)) :
252 - $this->display_sheet_header($header);
253 - endif;
254 -
255 - if (!is_null($this->dispatch)) :
256 - ?>
257 - <form action="admin.php?page=<?php print $GLOBALS['fwp_path']; ?>/<?php echo basename($this->filename); ?>" method="post">
258 - <div><?php
259 - FeedWordPressCompatibility::stamp_nonce($this->dispatch);
260 - $this->stamp_link_id();
261 - ?></div>
262 - <?php
263 - endif;
264 -
265 - if ($this->has_link()) :
266 - $this->display_feed_select_dropdown();
267 - $this->display_settings_scope_message();
268 - endif;
269 -
270 - if (function_exists('do_meta_boxes')) :
271 - ?>
272 - <div id="poststuff">
273 - <?php
274 - else :
275 - ?>
276 - </div> <!-- class="wrap" -->
277 - <?php
278 - endif;
279 -
280 - if (!is_null($this->dispatch)) :
281 - fwp_settings_form_single_submit();
282 - endif;
283 - } /* FeedWordPressAdminPage::open_sheet () */
284 -
285 - function close_sheet () {
286 - // WordPress 2.5+
287 - if (function_exists('do_meta_boxes')) :
288 - ?>
289 - </div> <!-- id="poststuff" -->
290 - <?php if (!is_null($this->dispatch)) : ?>
291 - <?php fwp_settings_form_single_submit_closer(); ?>
292 - </form>
293 - <?php endif; ?>
294 - </div> <!-- class="wrap" -->
295 - <?php
296 - endif;
297 - }
298 -} /* class FeedWordPressAdminPage */
299 -
300 -function fwp_settings_form_single_submit ($caption = NULL) {
301 - if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_27)) :
302 - if (is_null($caption)) : $caption = __('Save'); endif;
303 -?>
304 -<div class="submitbox" id="submitlink">
305 -<div id="previewview"></div>
306 -<div class="inside"></div>
307 -
308 -<p class="submit">
309 -<input type="submit" name="save" value="<?php print $caption; ?>" />
310 -</p>
311 -</div>
312 -<?php
140 + $mesg[] = sprintf( ' %d new post%s syndicated', intval( $delta['new'] ), _s( $delta['new'], 's were', ' was' ) );
141 + if ( $delta['updated'] > 0 ) :
142 + $mesg[] = sprintf( ' %d existing post%s updated', intval( $delta['updated'] ), _s( $delta['updated'], 's were', ' was' ) );
313 143 endif;
314 -}
315 -
316 -function fwp_settings_form_periodic_submit ($caption = NULL) {
317 - if (!fwp_test_wp_version(FWP_SCHEMA_25)) :
318 - if (is_null($caption)) : $caption = __('Save Changes &raquo;'); endif;
319 -?>
320 -<p class="submit">
321 -<input type="submit" name="save" value="<?php print $caption; ?>" />
322 -</p>
323 -<?php
144 + if ( $delta['stored'] > 0 ) :
145 + $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' ) );
324 146 endif;
325 -}
326 147
327 -function fwp_settings_form_single_submit_closer ($caption = NULL) {
328 - if (fwp_test_wp_version(FWP_SCHEMA_27)) :
329 - if (is_null($caption)) : $caption = __('Save Changes'); endif;
330 -?>
331 -<p class="submit">
332 -<input class="button-primary" type="submit" name="save" value="<?php print $caption; ?>" />
333 -</p>
334 -<?php
148 + if ( ! is_null( $joiner ) ) :
149 + $mesg = implode( $joiner, $mesg );
335 150 endif;
336 -}
151 + return $mesg;
152 +} /* function fwp_update_set_results_message() */
337 153
338 -function fwp_authors_single_submit ($link = NULL) {
339 - global $wp_db_version;
340 -
341 - if (fwp_test_wp_version(FWP_SCHEMA_25)) :
342 -?>
154 +/**
155 + * Outputs the HTML template for a "Submit" button on FWP admin pages.
156 + *
157 + * @param mixed $link The syndicated link, if any, that we are viewing settings for. (Unused)
158 + */
159 +function fwp_authors_single_submit( $link = null ) {
160 + ?>
343 161 <div class="submitbox" id="submitlink">
344 162 <div id="previewview">
345 163 </div>
346 164 <div class="inside">
@@ -346,465 +164,595 @@
346 164 <div class="inside">
347 165 </div>
348 166
349 167 <p class="submit">
350 -<input type="submit" name="save" value="<?php _e('Save') ?>" />
168 +<input type="submit" name="save" value="<?php esc_html_e( 'Save' ); ?>" />
351 169 </p>
352 170 </div>
353 -<?php
171 + <?php
172 +} /* function fwp_authors_single_submit() */
173 +
174 +/**
175 + * Outputs the HTML template for a Tags (or similar taxonomy) add / remove box in FeedWordPress admin UI pages.
176 + *
177 + * @param array $tags An array of tags already applied to the object.
178 + * @param string $object The human-readable description of the objects to be tagged ("post", "posts from this feed", etc.).
179 + * @param array $params An array of optional parameters.
180 + */
181 +function fwp_tags_box( $tags, $object, $params = array() ) {
182 + $params = wp_parse_args(
183 + $params,
184 + array( // Default values.
185 + 'taxonomy' => 'post_tag',
186 + 'textarea_name' => null,
187 + 'textarea_id' => null,
188 + 'input_id' => null,
189 + 'input_name' => null,
190 + 'id' => null,
191 + 'box_title' => __( 'Post Tags' ),
192 + )
193 + );
194 +
195 + if ( ! is_array( $tags ) ) :
196 + $tags = array();
354 197 endif;
355 -}
356 198
357 -function fwp_option_box_opener ($legend, $id, $class = "stuffbox") {
358 - // WordPress 2.5+
359 - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_25)) :
360 -?>
361 -<div id="<?php print $id; ?>" class="<?php print $class; ?>">
362 -<h3><?php print htmlspecialchars($legend); ?></h3>
363 -<div class="inside">
364 -<?php
365 - else :
366 -?>
367 - <div class="wrap">
368 - <h2><?php print htmlspecialchars($legend); ?></h2>
369 -<?php
199 + $tax_name = $params['taxonomy'];
200 + $o_tax = get_taxonomy( $params['taxonomy'] );
201 + $o_tax_labels = get_taxonomy_labels( $o_tax );
202 + $is_enabled = current_user_can( $o_tax->cap->assign_terms );
203 +
204 + if ( is_null( $params['textarea_name'] ) ) :
205 + $params['textarea_name'] = "tax_input[$tax_name]";
370 206 endif;
207 + if ( is_null( $params['textarea_id'] ) ) :
208 + $params['textarea_id'] = "tax-input-{$tax_name}";
209 + endif;
210 + if ( is_null( $params['input_id'] ) ) :
211 + $params['input_id'] = "new-tag-{$tax_name}";
212 + endif;
213 + if ( is_null( $params['input_name'] ) ) :
214 + $params['input_name'] = "newtag[$tax_name]";
215 + endif;
216 + if ( is_null( $params['id'] ) ) :
217 + $params['id'] = $tax_name;
218 + endif;
219 +
220 + printf( /* $desc = */ '<p style="font-size:smaller;font-style:bold;margin:0\">' . esc_html__( 'Tag' ) . ' %s '
221 + . esc_html__( 'as' ) . '...</p>', esc_html( $object ) );
222 + $helps = __( 'Separate tags with commas.' );
223 + $box['title'] = __( 'Tags' );
224 + ?>
225 +<div class="tagsdiv" id="<?php echo esc_attr( $params['id'] ); ?>">
226 + <div class="jaxtag">
227 + <div class="nojs-tags hide-if-js">
228 + <p><?php echo esc_html( $o_tax_labels->add_or_remove_items ); ?></p>
229 + <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>
230 +
231 + <?php if ( $is_enabled ) : ?>
232 + <div class="ajaxtag hide-if-no-js">
233 + <label class="screen-reader-text" for="<?php echo esc_attr( $params['input_id'] ); ?>"><?php echo esc_html( $params['box_title'] ); ?></label>
234 + <div class="taghint"><?php echo esc_html( $o_tax_labels->add_new_item ); ?></div>
235 + <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="" />
236 + <input type="button" class="button tagadd" value="<?php esc_attr_e( 'Add' ); ?>" tabindex="3" /></p>
237 + </div>
238 + <p class="howto"><?php echo esc_attr( $o_tax_labels->separate_items_with_commas ); ?></p>
239 + <?php endif; ?>
240 + </div>
241 +
242 + <div class="tagchecklist"></div>
243 +</div>
244 + <?php
245 + if ( $is_enabled ) :
246 + ?>
247 +<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>
248 + <?php
249 + endif;
250 +
371 251 }
372 252
373 -function fwp_option_box_closer () {
374 - global $wp_db_version;
375 - if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) :
376 -?>
377 - </div> <!-- class="inside" -->
378 - </div> <!-- class="stuffbox" -->
379 -<?php
380 - else :
381 -?>
382 - </div> <!-- class="wrap" -->
383 -<?php
253 +/**
254 + * Outputs the HTML template for a Category (or similar taxonomy) add / remove box in FeedWordPress admin UI pages.
255 + *
256 + * @param array $checked An array of cats already applied to the object.
257 + * @param string $object The human-readable description of the objects to be tagged ("post", "posts from this feed", etc.).
258 + * @param array $tags Not used.
259 + * @param array $params An array of optional parameters (to be parsed with wp_parse_args).
260 + *
261 + * @uses wp_parse_args()
262 + * @uses get_taxonomy()
263 + * @uses get_taxonomy_labels()
264 + */
265 +function fwp_category_box( $checked, $object, $tags = array(), $params = array() ) {
266 + if ( is_string( $params ) ) :
267 + $prefix = $params;
268 + $taxonomy = 'category';
269 + elseif ( is_array( $params ) ) :
270 + $params = wp_parse_args(
271 + $params,
272 + array(
273 + 'prefix' => '',
274 + 'taxonomy' => 'category',
275 + )
276 + );
277 +
278 + $prefix = $params['prefix'];
279 + $taxonomy = $params['taxonomy'];
384 280 endif;
385 -}
386 281
387 -function fwp_tags_box ($tags, $object) {
388 - if (!is_array($tags)) : $tags = array(); endif;
389 -
390 - $desc = "<p style=\"font-size:smaller;font-style:bold;margin:0\">Tag $object as...</p>";
282 + $o_tax = get_taxonomy( $taxonomy );
283 + $o_tax_labels = get_taxonomy_labels( $o_tax );
391 284
392 - if (fwp_test_wp_version(FWP_SCHEMA_29)) : // WordPress 2.9+
393 - print $desc;
394 - $tax_name = 'post_tag';
395 - $helps = __('Separate tags with commas.');
396 - $box['title'] = __('Tags');
397 - ?>
398 - <div class="tagsdiv" id="<?php echo $tax_name; ?>">
399 - <div class="jaxtag">
400 - <div class="nojs-tags hide-if-js">
401 - <p><?php _e('Add or remove tags'); ?></p>
402 - <textarea name="<?php echo "tax_input[$tax_name]"; ?>" class="the-tags" id="tax-input[<?php echo $tax_name; ?>]"><?php echo esc_attr(implode(",", $tags)); ?></textarea></div>
403 -
404 - <div class="ajaxtag hide-if-no-js">
405 - <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $box['title']; ?></label>
406 - <div class="taghint"><?php _e('Add new tag'); ?></div>
407 - <input type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
408 - <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" tabindex="3" />
409 - </div></div>
410 - <p class="howto"><?php echo $helps; ?></p>
411 - <div class="tagchecklist"></div>
412 - </div>
413 - <p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php printf( __('Choose from the most used tags in %s'), $box['title'] ); ?></a></p>
414 -<?php
415 - elseif (fwp_test_wp_version(FWP_SCHEMA_28)) : // WordPress 2.8+
416 -?>
417 - <?php print $desc; ?>
418 - <div class="tagsdiv" id="post_tag">
419 - <div class="jaxtag">
420 - <div class="nojs-tags hide-if-js">
421 - <p><?php _e('Add or remove tags'); ?></p>
422 - <textarea name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]"><?php echo implode(",", $tags); ?></textarea>
423 - </div>
424 -
425 - <span class="ajaxtag hide-if-no-js">
426 - <label class="screen-reader-text" for="new-tag-post_tag"><?php _e('Tags'); ?></label>
427 - <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'); ?>" />
428 - <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
429 - </span>
430 - </div>
431 - <p class="howto"><?php echo __('Separate tags with commas.'); ?></p>
432 - <div class="tagchecklist"></div>
433 - </div>
434 - <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>
435 - </div>
436 - </div>
437 -<?php
438 - else :
439 -?>
440 - <?php print $desc; ?>
441 - <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>
442 - <div id="tagchecklist"></div>
443 - </div>
444 - </div>
445 -<?php
285 + if ( strlen( $prefix ) === 0 ) :
286 + $prefix = 'feedwordpress';
446 287 endif;
447 -}
448 288
449 -function fwp_category_box ($checked, $object, $tags = array()) {
450 - global $wp_db_version;
289 + $id_prefix = $prefix . '-';
290 + $id_suffix = '-' . $prefix;
291 + $name_prefix = $prefix . '_'; // unused? (gwyneth 20230918)
451 292
452 - if (fwp_test_wp_version(FWP_SCHEMA_25)) : // WordPress 2.5.x
453 -?>
454 -<div id="category-adder" class="wp-hidden-children">
455 - <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
456 - <p id="category-add" class="wp-hidden-child">
457 - <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" />
458 - <?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?>
459 - <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" />
460 - <?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
461 - <span id="category-ajax-response"></span>
462 - </p>
293 + $box_div_id = sanitize_html_class( $id_prefix . 'taxonomy-' . $taxonomy );
294 + $tabs_ul_id = sanitize_html_class( $id_prefix . $taxonomy . '-tabs' );
295 + $all_tab_id = sanitize_html_class( $id_prefix . $taxonomy . '-all' );
296 + $chk_lst_id = sanitize_html_class( $id_prefix . $taxonomy . 'checklist' );
297 + $add_tax_id = sanitize_html_class( $id_prefix . $taxonomy . '-adder' );
298 + $add_tog_id = sanitize_html_class( $id_prefix . $taxonomy . '-add-toggle' );
299 + $add_cat_id = sanitize_html_class( $id_prefix . $taxonomy . '-add' );
300 + $new_tax_id = sanitize_html_class( $id_prefix . 'new' . $taxonomy );
301 +
302 + $tax_id_add_submit = sanitize_html_class( $id_prefix . $taxonomy . '-add-sumbit' );
303 + ?>
304 +<div id="<?php print esc_attr( $box_div_id ); ?>" class="feedwordpress-category-div">
305 + <ul id="<?php print esc_attr( $tabs_ul_id ); ?>" class="category-tabs">
306 + <li class="ui-tabs-selected tabs"><a href="#<?php print esc_attr( $all_tab_id ); ?>" tabindex="3"><?php esc_html_e( 'All posts' ); ?></a>
307 + <p style="font-size:smaller;font-style:bold;margin:0"><?php esc_html_e( 'Give' ); ?> <?php print esc_html( $object ); ?> <?php esc_html_e( 'these' ); ?> <?php print esc_html( $o_tax_labels->name ); ?></p>
308 + </li>
309 + </ul>
310 +
311 +<div id="<?php print esc_attr( $all_tab_id ); ?>" class="tabs-panel">
312 + <input type="hidden" value="0" name="tax_input[<?php print esc_attr( $taxonomy ); ?>][]" />
313 + <ul id="<?php print esc_attr( $chk_lst_id ); ?>" class="list:<?php print esc_attr( $taxonomy ); ?> categorychecklist form-no-clear">
314 + <?php fwp_category_checklist( null, false, $checked, $params ); ?>
315 + </ul>
463 316 </div>
464 317
465 -<ul id="category-tabs">
466 - <?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... */ ?>
467 - <li class="ui-tabs-selected tabs"><a href="#categories-all" tabindex="3"><?php _e( 'All posts' ); ?></a>
468 - <p style="font-size:smaller;font-style:bold;margin:0">Give <?php print $object; ?> these categories</p>
469 -</li>
470 -</ul>
318 +<div id="<?php print esc_attr( $add_tax_id ); ?>" class="<?php print esc_attr( $taxonomy ); ?>-adder wp-hidden-children">
319 + <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"><span class="dashicons dashicons-plus fwp-no-underline"></span> <?php esc_html_e( 'Add New Category' ); ?></a></h4>.
320 + <p id="<?php print esc_attr( $add_cat_id ); ?>" class="category-add wp-hidden-child">
321 + <?php
322 + $newcat = 'new' . $taxonomy;
323 + ?>
324 + <label class="screen-reader-text" for="<?php print esc_attr( $new_tax_id ); ?>"><?php esc_html_e( 'Add New Category' ); ?></label>
325 + <input
326 + id="<?php print esc_attr( $new_tax_id ); ?>"
327 + class="<?php print esc_attr( $newcat ); ?> form-required form-input-tip"
328 + aria-required="true"
329 + tabindex="3"
330 + type="text" name="<?php print esc_attr( $newcat ); ?>"
331 + value="<?php esc_attr_e( 'New category name' ); ?>"
332 + />
333 + <label class="screen-reader-text" for="<?php print esc_attr( $new_tax_id ); ?>-parent"><?php esc_html_e( 'Parent Category' ); ?>:</label>
334 + <?php
335 + wp_dropdown_categories(
336 + array(
337 + 'taxonomy' => $taxonomy,
338 + 'hide_empty' => 0,
339 + 'id' => $new_tax_id . '-parent',
340 + 'class' => $newcat . '-parent',
341 + 'name' => $newcat . '_parent',
342 + 'orderby' => 'name',
343 + 'hierarchical' => 1,
344 + 'show_option_none' => __( 'Parent category' ),
345 + 'tab_index' => 3,
346 + )
347 + );
471 348
472 -<?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... */ ?>
473 -<div id="categories-all" class="ui-tabs-panel tabs-panel">
474 - <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
475 - <?php fwp_category_checklist(NULL, false, $checked) ?>
476 - </ul>
349 + $nonce_code = ( 'add-' . $taxonomy );
350 + ?>
351 + <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" />
352 + <?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 */ ?>
353 + <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 ) ); ?>" />
354 + <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 ) ); ?>" />
355 + <span id="<?php print esc_attr( $id_prefix . $taxonomy ); ?>-ajax-response" class="<?php print esc_attr( $taxonomy ); ?>-ajax-response"></span>
356 + </p>
477 357 </div>
478 -<?php
479 - elseif (fwp_test_wp_version(FWP_SCHEMA_20)) : // WordPress 2.x
480 -?>
481 - <div id="moremeta" style="position: relative; right: auto">
482 - <div id="grabit" class="dbx-group">
483 - <fieldset id="categorydiv" class="dbx-box">
484 - <h3 class="dbx-handle"><?php _e('Categories') ?></h3>
485 - <div class="dbx-content">
486 - <p style="font-size:smaller;font-style:bold;margin:0">Place <?php print $object; ?> under...</p>
487 - <p id="jaxcat"></p>
488 - <div id="categorychecklist"><?php fwp_category_checklist(NULL, false, $checked); ?></div>
489 - </div>
490 - </fieldset>
491 - </div>
492 - </div>
493 -<?php
494 - else : // WordPress 1.5
495 -?>
496 - <fieldset style="width: 60%;">
497 - <legend><?php _e('Categories') ?></legend>
498 - <p style="font-size:smaller;font-style:bold;margin:0">Place <?php print $object; ?> under...</p>
499 - <div style="height: 10em; overflow: scroll;"><?php fwp_category_checklist(NULL, false, $checked); ?></div>
500 - </fieldset>
501 -<?php
502 - endif;
358 +
359 +</div>
360 + <?php
503 361 }
504 362
505 -function update_feeds_mention ($feed) {
506 - echo "<li>Updating <cite>".$feed['link/name']."</cite> from &lt;<a href=\""
507 - .$feed['link/uri']."\">".$feed['link/uri']."</a>&gt; ...";
363 +/**
364 + * Outputs a text/html status message indicating that FWP has started polling a feed.
365 + *
366 + * @param array $feed An associative array containing meta-data about the feed being polled.
367 + */
368 +function update_feeds_mention( $feed ) {
369 + printf(
370 + '<li>' . esc_html__( 'Updating' ) . ' <cite>%s</cite> ' . esc_html__( 'from' ) . ' &lt;<a href="%s">%s</a>&gt; ...',
371 + esc_html( $feed['link/name'] ),
372 + esc_url( $feed['link/uri'] ),
373 + esc_html( $feed['link/uri'] )
374 + );
508 375 flush();
509 -}
510 -function update_feeds_finish ($feed, $added, $dt) {
511 - echo " completed in $dt second".(($dt==1)?'':'s')."</li>\n";
512 -}
376 +} /* update_feeds_mention() */
513 377
514 -function fwp_author_list () {
515 - global $wpdb;
378 +/**
379 + * Outputs a text/html status message indicating that FWP has completed polling a feed.
380 + *
381 + * @param array $feed An associative array containing meta-data about the feed being polled (unused).
382 + * @param mixed $added a WP_Error object with error codes and messages, if there was an error in polling.
383 + * @param int $dt seconds it took to complete the poll.
384 + */
385 +function update_feeds_finish( $feed, $added, $dt ) {
386 + if ( is_wp_error( $added ) ) :
387 + $mesgs = $added->get_error_messages();
388 + foreach ( $mesgs as $mesg ) :
389 + printf( '<br/><strong>%s:</strong> <code>%s</code>', esc_html__( 'Feed error' ), esc_html( $mesg ) );
390 + endforeach;
391 + echo "</li>\n";
392 + else :
393 + printf( esc_html__(" completed in %d second%s") . "</li>\n", esc_html( $dt ), esc_html( _s( $dt ) ) );
394 + endif;
395 + flush();
396 +} /* update_feeds_finish() */
397 +
398 +/**
399 + * Retrieves a list of users via the WordPress API.
400 + *
401 + * @return array List of users, by numeric ID => display_name
402 + */
403 +function fwp_author_list() {
516 404 $ret = array();
517 405
518 - // display_name introduced in WP 2.0
519 - if (fwp_test_wp_version(FWP_SCHEMA_20)) :
520 - $name_column = 'display_name';
521 - else :
522 - $name_column = 'user_nickname';
523 - endif;
406 + $users = get_users();
407 + if ( is_array( $users ) ) :
408 + foreach ( $users as $user ) :
409 + $id = (int) $user->ID;
410 + $ret[ $id ] = $user->display_name;
524 411
525 - $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY {$name_column}");
526 - if (is_array($users)) :
527 - foreach ($users as $user) :
528 - $id = (int) $user->ID;
529 - $ret[$id] = $user->{$name_column};
530 - if (strlen(trim($ret[$id])) == 0) :
531 - $ret[$id] = $user->user_login;
412 + if ( strlen( trim( $ret[ $id ] ) ) === 0 ) :
413 + $ret[ $id ] = $user->user_login;
532 414 endif;
533 415 endforeach;
534 416 endif;
535 417 return $ret;
536 -}
418 +} /* fwp_author_list() */
537 419
538 -class FeedWordPressSettingsUI {
539 - function instead_of_posts_box ($link_id = null) {
540 - if (!is_null($link_id)) :
541 - $from_this_feed = 'from this feed';
542 - $by_default = '';
543 - $id_param = "&amp;link_id=".$link_id;
544 - else :
545 - $from_this_feed = 'from syndicated feeds';
546 - $by_default = " by default";
547 - $id_param = "";
420 +/**
421 + * Insert a new user into the WordPress database, with some FeedWordPress-specific default behaviors.
422 + *
423 + * @param string $newuser_name The "Display Name" for the new user; user logins and the like will be determined by a formula.
424 + * @return int|WP_Error Either a numeric ID or a WP_Error object.
425 + */
426 +function fwp_insert_new_user( $newuser_name ) {
427 + $ret = null;
428 + if ( strlen( $newuser_name ) > 0 ) :
429 + $userdata = array();
430 + $userdata['ID'] = null;
431 + $userdata['user_login'] = apply_filters( 'pre_user_login', sanitize_user( $newuser_name ) );
432 + $userdata['user_nicename'] = apply_filters( 'pre_user_nicename', sanitize_title( $newuser_name ) );
433 + $userdata['display_name'] = $newuser_name;
434 + $userdata['user_pass'] = substr( md5( uniqid( microtime() ) ), 0, 6 ); // just something random to lock it up.
435 +
436 + $blah_url = get_bloginfo( 'url' );
437 + $url = wp_parse_url( $blah_url );
438 +
439 + $userdata['user_email'] = substr( md5( uniqid( microtime() ) ), 0, 6 ) . '@' . $url['host'];
440 +
441 + $newuser_id = wp_insert_user( $userdata );
442 +
443 + $ret = $newuser_id; // Either a numeric ID or a WP_Error object.
444 +
445 + else :
446 +
447 + $ret = new WP_Error( 'empty_username', 'Provide a non-empty string for the Display Name to fwp_insert_new_user' );
448 +
449 + endif;
450 + return $ret;
451 +} /* fwp_insert_new_user ( ) */
452 +
453 +/**
454 + * Output HTML for table row in FeedWordPress Syndicated Sources list.
455 + *
456 + * @param array $links array of WordPress link objects.
457 + * @param object $page FeedWordPress admin page object.
458 + * @param string $visible 'Y' or 'N', whether to display syndicated sources marked as visible or as hidden.
459 + */
460 +function fwp_syndication_manage_page_links_table_rows( $links, $page, $visible = 'Y' ) {
461 +
462 + $fwp_syndicated_sources_columns = array( __( 'Name' ), __( 'Feed' ), __( 'Updated' ) );
463 +
464 + $subscribed = ( 'Y' === strtoupper( $visible ) );
465 + if ( $subscribed || ( count( $links ) > 0 ) ) :
466 + $table_classes = array( 'widefat' );
467 + if ( ! $subscribed ) :
468 + $table_classes[] = 'unsubscribed';
548 469 endif;
549 -?>
550 -<p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php<?php print $id_param; ?>"><?php _e('Posts & Links'); ?></a>
551 -settings page to set up how new posts <?php print $from_this_feed; ?> will be published<?php $by_default; ?>, whether they will accept
552 -comments and pings, any custom fields that should be set on each post, etc.</p>
553 -<?php
554 - } /* FeedWordPressSettingsUI::instead_of_posts_box () */
555 -
556 - function instead_of_authors_box ($link_id = null) {
557 - if (!is_null($link_id)) :
558 - $from_this_feed = 'from this feed';
559 - $by_default = '';
560 - $id_param = "&amp;link_id=".$link_id;
561 - else :
562 - $from_this_feed = 'from syndicated feeds';
563 - $by_default = " by default";
564 - $id_param = "";
565 - endif;
470 + $table_classes = implode( ' ', $table_classes );
471 + ?>
472 + <table class="<?php print esc_attr( $table_classes ); ?>">
473 + <thead>
474 + <tr>
475 + <th class="check-column" scope="col"><input type="checkbox" /></th>
476 + <?php
477 + foreach ( $fwp_syndicated_sources_columns as $col ) :
478 + printf( "\t<th scope='col'>%s</th>\n", esc_html( $col ) );
479 + endforeach;
480 + ?>
481 + </tr>
482 + </thead>
483 + <tbody>
484 + <?php
485 + $alt_row = true;
486 + if ( count( $links ) > 0 ) :
487 + foreach ( $links as $link ) :
488 + $tr_class = array();
566 489
567 -?>
568 -<p>Use the <a
569 -href="admin.php?page=<?php print $GLOBALS['fwp_path']
570 -?>/authors-page.php<?php print $id_param; ?>"><?php _e('Authors');
571 -?></a> settings page to set up how new posts
572 -<?php print $from_this_feed; ?> will be assigned to
573 -authors.</p>
574 -<?php
575 - } /* FeedWordPressSettingsUI::instead_of_authors_box () */
576 -
577 - function instead_of_categories_box ($link_id = null) {
578 - if (!is_null($link_id)) :
579 - $from_this_feed = 'from this feed';
580 - $by_default = '';
581 - $id_param = "&amp;link_id=".$link_id;
490 + $o_s_link = new SyndicatedLink( $link->link_id );
491 +
492 + if ( is_null( $o_s_link->setting( 'update/error' ) ) ) :
493 +
494 + $the_error = null;
495 +
496 + else :
497 + $tr_class[] = 'feed-error';
498 + $the_error = unserialize( $o_s_link->setting( 'update/error' ) );
499 + endif;
500 +
501 + $ttl = $o_s_link->setting( 'update/ttl' );
502 +
503 + $alt_row = ! $alt_row;
504 +
505 + if ( $alt_row ) :
506 + $tr_class[] = 'alternate';
507 + endif;
508 + ?>
509 + <tr<?php fwp_form_class_attr( implode( ' ', $tr_class ) ); ?>>
510 + <th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php echo esc_attr( $link->link_id ); ?>" /></th>
511 + <?php
512 + $caption = (
513 + ( strlen( $link->link_rss ) > 0 )
514 + ? __( 'Switch Feed' )
515 + : __( 'Find Feed' )
516 + );
517 + ?>
518 + <td>
519 + <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>
520 + <div class="row-actions">
521 + <?php
522 + if ( $subscribed ) :
523 + $page->display_feed_settings_page_links(
524 + array(
525 + 'before' => '<div><strong> ' . __( 'Settings' ) . ' &gt;</strong> ',
526 + 'after' => '</div>',
527 + 'subscription' => $link,
528 + )
529 + );
530 + endif;
531 + ?>
532 +
533 + <div><strong><?php esc_html_e( 'Actions' ); ?> &gt;</strong>
534 + <?php if ( $subscribed ) : ?>
535 + <a href="<?php print esc_url( $page->admin_page_href( 'syndication.php', array( 'action' => 'feedfinder' ), $link ) ); ?>"><?php echo esc_html( $caption ); ?></a>
536 + <?php else : ?>
537 + <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>
538 + <?php endif; ?>
539 + | <a href="<?php print esc_url( $page->admin_page_href( 'syndication.php', array( 'action' => 'Unsubscribe' ), $link ) ); ?>">
540 + <?php
541 + if ( $subscribed ) :
542 + esc_html_e( 'Unsubscribe' );
543 + else :
544 + esc_html_e( 'Delete permanently' );
545 + endif;
546 + ?>
547 + </a>
548 + | <a href="<?php print esc_url( $link->link_url ); ?>"><?php esc_html_e( 'View' ); ?></a></div>
549 + </div>
550 + </td>
551 + <?php if ( strlen( $link->link_rss ) > 0 ) : ?>
552 + <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>
553 + <?php else : ?>
554 + <td class="feed-missing"><p><strong><?php esc_html_e( 'no feed assigned' ); ?></strong></p></td>
555 + <?php endif; ?>
556 +
557 + <td><div style="float: right; padding-left: 10px">
558 + <input type="submit" class="button" name="update_uri[<?php print esc_html( $link->link_rss ); ?>]" value="<?php esc_html_e( 'Update Now' ); ?>" />
559 + </div>
560 + <?php
561 + fwp_links_table_rows_last_updated( $o_s_link );
562 + fwp_links_table_rows_file_size( $o_s_link );
563 + fwp_links_table_rows_errors_since( $the_error );
564 + fwp_links_table_rows_next_update( $o_s_link );
565 + ?>
566 + </td>
567 + </tr>
568 + <?php
569 + unset( $o_s_link );
570 +
571 + endforeach;
582 572 else :
583 - $from_this_feed = 'from syndicated feeds';
584 - $by_default = " by default";
585 - $id_param = "";
573 + ?>
574 + <tr><td colspan="4"><p><?php esc_html_e( 'There are no websites currently listed for syndication.' ); ?></p></td></tr>
575 + <?php
586 576 endif;
587 -
588 -?>
589 -<p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/categories-page.php<?php print $id_param; ?>"><?php _e('Categories'.FEEDWORDPRESS_AND_TAGS); ?></a>
590 -settings page to set up how new posts <?php print $from_this_feed; ?> are assigned categories <?php if (FeedWordPressCompatibility::post_tags()) : ?>or tags<?php endif; ?><?php print $by_default; ?>.</p>
591 -<?php
592 - } /* FeedWordPressSettingsUI::instead_of_categories_box () */
577 + ?>
578 + </tbody>
579 + </table> <!-- <?php print esc_attr( $table_classes ); ?> -->
580 + <?php
581 + endif;
582 +} /* function fwp_syndication_manage_page_links_table_rows ( ) */
593 583
594 - /*static*/ function ajax_nonce_fields () {
595 - if (function_exists('wp_nonce_field')) :
596 - echo "<form style='display: none' method='get' action=''>\n<p>\n";
597 - wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
598 - wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
599 - echo "</p>\n</form>\n";
600 - endif;
601 - } /* FeedWordPressSettingsUI::ajax_nonce_fields () */
584 +/**
585 + * Output HTML message indicating feed errors, if a feed has been returning errors, in Syndicated Sites table.
586 + *
587 + * @param mixed $the_error If last poll on this feed was successful, this is null.
588 + * 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).
589 + */
590 +function fwp_links_table_rows_errors_since( $the_error ) {
591 + if ( ! is_null( $the_error ) ) :
602 592
603 - /*static*/ function fix_toggles_js ($context) {
604 - ?>
605 - <script type="text/javascript">
606 - jQuery(document).ready( function($) {
607 - <?php if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_29)) : ?>
608 - if ( $('#post_tag').length ) {
609 - tagBox.init();
610 - }
611 - <?php endif; ?>
612 - <?php if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_25, FWP_SCHEMA_27)) : ?>
613 - // In case someone got here first...
614 - jQuery('.postbox h3').unbind('click');
593 + $s_elapsed = fwp_time_elapsed( $the_error['since'] );
594 + $s_recent = fwp_time_elapsed( $the_error['ts'] );
595 + ?>
615 596
616 - add_postbox_toggles('<?php print $context; ?>');
617 - <?php elseif (FeedWordPressCompatibility::test_version(FWP_SCHEMA_27)) : ?>
618 - // In case someone got here first...
619 - $('.postbox h3, .postbox .handlediv').unbind('click');
620 - $('.postbox h3 a').unbind('click');
621 - $('.hide-postbox-tog').unbind('click');
622 - $('.columns-prefs input[type="radio"]').unbind('click');
623 - $('.meta-box-sortables').sortable('destroy');
624 -
625 - postboxes.add_postbox_toggles('<?php print $context; ?>');
626 - <?php endif; ?>
627 - } );
628 - </script>
629 - <?php
630 - } /* FeedWordPressSettingsUI::fix_toggles_js () */
631 -
632 - function magic_input_tip_js ($id) {
633 - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_25)) :
597 +<div class="returning-errors"><p><strong><?php esc_html_e( 'Returning errors' ); ?></strong> <?php esc_html_e( 'since' ); ?> <?php print esc_html( $s_elapsed ); ?></p>
598 +<p><?php esc_html_e( 'Most recent' ); ?> (<?php print esc_html( $s_recent ); ?>):
599 + <?php
600 + foreach ( $the_error['object']->get_error_messages() as $mesg ) :
601 + printf( '<br/><code>%s</code>', esc_html( $mesg ) );
602 + endforeach;
634 603 ?>
635 - <script type="text/javascript">
636 - jQuery(document).ready( function () {
637 - var inputBox = jQuery("#<?php print $id; ?>");
638 - var boxEl = inputBox.get(0);
639 - if (boxEl.value==boxEl.defaultValue) { inputBox.addClass('form-input-tip'); }
640 - inputBox.focus(function() {
641 - if ( this.value == this.defaultValue )
642 - jQuery(this).val( '' ).removeClass( 'form-input-tip' );
643 - });
644 - inputBox.blur(function() {
645 - if ( this.value == '' )
646 - jQuery(this).val( this.defaultValue ).addClass( 'form-input-tip' );
647 - });
648 - } );
649 - </script>
604 +</p>
605 +</div>
606 +
650 607 <?php
608 + endif;
609 +}
610 +
611 +/**
612 + * Output the "Last checked..." status message in Syndicated Sites table.
613 + *
614 + * @param SyndicatedLink $o_s_link The SyndicatedLink object representing the feed displayed on this row.
615 + */
616 +function fwp_links_table_rows_last_updated( $o_s_link ) {
617 + if ( ! is_null( $o_s_link->setting( 'update/last' ) ) ) :
618 + print esc_html__( 'Last checked ') . esc_html( fwp_time_elapsed( $o_s_link->setting( 'update/last' ) ) );
619 + else :
620 + print esc_html__( 'None yet' );
621 + endif;
622 +
623 + $ttl = $o_s_link->setting( 'update/ttl' );
624 + if ( is_numeric( $ttl ) ) :
625 + $next = $o_s_link->setting( 'update/last' ) + $o_s_link->setting( 'update/fudge' ) + ( (int) $ttl * 60 );
626 +
627 + if ( 'automatically' !== $o_s_link->setting( 'update/timed' ) ) :
628 +
629 + print ' &middot; ' . esc_html__( 'Next') . ' ';
630 + print esc_html( fwp_relative_time_string( $next ) );
631 +
651 632 endif;
652 - } /* FeedWordPressSettingsUI::magic_input_tip_js () */
653 -} /* class FeedWordPressSettingsUI */
633 + endif;
654 634
655 -function fwp_insert_new_user ($newuser_name) {
656 - global $wpdb;
635 +}
657 636
658 - $ret = null;
659 - if (strlen($newuser_name) > 0) :
660 - $userdata = array();
661 - $userdata['ID'] = NULL;
662 -
663 - $userdata['user_login'] = sanitize_user($newuser_name);
664 - $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
665 -
666 - $userdata['user_nicename'] = sanitize_title($newuser_name);
667 - $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
668 -
669 - $userdata['display_name'] = $wpdb->escape($newuser_name);
637 +/**
638 + * Return a status message indicating when a feed will next be polled, based on a next-update timestamp.
639 + *
640 + * @param int $ts Timestamp for next updrate.
641 + * @param bool $ago Display "[relative time] ago", or "ASAP", if the timestamp is in the past.
642 + */
643 +function fwp_relative_time_string( $ts, $ago = false ) {
670 644
671 - $newuser_id = wp_insert_user($userdata);
672 - if (is_numeric($newuser_id)) :
673 - $ret = $newuser_id;
674 - else :
675 - // TODO: Add some error detection and reporting
676 - endif;
645 + $dt = ( $ts - time() );
646 +
647 + if ( $dt < 0 && ! $ago ) :
648 + $ret = __( 'ASAP' );
649 + elseif ( $dt < 60 * 60 ) :
650 + $ret = fwp_time_elapsed( $ts );
651 + elseif ( $dt < 60 * 60 * 24 ) :
652 + $ret = wp_date( 'g:ia', $ts );
677 653 else :
678 - // TODO: Add some error reporting
654 + $ret = wp_date( 'F j', $ts );
679 655 endif;
680 656 return $ret;
681 -} /* fwp_insert_new_user () */
657 +}
682 658
683 -function fwp_add_meta_box ($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args = null) {
684 - if (function_exists('add_meta_box')) :
685 - return add_meta_box($id, $title, $callback, $page, $context, $priority, $callback_args);
686 - else :
687 - /* Re-used as per terms of the GPL from add_meta_box() in WordPress 2.8.1 wp-admin/includes/template.php. */
688 - global $wp_meta_boxes;
689 -
690 - if ( !isset($wp_meta_boxes) )
691 - $wp_meta_boxes = array();
692 - if ( !isset($wp_meta_boxes[$page]) )
693 - $wp_meta_boxes[$page] = array();
694 - if ( !isset($wp_meta_boxes[$page][$context]) )
695 - $wp_meta_boxes[$page][$context] = array();
696 -
697 - foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
698 - foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
699 - if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
700 - continue;
701 -
702 - // If a core box was previously added or removed by a plugin, don't add.
703 - if ( 'core' == $priority ) {
704 - // If core box previously deleted, don't add
705 - if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
706 - return;
707 - // If box was added with default priority, give it core priority to maintain sort order
708 - if ( 'default' == $a_priority ) {
709 - $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
710 - unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
711 - }
712 - return;
713 - }
714 - // If no priority given and id already present, use existing priority
715 - if ( empty($priority) ) {
716 - $priority = $a_priority;
717 - // else if we're adding to the sorted priortiy, we don't know the title or callback. Glab them from the previously added context/priority.
718 - } elseif ( 'sorted' == $priority ) {
719 - $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
720 - $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
721 - $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
722 - }
723 - // An id can be in only one priority and one context
724 - if ( $priority != $a_priority || $context != $a_context )
725 - unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
726 - }
727 - }
728 -
729 - if ( empty($priority) )
730 - $priority = 'low';
731 -
732 - if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
733 - $wp_meta_boxes[$page][$context][$priority] = array();
734 -
735 - $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
659 +/**
660 + * Output the File Size / Format status message in Syndicated Sites table.
661 + *
662 + * @param SyndicatedLink $o_s_link Object representing the feed displayed on this row.
663 + */
664 +function fwp_links_table_rows_file_size( $o_s_link ) {
665 +
666 + $mesg_file_size_lines = array();
667 +
668 + $feed_type = $o_s_link->get_feed_type();
669 +
670 + if ( ! is_null( $o_s_link->setting( 'link/item count' ) ) ) :
671 + $n = $o_s_link->setting( 'link/item count' );
672 +
673 + // translators: %1$d is the item count; %2$s is the plural marker (if any) for item.
674 + $mesg_file_size_lines[] = sprintf( __( '%1$d item%2$s' ), $n, _s( $n ) ) . ', ' . $feed_type;
675 +
736 676 endif;
737 -} /* function fwp_add_meta_box () */
738 677
739 -function fwp_do_meta_boxes($page, $context, $object) {
740 - if (function_exists('do_meta_boxes')) :
741 - $ret = do_meta_boxes($page, $context, $object);
742 -
743 - // Avoid JavaScript error from WordPress 2.5 bug
744 -?>
745 - <div style="display: none">
746 - <div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->
747 - </div>
748 -<?php
749 - return $ret;
750 - else :
751 - /* Derived as per terms of the GPL from do_meta_boxes() in WordPress 2.8.1 wp-admin/includes/template.php. */
752 - global $wp_meta_boxes;
753 - static $already_sorted = false;
754 -
755 - //do_action('do_meta_boxes', $page, $context, $object);
756 -
757 - echo "<div id='$context-sortables' class='meta-box-sortables'>\n";
758 -
759 - $i = 0;
760 - do {
761 - if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
762 - break;
763 -
764 - foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
765 - if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
766 - foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
767 - if ( false == $box || ! $box['title'] )
768 - continue;
769 - $i++;
770 - fwp_option_box_opener($box['title'], $box['id'], 'postbox' /*. postbox_classes($box['id'], $page)*/);
771 - call_user_func($box['callback'], $object, $box);
772 - fwp_option_box_closer();
773 -
774 - if (is_object($object) and method_exists($object, 'interstitial')) :
775 - $object->interstitial();
776 - else :
777 - // Submit button for WP 1.5, early 2.x style
778 - fwp_settings_form_periodic_submit();
779 - endif;
780 - }
781 - }
782 - }
783 - } while(0);
784 -
785 - echo "</div>";
786 -
787 - return $i;
678 + if ( is_null( $o_s_link->setting( 'update/error' ) ) ) :
679 +
680 + if ( ! is_null( $o_s_link->setting( 'link/filesize' ) ) ) :
681 + // size_format() _can_ return false, so we check for that first (gwyneth 20230918)
682 + $formatted_bytes = size_format( $o_s_link->setting( 'link/filesize' ) );
683 + if ( $formatted_bytes ) :
684 + $mesg_file_size_lines[] = $formatted_bytes . '&nbsp;' . __( 'total' );
685 + else:
686 + $mesg_file_size_lines[] = __( '(invalid number of bytes)' );
687 + endif;
688 + FeedWordPress::diagnostic( 'link/filesize', 'File size for this link was reported as being `' . $o_s_link->setting( 'link/filesize' ) . '\'' );
689 + else :
690 + $mesg_file_size_lines[] = __( '(unknown bytes)' );
691 + FeedWordPress::diagnostic( 'link/filesize', 'No error, but link/filesize reported NULL bytes.' );
692 + endif;
693 +
694 +
788 695 endif;
789 -} /* function fwp_do_meta_boxes() */
790 696
791 -function fwp_remove_meta_box($id, $page, $context) {
792 - if (function_exists('remove_meta_box')) :
793 - return remove_meta_box($id, $page, $context);
794 - else :
795 - /* Re-used as per terms of the GPL from remove_meta_box() in WordPress 2.8.1 wp-admin/includes/template.php */
796 - global $wp_meta_boxes;
797 -
798 - if ( !isset($wp_meta_boxes) )
799 - $wp_meta_boxes = array();
800 - if ( !isset($wp_meta_boxes[$page]) )
801 - $wp_meta_boxes[$page] = array();
802 - if ( !isset($wp_meta_boxes[$page][$context]) )
803 - $wp_meta_boxes[$page][$context] = array();
804 -
805 - foreach ( array('high', 'core', 'default', 'low') as $priority )
806 - $wp_meta_boxes[$page][$context][$priority][$id] = false;
697 + if ( count( $mesg_file_size_lines ) > 0 ) :
698 +
699 + print '<div>';
700 + $sep = '';
701 + foreach ( $mesg_file_size_lines as $line ) :
702 + print esc_html( $sep );
703 + print esc_html( $line );
704 + $sep = ' / ';
705 + endforeach;
706 + print '</div>';
707 +
807 708 endif;
808 -} /* function fwp_remove_meta_box() */
809 709
710 +}
810 711
712 +/**
713 + * Output the Scheduled For Next Update status message in Syndicated Sites table.
714 + *
715 + * @param SyndicatedLink $o_s_link Object representing the feed displayed on this row.
716 + */
717 +function fwp_links_table_rows_next_update( $o_s_link ) {
718 + $ttl = $o_s_link->setting( 'update/ttl' );
719 + ?>
720 + <div style="max-width: 30.0em; font-size: 0.9em;"><div style="font-style:italic;">
721 + <?php
722 + if ( is_numeric( $ttl ) ) :
723 + $next = $o_s_link->setting( 'update/last' ) + $o_s_link->setting( 'update/fudge' ) + ( (int) $ttl * 60 );
724 + if ( 'automatically' === $o_s_link->setting( 'update/timed' ) ) :
725 + if ( $next < time() ) :
726 + esc_html_e( 'Ready and waiting to be updated since ' );
727 + else :
728 + esc_html_e( 'Scheduled for next update ' );
729 + endif;
730 +
731 + print esc_html( fwp_time_elapsed( $next ) );
732 + if ( FEEDWORDPRESS_DEBUG ) :
733 + $interval = ( ( $next - time() ) / 60 );
734 + printf( ' [%d %s%s]', intval( $interval ), esc_html__( 'minute' ), esc_html( _s( $interval ) ) );
735 + endif;
736 + else :
737 + printf( esc_html__( 'Scheduled to be checked for updates every ' ) . '%d %s%s.',
738 + intval( $ttl ),
739 + esc_html__( 'minute' ),
740 + esc_html( _s( $ttl ) ) );
741 + ?>
742 + </div>
743 +
744 + <div style="size:0.9em; margin-top: 0.5em"><?php esc_html_e( 'This update schedule was requested by the feed provider' ); ?>
745 + <?php
746 + if ( $o_s_link->setting( 'update/xml' ) ) :
747 + ?>
748 + <?php esc_html_e( '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> <?php esc_html_e( 'element' ); // Note: the tricky php tags placed here try to avoid a space before the period. (gwyneth 20230918)
749 + endif;
750 + endif;
751 + else :
752 + esc_html_e( 'Scheduled for update as soon as possible' );
753 + endif;
754 + print '.';
755 + ?>
756 + </div></div>
757 + <?php
758 +}