• Hiho,

    like the title says: IE 7 wont display page if in iframe and Your plugin is active. To be exact it will show the Page as long as you wont press the Ok Button on the Cannot Open Page Dialogbox.
    Reason: Script inside body element in an iframe throws that error.

    Fix:
    $scripttxt as class var

    in constructor

    add_action('wp_footer', array($this, '__footer'));

    in class

    function __footer()
    	{
    		echo $this->scripttxt;
    	}

    and in function __displayDynamicMap
    put all strings from '<script type="text/.... onwards till return in a temp var and set new classvar before return
    $this->scripttxt = $scripttxt;

    changed content.php

    <?php
    class bingMapsForWordpressContent
    {
    
    .
    .
    .
    	/**
    	 * Script which gets put in the Footer
    	 * @var string
    	 * @access public
    	 */
    	var $scripttxt = "";
    .
    .
    .
    	/**
    	 * PHP4 constructor
    	 * @access public
    	 * @return void
    	 */
    	function bingMapsForWordpressContent()
    	{
    		// Get options
    		$options = get_option('bing_maps_for_wordpress');
    
    		// Only run if we have an API key
    		if(isset($options['api']) AND $options['api'] != '')
    		{
    			// Header action - to load up Bing maps JavaScript
    			add_action('wp_head', array($this, '__header'));
    
    			// Set the API key
    			$this->apiKey = $options['api'];
    
    			// Add shortcode handler
    			add_shortcode('bingMap', array($this, 'shortcode'));
    
    			add_action('wp_footer', array($this, '__footer'));
    		}
    	}
    .
    .
    .
    	/**
    	 * Display a dynamic Bing map
    	 * @access private
    	 * @return string
    	 */
    	function __displayDynamicMap()
    	{
    		if(!$this->lat AND !$this->long) return '<div class="bingMapsForWordpressContainer">'.__('Unknown location').'</div>';
    
    		// Display DIV to put the map in
    		$string = '<div class="bingMapsForWordpressContainer">';
    
    		// Display title if we've specified one
    		if(isset($this->atts['title']) AND $this->atts['title'] != '')
    		{
    			$string .= '<span class="bingMapsForWordpressTitle">'.$this->atts['title'].'</span>';
    		}
    
    		$string .= '<div id="bingMapsForWordpress'.$this->mapCount.'" class="bingMapsForWordpress" style="position:relative; width:'.$this->atts['width'].'px; height:'.$this->atts['height'].'px;"></div></div>';
    
    		// Work out if we have pushpins
    		$pushpins = array();
    		foreach($this->atts as $key => $val)
    		{
    			if(preg_match('/^pp[0-9]+/', $key))
    			{
    				$pushpins[$key] = $val;
    			}
    		}
    		// Work out if we have pushpin titles
    		$pushpinst = array();
    		foreach($this->atts as $key => $val)
    		{
    			if(preg_match('/^ppt[0-9]+/', $key))
    			{
    				$pushpinst[$key] = $val;
    			}
    		}
    		// Work out if we have pushpin descriptions
    		$pushpinsd = array();
    		foreach($this->atts as $key => $val)
    		{
    			if(preg_match('/^ppd[0-9]+/', $key))
    			{
    				$pushpinsd[$key] = $val;
    			}
    		}
    		// Work out if we have pushpin links
    		$pushpinsl = array();
    		foreach($this->atts as $key => $val)
    		{
    			if(preg_match('/^ppl[0-9]+/', $key))
    			{
    				$pushpinsl[$key] = $val;
    			}
    		}
    
    		$scripttxt = "";
    
    		if(isset($this->atts['navi']) AND $this->atts['navi'] != 'yes'){
    			$scripttxt .= '<style>#MSVE_navAction_container { display:none; }</style>';
    		}
    
    		// Initialize a Bing Map, set its initial lat/long & zoom
    		$scripttxt .= '<script type="text/javascript">map = new VEMap(\'bingMapsForWordpress'.$this->mapCount.'\');map.SetCredentials("'.$this->apiKey.'");map.LoadMap(new VELatLong('.$this->lat.', '.$this->long.', 0, VEAltitudeMode.RelativeToGround), '.$this->atts['zoomDynamic'].', VEMapStyle.'.$this->maptypesDynamic[strtolower($this->atts['maptype'])].', false, VEMapMode.Mode2D, true, 1);var layer = new VEShapeLayer();';
    		if(!isset($this->atts['pp']))
    		{
    			// If we haven't specified a "pp" attribute, display one where we've centered the map
    			if (isset($this->atts['locationtitle']) AND $this->atts['locationtitle'] != '')
    			{
    				$pptitle = $this->atts['locationtitle']; //set pin title as locationtitle if set in shortcode
    			} else {
    				$pptitle = $this->atts['location']; //if location title isn't set, use location as pin title
    			}
    			// If a location link is set build the link
    			if (isset($this->atts['locationlink']) AND $this->atts['locationlink'] != '')
    			{
    					$linkstring = '<a href=';
    					$linkstring .= $this->atts['locationlink'];
    					$linkstring .= '>';
    					$linkstring .= $pptitle;
    					$linkstring .= '</a>';
    					$pptitle = $linkstring;
    			}
    			$scripttxt .= 'var pin = new VEShape(VEShapeType.Pushpin,map.GetCenter());pin.SetTitle("'.$pptitle.'");';
    
    			if(isset($this->atts['description']) AND $this->atts['description'] != '') $scripttxt .= 'pin.SetDescription("'.$this->atts['description'].'");';
    
    			$scripttxt .= 'layer.AddShape(pin);';
    
    			// Set the pushpin attribute for later use
    			$this->atts['pp'] = $this->atts['location'];
    
    		} else
    		{
    			// Check if we haven't turned off the pushpin
    			if($this->atts['pp'] != 'false')
    			{
    				// Resolve pushpin location
    				$pushpinLocation = $this->__resolveLocation(rawurlencode($this->atts['pp']));
    
    				if($pushpinLocation)
    				{
    					// Add the pushpin to the layer
    					$scripttxt .= 'var pin = new VEShape(VEShapeType.Pushpin,new VELatLong('.$pushpinLocation['lat'].', '.$pushpinLocation['long'].'));pin.SetTitle("'.$this->atts['pp'].'");';
    
    					if(isset($this->atts['description']) AND $this->atts['description'] != '') $string .= 'pin.SetDescription("'.$this->atts['description'].'");';
    
    					$scripttxt .= 'layer.AddShape(pin);';
    				}
    			}
    		}
    
    		// Any other pushpins
    		foreach($pushpins as $key => $val)
    		{
    			$pushpinLocation = $this->__resolveLocation(rawurlencode($val));
    			if($pushpinLocation)
    			{
    				// build the IDs for ppt, ppd, and ppl from pp
    				// I believe this could be improved to be more efficient
    				$pptid = 'ppt';
    				$ppdid = 'ppd';
    				$pplid = 'ppl';
    				$pptid .= substr($key, -1);
    				$ppdid .= substr($key, -1);
    				$pplid .= substr($key, -1);
    				if (isset($pushpinst[$pptid]) AND $pushpinst[$pptid] != '')
    				{
    					$pptmessage = $pushpinst[$pptid]; //set the title to ppt if ppt is set
    				} else
    				{
    					$pptmessage = $val; //if ppt is not set, use location as pin title
    				}
    				if (isset($pushpinsd[$ppdid]) AND $pushpinsd[$ppdid] != '')
    				{
    					$ppdmessage = $pushpinsd[$ppdid]; //set the pin description if ppd is set and not blank
    				}
    				if (isset($pushpinsl[$pplid]) AND $pushpinsl[$pplid] != '')
    				{
    					//build the pin link if ppl is set
    					$pplmessage = '<a href=';
    					$pplmessage .= $pushpinsl[$pplid];
    					$pplmessage .= '>';
    					$pplmessage .= $pptmessage;
    					$pplmessage .= '</a>';
    					$pptmessage = $pplmessage;
    				}
    
    				$scripttxt .= 'var pin = new VEShape(VEShapeType.Pushpin,new VELatLong('.$pushpinLocation['lat'].', '.$pushpinLocation['long'].'));pin.SetTitle("'.$pptmessage.'");';
    				if(isset($ppdmessage) AND $ppdmessage != '') $scripttxt .= 'pin.SetDescription("'.$ppdmessage.'");';
    				//unset variables to prevent data being used on further pins where data is not set
    				unset($pptmessage);
    				unset($ppdmessage);
    				unset($pplmessage);
    			}
    
    			$scripttxt .= 'layer.AddShape(pin);';
    		}
    
    		// Don't re-work out the bounding box if we have 1 pushpin, or we're in birdseye mode
    		if(
    		$this->atts['maptype'] != "birdseye" AND
    			(($this->atts['pp'] != "false" AND count($pushpins) > 0) OR
    			($this->atts['pp'] == "false" AND count($pushpins) > 1))
    		)
    		{
    			// Add shape, get bounding rectangle, and set the map view based on it
    			$scripttxt .= 'map.AddShapeLayer(layer);rect = layer.GetBoundingRectangle();map.SetMapView(rect);'
    			;
    		} else
    		{
    			// Just add the shape to the map
    			$scripttxt .= 'map.AddShapeLayer(layer);';
    		}
    
    		if(empty($pushpins))
    		{
    			// No pushpins - set the zoom level
    			$scripttxt .= 'map.SetZoomLevel('.$this->atts['zoomDynamic'].');';
    		}
    
    		$scripttxt .= '</script>';
    		$this->scripttxt = $scripttxt;
    
    		return $string;
    
    	}
    
    	/**
    	 * Load the Bing map controls JavaScript
    	 * @access private
    	 * @return void
    	 */
    	function __header()
    	{
    		echo '<script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>';
    	}
    
    	/**
    	 * Load the Bing map controls JavaScript
    	 * @access private
    	 * @return void
    	 */
    	function __footer()
    	{
    		echo $this->scripttxt;
    	}
    
    }

  • The topic ‘IE wont display page if in iframe and Your plugin is active’ is closed to new replies.