From 002caeade736a250da0aa9da661269382dec808e Mon Sep 17 00:00:00 2001 From: aschweigert Date: Thu, 7 Jan 2016 10:52:26 -0500 Subject: [PATCH 1/2] remove picturefill until we actually decide to use it, tidy up a bit --- inc/images.php | 20 ++- .../inc/class-model-picturefill-wp.php | 152 ------------------ inc/picturefill/inc/class-picturefill-wp.php | 54 ------- .../inc/class-view-picturefill-wp.php | 90 ----------- .../templates/fallback-source-template.php | 1 - .../inc/templates/noscript-template.php | 1 - .../inc/templates/picture-template.php | 5 - .../inc/templates/source-template.php | 1 - inc/picturefill/js/libs/picturefill.js | 75 --------- inc/picturefill/js/libs/picturefill.min.js | 1 - inc/picturefill/picturefill-wp.php | 17 -- inc/picturefill/readme.txt | 97 ----------- 12 files changed, 12 insertions(+), 502 deletions(-) delete mode 100644 inc/picturefill/inc/class-model-picturefill-wp.php delete mode 100644 inc/picturefill/inc/class-picturefill-wp.php delete mode 100644 inc/picturefill/inc/class-view-picturefill-wp.php delete mode 100644 inc/picturefill/inc/templates/fallback-source-template.php delete mode 100644 inc/picturefill/inc/templates/noscript-template.php delete mode 100644 inc/picturefill/inc/templates/picture-template.php delete mode 100644 inc/picturefill/inc/templates/source-template.php delete mode 100644 inc/picturefill/js/libs/picturefill.js delete mode 100644 inc/picturefill/js/libs/picturefill.min.js delete mode 100644 inc/picturefill/picturefill-wp.php delete mode 100644 inc/picturefill/readme.txt diff --git a/inc/images.php b/inc/images.php index 76435db56..14d1050db 100644 --- a/inc/images.php +++ b/inc/images.php @@ -5,7 +5,7 @@ * * @param object the post content * @return object post content with image links stripped out - * @since 1.0 + * @since 0.1 */ function largo_attachment_image_link_remove_filter( $content ) { $content = @@ -20,23 +20,27 @@ function largo_attachment_image_link_remove_filter( $content ) { add_filter( 'the_content', 'largo_attachment_image_link_remove_filter' ); /** - * Load the picturefill.wp plugin + * Get the home icon for the sticky nav + * + * @param (string) $class any additional classes you would like to add to icon when returned + * @param (string) $size the size of the logo to return + * @return (string) markup for the sticky nav home icon (logo if available, otherwise just an icon) + * + * @since 0.4 */ -//require_once(get_template_directory() . '/inc/picturefill/picturefill-wp.php'); - if ( ! function_exists( 'largo_home_icon' ) ) { - function largo_home_icon( $class='', $size = '60x60' ) { + function largo_home_icon( $class = '', $size = '60x60' ) { global $wpdb; $logo = of_get_option( 'sticky_header_logo' ); $default = ''; if ( ! empty( $logo ) ) { - $attachment_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid = %s", $logo) ); - if (!empty($attachment_id)) + $attachment_id = $wpdb->get_var( $wpdb->prepare( 'SELECT ID FROM {$wpdb->posts} WHERE guid = %s', $logo ) ); + if ( !empty( $attachment_id ) ) echo wp_get_attachment_image( $attachment_id, $size ); else { - if (preg_match('/^http(s)?\:\/\//', $logo)) + if ( preg_match( '/^http(s)?\:\/\//', $logo ) ) echo ''; else echo $default; diff --git a/inc/picturefill/inc/class-model-picturefill-wp.php b/inc/picturefill/inc/class-model-picturefill-wp.php deleted file mode 100644 index b934555a8..000000000 --- a/inc/picturefill/inc/class-model-picturefill-wp.php +++ /dev/null @@ -1,152 +0,0 @@ -loadHTML('' . $html); - return $DOMDocument->getElementsByTagName('img'); - } - - // Constructor, set the object variables - public function __construct($DOMDocument, $image){ - require_once(ABSPATH . 'wp-admin/includes/image.php'); - $this->DOMDocument = $DOMDocument; - $this->image = $image; - $this->set_image_attributes(); - $this->set_image_attachment_data($this->image_attributes['attachment_id']); - $this->set_unadjusted_image_size(); - $this->set_image_sizes(); - } - - // Methods to retrieve object data - public function get_image_attributes(){ - return $this->image_attributes; - } - - public function get_image_attachment_data(){ - return $this->image_attachment_data; - } - - public function get_image_sizes(){ - return $this->image_sizes; - } - - public function get_image_xml(){ - return $this->DOMDocument->saveXML($this->image); - } - - // Methods to set object data - private function set_image_attributes(){ - $DOMDocument_image = $this->image; - - $attributes = array( - 'src' => $DOMDocument_image->getAttribute('src'), - 'alt' => $DOMDocument_image->getAttribute('alt'), - 'title' => $DOMDocument_image->getAttribute('title'), - 'class' => $DOMDocument_image->getAttribute('class'), - 'id' => $DOMDocument_image->getAttribute('id'), - 'width' => $DOMDocument_image->getAttribute('width'), - 'height' => $DOMDocument_image->getAttribute('height') - ); - - preg_match('/(?:(?:^|\s)size-)(\w+)/', $attributes['class'], $attributes['size']); - preg_match('/(?:(?:^|\s)wp-image-)(\w+)/', $attributes['class'], $attributes['attachment_id']); - preg_match('/(?:(?:^|\s)min-size-)(\w+)/', $attributes['class'], $attributes['min_size']); - - $this->image_attributes = $attributes; - } - - private function set_unadjusted_image_size(){ - if(!empty($this->image_attributes['attachment_id'])){ - if(empty($this->image_attributes['size'])){ - $this->image_attributes['size'] = $this->get_unadjusted_size($this->image_attachment_data, $this->image_attributes['src']); - } - } - - } - - private function set_image_attachment_data($attachment_id){ - if(!empty($attachment_id)){ - $image_attachment_data = array( - 'full' => wp_get_attachment_image_src($attachment_id[1], 'full'), - 'thumbnail' => wp_get_attachment_image_src($attachment_id[1], 'thumbnail'), - 'thumbnail@2x' => wp_get_attachment_image_src($attachment_id[1], 'thumbnail@2x'), - 'medium' => wp_get_attachment_image_src($attachment_id[1], 'medium'), - 'medium@2x' => wp_get_attachment_image_src($attachment_id[1], 'medium@2x'), - 'large' => wp_get_attachment_image_src($attachment_id[1], 'large'), - 'large@2x' => wp_get_attachment_image_src($attachment_id[1], 'large@2x') - ); - - foreach($image_attachment_data as $attachment_size => $attachment_data){ - if($image_attachment_data['full'][0] === $attachment_data[0] && $image_attachment_data['full'][1] > $attachment_data[1] && $image_attachment_data['full'][2] > $attachment_data[2]){ - $new_meta_data = wp_generate_attachment_metadata($attachment_id, get_attached_file($attachment_id)); - wp_update_attachment_metadata($attachment_id, $new_meta_data); - $image_attachment_data[$attachment_size] = wp_get_attachment_image_src($attachment_id, $attachment_size); - } - } - - $this->image_attachment_data = $image_attachment_data; - }else{ - $this->image_attachment_data = false; - } - } - - private function get_unadjusted_size($image_attachment_data, $src){ - foreach($image_attachment_data as $attachment_size => $attachment_data){ - if($attachment_data[0] === $src){ - return array('adjusted', $attachment_size); - } - } - return false; - } - - private function set_image_sizes(){ - $image_attributes = $this->image_attributes; - $image_sizes = array( - 'full', - 'large@2x', - 'large', - 'medium@2x', - 'medium', - 'thumbnail@2x', - 'thumbnail' - ); - - if(!empty($image_attributes['size'])){ - foreach($image_sizes as $size){ - if($image_attributes['size'][1] === $size || $image_attributes['size'][1] . '@2x' === $size){ - break; - } - array_shift($image_sizes); - } - - $image_sizes = array_reverse($image_sizes); - - if(!empty($image_attributes['min_size'])){ - foreach($image_sizes as $size){ - if($image_attributes['min_size'][1] === $size){ - break; - } - array_shift($image_sizes); - } - } - - $this->image_sizes = $image_sizes; - } - } - } -} diff --git a/inc/picturefill/inc/class-picturefill-wp.php b/inc/picturefill/inc/class-picturefill-wp.php deleted file mode 100644 index 7b58f212b..000000000 --- a/inc/picturefill/inc/class-picturefill-wp.php +++ /dev/null @@ -1,54 +0,0 @@ -length > 0){ - require_once(PICTUREFILL_WP_PATH . 'inc/class-view-picturefill-wp.php'); - wp_enqueue_script('picturefill'); - $html = View_Picturefill_WP::standardize_img_tags($html); - foreach($images as $image){ - $model_picturefill_wp = new Model_Picturefill_WP($DOMDocument, $image); - $view_picturefill_wp = new View_Picturefill_WP($model_picturefill_wp); - - $html = str_replace($view_picturefill_wp->get_original_image(), $view_picturefill_wp->render_template('picture'), $html); - } - } - return $html; - } - - public function add_image_sizes(){ - add_image_size('thumbnail@2x', get_option('thumbnail_size_w') * 2, get_option('thumbnail_size_h') * 2, get_option('thumbnail_crop')); - add_image_size('medium@2x', get_option('medium_size_w') * 2, get_option('medium_size_h') * 2, get_option('medium_crop')); - add_image_size('large@2x', get_option('large_size_w') * 2, get_option('large_size_h') * 2, get_option('large_crop')); - } - } -} diff --git a/inc/picturefill/inc/class-view-picturefill-wp.php b/inc/picturefill/inc/class-view-picturefill-wp.php deleted file mode 100644 index 06d3015ec..000000000 --- a/inc/picturefill/inc/class-view-picturefill-wp.php +++ /dev/null @@ -1,90 +0,0 @@ -|\/>|\s\/>)/', '$1 />', $html); - } - - // Constructor, get data from model object - public function __construct($model_picturefill_wp){ - $this->original_image = html_entity_decode(self::standardize_img_tags($model_picturefill_wp->get_image_xml()), ENT_COMPAT, 'UTF-8'); - $this->image_attributes = $model_picturefill_wp->get_image_attributes(); - $this->image_attachment_data = $model_picturefill_wp->get_image_attachment_data(); - $this->image_sizes = $model_picturefill_wp->get_image_sizes(); - } - - // Methods to render data in the templates - public function generate_source_list(){ - $output = ''; - $template_data = array(); - $image_output_queue = $this->image_sizes; - - while(!empty($image_output_queue)){ - $image_size = array_shift($image_output_queue); - $template_data['image_size'] = $image_size; - $output .= $this->render_template('source', $template_data); - } - - return $output; - } - - public function get_picture_attribute_string(){ - $image_attributes = $this->image_attributes; - - $output_string = ''; - - foreach($image_attributes as $attribute => $value){ - $output_string .= !empty($value) && !is_array($value) ? ' data-' . $attribute . '="' . html_entity_decode($value, ENT_COMPAT, 'UTF-8') . '"' : ''; - } - - return $output_string; - } - - public function get_original_image_src(){ - return $this->image_attributes['src']; - } - - public function get_original_image(){ - return $this->original_image; - } - - public function get_image_src($image_size){ - return $this->image_attachment_data[$image_size][0]; - } - - public function get_image_width($image_size){ - return $image_size === $this->image_attributes['size'][1] ? $this->image_attributes['width'] : $this->image_attachment_data[$image_size][1]; - } - - public function get_image_height($image_size){ - return $image_size === $this->image_attributes['size'][1] ? $this->image_attributes['height'] : $this->image_attachment_data[$image_size][2]; - } - - public function get_media_query($image_size){ - $width = $image_size === $this->image_attributes['size'][1] ? $this->image_attributes['width'] : $this->image_attachment_data[$image_size][1]; - $breakpoint = 'thumbnail' === $image_size || 'thumbnail@2x' === $image_size ? 1 : $width + 20; - $resolution_query = '@2x' === substr($image_size, -3) ? ' and (-webkit-min-device-pixel-ratio: 1.5),(min-resolution: 144dpi),(min-resolution: 1.5dppx)' : ''; - return '(min-width: ' . $breakpoint . 'px)' . $resolution_query; - } - - // Render templates - public function render_template($template, $template_data = array()){ - $template = PICTUREFILL_WP_PATH . 'inc/templates/' . $template . '-template.php'; - $view_picturefill_wp = $this; - if(!empty($template_data)){ - extract($template_data); - } - ob_start(); - include($template); - return ob_get_clean(); - } - } -} diff --git a/inc/picturefill/inc/templates/fallback-source-template.php b/inc/picturefill/inc/templates/fallback-source-template.php deleted file mode 100644 index f4f6d19fe..000000000 --- a/inc/picturefill/inc/templates/fallback-source-template.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/inc/picturefill/inc/templates/noscript-template.php b/inc/picturefill/inc/templates/noscript-template.php deleted file mode 100644 index 1030fd558..000000000 --- a/inc/picturefill/inc/templates/noscript-template.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/inc/picturefill/inc/templates/picture-template.php b/inc/picturefill/inc/templates/picture-template.php deleted file mode 100644 index d4a9044db..000000000 --- a/inc/picturefill/inc/templates/picture-template.php +++ /dev/null @@ -1,5 +0,0 @@ -get_picture_attribute_string(); ?>> - render_template('fallback-source'); ?> - generate_source_list(); ?> - render_template('noscript'); ?> - diff --git a/inc/picturefill/inc/templates/source-template.php b/inc/picturefill/inc/templates/source-template.php deleted file mode 100644 index b85254535..000000000 --- a/inc/picturefill/inc/templates/source-template.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/inc/picturefill/js/libs/picturefill.js b/inc/picturefill/js/libs/picturefill.js deleted file mode 100644 index 3b65bb31a..000000000 --- a/inc/picturefill/js/libs/picturefill.js +++ /dev/null @@ -1,75 +0,0 @@ -/*! Picturefill - Responsive Images that work today. (and mimic the proposed Picture element with divs). Author: Scott Jehl, Filament Group, 2012 | License: MIT/GPLv2 */ - -(function( w ){ - - // Enable strict mode - "use strict"; - - w.picturefill = function() { - var ps = w.document.getElementsByTagName( "span" ); - - // Loop the pictures - for( var i = 0, il = ps.length; i < il; i++ ){ - if( ps[ i ].getAttribute( "data-picture" ) !== null ){ - - var sources = ps[ i ].getElementsByTagName( "span" ), - matches = []; - - // See if which sources match - for( var j = 0, jl = sources.length; j < jl; j++ ){ - var media = sources[ j ].getAttribute( "data-media" ); - // if there's no media specified, OR w.matchMedia is supported - if( !media || ( w.matchMedia && w.matchMedia( media ).matches ) ){ - matches.push( sources[ j ] ); - } - } - - // Find any existing img element in the picture element - var picImg = ps[ i ].getElementsByTagName( "img" )[ 0 ]; - - if( matches.length ){ - if( !picImg ){ - picImg = w.document.createElement( "img" ); - picImg.id = ps[ i ].getAttribute( "data-id" ); - picImg.className = ps[ i ].getAttribute( "data-class" ); - picImg.alt = ps[ i ].getAttribute( "data-alt" ); - picImg.title = ps[ i ].getAttribute( "data-title" ); - if(ps[i].getAttribute("data-width")){ - picImg.width = ps[ i ].getAttribute( "data-width" ); - } - if(ps[i].getAttribute("data-height")){ - picImg.height = ps[ i ].getAttribute( "data-height" ); - } - ps[ i ].appendChild( picImg ); - } - - if(matches[matches.length -1].getAttribute( "data-width" )){ - picImg.width = matches[matches.length -1].getAttribute( "data-width" ); - } - if(matches[matches.length -1].getAttribute( "data-height" )){ - picImg.height = matches[matches.length -1].getAttribute( "data-height" ); - } - picImg.src = matches.pop().getAttribute( "data-src" ); - } - else if( picImg ){ - ps[ i ].removeChild( picImg ); - } - } - } - }; - - // Run on resize and domready (w.load as a fallback) - if( w.addEventListener ){ - w.addEventListener( "resize", w.picturefill, false ); - w.addEventListener( "DOMContentLoaded", function(){ - w.picturefill(); - // Run once only - w.removeEventListener( "load", w.picturefill, false ); - }, false ); - w.addEventListener( "load", w.picturefill, false ); - } - else if( w.attachEvent ){ - w.attachEvent( "onload", w.picturefill ); - } - -}( this )); diff --git a/inc/picturefill/js/libs/picturefill.min.js b/inc/picturefill/js/libs/picturefill.min.js deleted file mode 100644 index ab00b73a2..000000000 --- a/inc/picturefill/js/libs/picturefill.min.js +++ /dev/null @@ -1 +0,0 @@ -(function(a){"use strict";a.picturefill=function(){for(var b=a.document.getElementsByTagName("span"),c=0,d=b.length;d>c;c++)if(null!==b[c].getAttribute("data-picture")){for(var e=b[c].getElementsByTagName("span"),f=[],g=0,h=e.length;h>g;g++){var i=e[g].getAttribute("data-media");(!i||a.matchMedia&&a.matchMedia(i).matches)&&f.push(e[g])}var j=b[c].getElementsByTagName("img")[0];f.length?(j||(j=a.document.createElement("img"),j.id=b[c].getAttribute("data-id"),j.className=b[c].getAttribute("data-class"),j.alt=b[c].getAttribute("data-alt"),j.title=b[c].getAttribute("data-title"),b[c].getAttribute("data-width")&&(j.width=b[c].getAttribute("data-width")),b[c].getAttribute("data-height")&&(j.height=b[c].getAttribute("data-height")),b[c].appendChild(j)),f[f.length-1].getAttribute("data-width")&&(j.width=f[f.length-1].getAttribute("data-width")),f[f.length-1].getAttribute("data-height")&&(j.height=f[f.length-1].getAttribute("data-height")),j.src=f.pop().getAttribute("data-src")):j&&b[c].removeChild(j)}},a.addEventListener?(a.addEventListener("resize",a.picturefill,!1),a.addEventListener("DOMContentLoaded",function(){a.picturefill(),a.removeEventListener("load",a.picturefill,!1)},!1),a.addEventListener("load",a.picturefill,!1)):a.attachEvent&&a.attachEvent("onload",a.picturefill)})(this); \ No newline at end of file diff --git a/inc/picturefill/picturefill-wp.php b/inc/picturefill/picturefill-wp.php deleted file mode 100644 index acd1bc4f5..000000000 --- a/inc/picturefill/picturefill-wp.php +++ /dev/null @@ -1,17 +0,0 @@ -` elements like this: - - Accessible alternate text for the image - -then replaces them with something like this: - - - - - - - - - - - - -The adapted version of picturefill.js then looks for the last `data-src` listed where the associated `data-media` matches the device and browser, and loads the appropriate image inside the parent `` element. - -###Heights and Widths and Breakpoints - -One of the goals of this plugin is to be completely "plug and play" i.e. no setup and no options. Just turn it on and it works. To do this, the plugin relies on several Wordpress defaults and conventions. - -####Wordpress Image Sizes - -By default, Wordpress creates as many as 3 images of different sizes for each uploaded image ("large", "medium", and "thumbnail"), in addition to the "full" image size. - -This plugin adds responsive breakpoints based on the width of the image. The largest available image will display unless the browser width is less than the image width + 20px, in which case the next size down is displayed. - -To use this plugin most effectively, set the default image sizes ("large", "medium", and "thumbnail") to reflect useful breakpoints in your theme design. - -####Wordpress Image Classes - -This plugin uses the default Wordpress image class `wp-image-{image id}` as a source of information. It will not work effectively if this class is removed. The original image will still be loaded, but it will not be responsive. - -The responsiveness of an image can be limited by adding the class `min-size-{image size}`. For example, an image with the class `min-size-medium` will not load an image smaller than size `medium`. - -== Installation == - -1. First, make sure that the image sizes set in your media settings reflect useful breakpoints in your design. -2. Upload the plugin folder to the `/wp-content/plugins/` directory -3. Activate the plugin through the 'Plugins' menu in WordPress - -== Frequently Asked Questions == - -= Where are the plugin options? = - -There aren't any. Breakpoints, as well as retina and responsive images are created based on the image sizes in your media settings. - -= Is this plugin on GitHub? = - -Yes it is. [Picturefill.WP](https://github.com/kylereicks/picturefill.js.wp) - -== Screenshots == - -== Changelog == - -= 1.1.3 = -* Correct encoding bug - -= 1.1.2 -* Reorganized code and file structure - -= 1.1.1 -* Bug-fix to allow special characters in `title` and `alt` attributes. - -= 1.1 -* Allow for responsive images for non-standard sizes -* Add a `min-size` class to limit the resposiveness of an image. - -= 1.0 = -* Release 1.0. - -== Upgrade Notice == - -= 1.1.3 = -This update corrects an encoding bug in the last update that caused problems < PHP 5.3. From 2596dcf75b1a11f4c94348d719446a72308d702c Mon Sep 17 00:00:00 2001 From: Ryan Nagle Date: Thu, 7 Jan 2016 11:54:48 -0600 Subject: [PATCH 2/2] doc block must immediately precede the function it documents --- inc/images.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/inc/images.php b/inc/images.php index 14d1050db..eb6e1551b 100644 --- a/inc/images.php +++ b/inc/images.php @@ -19,16 +19,16 @@ function largo_attachment_image_link_remove_filter( $content ) { } add_filter( 'the_content', 'largo_attachment_image_link_remove_filter' ); -/** - * Get the home icon for the sticky nav - * - * @param (string) $class any additional classes you would like to add to icon when returned - * @param (string) $size the size of the logo to return - * @return (string) markup for the sticky nav home icon (logo if available, otherwise just an icon) - * - * @since 0.4 - */ if ( ! function_exists( 'largo_home_icon' ) ) { + /** + * Get the home icon for the sticky nav + * + * @param (string) $class any additional classes you would like to add to icon when returned + * @param (string) $size the size of the logo to return + * @return (string) $result markup for the sticky nav home icon (logo if available, otherwise just an icon) + * + * @since 0.4 + */ function largo_home_icon( $class = '', $size = '60x60' ) { global $wpdb;