Topic: How to avoid massive downloads from Flickr.

Hello, I both the pro plugin.
I have a photo blog, and I use the plugin to play/grab images from my Flickr account.
I use this string on post:(example) [juicebox gallery_id="4"]

My home page on source show these codes:
<!--START JUICEBOX EMBED.-->
<script type="text/javascript">
    new juicebox({
        backgroundColor : 'rgba(255, 255, 255, 1.0)',
        containerId : 'juicebox-container4',
        configUrl : 'http://www.mysite.com/wp-content/uploads/juicebox/4.xml',
        galleryHeight : '650px',
        galleryWidth : '100%'
    });
</script>
<div id="juicebox-container4"></div>
<!--END JUICEBOX EMBED.--></p>

I tried different themes, Twenty Ten and Twenty Eleven included.

ISSUE:
The behavior of the plugin is not as i thought to have.
My home page show about 15/20 posts with just the featured image as thumbnail.

In each of them I grab from Flickr about 20/30 images.
My Home Page have about 20 post presentation.
Actually on my home page the plugin, for some reasons i don't know, download about 150/180 images in one shot even if nobody open any post as a single page. Iit seems absurd this function.

Usually a right behavior should be to download the images of the "POST A" when the "POST A" is open (click/user-action).
The plugin don't follow this way. It download all the photos of each post, even if, is not open as a single page.

This is a big problem for me because i have a photo blog!
My home page is became very very slow with more of 5 mega of data and 180 different call/urls!

Could you help me to fix this issue?
My wish should be to have the plugin working only if the relative post with the photo gallery is open from the user.

Hope you can help me.
Regards, Giadina

Re: How to avoid massive downloads from Flickr.

No matter where WordPress displays a post containing a Juicebox gallery (whether it is on an overview page along with other posts or on a page of its own), the shortcode within the post (e.g. [juicebox gallery_id="4"]) will be processed and the gallery will be displayed.
You can override this behavior by modifying the plugin's 'wp-juicebox.php' file. Open 'wp-juicebox.php' in a plain text editor and replace the shortcode_handler() function (lines 1052 - 1106 inclusive) with the following:

    function shortcode_handler($atts) {
        extract(shortcode_atts(array('gallery_id'=>'0'), $atts));
        if (is_singular()) {
            if ($gallery_id != 0) {

                $gallery_filename = $this->get_gallery_path() . $gallery_id . '.xml';

                if (file_exists($gallery_filename)) {

                    $dom_doc = new DOMDocument();
                    $dom_doc->load($gallery_filename);

                    $settings_tags = $dom_doc->getElementsByTagName('juiceboxgallery');
                    $settings_tag = $settings_tags->item(0);

                    $gallery_width = $settings_tag->getAttribute('e_galleryWidth');
                    $gallery_height = $settings_tag->getAttribute('e_galleryHeight');
                    $background_color = $settings_tag->getAttribute('e_backgroundColor');
                    $background_opacity = $settings_tag->getAttribute('e_backgroundOpacity');
                    $background_rgba = $this->get_rgba($background_color, $background_opacity);

                    if ($gallery_width == '') {
                        $gallery_width = '100%';
                    }

                    if ($gallery_height == '') {
                        $gallery_height = '600px';
                    }

                    $upload_dir = wp_upload_dir();
                    $gallery_filename = $upload_dir['baseurl'] . '/juicebox/' . $gallery_id . '.xml';

return <<<EOF
<!--START JUICEBOX EMBED.-->
<script type="text/javascript">
    new juicebox({
        backgroundColor : '$background_rgba',
        containerId : 'juicebox-container$gallery_id',
        configUrl : '$gallery_filename',
        galleryHeight : '$gallery_height',
        galleryWidth : '$gallery_width'
    });
</script>
<div id="juicebox-container$gallery_id"></div>
<!--END JUICEBOX EMBED.-->
EOF;

                } else {
                    return '<div><p>WP-Juicebox Gallery Id ' . $gallery_id . ' has been deleted.</p></div>';
                }
            } else {
                return '<div><p>WP-Juicebox Gallery Id cannot be found.</p></div>';
            }
        } else {
            return '<div><p>Open post to view WP-Juicebox Gallery Id ' . $gallery_id . '.</p></div>';
        }
    }
}

