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 |
|
---|
21 | function open_flash_chart_object_str( $width, $height, $url, $use_swfobject=true, $base='' )
|
---|
22 | {
|
---|
23 | //
|
---|
24 | // return the HTML as a string
|
---|
25 | //
|
---|
26 | return _ofc( $width, $height, $url, $use_swfobject, $base );
|
---|
27 | }
|
---|
28 |
|
---|
29 | function open_flash_chart_object( $width, $height, $url, $use_swfobject=true, $base='' )
|
---|
30 | {
|
---|
31 | //
|
---|
32 | // stream the HTML into the page
|
---|
33 | //
|
---|
34 | echo _ofc( $width, $height, $url, $use_swfobject, $base );
|
---|
35 | }
|
---|
36 |
|
---|
37 | function _ofc( $width, $height, $url, $use_swfobject, $base )
|
---|
38 | {
|
---|
39 | //
|
---|
40 | // I think we may use swfobject for all browsers,
|
---|
41 | // not JUST for IE...
|
---|
42 | //
|
---|
43 | //$ie = strstr(getenv('HTTP_USER_AGENT'), 'MSIE');
|
---|
44 |
|
---|
45 | //
|
---|
46 | // escape the & and stuff:
|
---|
47 | //
|
---|
48 | $url = urlencode($url);
|
---|
49 |
|
---|
50 | //
|
---|
51 | // output buffer
|
---|
52 | //
|
---|
53 | $out = array();
|
---|
54 |
|
---|
55 | //
|
---|
56 | // check for http or https:
|
---|
57 | //
|
---|
58 | if (isset ($_SERVER['HTTPS']))
|
---|
59 | {
|
---|
60 | if (strtoupper ($_SERVER['HTTPS']) == 'ON')
|
---|
61 | {
|
---|
62 | $protocol = 'https';
|
---|
63 | }
|
---|
64 | else
|
---|
65 | {
|
---|
66 | $protocol = 'http';
|
---|
67 | }
|
---|
68 | }
|
---|
69 | else
|
---|
70 | {
|
---|
71 | $protocol = 'http';
|
---|
72 | }
|
---|
73 |
|
---|
74 | //
|
---|
75 | // if there are more than one charts on the
|
---|
76 | // page, give each a different ID
|
---|
77 | //
|
---|
78 | global $open_flash_chart_seqno;
|
---|
79 | $obj_id = 'chart';
|
---|
80 | $div_name = 'flashcontent';
|
---|
81 |
|
---|
82 | //$out[] = '<script type="text/javascript" src="'. $base .'js/ofc.js"></script>';
|
---|
83 |
|
---|
84 | if( !isset( $open_flash_chart_seqno ) )
|
---|
85 | {
|
---|
86 | $open_flash_chart_seqno = 1;
|
---|
87 | $out[] = '<script type="text/javascript" src="'. $base .'js/swfobject.js"></script>';
|
---|
88 | }
|
---|
89 | else
|
---|
90 | {
|
---|
91 | $open_flash_chart_seqno++;
|
---|
92 | $obj_id .= '_'. $open_flash_chart_seqno;
|
---|
93 | $div_name .= '_'. $open_flash_chart_seqno;
|
---|
94 | }
|
---|
95 |
|
---|
96 | if( $use_swfobject )
|
---|
97 | {
|
---|
98 | // Using library for auto-enabling Flash object on IE, disabled-Javascript proof
|
---|
99 | $out[] = '<div id="'. $div_name .'"></div>';
|
---|
100 | $out[] = '<script type="text/javascript">';
|
---|
101 | $out[] = 'var so = new SWFObject("'. $base .'open-flash-chart.swf", "'. $obj_id .'", "'. $width . '", "' . $height . '", "9", "#FFFFFF");';
|
---|
102 |
|
---|
103 | $out[] = 'so.addVariable("data-file", "'. $url . '");';
|
---|
104 |
|
---|
105 | $out[] = 'so.addParam("allowScriptAccess", "always" );//"sameDomain");';
|
---|
106 | $out[] = 'so.write("'. $div_name .'");';
|
---|
107 | $out[] = '</script>';
|
---|
108 | $out[] = '<noscript>';
|
---|
109 | }
|
---|
110 |
|
---|
111 | $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" ';
|
---|
112 | $out[] = 'width="' . $width . '" height="' . $height . '" id="ie_'. $obj_id .'" align="middle">';
|
---|
113 | $out[] = '<param name="allowScriptAccess" value="sameDomain" />';
|
---|
114 | $out[] = '<param name="movie" value="'. $base .'open-flash-chart.swf?data='. $url .'" />';
|
---|
115 | $out[] = '<param name="quality" value="high" />';
|
---|
116 | $out[] = '<param name="bgcolor" value="#FFFFFF" />';
|
---|
117 | $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" ';
|
---|
118 | $out[] = 'type="application/x-shockwave-flash" pluginspage="' . $protocol . '://www.macromedia.com/go/getflashplayer" id="'. $obj_id .'"/>';
|
---|
119 | $out[] = '</object>';
|
---|
120 |
|
---|
121 | if ( $use_swfobject ) {
|
---|
122 | $out[] = '</noscript>';
|
---|
123 | }
|
---|
124 |
|
---|
125 | return implode("\n",$out);
|
---|
126 | }
|
---|
127 |
|
---|