Skip to content

Commit 34513d7

Browse files
committed
Get rid of dependency on simplehtmldom library
The autotitle functionality is now provided by the native PHP DOM extension. Fixes issue #28
1 parent ff8bfa0 commit 34513d7

File tree

3 files changed

+1
-1027
lines changed

3 files changed

+1
-1027
lines changed

block_course_contents.php

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function get_content() {
155155
$summary = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course',
156156
'section', $section->id);
157157
$summary = format_text($summary, $section->summaryformat, array('para' => false, 'context' => $context));
158-
$title = format_string($this->extract_title($summary), true, array('context' => $context));
158+
$title = format_string(\block_course_contents\autotitle::extract_title($summary), true, ['context' => $context]);
159159
}
160160

161161
// If at this point we have no title available, use the default one.
@@ -294,46 +294,4 @@ public function get_content() {
294294
$this->content->text = $text;
295295
return $this->content;
296296
}
297-
298-
299-
/**
300-
* Given a section summary, exctract a text suitable as a section title
301-
*
302-
* @param string $summary Section summary as returned from database (no slashes)
303-
* @return string Section title
304-
*/
305-
private function extract_title($summary) {
306-
global $CFG;
307-
require_once(dirname(__FILE__).'/lib/simple_html_dom.php');
308-
309-
$node = new simple_html_dom();
310-
$node->load($summary);
311-
return $this->node_plain_text($node);
312-
}
313-
314-
315-
/**
316-
* Recursively find the first suitable plaintext from the HTML DOM.
317-
*
318-
* Internal private function called only from {@link extract_title()}
319-
*
320-
* @param simple_html_dom $node Current root node
321-
* @return string
322-
*/
323-
private function node_plain_text($node) {
324-
if ($node->nodetype == HDOM_TYPE_TEXT) {
325-
$t = trim($node->plaintext);
326-
if (!empty($t)) {
327-
return $t;
328-
}
329-
}
330-
$t = '';
331-
foreach ($node->nodes as $n) {
332-
$t = $this->node_plain_text($n);
333-
if (!empty($t)) {
334-
break;
335-
}
336-
}
337-
return $t;
338-
}
339297
}

0 commit comments

Comments
 (0)