<?php
// Conditional test for IE6
function browser_ie6() {
$agents = array(
'MSIE 6.0'
);
foreach ($agents as $agent) {
if (strpos($_SERVER['HTTP_USER_AGENT'], $agent) or isset($_GET[$agent]) && $_GET[$agent] ) {
return true;
}
}
return false;
}
// Thanks very much to Thin & Light () for this custom function!
function tl_excerpt($text, $excerpt_length = 25) {
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$text = preg_replace("/\[.*?]/", "", $text);
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '...');
$text = implode(' ', $words);
}
return apply_filters('the_excerpt', $text);
}
function tl_post_excerpt($post) {
$excerpt = ($post->post_excerpt == '') ? (tl_excerpt($post->post_content))
: (apply_filters('the_excerpt', $post->post_excerpt));
return $excerpt;
}
function previous_post_excerpt($in_same_cat = false, $excluded_categories = '') {
if ( is_attachment() )
$post = &get_post($GLOBALS['post']->post_parent);
else
$post = get_previous_post($in_same_cat, $excluded_categories);
if ( !$post )
return;
$post = &get_post($post->ID);
echo tl_post_excerpt($post);
}
function next_post_excerpt($in_same_cat = false, $excluded_categories = '') {
$post = get_next_post($in_same_cat, $excluded_categories);
if ( !$post )
return;
$post = &get_post($post->ID);
echo tl_post_excerpt($post);
}
// Photo Author/Credit Display
function autofocus_credit() {
global $post;
if ( get_the_author_meta('user_url') == '' ) { ?>
<span class="photo-credit">© <?php the_time('Y'); ?> <?php the_author_meta('display_name'); ?>. <?php _e('All rights reserved.', 'thematic'); ?></span>
<?php } else { ?>
<span class="photo-credit">© <?php the_time('Y'); ?> <a href="<?php the_author_meta('user_url'); ?>" target="_blank" rel="author"><?php the_author_meta('display_name'); ?></a>. <?php _e('All rights reserved.', 'thematic'); ?></span>
<?php } ?>
<?php }
// Post Attachment image function. Direct link to file.
function the_post_image($size=large, $fullsize=false, $width=940, $height=600, $max_dims=false) {
global $post;
$linkedimgtag = get_post_meta ($post->ID, 'image_tag', true);
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
$attachmentresize=get_attachment_innerHTML($image->ID, $fullsize, array($width, $height));
echo $attachmentimage;
}
} elseif ( $linkedimgtag ) {
echo $linkedimgtag;
} elseif ( $linkedimgtag && $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
$attachmentresize=get_attachment_innerHTML($image->ID, $size, array($width, $height));
echo $attachmentresize;
}
} elseif (get_post_meta($post->ID, 'image_tag', $single = true) == "" && is_single()) {
// Don’t show anything on Single pages that don’t have Image or Video attachments.
} else {
echo '<!-- No Image Attached! -->';
echo '<img src="';
echo get_bloginfo ( 'stylesheet_directory' ) . '/img/no-attachment.png';
echo '" width="188" height="188" />';
}
}
// Setup Images for Attachment functions
function image_setup($postid) {
global $post;
$post = get_post($postid);
// get url
if ( !preg_match('/<img ([^>]*)src=(\"|\')(.+?)(\2)([^>\/]*)\/*>/', $post->post_content, $matches) ) {
return false;
}
// url setup /**/
$post->image_url = $matches[3];
if ( !$post->image_url = preg_replace('/\?w\=[0-9]+/','', $post->image_url) )
return false;
$post->image_url = clean_url( $post->image_url, 'raw' );
delete_post_meta($post->ID, 'image_url');
delete_post_meta($post->ID, 'image_tag');
add_post_meta($post->ID, 'image_url', $post->image_url);
add_post_meta($post->ID, 'image_tag', '<img src="'.$post->image_url.'" />');
}
add_action('publish_post', image_setup);
add_action('publish_page', image_setup);
// Post Attachment image function for Attachment Pages.
function the_attachment_image($size=large) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo ''.$attachmentimage.'';
}
// Grab EXIF Data from Attachments
//
function grab_exif_data() {
global $id, $post;
$imgmeta = wp_get_attachment_metadata($id, false);
// Start to display EXIF and IPTC data of digital photograph
echo "<h3 id='exif-data'>Exif Data</h3>";
echo "<ul><li><span class=\"exif-title\">Date Taken:</span> " . date("d-M-Y H:i:s", $imgmeta['image_meta']['created_timestamp'])."</li>";
echo "<li><span class=\"exif-title\">Copyright:</span> " . $imgmeta['image_meta']['copyright']."</li>";
echo "<li><span class=\"exif-title\">Credit:</span> " . $imgmeta['image_meta']['credit']."</li>";
echo "<li><span class=\"exif-title\">Title:</span> " . $imgmeta['image_meta']['title']."</li>";
echo "<li><span class=\"exif-title\">Caption:</span> " . $imgmeta['image_meta']['caption']."</li>";
echo "<li><span class=\"exif-title\">Camera:</span> " . $imgmeta['image_meta']['camera']."</li>";
echo "<li><span class=\"exif-title\">Focal Length:</span> " . $imgmeta['image_meta']['focal_length']."mm</li>";
echo "<li><span class=\"exif-title\">Aperture:</span> f/" . $imgmeta['image_meta']['aperture']."</li>";
echo "<li><span class=\"exif-title\">ISO:</span> " . $imgmeta['image_meta']['iso']."</li>";
echo "<li><span class=\"exif-title\">Shutter Speed:</span> " . number_format($imgmeta['image_meta']['shutter_speed'], 2)." seconds</li>\n</ul>";
}
// Get the Post Thumbnail URL for the EXIF link
function exif_link( $post_id = NULL, $size = 'single-post-thumbnail', $attr = '' ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$size = apply_filters( 'single-post-thumbnail', $size );
if ( $post_thumbnail_id ) {
$thumburl = get_attachment_link( $post_thumbnail_id, $size, false, $attr );
} else {
$thumburl = '';
}
return $thumburl;
}
// Add Images/Video/Embeds to feeds
// - Based on the Custom Fields for Feeds Plugin by Justin Tadlock
// -
Custom Fields For Feeds: WordPress Plugin
function autofocus_feed( $content ) {
global $post, $id, $afoptions;
foreach ($afoptions as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
$data = get_post_meta( $post->ID, 'autofocus', true );
$blog_key = substr( md5( get_bloginfo('url') ), 0, 16 );
if ( !is_feed() ) return $content;
// Is there a Video attached?
// - WordPress doesn’t setup [embed] codes as shortcodes.
// - Embedded content will not work in feeds without it.
// - See:
#12505 (embed is not registered as a shortcode) – WordPress Trac
// if ($data[ 'videoembed_value' ]) {
// $af_video_url = $data[ 'videoembed_value' ];
// $mediafeed = '[embed width="600" height="400"]' . $af_video_url . '[/embed]';
// }
// If there’s no video is there an image thumbnail?
if ( has_post_thumbnail() ) {
$mediafeed = the_post_thumbnail('medium');
}
// If there's a video or an image, display the media with the content
if ($mediafeed !== '') {
$content = '<p>' .$mediafeed . '</p><br />' . $content;
return $content;
// If there's no media, just display the content
} else {
$content = $content;
return $content;
}
}
add_filter('the_content', 'autofocus_feed');
// Add Post Thumbnails Support
if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 88, 88, true ); // Default thumbnail size
add_image_size( 'archive-thumbnail', 188, 188, true ); // Archives thumbnail size
add_image_size( 'single-post-thumbnail', 940, 600 ); // Single Posts thumbnail size
add_image_size( 'front-page-thumbnail', 940, 368, true ); // Front Page thumbnail size
}
// Set default content width for images in post content
$_GLOBALS['content_width'] = 494;
// Custom AutoFocus Thumbnail Sizes
function af_image_sizes( $sizes ) {
$sizes[] = 'afthumb';
$sizes[] = 'aflarge';
$sizes[] = 'afsingle';
return $sizes;
}
add_filter( 'intermediate_image_sizes', 'af_image_sizes' );
// Custom image size settings initiated at activation
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
if( FALSE === get_option('af_size_w') ) {
add_option('afthumb_size_w', '188');
add_option('afthumb_size_h', '188');
add_option('afthumb_crop', '1');
add_option('aflarge_size_w', '940');
add_option('aflarge_size_h', '368');
add_option('aflarge_crop', '1');
add_option('afsingle_size_w', '940');
add_option('afsingle_size_h', '600');
add_option('afsingle_crop', '0');
} else {
update_option('afthumb_size_w', '188');
update_option('afthumb_size_h', '188');
update_option('afthumb_crop', '1');
update_option('aflarge_size_w', '940');
update_option('aflarge_size_h', '368');
update_option('aflarge_crop', '1');
update_option('afsingle_size_w', '940');
update_option('afsingle_size_h', '600');
update_option('afsingle_crop', '0');
}
update_option('thumbnail_size_h', '88');
update_option('thumbnail_size_w', '88');
update_option('thumbnail_crop', '1');
update_option('medium_size_h', '188');
update_option('medium_size_w', '188');
update_option('medium_crop', '0');
update_option('large_size_h', '494');
update_option('large_size_w', '494');
update_option('large_crop', '0');
update_option('thread_comments', '1');
update_option('thread_comments_depth', '2');
update_option( 'posts_per_page', '12');
update_option( 'date_format', __('j M ’y') );
}
// Load Color Options
function af_load_color_options() {
global $afoptions;
foreach ($afoptions as $afvalue) {
if (get_settings( $afvalue['id'] ) === FALSE) { $$afvalue['id'] = $afvalue['std']; } else { $$afvalue['id'] = get_settings( $afvalue['id'] ); }
} ?>
<style type="text/css">
/* <![CDATA[ */
/* AutoFocus+ Color Options */
<?php $afcoloroptions = dirname( __FILE__ ) . '/css/af-styles.php'; if( is_file( $afcoloroptions ) ) require $afcoloroptions; ?>
/* ]]> */
</style>
<?php }
add_action('wp_head', 'af_load_color_options');
// Post Options and Instructions
// - New Video Array For Video Embed Codes
$key = "autofocus";
$af_meta_boxes = array(
"video" => array(
"name" => "videoembed_value",
"title" => __("Embed URL","thematic"),
"description" => __("Paste your oEmbed URL here. (Examples:
Blitz the Ambassador LIVE Sessions Teaser on Vimeo, http://www.flickr.com/photos/bking/3598750242/)","thematic")),
"copyright" => array(
"name" => "copyright_value",
"title" => __("Photo Credit","thematic"),
"description" => __("Text entered here will replace the default Photo credit. (Example: © 2009 Image Author. All rights reserved.)<br />Using HTML here works but is not recommended.","thematic")),
"What I did" => array(
"name" => "whatidid_value",
"title" => __("What I did","thematic"),
"description" => __("hier kommt rein was ich gemacht habe.)<br />Using HTML here works but is not recommended.","thematic")),
);
// - New Meta Boxes For Video Embed Codes
function display_meta_box() {
global $post, $af_meta_boxes, $key; ?>
<div class="form-wrap">
<?php wp_nonce_field( plugin_basename( __FILE__ ), $key . '_wpnonce', false, true );
foreach($af_meta_boxes as $meta_box) {
$data = get_post_meta($post->ID, $key, true); ?>
<div class="form-field form-required">
<label for="<?php echo $meta_box[ 'name' ]; ?>"><?php echo $meta_box[ 'title' ]; ?></label>
<input type="text" name="<?php echo $meta_box[ 'name' ]; ?>" value="<?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>" />
<p><?php echo $meta_box[ 'description' ]; ?></p>
</div>
<?php } ?>
</div>
<?php }
// - Create Form Data
function create_meta_box() {
global $key;
if( function_exists( 'add_meta_box' ) ) {
add_meta_box( 'new-meta-boxes', 'AutoFocus+ Post Options', 'display_meta_box', 'post', 'normal', 'high' );
}
}
// - Save Form Data
function save_meta_box( $post_id ) {
global $post, $af_meta_boxes, $key;
foreach( $af_meta_boxes as $meta_box ) {
$data[ $meta_box[ 'name' ] ] = $_POST[ $meta_box[ 'name' ] ];
}
if ( !wp_verify_nonce( $_POST[ $key . '_wpnonce' ], plugin_basename(__FILE__) ) )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;
update_post_meta( $post_id, $key, $data );
}
add_action( 'admin_menu', 'create_meta_box' );
add_action( 'save_post', 'save_meta_box' );
// Theme Options --------------------------------------------
$afthemename = "AutoFocus+";
$afshortname = "af";
$afoptions = array();
function autofocus_options() {
global $afthemename, $afshortname, $afoptions;
$af_categories_obj = get_categories('hide_empty=0');
$af_categories = array();
foreach ($af_categories_obj as $af_cat) {
$af_categories[$af_cat->cat_ID] = $af_cat->cat_name;
}
$categories_std = array_unshift($af_categories, "Select a category:");
$afoptions = array (
array( "name" => __('Text Color'),
"desc" => __('Change the color of links, backgrounds and borders by entering a HEX color number. (ie: <span style="font-family:Monaco,Lucida Console,Courier,monospace;">003333</span>)','thematic'),
"id" => $afshortname."_text_color",
"std" => "999999",
"type" => "colorpicker"),
array( "name" => __('Link Color','thematic'),
"desc" => __('Change the color of hover links by entering a HEX color number. (ie: <span style="font-family:Monaco,Lucida Console,Courier,monospace;">FF6600</span>)','thematic'),
"id" => $afshortname."_link_color",
"std" => "00CCFF",
"type" => "colorpicker"),
array( "name" => __('Background Color','thematic'),
"desc" => __('Change the color of hover links by entering a HEX color number. (ie: <span style="font-family:Monaco,Lucida Console,Courier,monospace;">FF6600</span>)','thematic'),
"id" => $afshortname."_bg_color",
"std" => "FFFFFF",
"type" => "colorpicker"),
array( "name" => __('Photo Background Color','thematic'),
"desc" => __('Change the background color of Portrait (narrow) images by entering a HEX color number. (ie: <span style="font-family:Monaco,Lucida Console,Courier,monospace;">FF6600</span>. Note: If left empty, the background color will be transparent.','thematic'),
"id" => $afshortname."_photo_color",
"std" => "F0F0F0",
"type" => "colorpicker"),
array( "name" => __('Show Post Titles','thematic'),
"desc" => __("Add a check here to show Post Titles instead of Post Dates on the home page.",'thematic'),
"id" => $afshortname."_show_post_title",
"std" => "false",
"type" => "checkbox"),
array( "name" => __('Show Exif data','thematic'),
"desc" => __("Add a check here to show the Exif data for your images on attachment pages (WP Gallery Images only).",'thematic'),
"id" => $afshortname."_show_exif_data",
"std" => "false",
"type" => "checkbox")
);
}
add_action('init', 'autofocus_options');
// Make a Theme Options Page
function childtheme_add_admin() {
global $afthemename, $afshortname, $afoptions;
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'save' == $_REQUEST['action'] ) {
foreach ($afoptions as $afvalue) {
update_option( $afvalue['id'], $_REQUEST[ $afvalue['id'] ] ); }
foreach ($afoptions as $afvalue) {
if( isset( $_REQUEST[ $afvalue['id'] ] ) ) { update_option( $afvalue['id'], $_REQUEST[ $afvalue['id'] ] ); } else { delete_option( $afvalue['id'] ); } }
header("Location: themes.php?page=functions.php&saved=true");
die;
} else if( 'reset' == $_REQUEST['action'] ) {
foreach ($afoptions as $afvalue) {
delete_option( $afvalue['id'] ); }
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_theme_page($afthemename." Options", "$afthemename Options", 'edit_themes', basename(__FILE__), 'childtheme_admin');
}
function childtheme_admin() {
global $afthemename, $afshortname, $afoptions;
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$afthemename.' settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$afthemename.' settings reset.</strong></p></div>';
?>
<script language="javascript" type="text/javascript" src="<?php echo bloginfo('stylesheet_directory') ?>/js/jscolor/jscolor.js"></script>
<div class="wrap">
<h2><?php echo $afthemename; ?> Options</h2>
<form method="post">
<table class="form-table">
<?php foreach ($afoptions as $afvalue) {
switch ( $afvalue['type'] ) {
case 'text':
?>
<tr valign="top">
<th scope="row"><?php echo $afvalue['name']; ?>:</th>
<td>
<input name="<?php echo $afvalue['id']; ?>" id="<?php echo $afvalue['id']; ?>" type="<?php echo $afvalue['type']; ?>" value="<?php if ( get_settings( $afvalue['id'] ) != "") { echo get_settings( $afvalue['id'] ); } else { echo $afvalue['std']; } ?>" />
<?php echo $afvalue['desc']; ?>
</td>
</tr>
<?php
break;
case 'colorpicker':
?>
<tr valign="top">
<th scope="row"><label for="<?php echo $afvalue['id']; ?>"><?php echo __($afvalue['name'],'thematic'); ?></label></th>
<td>
<input type="<?php echo $afvalue['type']; ?>" name="<?php echo $afvalue['id']; ?>" id="<?php echo $afvalue['id']; ?>" value="<?php if ( get_option( $afvalue['id'] ) != "") { echo get_option( $afvalue['id'] ); } else { echo $afvalue['std']; } ?>" class="color {pickerPosition:'right'}" />
<?php echo __($afvalue['desc'],'thematic'); ?>
</td>
</tr>
<?php
break;
case 'select':
?>
<tr valign="top">
<th scope="row"><?php echo $afvalue['name']; ?></th>
<td>
<select name="<?php echo $afvalue['id']; ?>" id="<?php echo $afvalue['id']; ?>">
<?php foreach ($afvalue['options'] as $option) { ?>
<option<?php if ( get_settings( $afvalue['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $afvalue['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
<?php } ?>
</select>
<?php echo $afvalue['desc']; ?>
</td>
</tr>
<?php
break;
case 'textarea':
$ta_options = $afvalue['options'];
?>
<tr valign="top">
<th scope="row"><?php echo $afvalue['name']; ?>:</th>
<td>
<?php echo $afvalue['desc']; ?>
<textarea name="<?php echo $afvalue['id']; ?>" id="<?php echo $afvalue['id']; ?>" cols="<?php echo $ta_options['cols']; ?>" rows="<?php echo $ta_options['rows']; ?>"><?php
if( get_settings($afvalue['id']) != "") {
echo stripslashes(get_settings($afvalue['id']));
}else{
echo $afvalue['std'];
}?></textarea>
</td>
</tr>
<?php
break;
case "radio":
?>
<tr valign="top">
<th scope="row"><?php echo $afvalue['name']; ?>:</th>
<td>
<?php foreach ($afvalue['options'] as $key=>$option) {
$radio_setting = get_settings($afvalue['id']);
if($radio_setting != ''){
if ($key == get_settings($afvalue['id']) ) {
$checked = "checked=\"checked\"";
} else {
$checked = "";
}
}else{
if($key == $afvalue['std']){
$checked = "checked=\"checked\"";
}else{
$checked = "";
}
}?>
<input type="radio" name="<?php echo $afvalue['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />
<?php } ?>
</td>
</tr>
<?php
break;
case "checkbox":
?>
<tr valign="top">
<th scope="row"><?php echo $afvalue['name']; ?></th>
<td>
<?php
if(get_settings($afvalue['id'])){
$checked = "checked=\"checked\"";
}else{
$checked = "";
}
?>
<input type="checkbox" name="<?php echo $afvalue['id']; ?>" id="<?php echo $afvalue['id']; ?>" value="true" <?php echo $checked; ?> />
<?php ?>
<?php echo $afvalue['desc']; ?>
</td>
</tr>
<?php
break;
default:
break;
}
}
?>
</table>
<p class="submit">
<input name="save" type="submit" value="Save changes" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
<p><?php _e('For more information about this theme, visit the <a href="http://fthrwght.com/autofocus">documentation page</a>. If you have any questions, check out <a href="http://wpquestions.com/">WPQuestions.com</a>.', 'thematic'); ?></p>
<?php }
add_action('admin_menu' , 'childtheme_add_admin');
// Add Thematic Body and Post Classes, Comment form classes & RSS links
define('THEMATIC_COMPATIBLE_BODY_CLASS', true);
define('THEMATIC_COMPATIBLE_POST_CLASS', true);
define('THEMATIC_COMPATIBLE_COMMENT_FORM', true);
define('THEMATIC_COMPATIBLE_FEEDLINKS', true);
// Add custom jQuery plugins and functions
function af_enqueue_styles() {
if (!is_admin()) {
// BOO IE6! :-/
if( browser_ie6() ) {
wp_enqueue_style('afiestyles', get_bloginfo('stylesheet_directory') . '/css/ie-styles.css','','20100329','all');
}
}
}
add_action('init', 'af_enqueue_styles');
// Add jQuery Plugins when not in IE
function af_enqueue_scripts() {
if( !browser_ie6() ) {
wp_enqueue_script('imgCenter', get_bloginfo('stylesheet_directory') . '/js/jquery.imgCenter.minified.js', array('jquery'), '20100329' );
wp_enqueue_script('hotkeys', get_bloginfo('stylesheet_directory') . '/js/jquery.hotkeys-0.7.9.min.js', array('jquery'), '20100329' );
wp_enqueue_script('autofocusjs', get_bloginfo('stylesheet_directory') . '/js/afscripts.js', array('jquery'), '20100329' );
}
}
add_action('wp_print_scripts', 'af_enqueue_scripts');
// Load Thematic Functions
require_once(STYLESHEETPATH . '/thematic-functions.php');
?>