| 1 |
<?php |
| 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 |
*/ |
| 16 |
|
| 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; |
| 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 ); |
| 111 |
} |
| 112 |
|
| 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' ) ); |
| 138 |
endif; |
| 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; |
| 142 |
|
| 143 |
if ( ! is_null( $joiner ) ) : |
| 144 |
$mesg = implode( $joiner, $mesg ); |
| 145 |
endif; |
| 146 |
return $mesg; |
| 147 |
} /* function fwp_update_set_results_message () */ |
| 148 |
|
| 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 |
?> |
| 156 |
<div class="submitbox" id="submitlink"> |
| 157 |
<div id="previewview"> |
| 158 |
</div> |
| 159 |
<div class="inside"> |
| 160 |
</div> |
| 161 |
|
| 162 |
<p class="submit"> |
| 163 |
<input type="submit" name="save" value="<?php esc_html_e( 'Save' ); ?>" /> |
| 164 |
</p> |
| 165 |
</div> |
| 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(); |
| 192 |
endif; |
| 193 |
|
| 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]"; |
| 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 |
|
| 246 |
} |
| 247 |
|
| 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() ) { |
| 257 |
global $wp_db_version; |
| 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']; |
| 273 |
endif; |
| 274 |
|
| 275 |
$o_tax = get_taxonomy( $taxonomy ); |
| 276 |
$o_tax_labels = get_taxonomy_labels( $o_tax ); |
| 277 |
|
| 278 |
if ( strlen( $prefix ) === 0 ) : |
| 279 |
$prefix = 'feedwordpress'; |
| 280 |
endif; |
| 281 |
|
| 282 |
$id_prefix = $prefix . '-'; |
| 283 |
$id_suffix = '-' . $prefix; |
| 284 |
$name_prefix = $prefix . '_'; |
| 285 |
|
| 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> |
| 309 |
</div> |
| 310 |
|
| 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 |
); |
| 341 |
|
| 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> |
| 350 |
</div> |
| 351 |
|
| 352 |
</div> |
| 353 |
<?php |
| 354 |
} |
| 355 |
|
| 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 <<a href="%s">%s</a>> ...', |
| 364 |
esc_html( $feed['link/name'] ), |
| 365 |
esc_url( $feed['link/uri'] ), |
| 366 |
esc_html( $feed['link/uri'] ) |
| 367 |
); |
| 368 |
flush(); |
| 369 |
} |
| 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(); |
| 389 |
} |
| 390 |
|
| 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() { |
| 397 |
global $wpdb; |
| 398 |
$ret = array(); |
| 399 |
|
| 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; |
| 405 |
|
| 406 |
if ( strlen( trim( $ret[ $id ] ) ) === 0 ) : |
| 407 |
$ret[ $id ] = $user->user_login; |
| 408 |
endif; |
| 409 |
endforeach; |
| 410 |
endif; |
| 411 |
return $ret; |
| 412 |
} |
| 413 |
|
| 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 ></strong> ', |
| 522 |
'after' => '</div>', |
| 523 |
'subscription' => $link, |
| 524 |
) |
| 525 |
); |
| 526 |
endif; |
| 527 |
?> |
| 528 |
|
| 529 |
<div><strong>Actions ></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; |
| 568 |
else : |
| 569 |
?> |
| 570 |
<tr><td colspan="4"><p>There are no websites currently listed for syndication.</p></td></tr> |
| 571 |
<?php |
| 572 |
|
| 573 |
endif; |
| 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 ' · Next '; |
| 631 |
print esc_html( fwp_relative_time_string( $next ) ); |
| 632 |
|
| 633 |
endif; |
| 634 |
endif; |
| 635 |
|
| 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'; |
| 683 |
endif; |
| 684 |
|
| 685 |
endif; |
| 686 |
|
| 687 |
if ( count( $mesg_file_size_lines ) > 0 ) : |
| 688 |
|
| 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>'; |
| 697 |
|
| 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; |
| 726 |
else : |
| 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"><<?php print esc_html( $o_s_link->setting( 'update/xml' ) ); ?>></code> element |
| 736 |
<?php |
| 737 |
endif; |
| 738 |
endif; |
| 739 |
else : |
| 740 |
print 'Scheduled for update as soon as possible'; |
| 741 |
endif; |
| 742 |
print '.'; |
| 743 |
?> |
| 744 |
</div></div> |
| 745 |
<?php |
| 746 |
} |
| 747 |
|