Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Iframe redirect issues

Status Resolved
Add-on / Version Publisher 2.10.6
Severity
EE Version 4.3.7

Hop Studios

Feb 04, 2019

Hello Brian,

I observed 2 anomalies while checking on the staging site.

1. When there is a scripts included with plain url (i.e. https://staging.lucistrust.org/includes/button_to_top_scripts) without any language prefix, chrome takes it to the script page when a switch_language_url is clicked
2. When I put an iframe without the language prefix but view it in different language, I get redirect too many times error on chrome and page redirection on safari

The first one is not a big deal because I can wrap all JS in minimee and the path redirection doesn’t happen. But the second one is kind of troublesome.

I have Show content fallback (FE) turned on and Persistent Entries turned on.

Testing page:
https://staging.lucistrust.org/ru/broadcast/testing

https://staging.lucistrust.org/admin.php?/cp/design/template/edit/608

#1

BoldMinded (Brian)

A page like https://staging.lucistrust.org/includes/button_to_top_scripts (which I assume is loaded through an EE template?) looks like a normal http/page request to everything, including Publisher, so it doesn’t know that it is supposed to be a JS request and not perform any redirects. I’d suggest either use the hidden template prefix (. or _) or don’t serve JS files through EE templates (I’d recommend this approach).

As for the iframe issue, have you tried it without embedding the iframe code in a wysiwyg field? It’s probably struggling to find out what language to set it to.

#2

BoldMinded (Brian)

Try changing the iframe source to src=”{site_url}/broadcast/simple_player”

#3

Hop Studios

I moved the html out of the WYSWIG and pasted it directly in the template.

It loads now but it now redirects you to the iframe src. https://staging.lucistrust.org/broadcast/testing

However, if you type in the url specifically it works. https://staging.lucistrust.org/ru/broadcast/testing

#4

Hop Studios

I don’t know if it’s useful information but on EE2 with version 1.7.5 the embed just works.

#5

BoldMinded (Brian)

I would find a way to get the prefix in there the first time the iframe source is loaded. There isn’t a reliable, and more importantly a non-specific to your site way, for me to add code to Publisher to determine if the current request is inside an iframe.

#6

Hop Studios

I tried your suggestions and they didn’t work when the switch language action is triggered. I dug deeper and found that the iframe url is getting recorded in the EE Tracker and being added to the segments to build to the url [Service/Url/Url.php @ line 380]. So when the switch language url is clicked, it goes to the iframe.

I’m assuming this happens to all sites with iframe. Can you provide any directions about how I can resolve this?

#7

BoldMinded (Brian)

Did you try setting the src to src=”{site_url}/broadcast/simple_player”? Your last couple of comments weren’t very clear on if you did that part specifically.

#8

Hop Studios

Yes I did.

So what happened was that when you go to https://staging.lucistrust.org/broadcast/testing which has the iframe src=”{site_url}/broadcast/simple_player”, clicking any one of the Switch Language Urls will take you to the src url like https://staging.lucistrust.org/el/broadcast/simple_player

This is because the set_language function calls the session service’s changeLanguage function which calls the url service’s addPrefixToUrl function. When the segment is built with getCurrentSegments, the iframe src is included.

#9

Hop Studios

Hello Brian,

I’ve tested on a fresh install and confirm that this is happening on sites that have the following settings: Enable URL translations off Add URL Prefix on Add URL prefix to the homepage on Hide the prefix for default language on

Create a template includes/iframe Create a template testing/iframe and add the publisher switch urls with <iframe src=”/includes/iframe”></iframe> Go to site.com/testing/iframe Click a switch language url link and see how it takes you to site.com/includes/iframe rather than site.com/fr/testing/iframe

Here are the modifications that I made to make the site not go to the iframe url but rather stay on the actual page. Please review it if you will and let me know if the changes will collide with anything or cause anything crazy. Thanks! in Service/Session.php @ line 674

if (isset($_GET['iframe'])) {
    $this->changeLanguage($defaultLanguage, $url);
} else {
    $this->changeLanguage($defaultLanguage);
}

in Service/Url/Url.php @ line 379

if ($this->request->isSwitching() && !isset($_GET['iframe'])) {

@ line 793

if (!$this->shouldAddPrefix($requestedLanguage) && !isset($_GET['iframe'])) {

@ line 823

if (strstr($url, $segmentsBefore)) {
    $url = str_replace($segmentsBefore, $segmentsAfter, $url);
} elseif (isset($_GET['iframe'])) {
    $url = $segmentsBefore.'?iframe=true';
} else {
    $url = $segmentsAfter;
}

in Service/Parser.php Add function

/**
 * replaceIframeSrc
 * Append iframe src with iframe=true so the url don't get tracked
 *
 * @param  string  $template
 * @return string
 */
public function replaceIframeSrc($template)
{
    $pattern = '/<iframe.*?src="(.*?)".*?<\/iframe>/';
    preg_match_all($pattern, $template, $matches);

    foreach ($matches[1] as $match) {
        if ($position = strpos($match, '?')) {
            $replacement = substr_replace($match, 'iframe=true&', $position + 1, 0);
        } else {
            $replacement = $match.'?iframe=true';
        }
        $template = str_replace($match, $replacement, $template);
    }

    return $template;
}

in ext.publisher.php @ line 1303

$final_template = $parser->replaceIframeSrc($final_template);
#10

BoldMinded (Brian)

Thanks for sending this code. I feel like this is a pretty heavy handed and specific approach though. I’m going to have to think about this for a bit to see if it’s something I want to add to the core codebase.

In the meantime I would suggest documenting your changes in your project so you can re-apply the patch if you upgrade Publisher in the future.

#11

BoldMinded (Brian)

Comment has been marked private.

#12

Hop Studios

Comment has been marked private.

#13

BoldMinded (Brian)

Thanks, I added that change to my repo.

#14

BoldMinded (Brian)

So, this is causing an issue with YT’s autoplay feature when embedding, so I’m making it so that you have to set a hidden config value before it will add ?publisher_iframe=true to the iframe source, thus preventing the redirects. In 2.11.0 and going forward, you will need to add this to your config.php file:

$config['publisher_fix_iframe_src'] = true;

Login to reply