[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 /////////////////////////////////////////////////////////////////////////// 3 // // 4 // NOTICE OF COPYRIGHT // 5 // // 6 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 7 // http://moodle.org // 8 // // 9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com // 10 // // 11 // This program is free software; you can redistribute it and/or modify // 12 // it under the terms of the GNU General Public License as published by // 13 // the Free Software Foundation; either version 2 of the License, or // 14 // (at your option) any later version. // 15 // // 16 // This program is distributed in the hope that it will be useful, // 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 19 // GNU General Public License for more details: // 20 // // 21 // http://www.gnu.org/copyleft/gpl.html // 22 // // 23 /////////////////////////////////////////////////////////////////////////// 24 25 class data_field_url extends data_field_base { 26 var $type = 'url'; 27 28 function display_add_field($recordid=0) { 29 global $CFG, $DB, $OUTPUT, $PAGE; 30 31 require_once($CFG->dirroot. '/repository/lib.php'); // necessary for the constants used in args 32 33 $args = new stdClass(); 34 $args->accepted_types = '*'; 35 $args->return_types = FILE_EXTERNAL; 36 $args->context = $this->context; 37 $args->env = 'url'; 38 $fp = new file_picker($args); 39 $options = $fp->options; 40 41 $fieldid = 'field_url_'.$options->client_id; 42 43 $straddlink = get_string('choosealink', 'repository'); 44 $url = ''; 45 $text = ''; 46 if ($recordid) { 47 if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { 48 $url = $content->content; 49 $text = $content->content1; 50 } 51 } 52 $str = '<div title="'.s($this->field->description).'">'; 53 if (!empty($this->field->param1) and empty($this->field->param2)) { 54 $str .= '<table><tr><td align="right">'; 55 $str .= get_string('url','data').':</td><td>'; 56 $str .= '<label class="accesshide" for="' . $fieldid . '">'. $this->field->name .'</label>'; 57 $str .= '<input type="text" name="field_'.$this->field->id.'_0" id="'.$fieldid.'" value="'.$url.'" size="60" />'; 58 $str .= '<button id="filepicker-button-'.$options->client_id.'" style="display:none">'.$straddlink.'</button></td></tr>'; 59 $str .= '<tr><td align="right">'.get_string('text','data').':</td><td><input type="text" name="field_'.$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.s($text).'" size="60" /></td></tr>'; 60 $str .= '</table>'; 61 } else { 62 // Just the URL field 63 $str .= '<label class="accesshide" for="' . $fieldid . '">'. $this->field->name .'</label>'; 64 $str .= '<input type="text" name="field_'.$this->field->id.'_0" id="'.$fieldid.'" value="'.s($url).'" size="60" />'; 65 if (count($options->repositories) > 0) { 66 $str .= '<button id="filepicker-button-'.$options->client_id.'" class="visibleifjs">'.$straddlink.'</button>'; 67 } 68 } 69 70 // print out file picker 71 //$str .= $OUTPUT->render($fp); 72 73 $module = array('name'=>'data_urlpicker', 'fullpath'=>'/mod/data/data.js', 'requires'=>array('core_filepicker')); 74 $PAGE->requires->js_init_call('M.data_urlpicker.init', array($options), true, $module); 75 76 $str .= '</div>'; 77 return $str; 78 } 79 80 function display_search_field($value = '') { 81 return '<label class="accesshide" for="f_'.$this->field->id.'">' . get_string('fieldname', 'data') . '</label>' . 82 '<input type="text" size="16" id="f_'.$this->field->id.'" name="f_'.$this->field->id.'" value="'.$value.'" />'; 83 } 84 85 function parse_search_field() { 86 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); 87 } 88 89 function generate_sql($tablealias, $value) { 90 global $DB; 91 92 static $i=0; 93 $i++; 94 $name = "df_url_$i"; 95 return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%")); 96 } 97 98 function display_browse_field($recordid, $template) { 99 global $DB; 100 101 if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { 102 $url = empty($content->content)? '':$content->content; 103 $text = empty($content->content1)? '':$content->content1; 104 if (empty($url) or ($url == 'http://')) { 105 return ''; 106 } 107 if (!empty($this->field->param2)) { 108 // param2 forces the text to something 109 $text = $this->field->param2; 110 } 111 if ($this->field->param1) { 112 // param1 defines whether we want to autolink the url. 113 $attributes = array(); 114 if ($this->field->param3) { 115 // param3 defines whether this URL should open in a new window. 116 $attributes['target'] = '_blank'; 117 } 118 119 if (empty($text)) { 120 $text = $url; 121 } 122 123 $str = html_writer::link($url, $text, $attributes); 124 } else { 125 $str = $url; 126 } 127 return $str; 128 } 129 return false; 130 } 131 132 function update_content($recordid, $value, $name='') { 133 global $DB; 134 135 $content = new stdClass(); 136 $content->fieldid = $this->field->id; 137 $content->recordid = $recordid; 138 $names = explode('_', $name); 139 140 switch ($names[2]) { 141 case 0: 142 // update link 143 $content->content = clean_param($value, PARAM_URL); 144 break; 145 case 1: 146 // add text 147 $content->content1 = clean_param($value, PARAM_NOTAGS); 148 break; 149 default: 150 break; 151 } 152 153 if (!empty($content->content) && (strpos($content->content, '://') === false) && (strpos($content->content, '/', 0) === false)) { 154 $content->content = 'http://' . $content->content; 155 } 156 157 if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { 158 $content->id = $oldcontent->id; 159 return $DB->update_record('data_content', $content); 160 } else { 161 return $DB->insert_record('data_content', $content); 162 } 163 } 164 165 function notemptyfield($value, $name) { 166 $names = explode('_',$name); 167 $value = clean_param($value, PARAM_URL); 168 //clean first 169 if ($names[2] == '0') { 170 return ($value!='http://' && !empty($value)); 171 } 172 return false; 173 } 174 175 function export_text_value($record) { 176 return $record->content . " " . $record->content1; 177 } 178 179 } 180 181
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |