Created
November 9, 2018 02:29
-
-
Save MattSandy/f2c7c5d62557d04bb2ba199a3a91844c to your computer and use it in GitHub Desktop.
Tableau Data Path Replace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
$url = str_replace("?dl=0","?dl=1",urldecode($_REQUEST['url'])); | |
$thumbs = ""; | |
$user['Not_Matt'] = array('C:/Users/Not_Matt/Dropbox/MSM/','C:\Users\Not_Matt\Dropbox\MSM\\'); | |
$user['matt'] = '/Users/macbook/Dropbox/work/shared/MSM/'; | |
if ($_POST['action'] == "download") { | |
$headers = get_headers($url, 1); | |
$filename = preg_match('/filename="(.*?)"/', $headers['content-disposition'], $match); | |
//print_r($match); | |
list($base, $extention) = explode(".", $match[1]); | |
$filename = $base . "." . $extention; | |
//print($filename); | |
$file = file_get_contents($url); | |
//removes pages from worksheets | |
if($_POST['pages']=="remove") { | |
$file = preg_replace("/<pages>(.*?)<\/pages>/ms", "", $file); | |
$filename = $base . "_no_pages." . $extention; | |
} | |
if($_POST['user']=="Not_Matt") { | |
$file = str_replace($user['matt'],$user['Not_Matt'][1],$file); | |
} else { | |
$file = str_replace($user['Not_Matt'],$user['matt'],$file); | |
} | |
$length = strlen($file); | |
header('Content-Description: File Transfer'); | |
header('Content-Type: text/plain');//<<<< | |
header('Content-Disposition: attachment; filename=' . $filename); | |
header('Content-Transfer-Encoding: binary'); | |
header('Content-Length: ' . $length); | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
header('Expires: 0'); | |
header('Pragma: public'); | |
echo $file; | |
exit; | |
} else if (isset($_GET['preview'])) { | |
error_reporting(E_ALL); | |
//print($filename); | |
$file = file_get_contents($url); | |
preg_match_all('/<thumbnail (.*?)>(.*?)<\/thumbnail>/ms', $file, $thumbnails); | |
foreach ($thumbnails[2] as $thumb) { | |
echo "<img src=\"data:image/png;base64, $thumb\" height=\"150\" /> "; | |
} | |
echo '<pre style="text-align:left">'; | |
$xml = simplexml_load_string($file); | |
foreach($xml->worksheets->worksheet as $worksheet) { | |
echo $worksheet->attributes()->name . "\n"; | |
//print_r($worksheet->table->view); | |
foreach($worksheet->table->view->filter as $filter) { | |
print_r($filter); | |
} | |
echo "\n!"; | |
} | |
//print_r($xml->worksheets); | |
echo "</pre>"; | |
exit; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>tableau</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> | |
</head> | |
<body> | |
<h1 class="text-center text-muted">Tableau Formatter</h1> | |
<div class="container"> | |
<form method="post"> | |
<select class="form-control" name="user"> | |
<optgroup label="User"> | |
<option value="Not_Matt" selected="">Not_Matt</option> | |
<option value="matt">Matt</option> | |
</optgroup> | |
</select> | |
<input class="form-control" type="url" name="url" placeholder="Dropbox URL" id="url"> | |
<div class="checkbox"> | |
<label for="Remove Pages"> | |
<input type="checkbox" name="pages" value="remove">Remove Page Shelf</label> | |
</div> | |
<p> | |
<button class="btn btn-success" type="button" id="preview">Preview</button> | |
<button class="btn btn-success" type="submit" name="action" value="download">Download</button> | |
</p> | |
</form> | |
</div> | |
<div class="row"> | |
<div class="col-md-12"> | |
<div class="container" id="thumbs"></div> | |
</div> | |
</div> | |
<script | |
src="https://code.jquery.com/jquery-2.2.4.min.js" | |
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" | |
crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script> | |
<script language="javascript"> | |
$(document).ready(function() { | |
//console.log("test"); | |
$("#preview").click(function() { | |
$("#thumbs").load("?preview&url=" + encodeURIComponent($("#url").val())); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment