Matt
Forum Replies Created
-
I’m not familiar with that plugin. Did you try removing any “rel” tags from those images? Did you try doing both my last php and the Java code updates? Anything in the php error log?
Update to jqlb_do_regexp function / DOMDocument method in wp-jquery-lightbox.php. I was verifying that the img src had bmp|gif|jpg|jpeg|png but not that the actual href on the link was linking to one.
function jqlb_do_regexp($content, $id){ if (stripos($content, '<a') === FALSE) return $content; if (stripos($content, '<img') === FALSE) return $content; $id = esc_attr($id); if (version_compare(phpversion(), '5.0.0', '>=') && class_exists('DOMDocument')) { $write = FALSE; $dom = new DOMDocument; libxml_use_internal_errors(true); if ($dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD)) { $a_tags = $dom->getElementsByTagName('a'); if (!empty($a_tags->length)) { foreach ($a_tags as $a_tag) { $img_tags = $a_tag->getElementsByTagName('img'); if (!empty($a_tag->getAttribute('href')) && !empty($img_tags->length)) { $img_tag = $img_tags->item(0); if (preg_match("/^.+?\\.(?:bmp|gif|jpg|jpeg|png)/i", $a_tag->getAttribute('href')) && !empty($img_tag->getAttribute('src'))) { if ($a_tag->hasAttribute('rel')) { if (!preg_match("/(?:\\blightbox\\b|\\bnolb\\b|\\bnobox\\b|\\bnolightbox\\b)/i", $a_tag->getAttribute('rel'))) { $a_tag->setAttribute('rel', 'lightbox['.$id.'] '.$a_tag->getAttribute('rel')); $write = TRUE; } } else { $a_tag->setAttribute('rel', 'lightbox['.$id.']'); $write = TRUE; } } } } } } libxml_use_internal_errors(false); if ($write) $content = $dom->saveHTML(); } else { $a_tag_img_regex = "/(<a[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png)[^>]+)>/i"; if (preg_match_all($a_tag_img_regex, $content, $a_tag_matches, PREG_SET_ORDER)) { foreach ($a_tag_matches as $a_tag) { $new_a_tag = $a_tag[0]; $rel_regex = "/(rel=(['\"]))(?![^>]*?(?:\\blightbox\\b|\\bnolb\\b|\\bnobox\\b|\\bnolightbox\\b))(.+?)(\\2)/i"; $new_a_tag = preg_replace($rel_regex, '$1lightbox['.$id.'] $3$4', $new_a_tag); $no_rel_regex = "/(<a(?![^>]*?rel=['\"].+)[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png)[^>]+)>/i"; $new_a_tag = preg_replace($no_rel_regex, '$1 rel="lightbox['.$id.']">', $new_a_tag); if ($new_a_tag != $a_tag[0]) $content = str_replace($a_tag[0], $new_a_tag, $content); } } } return $content; }Forum: Plugins
In reply to: [Media Library Assistant] Basic pdf list with pdf iconsbtw, just got to trying the development version as well. Icons are now working on my search results. thanks
And here is a modification to jquery.lightbox.js to allow for grouping of lightboxed images with different rel attributes (as long as they both have “lightbox” or “lightbox[sameid]”).
First change is to the selector in the “
doLightBox()” function:
jQuery('a[rel*="lightbox"]').not( 'a[rel*="nolightbox"]' ).lightbox({Note this could inadvertantly select something with “ANYTEXTlightboxANYTEXT” other than “nolightbox” but I think since we are only targeting the rel tag it’s safe to use this. Unfortunately the jquery contains word selector only allows for whitespace around the word and won’t match “lightbox[##]”.
Second change is in the “
start(imageLink)” function. Snipit picks up a the$("a").each(function(){iteration statement:[...] $("a").each(function(){ if(!this.href || !this.rel || !imageLink.rel /*|| (this.rel != imageLink.rel)*/) { return; } var this_rel_arr = this.rel.split(" "); var imageLink_rel_arr = imageLink.rel.split(" "); var matched = false; match_loop: for (i = 0; i < this_rel_arr.length; i++) { if (this_rel_arr[i].indexOf('lightbox') > -1) { for (x = 0; x < imageLink_rel_arr.length; x++) { if (this_rel_arr[i] == imageLink_rel_arr[x]) { matched = true; break match_loop; } } } } if (!matched) return; var jqThis = $(this); [...]Pastebin of unminified file (jquery.lightbox.js): http://pastebin.com/b9Dx4RRA
Minified (jquery.lightbox.min.js): http://pastebin.com/ULwybZNB
Note: the plugin uses the minified file.
edited: 10:19 AM EST … forgot to check that the rel tag values I was matching against actually contained ‘lightbox’ ><
Alright so here is an updated function which includes a better regex for PHP < 5. If PHP if 5 or greater it will use the DOMDocument method. Below that it will use the regex method. I added word boundaries around lightbox/nobox/nolb and also added a “nolightbox” option. So now only “nolb”, “nobox” or “nolightbox” will prevent the auto-lightboxing.
function jqlb_do_regexp($content, $id){ if (stripos($content, '<a') === FALSE) return $content; if (stripos($content, '<img') === FALSE) return $content; $id = esc_attr($id); if (version_compare(phpversion(), '5.0.0', '>=') && class_exists('DOMDocument')) { $write = FALSE; $dom = new DOMDocument; libxml_use_internal_errors(true); if ($dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD)) { $a_tags = $dom->getElementsByTagName('a'); if (!empty($a_tags)) { foreach ($a_tags as $a_tag) { $images = $a_tag->getElementsByTagName('img'); $match = FALSE; if (!empty($images)) { foreach ($images as $image) { if ($image->hasAttribute('src')) { if (preg_match("/.+\\.(?:bmp|gif|jpg|jpeg|png)/i", $image->getAttribute('src'))) $match = TRUE; } } } if ($match) { if ($a_tag->hasAttribute('rel')) { if (!preg_match("/(?:\\blightbox\\b|\\bnolb\\b|\\bnobox\\b|\\bnolightbox\\b)/i", $a_tag->getAttribute('rel'))) { $a_tag->setAttribute('rel', 'lightbox['.$id.'] '.$a_tag->getAttribute('rel')); $write = TRUE; } } else { $a_tag->setAttribute('rel', 'lightbox['.$id.']'); $write = TRUE; } } } } } libxml_use_internal_errors(false); if ($write) $content = $dom->saveHTML(); } else { $a_tag_img_regex = "/(<a[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png)[^>]+)>/i"; if (preg_match_all($a_tag_img_regex, $content, $a_tag_matches, PREG_SET_ORDER)) { foreach ($a_tag_matches as $a_tag) { $new_a_tag = $a_tag[0]; $rel_regex = "/(rel=(['\"]))(?![^>]*?(?:\\blightbox\\b|\\bnolb\\b|\\bnobox\\b|\\bnolightbox\\b))(.+?)(\\2)/i"; $new_a_tag = preg_replace($rel_regex, '$1lightbox['.$id.'] $3$4', $new_a_tag); $no_rel_regex = "/(<a(?![^>]*?rel=['\"].+)[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png)[^>]+)>/i"; $new_a_tag = preg_replace($no_rel_regex, '$1 rel="lightbox['.$id.']">', $new_a_tag); if ($new_a_tag != $a_tag[0]) $content = str_replace($a_tag[0], $new_a_tag, $content); } } } return $content; }Yes I mentioned that DOMDocument is a PHP 5 requirement. There are probably some 3rd party classes that could be included and function reworked for PHP4 compatibility. I could enhance the regex solution to at least add a few more fail-safes.
Hate that you can’t edit after a certain period. Updated to account for UTF-8 characters:
function jqlb_do_regexp($content, $id){ if (empty($content)) return $content; $id = esc_attr($id); $img_regex = "/.+\\.(?:bmp|gif|jpg|jpeg|png)/i"; $lightbox_regex = "/(?:lightbox|\\bnolb\\b|\\bnobox\\b)/i"; $write = FALSE; $dom = new DOMDocument; libxml_use_internal_errors(true); if ($dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD)) { $a_tags = $dom->getElementsByTagName('a'); foreach ($a_tags as $a_tag) { $images = $a_tag->getElementsByTagName('img'); $match = FALSE; foreach ($images as $image) { if ($image->hasAttribute('src')) { if (preg_match($img_regex, $image->getAttribute('src'))) $match = TRUE; } } if ($match) { if ($a_tag->hasAttribute('rel')) { if (!preg_match($lightbox_regex, $a_tag->getAttribute('rel'))) { $a_tag->setAttribute('rel', 'lightbox['.$id.'] '.$a_tag->getAttribute('rel')); $write = TRUE; } } else { $a_tag->setAttribute('rel', 'lightbox['.$id.']'); $write = TRUE; } } } } libxml_use_internal_errors(false); if ($write) $content = $dom->saveHTML(); return $content; }What I posted bothered me a little because I know that parsing html with regex isn’t ideal and I know that the regex could fail in certain situations. For example, if the path of the link contains the text “nolb”, “lightbox” or “nobox” it would also cause the regex to fail because you can’t fullproof match only the rel attribute, at least not without extra steps. It’s really hard to fine tune regex for html parsing. The proper way is via dom parsing.
So alas, a better option. Requires PHP 5+ though. Not sure if that’s a problem or not.
function jqlb_do_regexp($content, $id){ if (empty($content)) return $content; $id = esc_attr($id); $img_regex = "/.+\\.(?:bmp|gif|jpg|jpeg|png)/i"; $lightbox_regex = "/(?:lightbox|\\bnolb\\b|\\bnobox\\b)/i"; $write = FALSE; $dom = new DOMDocument; libxml_use_internal_errors(true); if ($dom->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD)) { $a_tags = $dom->getElementsByTagName('a'); foreach ($a_tags as $a_tag) { $images = $a_tag->getElementsByTagName('img'); $match = FALSE; foreach ($images as $image) { if ($image->hasAttribute('src')) { if (preg_match($img_regex, $image->getAttribute('src'))) $match = TRUE; } } if ($match) { if ($a_tag->hasAttribute('rel')) { if (!preg_match($lightbox_regex, $a_tag->getAttribute('rel'))) { $a_tag->setAttribute('rel', 'lightbox['.$id.'] '.$a_tag->getAttribute('rel')); $write = TRUE; } } else { $a_tag->setAttribute('rel', 'lightbox['.$id.']'); $write = TRUE; } } } } libxml_use_internal_errors(false); if ($write) $content = $dom->saveHTML(); return $content; }Forum: Plugins
In reply to: [Media Library Assistant] Basic pdf list with pdf iconsDev version did not work for me. I’m not using mla_gallery though. My attachments aren’t being displayed through an mla_gallery though. I usually make use of the icon feature for my search results. I have attachments indexed in my search results (via relevanssi) and had always had icons for the attachments until now.
Forum: Plugins
In reply to: [Media Library Assistant] Basic pdf list with pdf iconsI also have the grey icons now. Enable MLA File Type Icons Support is checked. Worked before. I’m assuming a wordpress 4.4 issue?
Forum: Plugins
In reply to: [LightPress Lightbox] Dont work with WordPress 4.4?Forum: Plugins
In reply to: [LightPress Lightbox] Auto-Lightbox issue with WordPress 4.4Forum: Plugins
In reply to: [Cloudflare] 4.4 https rewritte aint working with imagesa++ Joe McGill
edit: Actually I don’t think you need to specify https in the set_url_scheme(). That would force everything to https. If you have your site setup to be dynamic simply remove the ‘https’ in the second argument.
so–
//wordpress 4.4 srcset ssl fix function ssl_srcset( $sources ) { foreach ( $sources as &$source ) { $source['url'] = set_url_scheme( $source['url'] ); } return $sources; } add_filter( 'wp_calculate_image_srcset', 'ssl_srcset' );Forum: Plugins
In reply to: [Media Library Assistant] Shortcode not working in (special) widgetYup works with the dev version. Thanks
Forum: Plugins
In reply to: [Media Library Assistant] Help with Field-level data sources markupNo that’s fine. I’ll go with options A and/or B. Thanks for the support.