560, 780, 950 );
$styleinfo = get_option('k2styleinfo');
$columns = get_option('k2columns');
// dynamic columns, use 3 columns width
if ( 'dynamic' == $columns ) {
$columns = 3;
}
// style contains header width setting
if ( ! empty($styleinfo['header_width']) ) {
return $styleinfo['header_width'];
}
// style contains layout widths setting
if ( ! empty($styleinfo['layout_widths'][$columns]) ) {
return $styleinfo['layout_widths'][$columns];
}
return $default_widths[$columns];
}
function get_header_images() {
global $wpdb;
$images = K2::files_scan(K2_HEADERS_PATH, array('gif','jpeg','jpg','png'), 1, 2);
$attachment_ids = (array) $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'k2-header-image'");
foreach ($attachment_ids as $id) {
$images[] = str_replace(ABSPATH, '', get_attached_file($id) );
}
return $images;
}
function random_picture() {
$picture_files = K2Header::get_header_images();
$size = count($picture_files);
if ($size > 1) {
return ($picture_files[rand(0, $size - 1)]);
} else {
return $picture_files[0];
}
}
function output_header_css() {
$header_image = get_option('k2headerimage');
if ( 'random' == $header_image ) {
$picture = K2Header::random_picture();
} else {
$picture = $header_image;
}
?>
post_mime_type = 'image/' . $mime;
$attachment->post_excerpt = sprintf( __('Custom Header Image for K2 (%1$d x %2$d)', 'k2_domain'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
// Update the attachment
$id = wp_insert_attachment( $attachment, $source );
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $source ) );
}
// Allows K2 to find the attachment
add_post_meta( $id, 'k2-header-image', 'original' );
} elseif ( 3 == $_GET['step'] ) {
if ( get_wp_version() < 2.4 ) {
// Get original attachment
$parent = get_post( $_POST['attachment_id'] );
$parent_url = $parent->guid;
$url = str_replace(basename($parent_url), basename($source), $parent_url);
// Construct the object array
$object = array(
'post_title' => basename($source),
'post_content' => $url,
'post_excerpt' => sprintf( __('Custom Header Image for K2 (%1$d x %2$d)', 'k2_domain'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ),
'post_mime_type' => 'image/jpeg',
'guid' => $url
);
// Create a new attachment
$id = wp_insert_attachment( $object, $source );
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $source ) );
}
// Allows K2 to find the attachment
add_post_meta( $id, 'k2-header-image', 'cropped' );
}
// Update K2 Options
update_option( 'k2headerimage', str_replace(ABSPATH, '', $source) );
}
return $source;
}
}
add_action('k2_init', array('K2Header', 'init'), 11);
//add_action('k2_install', array('K2Header', 'install'));
add_action('k2_uninstall', array('K2Header', 'uninstall'));
add_action('wp_create_file_in_uploads', array('K2Header', 'process_custom_header_image'), 10, 2);
add_filter('wp_create_file_in_uploads', array('K2Header', 'process_custom_header_image'), 10, 2);
?>