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