open-flash-chart-object.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. function open_flash_chart_object_str( $width, $height, $url, $use_swfobject=true, $base='' )
  3. {
  4. //
  5. // return the HTML as a string
  6. //
  7. return _ofc( $width, $height, $url, $use_swfobject, $base );
  8. }
  9. function open_flash_chart_object( $width, $height, $url, $use_swfobject=true, $base='' )
  10. {
  11. //
  12. // stream the HTML into the page
  13. //
  14. echo _ofc( $width, $height, $url, $use_swfobject, $base );
  15. }
  16. function _ofc( $width, $height, $url, $use_swfobject, $base )
  17. {
  18. //
  19. // I think we may use swfobject for all browsers,
  20. // not JUST for IE...
  21. //
  22. //$ie = strstr(getenv('HTTP_USER_AGENT'), 'MSIE');
  23. //
  24. // escape the & and stuff:
  25. //
  26. $url = urlencode($url);
  27. //
  28. // output buffer
  29. //
  30. $out = array();
  31. //
  32. // check for http or https:
  33. //
  34. if (isset ($_SERVER['HTTPS']))
  35. {
  36. if (strtoupper ($_SERVER['HTTPS']) == 'ON')
  37. {
  38. $protocol = 'https';
  39. }
  40. else
  41. {
  42. $protocol = 'http';
  43. }
  44. }
  45. else
  46. {
  47. $protocol = 'http';
  48. }
  49. //
  50. // if there are more than one charts on the
  51. // page, give each a different ID
  52. //
  53. global $open_flash_chart_seqno;
  54. $obj_id = 'chart';
  55. $div_name = 'flashcontent';
  56. //$out[] = '<script type="text/javascript" src="'. $base .'js/ofc.js"></script>';
  57. if( !isset( $open_flash_chart_seqno ) )
  58. {
  59. $open_flash_chart_seqno = 1;
  60. $out[] = '<script type="text/javascript" src="'. $base .'js/swfobject.js"></script>';
  61. }
  62. else
  63. {
  64. $open_flash_chart_seqno++;
  65. $obj_id .= '_'. $open_flash_chart_seqno;
  66. $div_name .= '_'. $open_flash_chart_seqno;
  67. }
  68. if( $use_swfobject )
  69. {
  70. // Using library for auto-enabling Flash object on IE, disabled-Javascript proof
  71. $out[] = '<div id="'. $div_name .'"></div>';
  72. $out[] = '<script type="text/javascript">';
  73. $out[] = 'var so = new SWFObject("'. $base .'open-flash-chart.swf", "'. $obj_id .'", "'. $width . '", "' . $height . '", "9", "#FFFFFF");';
  74. $out[] = 'so.addVariable("data-file", "'. $url . '");';
  75. $out[] = 'so.addParam("allowScriptAccess", "always" );//"sameDomain");';
  76. $out[] = 'so.write("'. $div_name .'");';
  77. $out[] = '</script>';
  78. $out[] = '<noscript>';
  79. }
  80. $out[] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' . $protocol . '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
  81. $out[] = 'width="' . $width . '" height="' . $height . '" id="ie_'. $obj_id .'" align="middle">';
  82. $out[] = '<param name="allowScriptAccess" value="sameDomain" />';
  83. $out[] = '<param name="movie" value="'. $base .'open-flash-chart.swf?data='. $url .'" />';
  84. $out[] = '<param name="quality" value="high" />';
  85. $out[] = '<param name="bgcolor" value="#FFFFFF" />';
  86. $out[] = '<embed src="'. $base .'open-flash-chart.swf?data=' . $url .'" quality="high" bgcolor="#FFFFFF" width="'. $width .'" height="'. $height .'" name="'. $obj_id .'" align="middle" allowScriptAccess="sameDomain" ';
  87. $out[] = 'type="application/x-shockwave-flash" pluginspage="' . $protocol . '://www.macromedia.com/go/getflashplayer" id="'. $obj_id .'"/>';
  88. $out[] = '</object>';
  89. if ( $use_swfobject ) {
  90. $out[] = '</noscript>';
  91. }
  92. return implode("\n",$out);
  93. }
  94. ?>