Google Geo Chart and Map Chart Hashtag Emailing Tutorial

Google Geo Chart and Map Chart Hashtag Emailing Tutorial

Google Geo Chart and Map Chart Hashtag Emailing Tutorial

Before we got sidetracked, but along the same “where of life” themes, before the latest recent web application predilections …

… we were delving into passing on work from the Google Chart‘s Map Chart to the Google Chart Geo Chart and Image Chart Map Chart more often, where we started that thread (at Google Chart Image Chart Map Chart Mainstream Primer Tutorial at the end of last year) with a three point plan (which became four point two days later)

  1. Help itself … map.php … phase 1
  2. Redirect to Image Chart Map Chart … map.php and/or geo_chart.php … just after first prompt … phase 2
  3. Caller form method=POST map.php action interventions at onsubmit event … non map.php … phase 3
  4. Transfer the onclick prompt window functionality over to geo_chart.php … phase 4

And then yesterday’s work in Earth Bearing Distance Missing Two Earth Scanner Integration Tutorial involving the Missing Two web application’s interfacing to the Google Chart Map Chart saw a more happy interfacing with this Map Chart, and reminding us with both …

  • Google Charts Map Chart
  • Google Charts Geo Chart

… how on occasions we could have large data set scenarios relying on PHP $_POST data (via form method=POST (or you can use Ajax FormData post) arrangements) that had not passed on their data parts when the user clicked the “Email” link down the bottom. But ever since that happy discovery from around about the time of Earth Scanner Sharing Itinerary Detail Tutorial that …

  • hashtagging … was the friend of …
  • “a” “mailto:” and/or “sms:” link hrefs … replacing the need for …
  • PHP mail via a local mail server methodologies … when the email body is a single link whose length was greater than about 850 (ie. no such stringent limitations with “just clientside” hashtagging (which we’re yet to know what the limit is, but it seems huge))

… and … spoiler alert … we could not break (where we do not count as broken the clicking of a “Message clipped” message link, which we always click to fully show the whole link, as a warning from your email client application (eg. Gmail)) it with any large amounts of data from our PHP Wikipedia Australian List Integration Tutorial “peer to peer” suite of linked PHP web applications passing large amounts of data to those Google Charts and emailing that on to an emailee recipient. Good news indeed!

The changes feature …

Collect a method=POST (perhaps large data set) into a potentially useful (later) PHP variable hashtag part to an “a” “mailto:” href …
<?php

$shto="";

if (isset($_POST['title'])) {
foreach ($_POST as $name => $val) {
if (strpos($val, 'data:') !== false) {
$fval=urlencode($val); //str_replace(" ", "%20", str_replace("'", urlencode("'"), str_replace('"', urlencode('"'), str_replace('=', urlencode('='), str_replace('>', urlencode('>'), str_replace('<', urlencode('<'), str_replace('?', urlencode('?'), str_replace('&', urlencode('&'), $val)))))))); } else { $fval=str_replace('+','%20',urlencode(str_replace(' ',' + ',str_replace('+',' ',$val)))); //str_replace(" ", "%20", str_replace("'", urlencode("'"), str_replace('"', urlencode('"'), str_replace('=', urlencode('='), str_replace('>', urlencode('>'), str_replace('<', urlencode('<'), str_replace('?', urlencode('?'), str_replace('&', urlencode('&'), $val)))))))); } if ($shto == "") { $shto="#" . $name . "=" . $fval; //str_replace(" ", "%20", str_replace("'", urlencode("'"), str_replace('"', urlencode('"'), str_replace('=', urlencode('='), str_replace('>', urlencode('>'), str_replace('<', urlencode('<'), str_replace('?', urlencode('?'), str_replace('&', urlencode('&'), $val)))))))); } else { $shto.="&" . $name . "=" . $fval; //str_replace(" ", "%20", str_replace("'", urlencode("'"), str_replace('"', urlencode('"'), str_replace('=', urlencode('='), str_replace('>', urlencode('>'), str_replace('<', urlencode('<'), str_replace('?', urlencode('?'), str_replace('&', urlencode('&'), $val)))))))); } } }

?>
Up the top of where PHP is writing out the Javascript, checking for an email derived URL with huge hashtag we turn into a form method=POST scenario for the user clicking the email body huge link ...

var dependssuffix='';
if (('' + location.hash).indexOf('&data=') != -1) {
dependssuffix=('' + location.hash);
}
<?php
if ($shto != "") {
echo " if (typeof sethash == \"function\") { sethash(encodeURIComponent(\"" . $shto . "\")); } " . "\n";
}

echo "
var lhpassed=('' + location.hash);
if ((1 == 1 || document.URL.split('#')[0].indexOf('?') == -1) && lhpassed.indexOf('&data=') != -1) {
if (3 == 3) { // good for new style of hashtagged email
var gformoh='<iframe name=lastgif id=lastgif style=\"position:absolute;width:100%;height:100%;z-index:897;top:0px;left:0px;\" src=></iframe><br><form style=display:none; target=_self method=POST action=\"' + document.URL.split('#')[0] + '\"><input id=gformsubis type=submit value=Submit style=display:none;></input></form>';
var fldsare=lhpassed.replace(/^\#/g,'').split('=');
for (var ifldsare=1; ifldsare<fldsare.length; ifldsare++) {
gformoh=gformoh.replace('</form>','<input type=hidden name=\"' + fldsare[eval(-1 + ifldsare)].split('&')[eval(-1 + fldsare[eval(-1 + ifldsare)].split('&').length)] + '\" value=\"' + (fldsare[ifldsare].split('&')[0]) + '\"></input></form>');
}
setTimeout(function() {
document.body.innerHTML+=gformoh;
document.getElementById('gformsubis').click(); }, 7000);
} else {
var gzhr = new XMLHttpRequest();
var gzform=new FormData();
var fldsare=lhpassed.replace(/^\#/g,'').split('=');
for (var ifldsare=1; ifldsare<fldsare.length; ifldsare++) {
gzform.append(fldsare[eval(-1 + ifldsare)].split('&')[eval(-1 + fldsare[eval(-1 + ifldsare)].split('&').length)], decodeURIComponent(fldsare[ifldsare].split('&')[0]));
}
gzhr.open('post', document.URL.split('#')[0], true);
gzhr.send(gzform);
}
}
";

?>
All location.search. strings become, for example ...
<?php echo "

var ansis=(location.search + '" . $shto . "').split('val' + pnum + '=')[1] ? decodeURIComponent(decodeURIComponent((location.search + '" . $shto . "').split('val' + pnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : '';

"; ?>
Javascript functions that are wrappers to Javascript prompt window scenarios need ...
<?php echo "

function ourprompt(ourp1, ourp2) {
if (('' + location.hash).replace('&data=') != ('' + location.hash)) { return ourp2; }
var iop=0;
tzpn='';
// more code here
thisris=prompt(ourp1, ourp2);
// more code here
return thisris;
}

"; ?>
New if for code involving no data passed in $_GET[] nor $_POST[] but huge hashtag (via email) ...
<?php

echo ' if (("" + location.hash).replace("&data=") == ("" + location.hash)) { ' . "\n";

echo ' datalineprefix = " "; ' . "\n";
echo ' datalinesuffix = ""; ' . "\n";
echo ' var prethisline = "", fti=false, extra = ""; ' . "\n";
echo ' var thisline = 1, gc_m="", gtitle="", glabel="", gvalue=""; ' . "\n";
// more code here going on to interactive Javascript prompt window asks
// more code here
echo "} \n";

echo "} \n";

?>
New Javascript function helpers ...
<?php echo "

var dependssuffix='';

function sethash(towhat) {
if (towhat.indexOf(encodeURIComponent('#')) == 0) {
dependssuffix=decodeURIComponent(towhat);
} else {
dependssuffix=towhat;
}
}

function depends(ins) {
if (ins.indexOf('?') == -1 && ins.indexOf('#') == -1 && dependssuffix != '') {
if (dependssuffix.indexOf('?') == 0) {
return (ins + '#' + dependssuffix.substring(1));
} else if (dependssuffix.indexOf('#') == 0) {
return (ins + dependssuffix);
} else {
return (ins + '#' + dependssuffix);
}
}
return ins;
}

"; ?>
Add hashtag suffix to "a" "mailto:" link href attribute as applicable ...
<?php

echo '<a id="amapid" title="Another Map" href="' . $https . 'www.rjmprogramming.com.au/PHP/Map/map.php">Another</a> <a id="amapidgeo" title="Another Geo Map" style="text-decoration:underline;cursor:pointer;" onclick=gogeo("' . $https . 'www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php");>Geo</a> <a id="amapidtwo" title="Another Map" href="' . $https . 'www.rjmprogramming.com.au/PHP/Map/map.php">Map?</a>' . '  <a onclick=ahdepends(this); href="MAILTO:fillin.email@address?subject=Google%' . '20Chart%' . '20Snapshot&body=' . urlencode("HTTP://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . $shto) . '" style="display:inline;" title="To email a snapshot of this Google Chart click me." id="remail">Email snapshot of Google Chart ...</a>' . " \n";

?>

Codewise ...

If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Software, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *