open-flash-chart-object.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * PHP Integration of Open Flash Chart
  4. * Copyright (C) 2008 John Glazebrook <open-flash-chart@teethgrinder.co.uk>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. function open_flash_chart_object_str( $width, $height, $url, $use_swfobject=true, $base='' )
  21. {
  22. //
  23. // return the HTML as a string
  24. //
  25. return _ofc( $width, $height, $url, $use_swfobject, $base );
  26. }
  27. function open_flash_chart_object( $width, $height, $url, $use_swfobject=true, $base='' )
  28. {
  29. //
  30. // stream the HTML into the page
  31. //
  32. echo _ofc( $width, $height, $url, $use_swfobject, $base );
  33. }
  34. function _ofc( $width, $height, $url, $use_swfobject, $base )
  35. {
  36. //
  37. // I think we may use swfobject for all browsers,
  38. // not JUST for IE...
  39. //
  40. //$ie = strstr(getenv('HTTP_USER_AGENT'), 'MSIE');
  41. //
  42. // escape the & and stuff:
  43. //
  44. $url = urlencode($url);
  45. //
  46. // output buffer
  47. //
  48. $out = array();
  49. //
  50. // check for http or https:
  51. //
  52. if (isset ($_SERVER['HTTPS']))
  53. {
  54. if (strtoupper ($_SERVER['HTTPS']) == 'ON')
  55. {
  56. $protocol = 'https';
  57. }
  58. else
  59. {
  60. $protocol = 'http';
  61. }
  62. }
  63. else
  64. {
  65. $protocol = 'http';
  66. }
  67. //
  68. // if there are more than one charts on the
  69. // page, give each a different ID
  70. //
  71. global $open_flash_chart_seqno;
  72. $obj_id = 'chart';
  73. $div_name = 'flashcontent';
  74. //$out[] = '<script type="text/javascript" src="'. $base .'js/ofc.js"></script>';
  75. if( !isset( $open_flash_chart_seqno ) )
  76. {
  77. $open_flash_chart_seqno = 1;
  78. $out[] = '<script type="text/javascript" src="'. $base .'js/swfobject.js"></script>';
  79. }
  80. else
  81. {
  82. $open_flash_chart_seqno++;
  83. $obj_id .= '_'. $open_flash_chart_seqno;
  84. $div_name .= '_'. $open_flash_chart_seqno;
  85. }
  86. if( $use_swfobject )
  87. {
  88. // Using library for auto-enabling Flash object on IE, disabled-Javascript proof
  89. $out[] = '<div id="'. $div_name .'"></div>';
  90. $out[] = '<script type="text/javascript">';
  91. $out[] = 'var so = new SWFObject("'. $base .'open-flash-chart.swf", "'. $obj_id .'", "'. $width . '", "' . $height . '", "9", "#FFFFFF");';
  92. $out[] = 'so.addVariable("data-file", "'. $url . '");';
  93. $out[] = 'so.addParam("allowScriptAccess", "always" );//"sameDomain");';
  94. $out[] = 'so.write("'. $div_name .'");';
  95. $out[] = '</script>';
  96. $out[] = '<noscript>';
  97. }
  98. $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" ';
  99. $out[] = 'width="' . $width . '" height="' . $height . '" id="ie_'. $obj_id .'" align="middle">';
  100. $out[] = '<param name="allowScriptAccess" value="sameDomain" />';
  101. $out[] = '<param name="movie" value="'. $base .'open-flash-chart.swf?data='. $url .'" />';
  102. $out[] = '<param name="quality" value="high" />';
  103. $out[] = '<param name="bgcolor" value="#FFFFFF" />';
  104. $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" ';
  105. $out[] = 'type="application/x-shockwave-flash" pluginspage="' . $protocol . '://www.macromedia.com/go/getflashplayer" id="'. $obj_id .'"/>';
  106. $out[] = '</object>';
  107. if ( $use_swfobject ) {
  108. $out[] = '</noscript>';
  109. }
  110. return implode("\n",$out);
  111. }