Advertisement
globiws

ppdemo_gf_external

Mar 5th, 2019 (edited)
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. // private labels GlobiFlow external link flow on your own domain
  4. // eg https://workflow-automation.podio.com/external.php?id=xxxxxxxxx
  5. // expects to be in a sub-directory /gf and called the same way
  6. // eg http://yourdomain.com/gf/?id=xxxxxxxx
  7.  
  8. // make sure the server supports CURL
  9. if ( ! function_exists("curl_init") ) die("This server does not support CURL");
  10.  
  11. // direct call - ajax not set - show template page
  12. if ( ! isset($_GET['ajax']) ) {
  13.     include(__DIR__."/page.html");
  14.     $id = (isset($_GET['id'])?(urlencode($_GET['id'])):(""));
  15.     echo '<noscript>';
  16.     echo '<p>This site requires Javascript. Else <a href="http://https://workflow-automation.podio.com/external.php?id='.$id.'">click here</a>.</p>';
  17.     echo '</noscript>';
  18.     echo '<script>';
  19.     echo 'Http = new XMLHttpRequest();';
  20.     echo 'xnow = new Date().getTime();';
  21.     echo 'url="/gf/?ajax=1&id='.$id.'&cb="+xnow;'; // cb is for cache busting because some nginx hosts auto-cache
  22.     echo 'Http.open("GET", url);';
  23.     echo 'Http.send();';
  24.     echo 'Http.onreadystatechange=(e)=>{';
  25.     echo '  document.getElementById("gfcontent").innerHTML = Http.responseText';
  26.     echo '}';
  27.     echo '</script>';
  28.     exit();
  29. }
  30.  
  31. // ajax flag has been passed so fetch the page from GF
  32. if ( ! isset($_GET['id']) || empty($_GET['id']) ) {
  33.     $msg = "<p>Error: Invalid Link</p>";
  34. } else {
  35.     $url = "https://workflow-automation.podio.com/external.php?id=".$_GET['id'];
  36.     $ret = curl_get_url($url);
  37.     $msg = preg_replace('/.*?\("foo"\)[^<]*<\/script>/ism', '', $ret);
  38.     $msg = preg_replace('/<div[^>]*>Powered by\s*<a [^>]*>Citrix Podio.*/ism', '', $msg);
  39.     if ( empty($msg) ) $msg = '<p>Ooops - something unexpected went wrong.</p><script>console.log('.json_encode($ret).');</script>';
  40.     else $msg = '<div>' . $msg; // above get_between leaves a closing div on end
  41. }
  42.  
  43. // output result
  44. echo $msg;
  45. exit();
  46.  
  47. // some helper functions below
  48.  
  49. function curl_get_url($url) {
  50.     $crl = curl_init();
  51.     curl_setopt ($crl, CURLOPT_URL, $url);
  52.     curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
  53.     curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, 30);
  54.     curl_setopt ($crl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
  55.     $ret = curl_exec($crl);
  56.     if ( curl_errno($crl) ) {
  57.         die("CURL ERROR " . curl_errno($crl) . " - " . curl_error($crl));
  58.     }
  59.     curl_close($crl);
  60.     return $ret;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement