CFlexWidget.php 3.3 KB

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