Skip to content

Commit

Permalink
MDL-51483 lib/moodlelib.php: Added conditional checks to shorten_text
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhofer committed Dec 3, 2015
1 parent bcf2ea7 commit 4ebdd15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lib/medialib.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ public function embed($urls, $name, $width, $height, $options) {
<param name="ShowGotoBar" value="false" />
<param name="EnableFullScreenControls" value="true" />
<param name="uimode" value="full" />
<!--[if !IE]>-->
<!--[if !IE]><!-->
<object data="$url" type="$mimetype" $size>
<param name="src" value="$url" />
<param name="controller" value="true" />
Expand All @@ -820,7 +820,7 @@ public function embed($urls, $name, $width, $height, $options) {
<param name="resize" value="scale" />
<!--<![endif]-->
$fallback
<!--[if !IE]>-->
<!--[if !IE]><!-->
</object>
<!--<![endif]-->
</object>
Expand Down Expand Up @@ -875,7 +875,7 @@ public function embed($urls, $name, $width, $height, $options) {
<param name="autoplay" value="false" />
<param name="autostart" value="false" />
<param name="scale" value="aspect" />
<!--[if !IE]>-->
<!--[if !IE]><!-->
<object data="$url" type="$mimetype" $size>
<param name="src" value="$url" />
<param name="pluginurl" value="http://www.apple.com/quicktime/download/" />
Expand All @@ -886,7 +886,7 @@ public function embed($urls, $name, $width, $height, $options) {
<param name="scale" value="aspect" />
<!--<![endif]-->
$fallback
<!--[if !IE]>-->
<!--[if !IE]><!-->
</object>
<!--<![endif]-->
</object>
Expand Down Expand Up @@ -934,14 +934,14 @@ public function embed($urls, $name, $width, $height, $options) {
data="$url" width="$width" height="$height"">
<param name="src" value="$url" />
<param name="controls" value="All" />
<!--[if !IE]>-->
<!--[if !IE]><!-->
<object title="$info" type="audio/x-pn-realaudio-plugin"
data="$url" width="$width" height="$height">
<param name="src" value="$url" />
<param name="controls" value="All" />
<!--<![endif]-->
$fallback
<!--[if !IE]>-->
<!--[if !IE]><!-->
</object>
<!--<![endif]-->
</object>
Expand Down Expand Up @@ -989,7 +989,7 @@ public function embed($urls, $name, $width, $height, $options) {
<param name="scale" value="aspect" />
<param name="base" value="." />
<param name="allowscriptaccess" value="never" />
<!--[if !IE]>-->
<!--[if !IE]><!-->
<object type="application/x-shockwave-flash" data="$url" width="$width" height="$height">
<param name="controller" value="true" />
<param name="autoplay" value="true" />
Expand All @@ -999,7 +999,7 @@ public function embed($urls, $name, $width, $height, $options) {
<param name="allowscriptaccess" value="never" />
<!--<![endif]-->
$fallback
<!--[if !IE]>-->
<!--[if !IE]><!-->
</object>
<!--<![endif]-->
</object>
Expand Down
18 changes: 17 additions & 1 deletion lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7692,6 +7692,18 @@ function shorten_text($text, $ideal=30, $exact = false, $ending='...') {
'tag' => core_text::strtolower($tagmatchings[1]),
'pos' => core_text::strlen($truncate),
);
} else if (preg_match('/^<!--\[if\s.*?\]>$/s', $linematchings[1], $tagmatchings)) {
$tagdetails[] = (object) array(
'open' => true,
'tag' => core_text::strtolower('if'),
'pos' => core_text::strlen($truncate),
);
} else if (preg_match('/^<!--<!\[endif\]-->$/s', $linematchings[1], $tagmatchings)) {
$tagdetails[] = (object) array(
'open' => false,
'tag' => core_text::strtolower('if'),
'pos' => core_text::strlen($truncate),
);
}
}
// Add html-tag to $truncate'd text.
Expand Down Expand Up @@ -7777,7 +7789,11 @@ function shorten_text($text, $ideal=30, $exact = false, $ending='...') {

// Close all unclosed html-tags.
foreach ($opentags as $tag) {
$truncate .= '</' . $tag . '>';
if ($tag === 'if') {
$truncate .= '<!--<![endif]-->';
} else {
$truncate .= '</' . $tag . '>';
}
}

return $truncate;
Expand Down
8 changes: 8 additions & 0 deletions lib/tests/moodlelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,14 @@ public function test_shorten_text_with_tags_needs_shortening() {
"tags that ...</blockquote></p></div>", shorten_text($text));
}

public function test_shorten_text_with_tags_and_html_comment() {
$text = "<div class='frog'><p><blockquote><!--[if !IE]><!-->Long text with ".
"tags that will<!--<![endif]--> ".
"be chopped off but <b>should be added back again</b></blockquote></p></div>";
$this->assertEquals("<div class='frog'><p><blockquote><!--[if !IE]><!-->Long text with " .
"tags that ...<!--<![endif]--></blockquote></p></div>", shorten_text($text));
}

public function test_shorten_text_with_entities() {
// Remember to allow 3 chars for the final '...'.
// ......123456789012345678901234567_____890...
Expand Down
4 changes: 2 additions & 2 deletions webservice/amf/testclient/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
<param name="base" value="." />
<param name="allowscriptaccess" value="sameDomain" />
<param name="FlashVars" value="rooturl=$CFG->wwwroot" />
<!--[if !IE]>-->
<!--[if !IE]><!-->
<object type="application/x-shockwave-flash" data="$url" width="100%" height="1000">
<param name="base" value="." />
<param name="allowscriptaccess" value="sameDomain" />
<param name="FlashVars" value="rooturl=$CFG->wwwroot" />
<!--<![endif]-->
<p>You need to install Flash 9.0</p>
<!--[if !IE]>-->
<!--[if !IE]><!-->
</object>
<!--<![endif]-->
</object>
Expand Down

0 comments on commit 4ebdd15

Please sign in to comment.