| 1 |
<?php |
| 2 |
/** |
| 3 |
* This template contains the friend editor. |
| 4 |
* |
| 5 |
* @version 1.0 |
| 6 |
* @package Friends |
| 7 |
*/ |
| 8 |
|
| 9 |
$active_feeds = $args['friend']->get_active_feeds(); |
| 10 |
$_feeds = $args['friend']->get_feeds(); |
| 11 |
|
| 12 |
|
| 13 |
$has_last_log = false; |
| 14 |
?><form method="post"> |
| 15 |
<?php wp_nonce_field( 'edit-friend-feeds-' . $args['friend']->user_login ); ?> |
| 16 |
<table class="form-table"> |
| 17 |
<tbody> |
| 18 |
<tr> |
| 19 |
<th><label for="url"><?php esc_html_e( 'Feeds', 'friends' ); ?></label></th> |
| 20 |
<td> |
| 21 |
<?php if ( empty( $active_feeds ) ) : ?> |
| 22 |
<?php esc_html_e( 'There are no active feeds.', 'friends' ); ?> |
| 23 |
<?php endif; ?> |
| 24 |
<ul class="feeds <?php echo empty( $active_feeds ) ? ' hidden' : ''; ?>"> |
| 25 |
<?php |
| 26 |
$friends_feed = Friends\Friends::get_instance()->feed; |
| 27 |
foreach ( $_feeds as $term_id => $feed ) : |
| 28 |
if ( $feed->get_last_log() ) { |
| 29 |
$has_last_log = true; |
| 30 |
$last_log = $feed->get_last_log(); |
| 31 |
} |
| 32 |
$parser_slug = $feed->get_parser(); |
| 33 |
$feed_badge = $friends_feed->get_feed_badge( $feed ); |
| 34 |
$feed_title = $feed->get_title(); |
| 35 |
|
| 36 |
/** |
| 37 |
* Filter the feed title displayed in the feed list. |
| 38 |
* |
| 39 |
* @param string $feed_title The feed title. |
| 40 |
* @param User_Feed $feed The feed object. |
| 41 |
* @param string $parser The parser slug. |
| 42 |
*/ |
| 43 |
$feed_title = apply_filters( 'friends_feed_list_title', $feed_title, $feed, $parser_slug ); |
| 44 |
?> |
| 45 |
<li class="<?php echo esc_attr( $feed->get_active() ? 'active' : 'inactive hidden' ); ?> feed-parser-<?php echo esc_attr( $parser_slug ); ?>"<?php echo $feed_badge ? ' style="--feed-color: ' . esc_attr( $feed_badge['color'] ) . ';"' : ''; ?>> |
| 46 |
<details> |
| 47 |
<summary> |
| 48 |
<?php if ( $feed_badge ) : ?> |
| 49 |
<span class="feed-badge" title="<?php echo esc_attr( $feed_badge['title'] ); ?>"><?php echo esc_html( $feed_badge['label'] ); ?></span> |
| 50 |
<?php endif; ?> |
| 51 |
<?php if ( $feed_title ) : ?> |
| 52 |
<span class="feed-title"><?php echo esc_html( $feed_title ); ?></span> |
| 53 |
<?php endif; ?> |
| 54 |
<a class="feed-url" href="<?php echo esc_url( $feed->get_url() ); ?>"><?php echo esc_html( $feed->get_url() ); ?></a> |
| 55 |
</summary> |
| 56 |
<div class="feed-content"> |
| 57 |
<?php |
| 58 |
/** |
| 59 |
* Action to add content at the top of the feed edit section. |
| 60 |
* |
| 61 |
* @param User_Feed $feed The feed being edited. |
| 62 |
* @param int $term_id The term ID of the feed. |
| 63 |
* @param string $parser The parser slug. |
| 64 |
*/ |
| 65 |
do_action( 'friends_edit_feed_content_top', $feed, $term_id, $parser_slug ); |
| 66 |
?> |
| 67 |
<table class="form-table"> |
| 68 |
<tbody> |
| 69 |
<tr> |
| 70 |
<th><?php esc_html_e( 'Active', 'friends' ); ?></th> |
| 71 |
<td> |
| 72 |
<input type="checkbox" name="feeds[<?php echo esc_attr( $term_id ); ?>][active]" value="1" aria-label="<?php esc_attr_e( 'Feed is active', 'friends' ); ?>"<?php checked( $feed->get_active() ); ?> /> |
| 73 |
<?php if ( $feed->is_activitypub_feed() ) : ?> |
| 74 |
<p class="description"><?php esc_html_e( 'Make inactive and save changes to unfollow.', 'friends' ); ?></p> |
| 75 |
<?php endif; ?> |
| 76 |
</td> |
| 77 |
</tr> |
| 78 |
<?php if ( ! $feed->is_activitypub_feed() ) : ?> |
| 79 |
<tr> |
| 80 |
<th><?php esc_html_e( 'Feed URL', 'friends' ); ?></th> |
| 81 |
<td> |
| 82 |
<input type="text" name="feeds[<?php echo esc_attr( $term_id ); ?>][url]" value="<?php echo esc_attr( $feed->get_url() ); ?>" size="30" aria-label="<?php esc_attr_e( 'Feed URL', 'friends' ); ?>" class="url" /> |
| 83 |
</td> |
| 84 |
</tr> |
| 85 |
<?php endif; ?> |
| 86 |
<tr> |
| 87 |
<th><?php esc_html_e( 'Parser', 'friends' ); ?></th> |
| 88 |
<td> |
| 89 |
<?php if ( $feed->is_activitypub_feed() ) : ?> |
| 90 |
<strong><?php esc_html_e( 'ActivityPub', 'friends' ); ?></strong> |
| 91 |
<input type="hidden" name="feeds[<?php echo esc_attr( $term_id ); ?>][parser]" value="activitypub" /> |
| 92 |
<input type="hidden" name="feeds[<?php echo esc_attr( $term_id ); ?>][ap-actor-id]" value="<?php echo esc_attr( $feed->get_ap_actor_id() ); ?>" /> |
| 93 |
<?php else : ?> |
| 94 |
<select name="feeds[<?php echo esc_attr( $term_id ); ?>][parser]" aria-label="<?php esc_attr_e( 'Parser', 'friends' ); ?>"> |
| 95 |
<?php foreach ( $args['registered_parsers'] as $slug => $parser_name ) : ?> |
| 96 |
<option value="<?php echo esc_attr( $slug ); ?>"<?php selected( $slug, $feed->get_parser() ); ?>><?php echo esc_html( wp_strip_all_tags( $parser_name ) ); ?></option> |
| 97 |
<?php endforeach; ?> |
| 98 |
<?php if ( 'unsupported' === $feed->get_parser() ) : ?> |
| 99 |
<option value="<?php echo esc_attr( $feed->get_parser() ); ?>" selected="selected"> |
| 100 |
<?php |
| 101 |
// translators: %s is the name of a deleted parser. |
| 102 |
echo esc_html( $feed->get_parser() ); |
| 103 |
?> |
| 104 |
</option> |
| 105 |
<?php elseif ( ! isset( $args['registered_parsers'][ $feed->get_parser() ] ) ) : ?> |
| 106 |
<option value="<?php echo esc_attr( $feed->get_parser() ); ?>" selected="selected"> |
| 107 |
<?php |
| 108 |
// translators: %s is the name of a deleted parser. |
| 109 |
echo esc_html( sprintf( __( '%s (deleted)', 'friends' ), $feed->get_parser() ) ); |
| 110 |
?> |
| 111 |
</option> |
| 112 |
<?php endif; ?> |
| 113 |
</select> |
| 114 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( '_wp_http_referer', remove_query_arg( '_wp_http_referer' ), self_admin_url( 'admin.php?page=add-friend&parser=' . esc_url( $feed->get_parser() ) . '&feed=' . esc_attr( $term_id ) . '&preview=' . esc_url( $feed->get_url() ) ) ), 'preview-feed' ) ); ?>" class="preview-parser" target="_blank" rel="noopener noreferrer"><?php esc_attr_e( 'Preview', 'friends' ); ?></a> |
| 115 |
<?php endif; ?> |
| 116 |
</td> |
| 117 |
</tr> |
| 118 |
<tr> |
| 119 |
<th><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Post Format' ); ?></th> |
| 120 |
<td> |
| 121 |
<select name="feeds[<?php echo esc_attr( $term_id ); ?>][post-format]" aria-label="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_attr_e( 'Post Format' ); ?>"> |
| 122 |
<?php foreach ( $args['post_formats'] as $format => $_title ) : ?> |
| 123 |
<option value="<?php echo esc_attr( $format ); ?>"<?php selected( $format, $feed->get_post_format() ); ?>><?php echo esc_html( $_title ); ?></option> |
| 124 |
<?php endforeach; ?> |
| 125 |
</select> |
| 126 |
</td> |
| 127 |
</tr> |
| 128 |
<tr> |
| 129 |
<th><?php esc_html_e( 'Remarks', 'friends' ); ?></th> |
| 130 |
<td><input type="text" name="feeds[<?php echo esc_attr( $term_id ); ?>][title]" value="<?php echo esc_attr( $feed->get_title() ); ?>" size="20" aria-label="<?php esc_attr_e( 'Feed Name', 'friends' ); ?>" /></td> |
| 131 |
</tr> |
| 132 |
<tr> |
| 133 |
<th><?php esc_html_e( 'Actions', 'friends' ); ?></th> |
| 134 |
<td> |
| 135 |
<?php if ( $feed->is_activitypub_feed() ) : ?> |
| 136 |
<?php if ( $feed->get_active() ) : ?> |
| 137 |
<span class="dashicons dashicons-info-outline" title="<?php esc_attr_e( 'Make inactive and save changes so that you can remove this feed.', 'friends' ); ?>" aria-label="<?php esc_attr_e( 'Make inactive and save changes so that you can remove this feed.', 'friends' ); ?>"></span> |
| 138 |
<?php esc_html_e( 'Unfollow to remove', 'friends' ); ?> |
| 139 |
<?php else : ?> |
| 140 |
<a href="#" class="delete-feed activitypub-unfollow"><?php esc_html_e( 'Remove', 'friends' ); ?></a> |
| 141 |
<?php endif; ?> |
| 142 |
<?php else : ?> |
| 143 |
<a href="#" class="delete-feed"><?php esc_html_e( 'Delete', 'friends' ); ?></a> |
| 144 |
<?php endif; ?> |
| 145 |
</td> |
| 146 |
</tr> |
| 147 |
<?php do_action( 'friends_feed_list_item', $feed, $term_id ); ?> |
| 148 |
</tbody> |
| 149 |
</table> |
| 150 |
</div> |
| 151 |
</details> |
| 152 |
<?php if ( $feed->get_last_log() ) : ?> |
| 153 |
<p class="lastlog hidden notice"> |
| 154 |
<?php |
| 155 |
echo esc_html( $feed->get_last_log() ); |
| 156 |
echo ' '; |
| 157 |
echo wp_kses_post( |
| 158 |
sprintf( |
| 159 |
// translators: %s is a date. |
| 160 |
__( 'Will be fetched again at %s.', 'friends' ), |
| 161 |
esc_html( $feed->get_next_poll() ) |
| 162 |
) |
| 163 |
); |
| 164 |
?> |
| 165 |
</p> |
| 166 |
<?php endif; ?> |
| 167 |
</li> |
| 168 |
<?php endforeach; ?> |
| 169 |
<li class="template hidden"> |
| 170 |
<details open> |
| 171 |
<summary> |
| 172 |
<span class="feed-title"><?php esc_html_e( 'New Feed', 'friends' ); ?></span> |
| 173 |
</summary> |
| 174 |
<div class="feed-content"> |
| 175 |
<table class="form-table"> |
| 176 |
<tbody> |
| 177 |
<tr> |
| 178 |
<th><?php esc_html_e( 'Feed URL', 'friends' ); ?></th> |
| 179 |
<td><input type="text" name="feeds[new][url]" value="" size="30" aria-label="<?php esc_attr_e( 'Feed URL', 'friends' ); ?>" class="url" /></td> |
| 180 |
</tr> |
| 181 |
<tr> |
| 182 |
<th><?php esc_html_e( 'Parser', 'friends' ); ?></th> |
| 183 |
<td> |
| 184 |
<select name="feeds[new][parser]" aria-label="<?php esc_attr_e( 'Parser', 'friends' ); ?>"> |
| 185 |
<?php foreach ( $args['registered_parsers'] as $slug => $parser_name ) : ?> |
| 186 |
<option value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( wp_strip_all_tags( $parser_name ) ); ?></option> |
| 187 |
<?php endforeach; ?> |
| 188 |
</select> |
| 189 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( '_wp_http_referer', remove_query_arg( '_wp_http_referer' ), self_admin_url( 'admin.php?page=add-friend&parser=&preview=' ) ), 'preview-feed' ) ); ?>" class="preview-parser" target="_blank" rel="noopener noreferrer"><?php esc_attr_e( 'Preview', 'friends' ); ?></a> |
| 190 |
</td> |
| 191 |
</tr> |
| 192 |
<tr> |
| 193 |
<th><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Post Format' ); ?></th> |
| 194 |
<td> |
| 195 |
<select name="feeds[new][post-format]" aria-label="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_attr_e( 'Post Format' ); ?>"> |
| 196 |
<?php foreach ( $args['post_formats'] as $format => $_title ) : ?> |
| 197 |
<option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( $_title ); ?></option> |
| 198 |
<?php endforeach; ?> |
| 199 |
</select> |
| 200 |
</td> |
| 201 |
</tr> |
| 202 |
<tr> |
| 203 |
<th><?php esc_html_e( 'Remarks', 'friends' ); ?></th> |
| 204 |
<td><input type="text" name="feeds[new][title]" value="" size="20" aria-label="<?php esc_attr_e( 'Feed Name', 'friends' ); ?>" /></td> |
| 205 |
</tr> |
| 206 |
<?php do_action( 'friends_feed_list_item', isset( $feed ) ? $feed : array(), 'new' ); ?> |
| 207 |
</tbody> |
| 208 |
</table> |
| 209 |
</div> |
| 210 |
</details> |
| 211 |
</li> |
| 212 |
</ul> |
| 213 |
|
| 214 |
<?php if ( count( $active_feeds ) !== count( $_feeds ) ) : ?> |
| 215 |
<a href="" class="show-inactive-feeds"><?php esc_html_e( 'Show inactive feeds', 'friends' ); ?></a> | |
| 216 |
<?php endif; ?> |
| 217 |
<?php if ( $has_last_log ) : ?> |
| 218 |
<a href="" class="show-log-lines"><?php esc_html_e( 'Show log output', 'friends' ); ?></a> | |
| 219 |
<?php endif; ?> |
| 220 |
<a href="" class="add-feed"><?php esc_html_e( 'Add a feed', 'friends' ); ?></a> |
| 221 |
</td> |
| 222 |
</tr> |
| 223 |
<?php if ( $args['friend']->can_refresh_feeds() ) : ?> |
| 224 |
<tr> |
| 225 |
<th><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Dashboard' ); ?></th> |
| 226 |
<td> |
| 227 |
<label for="show_on_dashboard"> |
| 228 |
<input type="checkbox" name="show_on_dashboard" id="show_on_dashboard" value="1" <?php checked( $args['show_on_dashboard'] ); ?> /> |
| 229 |
<?php esc_html_e( 'Show a widget for this friend on your wp-admin dashboard', 'friends' ); ?> |
| 230 |
</label> |
| 231 |
</td> |
| 232 |
</tr> |
| 233 |
<tr> |
| 234 |
<th><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Posts' ); ?></th> |
| 235 |
<td> |
| 236 |
<fieldset> |
| 237 |
<label for="show_on_friends_page"> |
| 238 |
<input name="show_on_friends_page" type="checkbox" id="show_on_friends_page" value="1" <?php checked( '1', ! in_array( $args['friend']->user_login, $args['hide_from_friends_page'] ) ); ?>> |
| 239 |
<?php esc_html_e( 'Show posts on your friends page', 'friends' ); ?> |
| 240 |
</label> |
| 241 |
</fieldset> |
| 242 |
<fieldset> |
| 243 |
<a href="<?php echo esc_url( $args['friend']->get_local_friends_page_url() ); ?>"> |
| 244 |
<?php |
| 245 |
// translators: %d is the number of posts. |
| 246 |
echo esc_html( sprintf( _n( 'View %d post', 'View %d posts', $args['post_count'], 'friends' ), $args['post_count'] ) ); |
| 247 |
?> |
| 248 |
</a> |
| 249 |
<?php if ( apply_filters( 'friends_debug', false ) ) : ?> |
| 250 |
| <a href="<?php echo esc_url( self_admin_url( 'edit.php?post_type=' . Friends\Friends::CPT . '&author=' . $args['friend']->ID ) ); ?>"> |
| 251 |
<?php |
| 252 |
// translators: %d is the number of posts. |
| 253 |
echo esc_html( sprintf( _n( 'View %d cached post', 'View %d cached posts', $args['post_count'], 'friends' ), $args['post_count'] ) ); |
| 254 |
?> |
| 255 |
</a> |
| 256 |
|
| 257 |
<?php endif; ?> |
| 258 |
</fieldset> |
| 259 |
</td> |
| 260 |
</tr> |
| 261 |
<tr> |
| 262 |
<th><?php esc_html_e( 'Retention', 'friends' ); ?></th> |
| 263 |
<td> |
| 264 |
<fieldset> |
| 265 |
<div> |
| 266 |
<input type="checkbox" name="friends_enable_retention_days" id="friends_enable_retention_days" value="1" <?php checked( '1', $args['friend']->is_retention_days_enabled() ); ?> /> |
| 267 |
<span id="friends_enable_retention_days_line" class="<?php echo esc_attr( $args['friend']->is_retention_days_enabled() ? '' : 'disabled' ); ?>"> |
| 268 |
<?php |
| 269 |
echo wp_kses( |
| 270 |
sprintf( |
| 271 |
// translators: %s is an input field that allows specifying a number. |
| 272 |
__( 'Only keep posts for %s days', 'friends' ), |
| 273 |
'<input type="number" min="1" id="friends_retention_days" name="friends_retention_days" value="' . esc_attr( $args['friend']->get_retention_days() ) . '"' . ( $args['friend']->is_retention_days_enabled() ? '' : ' disabled="disabled"' ) . ' size="3">' |
| 274 |
), |
| 275 |
array( |
| 276 |
'input' => array( |
| 277 |
'type' => array(), |
| 278 |
'min' => array(), |
| 279 |
'id' => array(), |
| 280 |
'name' => array(), |
| 281 |
'value' => array(), |
| 282 |
'size' => array(), |
| 283 |
'disabled' => array(), |
| 284 |
), |
| 285 |
) |
| 286 |
); |
| 287 |
echo '. '; |
| 288 |
echo esc_html( |
| 289 |
sprintf( |
| 290 |
// translators: %s is a date. |
| 291 |
__( 'Earliest post: %s', 'friends' ), |
| 292 |
/* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ date_i18n( __( 'F j, Y' ), $args['earliest_post_date'] ) |
| 293 |
) |
| 294 |
); |
| 295 |
if ( $args['global_retention_days_enabled'] ) { |
| 296 |
echo '. '; |
| 297 |
echo esc_html( |
| 298 |
sprintf( |
| 299 |
// translators: %s is a number of days. |
| 300 |
__( 'Global setting: %s days', 'friends' ), |
| 301 |
number_format_i18n( $args['global_retention_days'] ) |
| 302 |
) |
| 303 |
); |
| 304 |
} |
| 305 |
|
| 306 |
?> |
| 307 |
</span> |
| 308 |
</div> |
| 309 |
<div> |
| 310 |
<input type="checkbox" name="friends_enable_retention_number" id="friends_enable_retention_number" value="1" <?php checked( '1', $args['friend']->is_retention_number_enabled() ); ?> /> |
| 311 |
<span id="friends_enable_retention_number_line" class="<?php echo esc_attr( $args['friend']->is_retention_number_enabled() ? '' : 'disabled' ); ?>"> |
| 312 |
<?php |
| 313 |
echo wp_kses( |
| 314 |
sprintf( |
| 315 |
// translators: %s is an input field that allows specifying a number. |
| 316 |
__( 'Only keep the last %s posts', 'friends' ), |
| 317 |
'<input type="number" min="1" id="friends_retention_number" name="friends_retention_number" value="' . esc_attr( $args['friend']->get_retention_number() ) . '"' . ( $args['friend']->is_retention_number_enabled() ? '' : ' disabled="disabled"' ) . ' size="3">' |
| 318 |
), |
| 319 |
array( |
| 320 |
'input' => array( |
| 321 |
'type' => array(), |
| 322 |
'min' => array(), |
| 323 |
'id' => array(), |
| 324 |
'name' => array(), |
| 325 |
'value' => array(), |
| 326 |
'size' => array(), |
| 327 |
'disabled' => array(), |
| 328 |
), |
| 329 |
) |
| 330 |
); |
| 331 |
if ( $args['global_retention_number_enabled'] ) { |
| 332 |
echo '. '; |
| 333 |
echo esc_html( |
| 334 |
sprintf( |
| 335 |
// translators: %s is a number. |
| 336 |
__( 'Global setting: %s posts', 'friends' ), |
| 337 |
number_format_i18n( $args['global_retention_number'] ) |
| 338 |
) |
| 339 |
); |
| 340 |
} |
| 341 |
?> |
| 342 |
</span> |
| 343 |
</div> |
| 344 |
</fieldset> |
| 345 |
<p class="description"> |
| 346 |
<?php |
| 347 |
echo esc_html( |
| 348 |
sprintf( |
| 349 |
// translators: %s is a size in bytes or kilo bytes (kB). |
| 350 |
__( 'Currently the posts use %s of disk space.', 'friends' ), |
| 351 |
size_format( $args['total_size'], 1 ) |
| 352 |
) |
| 353 |
); |
| 354 |
?> |
| 355 |
</p> |
| 356 |
<p class="description"> |
| 357 |
<?php |
| 358 |
echo ' '; |
| 359 |
esc_html_e( 'If you need to limit the amount of space, choose one of the options above (they can be combined).', 'friends' ); |
| 360 |
echo ' '; |
| 361 |
esc_html_e( 'The next auto-delete will kick in when refreshing the feeds of this friend.', 'friends' ); |
| 362 |
?> |
| 363 |
</p> |
| 364 |
</p> |
| 365 |
<p class="description"> |
| 366 |
<?php |
| 367 |
esc_html_e( 'Lower global settings have preceedence over the friend settings.', 'friends' ); |
| 368 |
?> |
| 369 |
</p> |
| 370 |
</td> |
| 371 |
</tr> |
| 372 |
<?php endif; ?> |
| 373 |
<?php do_action( 'friends_edit_feeds_table_end', $args['friend'] ); ?> |
| 374 |
</table> |
| 375 |
<?php do_action( 'friends_edit_feeds_after_form', $args['friend'] ); ?> |
| 376 |
<p class="submit"> |
| 377 |
<input type="submit" id="submit" class="button button-primary" value="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Save Changes' ); ?>"> |
| 378 |
</p> |
| 379 |
</form> |
| 380 |
|