Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b4b364657c
Fetching contributors…

Cannot retrieve contributors at this time

264 lines (217 sloc) 10.326 kb
<?php
/**
* The functions file is used to initialize everything in the theme. It controls how the theme is loaded and
* sets up the supported features, default actions, and default filters. If making customizations, users
* should create a child theme and make changes to its functions.php file (not this one). Friends don't let
* friends modify parent theme files. ;)
*
* Child themes should do their setup on the 'after_setup_theme' hook with a priority of 11 if they want to
* override parent theme features. Use a priority of 9 if wanting to run before the parent theme.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package Uridimmu
* @subpackage Functions
* @version 0.1.0
* @author Thiago Senna <thiago@thremes.com.br>
* @copyright Copyright (c) 2011 - 2012, Thiago Senna
* @link http://thremes.com.br/themes/uridimmu
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/* Load the core theme framework. */
require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
new Hybrid();
/* Do theme setup on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'uridimmu_theme_setup' );
/**
* Theme setup function. This function adds support for theme features and defines the default theme
* actions and filters.
*
* @since 0.1.0
*/
function uridimmu_theme_setup() {
/* Get action/filter hook prefix. */
$prefix = hybrid_get_prefix();
/* Add theme support for core framework features. */
add_theme_support( 'hybrid-core-menus', array( 'primary' ) );
add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'secondary', 'before-content', 'after-content', 'after-singular' ) );
add_theme_support( 'hybrid-core-widgets' );
add_theme_support( 'hybrid-core-shortcodes' );
add_theme_support( 'hybrid-core-theme-settings', array( 'about', 'footer' ) );
add_theme_support( 'hybrid-core-drop-downs' );
add_theme_support( 'hybrid-core-template-hierarchy' );
/* Add theme support for framework extensions. */
add_theme_support( 'theme-layouts', array( '1c', '2c-l', '2c-r', '3c-l', '3c-r', '3c-c' ) );
add_theme_support( 'post-stylesheets' );
add_theme_support( 'dev-stylesheet' );
add_theme_support( 'loop-pagination' );
add_theme_support( 'get-the-image' );
add_theme_support( 'breadcrumb-trail' );
add_theme_support( 'cleaner-gallery' );
/* Add theme support for WordPress features. */
add_theme_support( 'automatic-feed-links' );
/* Add support for a custom background. */
add_theme_support(
'custom-background',
array(
'default-image' => trailingslashit( get_template_directory_uri() ) . 'images/bg.jpg',
)
);
/* Embed width/height defaults. */
add_filter( 'embed_defaults', 'uridimmu_embed_defaults' );
/* Set the content width. */
hybrid_set_content_width( 630 );
/* Filter the sidebar widgets. */
add_filter( 'sidebars_widgets', 'uridimmu_disable_sidebars' );
add_action( 'template_redirect', 'uridimmu_one_column' );
/* Add classes to the comments pagination. */
add_filter( 'previous_comments_link_attributes', 'uridimmu_previous_comments_link_attributes' );
add_filter( 'next_comments_link_attributes', 'uridimmu_next_comments_link_attributes' );
/* Load some required font styles */
add_action( 'wp_enqueue_scripts', 'uridimmu_load_font_styles' );
}
/**
* Adds 'class="prev" to the previous comments link.
*
* @since 0.1.0
*/
function uridimmu_previous_comments_link_attributes( $attributes ) {
return $attributes . ' class="prev"';
}
/**
* Adds 'class="next" to the next comments link.
*
* @since 0.1.0
*/
function uridimmu_next_comments_link_attributes( $attributes ) {
return $attributes . ' class="next"';
}
/**
* Function for deciding which pages should have a one-column layout.
*
* @since 0.1.0
*/
function uridimmu_one_column() {
if ( !is_active_sidebar( 'primary' ) && !is_active_sidebar( 'secondary' ) )
add_filter( 'get_theme_layout', 'uridimmu_theme_layout_one_column' );
elseif ( is_attachment() && 'layout-default' == theme_layouts_get_layout() )
add_filter( 'get_theme_layout', 'uridimmu_theme_layout_one_column' );
}
/**
* Filters 'get_theme_layout' by returning 'layout-1c'.
*
* @since 0.1.0
*/
function uridimmu_theme_layout_one_column( $layout ) {
return 'layout-1c';
}
/**
* Disables sidebars if viewing a one-column page.
*
* @since 0.1.0
*/
function uridimmu_disable_sidebars( $sidebars_widgets ) {
if ( current_theme_supports( 'theme-layouts' ) ) {
if ( 'layout-1c' == theme_layouts_get_layout() ) {
$sidebars_widgets['primary'] = false;
$sidebars_widgets['secondary'] = false;
}
}
return $sidebars_widgets;
}
/**
* Overwrites the default widths for embeds. This is especially useful for making sure videos properly
* expand the full width on video pages. This function overwrites what the $content_width variable handles
* with context-based widths.
*
* @since 0.1.0
*/
function uridimmu_embed_defaults( $args ) {
if ( current_theme_supports( 'theme-layouts' ) ) {
$layout = theme_layouts_get_layout();
if ( 'layout-3c-l' == $layout || 'layout-3c-r' == $layout || 'layout-3c-c' == $layout )
$args['width'] = 520;
elseif ( 'layout-1c' == $layout )
$args['width'] = 980;
else
$args['width'] = 630;
}
else
$args['width'] = 630;
return $args;
}
/**
* Load specific font stylesheets needed by the theme.
*
* @since 0.1.0
*/
function uridimmu_load_font_styles() {
wp_register_style( 'museo_300', get_template_directory_uri() . '/fonts/museo_300_macroman/stylesheet.css' );
wp_enqueue_style( 'museo_300' );
wp_register_style( 'museo_500', get_template_directory_uri() . '/fonts/museo_500_macroman/stylesheet.css' );
wp_enqueue_style( 'museo_500' );
}
/**
* Displays an attachment image's metadata and exif data while viewing a singular attachment page.
*
* Note: This function will most likely be restructured completely in the future. The eventual plan is to
* separate each of the elements into an attachment API that can be used across multiple themes. Keep
* this in mind if you plan on using the current filter hooks in this function.
*
* @since 0.1.0
* @author Justin Tadlock
* @link http://justintadlock.com
*/
function uridimmu_image_info() {
/* Set up some default variables and get the image metadata. */
$meta = wp_get_attachment_metadata( get_the_ID() );
$items = array();
$list = '';
/* Add the width/height to the $items array. */
$items['dimensions'] = sprintf( __( '<span class="prep">Dimensions:</span> %s', 'retro-fitted' ), '<span class="image-data"><a href="' . esc_url( wp_get_attachment_url() ) . '">' . sprintf( __( '%1$s &#215; %2$s pixels', 'retro-fitted' ), $meta['width'], $meta['height'] ) . '</a></span>' );
/* If a timestamp exists, add it to the $items array. */
if ( !empty( $meta['image_meta']['created_timestamp'] ) )
$items['created_timestamp'] = sprintf( __( '<span class="prep">Date:</span> %s', 'retro-fitted' ), '<span class="image-data">' . date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $meta['image_meta']['created_timestamp'] ) . '</span>' );
/* If a camera exists, add it to the $items array. */
if ( !empty( $meta['image_meta']['camera'] ) )
$items['camera'] = sprintf( __( '<span class="prep">Camera:</span> %s', 'retro-fitted' ), '<span class="image-data">' . $meta['image_meta']['camera'] . '</span>' );
/* If an aperture exists, add it to the $items array. */
if ( !empty( $meta['image_meta']['aperture'] ) )
$items['aperture'] = sprintf( __( '<span class="prep">Aperture:</span> %s', 'retro-fitted' ), '<span class="image-data">' . sprintf( __( 'f/%s', 'retro-fitted' ), $meta['image_meta']['aperture'] ) . '</span>' );
/* If a focal length is set, add it to the $items array. */
if ( !empty( $meta['image_meta']['focal_length'] ) )
$items['focal_length'] = sprintf( __( '<span class="prep">Focal Length:</span> %s', 'retro-fitted' ), '<span class="image-data">' . sprintf( __( '%s mm', 'retro-fitted' ), $meta['image_meta']['focal_length'] ) . '</span>' );
/* If an ISO is set, add it to the $items array. */
if ( !empty( $meta['image_meta']['iso'] ) )
$items['iso'] = sprintf( __( '<span class="prep">ISO:</span> %s', 'retro-fitted' ), '<span class="image-data">' . $meta['image_meta']['iso'] . '</span>' );
/* If a shutter speed is given, format the float into a fraction and add it to the $items array. */
if ( !empty( $meta['image_meta']['shutter_speed'] ) ) {
if ( ( 1 / $meta['image_meta']['shutter_speed'] ) > 1 ) {
$shutter_speed = '1/';
if ( number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 1 ) == number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 0 ) )
$shutter_speed .= number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 0, '.', '' );
else
$shutter_speed .= number_format( ( 1 / $meta['image_meta']['shutter_speed'] ), 1, '.', '' );
} else {
$shutter_speed = $meta['image_meta']['shutter_speed'];
}
$items['shutter_speed'] = sprintf( __( '<span class="prep">Shutter Speed:</span> %s', 'retro-fitted' ), '<span class="image-data">' . sprintf( __( '%s sec', 'retro-fitted' ), $shutter_speed ) . '</span>' );
}
/* Allow devs to overwrite the array of items. */
$items = apply_atomic( 'image_info_items', $items );
/* Loop through the items, wrapping each in an <li> element. */
foreach ( $items as $item )
$list .= "<li>{$item}</li>";
/* Format the HTML output of the function. */
$output = '<div class="image-info"><h3>' . __( 'Image Info', 'retro-fitted' ) . '</h3><ul>' . $list . '</ul></div>';
/* Display the image info and allow devs to overwrite the final output. */
echo apply_atomic( 'image_info', $output );
}
Jump to Line
Something went wrong with that request. Please try again.