'd9d9d9', 'text' => '000000', 'link' => '222222', 'border' => '404040', 'url' => 'ffffff', ); } // Set the content width based on the theme's design and stylesheet. if ( ! isset( $content_width ) ) $content_width = 315; // define widths define( 'MIN_WIDTH', 560 ); define( 'MAX_WIDTH', 840 ); // Tell WordPress to run monotone_setup() when the 'after_setup_theme' hook is run. add_action( 'after_setup_theme', 'monotone_setup' ); function monotone_setup() { /** * Make theme available for translation * Translations can be filed in the /languages/ directory */ load_theme_textdomain( 'monotone', get_template_directory() . '/languages' ); // Add default posts and comments RSS feed links to head. add_theme_support( 'automatic-feed-links' ); // This theme uses wp_nav_menu() in one location. register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'monotone' ), ) ); } // Register widgetized areas function monotone_widgets_init() { register_sidebar( array( 'name' => __( 'Footer Area One', 'monotone' ), 'id' => 'sidebar-1', 'description' => __( 'An optional widget in the footer', 'monotone' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'monotone_widgets_init' ); // filters and actions add_action( 'wp_head', 'monotone_header_function' ); add_filter( 'the_content', 'monotone_image_scrape', 0 ); add_action( 'publish_post', 'monotone_image_setup' ); add_action( 'publish_page', 'monotone_image_setup' ); function monotone_header_function() { global $vertical; if ( ! is_archive() && ! is_search() ) : ?> breaks YouTube videos. */ function monotone_replace_empty_tag( $m ) { $no_replace = array( 'embed' ); // expand as required if ( in_array( strtolower( $m[1] ), $no_replace ) ) return $m[0]; // return the original untouched return ''; } // remove image tag from post_content for display function monotone_image_scrape( $entry ) { // don't scrape the image for the feed if ( is_feed() ) { return $entry; } $entry = str_replace( '[/wp_caption]','', $entry ); $entry = str_replace( '[/caption]','', $entry ); //remove image tag $entry = preg_replace( '/]*src=(\"|\').+?(\1)[^>]*\/*>/','', $entry ); //remove any empty tags left by the scrape. $entry = str_replace( '