Save the file and re-upload it to its original location ('wp-content/plugins/wp-juicebox/wp-juicebox.php') overwriting the original file.

3 (edited by portofinoworld 2012-09-30 13:43:48)

Re: How to avoid massive downloads from Flickr.

Hi Steven,
Thanks a lot for your support.
The script now don't download everything on the home page.

Please take a look to: http://www.yoursite.com/
Open "Parigi: Guy Laroche en bleu" the second post.

This Theme work with a popup system and with a traditional post page.
On the popup I receive: Open post to view WP-Juicebox Gallery Id 4.

If you reach the post trough a traditional post page at:
http://www.yoursite.com/parigi/parigi-g … he-en-bleu

You will see the gallery. Actually have some issues I am working to fix.
Don't worry about this, I tried to see the post in the Default WP Theme and looks and work fine.
So, I think I need to find a solution for my theme.

THE QUESTION:
Do you have some tricks/tips to have on the popup the gallery run?
I mean at the place of "Open post to view WP-Juicebox Gallery Id 4."
Have the gallery showed. It seems the behavior it's like this, because for some reason there is not a embed code.

Steven, i understand if you request me a development cost to fix this.
Or maybe do you have some "right direction" on how to fix it.

Thank you for your strong support.
Regards,
Giadina

Re: How to avoid massive downloads from Flickr.

WordPress will either parse the Juicebox shortcode and display the gallery or not. In a traditional WordPress theme (with no pop-ups), my code above will display the gallery when the post is viewed on its own page but will not display the gallery on the main overview page.
WordPress does not seem to classify your pop-up as being the post's own page (as the is_singular() method returns 'false' when the post is viewed in your pop-up).
Rather than try to determine whether or not the code is being parsed within your pop-up (and display the gallery if it is), you could instead try to prevent the Juicebox shortcode from being processed on your main overview page by changing the following code in the shortcode_handler() method (from the 'wp-juicebox.php' file) that I posted above.
Change:

