Fixes to the PaintWeb cron task.
[moodle/mihaisucan.git] / mod / data / filter.php
blob804e894a988788c83e152e2181c7f3f8cd6865a7
1 <?php // $Id$
2 //
3 // This function provides automatic linking to data contents of text
4 // fields where these fields have autolink enabled.
5 //
6 // Original code by Williams, Stronk7, Martin D.
7 // Modified for data module by Vy-Shane SF.
9 function data_filter($courseid, $text) {
10 global $CFG;
12 static $nothingtodo;
13 static $contentlist;
15 if (!empty($nothingtodo)) { // We've been here in this page already
16 return $text;
19 // if we don't have a courseid, we can't run the query, so
20 if (empty($courseid)) {
21 return $text;
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, ' .
31 'd.id AS dataid ' .
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' " .
42 "AND " . sql_compare_text('df.param1', 1) . " = '1'";
44 if (!$datacontents = get_records_sql($sql)) {
45 return $text;
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(
56 $currentcontent,
57 '<a class="data autolink" title="'.
58 $strippedcontent.'" href="'.
59 $CFG->wwwroot.'/mod/data/view.php?d='. $datacontent->dataid .
60 '&amp;rid='. $datacontent->recordid .'" '.$CFG->frametarget.'>',
61 '</a>', false, true);
63 } // End foreach
65 return filter_phrases($text, $contentlist); // Look for all these links in the text