[pmwiki-devel] New Recipe Code Problem: HTMLHeadFmt.

Craige Leeder craige at internetadvisor.ca
Mon Nov 20 12:10:48 CST 2006


Crisses wrote:

> I think either you should give the full function code, or test the  
> value of $HeadFmt IN the function.
>
> Here's one problem:  What's triggering your function?  Maybe the  
> function never runs?
>
> Here's another possibility for how to do what you're trying:
>
> $HeadFmt = '<script type="text/javascript">
>     //<![CDATA[
>
>     function load() {
>       if (GBrowserIsCompatible()) {
>         var map = new GMap2(document.getElementById("' .
> $GoogleMapDefaults['id'] . '"));
>       }
>     }
> ' . MoreTextFunction() . '
>     //]]>
>     </script>';
>
> then do whatever you need in MoreTextFunction() and have it return  
> the javascript text you want pasted into $HeadFmt:
>
>          return 'map.setCenter(new GLatLng(' . $ParsedArgs['lon'] .
> ', ' . $ParsedArgs['lat'] . '), ' . $GoogleMapDefaults['zoom'] . ');';
>
> And see if that works.
>
> Crisses


Well the function IS being run, it is called by a cvtMarkup() function, 
which you will see in a moment. I have made sure it has run.

I can't do the seccond method, as the javascript is dynamically 
generated throught multiple funcitons.

Here is the code I have so far.

<?php

/* Set Defaults
  */

// Config Defaults
SDV( $GoogleMapKey, '' );
SDV( $GoogleMapDefaults, array( 'width' => '300',
                                'height' => '300',
                                'id' => 'map',
                                'view' => 'normal',
                                'zoom' => '11',
                                'lon' => '42.72500',
                                'lat' => '-81.200935'
                                ) );

$PasedArgs &= $GoogleMapDefaults;
// HTMLHeader Defaults
$HTMLHeaderFmt[] = '<script 
src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=' . 
$GoogleMapKey . '"
            type="text/javascript"></script>';
           
$HeadFmt = '<script type="text/javascript">
    //<![CDATA[

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("' . 
$GoogleMapDefaults['id'] . '"));
      }
    }';

   
// Markup() Calls
Markup( 'map', '_begin', '/\(:map(-location\s|\s)(.*?):\)/ie', 
"CvtMarkup('$1', '$2')" );


/* Function Definitions.
 * AKA: The Fun Stuff
 */
 
 
/* (string) furncion cvtMarkup($call, $params);
 * Discription: Main() function of script. CvtMarkup() checkes for the 
markup call
 *             used, and makes a call to one of two fucntions  depending 
on call
 *             type. CvtMarkup() returns the result of this function 
call to the
 *             wiki, which is the html needed to preform the action 
requested.
 */
function CvtMarkup( $call, $params )
{
    $type = ( strpos( $call, '-location ' ) == 0 ) ? 'location' : 
'generate';
    $args = ParseArgs( $params );
   
    if ( $type = 'generate' )
    {
        return GenerateMap( $args );
    }
    elseif ( $type = 'location' )
    {
        return AddLocation( $args );
    }
}


/* (string) GenerateMap($params);
 * Discription: GenerateMap() does just as it's name implies: it 
generates a map.
 *              More specifically though, it adds the javascript from 
the Google
 *              Maps API, which generates the map for it.
 */
function GenerateMap( $params )
{
    global $GoogleMapDefaults, $HeadFmt;
    $loctype = null;
   
    /*
     * Time to parse the arguments
     */
    
     // Check the location paramater
     if ( preg_match('/"(.*\s*)?"/', $params['location']) )
     {
         echo true;
         $loctype = 'addr'; // It's an address
         $ParsedArgs['location'] = str_replace('"', '', 
$params['location']);
     }
     else
     {
         $loctype = 'll'; // It's a longitude and latitude
         $ll = explode( ',', $params['location'] );
         $ParsedArgs['location'] = array( 'lon' => $ll[0], 'lat' => 
$ll[1] );
        
         $HeadFmt .= 'map.setCenter(new GLatLng(' . $ParsedArgs['lon'] . 
', ' . $ParsedArgs['lat'] . '), ' . $GoogleMapDefaults['zoom'] . ');';
     }

    $HeadFmt .= '    //]]>
    </script>';

    echo $HeadFmt;
    return '<div id="' . $GoogleMapDefaults['id'] . '" style="width:' . 
$GoogleMapDefaults['width'] . 'px;height:' . 
$GoogleMapDefaults['height'] . 'px;"></div>';
}




function AddLocation( $params )
{
}



More information about the pmwiki-devel mailing list