if (is_singular()) {

to:

$pageURL = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
if ($pageURL != "www.alexis.it/") {

Re: How to avoid massive downloads from Flickr.

Steven,

I am sorry, believe me, I have not found the place where to add the code.
I thought on function.php theme/wp but is not there.

I am starting to think that maybe could be into the header.php go the home page.

However I found two conditional tag, it seems in this theme is not present the: if (is_singular()) {
I found this on the twenty ten/header.php

On my header I have:

line 5: <?php if (is_page() || is_single()) { global $post; ?>
line 39: <?php if (is_page() || is_single()) { ?>

So the question is:
I add a complete new code line:
$pageURL = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
if ($pageURL != "www.alexis.it/") {

I suppose it will need to have some more code at the start and end on this.

Thank you for your help.
Maybe can I send you a coffee though paypal?

Regards,
Giadina

Re: How to avoid massive downloads from Flickr.

Steven,
Ok, I got it.
Is in wp_include query.php correct?

Re: How to avoid massive downloads from Flickr.

Steven,
Listen, I think, if you can, that if you tell me where I have to place the code will be better...
Not sure if it's on query.php.

Sorry Steven,
I know this is not your job..
Thank you,
regards,
Giadina

Re: How to avoid massive downloads from Flickr.

Steven,
tell me do you refer to the wp-juicebox.php ?
The code you suggested me above?

I mean in wp-juicebox.php

Change the start code from

---
function shortcode_handler($atts) {
        extract(shortcode_atts(array('gallery_id'=>'0'), $atts));
        if (is_singular()) {
            if ($gallery_id != 0) {

                $gallery_filename = $this->get_gallery_path() . $gallery_id . '.xml';

                if (file_exists($gallery_filename)) {
----

to:

----
function shortcode_handler($atts) {
        extract(shortcode_atts(array('gallery_id'=>'0'), $atts));
        $pageURL = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
if ($pageURL != "www.alexis.it/") {
            if ($gallery_id != 0) {

                $gallery_filename = $this->get_gallery_path() . $gallery_id . '.xml';

                if (file_exists($gallery_filename)) {

----

I tried this, but it seems don't work.
I probably forgot some code...

Thank you for your help.
Regards,

Giadina :)

Re: How to avoid massive downloads from Flickr.

The latest code you posted is correct, replacing the if (is_singular()) { line in the shortcode_handler() method in the 'wp-juicebox.php' file. Try removing the trailing slash from the "www.alexis.it/" part of the code.
It may not work with all web servers but the solution to your problem lies with finding a conditional expression to replace if (is_singular()) { with such that the Juicebox shortcode will not be processed on your main overview page.

I would need access to your web server to test what is actually returned by using the different $_SERVER elements so trial and error may be required.

Re: How to avoid massive downloads from Flickr.

Hello Steven,
I really appreciate your support, very strong.
Listen how I can give you the access in private mode?

thank you,
Giadina

11 (edited by portofinoworld 2012-09-30 13:44:20)

Re: How to avoid massive downloads from Flickr.

Hi Steven,

i tried without the final slash.
$pageURL = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
if ($pageURL != "www.yoursite.com") {

In this case the plugin download  all the images on the home page.
They appear also on the popup.

We need to find the right:  conditional expression as you said.
tell me where I can send you the login access.

Thank you,
Regards,
Giadina

Re: How to avoid massive downloads from Flickr.

From what you have said, it sounds like your pop-up is still classed as being your main overview page and, as such, blocking the shortcode from running on one will also block it from running on the other. There may be no easy solution. However, please check your email. I have sent you a message with an email address where you can provide me with your web server and WordPress login details if you like.

Re: How to avoid massive downloads from Flickr.

Hi Steven,

I have done (sent).
Incredible support. The only one to give this kind of attentions.
Very good, Thank you,

Regards,
Giadina.

Re: How to avoid massive downloads from Flickr.

Correspondence continued via email.
For the sake of completeness and for others following this thread, I will post my replies in this forum thread also.

Re: How to avoid massive downloads from Flickr.

Thank you for providing your login details. (I have left everything as I found it.)

Having run a few tests, I can confirm that as far as your server is concerned, your main page and your pop-up window are one and the same page and they cannot be distinguished using $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] as the same value is returned for each.
I have also tried $_SERVER["HTTP_REFERER"] and $_SERVER["PHP_SELF"] but to no avail.

As there is no way to check using PHP whether the shortcode_handler() function is being run inside a frame or pop-up window, the only other possible solution I can think of at the moment is to:
(1) Disable processing of the Juicebox shortcode by default.
(2) Pass a query string variable in the URL to be opened by your pop-up window.
(3) Check (within the shortcode_handler() function) to see if the variable is present and process the shortcode if it is.

This would require that you change your shortcode_handler() conditional to the following:

if (is_singular() || $_GET['jb'] == true) {

... and you would also have to ensure that your pop-up window links are changed from:

<a href="http://www.alexis.it/fashion-week/parigi/parigi-guy-laroche-en-bleu" rel="#pin-1622" class="whitebox">

... to:

<a href="http://www.alexis.it/fashion-week/parigi/parigi-guy-laroche-en-bleu?jb=true" rel="#pin-1622" class="whitebox">

If the code that generated the links currently look like this:

<a href="<?php the_permalink(); ?>" rel="#pin-<?php the_ID(); ?>

... then change it to:

<a href="<?php the_permalink(); ?>?jb=true" rel="#pin-<?php the_ID(); ?>

This solution should work fine.
I do not know where the code for your links is generated within your theme but I tested it on your main page and it works as expected.

With regard to the CSS clashes resulting in odd formatting of your galleries, currently the only solution (other than changing the CSS within your theme) would be to create your galleries on your computer (i.e. not using WP-Juicebox) and then embed them in iframes as I have previously suggested.

Re: How to avoid massive downloads from Flickr.

Hello.

I have taken a look at your code and all seems OK. However, as you have discovered, it does not seem to work.
When clicking on a link, the URL in the browser's address bar changes to reflect the link but the query string is not passed to the pop-up window.
If you paste the URL directly into the address bar, the query string is passed to the pop-up window as expected.
There seems to be no way to distinguish between your home page and a page within your pop-up window using either PHP techniques (such as $_SERVER elements) or WordPress techniques (such as the is_home() method) as everything I have tried returns the same value on your home page as it does in the pop-up window. Both techniques work fine on my own web server using the default WordPress theme.

Only JavaScript is able to determine the URL of the page being displayed in the pop-up window so rather than try to prevent the shortcode from being processed on your home page, it looks like the only solution would be to allow the shortcode to be processed on all pages (and for Juicebox embedding code to be present on all pages) but to prevent the Juicebox embedding code from being executed on your home page by wrapping the Juicebox embedding code in a JavaScript conditional which is true only in the pop-up window.

Use the following as the shortcode_handler() method in your 'wp-juicebox.php' file:

function shortcode_handler($atts) {
        extract(shortcode_atts(array('gallery_id'=>'0'), $atts));
        if ($gallery_id != 0) {
            $gallery_filename = $this->get_gallery_path() . $gallery_id . '.xml';
            if (file_exists($gallery_filename)) {
                $dom_doc = new DOMDocument();
                $dom_doc->load($gallery_filename);
                $settings_tags = $dom_doc->getElementsByTagName('juiceboxgallery');
                $settings_tag = $settings_tags->item(0);
                $gallery_width = $settings_tag->getAttribute('e_galleryWidth');
                $gallery_height = $settings_tag->getAttribute('e_galleryHeight');
                $background_color = $settings_tag->getAttribute('e_backgroundColor');
                $background_opacity = $settings_tag->getAttribute('e_backgroundOpacity');
                $background_rgba = $this->get_rgba($background_color, $background_opacity);
                if ($gallery_width == '') {
                    $gallery_width = '100%';
                }
                if ($gallery_height == '') {
                    $gallery_height = '600px';
                }
                $upload_dir = wp_upload_dir();
                $gallery_filename = $upload_dir['baseurl'] . '/juicebox/' . $gallery_id . '.xml';
return <<<EOF
<!--START JUICEBOX EMBED.-->
<script type="text/javascript">
if (window.location.href != 'http://www.alexis.it/') {
    new juicebox({
        backgroundColor : '$background_rgba',
        containerId : 'juicebox-container$gallery_id',
        configUrl : '$gallery_filename',
        galleryHeight : '$gallery_height',
        galleryWidth : '$gallery_width'
    });
}
</script>
<div id="juicebox-container$gallery_id"></div>
<!--END JUICEBOX EMBED.-->
EOF;
            } else {
                return '<div><p>WP-Juicebox Gallery Id ' . $gallery_id . ' has been deleted.</p></div>';
            }
        } else {
            return '<div><p>WP-Juicebox Gallery Id cannot be found.</p></div>';
        }
    }
}

Please note that this method does not require the use of query strings so you can change your theme's 'index.php' file back to its original version to remove the '?jb=true' references.

Re: How to avoid massive downloads from Flickr.

Best support I never received in my life.
This guy is very serious and available.

Very good person.
Giadina.

Re: How to avoid massive downloads from Flickr.

portofinoworld wrote:

Best support I never received in my life.
This guy is very serious and available.

Very good person.
Giadina.

Yes Steven provides an incredible customer support.