Пример #1
0
/**
 * Provide a dropdown of major revisions of an article
 */
function annowf_get_clone_dropdown($post_id)
{
    $family_ids = annowf_clone_get_family($post_id);
    $markup = '';
    $inside = '';
    if (!empty($family_ids) && is_array($family_ids)) {
        // Only add this id if there are other revisions
        $family_ids[] = $post_id;
        // Only get articles that are published in the set of family ids
        $query = new WP_Query(array('post__in' => $family_ids, 'post_status' => 'publish', 'posts_per_page' => -1, 'post_type' => 'article'));
        if (!empty($query->posts)) {
            $i = count($query->posts);
            foreach ($query->posts as $post) {
                $inside .= '<option value="' . esc_attr(get_permalink($post->ID)) . '"' . selected($post->ID, $post_id, false) . '>' . esc_html(sprintf(_x('Edition %d - ', 'revision number', 'anno'), $i) . mysql2date(get_option('date_format'), $post->post_date)) . '</option>';
                $i--;
            }
        }
        wp_reset_query();
    }
    if (!empty($inside)) {
        $markup = '
	<select id="anno-revision-selector">
		<optgroup label="' . __('Revisions', 'anno') . '">
		' . $inside . '
		</optgroup>
	</select>
	<script type="text/javascript">
	/* <![CDATA[ */
		var dropdown = document.getElementById("anno-revision-selector");
		function annoOnRevisionChange() {
			if ( !!dropdown.options[dropdown.selectedIndex].value ) {
				location.href = dropdown.options[dropdown.selectedIndex].value;
			}
		}
		dropdown.onchange = annoOnRevisionChange;
	/* ]]> */
	</script>';
    }
    return $markup;
}
Пример #2
0
 /**
  * Text-only citation -- safe for textareas.
  * Output is cached for 1 hour unless cache is invalidated by updating the post.
  * @param int $post_id (optional) id of post to cite.
  */
 public function get_citation($post_id = null)
 {
     $post_id = $this->utils->post_id_for_sure($post_id);
     $cache_key = 'anno_citation_html_' . $post_id;
     /* Do we already have this cached? Let's return that. */
     $cache = get_transient($cache_key);
     if ($cache !== false && $this->enable_caches !== false) {
         return $cache;
     }
     /* Otherwise, let's build a cache and return it */
     $site = strip_tags(get_bloginfo('name'));
     $permalink = get_permalink();
     $post_date = get_the_date('Y M j');
     $last_modified = get_the_modified_date('Y M j');
     $title = get_the_title($post_id);
     $subtitle = $this->get_subtitle($post_id);
     if ($title && $subtitle) {
         $title = sprintf(_x('%1$s: %2$s', 'Title and subtitle as a textarea-safe string', 'anno'), $title, $subtitle);
     }
     $contributors = get_post_meta($post_id, '_anno_author_snapshot', true);
     $contributor_is_id = false;
     if (empty($contributors) || !is_array($contributors)) {
         $contributors = $this->get_author_ids($post_id);
         $contributor_is_id = true;
     }
     $names = array();
     foreach ($contributors as $contributor) {
         if ($contributor_is_id) {
             $contributor_wp_data = get_user_by('id', $contributor);
             $first = $contributor_wp_data->user_firstname;
             $last = $contributor_wp_data->user_lastname;
             $display_name = $contributor_wp_data->display_name;
         } else {
             $contributor_id = $contributor['id'];
             // Test for integer ID, thus we know its not a knol ID and we can attempt to look up a WP user for fallback
             if ($contributor_id == (string) intval($contributor_id)) {
                 $contributor_wp_data = get_user_by('id', $contributor_id);
             } else {
                 $contributor_wp_data = false;
             }
             $first = $contributor['given_names'];
             $last = $contributor['surname'];
             $display_name = empty($author_wp_data) ? '' : $contributor_wp_data->display_name;
         }
         if ($first && $last) {
             $first_formatted = '';
             $first_words = explode(' ', $first);
             foreach ($first_words as $word) {
                 if (is_string($word)) {
                     $first_formatted .= $word[0];
                 }
             }
             $name = sprintf(_x('%2$s %1$s', 'last name and first letter of firstname(s) as a textarea-safe string', 'anno'), $first_formatted, $last);
         } else {
             $name = $display_name;
         }
         if (!empty($name)) {
             $names[] = $name;
         }
     }
     $authors = implode(', ', $names);
     if (function_exists('annowf_clone_get_family')) {
         $family_ids = annowf_clone_get_family($post_id);
     } else {
         $family_ids = array();
     }
     $edition = 1;
     if (!empty($family_ids) && is_array($family_ids)) {
         // Only add this id if there are other revisions
         $family_ids[] = $post_id;
         // Only get articles that are published in the set of family ids
         $query = new WP_Query(array('post__in' => $family_ids, 'post_status' => 'publish', 'posts_per_page' => -1, 'post_type' => 'article', 'fields' => 'ids', 'cache' => false, 'order' => 'ASC'));
         if (!empty($query->posts)) {
             $i = 1;
             foreach ($query->posts as $query_post_id) {
                 if ($query_post_id == $post_id) {
                     $edition = $i;
                 }
                 $i++;
             }
         }
     }
     $doi = get_post_meta($post_id, '_anno_doi', true);
     $doi_str = '';
     if (!empty($doi)) {
         // Intentionally not i18n, doi is not translatable and inserted into another i18n
         $doi_str = 'doi: ' . $doi . '.';
     }
     $citation = sprintf(_x('%1$s. %2$s. %4$s. %5$s [last modified: %6$s]. Edition %3$s. %7$s', 'Citation format', 'anno'), $authors, $title, $edition, $site, $post_date, $last_modified, $doi_str);
     set_transient($cache_key, $citation, 60 * 60);
     // Cache for 1 hour.
     return $citation;
 }