'Sidebar', 'before_widget' => '
  • ', 'after_widget' => '
  • ', 'before_title' => '

    ', 'after_title' => '

    ', )); register_sidebar(array( 'name' => 'Footer', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '

    ', )); } /** * Add frames * * Filters content, adding frames to all objects with class 'frame', and all images if * corresponding option is set. */ function elegant_grunge_filter( $content , $arg2=null, $arg3=null ) { global $post; // Not for feeds if ( is_feed() ) return $content; // Look-ahead for class 'frame' $frameClass = '(?=[^>]+class=["\'][^"\']*frame)'; // Skipped classes $classes = "(?:".join("|", array_map("trim", explode(",",get_option('frame_class_skip')))).")"; $skippedClasses = '(?![^>]+class=["\'][^"\']*'.$classes.')'; // 'A' tags which we want to include inside the frame $aStart = '(?:<\s*a[^>]+>\s*)?'; $aEnd = '(?:\s*)?'; // Beginning tag, including class check $startTagWithFrameClass = "<\s*((?:(img)|[a-zA-Z]+))${skippedClasses}${frameClass}[^>]*"; // End of tag: Short form $endSingleTag = '(?(2)\s*/?>|\s*/>)'; // End of tag: Long form $endOriginalTag = ''; // Any tag $anyStartTag = '<\s*([a-z]+)[^>]*'; $endLastTag = ''; // Nested content - tags within tags $nestedContent = "([^<]+|(?:$anyStartTag(?:$endSingleTag|>(?-2)*$endLastTag)))*"; // Composite expression - look for a block with class of 'frame', and include all content $regex = "$aStart$startTagWithFrameClass(?:$endSingleTag|>$nestedContent$endOriginalTag)$aEnd"; $regexes = array("@".$regex."@is"); // Also replace all images $frame_all_images = get_option("frame_all_images"); $frame_all_images_post = get_post_meta($post->ID, 'frame_all_images', true); if ( $frame_all_images_post == "true" ) $frame_all_images = true; else if ( $frame_all_images_post == "false" ) $frame_all_images = false; if ( $frame_all_images ) { // Look-ahead for not class of frame (becuase we caught these above) $notFrameClass = '(?![^>]+class=["\'][^"\']*frame)'; // Composite expression - any images not with class of 'frame' $regex = "$aStart\s*<\s*(img)${notFrameClass}${skippedClasses}[^>]+>\s*$aEnd"; $regexes[] = "@".$regex."@is"; } // Perform replacement with helper function below $newContent = @preg_replace_callback($regexes, 'elegant_grunge_replace', $content); if ( !$newContent ) { return $content; } return $newContent; } /** * Filter helper function * * Perform replacements for blocks discovered in the filter function above. * Adds surrounding divs for frame, styled according to original block, * resizes too-large images, and ignores entire block if it is a too-small * image (because it will look weird, otherwise) */ function elegant_grunge_replace($matches) { $inner = $matches[0]; // Look for align and style attributes $align = '(^(?:<\s*a[^>]+>)?\s*<[^>]*?)align=["\'](left|right)["\']'; $style = '(^(?:<\s*a[^>]+>)?\s*<[^>]*?)style=["\']([^"\']+)["\']'; $class = '(^(?:<\s*a[^>]+>)?\s*<[^>]*?)class=["\']([^"\']+)["\']'; $styles = ""; if ( preg_match( "@$align@is", $inner, $newmatch ) ) { // Align attribute found: Add an equivalent float $styles .= "float: ".$newmatch[2].";"; } if ( preg_match( "@$style@is", $inner, $newmatch ) ) { // Style attribute found: Remember content, but minus some undesirable elements $styles .= preg_replace("@(border(-[a-z]+)?|padding(-[a-z]+)?|margin-([a-z]+)?)\s*:[^;\"']*@is", "", $newmatch[2]); } if ( preg_match( "@$class@is", $inner, $newmatch ) ) { // Style attribute found: Remember content $classes = trim(preg_replace("@(?]+>)?\s*<[^>]*?(?:width=[\'"]|width:\s*))([0-9]+)@is'; $heightRegex = '@(^(?:<\s*a[^>]+>)?\s*<[^>]*?(?:height=[\'"]|height:\s*))([0-9]+)@is'; if ( preg_match( $widthRegex, $inner, $newmatch ) ) { $width = $newmatch[2]; } if ( preg_match( $heightRegex, $inner, $newmatch ) ) { $height = $newmatch[2]; } if ( ( $width && $width < ELEGANT_GRUNGE_FRAME_MIN_WIDTH ) || ( $height && $height < ELEGANT_GRUNGE_FRAME_MIN_HEIGHT ) ) { // Image is too small - just skip this one: return original content return $inner; } if ( $width && $width > ELEGANT_GRUNGE_FRAME_MAX_WIDTH ) { // Image is too large - scale down proportionately if ( $height ) { $ratio = $width / $height; $height = round(ELEGANT_GRUNGE_FRAME_MAX_WIDTH / $ratio); // Replace height value $inner = preg_replace( $heightRegex, "\${1}$height", $inner ); } $width = ELEGANT_GRUNGE_FRAME_MAX_WIDTH; // Replace width value $inner = preg_replace( $widthRegex, "\${1}$width", $inner ); } $small = ''; if ( ( $width && $width < ELEGANT_GRUNGE_FRAME_SMALL_WIDTH ) || ( $height && $height < ELEGANT_GRUNGE_FRAME_SMALL_HEIGHT ) ) { // Image is too small for the large frame - use the small frame $small = ' small'; } // Wrap content, and remove align/style from inner tag return '' . preg_replace(array("@${align}@is","@${style}@is"), '\\1', $inner). ''; } // Photoblog routines /** * Prepare image from post * * Scans post for images and sets a few variables on post object */ function image_setup($post) { if ( !preg_match("@(?:]+?)/?>\s*)?]+?)/?>(?:\s*)@", $post->post_content, $matches) ) { return; } if ( !preg_match_all("@(?P[a-zA-Z]+)(?:=([\"'])(?P.+?)\\2)@", $matches[2], $tag) ) { return; } $image = array_combine($tag["tag"], $tag["value"]); if ( $matches[1] && preg_match_all("@(?P[a-zA-Z]+)(?:=([\"'])(?P.+?)\\2)@", $matches[1], $tag) ) { $link = array_combine($tag["tag"], $tag["value"]); } if ( !$image["src"] ) return; $post->thumb_url = $post->image_url = clean_url( $image["src"], 'raw' ); $post->image_tag = $matches[0]; if ( $link["href"] && preg_match("/jpg|jpeg|jpe|png|gif/i", $link["href"]) ) { $post->image_url = $link["href"]; } $post->image_dimensions = array("width" => $image["width"], "height" => $image["height"]); $post->image_info = $image; $post->image_link_info = $link; $description = trim(strip_tags($post->post_content)); if ( strlen($description) > 250 ) $description = substr($description, 0, 250)."..."; $post->image_info["description"] = $description; } /** * Template tag: Get the image from the post * * @param return boolean If true, returns the image tag instead of printing it */ function the_image($return = null) { global $post; if(!$post->image_tag) { image_setup($post); } if ($return) return $post->image_tag; else echo $post->image_tag; } /** * Template tag: Get the image URL from the post * * @param return boolean If true, returns the image URL instead of printing it */ function the_image_url($return = null) { global $post; if(!$post->image_url) { image_setup($post); } if ($return) return $post->image_url; else echo $post->image_url; } /** * Template tag: Get the thumbnail URL from the post * * @param return boolean If true, returns the thumb URL instead of printing it */ function the_image_thumb_url($return = false) { global $post; if(!$post->thumb_url) { image_setup($post); } if ($return) return $post->thumb_url; else echo $post->thumb_url; } /** * Get post image information * * @returns Information about the image */ function the_image_info() { global $post; if(!$post->thumb_url) { image_setup($post); } return $post->image_info; } /** * Template tag: Determine if post has an image * * @returns True if an image exists, false otherwise */ function has_image() { return (the_image_info() != null); } /** * Template tag: Get the scaled thumbnail * * Attempts to create a new image derived from the original image and * scaled down to width x height. Will crop out of center of image if * aspect ratio does not match * * @param width int Width of thumbnail * @param height int Height of thumbnail * @returns Path to scaled thumbnail, or false on failure */ function the_image_scaled_thumb_url($width, $height) { global $post; $thumb = the_image_thumb_url(true); if ( !$thumb ) return false; if ( substr($thumb, 0, strlen(WP_CONTENT_URL)) == WP_CONTENT_URL ) { if ( file_exists($f = WP_CONTENT_DIR."/".substr($thumb, strlen(WP_CONTENT_URL))) ) $thumb = $f; } $path = "/elegant-grunge-thumbnails/".preg_replace("/[^a-zA-Z0-9]/", "-", $thumb)."-$width.$height.jpg"; if ( file_exists(WP_CONTENT_DIR."/".$path) ) { return clean_url(WP_CONTENT_URL."/".$path, 'raw'); } if ( !get_option('create_photoblog_thumbnails') ) return false; // Check for GD support if ( !function_exists('imagejpeg') ) return false; require_once("Image.class.php"); $image = Image::Load($thumb); if ( !$image ) return false; $image->Scale($width, $height, true); if ( !file_exists(WP_CONTENT_DIR."/elegant-grunge-thumbnails") ) { mkdir(WP_CONTENT_DIR."/elegant-grunge-thumbnails", 0755); } if ( !$image->Save(WP_CONTENT_DIR."/".$path) ) { return false; } return clean_url(WP_CONTENT_URL."/".$path, 'raw'); } /** * Template tag: Get the thumbnail * * @param width int Width of thumbnail (optional) * @param height int Height of thumbnail (optional) * @param return boolean If true, returns the thumb URL instead of printing it (optional) */ function the_thumbnail($width = 0, $height = 0, $return = false) { global $post; $url = the_image_url(true); if ( !$url ) return; $info = the_image_info(); if ( !$width && !$height ) { $width = 100; $height = 80; if ( $info["width"] && $info["height"] ) { if ( $info["width"] > $info["height"] ) { $height = 100; $width = ($info["width"] / $info["height"]) * $height; if ( $width > 300 ) { $width = 300; $height = ($info["height"] / $info["width"]) * $width; } } else { $height = 100; $width = ($info["width"] / $info["height"]) * $height; } } $width = round($width); $height = round($height); } else if ( $width && !$height ) { $height = (3/4) * $width; if ( $info["width"] && $info["height"] ) { $height = ($info["height"] / $info["width"]) * $width; } } $thumb = the_image_scaled_thumb_url($width, $height); if ( !$thumb ) $thumb = the_image_thumb_url(true); $link = (get_option('photoblog_lightbox') ? $url : get_permalink()); ob_start(); ?>

    Elegant Grunge

    />
    />
    />
    If enabled, all images larger than x will have a frame with drop shadow applied. Otherwise, only images and other elements with a class of 'frame' will have this style applied.
    This setting can be configured per-post and per-page, also.

    Separate multiple classes with commas ','

    This can be used to add extra RSS feed links from your page, for example, such as a Twitter feed.

    />
    If enabled, will generate thumbnail files. Otherwise, will use the original images, resulting in slower loading times. Note that the first photoblog page load after this is enabled will be slow, while images are being created, so you should load this yourself.


    x
    Leave blank for flexible size


    />
    Requires a lightbox plugin to be installed, such as Lightbox 2.

    />

    ID; } $frame_all_images = get_option("frame_all_images"); $frame_all_images_post = get_post_meta($post_id, 'frame_all_images', true); if ( $frame_all_images_post == "true" ) $frame_all_images = true; else if ( $frame_all_images_post == "false" ) $frame_all_images = false; ?>

    onchange="document.getElementById('eg_frame_all_images').value = (this.checked ? 'true' : 'false');" />
    If enabled, all images larger than x will have a frame with drop shadow applied. Otherwise, only images and other elements with a class of 'frame' will have this style applied.
    ID; } $frame_all_images = get_option("frame_all_images"); $frame_all_images_post = get_post_meta($post_id, 'frame_all_images', true); if ( $frame_all_images_post == "true" ) $frame_all_images = true; else if ( $frame_all_images_post == "false" ) $frame_all_images = false; $relatedTitle = get_post_meta($post_id, 'related_title', true); if ( !$relatedTitle ) $relatedTitle = "Related posts"; ?>

    onchange="document.getElementById('eg_frame_all_images').value = (this.checked ? 'true' : 'false');" />
    If enabled, all images larger than x will have a frame with drop shadow applied. Otherwise, only images and other elements with a class of 'frame' will have this style applied.

    If specified and 'Page with custom sidebar' page template is selected, will display posts from these tags in the sidebar. Specify multiple tags by separating with a comma ','.

    If 'Page with custom sidebar' page template is selected, and one or more related tags are provided above, this will be the title above a list of related posts.

    If 'Page with custom sidebar' page template is selected, this text/HTML will be displayed in the sidebar.
    '; foreach ( $thumbs as $thumb ) { echo $thumb; } echo ''; echo $args["after_widget"]; } function elegant_grunge_photoblog_setup() { $options = array("elegant_grunge_photoblog_heading", "elegant_grunge_photoblog_entries", "elegant_grunge_photoblog_order", "elegant_grunge_photoblog_tags", "elegant_grunge_photoblog_width", "elegant_grunge_photoblog_height"); foreach ( $options as $option ) { if ( isset($_REQUEST[$option]) ) { update_option($option, stripslashes($_REQUEST[$option])); } } ?>

    entries

    />
    />


    Separate multiple tags with commas