/** * Which keys are allowed to managed in the snapshot data for manual editing, utilizes anno_user_meta * @return array Array using key => label format */ function anno_snapshot_allowed_keys() { global $anno_user_meta; $allowed_keys = array('id' => __('ID', 'anno'), 'bio' => __('Bio', 'anno'), 'surname' => __('Surname', 'anno'), 'given_names' => __('Given Names', 'anno')); $allowed_keys += anno_sanitize_user_meta_keys($anno_user_meta); return $allowed_keys; }
/** * Get the HTML list for authors. * @param int $post_id (optional) */ public function get_contributors_list($post_id = null) { $out = ''; $post_id = $this->utils->post_id_for_sure($post_id); global $anno_user_meta; $authors = get_post_meta($post_id, '_anno_author_snapshot', true); $author_is_id = false; if (empty($authors) || !is_array($authors)) { $authors = $this->get_author_ids($post_id); // Legacy data support $author_is_id = true; } $authors_data_arr = array(); foreach ($authors as $author) { $author_data = array('first_name' => '', 'last_name' => '', 'prefix' => '', 'suffix' => '', 'degrees' => '', 'institution' => '', 'bio' => ''); if ($author_is_id) { $author_id = $author; $author_wp_data = get_userdata($author_id); $author_data['first_name'] = $author_wp_data->user_firstname; $author_data['last_name'] = $author_wp_data->user_lastname; $author_data['link'] = $author_wp_data->user_url; $author_data['display_name'] = $author_wp_data->display_name; $author_data['link'] = $author_wp_data->user_url; $author_data['bio'] = $author_wp_data->user_description; // Load in additional Annotum User Meta if (is_array($anno_user_meta) && !empty($anno_user_meta)) { foreach ($anno_user_meta as $key => $label) { if (strpos($key, '_anno_') === 0) { $sanitized_key = substr($key, 6); } // Sanitized key for legacy data support $author_data[$sanitized_key] = get_user_meta($author_id, $key, true); } } } else { $author_id = $author['id']; if ($author_id == (string) intval($author_id)) { $author_wp_data = get_userdata($author_id); } else { $author_wp_data = false; } $author_data['first_name'] = isset($author['given_names']) ? $author['given_names'] : ''; $author_data['last_name'] = isset($author['surname']) ? $author['surname'] : ''; $author_data['bio'] = isset($author['bio']) ? $author['bio'] : ''; $author_data['link'] = isset($author['link']) ? $author['link'] : ''; // $author_data['email'] = $author['email']; // We may have an imported user here, in which case, they don't necessarily have a WP user ID and author_wp_data == false $author_data['display_name'] = empty($author_wp_data) ? '' : $author_wp_data->display_name; if (is_array($anno_user_meta) && !empty($anno_user_meta)) { $sanitized_key_meta = anno_sanitize_user_meta_keys($anno_user_meta); foreach ($sanitized_key_meta as $sanitized_key => $label) { if (!empty($author[$sanitized_key])) { $author_data[$sanitized_key] = $author[$sanitized_key]; } } } } $author_data['id'] = $author_id; // Use a user's website if there isn't a user object with associated id (imported user snapshots) // Also check to see if this is a string ID or int val id, knol_id vs wp_id if ($author_id == (string) intval($author_id)) { $posts_url = get_author_posts_url($author_id); $posts_url = $posts_url == home_url('/author/') ? $author_data['link'] : $posts_url; } else { $posts_url = ''; } $prefix_markup = empty($author_data['prefix']) ? '' : '<span class="name-prefix">' . esc_html($author_data['prefix']) . '</span> '; $suffix_markup = empty($author_data['suffix']) ? '' : ' <span class="name-suffix">' . esc_html($author_data['suffix']) . '</span>'; if ($author_data['first_name'] && $author_data['last_name']) { $fn = empty($posts_url) ? '<span class="name">' : '<a href="' . esc_url($posts_url) . '" class="url name">'; $fn .= $prefix_markup . '<span class="given-name">' . esc_html($author_data['first_name']) . '</span> <span class="family-name">' . esc_html($author_data['last_name']) . '</span>' . $suffix_markup; $fn .= empty($posts_url) ? '</span>' : '</a>'; } else { $fn = $posts_url ? '<a href="' . esc_url($posts_url) . '" class="url fn">' : '<span class="fn">'; $fn .= $prefix_markup . esc_html($author_data['display_name']) . $suffix_markup; $fn .= $posts_url ? '</a>' : '</span>'; } // Which (additional) user meta to display, and in what order, some fields are not filterable // Must match keys in $anno_user_meta global in order to properly pull the label $extra_meta_display = apply_filters('anno_user_meta_display', array('_anno_institution', '_anno_department', '_anno_state', '_anno_city', '_anno_country')); $extra = ''; foreach ($extra_meta_display as $key) { if (strpos($key, '_anno_') === 0) { $sanitized_key = substr($key, 6); } if (!empty($author_data[$sanitized_key])) { $label = isset($anno_user_meta[$key]) ? $anno_user_meta[$key] . ': ' : ucwords($sanitized_key) . ': '; $extra .= '<span class="' . esc_attr('group ' . $sanitized_key) . '">' . esc_html($label . $author_data[$sanitized_key]) . '</span>'; } } $extra = array(); if (!empty($author_data['department'])) { $extra[] = esc_html($author_data['department']); } if (!empty($author_data['institution'])) { $extra[] = esc_html($author_data['institution']); } if (!empty($author_data['city'])) { $extra[] = esc_html($author_data['city']); } if (!empty($author_data['state'])) { $extra[] = esc_html($author_data['state']); } if (!empty($author_data['country'])) { $extra[] = esc_html($author_data['country']); } $extra = implode(', ', $extra); $extra .= !empty($extra) ? '.' : ''; $card = ' <li> <div class="author vcard"> ' . $fn; if (!empty($extra)) { $card .= ' <span class="extra"> <span class="extra-in"> ' . $extra . ' </span> </span>'; } $card .= ' </div> </li>'; $out .= $card; $authors_data_arr[] = $author_data; } return apply_filters('anno_author_html', $out, $authors_data_arr); }