Example #1
0
 /**
  * Sets up and runs the functionality for getting the attachment meta.
  *
  * @since  2.0.0
  * @access public
  * @param  array   $args
  * @return void
  */
 public function __construct($args = array())
 {
     $defaults = array('post_id' => get_the_ID(), 'labels' => array(), 'echo' => true);
     $this->args = apply_filters('hybrid_media_meta_args', wp_parse_args($args, $defaults));
     /* Get the attachment metadata. */
     $this->meta = wp_get_attachment_metadata($this->args['post_id']);
     /* If the attachment is an image. */
     if (wp_attachment_is_image($this->args['post_id'])) {
         $this->image_meta();
     } elseif (hybrid_attachment_is_audio($this->args['post_id'])) {
         $this->audio_meta();
     } elseif (hybrid_attachment_is_video($this->args['post_id'])) {
         $this->video_meta();
     }
 }
Example #2
0
/**
 * Creates custom labels for ID3 tags that are used on the front end of the site when displaying 
 * media within the theme, typically on attachment pages.
 *
 * @since  2.0.0
 * @access public
 * @param  array   $fields
 * @param  object  $attachment
 * @param  string  $context
 * @return array
 */
function hybrid_attachment_id3_keys($fields, $attachment, $context)
{
    if ('display' === $context) {
        $fields['filesize'] = __('File Size', 'hybrid-core');
        $fields['mime_type'] = __('Mime Type', 'hybrid-core');
        $fields['length_formatted'] = __('Run Time', 'hybrid-core');
    }
    if (hybrid_attachment_is_audio($attachment->ID)) {
        $fields['genre'] = __('Genre', 'hybrid-core');
        $fields['year'] = __('Year', 'hybrid-core');
        $fields['composer'] = __('Composer', 'hybrid-core');
        $fields['track_number'] = __('Track', 'hybrid-core');
        if ('display' === $context) {
            $fields['unsynchronised_lyric'] = __('Lyrics', 'hybrid-core');
        }
    }
    return $fields;
}
Example #3
0
/**
 * Post <article> element attributes.
 *
 * @since  2.0.0
 * @access public
 * @param  array   $attr
 * @return array
 */
function hybrid_attr_post($attr)
{
    $post = get_post();
    /* Make sure we have a real post first. */
    if (!empty($post)) {
        $attr['id'] = 'post-' . get_the_ID();
        $attr['class'] = join(' ', get_post_class());
        $attr['itemscope'] = 'itemscope';
        if ('post' === get_post_type()) {
            $attr['itemtype'] = 'http://schema.org/BlogPosting';
            $attr['itemprop'] = 'blogPost';
        } elseif ('attachment' === get_post_type() && wp_attachment_is_image()) {
            $attr['itemtype'] = 'http://schema.org/ImageObject';
        } elseif ('attachment' === get_post_type() && hybrid_attachment_is_audio()) {
            $attr['itemtype'] = 'http://schema.org/AudioObject';
        } elseif ('attachment' === get_post_type() && hybrid_attachment_is_video()) {
            $attr['itemtype'] = 'http://schema.org/VideoObject';
        } else {
            $attr['itemtype'] = 'http://schema.org/CreativeWork';
        }
    } else {
        $attr['id'] = 'post-0';
        $attr['class'] = join(' ', get_post_class());
    }
    return $attr;
}
Example #4
0
/**
 * Post <article> element attributes.
 *
 * @since  2.0.0
 * @access public
 * @param  array   $attr
 * @return array
 */
function hybrid_attr_post($attr)
{
    $post = get_post();
    /* Make sure we have a real post first. */
    if (!empty($post)) {
        $attr['itemscope'] = 'itemscope';
        if ('post' === get_post_type()) {
            $attr['itemtype'] = 'http://schema.org/BlogPosting';
            // Add itemprop if within the main query
            if (is_main_query() && !is_search()) {
                $attr['itemprop'] = 'blogPost';
            }
        } elseif ('attachment' === get_post_type() && wp_attachment_is_image()) {
            $attr['itemtype'] = 'http://schema.org/ImageObject';
        } elseif ('attachment' === get_post_type() && hybrid_attachment_is_audio()) {
            $attr['itemtype'] = 'http://schema.org/AudioObject';
        } elseif ('attachment' === get_post_type() && hybrid_attachment_is_video()) {
            $attr['itemtype'] = 'http://schema.org/VideoObject';
        } else {
            $attr['itemtype'] = 'http://schema.org/CreativeWork';
        }
    }
    return $attr;
}
Example #5
0
/**
 * Adds a featured image (if one exists) next to the audio player.  Also adds a section below the player to
 * display the audio file information (toggled by custom JS).
 *
 * @since  1.0.0
 * @access public
 * @param  string  $html
 * @param  array   $atts
 * @param  object  $audio
 * @param  object  $post_id
 * @return string
 */
function stargazer_audio_shortcode($html, $atts, $audio, $post_id)
{
    // Don't show in the admin.
    if (is_admin()) {
        return $html;
    }
    // If we have an actual attachment to work with, use the ID.
    if (is_object($audio)) {
        $attachment_id = $audio->ID;
    } else {
        if ($post_id && hybrid_attachment_is_audio($post_id)) {
            $attachment_id = $post_id;
        } else {
            $extensions = join('|', wp_get_audio_extensions());
            preg_match('/(src|' . $extensions . ')=[\'"](.+?)[\'"]/i', preg_replace('/(\\?_=[0-9])/i', '', $html), $matches);
            if (!empty($matches)) {
                $dir = wp_upload_dir();
                $file = parse_url($matches[2]);
                if (isset($dir['baseurl']) && isset($file['path'])) {
                    $attachment_id = attachment_url_to_postid(trim(str_replace($dir['baseurl'], '', $file['path']), '/'));
                }
            }
        }
    }
    // If an attachment ID was found.
    if (!empty($attachment_id)) {
        // Get the attachment's featured image.
        $image = get_the_image(array('post_id' => $attachment_id, 'image_class' => 'audio-image', 'link_to_post' => is_attachment() ? false : true, 'echo' => false));
        // If there's no attachment featured image, see if there's one for the post.
        if (empty($image) && !empty($post_id)) {
            $image = get_the_image(array('image_class' => 'audio-image', 'link_to_post' => false, 'echo' => false));
        }
        // Add a wrapper for the audio element and image.
        if (!empty($image)) {
            $image = preg_replace(array('/width=[\'"].+?[\'"]/i', '/height=[\'"].+?[\'"]/i'), '', $image);
            $html = '<div class="audio-shortcode-wrap">' . $image . $html . '</div>';
        }
    }
    return $html;
}