Skip to content

Commit f96f99e

Browse files
committed
Merge tag '1.8-beta2'
2 parents e524c45 + b44031b commit f96f99e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5868
-2269
lines changed

assets/app.css

Lines changed: 996 additions & 42 deletions
Large diffs are not rendered by default.

assets/app.js

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/theme.css

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
/**
1+
/* *
22
* Entries
33
*/
44

55
.liveblog-entry {
6+
display: flex;
7+
padding: 1rem;
68
background: #f7f7f7;
79
border-top: 2px solid #eee;
810
border-bottom: 2px solid #eee;
@@ -12,28 +14,29 @@
1214
border-top: 2px solid #111;
1315
}
1416

15-
.liveblog-entry-edit {
16-
margin-left: 60px;
17+
.liveblog-meta {
18+
color: #666;
1719
}
1820

19-
@media (max-width: 58.74em) {
20-
.liveblog-entry-edit {
21-
margin-left: 0;
22-
}
21+
.liveblog-entry-aside {
22+
flex-basis: 70px;
23+
min-width: 70px;
24+
margin-right: 10px;
2325
}
2426

25-
.liveblog-entry-content {
26-
padding-top: 10px;
27-
padding-left: 60px;
27+
.liveblog-entry-main {
28+
flex-grow: 1;
2829
}
2930

30-
.liveblog-meta {
31-
color: #666;
31+
.liveblog-entry-content * {
32+
word-break: break-all;
3233
}
3334

34-
.liveblog-meta-time {
35-
-ms-flex-preferred-size: 60px;
36-
flex-basis: 60px;
35+
.entry-content .liveblog-meta-time,
36+
.entry-content .liveblog-meta-time:hover,
37+
.entry-content .liveblog-meta-time:focus {
38+
-webkit-box-shadow: none;
39+
box-shadow: none;
3740
}
3841

3942
.liveblog-meta-time span {
@@ -44,32 +47,29 @@
4447
.liveblog-meta-time span:first-child {
4548
font-weight: 600;
4649
color: #333;
47-
padding-right: 5px;
4850
margin-bottom: 5px;
4951
}
5052

53+
.liveblog-meta-authors {
54+
margin-bottom: .5rem;
55+
}
56+
57+
.liveblog-meta-author {
58+
margin-right: 8px;
59+
}
60+
5161
.liveblog-meta-author-name {
5262
font-size: 13px;
5363
margin-left: 8px;
5464
}
5565

56-
.liveblog-meta-author-avatar {
66+
.liveblog-meta-authour-avatar {
5767
border-radius: 50%;
5868
overflow: hidden;
5969
width: 30px;
6070
height: 30px;
6171
}
6272

63-
.liveblog-entry-tools {
64-
margin-left: 60px;
65-
}
66-
67-
@media (max-width: 58.74em) {
68-
.liveblog-entry-tools {
69-
margin-left: 0;
70-
}
71-
}
72-
7373
.liveblog-hash {
7474
color: #21759b;
7575
}

classes/class-wpcom-liveblog-entry-extend-feature-authors.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public function filter( $entry ) {
122122
// Map the authors and store them on the object
123123
// for use in another function, we need
124124
// them to be lowercased.
125-
$this->authors = array_map( array( $this, 'map_authors' ), get_users( $args ) );
125+
$authors = apply_filters( 'liveblog_author_list', get_users( $args ), '' );
126+
$this->authors = array_map( array( $this, 'map_authors' ), $authors );
126127

127128
// Map over every match and apply it via the
128129
// preg_replace_callback method.
@@ -245,7 +246,8 @@ public function get_authors( $term ) {
245246
}
246247

247248
// Map the authors into the expected format.
248-
$users = array_map( array( $this, 'map_ajax_authors' ), get_users( $args ) );
249+
$authors = apply_filters( 'liveblog_author_list', get_users( $args ), $term );
250+
$users = array_map( array( $this, 'map_ajax_authors' ), $authors );
249251

250252
return $users;
251253
}

classes/class-wpcom-liveblog-entry.php

Lines changed: 149 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ class WPCOM_Liveblog_Entry {
1313
*/
1414
const replaces_meta_key = 'liveblog_replaces';
1515

16+
/**
17+
* @var string If author editing is enabled, we stored contributors
18+
* in this meta key.
19+
*/
20+
const contributors_meta_key = 'liveblog_contributors';
21+
22+
/**
23+
* @var string Whether or not an entry should show an author
24+
*/
25+
const hide_authors_key = 'liveblog_hide_authors';
26+
1627
private $comment;
1728
private $type = 'new';
1829
private static $allowed_tags_for_entry;
@@ -97,19 +108,20 @@ public function get_timestamp() {
97108

98109
public function for_json() {
99110
$entry_id = $this->replaces ? $this->replaces : $this->get_id();
100-
$avatar_size = apply_filters( 'liveblog_entry_avatar_size', self::default_avatar_size );
101111
$css_classes = implode( ' ', get_comment_class( '', $entry_id, $this->comment->comment_post_ID ) );
112+
$share_link = get_permalink( $this->get_post_id() ) . '#' . $entry_id;
113+
102114
$entry = array(
103115
'id' => $entry_id,
104-
'type' => $this->get_type(),
105-
'html' => $this->render(),
116+
'type' => $this->get_type(),
117+
'html' => $this->render(),
106118
'render' => self::render_content( $this->get_content(), $this->comment ),
107119
'content' => apply_filters( 'liveblog_before_edit_entry', $this->get_content() ),
108120
'css_classes' => $css_classes,
109121
'timestamp' => $this->get_timestamp(),
110-
'avatar_img' => get_avatar( $this->comment->comment_author_email, $avatar_size ),
111-
'author_link' => get_comment_author_link( $entry_id ),
122+
'authors' => self::get_authors( $entry_id ),
112123
'entry_time' => get_comment_date( 'U', $entry_id ),
124+
'share_link' => $share_link,
113125
);
114126
$entry = apply_filters( 'liveblog_entry_for_json', $entry, $this );
115127
return (object) $entry;
@@ -122,18 +134,18 @@ public function get_fields_for_render() {
122134
$comment_text = get_comment_text( $entry_id );
123135
$css_classes = implode( ' ', get_comment_class( '', $entry_id, $post_id ) );
124136
$entry = array(
125-
'entry_id' => $entry_id,
126-
'post_id' => $post_id,
127-
'css_classes' => $css_classes,
128-
'content' => self::render_content( $comment_text, $this->comment ),
129-
'original_content' => apply_filters( 'liveblog_before_edit_entry', $comment_text ),
130-
'avatar_size' => $avatar_size,
131-
'avatar_img' => get_avatar( $this->comment->comment_author_email, $avatar_size ),
132-
'author_link' => get_comment_author_link( $entry_id ),
133-
'entry_date' => get_comment_date( get_option( 'date_format' ), $entry_id ),
134-
'entry_time' => get_comment_date( get_option( 'time_format' ), $entry_id ),
135-
'timestamp' => $this->get_timestamp(),
136-
'is_liveblog_editable' => WPCOM_Liveblog::is_liveblog_editable(),
137+
'entry_id' => $entry_id,
138+
'post_id' => $post_id,
139+
'css_classes' => $css_classes ,
140+
'content' => self::render_content( $comment_text, $this->comment ),
141+
'original_content' => apply_filters( 'liveblog_before_edit_entry', $comment_text ),
142+
'avatar_size' => $avatar_size,
143+
'avatar_img' => WPCOM_Liveblog::get_avatar( $this->comment->comment_author_email, $avatar_size ),
144+
'author_link' => get_comment_author_link( $entry_id ),
145+
'entry_date' => get_comment_date( get_option('date_format'), $entry_id ),
146+
'entry_time' => get_comment_date( get_option('time_format'), $entry_id ),
147+
'timestamp' => $this->get_timestamp(),
148+
'is_liveblog_editable' => WPCOM_Liveblog::is_liveblog_editable(),
137149
'allowed_tags_for_entry' => self::$allowed_tags_for_entry,
138150
);
139151

@@ -339,6 +351,126 @@ public static function handle_restricted_shortcodes( $args ) {
339351
// Return the Original entry arguments with any modifications.
340352
return $args;
341353
}
354+
355+
/**
356+
* Return the user using author_id, if user not found then set as current
357+
* user as a fallback, we store a meta to show that authors are hidden as
358+
* a comment must have an author.
359+
*
360+
* If a entry_id is supplied we should update it as its the
361+
* original entry which is used for displaying author information.
362+
*
363+
*
364+
* @param array $args The new Live blog Entry.
365+
* @param int $entry_id If set we should update the original entry
366+
* @return mixed
367+
*/
368+
private static function handle_author_select( $args, $entry_id ) {
369+
if ( isset( $args['author_id'] ) && $args['author_id'] ) {
370+
$user_object = self::get_userdata_with_filter( $args['author_id'] );
371+
if ( $user_object ) {
372+
$args['user'] = $user_object;
373+
374+
wp_update_comment( array(
375+
'comment_ID' => $entry_id,
376+
'user_id' => $args['user']->ID,
377+
'comment_author' => $args['user']->display_name,
378+
'comment_author_email' => $args['user']->user_email,
379+
'comment_author_url' => $args['user']->user_url,
380+
) );
381+
382+
update_comment_meta( $entry_id, self::hide_authors_key, false );
383+
}
384+
} else {
385+
update_comment_meta( $entry_id, self::hide_authors_key, true );
386+
}
387+
388+
if ( isset( $args['contributor_ids'] ) ) {
389+
self::add_contributors( $entry_id, $args['contributor_ids'] );
390+
}
391+
392+
return $args['user'];
393+
}
394+
395+
/**
396+
* Store the contributors as comment meta.
397+
*
398+
* @param int $comment_id The comment id for the meta we should update.
399+
* @param array $contributors Array of ids to store as meta.
400+
*/
401+
private static function add_contributors( $comment_id, $contributors ) {
402+
if ( ! $contributors ) {
403+
delete_comment_meta( $comment_id, self::contributors_meta_key );
404+
}
405+
406+
if ( is_array( $contributors ) ) {
407+
if ( metadata_exists( 'comment', $comment_id, self::contributors_meta_key ) ) {
408+
update_comment_meta( $comment_id, self::contributors_meta_key, $contributors );
409+
return;
410+
}
411+
412+
add_comment_meta( $comment_id, self::contributors_meta_key, $contributors, true );
413+
}
414+
}
415+
416+
/**
417+
* Returns a list of contributor user objects.
418+
*
419+
* @param int $comment_id The comment id to retrive the metadata.
420+
*/
421+
private static function get_contributors_for_json( $comment_id ) {
422+
$contributors = get_comment_meta( $comment_id, self::contributors_meta_key, true );
423+
424+
if ( ! $contributors ) {
425+
return array();
426+
}
427+
428+
return array_map( function( $contributor ) {
429+
$user_object = self::get_userdata_with_filter( $contributor );
430+
return self::get_user_data_for_json( $user_object );
431+
}, $contributors );
432+
}
433+
434+
public static function get_userdata_with_filter( $author_id ) {
435+
return apply_filters( 'liveblog_userdata', get_userdata( $author_id ), $author_id );
436+
}
437+
438+
/**
439+
* Returns a formatted array of user data.
440+
*
441+
* @param object $user The user object
442+
*/
443+
private static function get_user_data_for_json( $user ) {
444+
if ( is_wp_error( $user ) ) {
445+
return array();
446+
}
447+
448+
$avatar_size = apply_filters( 'liveblog_entry_avatar_size', self::default_avatar_size );
449+
return array(
450+
'id' => $user->ID,
451+
'key' => strtolower($user->user_nicename),
452+
'name' => $user->display_name,
453+
'avatar' => WPCOM_Liveblog::get_avatar( $user->ID, $avatar_size ),
454+
);
455+
}
456+
457+
/**
458+
* Return an array of authors, based on the original comment author and its contributors.
459+
*
460+
* @param number $comment_id The id of the comment.
461+
*/
462+
public static function get_authors( $comment_id ) {
463+
$hide_authors = get_comment_meta( $comment_id, self::hide_authors_key, true );
464+
465+
if ( $hide_authors ) {
466+
return array();
467+
}
468+
469+
$author = [ self::get_user_data_for_json( self::user_object_from_comment_id( $comment_id ) ) ];
470+
$contributors = self::get_contributors_for_json( $comment_id );
471+
472+
return array_merge( $author, $contributors );
473+
}
342474
}
343475

344476
WPCOM_Liveblog_Entry::generate_allowed_tags_for_entry();

classes/class-wpcom-liveblog-rest-api.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,11 @@ public static function crud_entry( WP_REST_Request $request ) {
369369
$json = $request->get_json_params();
370370

371371
$args = array(
372-
'post_id' => self::get_json_param( 'post_id', $json ),
373-
'content' => self::get_json_param( 'content', $json ),
374-
'entry_id' => self::get_json_param( 'entry_id', $json ),
372+
'post_id' => self::get_json_param( 'post_id', $json ),
373+
'content' => self::get_json_param( 'content', $json ),
374+
'entry_id' => self::get_json_param( 'entry_id', $json ),
375+
'author_id' => self::get_json_param( 'author_id', $json ),
376+
'contributor_ids' => self::get_json_param( 'contributor_ids', $json ),
375377
);
376378

377379
self::set_liveblog_vars( $args['post_id'] );

0 commit comments

Comments
 (0)