{"id":448,"date":"2006-07-13T02:01:46","date_gmt":"2006-07-13T02:01:46","guid":{"rendered":"http:\/\/www.nargalzius.com\/blog2\/http:\/www.nargalzius.com\/blog2\/archives\/2006\/07\/2006_07_13_1001.php"},"modified":"2017-02-11T08:36:34","modified_gmt":"2017-02-11T08:36:34","slug":"lightboxing-and-flickr","status":"publish","type":"post","link":"http:\/\/nargalzius.com\/blog\/archives\/2006\/07\/13\/lightboxing-and-flickr","title":{"rendered":"Lightboxing and Flickr"},"content":{"rendered":"<div class=\"notice\">\n<p class=\"header\"><strong>NOTICE<\/strong><br>CONTENTS NO LONGER APPLICABLE<\/p>\n<p class=\"content\">The content discussed in this post is no longer valid; as I&#8217;m now using a different &#8220;lightbox&#8221; implementation.<br><a style=\"color:yellow\" href=\"http:\/\/nargalzius.com\/blog\/archives\/2008\/07\/31\/zoom-just-one-look\">More here<\/a><\/p><\/div>\n<p><a href=\"http:\/\/www.medina.ph\" title=\"Visit JC's site\">JC<\/a> made me check out his installation of a cool <a href=\"http:\/\/www.medina.ph\/?page_id=255\" title=\"View print gallery\">WordPress plugin<\/a> that does <a href=\"http:\/\/www.huddletogether.com\/projects\/lightbox2\/\" title=\"Lightbox 2.0\">lightboxing.<\/a> I decided to apply the same stuff in my blog &#8211; and modify it a bit to be able to link to the image&#8217;s <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> page <em>somewhat<\/em> dynamically.<\/p>\n<h2>Results<\/h2>\n<p>If you&#8217;re not interested in the details, then just spot the difference between these two lightbox-enabled links (I just hope it does work as I intended it to).<\/p>\n<p>Here&#8217;s an image which I linked to <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a><\/p>\n<p><a rel=\"lightbox\" href=\"http:\/\/static.flickr.com\/54\/182121733_f8659ad49c_o.png\" title=\"You may click on the image for more details\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/static.flickr.com\/54\/182121733_f8659ad49c_s.jpg\" \/><\/a><\/p>\n<p>Here&#8217;s an image which I linked to the <a href=\"http:\/\/www.nargalzius.com\/gallery\" title=\"View Gallery\">Gallery<\/a> within my domian<\/p>\n<h2>LINK REMOVED (as the old gallery doesn&#8217;t exist anymore)<\/h2>\n<p>If you noticed the difference, and <em>are<\/em> interested in how I did that &#8211; read on&#8230;<!--more--><a href=\"http:\/\/www.huddletogether.com\/projects\/lightbox2\/\" title=\"Lightbox 2.0\">lightbox<\/a>: <a href=\"http:\/\/www.huddletogether.com\/projects\/lightbox2\/\">http:\/\/www.huddletogether.com\/projects\/lightbox2\/<\/a> &#8220;Lightbox 2.0&#8221;<\/p>\n<h2><a href=\"http:\/\/www.huddletogether.com\/projects\/lightbox2\/\" title=\"Lightbox 2.0\">Lightbox 2.0<\/a><\/h2>\n<p>My first concern was that the <a href=\"http:\/\/www.huddletogether.com\/projects\/lightbox2\/\" title=\"Lightbox 2.0\">lightbox script<\/a> might require that all your files are locally hosted (meaning coming from the same domain &#8211; <em>your\/my<\/em> domain). Of course, given that I try to host my blog images in <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> now &#8211; that certainly will not do. To cut a long story short, it <em>can<\/em> load hotlinked images &#8211; and naturally my next instinct was to incorporate my <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> linking into the script. Which required a bit of hacking into the <code>js<\/code> file.<\/p>\n<p>Basically, the script (or collection of scripts to be more precise) checks out all <code>&lt;a&gt;<\/code> tags in a given page and checks if it has an attribute <code>rel=\"lightbox\"<\/code> &#8211; which is the trigger that it is a lightbox-enabled anchor. You&#8217;d normally use this with images, so the script is built to load images.<\/p>\n<p>so you have code like:<\/p>\n<pre><code>&lt;a rel=\"lightbox\" href=\"your_BIG_image_here\" title=\"optional_caption_here\"&gt;\n&lt;img src=\"your_SMALL_image_here\" alt=\"optional_data\" \/&gt;\n&lt;\/a&gt;<\/code><\/pre>\n<p>Which it will then create the lighbox instance for and grabs some data into the array. The one I paid attention to was <code>imageArray[activeImage][0]<\/code> &#8211; which was the <code>URL<\/code> of the [BIG] image\/or the <code>URL<\/code> in your lightbox anchor.<\/p>\n<p>Next was simply just to inject code that does this:<\/p>\n<ol>\n<li>check the <code>URL<\/code>, and strip it off the extraneous data, leaving the <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> ID alone, then reinserting it into a newly formed <code>URL<\/code> string.<\/li>\n<li>Add a link in the image caption to redirect to the images <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> page.<\/li>\n<li><strong>Do not<\/strong> do any of this when the <code>URL<\/code> <em>isn&#8217;t<\/em> from <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a>.<\/li>\n<\/ol>\n<p>It&#8217;s a simple enough task, the only problem is the parsing of the <code>URL<\/code>, matching a flickr <code>URL<\/code>, and converting it to the standard Flickr photo page image <code>URL<\/code>. The <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> image above uses <code>http:\/\/static.flickr.com\/54\/182121733_f8659ad49c_o.png<\/code> &#8211; which had to be converted to <code>http:\/\/www.flickr.com\/photos\/nargalzius\/182121733<\/code>. The answer was to use regular expressions.<\/p>\n<p>For #3, I used your typical <code>if\/else<\/code> to match a regular expression as <em>true<\/em> or <em>false.<\/em> I used <code>\/(.+flickr.+)\/i<\/code> which basically meant a case insensitive match which had the word &#8220;flickr&#8221; between any one or more characters &#8211; which obviously solved the detection of a flickr <code>URL<\/code>. If that tested as <em>true<\/em>, it then gets that <code>URL<\/code> and does a <code>replace<\/code> function using the JavaScript syntax:<\/p>\n<pre><code>imageArray[activeImage][0].replace(\/(http:\\\/\\\/static.flickr.com\\\/.+\\\/)(\\d+)(.+)\/g, \"http:\/\/www.flickr.com\/photos\/nargalzius\/$2\");<\/code><\/pre>\n<p>Which meant:<\/p>\n<ol>\n<li>Take the first value from the array (which is <code>http:\/\/static.flickr.com\/54\/182121733_f8659ad49c_o.png<\/code>)<\/li>\n<li>Match it to <code>\/(http:\\\/\\\/static.flickr.com\\\/.+\\\/)(\\d+)(.+)\/g<\/code> &#8211; which <em>further<\/em> meant\n<ul>\n<li>Match in groups: first group matches <code>http:\/\/www.static.flickr.com\/<\/code>, then any one or more characters which ending with a forward slash. This will incidentally match: <code>http:\/\/static.flickr.com\/54\/<\/code> as group 1.<\/li>\n<li>Second group matches any one or more <strong>digits<\/strong> &#8211; which will match <code>182121733<\/code><\/li>\n<li>Lastly, match any one or more characters as the third group <code>_f8659ad49c_o.png<\/code> (just to be safe and sure that underscore was delimited properly)<\/li>\n<\/ul><\/li>\n<li>Take that\/those match(es) and replace them with <code>http:\/\/www.flickr.com\/photos\/nargalzius\/<\/code> plus the data from the <em>second<\/em> group.<\/li>\n<\/ol>\n<p>And <em>voila!<\/em> you have an instant JavaScript <em>match and replace<\/em> of any valid <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> hotlinking <code>URL<\/code> &#8211; which is displayed in the caption. In case you haven&#8217;t noticed it yet, the <em>difference<\/em> between those two links are: for the <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a>, you should see a link at the bottom left of the image&#8230; to its respective <a href=\"http:\/\/www.flickr.com\/photos\/nargalzius\" title=\"View flickr page\">Flickr<\/a> page.<\/p>","protected":false},"excerpt":{"rendered":"<p>: http:\/\/www.flickr.com\/photos\/nargalzius &#8220;View flickr page&#8221; http:\/\/www.nargalzius.com\/gallery &#8220;View Gallery&#8221; NOTICECONTENTS NO LONGER APPLICABLE The content discussed in this post is no longer valid; as I&#8217;m now using a different &#8220;lightbox&#8221; implementation.More here JC made me check out his installation of a cool WordPress plugin that does lightboxing. I decided to apply the same stuff in my &hellip; <p class=\"link-more\"><a href=\"http:\/\/nargalzius.com\/blog\/archives\/2006\/07\/13\/lightboxing-and-flickr\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Lightboxing and Flickr&#8221;<\/span><\/a><\/p><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[5,9,13],"tags":[305,441,517,518,595,627,629,645,694,810],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-internet","category-nargalzius","category-technology","tag-css","tag-flickr","tag-hack","tag-hacking","tag-internet","tag-javascript","tag-jc","tag-js","tag-lightbox","tag-nargalzius"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":3,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"predecessor-version":[{"id":1890,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts\/448\/revisions\/1890"}],"wp:attachment":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}