', '', $entry ); $entry = preg_replace_callback( '|<([a-z]+)[^>]*>\s*|i', 'monotone_replace_empty_tag', $entry ); $entry = preg_replace_callback( '|<([a-z]+)[^>]*>\s*|i', 'monotone_replace_empty_tag', $entry ); $entry = preg_replace_callback( '|<([a-z]+)[^>]*>\s*|i', 'monotone_replace_empty_tag', $entry ); return $entry; } // this resets post meta function monotone_reset_colors( $post ) { global $post; delete_post_meta( $post->ID, 'image_md5' ); delete_post_meta( $post->ID, 'image_url' ); delete_post_meta( $post->ID, 'image_size' ); delete_post_meta( $post->ID, 'image_tag' ); delete_post_meta( $post->ID, 'image_color_base' ); delete_post_meta( $post->ID, 'image_colors' ); delete_post_meta( $post->ID, 'image_colors_bg' ); delete_post_meta( $post->ID, 'image_colors_fg' ); } function monotone_image_setup( $postid ) { global $post; $post = get_post( $postid ); // get url if ( ! preg_match( '/]*)src=(\"|\')(.+?)(\2)([^>\/]*)\/*>/', $post->post_content, $matches ) ) { monotone_reset_colors( $post ); 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 = esc_url( $post->image_url, 'raw' ); $previous_md5 = get_post_meta( $post->ID, 'image_md5', true ); $previous_url = get_post_meta( $post->ID, 'image_url', true ); if ( ( md5( $post->image_tag ) != $previous_md5 ) or ( $post->image_url != $previous_url ) ) { monotone_reset_colors( $post ); add_post_meta( $post->ID, 'image_url', $post->image_url ); add_post_meta( $post->ID, 'image_md5', md5($post->image_tag ) ); //image tag setup $extra = $matches[1].' '.$matches[5]; $extra = preg_replace( '/width=(\"|\')[0-9]+(\1)/','', $extra ); $extra = preg_replace( '/height=(\"|\')[0-9]+(\1)/','', $extra ); $width = ( monotone_is_vertical( $post->image_url ) ) ? MIN_WIDTH : MAX_WIDTH; delete_post_meta( $post->ID, 'image_tag' ); add_post_meta( $post->ID, 'image_tag', '' ); // get colors monotone_get_all_colors( $post ); return false; } return true; } function monotone_is_vertical( $url ) { if ( preg_match( '/(jpg|jpeg|jpe|JPEG|JPG|png|PNG|gif|GIF)/',$url ) ) { global $post; $size = get_post_meta( $post->ID, 'image_size', true ); if ( ! $size ) { $size = getimagesize( $url ); add_post_meta( $post->ID, 'image_size', $size ); } $post->image_width = $size[0]; if ( $size ) { if ( $size[0] == $size[1] ) return true; if ( $size[0] < $size[1] ) return true; if ( $size[0] < MIN_WIDTH ) return true; } return false; } return false; } function monotone_the_image( $return = null ) { global $post; if ( get_post_status($post->ID) == 'private' ) { if ( ! is_page() && ! current_user_can( 'read_private_posts' ) ) { return false; } elseif ( is_page() && ! current_user_can( 'read_private_pages' ) ) { return false; } } if ( post_password_required() ) return false; $tag = get_post_meta( $post->ID, 'image_tag', true ); if ( ! $tag ) { monotone_image_setup( $post->ID ); $tag = get_post_meta( $post->ID, 'image_tag', true ); } $tag = preg_replace( '/width=(\"|\')[0-9]+(\1)/','', $tag ); $tag = preg_replace( '/height=(\"|\')[0-9]+(\1)/','', $tag ); if ( $return ) return wp_kses( $tag, wp_kses_allowed_html( 'post' ) ); /*else*/ echo wp_kses( $tag, wp_kses_allowed_html( 'post' ) ); } function monotone_the_image_url( $return = null ) { global $post; $tag = get_post_meta( $post->ID, 'image_url', true ); if ( ! $tag ) { monotone_image_setup( $post->ID ); $tag = get_post_meta( $post->ID, 'image_url', true ); } if ( $return ) return $tag; /*else*/ echo $tag; } function monotone_the_thumbnail() { global $post; $src = preg_replace( '/\?w\=[0-9]+/','?w=125', monotone_the_image( true ) ); if ( ! $src ) $src = 'Placeholder'; $src = '
'.$src.'
'; echo $src; } function monotone_get_all_colors( $post ) { $base = new stdClass; //pull from DB $base->bg = get_post_meta( $post->ID, 'image_colors_bg',true ); $base->fg = get_post_meta( $post->ID, 'image_colors_fg',true ); // show return variable if full if ( $base->bg != '' && $base->fg != '' ) { return $base; } else { // else, get the colors include_once __DIR__ . '/csscolor.php' ; $base = new CSS_Color( monotone_base_color( $post ) ); //set bg $bg = $base->bg; //set fg $fg = $base->fg; if ( add_post_meta( $post->ID, 'image_colors_bg', $bg, false ) && add_post_meta( $post->ID, 'image_colors_fg', $fg, false ) ) return $base; } } function monotone_print_stylesheet() { global $post; $new_color = new StdClass(); $color = monotone_get_all_colors( $post ); // hack for array keys like -1 being stored in post_meta as 4294967295 foreach ( $color->bg as $key => $value ) { if ( is_int( $key ) && $key > 0 ) $key = -( 4294967296 - $key ); $new_color->bg[$key] = $value; } foreach ( $color->fg as $key => $value ) { if ( is_int( $key ) && $key > 0 ) $key = -( 4294967296 - $key ); $new_color->fg[$key] = $value; } $color = $new_color; // end hack ?> #page { background-color:#bg['-1']; ?>; color:#fg['-2']; ?>; } a, a:link, a:visited { color: #fg['-3']; ?>; } a:hover, a:active { color: #bg['+2']; ?>; } #header h1, #header h1 a, #header h1 a:link, #header h1 a:visited, #header h1 a:active { color: #fg['0']; ?>; } #header h1 a:hover { color: #bg['+2']; ?>; } .navigation a, .navigation a:link, .navigation a:visited, .navigation a:active { color: #fg['0']; ?>; } h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover h6 a:hover, .navigation a:hover { color: #fg['-2']; ?>; } .description, h3#respond, #comments, #content h1, #content #post h1, #content .content h1, h1 a, h1 a:link, h1 a:visited, h1 a:active, #content h2, #content #post h2, #content .content h2, h2 a, h2 a:link, h2 a:visited, h2 a:active, #content h3, #content #post h3, #content .content h3, h3 a, h3 a:link, h3 a:visited, h3 a:active, #content h4, #content #post h4, #content .content h4, h4 a, h4 a:link, h4 a:visited, h4 a:active, #content h5, #content #post h5, #content .content h5, h5 a, h5 a:link, h5 a:visited, h5 a:active, #content h6, #content #post h6, #content .content h6, h6 a, h6 a:link, h6 a:visited, h6 a:active { /* Use the corresponding foreground color */ color: #fg['-1']; ?>; } #postmetadata, #commentform p, .commentlist li, #post, #postmetadata .sleeve, #post .sleeve, #content, h3#respond, h3#comments, #reply-title { color: #fg['-2']; ?>; border-color: #fg['-2']; ?>; }ID, 'image_url', true ); if ( ! $url ) { monotone_image_setup( $post->ID ); $url = get_post_meta( $post->ID, 'image_url', true ); } $ext = strtolower( pathinfo( trim( $url ), PATHINFO_EXTENSION ) ); $ext = explode( '?', $ext ); $ext = $ext[0]; switch( $ext ) { case 'gif' : $im = imagecreatefromgif( $url ); break; case 'png' : $im = imagecreatefrompng( $url ); break; case 'jpg' : $im = imagecreatefromjpeg( $url ); break; case 'jpeg' : $im = imagecreatefromjpeg( $url ); break; default: return 'ffffff'; } $height = imagesy( $im ); $top = $height - 400; $width = imagesx( $im ); // sample five points in the image, based on rule of thirds and center $rgb = array(); $topy = round( $height / 3 ); $bottomy = round( ( $height / 3 ) * 2 ); $leftx = round( $width / 3 ); $rightx = round( ( $width / 3 ) * 2 ); $centery = round( $height / 2 ); $centerx = round( $width / 2 ); $rgb[1] = imagecolorat( $im, $leftx, $topy ); $rgb[2] = imagecolorat( $im, $rightx, $topy ); $rgb[3] = imagecolorat( $im, $leftx, $bottomy ); $rgb[4] = imagecolorat( $im, $rightx, $bottomy ); $rgb[5] = imagecolorat( $im, $centerx, $centery ); // extract each value for r, g, b $r = array(); $g = array(); $b = array(); $hex = array(); $ct = 0; $val = 50; // process points for ( $i = 1; $i <= 5; $i++ ) { $r[$i] = ( $rgb[$i] >> 16 ) & 0xFF; $g[$i] = ( $rgb[$i] >> 8 ) & 0xFF; $b[$i] = $rgb[$i] & 0xFF; // find darkest color $tmp = $r[$i] + $g[$i] + $b[$i]; if ( $tmp < $val ) { $val = $tmp; $ct = $i; } $hex[$i] = monotone_rgbhex( $r[$i],$g[$i],$b[$i] ); } return $hex[3]; } function monotone_rgbhex( $red, $green, $blue ) { return sprintf( '%02X%02X%02X', $red, $green, $blue ); } // force 24 posts per page for archives function monotone_posts_per_page() { return 24; } add_filter( 'pre_option_posts_per_page', 'monotone_posts_per_page' ); function monotone_page_menu() { global $wpdb; // fallback for primary navigation ?>
  • id="comment-">
    comment_approved == '0' ) : ?>

    is_main_query() ) return; $query->set( 'posts_per_page', 1 ); $query->set( 'ignore_sticky_posts', true ); } add_action( 'pre_get_posts', 'monotone_home_posts' ); /** * Filters wp_title to print a neat tag based on what is being viewed. * * @since Monotone 1.2 */ function monotone_wp_title( $title, $sep ) { global $page, $paged; if ( is_feed() ) return $title; // Add the blog name $title .= get_bloginfo( 'name' ); // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) $title .= " $sep $site_description"; // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) $title .= " $sep " . sprintf( __( 'Page %s', 'monotone' ), max( $paged, $page ) ); return $title; } add_filter( 'wp_title', 'monotone_wp_title', 10, 2 ); /** * WP.com: Show a nice admin message noting that the current theme has been * trumped by a newer one. */ function monotone_add_notice() { $current_theme = wp_get_theme()->Name; if ( ! get_user_meta( get_current_user_id(), "$current_theme-theme-update", true ) ) { add_settings_error( 'theme-update', 'theme-update', sprintf( __( 'Howdy! Your current theme, <em>%1$s</em>, has seen an update in the form of a brand new theme, <a href="%3$s">%2$s</a>. For more information, check out <a href="%4$s">our blog post introducing %2$s to the world</a>. %5$s' ), $current_theme, // Old theme 'Duotone', // New theme admin_url( 'themes.php?s=duotone' ), // Link to new theme esc_url( 'http://en.blog.wordpress.com/2009/12/24/new-theme-duotone/' ), // Link to announcement post sprintf( '<a id="dismiss-theme-update" class="alignright" style="font-size: 16px;" title="%s" href="#">×</a>', __( 'Dismiss' ) ) // Dismiss ), 'updated' ); remove_action( 'admin_notices', 'show_tip' ); if ( ! has_filter( 'admin_notices', 'settings_errors' ) ) add_action( 'admin_notices', 'settings_errors' ); wp_enqueue_script( 'dismiss-theme-update', get_template_directory_uri() . '/js/dismiss-theme-update.js', array( 'jquery' ), 20130225 ); wp_localize_script( 'dismiss-theme-update', 'dismissThemeUpdate', array( 'theme' => $current_theme, 'nonce' => wp_create_nonce( "$current_theme-theme-update" ), ) ); } } add_action( 'admin_init', 'monotone_add_notice' ); /** * Updates user setting when theme update notice was dismissed. */ function monotone_dismiss_theme_update() { $current_theme = wp_get_theme()->Name; check_ajax_referer( "$current_theme-theme-update", 'nonce' ); if ( $_REQUEST['theme'] == $current_theme ) { update_user_meta( get_current_user_id(), "$current_theme-theme-update", true ); wp_die( 1 ); } } add_action( 'wp_ajax_dismiss_theme_update', 'monotone_dismiss_theme_update' );