/** * Flash object helper - embeds Flash objects (files with the .swf extension) * * Uses Unobtrusive Flash Objects (UFO) * * @param string $id - The ID od the div which will be replaced by flash movie * @param mixed $options - Flash object options * @see http://www.bobbyvandersluis.com/ufo/ */ function flash_object($id, $options = array()) { sfContext::getInstance()->getResponse()->addJavascript('ufo.js'); $options = _parse_attributes($options); $absolute = false; if (isset($options['absolute'])) { unset($options['absolute']); $absolute = true; } if (isset($options['size'])) { list($options['width'], $options['height']) = split('x', $options['size'], 2); unset($options['size']); } if (!isset($options['majorversion'])) { $options['majorversion'] = 7; } if (!isset($options['build'])) { $options['build'] = 0; } // check for all required params foreach (array('movie', 'width', 'height', 'majorversion', 'build') as $required) { if (!isset($options[$required])) { throw new sfException("{FlashHelper} Required parameter \"{$required}\" is missing."); } } $options['movie'] = flash_path($options['movie'], $absolute); $opts = array(); foreach ($options as $key => $value) { $opts[] = $key . ': "' . $value . '"'; } sort($opts); // javascript variable name $name = $id . '_var'; $js = 'var ' . $name . " = {" . join(', ', $opts) . "};\n"; $js .= 'UFO.create(' . $name . ', "' . $id . '");' . "\n"; return content_tag('script', "\n//" . cdata_section("\n{$js}\n//") . "\n", array('type' => 'text/javascript')); }
function javascript_cdata_section($content) { return "\n//" . cdata_section("\n{$content}\n//") . "\n"; }
$t->is(tag('br'), '<br />', 'tag() takes a tag as its first parameter'); $t->is(tag('p', null, true), '<p>', 'tag() takes a boolean parameter as its third parameter'); $t->is(tag('br', array('class' => 'foo'), false), '<br class="foo" />', 'tag() takes an array of options as its second parameters'); $t->is(tag('br', 'class=foo', false), '<br class="foo" />', 'tag() takes a string of options as its second parameters'); $t->is(tag('p', array('class' => 'foo', 'id' => 'bar'), true), '<p class="foo" id="bar">', 'tag() takes a boolean parameter as its third parameter'); //$t->is(tag('br', array('class' => '"foo"')), '<br class=""foo"" />'); // content_tag() $t->diag('content_tag()'); $t->is(content_tag(''), '', 'content_tag() returns an empty string with empty input'); $t->is(content_tag('', ''), '', 'content_tag() returns an empty string with empty input'); $t->is(content_tag('p', 'Toto'), '<p>Toto</p>', 'content_tag() takes a content as its second parameter'); $t->is(content_tag('p', ''), '<p></p>', 'content_tag() takes a tag as its first parameter'); // cdata_section() $t->diag('cdata_section()'); $t->is(cdata_section(''), '<![CDATA[]]>', 'cdata_section() returns a string wrapped into a CDATA section'); $t->is(cdata_section('foobar'), '<![CDATA[foobar]]>', 'cdata_section() returns a string wrapped into a CDATA section'); // escape_javascript() $t->diag('escape_javascript()'); $t->is(escape_javascript("alert('foo');\nalert(\"bar\");"), 'alert(\\\'foo\\\');\\nalert(\\"bar\\");', 'escape_javascript() escapes JavaScript scripts'); // _get_option() $t->diag('_get_option()'); $options = array('foo' => 'bar', 'bar' => 'foo'); $t->is(_get_option($options, 'foo'), 'bar', '_get_option() returns the value for the given key'); $t->ok(!isset($options['foo']), '_get_option() removes the key from the original array'); $t->is(_get_option($options, 'nofoo', 'nobar'), 'nobar', '_get_option() returns the default value if the key does not exist'); // escape_once() $t->diag('escape_once()'); $t->is(escape_once('This a > text to "escape"'), 'This a > text to "escape"', 'escape_once() escapes an HTML strings'); $t->is(escape_once(escape_once('This a > text to "escape"')), 'This a > text to "escape"', 'escape_once() does not escape an already escaped string'); $t->is(escape_once('This a > text to "escape"'), 'This a > text to "escape"', 'escape_once() does not escape an already escaped string'); $t->is(escape_once("This a > \"text\" to 'escape'"), "This a > "text" to 'escape'", 'escape_once() does not escape simple quotes but escape double quotes');
public function testCdataSection() { $this->assertEqual(cdata_section('<hello world>'), '<![CDATA[<hello world>]]>'); }
/** * @see javascript_tag_minified * @param string $content * @return string */ function style_tag_minified($content = null, array $elementOptions = array()) { use_helper('Tag'); if (null === $content) { ob_start(); } else { // minify content $content = sfCombineUtility::minifyInlineCss($content); if (!isset($elementOptions['type'])) { $elementOptions['type'] = 'text/css'; } return content_tag('style', "\n/*" . cdata_section("*/\n{$content}\n/*") . "*/\n", $elementOptions); } }
/** * Test cdata_section(). */ public function testCdata_section() { // Test the cdata_section() method of the object $h = new Helpers(); $s = $h->cdata_section('foo'); $this->assertEquals("<![CDATA[foo]]>", $s); // Test the file function that calls cdata_section() $s = cdata_section('foo'); $this->assertEquals("<![CDATA[foo]]>", $s); }