Skip to content
This repository has been archived by the owner on Sep 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Single Publication Template
Include a single publication template that includes a main download link
and summary.
  • Loading branch information
ericmann committed Mar 19, 2013
1 parent 4ab5fdb commit 3fba815
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 33 deletions.
42 changes: 42 additions & 0 deletions includes/single-publication.php
@@ -0,0 +1,42 @@
<?php
/**
* The Template for displaying all single publications.
*
* @package WP Publication Archive
* @since 3.0
*/

get_header(); ?>

<div id="primary" class="site-content">
<div id="content" role="main">

<?php
while ( have_posts() ) : the_post(); $publication = new WP_Publication_Archive_Item( get_the_ID() ); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content">
<?php $publication->the_thumbnail(); ?>
<?php the_content(); ?>
<section class="publication-downloads">
<?php $publication->the_uri(); ?>
<?php $publication->list_downloads(); ?>
</section>
</div><!-- .entry-content -->

<footer class="entry-meta">
<?php edit_post_link( __( 'Edit Publication', 'wp_pubarch_translate' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->

<?php endwhile; // end of the loop. ?>

</div><!-- #content -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
39 changes: 36 additions & 3 deletions lib/class.publication-markup.php
Expand Up @@ -58,6 +58,18 @@ class WP_Publication_Archive_Item {
*/
public $uri;

/**
* @var string
*/
public $filename;

/**
* Alternate file downloads.
*
* @var array
*/
public $alternates = array();

/**
* @var bool|string
*/
Expand Down Expand Up @@ -110,6 +122,7 @@ public function __construct( $post ) {

$this->upload_image = get_post_meta( $this->ID, 'wpa-upload_image', true );
$this->uri = get_post_meta( $this->ID, 'wpa_upload_doc', true );
$this->filename = basename( $this->uri );

// Filter legacy URLs to strip out bad pipes
$this->uri = str_replace( 'http|', 'http://', $this->uri );
Expand Down Expand Up @@ -156,7 +169,9 @@ public function __construct( $post ) {
* @return string
*/
public function get_the_title( $before = '<div class="publication_title">', $after = '</div>' ) {
$title = apply_filters( 'wpa-title', $this->title, $this->ID );
$title = '<a href="' . get_permalink( $this->ID ) . '">';
$title .= apply_filters( 'wpa-title', $this->title, $this->ID );
$title .= '</a>';

return $before . $title . $after;
}
Expand Down Expand Up @@ -262,15 +277,15 @@ public function get_the_uri() {
return '';

$output = '<div class="publication_download">';
$output .= '<span class="title">' . __( 'Download:', 'wp_pubarch_translate' ) . ' </span>';
$output .= '<span class="title">' . $this->filename . ' </span>';
$output .= '<span class="description">';
$output .= '<img height="16" width="16" alt="download" src="' . WP_Publication_Archive::get_image( $mime->getType( $this->uri ) ) . '" /> ';
$output .= '<a ';
if ( apply_filters( 'wp_pubarch_open_in_blank', false ) ) {
$output .= 'target="_blank" ';
}
$output .= 'href="' . WP_Publication_Archive::get_open_link( $this->ID ) . '">';
$output .= __( 'Open', 'wp_pubarch_translate' ) . '</a> | ';
$output .= __( 'View', 'wp_pubarch_translate' ) . '</a> | ';
$output .= '<a href="' . WP_Publication_Archive::get_download_link( $this->ID ) . '">';
$output .= __( 'Download', 'wp_pubarch_translate' ) . '</a>';
$output .= '</span>';
Expand Down Expand Up @@ -377,4 +392,22 @@ public function get_the_categories() {
public function the_categories() {
echo $this->get_the_categories();
}

/**
* List out the downloads associated with this publication
*/
public function list_downloads() {
if ( count( $this->alternates ) == 0 ) {
return;
}

echo '<span class="title">' . __( 'Other Files:', 'wp_pubarch_translate' ) . ' </span>';
echo '<ul>';
foreach( $this->alternates as $alt ) {
echo '<li>';

echo '</li>';
}
echo '</ul>';
}
}
34 changes: 33 additions & 1 deletion lib/class.wp-publication-archive-utilities.php
Expand Up @@ -21,9 +21,10 @@ class WP_Publication_Archive_Utilities {
*/
protected function __construct() {
// Wireup actions
add_action( 'widgets_init', array( $this, 'register_widget' ) );
add_action( 'widgets_init', array( $this, 'register_widget' ) );

// Wireup filters
add_filter( 'template_include', array( $this, 'single_publication' ) );
}

/**
Expand Down Expand Up @@ -230,6 +231,37 @@ public function filter_terms_by_cpt( $pieces, $tax, $args ) {

return $pieces;
}

/***********************************************************/
/* Templates and Redirects */
/***********************************************************/

/**
* Override the template hierarchy to include our plugin's version if necessary.
*
* @param string $template
*
* @return string
*/
public function single_publication( $template ) {
if ( is_singular( 'publication' ) ) {
$template_name = apply_filters( 'wppa_single_template', 'single-publication.php' );

$paths = array(
get_stylesheet_directory() . '/' . $template_name,
get_template_directory() . '/' . $template_name,
WP_PUB_ARCH_DIR . 'includes/' . $template_name
);

foreach ( $paths as $path ) {
if ( file_exists( $path ) ) {
return $path;
}
}
}

return $template;
}
}

// Initialize the singleton
Expand Down
58 changes: 29 additions & 29 deletions lib/class.wp-publication-archive.php
Expand Up @@ -57,7 +57,7 @@ public static function upgrade( $from ) {
* @return string Download/Open link.
* @since 2.5
*/
protected static function get_link( $publication_id = 0, $endpoint = 'wppa_open', $permalink = false ) {
protected static function get_link( $publication_id = 0, $endpoint = 'view', $permalink = false ) {
if ( ! $permalink ) {
remove_filter( 'post_type_link', array( 'WP_Publication_Archive', 'publication_link' ) );
$permalink = get_permalink( $publication_id );
Expand All @@ -67,9 +67,9 @@ protected static function get_link( $publication_id = 0, $endpoint = 'wppa_open'
$structure = get_option( 'permalink_structure' );

if ( empty( $structure ) ) {
$new = add_query_arg( $endpoint, 1, $permalink );
$new = add_query_arg( $endpoint, 'yes', $permalink );
} else {
$new = trailingslashit( $permalink ) . $endpoint;
$new = site_url() . '/publication/' . $endpoint . '/' . basename( $permalink );
}

return $new;
Expand All @@ -84,7 +84,7 @@ protected static function get_link( $publication_id = 0, $endpoint = 'wppa_open'
* @since 2.5
*/
public static function get_open_link( $publication_id = 0 ) {
return WP_Publication_Archive::get_link( $publication_id, 'wppa_open' );
return WP_Publication_Archive::get_link( $publication_id, 'view' );
}

/**
Expand All @@ -96,7 +96,7 @@ public static function get_open_link( $publication_id = 0 ) {
* @since 2.5
*/
public static function get_download_link( $publication_id = 0 ) {
return WP_Publication_Archive::get_link( $publication_id, 'wppa_download' );
return WP_Publication_Archive::get_link( $publication_id, 'download' );
}

/**
Expand All @@ -115,10 +115,10 @@ public static function open_file() {
return;
}

$uri = get_post_meta( $wp_query->post->ID, 'wpa_upload_doc', true );
$publication = new WP_Publication_Archive_Item( $wp_query->post );

// Strip the old http| and https| if they're there
$uri = str_replace( 'http|', 'http://', $uri );
$uri = str_replace( 'http|', 'http://', $publication->uri );
$uri = str_replace( 'https|', 'https://', $uri );

$uri = apply_filters( 'wppa_download_url', $uri );
Expand Down Expand Up @@ -188,10 +188,10 @@ public static function download_file() {
return;
}

$uri = get_post_meta( $wp_query->post->ID, 'wpa_upload_doc', true );
$publication = new WP_Publication_Archive_Item( $wp_query->post );

// Strip the old http| and https| if they're there
$uri = str_replace( 'http|', 'http://', $uri );
$uri = str_replace( 'http|', 'http://', $publication->uri );
$uri = str_replace( 'https|', 'https://', $uri );

$uri = apply_filters( 'wppa_download_url', $uri );
Expand Down Expand Up @@ -225,7 +225,7 @@ public static function download_file() {

header( 'HTTP/1.1 200 OK' );
header( 'Expires: Wed, 9 Nov 1983 05:00:00 GMT' );
header( 'Content-Disposition: attachment; filename=' . basename( $uri ) );
header( 'Content-Disposition: attachment; filename=' . $publication->filename );
header( 'Content-type: ' . $content_type );
header( 'Content-Transfer-Encoding: binary' );

Expand Down Expand Up @@ -262,13 +262,13 @@ public static function get_image( $doctype ) {
switch ( $doctype ) {
case 'application/pdf':
case 'application/postscript':
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/pdf.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/pdf.png';
break;
case 'application/zip':
case 'application/x-stuffit':
case 'application/x-rar-compressed':
case 'application/x-tar':
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/zip.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/zip.png';
break;
case 'audio/basic':
case 'audio/mp4':
Expand All @@ -279,7 +279,7 @@ public static function get_image( $doctype ) {
case 'audio/x-ms-wax':
case 'audio/vnd.rn-realaudio':
case 'audio/vnd.wave':
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/audio.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/audio.png';
break;
case 'image/gif':
case 'image/jpeg':
Expand All @@ -289,7 +289,7 @@ public static function get_image( $doctype ) {
case 'image/vnd.microsoft.icon':
case 'application/vnd.oasis.opendocument.graphics':
case 'application/vnd.ms-excel':
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/image.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/image.png';
break;
case 'text/cmd':
case 'text/css':
Expand All @@ -300,23 +300,23 @@ public static function get_image( $doctype ) {
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
case 'application/msword':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/doc.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/doc.png';
break;
case 'text/csv':
case 'application/vnd.oasis.opendocument.spreadsheet':
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/data.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/data.png';
break;
case 'video/mpeg':
case 'video/mp4':
case 'video/ogg':
case 'video/quicktime':
case 'video/webm':
case 'video/x-ms-wmv':
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/video.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/video.png';
break;
default:
$image_url = WP_PUB_ARCH_IMG_URL . '/icons/unknown.png';
$image_url = WP_PUB_ARCH_URL . 'images' . '/icons/unknown.png';
}

return apply_filters( 'wppa_publication_icon', $image_url, $doctype );
Expand Down Expand Up @@ -417,6 +417,7 @@ public static function register_author() {
*/
public static function pub_meta_boxes() {
add_meta_box( 'publication_uri', __( 'Publication', 'wp_pubarch_translate' ), array( 'WP_Publication_Archive', 'doc_uri_box' ), 'publication', 'normal', 'high', '' );
add_meta_box( 'publication_thumb', __( 'Thumbnail', 'wp_pubarch_translate' ), array( 'WP_Publication_Archive', 'doc_thumb_box'), 'publication', 'normal', 'high', '' );
}

/**
Expand Down Expand Up @@ -447,7 +448,6 @@ public static function doc_uri_box() {
window.send_to_editor = window.orig_send_to_editor;
};

formfield = document.getElementById( 'wpa_upload_doc' ).getAttribute( 'name' );
window.tb_show( '<?php _e( 'Upload Publication', 'wp_pubarch_translate' ); ?>', 'media-upload.php?TB_iframe=1&width=640&height=263' );
return false;
};
Expand All @@ -466,12 +466,9 @@ public static function doc_thumb_box() {

$thumb = get_post_meta( $post->ID, 'wpa-upload_image', true );

_e( 'Enter an URL or upload an image for the thumb.', 'wp_pubarch_translate' );
echo '<br />';
echo '<br />';
echo '<label for="wpa-upload_image">';
echo '<input id="wpa-upload_image" type="text" size="36" name="wpa-upload_image" value=" ' . $thumb . '" />';
echo '<input id="wpa-upload_image_button" type="button" value="' . __( 'Upload Thumb', 'wp_pubarch_translate' ) . '" />';
echo '<p>' . __( 'Please provide the absolute url for a thumbnail image (including the <code>http://</code>):', 'wp_pubarch_translate' ) . '</p>';
echo '<input type="text" id="wpa-upload_image" name="wpa-upload_image" value=" ' . $thumb . '" size="36" size="25" style="width:85%" />';
echo '<input class="button" id="wpa-upload_image_button" type="button" value="' . __( 'Upload Thumbnail', 'wp_pubarch_translate' ) . '" alt="' . __( 'Upload Thumbnail', 'wp_pubarch_translate' ) . '" />';
?>
<script type="text/javascript">
( function( window, $, undefined ) {
Expand All @@ -480,16 +477,19 @@ public static function doc_thumb_box() {

window.orig_send_to_editor = window.send_to_editor;
window.send_to_editor = function( html ) {
var imgurl = jQuery('img',html).attr('src');
jQuery('#wpa-upload_image').val(imgurl);
tb_remove();
document.getElementById( 'wpa-upload_image' ).value = $( html ).attr( 'href' );

window.tb_remove();

// Restore original handler
window.send_to_editor = window.orig_send_to_editor;
};

$( '#wpa-upload_image_button' ).on( 'click', handle_thumb_upload );
window.tb_show( '<?php _e( 'Upload Thumbnail', 'wp_pubarch_translate' ); ?>', 'media-upload.php?TB_iframe=1&width=640&height=263' );
return false;
}

$( '#wpa-upload_image_button' ).on( 'click', handle_thumb_upload );
} )( this, jQuery );
</script>
<?php
Expand Down

0 comments on commit 3fba815

Please sign in to comment.