Skip to content

Instantly share code, notes, and snippets.

@bsullins
Created February 3, 2015 17:50
Show Gist options
  • Save bsullins/d824490e0772b9b961e4 to your computer and use it in GitHub Desktop.
Save bsullins/d824490e0772b9b961e4 to your computer and use it in GitHub Desktop.
Wordpress Tableau Server SSO
<?php
//get dashboard if one is setup
global $current_user;
get_currentuserinfo();
// $custom_fields = get_post_custom_values('dashboard_url'); //post must have this configured
// $dashboard_url = $custom_fields[0]; //the first value, there technically could be more than 1
$meta_values = get_post_meta( get_the_ID() );
// print_r($meta_values);
$dashboard = Array (
'url' => $meta_values['dashboard_url'][0],
'width' => $meta_values['dashboard_width'][0],
'height' => $meta_values['dashboard_height'][0]
);
//parse dashboard url to pull out the path
$parsed_dash_url = parse_url($dashboard['url']);
//support original posts w/o full url
if( substr($dashboard['url'],0,6) != '/views' ) {
$dashboard['url'] = $parsed_dash_url['path'];
}
//set defaults for height and width
if (!$dashboard['width']) { $dashboard['width']='1020'; } else { $dashboard['width']=$dashboard['width']+20; }
if (!$dashboard['height']) { $dashboard['height']='830px'; } else { $dashboard['height']=$dashboard['height']+30; }
//if there is a dashboard url try to load it
if($dashboard['url']) {
try {
//get URL
$trusted_url = get_trusted_url($current_user->user_email,TABLEAU_URL,$dashboard['url']);
if($trusted_url==-1){
echo('Unable to fetch trusted URL');
} else {
echo('<div id="psa-dashboard" style="padding:10px; text-align: center; width: 100%;"><iframe src="'.$trusted_url.'" width="'.$dashboard['width'].'" height="'.$dashboard['height'].'"></iframe></div>');
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
//get main content
// x_get_view( 'global', '_content' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment