GPS Track BBCode mod

Post ideas, suggestions, or feature requests for Star Trek Guide.
Post new forum suggestions here as well.
Forum rules
Image Post suggestions, ideas, features, or new forum requests for Star Trek Guide here.

NO Support or MOD Requests!

GPS Track BBCode mod

Postby stef775 » 22 Feb 2012, 13:56

Well don't know if this is a mod or just a custom bbcode. It's easy to do, you only need a api key at http://gpsies.com and it will embed your track in your forum by using bbcode [gpsies=your trackcode]Your tracktitle[/gpsies]
It looks like this:
Naamloos-2.jpg

Here it comes:

In constants.php change NUM_CORE_BBCODES in 13.

In bbcode.php in function bbcode_second_pass on line 116 add:
Code: Select all
            if ($bbcode_id == 13)
            {
                if (preg_match("/fileId=([a-z]{12,19})/", $message, $matches))
                {
                        $track = '</iframe>' . gpsies_properties($matches[1]) . '</div><br style="clear:both;" />';
                        $message = preg_replace("~</iframe>~", $track, $message);
                }else
                {
                    $message .= '</div>';
                }
            }   


On line 346 in functiion bbcode_cache_init add:
Code: Select all
                case 13:
                    $this->bbcode_cache[$bbcode_id] = array(
                        'preg' => array(
                            '!\[gpsies=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/gpsies:$uid\]!is'    => $this->bbcode_tpl('gpsies', $bbcode_id),
                        )
                    );
                break;   


In function bbcode_tpl on line 425 add:
Code: Select all
                'gpsies'    => '<div><iframe src="http://www.gpsies.com/mapOnly.do?fileId=$1" style="float:left; width:400px; height:400px; border:none;" scrolling="no" title="$2"></iframe>',   


In functions.php add to the end:
Code: Select all
function gpsies_properties($gpsies='')
{
    $gpsies_api_key = 'Your Api key';
    $gpsies_url_api = 'http://www.gpsies.com/api.do?key=';
    $gpsies_url_api .= $gpsies_api_key;
    $gpsies = 'fileId=' . $gpsies . ' show=details';
  
    $defaults 
= array( 
        CURLOPT_URL 
=> $gpsies_url_api . (strpos($gpsies_url_api, '?') === FALSE ? '?' : '&') . $gpsies, 
        CURLOPT_HEADER 
=> 0, 
        CURLOPT_RETURNTRANSFER 
=> TRUE, 
        CURLOPT_TIMEOUT 
=> 4 
    
); 

    $ch 
= curl_init(); 
    curl_setopt_array
($ch, ($defaults)); 
    if 
(!$result = curl_exec($ch)) 
    
{ 
        trigger_error
(curl_error($ch)); 
    
} 
    curl_close
($ch); 
    $xmlresp 
= $result; 
    
    $xmlgpsies 
= new SimpleXMLElement($xmlresp);     
    $tracksrev 
= array_reverse($xmlgpsies->tracks->xpath('track')); 
    $trackinfo 
= 'No data available!';
    foreach ($tracksrev as $track) 
    
{
        $trackinfo ='<div style="float:left; width:250px; font-size:11px; margin-left:10px;">
                    <strong>Track title:</strong> '
 . $track->title . '
                    <strong>Track length:</strong> '
 . round((real)$track->trackLengthM/1000, 1) . ' km
                    <strong>Altitudes:</strong> '
 . $track->altitudeDifferenceM . ' m
                    <strong>Min. height:</strong> '
 . $track->altitudeMinHeightM . ' m
                    <strong>Max. height:</strong> '
 . $track->altitudeMaxHeightM . ' m
                    <strong>Climb:</strong> '
 . $track->totalAscentM . ' m | '.
                    '<strong>Descents:</strong> ' . $track->totalDescentM . ' m
                    <strong>Address:</strong> '
 . $track->startPointAddress . '
                    <strong>Latitude:</strong> '
 . $track->startPointLat . '
                    <strong>Longitude:</strong> '
 . $track->startPointLon . '</div>';
    }
    return $trackinfo;    
}
   


In message_parser.php about line 128 add:
Code: Select all
            'gpsies'        => array('bbcode_id' => 13,    'regexp' => array('!\[gpsies=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[/gpsies\]!uise' => "\$this->bbcode_gpsies('\$1', '\$2')")),   


and about line 281:
Code: Select all
    /**
    * Parse gpsies tag
    */
    function bbcode_gpsies($stx, $in)
    {
        if (!$this->check_bbcode('gpsies', $in))
        {
            return $in;
        }

        return '[gpsies=' . $stx . ':' . $this->bbcode_uid . ']' . $in . '[/gpsies:' . $this->bbcode_uid . ']';
    }   


Happy tracking
ForumHulp.com
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign
stef775
Ensign
Ensign
 
Posts: 88
Joined: 05 Oct 2008, 16:00
Gender: Male
phpBB Knowledge: 8


Return to Suggestions / Ideas

Who is online

Users browsing this forum: No registered users and 2 guests