DerReuter

functions.php

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