1

I have a requirement to pass parameters from the joomla calling URL to the wrapper iframe URL.

I had a look around to see if I could do this and found this thread https://stackoverflow.com/questions/12200934/pass-value-in-url-to-wrapped-url-in-joomla-2-5 for J2.5 version, which suggests customising the core wrapper files to achieve this

Find $url = $params->def('url', '');

Then add the following after it (as outlined in Abid's link)

foreach ($_GET as $key => $value) {
  if ($key<>"option" && $key<>"Itemid") {
    $url.=(strpos($url,"?")) ? "&" : "?";
    $url.="$key=$value";
  }
}

So that is parsing the calling URL and adding the params to the of it

But customising core is generally a bad idea. I was wondering if it might be possible to achieve the same outcome using a template override?

I have created an override from /html/com_wrapper/wrapper/default.php

In there the iframe code is as follows:

<iframe <?php echo $this->wrapper->load; ?>
    id="blockrandom"
    name="iframe"
    src="<?php echo $this->escape($this->wrapper->url); ?>"
    width="<?php echo $this->escape($this->params->get('width')); ?>"
    height="<?php echo $this->escape($this->params->get('height')); ?>"
    scrolling="<?php echo $this->escape($this->params->get('scrolling')); ?>"
    frameborder="<?php echo $this->escape($this->params->get('frameborder', 1)); ?>"
    class="wrapper<?php echo $this->pageclass_sfx; ?>">
    <?php echo JText::_('COM_WRAPPER_NO_IFRAMES'); ?>
</iframe>

So is it possible to add that same foreach logic into this code ?

And would it work?

1 Answer 1

1

I would just write the logic into the default.php:

<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_wrapper
 *
 * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;
JHtml::_('script', 'com_wrapper/iframe-height.min.js', array('version' => 'auto', 'relative' => true));

$app    = JFactory::getApplication();
$params = $app->getParams();

$wrapper = new stdClass;

// Auto height control
if ($params->def('height_auto'))
{
        $wrapper->load = 'onload="iFrameHeight()"';
}
else
{
        $wrapper->load = '';
}

$url = $params->def('url', '');

foreach ($_GET as $key => $value) {
  if ($key<>"option" && $key<>"Itemid") {
    $url.=(strpos($url,"?")) ? "&" : "?";
    $url.="$key=$value";
  }
}

if ($params->def('add_scheme', 1))
{
        // Adds 'http://' or 'https://' if none is set
        if (strpos($url, '//') === 0)
        {
                // URL without scheme in component. Prepend current scheme.
                $wrapper->url = JUri::getInstance()->toString(array('scheme')) . substr($url, 2);
        }
        elseif (strpos($url, '/') === 0)
        {
                // Relative URL in component. Use scheme + host + port.
                $wrapper->url = JUri::getInstance()->toString(array('scheme', 'host', 'port')) . $url;
        }
        elseif (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0)
        {
                // URL doesn't start with either 'http://' or 'https://'. Add current scheme.
                $wrapper->url = JUri::getInstance()->toString(array('scheme')) . $url;
        }
        else
        {
                // URL starts with either 'http://' or 'https://'. Do not change it.
                $wrapper->url = $url;
        }
}
else
{
        $wrapper->url = $url;
}

$this->params        = &$params;
$this->wrapper       = &$wrapper;

?>
<div class="contentpane<?php echo $this->pageclass_sfx; ?>">
<?php if ($this->params->get('show_page_heading')) : ?>
    <div class="page-header">
        <h1>
            <?php if ($this->escape($this->params->get('page_heading'))) : ?>
                <?php echo $this->escape($this->params->get('page_heading')); ?>
            <?php else : ?>
                <?php echo $this->escape($this->params->get('page_title')); ?>
            <?php endif; ?>
        </h1>
    </div>
<?php endif; ?>
<iframe <?php echo $this->wrapper->load; ?>
    id="blockrandom"
    name="iframe"
    src="<?php echo $this->escape($this->wrapper->url); ?>"
    width="<?php echo $this->escape($this->params->get('width')); ?>"
    height="<?php echo $this->escape($this->params->get('height')); ?>"
    scrolling="<?php echo $this->escape($this->params->get('scrolling')); ?>"
    frameborder="<?php echo $this->escape($this->params->get('frameborder', 1)); ?>"
    class="wrapper<?php echo $this->pageclass_sfx; ?>">
    <?php echo JText::_('COM_WRAPPER_NO_IFRAMES'); ?>
</iframe>
</div>

If you don't need the sheme logic again and just want to add the params to the url, you can reduce it to:

    $url = $this->wrapper->url;
    foreach ($_GET as $key => $value) {
      if ($key<>"option" && $key<>"Itemid") {
        $url.=(strpos($url,"?")) ? "&" : "?";
        $url.="$key=$value";
      }
    }

    $this->wrapper->url = $url;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.