1: <?php
2: /**
3: * CFlexWidget class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CFlexWidget embeds a Flex 3.x application into a page.
13: *
14: * To use CFlexWidget, set {@link name} to be the Flex application name
15: * (without the .swf suffix), and set {@link baseUrl} to be URL (without the ending slash)
16: * of the directory containing the SWF file of the Flex application.
17: *
18: * @property string $flashVarsAsString The flash parameter string.
19: *
20: * @author Qiang Xue <qiang.xue@gmail.com>
21: * @package system.web.widgets
22: * @since 1.0
23: */
24: class CFlexWidget extends CWidget
25: {
26: /**
27: * @var string name of the Flex application.
28: * This should be the SWF file name without the ".swf" suffix.
29: */
30: public $name;
31: /**
32: * @var string the base URL of the Flex application.
33: * This refers to the URL of the directory containing the SWF file.
34: */
35: public $baseUrl;
36: /**
37: * @var string width of the application region. Defaults to 450.
38: */
39: public $width='100%';
40: /**
41: * @var string height of the application region. Defaults to 300.
42: */
43: public $height='100%';
44: /**
45: * @var string quality of the animation. Defaults to 'high'.
46: */
47: public $quality='high';
48: /**
49: * @var string background color of the application region. Defaults to '#FFFFFF', meaning white.
50: */
51: public $bgColor='#FFFFFF';
52: /**
53: * @var string align of the application region. Defaults to 'middle'.
54: */
55: public $align='middle';
56: /**
57: * @var string the access method of the script. Defaults to 'sameDomain'.
58: */
59: public $allowScriptAccess='sameDomain';
60: /**
61: * @var boolean whether to allow running the Flash in full screen mode. Defaults to false.
62: * @since 1.1.1
63: */
64: public $allowFullScreen=false;
65: /**
66: * @var string the HTML content to be displayed if Flash player is not installed.
67: */
68: public $altHtmlContent;
69: /**
70: * @var boolean whether history should be enabled. Defaults to true.
71: */
72: public $enableHistory=true;
73: /**
74: * @var array parameters to be passed to the Flex application.
75: */
76: public $flashVars=array();
77:
78: /**
79: * Renders the widget.
80: */
81: public function run()
82: {
83: if(empty($this->name))
84: throw new CException(Yii::t('yii','CFlexWidget.name cannot be empty.'));
85: if(empty($this->baseUrl))
86: throw new CException(Yii::t('yii','CFlexWidget.baseUrl cannot be empty.'));
87: if($this->altHtmlContent===null)
88: $this->altHtmlContent=Yii::t('yii','This content requires the <a href="http://www.adobe.com/go/getflash/">Adobe Flash Player</a>.');
89:
90: $this->registerClientScript();
91:
92: $this->render('flexWidget');
93: }
94:
95: /**
96: * Registers the needed CSS and JavaScript.
97: */
98: public function registerClientScript()
99: {
100: $cs=Yii::app()->getClientScript();
101: $cs->registerScriptFile($this->baseUrl.'/AC_OETags.js');
102:
103: if($this->enableHistory)
104: {
105: $cs->registerCssFile($this->baseUrl.'/history/history.css');
106: $cs->registerScriptFile($this->baseUrl.'/history/history.js');
107: }
108: }
109:
110: /**
111: * Generates the properly quoted flash parameter string.
112: * @return string the flash parameter string.
113: */
114: public function getFlashVarsAsString()
115: {
116: $params=array();
117: foreach($this->flashVars as $k=>$v)
118: $params[]=urlencode($k).'='.urlencode($v);
119: return CJavaScript::quote(implode('&',$params));
120: }
121: }