Advertisement
Guest User

Minimatica WordPress Theme 3.5 Compatibility Fixes

a guest
Dec 13th, 2012
6,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 25.30 KB | None | 0 0
  1. <?php
  2. /**
  3.  *
  4.  * THIS FIXES THE MINIMATICA WORDPRESS THEME 3.5 INCOMPATIBILITY ISSUES AND ALLOWS USE OF THE
  5.  * MEDIA UPLOADER!!!!!
  6.  *
  7.  * Minimatica functions and definitions
  8.  *
  9.  * Sets up the theme and provides custom functions to use as Template Tags
  10.  * The theme functions are pluggable, which means they can be overrided by Child Themes
  11.  * If you wish to modify code, do not modify the theme's code directly as it will be overwritten on updates
  12.  * Instead create a child theme and make the desired modifications there
  13.  * Read more about pluggable functions:
  14.  * http://codex.wordpress.org/Pluggable_Functions
  15.  * And Child Themes:
  16.  * http://codex.wordpress.org/Child_Themes
  17.  *
  18.  * @package WordPress
  19.  * @subpackage Minimatica
  20.  * @since Minimatica 1.0
  21.  */
  22.  
  23. /**
  24.  * Load custom widgets
  25.  */
  26. if ( is_readable( get_template_directory() . '/includes/widgets.php' ) )
  27.     require_once( get_template_directory() . '/includes/widgets.php' );
  28.  
  29. /**
  30.  * Load the theme options page if in admin mode
  31.  */
  32. if ( is_admin() && is_readable( get_template_directory() . '/includes/theme-options.php' ) )
  33.     require_once( get_template_directory() . '/includes/theme-options.php' );
  34.  
  35. if ( ! function_exists( 'minimatica_theme_setup' ) ) :
  36. /**
  37.  * Set up theme specific settings
  38.  *
  39.  * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  40.  * @uses register_nav_menus() To add support for navigation menus.
  41.  * @uses add_editor_style() To style the visual editor.
  42.  * @uses load_theme_textdomain() For translation/localization support.
  43.  * @uses add_image_size() To set custom image sizes.
  44.  *
  45.  * @since Minimatica 1.0
  46.  */
  47. function minimatica_theme_setup() {
  48.     // Set default content width based on the theme's layout. This affects the width of post images and embedded media.
  49.     global $content_width;
  50.     if( !isset( $content_width ) ) $content_width = 700;
  51.     // Automatically add feed links to document head
  52.     add_theme_support( 'automatic-feed-links' );
  53.     // Register Primary Navigation Menu
  54.     register_nav_menus(
  55.         array(
  56.           'primary_nav' => 'Primary Navigation',
  57.         )
  58.     );
  59.     // Add support for Post Formats
  60.     add_theme_support( 'post-formats', array( 'image', 'gallery', 'video', 'audio', 'aside', 'link' ) );
  61.     // Add support for post formats and custom image sizes specific to theme locations
  62.     add_theme_support( 'post-thumbnails', array( 'post' ) );
  63.     add_image_size( 'slider-thumb', 600, 400, 1 );
  64.     add_image_size( 'homepage-thumb', 688, 230, 1 );
  65.     add_image_size( 'gallery-thumb', 200, 200, 1 );
  66.     add_image_size( 'video-thumb', 700, 444, 1 );
  67.     add_image_size( 'single-thumb', 460, 348 );
  68.     add_image_size( 'attachment-thumb', 688, 9999 ); // no crop flag, unlimited height
  69.     // Allows users to set a custom background
  70. //  add_custom_background();
  71.     // Allows users to set a custom header image
  72.     if ( ! defined( 'HEADER_TEXTCOLOR' ) )
  73.         define( 'HEADER_TEXTCOLOR', '151515' );
  74.     // The height and width of your custom header.
  75.     if ( ! defined( 'HEADER_IMAGE_WIDTH' ) )
  76.         define( 'HEADER_IMAGE_WIDTH', 940 );
  77.     if ( ! defined( 'HEADER_IMAGE_HEIGHT' ) )
  78.         define( 'HEADER_IMAGE_HEIGHT', 100 );
  79.     // Add a way for the custom header to be styled in the admin panel
  80. //  add_custom_image_header( 'minimatica_header_style', 'minimatica_admin_header_style' );
  81.     // Styles the post editor
  82.     add_editor_style();
  83.     // Makes theme translation ready
  84.     load_theme_textdomain( 'minimatica', get_template_directory() . '/languages' );
  85.     $locale = get_locale();
  86.     $locale_file = get_template_directory() . "/languages/$locale.php";
  87.     if ( is_readable( $locale_file ) )
  88.         require_once( $locale_file );
  89. }
  90. endif;
  91.  
  92. add_action( 'after_setup_theme', 'minimatica_theme_setup' );
  93.  
  94. if ( ! function_exists( 'minimatica_widgets_init' ) ) :
  95. /**
  96.  * Registers theme widget areas
  97.  *
  98.  * @uses register_sidebar()
  99.  *
  100.  * @since Minimatica 1.0
  101.  */
  102. function  minimatica_widgets_init() {
  103.     register_sidebar(
  104.         array(
  105.             'name' => 'Sidebar',
  106.             'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  107.             'after_widget' => '</aside><!-- .widget -->',
  108.             'before_title' => '<h3 class="widget-title">',
  109.             'after_title' => '</h3>'
  110.         )
  111.     );
  112.     register_sidebar(
  113.         array(
  114.             'name' => 'Footer',
  115.             'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  116.             'after_widget' => '</aside><!-- .widget -->',
  117.             'before_title' => '<h3 class="widget-title">',
  118.             'after_title' => '</h3>'
  119.         )
  120.     );
  121. }
  122. endif;
  123.  
  124. add_action( 'widgets_init', 'minimatica_widgets_init' );
  125.  
  126. if ( ! function_exists( 'minimatica_paged_posts' ) ) :
  127. /**
  128.  * Overrides the default posts_per_page value when viewing in gallery mode
  129.  * This prevents the 404 flag from being triggered when using query_posts() with pagination
  130.  * It does not alter the database value for the option, only fiters it when the posts query is called
  131.  *
  132.  * @since Minimatica 1.0
  133.  */
  134. function minimatica_paged_posts( $query ) {
  135.     if( (
  136.         ( $query->is_home() && 'gallery' == minimatica_get_option( 'homepage_view' ) ) ||
  137.         ( $query->is_category() && 'gallery' == minimatica_get_option( 'category_view' ) ) ||
  138.         ( $query->is_tag() && 'gallery' == minimatica_get_option( 'tag_view' ) ) ||
  139.         ( $query->is_author() && 'gallery' == minimatica_get_option( 'author_view' ) ) ||
  140.         ( $query->is_archive() && 'gallery' == minimatica_get_option( 'archive_view' ) )
  141.         ) && ( ! is_single() )
  142.     )
  143.         $query->set( 'posts_per_page', '4' );
  144. }
  145. endif;
  146.  
  147. add_filter( 'pre_get_posts', 'minimatica_paged_posts' );
  148.  
  149. /**
  150.  * Return default array of options
  151.  *
  152.  * @since Minimatica 1.0
  153.  */
  154. function minimatica_default_options() {
  155.     $options = array(
  156.         'homepage_view' => 'gallery',
  157.         'category_view' => 'gallery',
  158.         'tag_view' => 'blog',
  159.         'author_view' => 'blog',
  160.         'archive_view' => 'blog',
  161.         'blog_category' => 0
  162.     );
  163.     return $options;
  164. }
  165.  
  166. if ( ! function_exists( 'minimatica_get_option' ) ) :
  167. /**
  168.  * Used to output theme options is an elegant way
  169.  *
  170.  * @uses get_option() To retrieve the options array
  171.  *
  172.  * @since Minimatica 1.0
  173.  */
  174. function minimatica_get_option( $option ) {
  175.     $options = get_option( 'minimatica_options', minimatica_default_options() );
  176.     return $options[ $option ];
  177. }
  178. endif;
  179.  
  180. if ( ! function_exists( 'minimatica_doc_title' ) ) :
  181. /**
  182.  * Output the <title> tag
  183.  *
  184.  * @since Minimatica 1.0
  185.  */
  186. function minimatica_doc_title() {
  187.     global $page, $paged;
  188.     $doc_title = '';
  189.     $site_description = get_bloginfo( 'description', 'display' );
  190.     $separator = '#124';
  191.     if ( !is_front_page() ) :
  192.         $doc_title .= wp_title('', false);
  193.         if ( $paged >= 2 || $page >= 2 )
  194.             $doc_title .=  ', ' . __( 'Page' ) . ' ' . max( $paged, $page );
  195.         if ( is_archive() )
  196.             $doc_title .=  ' &' . $separator . '; ';
  197.         elseif ( is_singular() )
  198.             $doc_title .=  ' &' . $separator . '; ';
  199.     endif;
  200.     if ( is_archive() )
  201.         $doc_title .= get_bloginfo( 'name' );
  202.     elseif ( is_singular() )
  203.         $doc_title .= get_bloginfo( 'name' );
  204.     elseif ( is_front_page() )
  205.         $doc_title .= get_bloginfo( 'name' );
  206.     if ( is_front_page() && ( $paged >= 2 || $page >= 2 ) )
  207.         $doc_title .=  ', ' . __( 'Page' ) . ' ' . max( $paged, $page );
  208.     if ( $site_description && ( is_home() || is_front_page() ) )
  209.         $doc_title .= ' &' . $separator . '; ' . $site_description;
  210.     echo $doc_title;
  211. }
  212. endif;
  213.  
  214. if ( ! function_exists( 'minimatica_register_styles' ) ) :
  215. /**
  216.  * Register theme styles
  217.  *
  218.  * @uses wp_register_style() To register styles
  219.  *
  220.  * @since Minimatica 1.0.1
  221.  */
  222. function minimatica_register_styles() {
  223.     wp_register_style( 'minimatica', get_bloginfo( 'stylesheet_url' ), false, '1.0.1' );
  224.     wp_register_style( 'colorbox', get_template_directory_uri() . '/styles/colorbox.css', false, '0.5' );
  225.     wp_register_style( 'minimatica-ie', get_template_directory_uri() . '/styles/ie.css', false, '1.0' );
  226. }
  227. endif;
  228.  
  229. add_action('wp_enqueue_scripts', 'minimatica_register_styles');
  230.  
  231. if ( ! function_exists( 'minimatica_enqueue_styles' ) ) :
  232. /**
  233.  * Enqueue theme styles
  234.  *
  235.  * @uses wp_enqueue_style() To enqueue styles
  236.  *
  237.  * @since Minimatica 1.0
  238.  */
  239. function minimatica_enqueue_styles() {
  240.     wp_enqueue_style( 'minimatica' );
  241.     if( is_single() )
  242.         wp_enqueue_style( 'colorbox' );
  243.     wp_enqueue_style( 'minimatica-ie' );
  244.     // Add IE conditionals
  245.     global $wp_styles;
  246.     $wp_styles->add_data( 'minimatica-ie', 'conditional', 'lte IE 8' );
  247. }
  248. endif;
  249.  
  250. add_action('wp_print_styles', 'minimatica_enqueue_styles');
  251.  
  252. if ( ! function_exists( 'minimatica_register_scripts' ) ) :
  253. /**
  254.  * Register theme scripts
  255.  *
  256.  * @uses wp_register_scripts() To register scripts
  257.  *
  258.  * @since Minimatica 1.0.1
  259.  */
  260. function minimatica_register_scripts() {
  261.     // Add HTML5 support to older versions of IE
  262.     wp_register_script( 'html5', get_template_directory_uri() . '/scripts/html5.js', false, '1.5.1' );
  263.     wp_register_script( 'audio-player', get_template_directory_uri() . '/scripts/audio-player.js', array( 'swfobject' ), '2.2' );
  264.     wp_register_script( 'kwicks', get_template_directory_uri() . '/scripts/kwicks.js', array( 'jquery' ), '1.5.1' );
  265.     wp_register_script( 'colorbox', get_template_directory_uri() . '/scripts/colorbox.js', array( 'jquery' ), '1.3.16' );
  266.     wp_register_script( 'minimatica', get_template_directory_uri() . '/scripts/minimatica.js', array( 'kwicks' ), '1.0' );
  267. }
  268. endif;
  269.  
  270. add_action( 'wp_enqueue_scripts', 'minimatica_register_scripts' );
  271.  
  272. if ( ! function_exists( 'minimatica_enqueue_scripts' ) ) :
  273. /**
  274.  * Enqueue theme scripts
  275.  *
  276.  * @uses wp_enqueue_scripts() To enqueue scripts
  277.  *
  278.  * @since Minimatica 1.0
  279.  */
  280. function minimatica_enqueue_scripts() {
  281.     // Add HTML5 support to older versions of IE
  282.     if( isset( $_SERVER['HTTP_USER_AGENT'] ) &&
  283.         ( false !== strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) ) &&
  284.         ( false === strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) ) )
  285.         wp_enqueue_script( 'html5' );
  286.     wp_enqueue_script( 'kwicks' );
  287.     if ( is_singular() && get_option( 'thread_comments' ) )
  288.         wp_enqueue_script( 'comment-reply' );
  289.     if ( is_single() && has_post_format( 'video' ) )
  290.         wp_enqueue_script( 'swfobject' );
  291.     if ( is_single() && has_post_format( 'audio' ) )
  292.         wp_enqueue_script( 'audio-player' );
  293.     if ( is_single() )
  294.         wp_enqueue_script( 'colorbox' );
  295.     wp_enqueue_script( 'minimatica' );
  296. }
  297. endif;
  298.  
  299. add_action( 'wp_enqueue_scripts', 'minimatica_enqueue_scripts' );
  300.  
  301. if ( ! function_exists( 'minimatica_call_scripts' ) ) :
  302. /**
  303.  * Call script functions in document head
  304.  *
  305.  * @since Minimatica 1.0
  306.  */
  307. function minimatica_call_scripts() { ?>
  308. <script type="text/javascript">
  309. /* <![CDATA[ */
  310.     jQuery().ready(function() {
  311.         jQuery('#nav-slider a').live('click', function(e){
  312.             e.preventDefault();
  313.             var link = jQuery(this).attr('href');
  314.             jQuery('#slider').html('<img src="<?php echo get_template_directory_uri(); ?>/images/loader.gif" style="display:block; margin:173px auto" />');
  315.             jQuery('#slider').load(link+' #ajax-content', function(){
  316.                 slide();
  317.             });
  318.         });
  319.         <?php if( is_single() ) : ?>
  320.         jQuery('a.colorbox').colorbox({
  321.             maxWidth:900,
  322.             maxHeight:600
  323.         });
  324.         <?php endif; ?>
  325.     });
  326.     <?php if ( is_single() && has_post_format( 'audio' ) ) : ?>
  327.     AudioPlayer.setup("<?php echo get_template_directory_uri(); ?>/audio-player/player.swf", {  
  328.         width: 290  
  329.     });
  330.     <?php endif; ?>
  331. /* ]]> */
  332. </script>
  333. <?php
  334. }
  335. endif;
  336.  
  337. add_action( 'wp_head', 'minimatica_call_scripts' );
  338.  
  339. if ( ! function_exists( 'minimatica_header_style' ) ) :
  340. /**
  341.  * Styles the header image displayed on the Appearance > Header admin panel.
  342.  *
  343.  * @since Minimatica 1.0.7
  344.  */
  345. function minimatica_header_style() {
  346.     if( '' != get_header_image() ) : ?>
  347. <style type="text/css">
  348. #site-title {
  349.     width:<?php echo HEADER_IMAGE_WIDTH; ?>px;
  350.     height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;
  351.     background-image:url(<?php header_image(); ?>);
  352. }
  353. #site-title a {
  354. <?php if ( 'blank' == get_header_textcolor() ) : ?>
  355.     display:none;
  356. <?php else : ?>
  357.     color:#<?php header_textcolor(); ?>;
  358. <?php endif; ?>
  359. }
  360. </style>
  361. <?php endif;
  362. }
  363. endif;
  364.  
  365. if ( ! function_exists( 'minimatica_admin_header_style' ) ) :
  366. /**
  367.  * Shows the header image in the admin panel.
  368.  *
  369.  * @since Minimatica 1.0.7
  370.  */
  371. function minimatica_admin_header_style() { ?>
  372. <style type="text/css">
  373. #headimg {
  374.     background-image:url(<?php header_image(); ?>);
  375. }
  376. <?php if ( 'blank' != get_header_textcolor() ) : ?>
  377. #headimg h1 a {
  378.     color:#<?php header_textcolor(); ?>;
  379.     font-weight:normal;
  380.     line-height:60px;
  381.     text-decoration:none;
  382. }
  383. <?php endif; ?>
  384. #headimg #desc {
  385.     display:none;
  386. }
  387. </style>
  388. <?php
  389. }
  390. endif;
  391.  
  392. if ( ! function_exists( 'minimatica_nav_menu' ) ) :
  393. /**
  394.  * Fallback menu if no custom menu is declared
  395.  *
  396.  * Falls back to a list of categories and displays a link to home
  397.  *
  398.  * @uses wp_list_categories() To list categories as menu items
  399.  *
  400.  * @since Minimatica 1.0
  401.  */
  402. function minimatica_nav_menu() { ?>
  403.     <div id="primary-nav" class="nav">
  404.         <ul>
  405.             <li><a href="<?php echo home_url(); ?>" rel="home"><?php _e( 'Home', 'minimatica' ); ?></a></li>
  406.             <?php wp_list_categories( 'title_li=' ); ?>
  407.         </ul>
  408.     </div><!-- #primary-nav -->
  409.     <?php
  410. }
  411. endif;
  412.  
  413. if ( ! function_exists( 'minimatica_excerpt_more' ) ) :
  414. /**
  415.  * Changes the default excerpt trailing content
  416.  *
  417.  * Replaces the default [...] trailing text from excerpts
  418.  * to a more pleasant ...
  419.  *
  420.  * @since Minimatica 1.0
  421.  */
  422. function minimatica_excerpt_more($more) {
  423.     return ' &#8230;';
  424. }
  425. endif;
  426.  
  427. add_filter( 'excerpt_more', 'minimatica_excerpt_more' );
  428.  
  429. if ( ! function_exists( 'minimatica_file_types' ) ) :
  430. /**
  431.  * Allows uploading of .webm video files
  432.  *
  433.  * @since Minimatica 1.0
  434.  */
  435. function minimatica_file_types( $types ) {
  436.     $types['video'][] = 'webm';
  437.     return $types;
  438. }
  439. endif;
  440.  
  441. //add_filter( 'ext2type', 'minimatica_mime_types' );
  442.  
  443. if ( ! function_exists( 'minimatica_mime_types' ) ) :
  444. /**
  445.  * Registers the webm mime type
  446.  *
  447.  * @since Minimatica 1.0
  448.  */
  449. function minimatica_mime_types( $types ) {
  450.     $types['webm'] = 'video/webm';
  451.     return $types;
  452. }
  453. endif;
  454.  
  455. //add_filter( 'upload_mimes', 'minimatica_mime_types' );
  456.  
  457. if ( ! function_exists( 'minimatica_post_image' ) ) :
  458. /**
  459.  * Show the last image attached to the current post
  460.  *
  461.  * Used in image post formats
  462.  * Images attached to image posts should not appear in the post's content
  463.  * to avoid duplicate display of the same content
  464.  *
  465.  * @uses get_posts() To retrieve attached image
  466.  *
  467.  * @since Minimatica 1.0
  468.  */
  469. function minimatica_post_image() {
  470.     if( has_post_thumbnail() ) :
  471.     // If post has a thumbnail, show it as the post's image ?>
  472.         <a class="colorbox" href="<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); echo $image[0] ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
  473.             <?php the_post_thumbnail( 'attachment-thumb' ); ?>
  474.         </a>
  475.     <?php else :
  476.         // Retrieve the last image attached to the post
  477.         $args = array(
  478.             'numberposts' => 1,
  479.             'post_type' => 'attachment',
  480.             'post_mime_type' => 'image',
  481.             'post_parent' => get_the_ID()
  482.         );
  483.         $attachments = get_posts( $args );
  484.         if( count( $attachments ) )
  485.             $attachment = $attachments[0];
  486.         if( isset( $attachment ) && ! post_password_required() ) : ?>
  487.             <figure class="entry-attachment">
  488.                 <a class="colorbox" href="<?php $image = wp_get_attachment_image_src( $attachment->ID, 'full' ); echo $image[0]; ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
  489.                 <?php echo wp_get_attachment_image( $attachment->ID, 'attachment-thumb' ); ?>
  490.                 </a>
  491.                 <?php if ( !empty( $attachment->post_excerpt ) ) : ?>
  492.                     <figcaption class="entry-caption">
  493.                         <?php echo apply_filters( 'the_excerpt', $attachment->post_excerpt ); ?>
  494.                     </figcaption><!-- .entry-caption -->
  495.                 <?php endif; ?>
  496.             </figure><!-- .entry-attachment -->
  497.         <?php endif;
  498.     endif;
  499. }
  500. endif;
  501.  
  502. if ( ! function_exists( 'minimatica_post_gallery' ) ) :
  503. /**
  504.  * Show a gallery of images attached to the current post
  505.  *
  506.  * Used in gallery post formats
  507.  * Galery post formats shou;d not use the [gallery] shortcode
  508.  * to avoid duplicate display of the same content
  509.  * to avoid duplicate of the same content
  510.  *
  511.  * @uses get_posts() To retrieve attached images
  512.  *
  513.  * @since Minimatica 1.0
  514.  */
  515. function minimatica_post_gallery() {
  516.     // Retrieve images attached to post
  517.     $args = array(
  518.         'numberposts' => -1,
  519.         'post_type' => 'attachment',
  520.         'post_mime_type' => 'image',
  521.         'post_parent' => get_the_ID()
  522.     );
  523.     $attachments = get_posts( $args );
  524.     // Reverse array to display them in chronological form instead of reverse chronological
  525.     $attachments = array_reverse( $attachments );
  526.     if( count( $attachments ) && ! post_password_required() ) : ?>
  527.         <?php $counter = 0; ?>
  528.         <div class="gallery post-gallery gallery-columns-3">
  529.             <div class="gallery-row">
  530.                 <?php foreach( $attachments as $attachment ) : ?>
  531.                     <?php $counter++;
  532.                     // Show gallery in 3 rows ?>
  533.                     <figure class='gallery-item'>
  534.                         <a class="colorbox" href="<?php $image = wp_get_attachment_image_src( $attachment->ID, 'full' ); echo $image[0]; ?>" title="<?php echo esc_attr( get_the_title( $attachment->ID ) ); ?>" rel="attachment">
  535.                             <?php echo wp_get_attachment_image( $attachment->ID, 'gallery-thumb' ); ?>
  536.                         </a>
  537.                         <?php if ( !empty( $attachment->post_excerpt ) ) : ?>
  538.                             <figcaption class='wp-caption-text gallery-caption'>
  539.                                 <?php echo apply_filters( 'the_excerpt', $attachment->post_excerpt ); ?>
  540.                             </figcaption><!-- .gallery-caption -->
  541.                         <?php endif; ?>
  542.                     </figure><!-- .gallery-item -->
  543.                     <?php if( !( $counter % 3 ) && ( $attachment != end( $attachments ) ) ) :
  544.                         // If 3 images have been shown, end the image row and open a new one ?>
  545.                             <div class="clear"></div>
  546.                         </div><!-- .gallery-row -->
  547.                         <div class="gallery-row">
  548.                     <?php endif; ?>
  549.                 <?php endforeach; ?>
  550.                 <div class="clear"></div>
  551.             </div><!-- .gallery-row -->
  552.         </div><!-- .post-gallery -->
  553.     <?php endif;
  554. }
  555. endif;
  556.  
  557. if ( ! function_exists( 'minimatica_post_video' ) ) :
  558. /**
  559.  * Video playback support for post with the video format
  560.  *
  561.  * Displays the attached video in a HTML5 <video> tag with flash fallback
  562.  * If more then one attached video is found, they are used as fallback to the first one
  563.  * Should work in most if not all browsers :)
  564.  *
  565.  * @uses get_posts() To retrieve attached videos
  566.  *
  567.  * @since Minimatica 1.0
  568.  */
  569. function minimatica_post_video() {
  570.     // Get attached videos
  571.     $args = array(
  572.         'numberposts' => -1,
  573.         'post_type' => 'attachment',
  574.         'post_mime_type' => 'video',
  575.         'post_parent' => get_the_ID()
  576.     );
  577.     $attachments = get_posts( $args );
  578.     // Reverse array to display them in chronological form instead of reverse chronological
  579.     $attachments = array_reverse( $attachments );
  580.     if( count( $attachments ) ) :
  581.         // Detect flash video format to use it as fallback
  582.         $mime_types = array();
  583.         foreach( $attachments as $attachment ) :
  584.             if( $attachment->post_mime_type == 'video/x-flv' )
  585.                 $flash_video = $attachment;
  586.         endforeach;
  587.     endif;
  588.     if( count( $attachments ) && ! post_password_required() ) : ?>
  589.         <div class="entry-attachment">
  590.             <video controls width="700" height="444" poster="<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'video-thumb' ); echo $image[0]; // Use post thumbnail as video poster ?>" id="video-player">
  591.                 <?php foreach( $attachments as $attachment ) :
  592.                     // Show each video file as a fallback source ?>
  593.                     <source src="<?php echo wp_get_attachment_url( $attachment->ID ); ?>" type='<?php echo $attachment->post_mime_type; if( $attachment->post_mime_type == 'video/mp4' ) echo '; codecs="avc1.42E01E, mp4a.40.2"'; elseif( $attachment->post_mime_type == 'video/webm' ) echo '; codecs="vp8, vorbis"'; elseif( $attachment->post_mime_type == 'video/ogg' ) echo '; codecs="theora, vorbis"'; ?>'>
  594.                 <?php endforeach; ?>
  595.             </video>
  596.             <?php if( isset( $flash_video ) ) :
  597.                 // Display flash fallback ?>
  598.                 <?php if( count( $attachments ) ) : ?>
  599.                 <div id="player"></div>
  600.                 <script type="text/javascript">
  601.                 /* <![CDATA[ */
  602.                     var videoTag = document.createElement('video');
  603.                     if( !( !!( videoTag.canPlayType ) && ( <?php foreach( $attachments as $attachment ) : ?>( ( "no" != videoTag.canPlayType( "<?php echo $attachment->post_mime_type; ?>" ) ) && ( "" != videoTag.canPlayType( "<?php echo $attachment->post_mime_type; ?>" ) ) )<?php if( $attachment != end( $attachments ) ) : ?> || <?php endif; ?><?php endforeach; ?> ) ) ) {
  604.                         document.getElementById("video-player").style.display="none";
  605.                         var flashvars = {
  606.                             skin: "<?php echo get_template_directory_uri(); ?>/video-player/skin.swf",
  607.                             video: "<?php echo wp_get_attachment_url( $flash_video->ID ); ?>",
  608.                             thumbnail: "<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'video-thumb' ); echo $image[0] ?>"
  609.                         };
  610.                         var params = {
  611.                             quality: "high",
  612.                             menu: "false",
  613.                             allowFullScreen: "true",
  614.                             scale: "noscale",
  615.                             allowScriptAccess: "always",
  616.                             swLiveConnect: "true"
  617.                         };
  618.                         var attributes = {
  619.                             id: "f4-player"
  620.                         };
  621.                         swfobject.embedSWF("<?php echo get_template_directory_uri(); ?>/video-player/player.swf", "player", "700", "444", "9.0.0","expressInstall.swf", flashvars, params, attributes);
  622.                     } else {
  623.                         document.getElementById("player").style.display="none";
  624.                     }
  625.                 /* ]]> */
  626.                 </script>
  627.                 <?php endif; ?>
  628.             <?php endif; ?>
  629.         </div><!-- .entry-attachment -->
  630.     <?php endif;
  631. }
  632. endif;
  633.  
  634. if ( ! function_exists( 'minimatica_post_audio' ) ) :
  635. /**
  636.  * Audio playback support for post with the audio format
  637.  *
  638.  * Displays the attached audio files in a HTML5 <audio> tag with flash fallback
  639.  * If more then one attached audio file is found, they are used as fallback to the first one
  640.  * Should work in most if not all browsers :)
  641.  *
  642.  * @uses get_posts() To retrieve attached audio files
  643.  *
  644.  * @since Minimatica 1.0
  645.  */
  646. function minimatica_post_audio() {
  647.     // Get attached audio files
  648.     $args = array(
  649.         'numberposts' => -1,
  650.         'post_type' => 'attachment',
  651.         'post_mime_type' => 'audio',
  652.         'post_parent' => get_the_ID()
  653.     );
  654.     $attachments = get_posts( $args );
  655.     // Reverse array to display them in chronological form instead of reverse chronological
  656.     $attachments = array_reverse( $attachments );
  657.     if( count( $attachments ) ) :
  658.         // Detect MP3 file to use it as flash fallback
  659.         $mime_types = array();
  660.         foreach( $attachments as $attachment ) :
  661.             if( $attachment->post_mime_type == 'audio/mpeg' )
  662.                 $flash_audio = $attachment;
  663.         endforeach;
  664.     endif;
  665.     if( count( $attachments ) && ! post_password_required() ) : ?>
  666.         <div class="entry-attachment">
  667.             <audio controls id="player">
  668.                 <?php foreach( $attachments as $attachment ) : ?>
  669.                     <source src="<?php echo wp_get_attachment_url( $attachment->ID ); ?>">
  670.                 <?php endforeach; ?>
  671.             </audio>
  672.             <?php if( isset( $flash_audio ) ) :
  673.                 // Display flash fallback ?>
  674.                 <div id="audioplayer"></div>
  675.                 <script type="text/javascript">
  676.                     var audioTag = document.createElement('audio');
  677.                         if( !( !!( audioTag.canPlayType ) && ( <?php foreach( $attachments as $attachment ) : ?>( ( "no" != audioTag.canPlayType( "<?php echo $attachment->post_mime_type; ?>" ) ) && ( "" != audioTag.canPlayType( "<?php echo $attachment->post_mime_type; ?>" ) ) )<?php if( $attachment != end( $attachments ) ) : ?> || <?php endif; ?><?php endforeach; ?> ) ) ) {
  678.                         document.getElementById("player").style.display="none";
  679.                         AudioPlayer.embed("audioplayer", {soundFile: "<?php echo wp_get_attachment_url( $flash_audio->ID ); ?>"});
  680.                     }
  681.                 </script>
  682.             <?php endif; ?>
  683.         </div><!-- .entry-attachment -->
  684.     <?php endif;
  685. }
  686. endif;
  687.  
  688. if ( ! function_exists( 'minimatica_comment' ) ) :
  689. /**
  690.  * Template for comments and pingbacks.
  691.  *
  692.  * Used as a callback by wp_list_comments() for displaying the comments.
  693.  *
  694.  * @since Minimatica 1.0
  695.  */
  696. function minimatica_comment( $comment, $args, $depth ) {
  697.     $GLOBALS['comment'] = $comment;
  698.     switch ( $comment->comment_type ) :
  699.         case '' :
  700.     ?>
  701. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  702.     <article id="comment-<?php comment_ID(); ?>" class="comment-body">
  703.         <header class="comment-header">
  704.             <div class="comment-author vcard">
  705.                 <?php echo get_avatar( $comment, 64 ); ?>
  706.                 <?php printf( __( '%s <span class="says">says:</span>', 'minimatica' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  707.             </div><!-- .comment-author .vcard -->
  708.             <?php if ( $comment->comment_approved == '0' ) : ?>
  709.                 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'minimatica' ); ?></em>
  710.                 <br />
  711.             <?php endif; ?>
  712.             <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  713.                 <?php printf( __( '%1$s at %2$s', 'minimatica' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'minimatica' ), ' ' ); ?>
  714.             </div><!-- .comment-meta .commentmetadata -->
  715.         </header><!-- .comment-header -->
  716.         <div class="comment-content"><?php comment_text(); ?></div>
  717.         <footer class="comment-footer">
  718.             <div class="reply">
  719.                 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  720.             </div><!-- .reply -->
  721.         </footer><!-- .comment-footer -->
  722.     </article><!-- #comment-##  -->
  723.  
  724.     <?php
  725.             break;
  726.         case 'pingback'  :
  727.         case 'trackback' :
  728.     ?>
  729.     <li class="pingback">
  730.         <p><?php _e( 'Pingback:', 'minimatica' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'minimatica' ), ' ' ); ?></p>
  731.     <?php
  732.             break;
  733.     endswitch;
  734. }
  735. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement