3 // This function provides automatic linking to data contents of text
4 // fields where these fields have autolink enabled.
6 // Original code by Williams, Stronk7, Martin D.
7 // Modified for data module by Vy-Shane SF.
9 function data_filter($courseid, $text) {
15 if (!empty($nothingtodo)) { // We've been here in this page already
19 // if we don't have a courseid, we can't run the query, so
20 if (empty($courseid)) {
24 // Create a list of all the resources to search for. It may be cached already.
25 if (empty($contentlist)) {
26 // We look for text field contents only, and only if the field has
27 // autolink enabled (param1).
28 $sql = 'SELECT dc.id AS contentid, ' .
29 'dr.id AS recordid, ' .
30 'dc.content AS content, ' .
32 'FROM '.$CFG->prefix
.'data d, ' .
33 $CFG->prefix
.'data_fields df, ' .
34 $CFG->prefix
.'data_records dr, ' .
35 $CFG->prefix
.'data_content dc ' .
36 "WHERE (d.course = '$courseid' or d.course = '".SITEID
."')" .
37 'AND d.id = df.dataid ' .
38 'AND df.id = dc.fieldid ' .
39 'AND d.id = dr.dataid ' .
40 'AND dr.id = dc.recordid ' .
41 "AND df.type = 'text' " .
44 if (!$datacontents = get_records_sql($sql)) {
48 $contentlist = array();
50 foreach ($datacontents as $datacontent) {
51 $currentcontent = trim($datacontent->content
);
52 $strippedcontent = strip_tags($currentcontent);
54 if (!empty($strippedcontent)) {
55 $contentlist[] = new filterobject(
57 '<a class="data autolink" title="'.
58 $strippedcontent.'" href="'.
59 $CFG->wwwroot
.'/mod/data/view.php?d='. $datacontent->dataid
.
60 '&rid='. $datacontent->recordid
.'" '.$CFG->frametarget
.'>',
65 return filter_phrases($text, $contentlist); // Look for all these links in the text